-- | Defines theories in the field of Physics.
module Data.Drasil.Theories.Physics where

import Language.Drasil
import Language.Drasil.Document
import Data.List.Extras (weave)
import Theory.Drasil
import qualified Language.Drasil.Sentence.Combinators as S

import Data.Drasil.Citations (velocityWiki, accelerationWiki, hibbeler2004)
import Data.Drasil.Concepts.Documentation (component, material_, value, constant)
import Data.Drasil.Concepts.Math (cartesian, equation, vector)
import Data.Drasil.Concepts.Physics (gravity, twoD, rigidBody)
import qualified Data.Drasil.Quantities.PhysicalProperties as QPP (density,
  mass, specWeight, vol)
import qualified Data.Drasil.Quantities.Physics as QP (acceleration, velocity,
  force, gravitationalAccel, pressure, torque, weight, positionVec, momentOfInertia,
  angularAccel, speed)
import Data.Drasil.Equations.Defining.Physics
import Data.Drasil.Equations.Defining.Derivations

-- | Collects theoretical models defined in this file.
physicsTMs :: [TheoryModel]
physicsTMs :: [TheoryModel]
physicsTMs = [TheoryModel
newtonSL]

-- * Newton's Second Law of Motion

newtonSL :: TheoryModel
newtonSL :: TheoryModel
newtonSL = ModelKind ModelExpr
-> [DecRef] -> String -> [Sentence] -> TheoryModel
tm (String -> QDefinition ModelExpr -> ModelKind ModelExpr
forall e. String -> QDefinition e -> ModelKind e
equationalModelU String
"newtonSL" QDefinition ModelExpr
newtonSLQD) [Citation -> DecRef
forall r.
(IsChunk r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
hibbeler2004]
  String
"NewtonSecLawMot" [Sentence
newtonSLDesc]

-- * Weight

weightGD :: GenDefn
weightGD :: GenDefn
weightGD = ModelKind ModelExpr
-> Maybe UnitDefn
-> Maybe Derivation
-> [DecRef]
-> String
-> [Sentence]
-> GenDefn
gd (QDefinition ModelExpr -> ModelKind ModelExpr
forall e. QDefinition e -> ModelKind e
equationalModel' QDefinition ModelExpr
weightQD) (DefinedQuantityDict -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit DefinedQuantityDict
QP.weight) (Derivation -> Maybe Derivation
forall a. a -> Maybe a
Just Derivation
weightDeriv) [Reference -> DecRef
forall r.
(IsChunk r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Reference
weightSrc]
  String
"weight" [{-Notes-}]

weightQD :: ModelQDef
weightQD :: QDefinition ModelExpr
weightQD = DefinedQuantityDict -> NP -> ModelExpr -> QDefinition ModelExpr
forall c e.
(Quantity c, MayHaveUnit c) =>
c -> NP -> e -> QDefinition e
mkQuantDef' DefinedQuantityDict
QP.weight (String -> NP
nounPhraseSP String
"weight") ModelExpr
forall r. ExprC r => r
weightEqn

weightSrc :: Reference
weightSrc :: Reference
weightSrc = String -> String -> ShortName -> Reference
makeURI String
"weightSrc" String
"https://en.wikipedia.org/wiki/Weight" (ShortName -> Reference) -> ShortName -> Reference
forall a b. (a -> b) -> a -> b
$
  Sentence -> ShortName
shortname' (Sentence -> ShortName) -> Sentence -> ShortName
forall a b. (a -> b) -> a -> b
$ String -> Sentence
S String
"Definition of Weight"

weightDeriv :: Derivation
weightDeriv :: Derivation
weightDeriv = Sentence -> [Sentence] -> Derivation
mkDerivName (DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QP.weight) ([Sentence] -> Derivation) -> [Sentence] -> Derivation
forall a b. (a -> b) -> a -> b
$ [Sentence] -> [Sentence] -> [Sentence]
forall a. [a] -> [a] -> [a]
weave [Sentence]
weightDerivSentences [Sentence]
weightDerivEqns

weightDerivSentences, weightDerivEqns :: [Sentence]
weightDerivSentences :: [Sentence]
weightDerivSentences = ([Sentence] -> Sentence) -> [[Sentence]] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map [Sentence] -> Sentence
foldlSentCol [[Sentence]
weightDerivAccelSentence,
  [Sentence]
weightDerivNewtonSentence, [Sentence]
weightDerivReplaceMassSentence,
  [Sentence]
weightDerivSpecWeightSentence]
weightDerivEqns :: [Sentence]
weightDerivEqns = (ModelExpr -> Sentence) -> [ModelExpr] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map ModelExpr -> Sentence
eS [ModelExpr
weightDerivAccelEqn, ModelExpr
weightDerivNewtonEqn,
  ModelExpr
weightDerivReplaceMassEqn, ModelExpr
weightDerivSpecWeightEqn]

weightDerivAccelSentence :: [Sentence]
weightDerivAccelSentence :: [Sentence]
weightDerivAccelSentence = [String -> Sentence
S String
"Under the influence" Sentence -> Sentence -> Sentence
`S.of_` ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
gravity Sentence -> Sentence -> Sentence
`sC`
  String -> Sentence
S String
"and assuming a", CI -> Sentence
forall c. Idea c => c -> Sentence
short CI
twoD, ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
cartesian, String -> Sentence
S String
"with down as positive" Sentence -> Sentence -> Sentence
`sC`
  String -> Sentence
S String
"an object has an", DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QP.acceleration, ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
vector, String -> Sentence
S String
"of"]

weightDerivNewtonSentence :: [Sentence]
weightDerivNewtonSentence :: [Sentence]
weightDerivNewtonSentence = [String -> Sentence
S String
"Since there is only one non-zero",
  ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
vector, IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase IdeaDict
component Sentence -> Sentence -> Sentence
`sC` String -> Sentence
S String
"the scalar", IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase IdeaDict
value,
  DefinedQuantityDict -> Sentence
forall t.
(IsChunk t, Idea t, HasSpace t, HasSymbol t) =>
t -> Sentence
ch DefinedQuantityDict
QP.weight, String -> Sentence
S String
"will be used for the" Sentence -> Sentence -> Sentence
+:+. DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QP.weight,
  String -> Sentence
S String
"In this scenario" Sentence -> Sentence -> Sentence
`sC` TheoryModel -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase TheoryModel
newtonSL, String -> Sentence
S String
"from", TheoryModel -> Sentence
forall r.
(IsChunk r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS TheoryModel
newtonSL,
  String -> Sentence
S String
"can be expressed as"]

weightDerivReplaceMassSentence :: [Sentence]
weightDerivReplaceMassSentence :: [Sentence]
weightDerivReplaceMassSentence = [DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart DefinedQuantityDict
QPP.mass, String -> Sentence
S String
"can be expressed as",
  DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QPP.density, String -> Sentence
S String
"multiplied by", DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QPP.vol Sentence -> Sentence -> Sentence
`sC` String -> Sentence
S String
"resulting in"]

weightDerivSpecWeightSentence :: [Sentence]
weightDerivSpecWeightSentence :: [Sentence]
weightDerivSpecWeightSentence = [String -> Sentence
S String
"Substituting", DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QPP.specWeight,
  String -> Sentence
S String
"as the product" Sentence -> Sentence -> Sentence
`S.of_` DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QPP.density Sentence -> Sentence -> Sentence
`S.and_` DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QP.gravitationalAccel,
  String -> Sentence
S String
"yields"]

-- * Pressure

hsPressureGD :: GenDefn
hsPressureGD :: GenDefn
hsPressureGD = ModelKind ModelExpr
-> Maybe UnitDefn
-> Maybe Derivation
-> [DecRef]
-> String
-> [Sentence]
-> GenDefn
gd (QDefinition ModelExpr -> ModelKind ModelExpr
forall e. QDefinition e -> ModelKind e
equationalModel' QDefinition ModelExpr
hsPressureQD) (DefinedQuantityDict -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit DefinedQuantityDict
QP.pressure) Maybe Derivation
forall a. Maybe a
Nothing
  [Reference -> DecRef
forall r.
(IsChunk r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Reference
hsPressureSrc] String
"hsPressure" [Sentence
hsPressureNotes]

hsPressureQD :: ModelQDef
hsPressureQD :: QDefinition ModelExpr
hsPressureQD = DefinedQuantityDict -> NP -> ModelExpr -> QDefinition ModelExpr
forall c e.
(Quantity c, MayHaveUnit c) =>
c -> NP -> e -> QDefinition e
mkQuantDef' DefinedQuantityDict
QP.pressure (String -> NP
nounPhraseSP String
"hydrostatic pressure") ModelExpr
forall r. ExprC r => r
hsPressureEqn

hsPressureSrc :: Reference
hsPressureSrc :: Reference
hsPressureSrc = String -> String -> ShortName -> Reference
makeURI String
"hsPressureSrc" String
"https://en.wikipedia.org/wiki/Pressure" (ShortName -> Reference) -> ShortName -> Reference
forall a b. (a -> b) -> a -> b
$
  Sentence -> ShortName
shortname' (Sentence -> ShortName) -> Sentence -> ShortName
forall a b. (a -> b) -> a -> b
$ String -> Sentence
S String
"Definition of Pressure"

hsPressureNotes :: Sentence
hsPressureNotes :: Sentence
hsPressureNotes = String -> Sentence
S String
"This" Sentence -> Sentence -> Sentence
+:+ ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
equation Sentence -> Sentence -> Sentence
+:+ String -> Sentence
S String
"is derived from" Sentence -> Sentence -> Sentence
+:+
  String -> Sentence
S String
"Bernoulli's" Sentence -> Sentence -> Sentence
+:+ ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
equation Sentence -> Sentence -> Sentence
+:+ String -> Sentence
S String
"for a slow moving fluid" Sentence -> Sentence -> Sentence
+:+
  String -> Sentence
S String
"through a porous" Sentence -> Sentence -> Sentence
+:+. IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase IdeaDict
material_

-- * Torque

torqueDD :: DataDefinition
torqueDD :: DataDefinition
torqueDD = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
torque Maybe Derivation
forall a. Maybe a
Nothing String
"torque" [Sentence
torqueDesc]

torque :: SimpleQDef
torque :: SimpleQDef
torque = DefinedQuantityDict -> Expr -> SimpleQDef
forall c e.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> e -> QDefinition e
mkQuantDef DefinedQuantityDict
QP.torque Expr
torqueEqn

torqueEqn :: Expr
torqueEqn :: Expr
torqueEqn = DefinedQuantityDict -> Expr
forall c. (IsChunk c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy DefinedQuantityDict
QP.positionVec Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
`cross` DefinedQuantityDict -> Expr
forall c. (IsChunk c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy DefinedQuantityDict
QP.force

torqueDesc :: Sentence
torqueDesc :: Sentence
torqueDesc = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"The", SimpleQDef -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase SimpleQDef
torque,
  String -> Sentence
S String
"on a body measures the", String -> Sentence
S String
"tendency" Sentence -> Sentence -> Sentence
`S.of_` String -> Sentence
S String
"a", DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QP.force,
  String -> Sentence
S String
"to rotate the body around an axis or pivot"]

-- * Vector Magnitude

vecMagQD :: SimpleQDef
vecMagQD :: SimpleQDef
vecMagQD = DefinedQuantityDict -> Expr -> SimpleQDef
forall c e.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> e -> QDefinition e
mkQuantDef DefinedQuantityDict
QP.speed Expr
forall r. ExprC r => r
speedEqn

magNote :: Sentence
magNote :: Sentence
magNote = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"For a given", DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QP.velocity, String -> Sentence
S String
"vector", DefinedQuantityDict -> Sentence
forall t.
(IsChunk t, Idea t, HasSpace t, HasSymbol t) =>
t -> Sentence
ch DefinedQuantityDict
QP.velocity Sentence -> Sentence -> Sentence
`sC`
  String -> Sentence
S String
"the magnitude of the vector", Sentence -> Sentence
sParen (ModelExpr -> Sentence
eS ModelExpr
forall r. ExprC r => r
speedEqn) Sentence -> Sentence -> Sentence
`S.isThe`
  String -> Sentence
S String
"scalar called", DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QP.speed]

vecMag :: DataDefinition
vecMag :: DataDefinition
vecMag = SimpleQDef
-> Maybe Derivation -> String -> [Sentence] -> DataDefinition
ddENoRefs SimpleQDef
vecMagQD Maybe Derivation
forall a. Maybe a
Nothing String
"vecMag" [Sentence
magNote]

-- * Newton's Second Law of Rotational Motion

newtonSLR :: TheoryModel
newtonSLR :: TheoryModel
newtonSLR = ModelKind ModelExpr
-> [DecRef] -> String -> [Sentence] -> TheoryModel
tm (String -> QDefinition ModelExpr -> ModelKind ModelExpr
forall e. String -> QDefinition e -> ModelKind e
equationalModelU String
"newtonSLR" QDefinition ModelExpr
newtonSLRQD) [Citation -> DecRef
forall r.
(IsChunk r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
hibbeler2004]
  String
"NewtonSecLawRotMot" [Sentence]
newtonSLRNotes

newtonSLRQD :: ModelQDef
newtonSLRQD :: QDefinition ModelExpr
newtonSLRQD = DefinedQuantityDict -> NP -> ModelExpr -> QDefinition ModelExpr
forall c e.
(Quantity c, MayHaveUnit c) =>
c -> NP -> e -> QDefinition e
mkQuantDef' DefinedQuantityDict
QP.torque (String -> NP
nounPhraseSP String
"Newton's second law for rotational motion") ModelExpr
forall r. ExprC r => r
newtonSLRExpr

newtonSLRExpr :: ExprC r => r
newtonSLRExpr :: forall r. ExprC r => r
newtonSLRExpr = DefinedQuantityDict -> r
forall c. (IsChunk c, HasSymbol c) => c -> r
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy DefinedQuantityDict
QP.momentOfInertia r -> r -> r
forall r. ExprC r => r -> r -> r
$* DefinedQuantityDict -> r
forall c. (IsChunk c, HasSymbol c) => c -> r
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy DefinedQuantityDict
QP.angularAccel

newtonSLRNotes :: [Sentence]
newtonSLRNotes :: [Sentence]
newtonSLRNotes = [[Sentence] -> Sentence
foldlSent
  [String -> Sentence
S String
"The net", DefinedQuantityDict -> Sentence
forall a. Quantity a => a -> Sentence
getTandS DefinedQuantityDict
QP.torque, String -> Sentence
S String
"on a", ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
rigidBody Sentence -> Sentence -> Sentence
`S.is`
   String -> Sentence
S String
"proportional to its", DefinedQuantityDict -> Sentence
forall a. Quantity a => a -> Sentence
getTandS DefinedQuantityDict
QP.angularAccel Sentence -> Sentence -> Sentence
`sC` String -> Sentence
S String
"where",
   DefinedQuantityDict -> Sentence
forall t.
(IsChunk t, Idea t, HasSpace t, HasSymbol t) =>
t -> Sentence
ch DefinedQuantityDict
QP.momentOfInertia, String -> Sentence
S String
"denotes", DefinedQuantityDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase DefinedQuantityDict
QP.momentOfInertia Sentence -> Sentence -> Sentence
`S.the_ofThe`
   ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
rigidBody, String -> Sentence
S String
"as the", IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase IdeaDict
constant Sentence -> Sentence -> Sentence
`S.of_` String -> Sentence
S String
"proportionality"]]

-- * Acceleration

accelerationTM :: TheoryModel
accelerationTM :: TheoryModel
accelerationTM = ModelKind ModelExpr
-> [DecRef] -> String -> [Sentence] -> TheoryModel
tm (String -> QDefinition ModelExpr -> ModelKind ModelExpr
forall e. String -> QDefinition e -> ModelKind e
equationalModelU String
"accelerationTM" QDefinition ModelExpr
accelerationQD)
  [Citation -> DecRef
forall r.
(IsChunk r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
accelerationWiki] String
"acceleration" []

-- * Velocity

velocityTM :: TheoryModel
velocityTM :: TheoryModel
velocityTM = ModelKind ModelExpr
-> [DecRef] -> String -> [Sentence] -> TheoryModel
tm (String -> QDefinition ModelExpr -> ModelKind ModelExpr
forall e. String -> QDefinition e -> ModelKind e
equationalModelU String
"velocityTM" QDefinition ModelExpr
velocityQD)
  [Citation -> DecRef
forall r.
(IsChunk r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
velocityWiki] String
"velocity" []