diff --git a/code/drasil-code/lib/Language/Drasil/Chunk/CodeDefinition.hs b/code/drasil-code/lib/Language/Drasil/Chunk/CodeDefinition.hs index cd01a25abb1..3fcb27bf2bd 100644 --- a/code/drasil-code/lib/Language/Drasil/Chunk/CodeDefinition.hs +++ b/code/drasil-code/lib/Language/Drasil/Chunk/CodeDefinition.hs @@ -1,6 +1,7 @@ {-# LANGUAGE TemplateHaskell #-} module Language.Drasil.Chunk.CodeDefinition ( - CodeDefinition, DefinitionType(..), qtoc, qtov, odeDef, auxExprs, defType, + CodeDefinition, DefinitionType(..), qtoc, qtov, + odeDef, auxExprs, defType, ) where import Drasil.Code.CodeExpr.Development (expr, CanGenCode(..)) @@ -54,12 +55,12 @@ instance DefiningCodeExpr CodeDefinition where codeExpr = def -- It _might_ be good to create make a ``CanGenCodeDefinition''-like typeclass -- | Constructs a 'CodeDefinition' where the underlying 'CodeChunk' is for a function. -qtoc :: (Quantity (q Expr), MayHaveUnit (q Expr), DefiningExpr q) => q Expr -> CodeDefinition -qtoc q = CD (codeChunk $ quantfunc q) (expr $ q ^. defnExpr) [] Definition +qtoc :: (DefinesQuantity (q Expr), DefiningExpr q) => q Expr -> CodeDefinition +qtoc q = CD (codeChunk $ quantfunc $ q ^. defLhs) (expr $ q ^. defnExpr) [] Definition -- | Constructs a 'CodeDefinition' where the underlying 'CodeChunk' is for a variable. qtov :: CanGenCode e => QDefinition e -> CodeDefinition -qtov q = CD (codeChunk $ quantvar q) (toCodeExpr $ q ^. defnExpr) [] Definition +qtov q = CD (codeChunk $ quantvar $ q ^. defLhs) (toCodeExpr $ q ^. defnExpr) [] Definition -- | Constructs a 'CodeDefinition' for an ODE. odeDef :: ODEInfo -> CodeDefinition diff --git a/code/drasil-code/lib/Language/Drasil/CodeSpec.hs b/code/drasil-code/lib/Language/Drasil/CodeSpec.hs index 5912bbeecaa..2483450dcbc 100644 --- a/code/drasil-code/lib/Language/Drasil/CodeSpec.hs +++ b/code/drasil-code/lib/Language/Drasil/CodeSpec.hs @@ -13,8 +13,8 @@ import System.Drasil (HasSystem(..)) import Theory.Drasil (DataDefinition, qdEFromDD, getEqModQdsFromIm) import Language.Drasil.Chunk.ConstraintMap (ConstraintCEMap, ConstraintCE, constraintMap) -import Language.Drasil.Chunk.CodeDefinition (CodeDefinition, qtov, qtoc, odeDef, - auxExprs) +import Language.Drasil.Chunk.CodeDefinition (CodeDefinition, qtov, qtoc, + odeDef, auxExprs) import Language.Drasil.Choices (Choices(..), Maps(..), ODE(..), ExtLib(..)) import Language.Drasil.Chunk.CodeBase import Language.Drasil.Mod (Func(..), FuncData(..), FuncDef(..), Mod(..), Name) @@ -199,7 +199,7 @@ oldcodeSpec SI.SI{ SI._sys = sys -- directly from the instance models (ims) instead of directly from the choices. outs' = map quantvar outs allInputs = nub $ inputs' ++ map quantvar derived - exOrder = getExecOrder rels (allInputs ++ map quantvar cnsts) outs' db + exOrder = getExecOrder rels (allInputs ++ map (quantvar . (^. defLhs)) cnsts) outs' db in OldCodeSpec { _pName = n, _authors = as, diff --git a/code/drasil-docLang/lib/Drasil/DocumentLanguage.hs b/code/drasil-docLang/lib/Drasil/DocumentLanguage.hs index 2ec471e1a48..03719ff1033 100644 --- a/code/drasil-docLang/lib/Drasil/DocumentLanguage.hs +++ b/code/drasil-docLang/lib/Drasil/DocumentLanguage.hs @@ -412,7 +412,7 @@ mkOffShelfSolnSec (OffShelfSolnsProg cs) = SRS.offShelfSol cs [] -- | Helper for making the Values of Auxiliary Constants section. mkAuxConsSec :: AuxConstntSec -> Section -mkAuxConsSec (AuxConsProg key listOfCons) = AC.valsOfAuxConstantsF key $ sortBySymbol listOfCons +mkAuxConsSec (AuxConsProg key listOfCons) = AC.valsOfAuxConstantsF key $ sortByLhsSymbol listOfCons -- ** References diff --git a/code/drasil-docLang/lib/Drasil/Sections/AuxiliaryConstants.hs b/code/drasil-docLang/lib/Drasil/Sections/AuxiliaryConstants.hs index 788ecfa3943..c1e15e66444 100644 --- a/code/drasil-docLang/lib/Drasil/Sections/AuxiliaryConstants.hs +++ b/code/drasil-docLang/lib/Drasil/Sections/AuxiliaryConstants.hs @@ -29,7 +29,7 @@ intro kWord = foldlSP [S "This section contains the standard values that are use tableOfConstants :: [ConstQDef] -> LabelledContent tableOfConstants f = llcc tableOfConstantsRef $ Table [titleize symbol_, titleize description, titleize value, titleize CM.unit_] - (mkTable [ch, phrase, \c -> eS $ express $ c ^. defnExpr, toSentence] f) + (mkTable [ch . (^. defLhs), phrase, \c -> eS $ express $ c ^. defnExpr, toSentence] f) (titleize' tAuxConsts) True diff --git a/code/drasil-example/dblpend/lib/Drasil/DblPend/Unitals.hs b/code/drasil-example/dblpend/lib/Drasil/DblPend/Unitals.hs index 4af35ff9fbb..1f6b5f92d2d 100644 --- a/code/drasil-example/dblpend/lib/Drasil/DblPend/Unitals.hs +++ b/code/drasil-example/dblpend/lib/Drasil/DblPend/Unitals.hs @@ -1,5 +1,7 @@ module Drasil.DblPend.Unitals where +import Control.Lens ((^.)) + import Language.Drasil import Language.Drasil.Display (Symbol(..)) import Language.Drasil.ShortHands @@ -23,7 +25,7 @@ import Data.Drasil.Quantities.Physics (gravitationalAccelConst) symbols:: [QuantityDict] -symbols = map qw unitalChunks ++ map qw unitless ++ [qw pendDisAngle] ++ map qw constants +symbols = map qw unitalChunks ++ map qw unitless ++ [qw pendDisAngle] ++ map (^. defLhs) constants acronyms :: [CI] acronyms = [twoD, assumption, dataDefn, genDefn, goalStmt, inModel, diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Assumptions.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Assumptions.hs index 29f0fe91962..d31d5e29bdb 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Assumptions.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Assumptions.hs @@ -2,6 +2,8 @@ module Drasil.GlassBR.Assumptions (assumpGT, assumpGC, assumpES, assumpSV, assumpGL, assumpBC, assumpRT, assumpLDFC, assumptionConstants, assumptions) where +import Control.Lens ((^.)) + import Language.Drasil hiding (organization) import qualified Drasil.DocLang.SRS as SRS (valsOfAuxCons) import Language.Drasil.Chunk.Concept.NamedCombinators @@ -67,7 +69,7 @@ standardValuesDesc :: UnitaryChunk -> Sentence standardValuesDesc mainIdea = foldlSent [atStartNP' (the value), S "provided in", refS $ SRS.valsOfAuxCons ([]::[Contents]) ([]::[Section]), S "are assumed for the", phrase mainIdea, sParen (ch mainIdea) `sC` S "and the", plural materialProprty `S.of_` - foldlList Comma List (map ch (take 3 assumptionConstants))] + foldlList Comma List (map (ch . (^. defLhs)) (take 3 assumptionConstants))] glassLiteDesc :: Sentence glassLiteDesc = foldlSent [atStart glass, S "under consideration is assumed to be a single", diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Changes.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Changes.hs index ca1347fffd5..61e621d580d 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Changes.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Changes.hs @@ -2,6 +2,8 @@ module Drasil.GlassBR.Changes (likelyChgs, unlikelyChgs) where --A list of likely and unlikely changes for GlassBR +import Control.Lens ((^.)) + import Language.Drasil hiding (variable) import Language.Drasil.Chunk.Concept.NamedCombinators @@ -39,7 +41,7 @@ calcInternalBlastRiskDesc mainConcept = foldlSent [chgsStart assumpES (S "The"), S "can be added for the internal", phrase mainConcept] varValsOfmkEDesc = foldlSent [refS assumpSV `sC` chgsStart assumpLDFC (S "Currently, the"), - plural value, S "for", foldlList Comma List (map ch (take 3 assumptionConstants)), + plural value, S "for", foldlList Comma List (map (ch . (^. defLhs)) (take 3 assumptionConstants)), S "are assumed to be the same for all" +:+. phrase glass, S "In the future, these", plural value, S "can be changed to", pluralNP (combineNINI variable input_)] diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs index e5979283633..c2b4e58c61a 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/IMods.hs @@ -59,7 +59,7 @@ riskQD = mkQuantDef riskFun ((sy sflawParamK $/ strDisFac :: InstanceModel strDisFac = imNoDeriv (equationalModelN (stressDistFac ^. term) strDisFacQD) (qwC aspectRatio aspectRatioConstraint : [qwUC dimlessLoad]) (qw stressDistFac) - [Bounded (Inc, sy stressDistFacMin) (Inc, sy stressDistFacMax)] + [Bounded (Inc, sy $ stressDistFacMin ^. defLhs) (Inc, sy $ stressDistFacMax ^. defLhs)] [dRef astm2009] "stressDistFac" [interpolating stressDistFac dimlessloadVsARFig, arRef, qHtRef] diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Requirements.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Requirements.hs index 71ea9978067..33b9df58fb4 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Requirements.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Requirements.hs @@ -60,7 +60,7 @@ sysSetValsFollowingAssumpsTable = "ReqAssignments" (S "Required Assignments") where - r2AQs = qw loadSF : map qw (take 4 assumptionConstants) + r2AQs = qw loadSF : map (qw . (^. defLhs)) (take 4 assumptionConstants) r2ARs = assumpGL : replicate 4 assumpSV r2DDs = [loadDF, hFromt, glaTyFac, standOffDis, aspRat] diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Symbols.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Symbols.hs index 8d918702074..2dd8ec9a529 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Symbols.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Symbols.hs @@ -1,6 +1,8 @@ module Drasil.GlassBR.Symbols where -import Language.Drasil (QuantityDict, qw, cnstrw) +import Control.Lens ((^.)) + +import Language.Drasil (QuantityDict, qw, cnstrw, DefinesQuantity(defLhs)) import Language.Drasil.Code (Mod(Mod), asVC) import Drasil.GlassBR.ModuleDefs (allMods, implVars) @@ -17,7 +19,7 @@ symbolsForSymbolTable = symbolsForTermTable ++ map qw symbols ++ symbolsForTermTable :: [QuantityDict] symbolsForTermTable = map qw inputsWUnitsUncrtn ++ map qw inputsWUncrtn ++ - map qw sdVector ++ tmSymbols ++ map qw specParamVals ++ + map qw sdVector ++ tmSymbols ++ map (^. defLhs) specParamVals ++ map qw symbolsWithDefns ++ interps -- include all module functions as symbols diff --git a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Unitals.hs b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Unitals.hs index c86f3a36d2d..7d1f8c9cfdd 100644 --- a/code/drasil-example/glassbr/lib/Drasil/GlassBR/Unitals.hs +++ b/code/drasil-example/glassbr/lib/Drasil/GlassBR/Unitals.hs @@ -1,5 +1,7 @@ module Drasil.GlassBR.Unitals where --whole file is used +import Control.Lens ((^.)) + import Language.Drasil import Language.Drasil.Display (Symbol(..)) import Language.Drasil.ShortHands @@ -82,16 +84,16 @@ plateLen = uqcND "plateLen" (nounPhraseSP "plate length (long dimension)") lA metre Real [ gtZeroConstr, physRange $ UpFrom (Inc, sy plateWidth), - sfwrRange $ Bounded (Inc , sy dimMin) (Inc , sy dimMax)] (dbl 1.5) defaultUncrt + sfwrRange $ Bounded (Inc , sy $ dimMin ^. defLhs) (Inc , sy $ dimMax ^. defLhs)] (dbl 1.5) defaultUncrt plateWidth = uqcND "plateWidth" (nounPhraseSP "plate width (short dimension)") lB metre Real [ physRange $ Bounded (Exc, exactDbl 0) (Inc, sy plateLen), - sfwrRange $ Bounded (Inc, sy dimMin) (Inc, sy dimMax)] (dbl 1.2) defaultUncrt + sfwrRange $ Bounded (Inc, sy $ dimMin ^. defLhs) (Inc, sy $ dimMax ^. defLhs)] (dbl 1.2) defaultUncrt aspectRatio = uq (constrained' (dqdNoUnit aspectRatioCon (variable "AR") Real) [ physRange $ UpFrom (Inc, exactDbl 1), - sfwrRange $ UpTo (Inc, sy arMax)] (dbl 1.5)) defaultUncrt + sfwrRange $ UpTo (Inc, sy $ arMax ^. defLhs)] (dbl 1.5)) defaultUncrt pbTol = uvc "pbTol" (nounPhraseSP "tolerable probability of breakage") (sub cP (Concat [lBreak, lTol])) Real @@ -100,7 +102,7 @@ pbTol = uvc "pbTol" (nounPhraseSP "tolerable probability of breakage") charWeight = uqcND "charWeight" (nounPhraseSP "charge weight") lW kilogram Real [ gtZeroConstr, - sfwrRange $ Bounded (Inc, sy cWeightMin) (Inc, sy cWeightMax)] + sfwrRange $ Bounded (Inc, sy $ cWeightMin ^. defLhs) (Inc, sy $ cWeightMax ^. defLhs)] (exactDbl 42) defaultUncrt tNT = uvc "tNT" (nounPhraseSP "TNT equivalent factor") @@ -109,7 +111,7 @@ tNT = uvc "tNT" (nounPhraseSP "TNT equivalent factor") standOffDist = uq (constrained' (uc sD (variable "SD") Real metre) [ gtZeroConstr, - sfwrRange $ Bounded (Inc, sy sdMin) (Inc, sy sdMax)] (exactDbl 45)) defaultUncrt + sfwrRange $ Bounded (Inc, sy $ sdMin ^. defLhs) (Inc, sy $ sdMax ^. defLhs)] (exactDbl 45)) defaultUncrt nomThick = cuc "nomThick" (nounPhraseSent $ S "nominal thickness t is in" +:+ eS (mkSet Rational (map dbl nominalThicknesses))) @@ -133,7 +135,7 @@ probBr = cvc "probBr" (nounPhraseSP "probability of breakage") [probConstr] (Just $ dbl 0.4) stressDistFac = cvc "stressDistFac" (nounPhraseSP "stress distribution factor (Function)") - cJ Real [physRange $ Bounded (Inc, sy stressDistFacMin) (Inc, sy stressDistFacMax)] (Just $ exactDbl 15) + cJ Real [physRange $ Bounded (Inc, sy $ stressDistFacMin ^. defLhs) (Inc, sy $ stressDistFacMax ^. defLhs)] (Just $ exactDbl 15) probFail = cvc "probFail" (nounPhraseSP "probability of failure") (sub cP lFail) Real diff --git a/code/drasil-example/hghc/lib/Drasil/HGHC/HeatTransfer.hs b/code/drasil-example/hghc/lib/Drasil/HGHC/HeatTransfer.hs index 5b518446c60..f8086343973 100644 --- a/code/drasil-example/hghc/lib/Drasil/HGHC/HeatTransfer.hs +++ b/code/drasil-example/hghc/lib/Drasil/HGHC/HeatTransfer.hs @@ -1,5 +1,7 @@ module Drasil.HGHC.HeatTransfer where --whole file is used +import Control.Lens ((^.)) + import Language.Drasil import Language.Drasil.ShortHands import Theory.Drasil (DataDefinition, ddENoRefs) @@ -22,7 +24,7 @@ htVars = [cladThick, coolFilmCond, gapFilmCond, cladCond] htInputs, htOutputs :: [QuantityDict] htInputs = map qw htVars -htOutputs = map qw qDefs +htOutputs = map (^. defLhs) qDefs cladThick, coolFilmCond, gapFilmCond, cladCond :: QuantityDict cladThick = vc "cladThick" (cn''' "clad thickness") diff --git a/code/drasil-example/pdcontroller/lib/Drasil/PDController/Body.hs b/code/drasil-example/pdcontroller/lib/Drasil/PDController/Body.hs index 2ce5db7f719..dda18c7b9c3 100644 --- a/code/drasil-example/pdcontroller/lib/Drasil/PDController/Body.hs +++ b/code/drasil-example/pdcontroller/lib/Drasil/PDController/Body.hs @@ -1,5 +1,7 @@ module Drasil.PDController.Body (pidODEInfo, printSetting, si, srs, fullSI) where +import Control.Lens ((^.)) + import Language.Drasil import Drasil.SRSDocument import qualified Drasil.DocLang.SRS as SRS (inModel) @@ -132,7 +134,7 @@ background = foldlSent_ [S "Automatic process control with a controller (P/PI/PD S "cruise-control, etc"] symbolsAll :: [QuantityDict] -symbolsAll = symbols ++ map qw pidDqdConstants ++ map qw pidConstants +symbolsAll = symbols ++ map qw pidDqdConstants ++ map (^. defLhs) pidConstants ++ scipyODESymbols ++ osloSymbols ++ apacheODESymbols ++ odeintSymbols ++ map qw [listToArray $ quantvar opProcessVariable, arrayVecDepVar pidODEInfo] diff --git a/code/drasil-example/pdcontroller/lib/Drasil/PDController/ODEs.hs b/code/drasil-example/pdcontroller/lib/Drasil/PDController/ODEs.hs index 82f7f3d255e..edcbb3f697f 100644 --- a/code/drasil-example/pdcontroller/lib/Drasil/PDController/ODEs.hs +++ b/code/drasil-example/pdcontroller/lib/Drasil/PDController/ODEs.hs @@ -5,13 +5,13 @@ import Language.Drasil.Code (odeInfo', odeOptions, quantvar, ODEInfo, ODEMethod(RK45), ODEOptions) import Drasil.PDController.Unitals (qdSetPointTD, qdPropGain, qdDerivGain, - qdSimTime, qdStepTime, odeRelTolConst, odeAbsTolConst) + qdSimTime, qdStepTime, dqdAbsTol, dqdRelTol) import Drasil.PDController.IModel(imPDRC) pidODEOptions :: ODEOptions pidODEOptions = odeOptions - RK45 (sy odeAbsTolConst) (sy odeRelTolConst) (sy qdStepTime) + RK45 (sy dqdAbsTol) (sy dqdRelTol) (sy qdStepTime) pdIVP :: InitialValueProblem pdIVP = makeAIVP (exactDbl 0) (sy qdSimTime) [exactDbl 0, exactDbl 0] diff --git a/code/drasil-example/projectile/lib/Drasil/Projectile/Body.hs b/code/drasil-example/projectile/lib/Drasil/Projectile/Body.hs index 4a5c2053a34..db4789a8245 100644 --- a/code/drasil-example/projectile/lib/Drasil/Projectile/Body.hs +++ b/code/drasil-example/projectile/lib/Drasil/Projectile/Body.hs @@ -1,5 +1,7 @@ module Drasil.Projectile.Body (printSetting, si, srs, fullSI) where +import Control.Lens ((^.)) + import Language.Drasil import Drasil.SRSDocument import Language.Drasil.Chunk.Concept.NamedCombinators @@ -25,7 +27,7 @@ import Data.Drasil.Quantities.Math (pi_, piConst) import Data.Drasil.Quantities.Physics (acceleration, constAccel, gravitationalAccelConst, iPos, iSpeed, iVel, ixPos, iyPos, ixVel, iyVel, position, scalarPos, time, velocity, xAccel, xConstAccel, xPos, - xVel, yAccel, yConstAccel, yPos, yVel, speed, scalarAccel, constAccelV) + xVel, yAccel, yConstAccel, yPos, yVel, speed, scalarAccel, constAccelV, gravitationalMagnitude) import Data.Drasil.People (brooks, samCrawford, spencerSmith) import Data.Drasil.SI_Units (siUnits) @@ -292,8 +294,8 @@ physSystParts = map (!.) -- Various gathered data that should be automated -- ---------------------------------------------------- symbols :: [QuantityDict] -symbols = unitalQuants ++ map qw [gravitationalAccelConst, tol] ++ - map qw [acceleration, constAccel, iPos, iSpeed, iVel, ixPos, +symbols = unitalQuants ++ (tol ^. defLhs) : + map qw [gravitationalMagnitude, acceleration, constAccel, iPos, iSpeed, iVel, ixPos, iyPos, ixVel, iyVel, position, scalarPos, projPos, projSpeed, time, velocity, xAccel, xConstAccel, xPos, xVel, yAccel, yConstAccel, yPos, yVel, speed, scalarAccel, constAccelV] diff --git a/code/drasil-example/projectile/lib/Drasil/Projectile/Derivations.hs b/code/drasil-example/projectile/lib/Drasil/Projectile/Derivations.hs index 2012f45a925..a8e96dbeaf4 100644 --- a/code/drasil-example/projectile/lib/Drasil/Projectile/Derivations.hs +++ b/code/drasil-example/projectile/lib/Drasil/Projectile/Derivations.hs @@ -10,7 +10,8 @@ import Prelude hiding (cos, sin) import Language.Drasil (eqSymb, LiteralC(..), ModelExprC(..), ExprC(..), ModelExpr, square, half) import qualified Data.Drasil.Quantities.Physics as QP (iSpeed, constAccel) -import Data.Drasil.Quantities.Physics (gravitationalAccelConst, iPos, ixVel, iyVel, scalarPos, speed, time, xPos, yPos) +import Data.Drasil.Quantities.Physics (gravitationalMagnitude, + iPos, ixVel, iyVel, scalarPos, speed, time, xPos, yPos) import Drasil.Projectile.Unitals (launAngle, launSpeed, landPos, flightDur) @@ -19,10 +20,10 @@ timeDeriv :: [ModelExpr] timeDeriv = [timeDerivEqn1, timeDerivEqn2, timeDerivEqn3, timeDerivEqn4] timeDerivEqn1, timeDerivEqn2, timeDerivEqn3, timeDerivEqn4 :: ModelExpr -timeDerivEqn1 = sy yPos $= (sy iyVel $* sy time) $- half (sy gravitationalAccelConst $* square (sy time)) -timeDerivEqn2 = (sy iyVel $* sy flightDur) $- half (sy gravitationalAccelConst $* square (sy flightDur)) $= exactDbl 0 -timeDerivEqn3 = sy iyVel $- half (sy gravitationalAccelConst $* sy flightDur) $= exactDbl 0 -timeDerivEqn4 = sy flightDur $= exactDbl 2 $* sy iyVel $/ sy gravitationalAccelConst +timeDerivEqn1 = sy yPos $= (sy iyVel $* sy time) $- half (sy gravitationalMagnitude $* square (sy time)) +timeDerivEqn2 = (sy iyVel $* sy flightDur) $- half (sy gravitationalMagnitude $* square (sy flightDur)) $= exactDbl 0 +timeDerivEqn3 = sy iyVel $- half (sy gravitationalMagnitude $* sy flightDur) $= exactDbl 0 +timeDerivEqn4 = sy flightDur $= exactDbl 2 $* sy iyVel $/ sy gravitationalMagnitude -- landPosDeriv :: [ModelExpr] @@ -30,8 +31,8 @@ landPosDeriv = [landPosDerivEqn1, landPosDerivEqn2, landPosDerivEqn3] landPosDerivEqn1, landPosDerivEqn2, landPosDerivEqn3 :: ModelExpr landPosDerivEqn1 = sy xPos $= sy ixVel $* sy time -landPosDerivEqn2 = sy landPos $= sy ixVel $* exactDbl 2 $* sy launSpeed $* sin (sy launAngle) $/ sy gravitationalAccelConst -landPosDerivEqn3 = sy landPos $= sy launSpeed $* cos (sy launAngle) $* exactDbl 2 $* sy launSpeed $* sin (sy launAngle) $/ sy gravitationalAccelConst +landPosDerivEqn2 = sy landPos $= sy ixVel $* exactDbl 2 $* sy launSpeed $* sin (sy launAngle) $/ sy gravitationalMagnitude +landPosDerivEqn3 = sy landPos $= sy launSpeed $* cos (sy launAngle) $* exactDbl 2 $* sy launSpeed $* sin (sy launAngle) $/ sy gravitationalMagnitude -- diff --git a/code/drasil-example/projectile/lib/Drasil/Projectile/Expressions.hs b/code/drasil-example/projectile/lib/Drasil/Projectile/Expressions.hs index 1993b5191e8..9827ab46b3f 100644 --- a/code/drasil-example/projectile/lib/Drasil/Projectile/Expressions.hs +++ b/code/drasil-example/projectile/lib/Drasil/Projectile/Expressions.hs @@ -6,18 +6,20 @@ module Drasil.Projectile.Expressions where import Prelude hiding (cos, sin) +import Control.Lens ((^.)) + import Language.Drasil import qualified Data.Drasil.Quantities.Physics as QP (iSpeed, constAccel, xConstAccel, yConstAccel, ixPos, iyPos) -import Data.Drasil.Quantities.Physics (gravitationalAccel, gravitationalAccelConst, +import Data.Drasil.Quantities.Physics (gravitationalMagnitude, ixVel, iyVel, xPos, yPos, time, iPos, scalarPos, xVel, yVel, xAccel, yAccel, position, velocity, acceleration, constAccelV, speed) import Drasil.Projectile.Unitals (launAngle, launSpeed, targPos, tol, landPos, offset) flightDur', iyPos, yConstAccel, iSpeed :: PExpr -flightDur' = exactDbl 2 $* sy launSpeed $* sin (sy launAngle) $/ sy gravitationalAccelConst +flightDur' = exactDbl 2 $* sy launSpeed $* sin (sy launAngle) $/ sy gravitationalMagnitude iyPos = exactDbl 0 -- launchOrigin -yConstAccel = neg $ sy gravitationalAccelConst -- accelYGravity +yConstAccel = neg $ sy gravitationalMagnitude -- accelYGravity iSpeed = sy launSpeed offset' :: PExpr @@ -25,7 +27,7 @@ offset' = sy landPos $- sy targPos message :: PExpr message = completeCase [case1, case2, case3] - where case1 = (str "The target was hit.", abs_ (sy offset $/ sy targPos) $< sy tol) + where case1 = (str "The target was hit.", abs_ (sy offset $/ sy targPos) $< sy (tol ^. defLhs)) case2 = (str "The projectile fell short.", sy offset $< exactDbl 0) case3 = (str "The projectile went long.", sy offset $> exactDbl 0) @@ -51,7 +53,7 @@ posVecExpr = vec2D -- landPosExpr :: PExpr -landPosExpr = exactDbl 2 $* square (sy launSpeed) $* sin (sy launAngle) $* cos (sy launAngle) $/ sy gravitationalAccelConst +landPosExpr = exactDbl 2 $* square (sy launSpeed) $* sin (sy launAngle) $* cos (sy launAngle) $/ sy gravitationalMagnitude -- Helper expressions that represent the vectors of quantities as components positionXY, velocityXY, accelerationXY, constAccelXY :: PExpr @@ -66,9 +68,9 @@ horizVel = sy xVel $= sy ixVel horizPos = sy xPos $= sy QP.ixPos $+ (sy ixVel $* sy time) vertVel, vertPos, vertNoTime :: PExpr -vertVel = sy yVel $= sy iyVel $- (sy gravitationalAccel $* sy time) -vertPos = sy yPos $= sy QP.iyPos $+ (sy iyVel $* sy time) $- (sy gravitationalAccel $* square (sy time) $/ exactDbl 2) -vertNoTime = square (sy yVel) $= square (sy iyVel) $- (exactDbl 2 $* sy gravitationalAccel $* (sy yPos $- sy QP.iyPos)) +vertVel = sy yVel $= sy iyVel $- (sy gravitationalMagnitude $* sy time) +vertPos = sy yPos $= sy QP.iyPos $+ (sy iyVel $* sy time) $- (sy gravitationalMagnitude $* square (sy time) $/ exactDbl 2) +vertNoTime = square (sy yVel) $= square (sy iyVel) $- (exactDbl 2 $* sy gravitationalMagnitude $* (sy yPos $- sy QP.iyPos)) lcrectVel, lcrectPos, lcrectNoTime, lchorizVel, lchorizPos, lcvertVel, lcvertPos, lcvertNoTime :: LabelledContent lcrectVel = lbldExpr (sy speed $= speed') (makeEqnRef "rectVel") diff --git a/code/drasil-example/projectile/lib/Drasil/Projectile/IMods.hs b/code/drasil-example/projectile/lib/Drasil/Projectile/IMods.hs index 6f974b3e98d..5ac808d35b4 100644 --- a/code/drasil-example/projectile/lib/Drasil/Projectile/IMods.hs +++ b/code/drasil-example/projectile/lib/Drasil/Projectile/IMods.hs @@ -2,6 +2,8 @@ module Drasil.Projectile.IMods (iMods, landPosIM, messageIM, offsetIM, timeIM) w import Prelude hiding (cos, sin) +import Control.Lens ((^.)) + import Language.Drasil import Theory.Drasil (InstanceModel, imNoDerivNoRefs, imNoRefs, qwC, equationalModelN) import Utils.Drasil (weave) @@ -14,7 +16,7 @@ import Data.Drasil.Concepts.Documentation (value) import Data.Drasil.Concepts.Math (constraint, equation, xAxis) import Data.Drasil.Quantities.Math (pi_) -import Data.Drasil.Quantities.Physics (gravitationalAccelConst, iSpeed, ixPos, +import Data.Drasil.Quantities.Physics (gravitationalMagnitude, iSpeed, ixPos, ixVel, iyPos, iyVel, time, xConstAccel, xPos, yConstAccel, yPos) import Drasil.Projectile.Assumptions (accelXZero, accelYGravity, gravAccelValue, @@ -134,7 +136,7 @@ angleConstraintNote = foldlSent [atStartNP (the constraint), refS posXDirection `S.and_` refS yAxisGravity `sC` S "and is shown" `S.in_` refS figLaunch] -gravitationalAccelConstNote = ch gravitationalAccelConst `S.is` +gravitationalAccelConstNote = ch gravitationalMagnitude `S.is` S "defined in" +:+. refS gravAccelValue landAndTargPosConsNote = atStartNP' (the constraint) +:+ @@ -156,4 +158,4 @@ targPosConsNote = atStartNP (the constraint) +:+ timeConsNote = atStartNP (the constraint) +:+ eS (sy flightDur $> exactDbl 0) `S.is` S "from" +:+. refS timeStartZero -tolNote = ch tol `S.is` S "defined in" +:+. refS (SRS.valsOfAuxCons ([]::[Contents]) ([]::[Section])) +tolNote = ch (tol ^. defLhs) `S.is` S "defined in" +:+. refS (SRS.valsOfAuxCons ([]::[Contents]) ([]::[Section])) diff --git a/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs b/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs index 755238771cd..25ff6d1193a 100644 --- a/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs +++ b/code/drasil-example/swhs/lib/Drasil/SWHS/Unitals.hs @@ -26,8 +26,8 @@ symbols :: [DefinedQuantityDict] symbols = pi_ : map dqdWr units ++ map dqdWr unitless ++ map dqdWr constrained symbolsAll :: [QuantityDict] -symbolsAll = map qw symbols ++ map qw specParamValList ++ - map qw [htFusionMin, htFusionMax, coilSAMax] ++ +symbolsAll = map qw symbols ++ map (^. defLhs) specParamValList ++ + map (^. defLhs) [htFusionMin, htFusionMax, coilSAMax] ++ map qw [absTol, relTol] ++ map qw unitalChuncks @@ -265,13 +265,13 @@ tempPCM, tempW, watE, pcmE :: ConstrConcept tankLength = uqc "tankLength" (nounPhraseSP "length of tank") "the length of the tank" cL metre Real [gtZeroConstr, - sfwrRange $ Bounded (Inc, sy tankLengthMin) (Inc, sy tankLengthMax)] (dbl 1.5) + sfwrRange $ Bounded (Inc, sy $ tankLengthMin ^. defLhs) (Inc, sy $ tankLengthMax ^. defLhs)] (dbl 1.5) defaultUncrt -- Constraint 2 diam = uqc "diam" (nounPhraseSP "diameter of tank") "the diameter of the tank" cD metre Real - [gtZeroConstr, sfwrRange $ Bounded (Inc, sy arMin) (Inc, sy arMax)] + [gtZeroConstr, sfwrRange $ Bounded (Inc, sy $ arMin ^. defLhs) (Inc, sy $ arMax ^. defLhs)] (dbl 0.412) defaultUncrt -- Constraint 3 @@ -300,7 +300,7 @@ pcmSA = uqc "pcmSA" pcmDensity = uq (cuc'' "pcmDensity" (nounPhraseSP "density of PCM") "Mass per unit volume of the phase change material" (autoStage $ sub (eqSymb density) lPCM) densityU Real - [gtZeroConstr, sfwrRange $ Bounded (Exc, sy pcmDensityMin) (Exc, sy pcmDensityMax)] + [gtZeroConstr, sfwrRange $ Bounded (Exc, sy $ pcmDensityMin ^. defLhs) (Exc, sy $ pcmDensityMax ^. defLhs)] (exactDbl 1007)) defaultUncrt -- Constraint 6 @@ -317,7 +317,7 @@ htCapSP = uqc "htCapSP" "given unit mass of solid phase change material by a given amount") (sup (sub (eqSymb heatCapSpec) lPCM) lSolid) UT.heatCapSpec Real [gtZeroConstr, - sfwrRange $ Bounded (Exc, sy htCapSPMin) (Exc, sy htCapSPMax)] + sfwrRange $ Bounded (Exc, sy $ htCapSPMin ^. defLhs) (Exc, sy $ htCapSPMax ^. defLhs)] (exactDbl 1760) defaultUncrt -- Constraint 8 @@ -327,7 +327,7 @@ htCapLP = uqc "htCapLP" "given unit mass of liquid phase change material by a given amount") (sup (sub (eqSymb heatCapSpec) lPCM) lLiquid) UT.heatCapSpec Real [gtZeroConstr, - sfwrRange $ Bounded (Exc, sy htCapLPMin) (Exc, sy htCapLPMax )] + sfwrRange $ Bounded (Exc, sy $ htCapLPMin ^. defLhs) (Exc, sy $ htCapLPMax ^. defLhs)] (exactDbl 2270) defaultUncrt --Constraint 9 @@ -335,7 +335,7 @@ htFusion = uqc "htFusion" (nounPhraseSP "specific latent heat of fusion") "amount of thermal energy required to completely melt a unit mass of a substance" (sub cH lFusion) specificE Real [gtZeroConstr, - sfwrRange $ Bounded (Exc, sy htFusionMin) (Exc, sy htFusionMax)] (exactDbl 211600) defaultUncrt + sfwrRange $ Bounded (Exc, sy $ htFusionMin ^. defLhs) (Exc, sy $ htFusionMax ^. defLhs)] (exactDbl 211600) defaultUncrt -- Constraint 10 -- The "S "heating coil" " should be replaced by "phrase coil", @@ -345,7 +345,7 @@ coilSA = uqc "coilSA" (nounPhrase'' (phrase surArea) (phrase surArea) CapFirst CapWords)) "area covered by the outermost layer of the coil" (sub cA lCoil) m_2 Real [gtZeroConstr, - sfwrRange $ UpTo (Inc, sy coilSAMax)] (dbl 0.12) defaultUncrt + sfwrRange $ UpTo (Inc, sy $ coilSAMax ^. defLhs)] (dbl 0.12) defaultUncrt -- Constraint 11 tempC = uqc "tempC" (nounPhraseSP "temperature of the heating coil") @@ -356,7 +356,7 @@ tempC = uqc "tempC" (nounPhraseSP "temperature of the heating coil") -- Constraint 12 wDensity = uq (cuc'' "wDensity" (density `of_` water) "mass per unit volume of water" (autoStage $ sub (eqSymb density) lWater) densityU Real - [gtZeroConstr, sfwrRange $ Bounded (Exc, sy wDensityMin) (Inc, sy wDensityMax)] + [gtZeroConstr, sfwrRange $ Bounded (Exc, sy $ wDensityMin ^. defLhs) (Inc, sy $ wDensityMax ^. defLhs)] (exactDbl 1000)) defaultUncrt -- Constraint 13 @@ -365,7 +365,7 @@ htCapW = uqc "htCapW" (heatCapSpec `of_` water) "temperature of a given unit mass of water by a given amount") (sub (eqSymb heatCapSpec) lWater) UT.heatCapSpec Real [gtZeroConstr, - sfwrRange $ Bounded (Exc, sy htCapWMin) (Exc, sy htCapWMax)] (exactDbl 4186) defaultUncrt + sfwrRange $ Bounded (Exc, sy $ htCapWMin ^. defLhs) (Exc, sy $ htCapWMax ^. defLhs)] (exactDbl 4186) defaultUncrt -- Constraint 14 coilHTC = uqc "coilHTC" (nounPhraseSP @@ -375,7 +375,7 @@ coilHTC = uqc "coilHTC" (nounPhraseSP (sub (eqSymb htTransCoeff) lCoil) UT.heatTransferCoef Real [gtZeroConstr, - sfwrRange $ Bounded (Inc, sy coilHTCMin) (Inc, sy coilHTCMax)] (exactDbl 1000) defaultUncrt + sfwrRange $ Bounded (Inc, sy $ coilHTCMin ^. defLhs) (Inc, sy $ coilHTCMax ^. defLhs)] (exactDbl 1000) defaultUncrt -- Constraint 15 pcmHTC = uqc "pcmHTC" @@ -384,7 +384,7 @@ pcmHTC = uqc "pcmHTC" "the thermal flux from the phase change material to the surrounding water") (sub lH lPCM) UT.heatTransferCoef Real [gtZeroConstr, - sfwrRange $ Bounded (Inc, sy pcmHTCMin) (Inc, sy pcmHTCMax)] (exactDbl 1000) defaultUncrt + sfwrRange $ Bounded (Inc, sy $ pcmHTCMin ^. defLhs) (Inc, sy $ pcmHTCMax ^. defLhs)] (exactDbl 1000) defaultUncrt -- Constraint 16 tempInit = uqc "tempInit" (nounPhraseSP "initial temperature") @@ -398,7 +398,7 @@ timeFinal = uqc "timeFinal" (nounPhraseSP "final time") "simulation to its conclusion") (sub (eqSymb time) lFinal) second Real [gtZeroConstr, - sfwrRange $ UpTo (Exc, sy timeFinalMax)] (exactDbl 50000) defaultUncrt + sfwrRange $ UpTo (Exc, sy $ timeFinalMax ^. defLhs)] (exactDbl 50000) defaultUncrt timeStep = uqc "timeStep" (nounPhraseSP "time step for simulation") ("the finite discretization of time used in the numerical method " ++ diff --git a/code/drasil-example/swhsnopcm/lib/Drasil/SWHSNoPCM/Body.hs b/code/drasil-example/swhsnopcm/lib/Drasil/SWHSNoPCM/Body.hs index 9a677b0185d..a0b93d9368f 100644 --- a/code/drasil-example/swhsnopcm/lib/Drasil/SWHSNoPCM/Body.hs +++ b/code/drasil-example/swhsnopcm/lib/Drasil/SWHSNoPCM/Body.hs @@ -9,6 +9,7 @@ import qualified Language.Drasil.Sentence.Combinators as S import Language.Drasil.Code (quantvar) +import Control.Lens ((^.)) import Data.List ((\\)) import Data.Drasil.People (thulasi) @@ -88,8 +89,8 @@ symbols = pi_ : map dqdWr concepts ++ map dqdWr constrained symbolsAll :: [QuantityDict] --FIXME: Why is PCM (swhsSymbolsAll) here? --Can't generate without SWHS-specific symbols like pcmHTC and pcmSA --FOUND LOC OF ERROR: Instance Models -symbolsAll = map qw symbols ++ map qw specParamValList ++ - [qw coilSAMax, qw tauW] ++ map qw [absTol, relTol] ++ +symbolsAll = map qw symbols ++ map (^. defLhs) specParamValList ++ + [coilSAMax ^. defLhs, qw tauW] ++ map qw [absTol, relTol] ++ scipyODESymbols ++ osloSymbols ++ apacheODESymbols ++ odeintSymbols ++ map qw [listToArray $ quantvar tempW, arrayVecDepVar noPCMODEInfo] diff --git a/code/drasil-lang/lib/Language/Drasil.hs b/code/drasil-lang/lib/Language/Drasil.hs index 6892f815d6c..715b7417701 100644 --- a/code/drasil-lang/lib/Language/Drasil.hs +++ b/code/drasil-lang/lib/Language/Drasil.hs @@ -261,7 +261,8 @@ module Language.Drasil ( -- ** List-related functions , bulletFlat, bulletNested, itemRefToSent, makeTMatrix, mkEnumAbbrevList - , mkTableFromColumns, noRefs, refineChain, sortBySymbol, sortBySymbolTuple + , mkTableFromColumns, noRefs, refineChain + , sortBySymbol, sortBySymbolTuple, sortByLhsSymbol , tAndDOnly, tAndDWAcc, tAndDWSym , zipSentList diff --git a/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs b/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs index 093a93f8b4f..7a9e09a8360 100644 --- a/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs +++ b/code/drasil-lang/lib/Language/Drasil/Chunk/Eq.hs @@ -52,10 +52,7 @@ instance HasUID (QDefinition e) where uid = qdQua . uid instance NamedIdea (QDefinition e) where term = qdQua . term instance Idea (QDefinition e) where getA = getA . (^. qdQua) instance DefinesQuantity (QDefinition e) where defLhs = qdQua . to qw -instance HasSpace (QDefinition e) where typ = qdQua . typ -instance HasSymbol (QDefinition e) where symbol = symbol . (^. qdQua) instance Definition (QDefinition e) where defn = qdQua . defn -instance Quantity (QDefinition e) where instance Eq (QDefinition e) where a == b = a ^. uid == b ^. uid instance MayHaveUnit (QDefinition e) where getUnit = getUnit . view qdQua instance DefiningExpr QDefinition where defnExpr = qdExpr @@ -63,8 +60,8 @@ instance Express e => Express (QDefinition e) where express q = f $ express $ q ^. defnExpr where f = case q ^. qdInputs of - [] -> defines (sy q) - is -> defines $ apply q (map M.C is) + [] -> defines (sy $ q ^. qdQua) + is -> defines $ apply (q ^. qdQua) (map M.C is) -- FIXME: The fact that we have to manually use `C` here is because our -- UID references don't carry enough information. This feels hacky at -- the moment, and should eventually be fixed. diff --git a/code/drasil-lang/lib/Language/Drasil/Document/Combinators.hs b/code/drasil-lang/lib/Language/Drasil/Document/Combinators.hs index a0a0b07567d..e359cb28b57 100644 --- a/code/drasil-lang/lib/Language/Drasil/Document/Combinators.hs +++ b/code/drasil-lang/lib/Language/Drasil/Document/Combinators.hs @@ -14,7 +14,8 @@ module Language.Drasil.Document.Combinators ( unwrap, fterms, -- * List-related Functions bulletFlat, bulletNested, itemRefToSent, makeTMatrix, mkEnumAbbrevList, - mkTableFromColumns, noRefs, refineChain, sortBySymbol, sortBySymbolTuple, + mkTableFromColumns, noRefs, refineChain, + sortBySymbol, sortBySymbolTuple, sortByLhsSymbol, tAndDOnly, tAndDWAcc, tAndDWSym, zipSentList ) where @@ -68,6 +69,9 @@ import Data.List (sortBy, transpose) sortBySymbol :: HasSymbol a => [a] -> [a] sortBySymbol = sortBy compareBySymbol +sortByLhsSymbol :: ( DefinesQuantity a) =>[a] -> [a] +sortByLhsSymbol = sortBy (compareBySymbol `on` (^. defLhs)) + -- | Sorts a tuple list of 'HasSymbols' by first Symbol in the tuple. sortBySymbolTuple :: HasSymbol a => [(a, b)] -> [(a, b)] sortBySymbolTuple = sortBy (compareBySymbol `on` fst) diff --git a/code/drasil-theory/lib/Theory/Drasil/ModelKinds.hs b/code/drasil-theory/lib/Theory/Drasil/ModelKinds.hs index d026840e9ce..075bb2edae2 100644 --- a/code/drasil-theory/lib/Theory/Drasil/ModelKinds.hs +++ b/code/drasil-theory/lib/Theory/Drasil/ModelKinds.hs @@ -21,7 +21,7 @@ import Data.Maybe (mapMaybe) import Language.Drasil (NamedIdea(..), NP, QDefinition, HasUID(..), Expr, RelationConcept, ConceptDomain(..), Definition(..), Idea(..), Express(..), UID, DifferentialModel, mkUid, nsUid, RequiresChecking(..), Space, - HasSpace(typ), DefiningExpr(..)) + HasSpace(typ), DefiningExpr(..), DefinesQuantity (defLhs)) import Theory.Drasil.ConstraintSet (ConstraintSet) import Theory.Drasil.MultiDefn (MultiDefn) @@ -144,7 +144,7 @@ instance RequiresChecking (ModelKinds Expr) Expr Space where requiredChecks (NewDEModel dm) = requiredChecks dm requiredChecks (DEModel _) = mempty requiredChecks (EquationalConstraints cs) = requiredChecks cs - requiredChecks (EquationalModel qd) = pure (qd ^. defnExpr, qd ^. typ) + requiredChecks (EquationalModel qd) = pure (qd ^. defnExpr, qd ^. defLhs . typ) requiredChecks (EquationalRealm md) = requiredChecks md requiredChecks (OthModel _) = mempty