{-# LANGUAGE PostfixOperators #-}
module Drasil.SSP.TMods (tMods, factOfSafety, equilibrium, mcShrStrgth, effStress) 
  where

import Control.Lens ((^.))
import Prelude hiding (tan)
import qualified Data.List.NonEmpty as NE

import Language.Drasil
import Theory.Drasil
import Language.Drasil.Chunk.Concept.NamedCombinators
import qualified Language.Drasil.Sentence.Combinators as S

import Data.Drasil.Quantities.Physics (distance, force)

import Data.Drasil.Concepts.Documentation (model)
import Data.Drasil.Concepts.Physics (friction, linear)
import Data.Drasil.Theories.Physics (newtonSL)

import Drasil.SSP.Assumptions (assumpENSL, assumpSBSBISL)
import Drasil.SSP.Defs (factorOfSafety)
import Drasil.SSP.References (fredlund1977)
import Drasil.SSP.Unitals (effCohesion, effNormStress, effectiveStress, 
  fricAngle, fs, fx, fy, genericM, mobilizedShear, nrmFSubWat, porePressure, 
  resistiveShear, shrStress, totNormStress)
import Drasil.SSP.DataDefs (normStressDD)

--------------------------
--  Theoretical Models  --
--------------------------
tMods :: [TheoryModel]
tMods :: [TheoryModel]
tMods = [TheoryModel
factOfSafety, TheoryModel
equilibrium, TheoryModel
mcShrStrgth, TheoryModel
effStress, TheoryModel
newtonSL]

------------- New Chunk -----------
factOfSafety :: TheoryModel
factOfSafety :: TheoryModel
factOfSafety = forall q c.
(Quantity q, MayHaveUnit q, Concept c) =>
ModelKind ModelExpr
-> [q]
-> [c]
-> [ModelQDef]
-> [ModelExpr]
-> [ModelQDef]
-> [DecRef]
-> String
-> [Sentence]
-> TheoryModel
tm (forall e. String -> QDefinition e -> ModelKind e
equationalModelU String
"factOfSafetyTM" ModelQDef
factOfSafetyQD)
  [forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw ConstrConcept
fs, forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UnitalChunk
resistiveShear, forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UnitalChunk
mobilizedShear] ([] :: [ConceptChunk])
  [ModelQDef
factOfSafetyQD] [] [] [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
fredlund1977] String
"factOfSafety" []

------------------------------------
factOfSafetyQD :: ModelQDef
factOfSafetyQD :: ModelQDef
factOfSafetyQD = forall c e.
(Quantity c, MayHaveUnit c) =>
c -> NP -> e -> QDefinition e
mkQuantDef' ConstrConcept
fs NP
factorOfSafety PExpr
factOfSafetyExpr

factOfSafetyExpr :: PExpr
factOfSafetyExpr :: PExpr
factOfSafetyExpr = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
resistiveShear forall r. ExprC r => r -> r -> r
$/ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
mobilizedShear

--
------------- New Chunk -----------
equilibrium :: TheoryModel
equilibrium :: TheoryModel
equilibrium = forall q c.
(Quantity q, MayHaveUnit q, Concept c) =>
ModelKind ModelExpr
-> [q]
-> [c]
-> [ModelQDef]
-> [ModelExpr]
-> [ModelQDef]
-> [DecRef]
-> String
-> [Sentence]
-> TheoryModel
tm (forall e. ConstraintSet e -> ModelKind e
equationalConstraints' ConstraintSet ModelExpr
equilibriumCS)
  [forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UnitalChunk
fx] ([] :: [ConceptChunk])
  [] (forall a b. (a -> b) -> [a] -> [b]
map forall c. Express c => c -> ModelExpr
express [ModelExpr]
equilibriumRels) [] [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
fredlund1977] String
"equilibrium" [Sentence
eqDesc]

------------------------------------  

equilibriumRels :: [ModelExpr]
equilibriumRels :: [ModelExpr]
equilibriumRels = forall a b. (a -> b) -> [a] -> [b]
map ((forall r. ExprC r => r -> r -> r
$= forall r. LiteralC r => Integer -> r
int Integer
0) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r. ModelExprC r => Symbol -> r -> r
sumAll (String -> Symbol
variable String
"i") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy) [UnitalChunk
fx, UnitalChunk
fy, UnitalChunk
genericM]

-- FIXME: variable "i" is a hack.  But we need to sum over something!
equilibriumCS :: ConstraintSet ModelExpr
equilibriumCS :: ConstraintSet ModelExpr
equilibriumCS = forall e. ConceptChunk -> NonEmpty e -> ConstraintSet e
mkConstraintSet
  (String -> NP -> Sentence -> ConceptChunk
dccWDS String
"equilibriumCS" (String -> NP
nounPhraseSP String
"equilibrium") Sentence
eqDesc) forall a b. (a -> b) -> a -> b
$
  forall a. [a] -> NonEmpty a
NE.fromList [ModelExpr]
equilibriumRels
-- makeRC "equilibriumRC" (nounPhraseSP "equilibrium") eqDesc eqRel

eqDesc :: Sentence
eqDesc :: Sentence
eqDesc = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"For a body in static equilibrium, the net",
  forall n. NounPhrase n => n -> Sentence
pluralNP (UnitalChunk
force forall c d. (NamedIdea c, NamedIdea d) => c -> d -> NP
`and_PP` UnitalChunk
genericM) Sentence -> Sentence -> Sentence
+:+. String -> Sentence
S String
"acting on the body will cancel out",
  String -> Sentence
S String
"Assuming a 2D problem", Sentence -> Sentence
sParen (forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS ConceptInstance
assumpENSL) Sentence -> Sentence -> Sentence
`sC` String -> Sentence
S String
"the", forall a. Quantity a => a -> Sentence
getTandS UnitalChunk
fx Sentence -> Sentence -> Sentence
`S.and_`
  forall a. Quantity a => a -> Sentence
getTandS UnitalChunk
fy, String -> Sentence
S String
"will be equal to" Sentence -> Sentence -> Sentence
+:+. ModelExpr -> Sentence
eS (forall r. LiteralC r => Integer -> r
exactDbl Integer
0), String -> Sentence
S String
"All", forall n. NamedIdea n => n -> Sentence
plural UnitalChunk
force,
  String -> Sentence
S String
"and their", forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
distance, String -> Sentence
S String
"from the chosen point of rotation",
  String -> Sentence
S String
"will create a net", forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
genericM, String -> Sentence
S String
"equal to" Sentence -> Sentence -> Sentence
+:+ ModelExpr -> Sentence
eS (forall r. LiteralC r => Integer -> r
exactDbl Integer
0)]

