module Drasil.GlassBR.DataDefs (dataDefs, aspRat, glaTyFac, glaTyFacQD, gtfRef,
  hFromt, hFromtQD, loadDF, standOffDis, eqTNTWDD, calofDemand, aGrtrThanB,
  arRef, hRef, configFp, stdVals) where

import Control.Lens ((^.))
import Language.Drasil
import Prelude hiding (log, exp, sqrt)
import Theory.Drasil (DataDefinition, ddE)
import qualified Language.Drasil.Sentence.Combinators as S

import Data.Drasil.Concepts.Math (parameter)
import Data.Drasil.Concepts.PhysicalProperties (dimension)

import Drasil.GlassBR.Assumptions (assumpSV, assumpLDFC)
import Drasil.GlassBR.Concepts (annealed, fullyT, glass, heatS)
import Drasil.GlassBR.Figures (demandVsSDFig)
import Drasil.GlassBR.References (astm2009)
import Drasil.GlassBR.Unitals

----------------------
-- DATA DEFINITIONS --
----------------------

dataDefs :: [DataDefinition]
dataDefs :: [DataDefinition]
dataDefs = [DataDefinition
hFromt, DataDefinition
loadDF, DataDefinition
glaTyFac, DataDefinition
standOffDis, DataDefinition
aspRat, DataDefinition
eqTNTWDD, DataDefinition
calofDemand]

{--}

hFromtEq :: Relation
hFromtEq :: Expr
hFromtEq = forall r. (ExprC r, LiteralC r) => Integer -> Integer -> r
frac Integer
1 Integer
1000 forall r. ExprC r => r -> r -> r
`mulRe` forall r. ExprC r => [(r, r)] -> r
incompleteCase (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Double -> Double -> (Expr, Expr)
hFromtHelper
  [Double]
actualThicknesses [Double]
nominalThicknesses)

hFromtHelper :: Double -> Double -> (Expr, Relation)
hFromtHelper :: Double -> Double -> (Expr, Expr)
hFromtHelper Double
result Double
condition = (forall r. LiteralC r => Double -> r
dbl Double
result, forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrainedChunk
nomThick forall r. ExprC r => r -> r -> r
$= forall r. LiteralC r => Double -> r
dbl Double
condition)

hFromtQD :: SimpleQDef
hFromtQD :: SimpleQDef
hFromtQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitaryChunk
minThick Expr
hFromtEq

hFromt :: DataDefinition
hFromt :: DataDefinition
hFromt = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
hFromtQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] forall a. Maybe a
Nothing String
"minThick" [Sentence
hMin]

{--}

loadDFEq :: Expr
loadDFEq :: Expr
loadDFEq = (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitaryChunk
loadDur forall r. ExprC r => r -> r -> r
$/ forall r. LiteralC r => Integer -> r
exactDbl Integer
60) forall r. ExprC r => r -> r -> r
$^ (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitaryChunk
sflawParamM forall r. ExprC r => r -> r -> r
$/ forall r. LiteralC r => Integer -> r
exactDbl Integer
16)

loadDFQD :: SimpleQDef
loadDFQD :: SimpleQDef
loadDFQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef QuantityDict
lDurFac Expr
loadDFEq

loadDF :: DataDefinition
loadDF :: DataDefinition
loadDF = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
loadDFQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] forall a. Maybe a
Nothing String
"loadDurFactor"
  [forall s. (HasSymbol s, HasUID s) => [s] -> Sentence
stdVals [UnitaryChunk
loadDur, UnitaryChunk
sflawParamM], Sentence
ldfConst]

{--}

glaTyFacEq :: Expr
glaTyFacEq :: Expr
glaTyFacEq = forall r. ExprC r => [(r, r)] -> r
incompleteCase (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Integer -> String -> (Expr, Expr)
glaTyFacHelper [Integer]
glassTypeFactors forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall c. CommonIdea c => c -> String
abrv forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) GlassType
glassType)

glaTyFacHelper :: Integer -> String -> (Expr, Relation)
glaTyFacHelper :: Integer -> String -> (Expr, Expr)
glaTyFacHelper Integer
result String
condition = (forall r. LiteralC r => Integer -> r
int Integer
result, forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrConcept
glassTypeCon forall r. ExprC r => r -> r -> r
$= forall r. LiteralC r => String -> r
str String
condition)

glaTyFacQD :: SimpleQDef
glaTyFacQD :: SimpleQDef
glaTyFacQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef DefinedQuantityDict
gTF Expr
glaTyFacEq

