Skip to content

Commit

Permalink
Merge pull request #1822 from JacquesCarette/swhsNewtonsLawOfCooling
Browse files Browse the repository at this point in the history
[SWHS] Fixed Newton's Law of Cooling
  • Loading branch information
smiths authored Aug 14, 2019
2 parents 1e3e4a6 + e4bb4f5 commit a74c2fc
Show file tree
Hide file tree
Showing 13 changed files with 490 additions and 498 deletions.
8 changes: 4 additions & 4 deletions code/drasil-example/Drasil/NoPCM/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import Drasil.SWHS.Body (charsOfReader, dataContMid, introEnd, introStart,
import Drasil.SWHS.Changes (likeChgTCVOD, likeChgTCVOL, likeChgTLH)
import Drasil.SWHS.Concepts (acronyms, coil, progName, sWHT, tank, transient, water, con)
import Drasil.SWHS.Requirements (nfRequirements)
import Drasil.SWHS.TMods (consThermE, sensHtETemplate, PhaseChange(Liquid))
import Drasil.SWHS.TMods (PhaseChange(Liquid), consThermE, nwtnCooling, sensHtETemplate)
import Drasil.SWHS.Unitals (coilSAMax, deltaT, eta, htFluxC, htFluxIn,
htFluxOut, htCapL, htTransCoeff, inSA, outSA, tankVol, tau, tauW, tempEnv,
tempW, thFluxVect, volHtGen, watE, wMass, wVol, unitalChuncks, absTol, relTol)
Expand Down Expand Up @@ -202,7 +202,7 @@ symbMap = cdb symbolsAll (map nw symbols ++ map nw acronyms ++ map nw thermocon
++ map nw physicalcon ++ map nw unitalChuncks ++ [nw srsSWHS, nw algorithm, nw htTrans]
++ map nw [absTol, relTol] ++ [nw materialProprty])
(map cw symbols ++ srsDomains) units NoPCM.dataDefs NoPCM.iMods genDefs
theoreticalModels concIns section labCon
tMods concIns section labCon

usedDB :: ChunkDB
usedDB = cdb ([] :: [QuantityDict]) (map nw symbols ++ map nw acronyms)
Expand Down Expand Up @@ -297,8 +297,8 @@ goalInputs = [phrase temp `ofThe` phrase coil,
--Section 4.2 : SOLUTION CHARACTERISTICS SPECIFICATION
------------------------------------------------------

theoreticalModels :: [TheoryModel]
theoreticalModels = [consThermE, sensHtE]
tMods :: [TheoryModel]
tMods = [consThermE, sensHtE, nwtnCooling]

sensHtE :: TheoryModel
sensHtE = sensHtETemplate Liquid sensHtEdesc
Expand Down
6 changes: 3 additions & 3 deletions code/drasil-example/Drasil/NoPCM/DataDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module Drasil.NoPCM.DataDefs where --exports all of it
import Language.Drasil
import Theory.Drasil (DataDefinition)

import Drasil.SWHS.DataDefs (ddHtFluxC, ddHtFluxCQD, balanceDecayRate, balanceDecayRateQD)
import Drasil.SWHS.DataDefs (balanceDecayRate, balanceDecayRateQD)

qDefs :: [QDefinition]
qDefs = [ddHtFluxCQD, balanceDecayRateQD]
qDefs = [balanceDecayRateQD]

dataDefs :: [DataDefinition]
dataDefs = [ddHtFluxC, balanceDecayRate]
dataDefs = [balanceDecayRate]
4 changes: 2 additions & 2 deletions code/drasil-example/Drasil/NoPCM/GenDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Theory.Drasil (GenDefn, gdNoRefs)

import Drasil.NoPCM.Assumptions (assumpDWCoW, assumpSHECoW)
import Drasil.SWHS.Assumptions (assumpCWTAT)
import Drasil.SWHS.GenDefs (nwtnCooling, rocTempSimpRC, rocTempSimpDeriv)
import Drasil.SWHS.GenDefs (htFluxWaterFromCoil, rocTempSimpRC, rocTempSimpDeriv)

genDefs :: [GenDefn]
genDefs = [nwtnCooling, rocTempSimp]
genDefs = [rocTempSimp, htFluxWaterFromCoil]

rocTempSimp :: GenDefn
rocTempSimp = gdNoRefs rocTempSimpRC (Nothing :: Maybe UnitDefn)
Expand Down
16 changes: 10 additions & 6 deletions code/drasil-example/Drasil/NoPCM/IMods.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import Data.Drasil.Concepts.Thermodynamics (melting, boilPt)
import Data.Drasil.Quantities.Physics (energy, time)

import Drasil.SWHS.Concepts (water)
import Drasil.SWHS.DataDefs (ddHtFluxC, balanceDecayRate)
import Drasil.SWHS.IMods (eBalanceOnWtrDerivDesc1, eBalanceOnWtrDerivDesc2,
eBalanceOnWtrDerivDesc3, heatEInWtr)
import Drasil.SWHS.DataDefs (balanceDecayRate)
import Drasil.SWHS.GenDefs (htFluxWaterFromCoil)
import Drasil.SWHS.IMods (eBalanceOnWtrDerivDesc1, eBalanceOnWtrDerivDesc3, heatEInWtr)
import Drasil.SWHS.References (koothoor2013)
import Drasil.SWHS.Unitals (tempW, tempC, tauW, wMass, htCapW, coilHTC,
coilSA, tempInit, timeFinal, htFluxC)
import Drasil.SWHS.Unitals (coilHTC, coilSA, htCapW, htFluxC, tauW, tempC,
tempInit, tempW, timeFinal, wMass)

import Drasil.NoPCM.Assumptions (assumpNIHGBW, assumpWAL)
import Drasil.NoPCM.Goals (waterTempGS, waterEnergyGS)
Expand Down Expand Up @@ -66,7 +66,11 @@ eBalanceOnWtrDeriv = mkDerivName (S "the" +:+ phrase energy +:+ S "balance on wa

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

eBalanceOnWtrDerivDesc2 :: Sentence
eBalanceOnWtrDerivDesc2 = foldlSentCol [S "Using", makeRef2S htFluxWaterFromCoil, S "for",
ch htFluxC `sC` S "this can be written as"]

eBalanceOnWtrDerivDesc4 :: Sentence
eBalanceOnWtrDerivDesc4 = substitute [balanceDecayRate]
Expand Down
23 changes: 10 additions & 13 deletions code/drasil-example/Drasil/SWHS/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Database.Drasil (Block, ChunkDB, ReferenceDB,
SystemInformation(SI), cdb, rdb, refdb, _authors, _concepts, _constants,
_constraints, _datadefs, _definitions, _defSequence, _inputs, _kind, _outputs,
_quants, _sys, _sysinfodb, _usedinfodb)
import Theory.Drasil (DataDefinition, InstanceModel, TheoryModel)
import Theory.Drasil (GenDefn, InstanceModel)
import Utils.Drasil

import Control.Lens ((^.))
Expand Down Expand Up @@ -52,16 +52,16 @@ import Drasil.SWHS.Assumptions (assumpPIS, assumptions)
import Drasil.SWHS.Changes (likelyChgs, unlikelyChgs)
import Drasil.SWHS.Concepts (acronymsFull, coil, con, phaseChangeMaterial,
phsChgMtrl, progName, rightSide, sWHT, swhsPCM, tank, tankPCM, transient, water)
import Drasil.SWHS.DataDefs (ddHtFluxC, ddHtFluxP, qDefs)
import Drasil.SWHS.DataDefs (qDefs)
import qualified Drasil.SWHS.DataDefs as SWHS (dataDefs)
import Drasil.SWHS.GenDefs (genDefs)
import Drasil.SWHS.GenDefs (genDefs, htFluxWaterFromCoil, htFluxPCMFromWater)
import Drasil.SWHS.Goals (goals)
import Drasil.SWHS.IMods (eBalanceOnWtr, eBalanceOnPCM, heatEInWtr, heatEInPCM,
iMods, instModIntro)
import Drasil.SWHS.References (parnas1972, parnasClements1984, citations)
import Drasil.SWHS.Requirements (funcReqs, inputInitQuantsTable, nfRequirements,
verifyEnergyOutput)
import Drasil.SWHS.TMods (consThermE, latentHtE, sensHtE)
import Drasil.SWHS.TMods (tMods)
import Drasil.SWHS.Unitals (absTol, coilHTC, coilSA, consTol, constrained,
htFluxC, htFluxP, inputs, inputConstraints, outputs, pcmE, pcmHTC, pcmSA,
relTol, simTime, specParamValList, symbols, symbolsAll, tempC, tempPCM,
Expand Down Expand Up @@ -111,7 +111,7 @@ symbMap = cdb (qw heatEInPCM : symbolsAll) -- heatEInPCM ?
++ map nw fundamentals ++ map nw educon ++ map nw derived ++ map nw physicalcon ++ map nw unitalChuncks
++ [nw swhsPCM, nw algorithm] ++ map nw compcon ++ [nw materialProprty])
(cw heatEInPCM : map cw symbols ++ srsDomains) -- FIXME: heatEInPCM?
(units ++ [m_2, m_3]) SWHS.dataDefs insModel genDefs theory concIns section labCon
(units ++ [m_2, m_3]) SWHS.dataDefs insModel genDefs tMods concIns section labCon

usedDB :: ChunkDB
usedDB = cdb ([] :: [QuantityDict]) (map nw symbols ++ map nw acronymsFull)
Expand Down Expand Up @@ -170,9 +170,6 @@ tSymbIntro = [TSPurpose, SymbConvention
insModel :: [InstanceModel]
insModel = [eBalanceOnWtr, eBalanceOnPCM, heatEInWtr, heatEInPCM]

theory :: [TheoryModel]
theory = [consThermE, sensHtE, latentHtE]

concIns :: [ConceptInstance]
concIns = goals ++ assumptions ++ likelyChgs ++ unlikelyChgs ++ funcReqs
++ nfRequirements
Expand Down Expand Up @@ -540,22 +537,22 @@ outputConstraints = [tempW, tempPCM, watE, pcmE] --FIXME: add "(by A11)" in Phys
propsDeriv :: [Contents]
propsDeriv = [
propCorSolDeriv1 lawConsEnergy watE energy coil phsChgMtrl
ddHtFluxC ddHtFluxP surface heatTrans,
htFluxWaterFromCoil htFluxPCMFromWater surface heatTrans,
propCorSolDeriv2,
propCorSolDeriv3 pcmE energy phsChgMtrl water,
propCorSolDeriv4,
propCorSolDeriv5 equation progName rightSide]

propCorSolDeriv1 :: (NamedIdea b, NamedIdea h) => ConceptChunk -> b -> UnitalChunk -> ConceptChunk ->
CI -> DataDefinition -> DataDefinition -> h -> ConceptChunk -> Contents
propCorSolDeriv1 lce ewat en co pcmat d1hfc d2hfp su ht =
propCorSolDeriv1 :: (NamedIdea b, NamedIdea h) => ConceptChunk -> b -> UnitalChunk ->
ConceptChunk -> CI -> GenDefn -> GenDefn -> h -> ConceptChunk -> Contents
propCorSolDeriv1 lce ewat en co pcmat g1hfc g2hfp su ht =
foldlSPCol [S "A", phrase corSol, S "must exhibit the" +:+.
phrase lce, S "This means that the", phrase ewat,
S "should equal the difference between the total", phrase en,
phrase input_, S "from the", phrase co `sAnd` S "the",
phrase en, phrase output_, S "to the" +:+. short pcmat,
S "This can be shown as an", phrase equation, S "by taking",
makeRef2S d1hfc `sAnd` makeRef2S d2hfp `sC`
makeRef2S g1hfc `sAnd` makeRef2S g2hfp `sC`
S "multiplying each by their respective", phrase su,
S "area of", phrase ht `sC` S "and integrating each",
S "over the", phrase simTime `sC` S "as follows"]
Expand Down
40 changes: 7 additions & 33 deletions code/drasil-example/Drasil/SWHS/DataDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,30 @@ import Utils.Drasil
import Data.Drasil.Concepts.Documentation (value)
import Data.Drasil.Concepts.Thermodynamics (heat)

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

import Drasil.SWHS.Assumptions (assumpLCCCW, assumpTHCCoT)
import Drasil.SWHS.References (bueche1986, koothoor2013, lightstone2012)
import Drasil.SWHS.Unitals (aspectRatio, coilHTC, coilSA, diam, eta, htCapLP,
htCapSP, htCapW, htFluxC, htFluxP, htFusion, latentEP, meltFrac, pcmHTC,
pcmMass, pcmSA, tankLength, tauLP, tauSP, tauW, tempC, tempPCM, tempW, wMass)
htCapSP, htCapW, htFusion, latentEP, meltFrac, pcmHTC, pcmMass, pcmSA,
tankLength, tauLP, tauSP, tauW, wMass)

refMDB :: ModelDB
refMDB = mdb [] [] dataDefs []

qDefs :: [QDefinition]
qDefs = [ddHtFluxCQD, ddHtFluxPQD, balanceDecayRateQD, balanceDecayTimeQD,
balanceSolidPCMQD, balanceLiquidPCMQD, ddHtFusionQD, ddMeltFracQD, aspRatQD]
qDefs = [balanceDecayRateQD, balanceDecayTimeQD, balanceSolidPCMQD,
balanceLiquidPCMQD, ddHtFusionQD, ddMeltFracQD, aspRatQD]

dataDefs :: [DataDefinition]
dataDefs = [ddHtFluxC, ddHtFluxP, balanceDecayRate, balanceDecayTime,
balanceSolidPCM, balanceLiquidPCM, ddHtFusion, ddMeltFrac, aspRat]
dataDefs = [balanceDecayRate, balanceDecayTime, balanceSolidPCM,
balanceLiquidPCM, ddHtFusion, ddMeltFrac, 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.

ddHtFluxCQD :: QDefinition
ddHtFluxCQD = mkQuantDef htFluxC htFluxCEqn

htFluxCEqn :: Expr
htFluxCEqn = sy coilHTC * (sy tempC - apply1 tempW time)

ddHtFluxC :: DataDefinition
ddHtFluxC = dd ddHtFluxCQD [makeCite koothoor2013]
Nothing "htFluxC" [makeRef2S assumpLCCCW, makeRef2S assumpTHCCoT]

--Can't include info in description beyond definition of variables?
----

ddHtFluxPQD :: QDefinition
ddHtFluxPQD = mkQuantDef htFluxP htFluxPEqn

htFluxPEqn :: Expr
htFluxPEqn = sy pcmHTC * (apply1 tempW time - apply1 tempPCM time)

ddHtFluxP :: DataDefinition
ddHtFluxP = dd ddHtFluxPQD [makeCite koothoor2013]
Nothing "htFluxP" [makeRef2S assumpLCCCW]

----

balanceDecayRateQD :: QDefinition
balanceDecayRateQD = mkQuantDef tauW balanceDecayRateEqn

Expand Down
105 changes: 57 additions & 48 deletions code/drasil-example/Drasil/SWHS/GenDefs.hs
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
module Drasil.SWHS.GenDefs (genDefs, nwtnCooling, rocTempSimp,
rocTempSimpDeriv, nwtnCoolingDesc, rocTempSimpRC) where

import Prelude hiding (sin, cos, tan)
module Drasil.SWHS.GenDefs (genDefs, htFluxWaterFromCoil, htFluxPCMFromWater,
rocTempSimp, rocTempSimpDeriv, rocTempSimpRC) where

import Language.Drasil
import Theory.Drasil (GenDefn, gd, gdNoRefs)
import Utils.Drasil

import Data.Drasil.Concepts.Math (rate, rOfChng, unit_)
import Control.Lens ((^.))

import Data.Drasil.Concepts.Math (rOfChng, unit_)
import Data.Drasil.Concepts.Thermodynamics (lawConvCooling)

import Data.Drasil.Quantities.Math (uNormalVect, surface, gradient)
import Data.Drasil.Quantities.PhysicalProperties as QPP (vol, mass, density)
import Data.Drasil.Quantities.Physics as QP (time)
import Data.Drasil.Quantities.Thermodynamics as QT (htFlux, heatCapSpec,
temp)

import Data.Drasil.Units.Thermodynamics (thermalFlux)
import Data.Drasil.Quantities.Thermodynamics as QT (heatCapSpec, temp)

import Drasil.SWHS.Assumptions (assumpHTCC, assumpCWTAT, assumpTPCAV,
assumpDWPCoV, assumpSHECoV)
import Drasil.SWHS.Concepts (gaussDiv)
import Drasil.SWHS.References (incroperaEtAl2007)
import Drasil.SWHS.TMods (consThermE)
import Drasil.SWHS.Unitals (deltaT, htFluxIn, htFluxOut, htTransCoeff, inSA,
outSA, tempEnv, thFluxVect, volHtGen)
import Drasil.SWHS.Assumptions (assumpCWTAT, assumpLCCCW, assumpLCCWP,
assumpTPCAV, assumpDWPCoV, assumpSHECoV, assumpTHCCoT)
import Drasil.SWHS.Concepts (coil, gaussDiv, phaseChangeMaterial)
import Drasil.SWHS.References (koothoor2013)
import Drasil.SWHS.TMods (consThermE, nwtnCooling)
import Drasil.SWHS.Unitals (coilHTC, htFluxC, htFluxIn, htFluxOut, htFluxP,
inSA, outSA, pcmHTC, tempC, tempPCM, tempW, thFluxVect, volHtGen)

---------------------------
-- General Definitions --
Expand All @@ -35,49 +32,61 @@ import Drasil.SWHS.Unitals (deltaT, htFluxIn, htFluxOut, htTransCoeff, inSA,
--stabilized yet (since RelationConcept isn't an instance of --
--the Referable class. --
genDefs :: [GenDefn]
genDefs = [nwtnCooling, rocTempSimp]

nwtnCooling, rocTempSimp :: GenDefn
nwtnCooling = gd nwtnCoolingRC (Just thermalFlux) Nothing
[makeCiteInfo incroperaEtAl2007 $ Page [8]] "nwtnCooling" nwtnCoolingDesc
genDefs = [rocTempSimp, htFluxWaterFromCoil, htFluxPCMFromWater]

rocTempSimp :: GenDefn
rocTempSimp = gdNoRefs rocTempSimpRC (Nothing :: Maybe UnitDefn)
(Just $ rocTempSimpDeriv rocTempDerivConsFlxSWHS [assumpCWTAT, assumpTPCAV, assumpDWPCoV, assumpSHECoV])
(Just $ rocTempSimpDeriv rocTempDerivConsFlxSWHS
[assumpCWTAT, assumpTPCAV, assumpDWPCoV, assumpSHECoV])
"rocTempSimp" [{-Notes-}]

--

nwtnCoolingRC :: RelationConcept
nwtnCoolingRC = makeRC "nwtnCooling" (nounPhraseSP "Newton's law of cooling")
EmptyS nwtnCoolingRel -- nwtnCoolingL

nwtnCoolingRel :: Relation
nwtnCoolingRel = apply1 htFlux QP.time $= sy htTransCoeff *
apply1 deltaT QP.time

nwtnCoolingDesc :: [Sentence]
nwtnCoolingDesc = map foldlSent [
[atStart lawConvCooling +:+. S "describes convective cooling from a surface" +:
S "The law is stated as", S "the", phrase rate `sOf` S "heat loss from a body" `sIs`
S "proportional to the difference in", plural temp, S "between the body and its surroundings"],
[ch htTransCoeff, S "is assumed to be independent" `sOf` ch QT.temp,
sParen (S "from" +:+ makeRef2S assumpHTCC)],
[E (apply1 deltaT QP.time $= apply1 temp QP.time - apply1 tempEnv QP.time) `isThe`
S "time-dependant thermal gradient between the environment and the object"]]

--
rocTempSimpRC :: RelationConcept
rocTempSimpRC = makeRC "rocTempSimp" (nounPhraseSP $ "Simplified rate " ++
"of change of temperature") EmptyS rocTempSimpRel -- rocTempSimpL
rocTempSimpRC = makeRC "rocTempSimpRC" (nounPhraseSP $ "Simplified rate " ++
"of change of temperature") EmptyS rocTempSimpRel

rocTempSimpRel :: Relation
rocTempSimpRel = sy QPP.mass * sy QT.heatCapSpec *
deriv (sy QT.temp) QP.time $= sy htFluxIn * sy inSA -
sy htFluxOut * sy outSA + sy volHtGen * sy QPP.vol

---------------------------------------
-- General Definitions Derivation --
---------------------------------------
----

htFluxWaterFromCoil :: GenDefn
htFluxWaterFromCoil = gd htFluxWaterFromCoilRC (getUnit htFluxC) Nothing
[makeCite koothoor2013] "htFluxWaterFromCoil"
[newtonLawNote htFluxC assumpLCCCW coil, makeRef2S assumpTHCCoT]

htFluxWaterFromCoilRC :: RelationConcept
htFluxWaterFromCoilRC = makeRC "htFluxWaterFromCoilRC" (htFluxC ^. term)
EmptyS htFluxWaterFromCoilRel

htFluxWaterFromCoilRel :: Relation
htFluxWaterFromCoilRel = sy htFluxC $= sy coilHTC * (sy tempC - apply1 tempW time)

--Can't include info in description beyond definition of variables?
----

htFluxPCMFromWater :: GenDefn
htFluxPCMFromWater = gd htFluxPCMFromWaterRC (getUnit htFluxP) Nothing
[makeCite koothoor2013] "htFluxPCMFromWater"
[newtonLawNote htFluxP assumpLCCWP phaseChangeMaterial]

htFluxPCMFromWaterRC :: RelationConcept
htFluxPCMFromWaterRC = makeRC "htFluxPCMFromWaterRC" (htFluxP ^. term)
EmptyS htFluxPCMFromWaterRel

htFluxPCMFromWaterRel :: Relation
htFluxPCMFromWaterRel = sy htFluxP $= sy pcmHTC * (apply1 tempW time - apply1 tempPCM time)

newtonLawNote :: UnitalChunk -> ConceptInstance -> ConceptChunk -> Sentence
newtonLawNote u a c = foldlSent [ch u `sIs` S "found by assuming that",
phrase lawConvCooling, S "applies" +:+. sParen (makeRef2S a), S "This law",
sParen (S "defined" `sIn` makeRef2S nwtnCooling) `sIs` S "used on",
phrase surface `ofThe` phrase c]

--------------------------------------
-- General Definitions Derivation --
--------------------------------------

rocTempSimpDeriv :: Sentence -> [ConceptInstance] -> Derivation
rocTempSimpDeriv s a = mkDerivName (S "simplified" +:+ phrase rOfChng `sOf` phrase temp)
Expand Down
Loading

0 comments on commit a74c2fc

Please sign in to comment.