--
------------- New Chunk -----------
mcShrStrgth :: TheoryModel
mcShrStrgth :: TheoryModel
mcShrStrgth = forall q c.
(Quantity q, MayHaveUnit q, Concept c) =>
ModelKind ModelExpr
-> [q]
-> [c]
-> [ModelQDef]
-> [ModelExpr]
-> [ModelQDef]
-> [DecRef]
-> String
-> [Sentence]
-> TheoryModel
tm (forall e. String -> QDefinition e -> ModelKind e
equationalModelU String
"mcShrSrgth" ModelQDef
mcShrStrgthQD)
  [forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UnitalChunk
shrStress, forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UnitalChunk
effNormStress, forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UncertQ
fricAngle, forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UncertQ
effCohesion] 
  ([] :: [ConceptChunk])
  [ModelQDef
mcShrStrgthQD] [] [] [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
fredlund1977] String
"mcShrStrgth" [Sentence
mcShrStrgthDesc]

------------------------------------
mcShrStrgthQD :: ModelQDef
mcShrStrgthQD :: ModelQDef
mcShrStrgthQD = forall e.
UID
-> NP
-> Sentence
-> (Stage -> Symbol)
-> Space
-> e
-> QDefinition e
fromEqnSt' (UnitalChunk
shrStress forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid) (String -> NP
nounPhraseSP String
"Mohr-Coulumb shear strength")
 Sentence
mcShrStrgthDesc (forall c. HasSymbol c => c -> Stage -> Symbol
symbol UnitalChunk
shrStress) Space
Real PExpr
mcShrStrgthExpr