glaTyFac :: DataDefinition
glaTyFac :: DataDefinition
glaTyFac = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
glaTyFacQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] forall a. Maybe a
Nothing String
"gTF"
  [Sentence
anGlass, Sentence
ftGlass, Sentence
hsGlass]

{--}

standOffDisEq :: Expr
standOffDisEq :: Expr
standOffDisEq = forall r. ExprC r => r -> r
sqrt (forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitaryChunk
sdx) forall r. ExprC r => r -> r -> r
`addRe` forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitaryChunk
sdy) forall r. ExprC r => r -> r -> r
`addRe` forall r. (ExprC r, LiteralC r) => r -> r
square (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitaryChunk
sdz))

standOffDisQD :: SimpleQDef
standOffDisQD :: SimpleQDef
standOffDisQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UncertQ
standOffDist Expr
standOffDisEq

standOffDis :: DataDefinition
standOffDis :: DataDefinition
standOffDis = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
standOffDisQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] forall a. Maybe a
Nothing String
"standOffDist" []

{--}

aspRatEq :: Expr
aspRatEq :: Expr
aspRatEq = forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
plateLen forall r. ExprC r => r -> r -> r
$/ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
plateWidth

aspRatQD :: SimpleQDef
aspRatQD :: SimpleQDef
aspRatQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UncertQ
aspectRatio Expr
aspRatEq

aspRat :: DataDefinition
aspRat :: DataDefinition
aspRat = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
aspRatQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] forall a. Maybe a
Nothing String
"aspectRatio" [Sentence
aGrtrThanB]

{--}

eqTNTWEq :: Expr
eqTNTWEq :: Expr
eqTNTWEq = forall r. ExprC r => r -> r -> r
mulRe (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
charWeight) (forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertainChunk
tNT)

eqTNTWQD :: SimpleQDef
eqTNTWQD :: SimpleQDef
eqTNTWQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
eqTNTWeight Expr
eqTNTWEq

eqTNTWDD :: DataDefinition
eqTNTWDD :: DataDefinition
eqTNTWDD = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
eqTNTWQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] forall a. Maybe a
Nothing String
"eqTNTW" []

{--}

calofDemandEq :: Expr
calofDemandEq :: Expr
calofDemandEq = forall r f. (ExprC r, HasUID f, HasSymbol f) => f -> [r] -> r
apply QuantityDict
interpY [forall r. LiteralC r => String -> r
str String
"TSD.txt", forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
standOffDist, forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UnitalChunk
eqTNTWeight]

calofDemandQD :: SimpleQDef
calofDemandQD :: SimpleQDef
calofDemandQD = forall c e. (Quantity c, MayHaveUnit c) => c -> e -> QDefinition e
mkQuantDef UnitalChunk
demand Expr
calofDemandEq

calofDemand :: DataDefinition
calofDemand :: DataDefinition
calofDemand = SimpleQDef
-> [DecRef]
-> Maybe Derivation
-> String
-> [Sentence]
-> DataDefinition
ddE SimpleQDef
calofDemandQD [forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] forall a. Maybe a
Nothing String
"calofDemand" [Sentence
calofDemandDesc]

-- Additional Notes --
aGrtrThanB :: Sentence
aGrtrThanB :: Sentence
aGrtrThanB = forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UncertQ
plateLen Sentence -> Sentence -> Sentence
`S.and_` forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UncertQ
plateWidth Sentence -> Sentence -> Sentence
`S.are`
  (forall n. NamedIdea n => n -> Sentence
plural ConceptChunk
dimension Sentence -> Sentence -> Sentence
`S.the_ofThe` String -> Sentence
S String
"plate") Sentence -> Sentence -> Sentence
`sC` String -> Sentence
S String
"where" Sentence -> Sentence -> Sentence
+:+.
  Sentence -> Sentence
sParen (ModelExpr -> Sentence
eS forall a b. (a -> b) -> a -> b
$ forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
plateLen forall r. ExprC r => r -> r -> r
$>= forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
plateWidth)

anGlass, ftGlass, hsGlass :: Sentence
anGlass :: Sentence
anGlass = CI -> Sentence
glassTypeHelper CI
annealed
ftGlass :: Sentence
ftGlass = CI -> Sentence
glassTypeHelper CI
fullyT
hsGlass :: Sentence
hsGlass = CI -> Sentence
glassTypeHelper CI
heatS

