Skip to content

Commit

Permalink
Merge pull request #1828 from JacquesCarette/gameGenDef
Browse files Browse the repository at this point in the history
Plugged in GenDef.hs and added acceleration due to gravity
  • Loading branch information
smiths authored Aug 15, 2019
2 parents 8b4e245 + cab05a1 commit f86a030
Show file tree
Hide file tree
Showing 9 changed files with 437 additions and 65 deletions.
1 change: 1 addition & 0 deletions code/drasil-code/Language/Drasil/Code/Imperative/Import.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ genMethod s pr t n desc p r b = do
genInOutFunc :: (RenderSym repr, HasUID c, HasCodeType c, CodeIdea c) =>
repr (Scope repr) -> repr (Permanence repr) -> Label -> String -> [c] ->
[c] -> [c] -> [repr (Block repr)] -> Reader State (repr (Method repr))

genInOutFunc s pr n desc ins outs both b = do
g <- ask
inVs <- mapM mkVar ins
Expand Down
11 changes: 6 additions & 5 deletions code/drasil-example/Drasil/GamePhysics/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Data.Drasil.IdeaDicts as Doc (dataDefn, inModel, thModel)
import Data.Drasil.Concepts.Education (frstYr, highSchoolCalculus,
highSchoolPhysics, educon)
import Data.Drasil.Concepts.Software (physLib, softwarecon)
import Data.Drasil.People (alex, luthfi)
import Data.Drasil.People (alex, luthfi, olu)
import Data.Drasil.SI_Units (metre, kilogram, second, newton, radian,
derived, fundamentals, joule)
import Data.Drasil.Software.Products (openSource, prodtcon, sciCompS, videoGame)
Expand All @@ -49,6 +49,7 @@ import Drasil.GamePhysics.Requirements (funcReqs, nonfuncReqs)
import Drasil.GamePhysics.TMods (tMods)
import Drasil.GamePhysics.Unitals (symbolsAll, outputConstraints,
inputSymbols, outputSymbols, inputConstraints, defSymbols)
import Drasil.GamePhysics.GenDefs (generalDefns)

