module Language.Drasil.Data.ODEInfo (
ODEInfo(..), odeInfo, odeInfo', ODEOptions(..), odeOptions, ODEMethod(..)
) where
import Language.Drasil.Chunk.Code (CodeVarChunk)
import Language.Drasil.CodeExpr.Development
import Language.Drasil(makeAODESolverFormat, formEquations,
DifferentialModel(..), ODESolverFormat(..), InitialValueProblem(..))
import Language.Drasil.Chunk.CodeBase (quantvar)
data ODEInfo = ODEInfo {
ODEInfo -> CodeVarChunk
indepVar :: CodeVarChunk,
ODEInfo -> CodeVarChunk
depVar :: CodeVarChunk,
ODEInfo -> [CodeVarChunk]
otherVars :: [CodeVarChunk],
ODEInfo -> CodeExpr
tInit :: CodeExpr,
ODEInfo -> CodeExpr
tFinal :: CodeExpr,
ODEInfo -> [CodeExpr]
initVal :: [CodeExpr],
ODEInfo -> [CodeExpr]
odeSyst :: [CodeExpr],
ODEInfo -> ODEOptions
odeOpts :: ODEOptions
}
odeInfo :: CodeVarChunk -> CodeVarChunk -> [CodeVarChunk] -> CodeExpr -> CodeExpr ->
[CodeExpr] -> [CodeExpr] -> ODEOptions -> ODEInfo
odeInfo :: CodeVarChunk
-> CodeVarChunk
-> [CodeVarChunk]
-> CodeExpr
-> CodeExpr
-> [CodeExpr]
-> [CodeExpr]
-> ODEOptions
-> ODEInfo
odeInfo = CodeVarChunk
-> CodeVarChunk
-> [CodeVarChunk]
-> CodeExpr
-> CodeExpr
-> [CodeExpr]
-> [CodeExpr]
-> ODEOptions
-> ODEInfo
ODEInfo
odeInfo' :: [CodeVarChunk] -> ODEOptions -> DifferentialModel -> InitialValueProblem -> ODEInfo
odeInfo' :: [CodeVarChunk]
-> ODEOptions
-> DifferentialModel
-> InitialValueProblem
-> ODEInfo
odeInfo' [CodeVarChunk]
ovs ODEOptions
opt DifferentialModel
dm InitialValueProblem
ivp = CodeVarChunk
-> CodeVarChunk
-> [CodeVarChunk]
-> CodeExpr
-> CodeExpr
-> [CodeExpr]
-> [CodeExpr]
-> ODEOptions
-> ODEInfo
ODEInfo
(UnitalChunk -> CodeVarChunk
forall c. (Quantity c, MayHaveUnit c) => c -> CodeVarChunk
quantvar (UnitalChunk -> CodeVarChunk) -> UnitalChunk -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ DifferentialModel -> UnitalChunk
_indepVar DifferentialModel
dm)
(ConstrConcept -> CodeVarChunk
forall c. (Quantity c, MayHaveUnit c) => c -> CodeVarChunk
quantvar (ConstrConcept -> CodeVarChunk) -> ConstrConcept -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ DifferentialModel -> ConstrConcept
_depVar DifferentialModel
dm)
[CodeVarChunk]
ovs
(Expr -> CodeExpr
expr (Expr -> CodeExpr) -> Expr -> CodeExpr
forall a b. (a -> b) -> a -> b
$ InitialValueProblem -> Expr
initTime InitialValueProblem
ivp)
(Expr -> CodeExpr
expr (Expr -> CodeExpr) -> Expr -> CodeExpr
forall a b. (a -> b) -> a -> b
$ InitialValueProblem -> Expr
finalTime InitialValueProblem
ivp)
((Expr -> CodeExpr) -> [Expr] -> [CodeExpr]
forall a b. (a -> b) -> [a] -> [b]
map Expr -> CodeExpr
expr ([Expr] -> [CodeExpr]) -> [Expr] -> [CodeExpr]
forall a b. (a -> b) -> a -> b
$ InitialValueProblem -> [Expr]
initValues InitialValueProblem
ivp)
(DifferentialModel -> [CodeExpr]
createFinalExpr DifferentialModel
dm)
ODEOptions
opt
data ODEOptions = ODEOpts {
ODEOptions -> ODEMethod
solveMethod :: ODEMethod,
ODEOptions -> CodeExpr
absTol :: CodeExpr,
ODEOptions -> CodeExpr
relTol :: CodeExpr,
ODEOptions -> CodeExpr
stepSize :: CodeExpr
}
odeOptions :: ODEMethod -> CodeExpr -> CodeExpr -> CodeExpr -> ODEOptions
odeOptions :: ODEMethod -> CodeExpr -> CodeExpr -> CodeExpr -> ODEOptions
odeOptions = ODEMethod -> CodeExpr -> CodeExpr -> CodeExpr -> ODEOptions
ODEOpts
data ODEMethod = RK45 | BDF | Adams
createFinalExpr :: DifferentialModel -> [CodeExpr]
createFinalExpr :: DifferentialModel -> [CodeExpr]
createFinalExpr DifferentialModel
dm = (Expr -> CodeExpr) -> [Expr] -> [CodeExpr]
forall a b. (a -> b) -> [a] -> [b]
map Expr -> CodeExpr
expr ([Expr] -> [CodeExpr]) -> [Expr] -> [CodeExpr]
forall a b. (a -> b) -> a -> b
$ [[Expr]] -> [Unknown] -> [Expr] -> ConstrConcept -> [Expr]
formEquations (ODESolverFormat -> [[Expr]]
coeffVects ODESolverFormat
ode) (ODESolverFormat -> [Unknown]
unknownVect ODESolverFormat
ode) (ODESolverFormat -> [Expr]
constantVect ODESolverFormat
ode) (DifferentialModel -> ConstrConcept
_depVar DifferentialModel
dm)
where ode :: ODESolverFormat
ode = DifferentialModel -> ODESolverFormat
makeAODESolverFormat DifferentialModel
dm