Skip to content

Commit

Permalink
Merge pull request #1805 from JacquesCarette/swhsIMs
Browse files Browse the repository at this point in the history
Improved SWHS IMs
  • Loading branch information
JacquesCarette authored Aug 9, 2019
2 parents eb67038 + bc3e20c commit 1c0b0d1
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 343 deletions.
51 changes: 21 additions & 30 deletions code/drasil-example/Drasil/NoPCM/IMods.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Drasil.NoPCM.IMods (eBalanceOnWtr, iMods, instModIntro) where

import Language.Drasil
import Theory.Drasil (DataDefinition, InstanceModel, im)
import Theory.Drasil (InstanceModel, im)
import Utils.Drasil
import Control.Lens ((^.))

import Data.Drasil.Concepts.Documentation (goal)
import Data.Drasil.Concepts.Math (equation)
Expand All @@ -13,8 +14,8 @@ import Data.Drasil.Quantities.Physics (energy, time)

import Drasil.SWHS.Concepts (water)
import Drasil.SWHS.DataDefs (ddHtFluxC, balanceDecayRate)
import Drasil.SWHS.IMods (eBalanceOnWtrDerivDesc1, eBalanceOnWtrDerivDesc3,
heatEInWtr)
import Drasil.SWHS.IMods (eBalanceOnWtrDerivDesc1, eBalanceOnWtrDerivDesc2,
eBalanceOnWtrDerivDesc3, heatEInWtr)
import Drasil.SWHS.References (koothoor2013)
import Drasil.SWHS.Unitals (tempW, tempC, tauW, wMass, htCapW, coilHTC,
coilSA, tempInit, timeFinal, htFluxC)
Expand All @@ -32,32 +33,29 @@ iMods = [eBalanceOnWtr, heatEInWtr]
eBalanceOnWtr :: InstanceModel
eBalanceOnWtr = im eBalanceOnWtrRC [qw tempC, qw tempInit, qw timeFinal,
qw coilSA, qw coilHTC, qw htCapW, qw wMass]
[sy tempInit $<= sy tempC] (qw tempW)
[sy tempInit $<= sy tempC] (qw tempW) [0 $< sy time $< sy timeFinal]
--Tw(0) cannot be presented, there is one more constraint Tw(0) = Tinit
[0 $< sy time $< sy timeFinal] [makeCiteInfo koothoor2013 $ RefNote "with PCM removed"]
(Just eBalanceOnWtrDeriv) "eBalanceOnWtr" [balWtrDesc]
[makeCiteInfo koothoor2013 $ RefNote "with PCM removed"]
(Just eBalanceOnWtrDeriv) "eBalanceOnWtr" balWtrNotes

eBalanceOnWtrRC :: RelationConcept
eBalanceOnWtrRC = makeRC "eBalanceOnWtrRC" (nounPhraseSP $ "Energy balance on " ++
"water to find the temperature of the water") balWtrDesc balWtrRel
"water to find the temperature of the water") (tempW ^. defn) balWtrRel
-- (mkLabelSame "eBalnaceOnWtr" (Def Instance))

balWtrRel :: Relation
balWtrRel = deriv (sy tempW) time $= 1 / sy tauW *
(sy tempC - apply1 tempW time)