srs :: Document
srs = mkDoc mkSRS for' si
Expand Down Expand Up @@ -78,7 +79,7 @@ mkSRS = [RefSec $ RefProg intro [TUnits, tsymb tableOfSymbols, TAandA],
, SSDSolChSpec $ SCSProg
[ Assumptions
, TMs [] (Label : stdFields)
, GDs [] [] HideDerivation -- No Gen Defs for Gamephysics
, GDs [] ([Label, Units] ++ stdFields) ShowDerivation
, DDs [] ([Label, Symbol, Units] ++ stdFields) ShowDerivation
, IMs [instModIntro] ([Label, Input, Output, InConstraints, OutConstraints] ++ stdFields) ShowDerivation
, Constraints (S "FIXME") inputConstraints
Expand All @@ -101,7 +102,7 @@ si :: SystemInformation
si = SI {
_sys = gamePhysics,
_kind = Doc.srs,
_authors = [alex, luthfi],
_authors = [alex, luthfi, olu],
-- FIXME: The _quants field should be filled in with all the symbols, however
-- #1658 is why this is empty, otherwise we end up with unused (and probably
-- should be removed) symbols. But that's for another time. This is "fine"
Expand Down Expand Up @@ -142,12 +143,12 @@ units = map unitWrapper [metre, kilogram, second, joule] ++ map unitWrapper [new

symbMap :: ChunkDB
symbMap = cdb (map qw iModelsNew ++ map qw symbolsAll) (map nw symbolsAll
++ map nw acronyms ++ map nw prodtcon ++ map nw iModelsNew
++ map nw acronyms ++ map nw prodtcon ++ map nw generalDefns ++ map nw iModelsNew
++ map nw softwarecon ++ map nw doccon ++ map nw doccon'
++ map nw CP.physicCon ++ map nw educon ++ [nw algorithm] ++ map nw derived
++ map nw fundamentals ++ map nw CM.mathcon ++ map nw CM.mathcon')
(map cw defSymbols ++ srsDomains ++ map cw iModelsNew) units GP.dataDefs
iModelsNew [] tMods concIns section []
iModelsNew generalDefns tMods concIns section []

usedDB :: ChunkDB
usedDB = cdb ([] :: [QuantityDict]) (map nw symbolsAll ++ map nw acronyms)
Expand Down
37 changes: 36 additions & 1 deletion code/drasil-example/Drasil/GamePhysics/DataDefs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import qualified Data.Drasil.Quantities.Physics as QP (angularAccel,
linearDisplacement, linearVelocity, position, restitutionCoef, time, velocity,
force, torque, kEnergy, energy, impulseV, chgInVelocity, acceleration, potEnergy,
height, gravitationalAccel, momentOfInertia)

import qualified Data.Drasil.Quantities.PhysicalProperties as QPP (mass)

import Data.Drasil.Theories.Physics (torque, torqueDD)
Expand Down Expand Up @@ -203,7 +204,7 @@ dd7descr = (QP.angularAccel ^. term) +:+ S "of a" +:+
-------------------------DD8 Impulse for Collision-------------------------------

impulseDD :: DataDefinition
impulseDD = ddNoRefs impulse Nothing "impulse"
impulseDD = ddNoRefs impulse (Just impulseDeriv) "impulse"
[makeRef2S assumpOT, makeRef2S assumpOD, makeRef2S assumpAD, makeRef2S assumpCT]

impulse :: QDefinition
Expand All @@ -223,6 +224,40 @@ dd8descr = (impulseScl ^. term) +:+ S "used to determine" +:+
(CP.collision ^. term) +:+ S "response between two" +:+
irregPlur (CP.rigidBody ^. term)
-}

impulseDeriv :: Derivation
impulseDeriv = mkDerivName (phrase QP.impulseS) (weave [impulseDerivSentences, map E impulseDerivEqns])

impulseDerivSentences :: [Sentence]
impulseDerivSentences = map foldlSentCol [impulseDerivSentence1,
impulseDerivSentence2, impulseDerivSentence3]

impulseDerivSentence1 :: [Sentence]
impulseDerivSentence1 = [S "Newton's second law of motion states"]

impulseDerivSentence2 :: [Sentence]
impulseDerivSentence2 = [S "Rearranging "]

impulseDerivSentence3 :: [Sentence]
impulseDerivSentence3 = [S "Integrating the right hand side "]

impulseDerivEqn1 :: Expr
impulseDerivEqn1 = sy QP.force $= sy QPP.mass * sy QP.acceleration
$= sy QPP.mass * deriv (sy QP.velocity) QP.time

impulseDerivEqn2 :: Expr
impulseDerivEqn2 = defint (eqSymb timeT) (sy time_1) (sy time_2) (sy QP.force) $=
sy QPP.mass * defint (eqSymb QP.velocity) (sy velo_1) (sy velo_2) 1


impulseDerivEqn3 :: Expr
impulseDerivEqn3 = defint (eqSymb timeT) (sy time_1) (sy time_2) (sy QP.force)
$= (sy QPP.mass * sy velo_2) - (sy QPP.mass * sy velo_1)
$= sy QPP.mass * sy QP.chgInVelocity

impulseDerivEqns :: [Expr]
impulseDerivEqns = [impulseDerivEqn1, impulseDerivEqn2, impulseDerivEqn3]

------------------------DD9 Chasles Theorem----------------------------------
chaslesDD :: DataDefinition
chaslesDD = dd chasles [makeCite chaslesWiki] Nothing "chaslesThm"
Expand Down
103 changes: 103 additions & 0 deletions code/drasil-example/Drasil/GamePhysics/GenDefs.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module Drasil.GamePhysics.GenDefs (generalDefns, accelGravityGD) where

import Language.Drasil
import Utils.Drasil
--import Data.Drasil.Concepts.Physics as CP (rigidBody, time)
import Theory.Drasil (GenDefn, gd)
import qualified Data.Drasil.Quantities.Physics as QP (acceleration,
gravitationalAccel, gravitationalConst)
import Drasil.GamePhysics.Unitals (mLarger, dispNorm, dispUnit)

----- General Models -----

generalDefns :: [GenDefn]
generalDefns = [accelGravityGD]


{-conservationOfMomentGDef :: RelationConcept
conservationOfMomentGDef = makeRC "conservOfMoment" (nounPhraseSP "Conservation of Momentum")
conservationOfMomentDesc conservationOfMomentRel
conservationOfMomentRel :: Relation
conservationOfMomentRel = UnaryOp $ Summation Nothing
C massI
conservationOfMomentDesc :: Sentence
conservationOfMomentDesc = foldlSent [S "In an isolated system,",
S "where the sum of external", phrase impulseS, S "acting on the system is zero,",
S "the total momentum of the bodies is constant (conserved)"
]
--[mass, initialVelocity, finalVelocity]
conservationOfMomentDeriv :: Sentence
conservationOfMomentDeriv = foldlSent [S "When bodies collide, they exert",
S "an equal (force) on each other in opposite directions" +:+.
S "This is Newton's third law:",
S "(expr1)",
S "The objects collide with each other for the exact same amount of",
phrase time, getS time,
S "The above equation is equal to the", phrase impulseS,
S "(GD1 ref)",
S "(expr2)",
S "The", phrase impulseS, S "is equal to the change in momentum:",
S "(expr3)",
S "Substituting 2*ref to 2* into 1*ref to 1* yields:",
S "(expr4)",
S "Expanding and rearranging the above formula gives",
S "(expr5)",
S "Generalizing for multiple (k) colliding objects:",
S "(expr6)"
]
-}


--------------------------Acceleration due to gravity----------------------------
accelGravityGD :: GenDefn
accelGravityGD = gd accelGravityRC (getUnit QP.acceleration) Nothing
[accelGravitySrc] "accelGravity" [{-Notes-}]


accelGravityRC :: RelationConcept
accelGravityRC = makeRC "accelGravityRC" (nounPhraseSP "Acceleration due to gravity")
accelGravityDesc accelGravityRel

accelGravityRel :: Relation
accelGravityRel = sy QP.gravitationalAccel $= sy QP.gravitationalConst * sy mLarger/
(sy dispNorm $^ 2) * sy dispUnit

accelGravitySrc :: Reference
accelGravitySrc = makeURI "accelGravitySrc" "https://en.wikipedia.org/wiki/Gravitational_acceleration" $
shortname' "Definition of Gravitational Acceleration"

accelGravityDesc :: Sentence
accelGravityDesc = foldlSent [S "Acceleration due to gravity"]

-- [gravitationalAccel, mass, gravitationalConst]

-- accelerationDueToGravityDeriv :: Sentence
-- accelerationDueToGravityDeriv = foldlSent [S "From Newton's law of universal",
-- S "gravitation (T3 ref), we have:",
-- S "(expr1)",
-- S "Equation 3 **ref to 3** governs the gravitational attraction between two",
-- S "bodies. Suppose that one of the bodies is significantly more massive than",
-- S "other, so that we concern ourselves with the force the massive body exerts",
-- S "on the lighter body" +:+. S "Further suppose that the coordinate system is",
-- S "chosen such that this force acts on a line which lies along one of the",
-- S "principle axes (A2 ref)" +:+. S "Then our unit vector", S "(expr2)", S "for",
-- S "the x or y axes (A3 ref), respectively"
-- S "Given the above assumptions, let M and m be the", phrase mass,
-- S "of the massive and",
-- S "light body, respectively" +:+. S "Using 3 **ref to 3** and equating this",
-- S "with Newton's second law (T1 ref) for the force experienced by the light",
-- S "body, we get:",
-- S "(expr3)",
-- S "where", getS gravitationalConst, S "is", phrase gravitationalAccel,
-- S "Dividing 4 **ref to 4**",
-- S "by m, and resolving this into separate x and y components:",
-- S "(expr4)",
-- S "(expr5)",
-- S "Thus:",
-- S "(expr6)"
-- ]

2 changes: 2 additions & 0 deletions code/drasil-example/Drasil/GamePhysics/TMods.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import qualified Data.Drasil.Quantities.Physics as QP (angularAccel,
import qualified Data.Drasil.Theories.Physics as TP (newtonSL)

----- Theoretical Models -----

tMods :: [TheoryModel]
tMods = [TP.newtonSL, newtonTL, newtonLUG, newtonSLR]

Expand Down Expand Up @@ -126,3 +127,4 @@ newtonSLRDesc = foldlSent [S "The net", phrase QP.torque,
phrase CP.rigidBody, S "We also assume that all",
plural CP.rigidBody, S "involved are two-dimensional",
makeRef2S assumpOD]

12 changes: 8 additions & 4 deletions code/drasil-example/Drasil/GamePhysics/Unitals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ unitSymbs = map ucw unitalChunks ++ map ucw [iVect, jVect, normalVect,
massA, massB, massIRigidBody, normalLen, contDispA, contDispB,
perpLenA, momtInertA, perpLenB, momtInertB, timeT, inittime,
momtInertK, pointOfCollision, contDispK, collisionImpulse, velAP,
velBP, time_1, time_2, velo_1, velo_2, rRot]
velBP, time_1, time_2, velo_1, velo_2, rRot, mLarger]

----------------------
-- TABLE OF SYMBOLS --
Expand Down Expand Up @@ -65,7 +65,7 @@ unitalChunks = [QP.acceleration, QP.angularAccel, QP.gravitationalAccel,
dispNorm, sqrDist, velO, rOB, massIRigidBody, contDispA, contDispB,
momtInertA, momtInertB, timeT, inittime, momtInertK, pointOfCollision,
contDispK, collisionImpulse, QP.kEnergy, finRelVel, velAP, velBP, time_1, time_2, velo_1, velo_2,
QP.chgInVelocity, QP.potEnergy, QP.height, rRot]
QP.chgInVelocity, QP.potEnergy, QP.height, rRot, mLarger]

-----------------------
-- PARAMETRIZED HACK --
Expand Down Expand Up @@ -134,7 +134,7 @@ iVect, jVect, normalVect, force_1, force_2, forceI, mass_1, mass_2, dispUnit,
massA, massB, massIRigidBody, normalLen, contDispA, contDispB,
perpLenA, momtInertA, perpLenB, momtInertB, timeT, inittime,
momtInertK, pointOfCollision, contDispK, collisionImpulse, finRelVel,
velAP, velBP, time_1, time_2, velo_1, velo_2, rRot :: UnitalChunk
velAP, velBP, time_1, time_2, velo_1, velo_2, rRot, mLarger :: UnitalChunk

iVect = ucs' (dccWDS "unitVect" (compoundPhrase' (cn "horizontal")
(QM.unitVect ^. term)) (phrase QM.unitVect))
Expand Down Expand Up @@ -186,7 +186,11 @@ torqueI = ucs' (dccWDS "torqueI"
(cn "torque applied to the i-th body")
(phrase QP.torque)) (sub (eqSymb QP.torque) lI) Real torqueU

mTot = ucs' (dccWDS "M" (compoundPhrase' (cn "total mass of the")
mTot = ucs' (dccWDS "M_T" (compoundPhrase' (cn "total mass of the")
(CP.rigidBody ^. term)) (phrase QPP.mass))
(sub (eqSymb QPP.mass) cT) Real kilogram

mLarger = ucs' (dccWDS "mLarger" (compoundPhrase' (cn "mass of the larger")
(CP.rigidBody ^. term)) (phrase QPP.mass)) cM Real kilogram

timeC = ucs' (dccWDS "timeC" (cn "denotes the time at collision")
Expand Down
1 change: 1 addition & 0 deletions code/drasil-example/drasil-example.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ executable gamephysics
, Drasil.GamePhysics.Changes
, Drasil.GamePhysics.Concepts
, Drasil.GamePhysics.DataDefs
, Drasil.GamePhysics.GenDefs
, Drasil.GamePhysics.Goals
, Drasil.GamePhysics.TMods
, Drasil.GamePhysics.Unitals
Expand Down
Loading

0 comments on commit f86a030

Please sign in to comment.