glassTypeHelper :: CI -> Sentence
glassTypeHelper :: CI -> Sentence
glassTypeHelper CI
t = CI -> Sentence
getAcc CI
t Sentence -> Sentence -> Sentence
`S.is` forall n. NamedIdea n => n -> Sentence
phrase CI
t Sentence -> Sentence -> Sentence
+:+. forall n. NamedIdea n => n -> Sentence
phrase IdeaDict
glass

calofDemandDesc :: Sentence
calofDemandDesc :: Sentence
calofDemandDesc =
  [Sentence] -> Sentence
foldlSent [forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
demand Sentence -> Sentence -> Sentence
`sC` Sentence
EmptyS Sentence -> Sentence -> Sentence
`S.or_` forall n. NamedIdea n => n -> Sentence
phrase ConceptChunk
demandq Sentence -> Sentence -> Sentence
`sC` Sentence
EmptyS Sentence -> Sentence -> Sentence
`S.isThe`
  (ConceptChunk
demandq forall s a. s -> Getting a s a -> a
^. forall c. Definition c => Lens' c Sentence
defn), String -> Sentence
S String
"obtained from", forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS LabelledContent
demandVsSDFig,
  String -> Sentence
S String
"by interpolation using", forall n. NamedIdea n => n -> Sentence
phrase UncertQ
standOffDist, Sentence -> Sentence
sParen (forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UncertQ
standOffDist)
  Sentence -> Sentence -> Sentence
`S.and_` forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
eqTNTWeight, String -> Sentence
S String
"as" Sentence -> Sentence -> Sentence
+:+. forall n. NamedIdea n => n -> Sentence
plural ConceptChunk
parameter, forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitalChunk
eqTNTWeight,
  String -> Sentence
S String
"is defined in" Sentence -> Sentence -> Sentence
+:+. forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS DataDefinition
eqTNTWDD, forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UncertQ
standOffDist Sentence -> Sentence -> Sentence
`S.isThe`
  forall n. NamedIdea n => n -> Sentence
phrase UncertQ
standOffDist, String -> Sentence
S String
"as defined in", forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS DataDefinition
standOffDis]

hMin :: Sentence
hMin :: Sentence
hMin = forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch ConstrainedChunk
nomThick Sentence -> Sentence -> Sentence
`S.is` String -> Sentence
S String
"a function that maps from the nominal thickness"
  Sentence -> Sentence -> Sentence
+:+. (Sentence -> Sentence
sParen (forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitaryChunk
minThick) Sentence -> Sentence -> Sentence
`S.toThe` forall n. NamedIdea n => n -> Sentence
phrase UnitaryChunk
minThick)

ldfConst :: Sentence
ldfConst :: Sentence
ldfConst = forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch QuantityDict
lDurFac Sentence -> Sentence -> Sentence
`S.is` String -> Sentence
S String
"assumed to be constant" Sentence -> Sentence -> Sentence
+:+. forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource ConceptInstance
assumpLDFC

arRef, gtfRef, hRef :: Sentence
arRef :: Sentence
arRef  = forall r.
(Referable r, HasShortName r, DefinesQuantity r) =>
r -> Sentence
definedIn  DataDefinition
aspRat
gtfRef :: Sentence
gtfRef = forall r.
(Referable r, HasShortName r, DefinesQuantity r) =>
r -> Sentence
definedIn  DataDefinition
glaTyFac
hRef :: Sentence
hRef   = forall r.
(Referable r, HasShortName r, DefinesQuantity r) =>
r -> Sentence -> Sentence
definedIn' DataDefinition
hFromt (String -> Sentence
S String
"and is based on the nominal thicknesses")

-- List of Configuration Files necessary for DataDefs.hs
configFp :: [String]
configFp :: [String]
configFp = [String
"SDF.txt", String
"TSD.txt"]

--- Helper
stdVals :: (HasSymbol s, HasUID s) => [s] -> Sentence
stdVals :: forall s. (HasSymbol s, HasUID s) => [s] -> Sentence
stdVals [s]
s = SepType -> FoldType -> [Sentence] -> Sentence
foldlList SepType
Comma FoldType
List (forall a b. (a -> b) -> [a] -> [b]
map forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch [s]
s) Sentence -> Sentence -> Sentence
+:+ Sentence
sent Sentence -> Sentence -> Sentence
+:+. forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS ConceptInstance
assumpSV
  where sent :: Sentence
sent = case [s]
s of [ ]   -> forall a. HasCallStack => String -> a
error String
"stdVals needs quantities"
                         [s
_]   -> String -> Sentence
S String
"comes from"
                         (s
_:[s]
_) -> String -> Sentence
S String
"come from"