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

import Prelude hiding (tan)
import Language.Drasil
import Theory.Drasil (TheoryModel, tm, ModelKinds(EquationalModel, OthModel))
import Utils.Drasil
import Utils.Drasil.Concepts
import qualified Utils.Drasil.Sentence 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 = [factOfSafety, equilibrium, mcShrStrgth, effStress, newtonSL]

------------- New Chunk -----------
factOfSafety :: TheoryModel
factOfSafety = tm (EquationalModel factOfSafetyQD)
  [qw fs, qw resistiveShear, qw mobilizedShear] ([] :: [ConceptChunk])
  [] [relat factOfSafetyQD] [] [makeCite fredlund1977] "factOfSafety" []

------------------------------------
factOfSafetyQD :: QDefinition
factOfSafetyQD = mkQuantDef' fs factorOfSafety factOfSafetyExpr

factOfSafetyExpr :: Expr
factOfSafetyExpr = sy resistiveShear $/ sy mobilizedShear

--
------------- New Chunk -----------
equilibrium :: TheoryModel
equilibrium = tm (OthModel equilibriumRC)
  [qw fx] ([] :: [ConceptChunk])
  [] [eqRel] [] [makeCite fredlund1977] "equilibrium" [eqDesc]

------------------------------------  
equilibriumRC :: RelationConcept
equilibriumRC = makeRC "equilibriumRC" (nounPhraseSP "equilibrium") eqDesc eqRel

-- FIXME: Variable "i" is a hack.  But we need to sum over something!
eqRel :: Relation
eqRel = foldr (($=) . sumAll (Variable "i") . sy) (int 0) [fx, fy, genericM]

eqDesc :: Sentence
eqDesc = foldlSent [S "For a body in static equilibrium, the net",
  pluralNP (force `and_PP` genericM) +:+. S "acting on the body will cancel out",
  S "Assuming a 2D problem", sParen (makeRef2S assumpENSL) `sC` S "the", getTandS fx `S.and_`
  getTandS fy, S "will be equal to" +:+. E (exactDbl 0), S "All", plural force,
  S "and their", phrase distance, S "from the chosen point of rotation",
  S "will create a net", phrase genericM, S "equal to" +:+ E (exactDbl 0)]

--
------------- New Chunk -----------
mcShrStrgth :: TheoryModel
mcShrStrgth = tm (OthModel mcShrStrgthRC)
  [qw shrStress, qw effNormStress, qw fricAngle, qw effCohesion] 
  ([] :: [ConceptChunk])
  [] [mcShrStrgthRel] [] [makeCite fredlund1977] "mcShrStrgth" [mcShrStrgthDesc]

------------------------------------
mcShrStrgthRC :: RelationConcept
mcShrStrgthRC = makeRC "mcShrStrgthRC" (nounPhraseSP "Mohr-Coulumb shear strength")
  mcShrStrgthDesc mcShrStrgthRel

mcShrStrgthRel :: Relation
mcShrStrgthRel = sy shrStress $= (sy effNormStress `mulRe` tan (sy fricAngle) `addRe` sy effCohesion)

mcShrStrgthDesc :: Sentence
mcShrStrgthDesc = foldlSent [S "In this", phrase model, S "the",
  getTandS shrStress, S "is proportional to the product of the",
  phrase effNormStress, ch effNormStress, S "on the plane", 
  S "with its static", phrase friction, S "in the angular form" +:+.
  E (tan $ sy fricAngle),
  S "The", ch shrStress, S "versus", ch effNormStress,
  S "relationship is not truly",
  phrase linear `sC` S "but assuming the", phrase nrmFSubWat, 
  S "is strong enough, it can be approximated with a", phrase linear,
  S "fit", sParen (makeRef2S assumpSBSBISL), S "where the", phrase effCohesion, 
  ch effCohesion, S "represents the", ch shrStress,
  S "intercept of the fitted line"]

--
------------- New Chunk -----------
effStress :: TheoryModel
effStress = tm (OthModel effStressRC)
  [qw effectiveStress, qw totNormStress, qw porePressure] 
  ([] :: [ConceptChunk])
  [] [effStressRel] [] [makeCite fredlund1977] "effStress" [effStressDesc]

------------------------------------
effStressRC :: RelationConcept
effStressRC = makeRC "effStressRC"
  (nounPhraseSP "effective stress") effStressDesc effStressRel -- l4