mcShrStrgthExpr :: PExpr
mcShrStrgthExpr :: PExpr
mcShrStrgthExpr = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
effNormStress forall r. ExprC r => r -> r -> r
`mulRe` forall r. ExprC r => r -> r
tan (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
fricAngle) forall r. ExprC r => r -> r -> r
`addRe` forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
effCohesion

mcShrStrgthDesc :: Sentence
mcShrStrgthDesc :: Sentence
mcShrStrgthDesc = [Sentence] -> Sentence
foldlSent [String -> Sentence
S String
"In this", forall n. NamedIdea n => n -> Sentence
phrase IdeaDict
model, String -> Sentence
S String
"the",
  forall a. Quantity a => a -> Sentence
getTandS UnitalChunk
shrStress, String -> Sentence
S String
"is proportional to the product of the",
  forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
effNormStress, forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
effNormStress, String -> Sentence
S String
"on the plane", 
  String -> Sentence
S String
"with its static", forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
friction, String -> Sentence
S String
"in the angular form" Sentence -> Sentence -> Sentence
+:+.
  ModelExpr -> Sentence
eS (forall r. ExprC r => r -> r
tan forall a b. (a -> b) -> a -> b
$ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
fricAngle),
  String -> Sentence
S String
"The", forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
shrStress, String -> Sentence
S String
"versus", forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
effNormStress,
  String -> Sentence
S String
"relationship is not truly",
  forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
linear Sentence -> Sentence -> Sentence
`sC` String -> Sentence
S String
"but assuming the", forall n. NamedIdea n => n -> Sentence
phrase UnitalChunk
nrmFSubWat, 
  String -> Sentence
S String
"is strong enough, it can be approximated with a", forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
linear,
  String -> Sentence
S String
"fit", Sentence -> Sentence
sParen (forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS ConceptInstance
assumpSBSBISL), String -> Sentence
S String
"where the", forall n. NamedIdea n => n -> Sentence
phrase UncertQ
effCohesion, 
  forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UncertQ
effCohesion, String -> Sentence
S String
"represents the", forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
shrStress,
  String -> Sentence
S String
"intercept of the fitted line"]

--
------------- New Chunk -----------
effStress :: TheoryModel
effStress :: TheoryModel
effStress = forall q c.
(Quantity q, MayHaveUnit q, Concept c) =>
ModelKind ModelExpr
-> [q]
-> [c]
-> [ModelQDef]
-> [ModelExpr]
-> [ModelQDef]
-> [DecRef]
-> String
-> [Sentence]
-> TheoryModel
tm (forall e. String -> QDefinition e -> ModelKind e
equationalModelU String
"effectiveStressTM" ModelQDef
effStressQD)
  [forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UnitalChunk
effectiveStress, forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UnitalChunk
totNormStress, forall q. (Quantity q, MayHaveUnit q) => q -> QuantityDict
qw UnitalChunk
porePressure] 
  ([] :: [ConceptChunk])
  [ModelQDef
effStressQD] [] [] [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
fredlund1977] String
"effStress" [Sentence
effStressDesc]

------------------------------------
effStressQD :: ModelQDef
effStressQD :: ModelQDef
effStressQD = forall e.
UID
-> NP
-> Sentence
-> (Stage -> Symbol)
-> Space
-> e
-> QDefinition e
fromEqnSt' (UnitalChunk
effectiveStress forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid) (String -> NP
nounPhraseSP String
"effective stress")
 Sentence
effStressDesc (forall c. HasSymbol c => c -> Stage -> Symbol
symbol UnitalChunk
effectiveStress) Space
Real PExpr
effStressExpr

effStressExpr :: PExpr
effStressExpr :: PExpr
effStressExpr = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
totNormStress forall r. ExprC r => r -> r -> r
$- forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
porePressure

effStressDesc :: Sentence
effStressDesc :: Sentence
effStressDesc = (UnitalChunk
totNormStress forall q r.
(HasSymbol q, HasUID q, Referable r, HasShortName r) =>
q -> r -> Sentence
`definedIn'''` DataDefinition
normStressDD !.)