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 = Integer -> Integer -> Expr
forall r. (ExprC r, LiteralC r) => Integer -> Integer -> r
frac Integer
1 Integer
1000 Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$* [(Expr, Expr)] -> Expr
forall r. ExprC r => [(r, r)] -> r
incompleteCase ((Double -> Double -> (Expr, Expr))
-> [Double] -> [Double] -> [(Expr, Expr)]
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 = (Double -> Expr
forall r. LiteralC r => Double -> r
dbl Double
result, ConstrainedChunk -> Expr
forall c. (HasUID c, HasSymbol c) => c -> Expr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy ConstrainedChunk
nomThick Expr -> Expr -> Expr
forall r. ExprC r => r -> r -> r
$= Double -> Expr
forall r. LiteralC r => Double -> r
dbl Double
condition)

hFromtQD :: SimpleQDef
hFromtQD :: SimpleQDef
hFromtQD = UnitaryChunk -> Expr -> SimpleQDef
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 [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] Maybe Derivation
forall a. Maybe a
Nothing String
"minThick" [Sentence
hMin]

{--}

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

loadDFQD :: SimpleQDef
loadDFQD :: SimpleQDef
loadDFQD = QuantityDict -> Expr -> SimpleQDef
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 [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] Maybe Derivation
forall a. Maybe a
Nothing String
"loadDurFactor"
  [[UnitaryChunk] -> Sentence
forall s. (HasSymbol s, HasUID s) => [s] -> Sentence
stdVals [UnitaryChunk
loadDur, UnitaryChunk
sflawParamM], Sentence
ldfConst]

{--}

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

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

glaTyFacQD :: SimpleQDef
glaTyFacQD :: SimpleQDef
glaTyFacQD = DefinedQuantityDict -> Expr -> SimpleQDef
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 [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] Maybe Derivation
forall a. Maybe a
Nothing String
"gTF"
  [Sentence
anGlass, Sentence
ftGlass, Sentence
hsGlass]

{--}

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

standOffDisQD :: SimpleQDef
standOffDisQD :: SimpleQDef
standOffDisQD = UncertQ -> Expr -> SimpleQDef
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 [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] Maybe Derivation
forall a. Maybe a
Nothing String
"standOffDist" []

{--}

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

aspRatQD :: SimpleQDef
aspRatQD :: SimpleQDef
aspRatQD = UncertQ -> Expr -> SimpleQDef
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 [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] Maybe Derivation
forall a. Maybe a
Nothing String
"aspectRatio" [Sentence
aGrtrThanB]

{--}

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

eqTNTWQD :: SimpleQDef
eqTNTWQD :: SimpleQDef
eqTNTWQD = UnitalChunk -> Expr -> SimpleQDef
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 [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] Maybe Derivation
forall a. Maybe a
Nothing String
"eqTNTW" []

{--}

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

calofDemandQD :: SimpleQDef
calofDemandQD :: SimpleQDef
calofDemandQD = UnitalChunk -> Expr -> SimpleQDef
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 [Citation -> DecRef
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> DecRef
dRef Citation
astm2009] Maybe Derivation
forall a. Maybe a
Nothing String
"calofDemand" [Sentence
calofDemandDesc]

-- Additional Notes --
aGrtrThanB :: Sentence
aGrtrThanB :: Sentence
aGrtrThanB = UncertQ -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UncertQ
plateLen Sentence -> Sentence -> Sentence
`S.and_` UncertQ -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UncertQ
plateWidth Sentence -> Sentence -> Sentence
`S.are`
  (ConceptChunk -> Sentence
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 (ModelExpr -> Sentence) -> ModelExpr -> Sentence
forall a b. (a -> b) -> a -> b
$ UncertQ -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
forall r c. (ExprC r, HasUID c, HasSymbol c) => c -> r
sy UncertQ
plateLen ModelExpr -> ModelExpr -> ModelExpr
forall r. ExprC r => r -> r -> r
$>= UncertQ -> ModelExpr
forall c. (HasUID c, HasSymbol c) => c -> ModelExpr
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` CI -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase CI
t Sentence -> Sentence -> Sentence
+:+. IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase IdeaDict
glass

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

hMin :: Sentence
hMin :: Sentence
hMin = ConstrainedChunk -> Sentence
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 (UnitaryChunk -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch UnitaryChunk
minThick) Sentence -> Sentence -> Sentence
`S.toThe` UnitaryChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase UnitaryChunk
minThick)

ldfConst :: Sentence
ldfConst :: Sentence
ldfConst = QuantityDict -> Sentence
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
+:+. ConceptInstance -> Sentence
forall r. (Referable r, HasShortName r) => r -> Sentence
fromSource ConceptInstance
assumpLDFC

arRef, gtfRef, hRef :: Sentence
arRef :: Sentence
arRef  = DataDefinition -> Sentence
forall r.
(Referable r, HasShortName r, DefinesQuantity r) =>
r -> Sentence
definedIn  DataDefinition
aspRat
gtfRef :: Sentence
gtfRef = DataDefinition -> Sentence
forall r.
(Referable r, HasShortName r, DefinesQuantity r) =>
r -> Sentence
definedIn  DataDefinition
glaTyFac
hRef :: Sentence
hRef   = DataDefinition -> Sentence -> Sentence
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 ((s -> Sentence) -> [s] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map s -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch [s]
s) Sentence -> Sentence -> Sentence
+:+ Sentence
sent Sentence -> Sentence -> Sentence
+:+. ConceptInstance -> Sentence
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence
refS ConceptInstance
assumpSV
  where sent :: Sentence
sent = case [s]
s of [ ]   -> String -> Sentence
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"