effStressRel :: Relation
effStressRel = sy effectiveStress $= sy totNormStress $- sy porePressure<commit_msg>Convert effStressTM into EquationalModel<commit_after>{-# LANGUAGE PostfixOperators #-}
module Drasil.SSP.TMods (tMods, factOfSafety, equilibrium, mcShrStrgth, effStress) 
  where

import Control.Lens ((^.))
import Prelude hiding (tan)

import Language.Drasil
import Theory.Drasil (TheoryModel, tm, tm', ModelKinds(EquationalModel, OthModel))
import Utils.Drasil
import Utils.Drasil.Concepts
import qualified Utils.Drasil.Sentence 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 = [factOfSafety, equilibrium, mcShrStrgth, effStress, newtonSL]

------------- New Chunk -----------
factOfSafety :: TheoryModel
factOfSafety = tm (EquationalModel factOfSafetyQD)
  [qw fs, qw resistiveShear, qw mobilizedShear] ([] :: [ConceptChunk])
  [] [relat factOfSafetyQD] [] [makeCite fredlund1977] "factOfSafety" []

------------------------------------
factOfSafetyQD :: QDefinition
factOfSafetyQD = mkQuantDef' fs factorOfSafety factOfSafetyExpr

factOfSafetyExpr :: Expr
factOfSafetyExpr = sy resistiveShear $/ sy mobilizedShear

--
------------- New Chunk -----------
equilibrium :: TheoryModel
equilibrium = tm (OthModel equilibriumRC)
  [qw fx] ([] :: [ConceptChunk])
  [] [eqRel] [] [makeCite fredlund1977] "equilibrium" [eqDesc]

------------------------------------  
equilibriumRC :: RelationConcept
equilibriumRC = makeRC "equilibriumRC" (nounPhraseSP "equilibrium") eqDesc eqRel

-- FIXME: Variable "i" is a hack.  But we need to sum over something!
eqRel :: Relation
eqRel = foldr (($=) . sumAll (Variable "i") . sy) (int 0) [fx, fy, genericM]

eqDesc :: Sentence
eqDesc = foldlSent [S "For a body in static equilibrium, the net",
  pluralNP (force `and_PP` genericM) +:+. S "acting on the body will cancel out",
  S "Assuming a 2D problem", sParen (makeRef2S assumpENSL) `sC` S "the", getTandS fx `S.and_`
  getTandS fy, S "will be equal to" +:+. E (exactDbl 0), S "All", plural force,
  S "and their", phrase distance, S "from the chosen point of rotation",
  S "will create a net", phrase genericM, S "equal to" +:+ E (exactDbl 0)]

--
------------- New Chunk -----------
mcShrStrgth :: TheoryModel
mcShrStrgth = tm (OthModel mcShrStrgthRC)
  [qw shrStress, qw effNormStress, qw fricAngle, qw effCohesion] 
  ([] :: [ConceptChunk])
  [] [mcShrStrgthRel] [] [makeCite fredlund1977] "mcShrStrgth" [mcShrStrgthDesc]

------------------------------------
mcShrStrgthRC :: RelationConcept
mcShrStrgthRC = makeRC "mcShrStrgthRC" (nounPhraseSP "Mohr-Coulumb shear strength")
  mcShrStrgthDesc mcShrStrgthRel

mcShrStrgthRel :: Relation
mcShrStrgthRel = sy shrStress $= (sy effNormStress `mulRe` tan (sy fricAngle) `addRe` sy effCohesion)

mcShrStrgthDesc :: Sentence
mcShrStrgthDesc = foldlSent [S "In this", phrase model, S "the",
  getTandS shrStress, S "is proportional to the product of the",
  phrase effNormStress, ch effNormStress, S "on the plane", 
  S "with its static", phrase friction, S "in the angular form" +:+.
  E (tan $ sy fricAngle),
  S "The", ch shrStress, S "versus", ch effNormStress,
  S "relationship is not truly",
  phrase linear `sC` S "but assuming the", phrase nrmFSubWat, 
  S "is strong enough, it can be approximated with a", phrase linear,
  S "fit", sParen (makeRef2S assumpSBSBISL), S "where the", phrase effCohesion, 
  ch effCohesion, S "represents the", ch shrStress,
  S "intercept of the fitted line"]

--
------------- New Chunk -----------
effStress :: TheoryModel
effStress = tm' "effectiveStressTM" (EquationalModel effStressQD)
  [qw effectiveStress, qw totNormStress, qw porePressure] 
  ([] :: [ConceptChunk])
  [] [relat effStressQD] [] [makeCite fredlund1977] "effStress" [effStressDesc]

------------------------------------
effStressQD :: QDefinition
effStressQD = fromEqnSt' (effectiveStress ^. uid) (nounPhraseSP "effective stress")
 effStressDesc (symbol effectiveStress) Real effStressExpr

effStressExpr :: Expr
effStressExpr = sy totNormStress $- sy porePressure
{'fraction_non_alphanumeric': 0.16574524546660768, 'fraction_numerical': 0.005860238832375055, 'mean_word_length': 3.6889580093312597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '658278', 'n_tokens_mistral': 3333, 'n_tokens_neox': 3194, 'n_words': 880}