module Drasil.SWHS.DataDefs where --exports all of it

import Language.Drasil
import Theory.Drasil (DataDefinition, ddE, ddENoRefs)
import Language.Drasil.Chunk.Concept.NamedCombinators
import qualified Language.Drasil.Sentence.Combinators as S

import Data.Drasil.Concepts.Documentation (value)
import Data.Drasil.Concepts.Thermodynamics (heat)

import Data.Drasil.Quantities.Math (pi_)
import Data.Drasil.Quantities.Physics (energy, pressure)
import Data.Drasil.Quantities.PhysicalProperties (mass)
import Data.Drasil.Quantities.Thermodynamics (latentHeat)

import Drasil.SWHS.Assumptions (assumpVCN)
import Drasil.SWHS.References (bueche1986, koothoor2013, lightstone2012)
import Drasil.SWHS.Unitals (aspectRatio, coilHTC, coilSA, diam, eta, htCapLP,
  htCapSP, htCapW, htFusion, latentEP, meltFrac, pcmHTC, pcmMass, pcmSA, pcmVol,
  tankLength, tankVol, tauLP, tauSP, tauW, wDensity, wMass, wVol)

qDefs :: [SimpleQDef]
qDefs :: [SimpleQDef]
qDefs = [SimpleQDef
waterMassQD, SimpleQDef
waterVolumeQD, SimpleQDef
tankVolumeQD, SimpleQDef
balanceDecayRateQD, 
  SimpleQDef
balanceDecayTimeQD, SimpleQDef
balanceSolidPCMQD, SimpleQDef
balanceLiquidPCMQD, SimpleQDef
ddHtFusionQD, 
  SimpleQDef
ddMeltFracQD, SimpleQDef
aspRatQD]

dataDefs :: [DataDefinition] 
dataDefs :: [DataDefinition]
dataDefs = [DataDefinition
waterMass, DataDefinition
waterVolume, DataDefinition
tankVolume, DataDefinition
balanceDecayRate, 
  DataDefinition
balanceDecayTime, DataDefinition
balanceSolidPCM, DataDefinition
balanceLiquidPCM, DataDefinition
ddHtFusion, DataDefinition
ddMeltFrac, 
  DataDefinition
aspRat]

-- FIXME? This section looks strange. Some data defs are created using
--    terms, some using defns, and some with a brand new description.
--    I think this will need an overhaul after we fix Data Definitions.

waterMassQD :: SimpleQDef
waterMassQD :: SimpleQDef
waterMassQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
wMass Expr
waterMassEqn

waterMassEqn :: Expr
waterMassEqn :: Expr
waterMassEqn = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
wVol forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
wDensity

waterMassNotes :: Sentence
waterMassNotes :: Sentence
waterMassNotes = [Sentence] -> Sentence
foldlSent [forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
wVol, String -> Sentence
S String
"is defined in", forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS DataDefinition
waterVolume]

waterMass :: DataDefinition
waterMass :: DataDefinition
waterMass = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
waterMassQD forall a. Maybe a
Nothing String
"waterMass" []

----

waterVolumeQD :: SimpleQDef
waterVolumeQD :: SimpleQDef
waterVolumeQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
wVol Expr
waterVolumeEqn

waterVolumeEqn :: Expr
waterVolumeEqn :: Expr
waterVolumeEqn = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
tankVol forall r. ExprC r => r -> r -> r
$- forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
pcmVol

waterVolumeNotes :: Sentence
waterVolumeNotes :: Sentence
waterVolumeNotes = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"Based on" Sentence -> Sentence -> Sentence
+:+. forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS ConceptInstance
assumpVCN, 
  forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
tankVol, String -> Sentence
S String
"is defined in", forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS DataDefinition
tankVolume]

waterVolume :: DataDefinition
waterVolume :: DataDefinition
waterVolume = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
waterVolumeQD forall a. Maybe a
Nothing String
"waterVolume_pcm" 
  [Sentence
waterVolumeNotes]

----