balWtrDesc :: Sentence
balWtrDesc = foldlSent [(E $ sy tempW) `isThe` phrase tempW +:+.
sParen (unwrap $ getUnit tempW),
(E $ sy tempC) `isThe` phrase tempC +:+. sParen (unwrap $ getUnit tempC),
ch tauW, S "is from" +:+. makeRef2S balanceDecayRate,
S "The above", phrase equation, S "applies as long as the", phrase water,
S "is in", phrase liquid, S "form" `sC` (E $ 0 $< sy tempW $< 100),
sParen (unwrap $ getUnit tempW), S "where", E 0,
sParen (unwrap $ getUnit tempW) `sAnd` E 100,
sParen (unwrap $ getUnit tempW), S "are the", phrase melting `sAnd`
plural boilPt, S "of", phrase water `sC` S "respectively"
+:+ sParen (makeRef2S assumpWAL)]
balWtrNotes :: [Sentence]
balWtrNotes = map foldlSent [
[ch tauW `sIs` S "calculated from", makeRef2S balanceDecayRate],
[S "The above", phrase equation, S "applies as long as the", phrase water,
S "is in", phrase liquid, S "form" `sC` E (0 $< sy tempW $< 100),
sParen (unwrap $ getUnit tempW), S "where", E 0,
sParen (unwrap $ getUnit tempW) `sAnd` E 100,
sParen (unwrap $ getUnit tempW), S "are the", phrase melting `sAnd`
plural boilPt `sOf` phrase water `sC` S "respectively", sParen (makeRef2S assumpWAL)]]

----------------------------------------------
-- Derivation of eBalanceOnWtr --
Expand All @@ -67,17 +65,11 @@ eBalanceOnWtrDeriv = mkDerivName (S "the" +:+ phrase energy +:+ S "balance on wa
(weave [eBalanceOnWtrDerivSentences, map E eBalanceOnWtrDerivEqns])

eBalanceOnWtrDerivSentences :: [Sentence]
eBalanceOnWtrDerivSentences = map foldlSentCol [
eBalanceOnWtrDerivDesc1 EmptyS (S "over area" +:+ (E $ sy coilSA)) EmptyS assumpNIHGBW,
eBalanceOnWtrDerivDesc2 ddHtFluxC,
eBalanceOnWtrDerivDesc3, eBalanceOnWtrDerivDesc4]
eBalanceOnWtrDerivSentences = [eBalanceOnWtrDerivDesc1 EmptyS (S "over area" +:+ ch coilSA) EmptyS assumpNIHGBW,
eBalanceOnWtrDerivDesc2 [ddHtFluxC], eBalanceOnWtrDerivDesc3, eBalanceOnWtrDerivDesc4]

eBalanceOnWtrDerivDesc2 :: DataDefinition -> [Sentence]
eBalanceOnWtrDerivDesc2 dd = [S "Using", makeRef2S dd, S "for", ch dd `sC`
S "this can be written as"]

eBalanceOnWtrDerivDesc4 :: [Sentence]
eBalanceOnWtrDerivDesc4 = [substitute [balanceDecayRate]]
eBalanceOnWtrDerivDesc4 :: Sentence
eBalanceOnWtrDerivDesc4 = substitute [balanceDecayRate]

eBalanceOnWtrDerivEqn1, eBalanceOnWtrDerivEqn2, eBalanceOnWtrDerivEqn3, eBalanceOnWtrDerivEqn4 :: Expr

Expand Down Expand Up @@ -105,4 +97,3 @@ instModIntro :: Sentence
instModIntro = foldlSent [S "The", phrase goal, makeRef2S waterTempGS,
S "is met by", makeRef2S eBalanceOnWtr `andThe` phrase goal,
makeRef2S waterEnergyGS, S "is met by", makeRef2S heatEInWtr]

2 changes: 1 addition & 1 deletion code/drasil-example/Drasil/SWHS/GenDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ rocTempDerivDens = [S "Using the fact that", ch density :+: S "=" :+: ch mass :+
rocTempDerivIntegEq, rocTempDerivGaussEq, rocTempDerivArbVolEq,
rocTempDerivConsFlxEq, rocTempDerivDensEq :: Expr

rocTempDerivIntegEq = negate (intAll (eqSymb vol) (sy gradient $. sy thFluxVect)) +
rocTempDerivIntegEq = negate (intAll (eqSymb vol) (sy gradient $. sy thFluxVect)) +
intAll (eqSymb vol) (sy volHtGen) $=
intAll (eqSymb vol) (sy density
* sy QT.heatCapSpec * pderiv (sy QT.temp) time)
Expand Down
Loading

0 comments on commit 1c0b0d1

Please sign in to comment.