tankVolumeQD :: SimpleQDef
tankVolumeQD :: SimpleQDef
tankVolumeQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
tankVol Expr
tankVolumeEqn

tankVolumeEqn :: Expr
tankVolumeEqn :: Expr
tankVolumeEqn = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy DefinedQuantityDict
pi_ forall r. ExprC r => r -> r -> r
`mulRe` forall r. (ExprC r, LiteralC r) => r -> r
square (forall r. (ExprC r, LiteralC r) => r -> r
half forall a b. (a -> b) -> a -> b
$ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
diam) forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
tankLength

tankVolume :: DataDefinition
tankVolume :: DataDefinition
tankVolume = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
tankVolumeQD forall a. Maybe a
Nothing String
"tankVolume" []

----

balanceDecayRateQD :: SimpleQDef
balanceDecayRateQD :: SimpleQDef
balanceDecayRateQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
tauW Expr
balanceDecayRateEqn

balanceDecayRateEqn :: Expr
balanceDecayRateEqn :: Expr
balanceDecayRateEqn = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
wMass forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
htCapW forall r. ExprC r => r -> r -> r
$/ (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
coilHTC forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
coilSA)

balanceDecayRateNotes :: Sentence
balanceDecayRateNotes :: Sentence
balanceDecayRateNotes = [Sentence] -> Sentence
foldlSent [forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
wMass, String -> Sentence
S String
"is defined in", 
  forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS DataDefinition
waterMass]

balanceDecayRate :: DataDefinition
balanceDecayRate :: DataDefinition
balanceDecayRate = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
balanceDecayRateQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
koothoor2013]
  forall a. Maybe a
Nothing String
"balanceDecayRate" []

----

balanceDecayTimeQD :: SimpleQDef
balanceDecayTimeQD :: SimpleQDef
balanceDecayTimeQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef DefinedQuantityDict
eta Expr
balanceDecayTimeEqn

balanceDecayTimeEqn :: Expr
balanceDecayTimeEqn :: Expr
balanceDecayTimeEqn = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
pcmHTC forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
pcmSA forall r. ExprC r => r -> r -> r
$/ (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
coilHTC forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
coilSA)

balanceDecayTime :: DataDefinition
balanceDecayTime :: DataDefinition
balanceDecayTime = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
balanceDecayTimeQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
koothoor2013]
  forall a. Maybe a
Nothing String
"balanceDecayTime" []

----

balanceSolidPCMQD :: SimpleQDef
balanceSolidPCMQD :: SimpleQDef
balanceSolidPCMQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
tauSP Expr
balanceSolidPCMEqn

balanceSolidPCMEqn :: Expr
balanceSolidPCMEqn :: Expr
balanceSolidPCMEqn = (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
pcmMass forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
htCapSP) forall r. ExprC r => r -> r -> r
$/
  (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
pcmHTC forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
pcmSA)

balanceSolidPCM :: DataDefinition
balanceSolidPCM :: DataDefinition
balanceSolidPCM = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
balanceSolidPCMQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
lightstone2012]
  forall a. Maybe a
Nothing String
"balanceSolidPCM" []

----

balanceLiquidPCMQD :: SimpleQDef
balanceLiquidPCMQD :: SimpleQDef
balanceLiquidPCMQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
tauLP Expr
balanceLiquidPCMEqn

balanceLiquidPCMEqn :: Expr
balanceLiquidPCMEqn :: Expr
balanceLiquidPCMEqn = (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
pcmMass forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
htCapLP) forall r. ExprC r => r -> r -> r
$/
  (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
pcmHTC forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
pcmSA)

balanceLiquidPCM :: DataDefinition
balanceLiquidPCM :: DataDefinition
balanceLiquidPCM = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
balanceLiquidPCMQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
lightstone2012]
  forall a. Maybe a
Nothing String
"balanceLiquidPCM" []

----

ddHtFusionQD :: SimpleQDef
ddHtFusionQD :: SimpleQDef
ddHtFusionQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UncertQ
htFusion Expr
htFusionEqn

htFusionEqn :: Expr
htFusionEqn :: Expr
htFusionEqn = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
latentHeat forall r. ExprC r => r -> r -> r
$/ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
mass

ddHtFusion :: DataDefinition
ddHtFusion :: DataDefinition
ddHtFusion = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
ddHtFusionQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> RefInfo -> DecRef
dRefInfo Citation
bueche1986 forall a b. (a -> b) -> a -> b
$ [Int] -> RefInfo
Page [Int
282]]
  forall a. Maybe a
Nothing String
"htFusion" [Sentence
htFusionNote]

htFusionNote :: Sentence
htFusionNote :: Sentence
htFusionNote = [Sentence] -> Sentence
foldlSent [forall n. NounPhrase n => n -> Sentence
atStartNP (forall t. NamedIdea t => t -> NP
the UncertQ
htFusion),
  Sentence -> Sentence
sParen (String -> Sentence
S String
"also known as the enthalpy of fusion"), String -> Sentence
S String
"of a substance is the",
  forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
heat, forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
energy, String -> Sentence
S String
"required", Sentence -> Sentence
sParen (forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
latentHeat), String -> Sentence
S String
"to change the state of a unit of the",
  forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
mass, Sentence -> Sentence
sParen (forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
mass), String -> Sentence
S String
"of the substance from solid to liquid" Sentence -> Sentence -> Sentence
`sC`
  String -> Sentence
S String
"at constant", forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
pressure]

----

ddMeltFracQD :: SimpleQDef
ddMeltFracQD :: SimpleQDef
ddMeltFracQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef DefinedQuantityDict
meltFrac Expr
meltFracEqn

--FIXME: "Phi is the melt fraction" is produced; 
  --"Phi is the fraction of the PCM that is liquid" is what is supposed to be
  -- produced according to CaseStudies' original

meltFracEqn :: Expr
meltFracEqn :: Expr
meltFracEqn = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
latentEP forall r. ExprC r => r -> r -> r
$/ (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
htFusion forall r. ExprC r => r -> r -> r
`mulRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
pcmMass)

ddMeltFrac :: DataDefinition
ddMeltFrac :: DataDefinition
ddMeltFrac = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
ddMeltFracQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
koothoor2013]
  forall a. Maybe a
Nothing String
"meltFrac" [Sentence
meltFracConst, forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS DataDefinition
ddHtFusion]
  where meltFracConst :: Sentence
meltFracConst = forall n. NounPhrase n => n -> Sentence
atStartNP (forall t. NamedIdea t => t -> NP
the IdeaDict
value) Sentence -> Sentence -> Sentence
`S.of_` forall t. Express t => t -> Sentence
eS' DefinedQuantityDict
meltFrac Sentence -> Sentence -> Sentence
`S.is`
                        String -> Sentence
S String
"constrained to" Sentence -> Sentence -> Sentence
+:+. ModelExpr -> Sentence
eS (forall r c. (ExprC r, HasUID c) => c -> RealInterval r r -> r
realInterval DefinedQuantityDict
meltFrac (forall a b. (Inclusive, a) -> (Inclusive, b) -> RealInterval a b
Bounded (Inclusive
Inc, forall r. LiteralC r => Integer -> r
exactDbl Integer
0) (Inclusive
Inc, forall r. LiteralC r => Integer -> r
exactDbl Integer
1)))

----

aspRatQD :: SimpleQDef
aspRatQD :: SimpleQDef
aspRatQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef DefinedQuantityDict
aspectRatio Expr
aspRatEq

aspRatEq :: Expr
aspRatEq :: Expr
aspRatEq = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
diam forall r. ExprC r => r -> r -> r
$/ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
tankLength

aspRat :: DataDefinition
aspRat :: DataDefinition
aspRat = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
aspRatQD forall a. Maybe a
Nothing String
"aspectRatio" []

--Need to add units to data definition descriptions

--Symbol appears as "Label"
--There is no actual label
--Units section doesn't appear