-- | Define and collect information about ODEs and ODE solvers from various libraries.
module Data.Drasil.ExternalLibraries.ODELibraries (
  -- * SciPy Library (Python)
  scipyODEPckg,
  -- * Oslo Library (C#)
  osloPckg, arrayVecDepVar,
  -- * Apache Commons (Java)
  apacheODEPckg,
  -- * Odeint (C++)
  odeintPckg, diffCodeChunk,
  odeInfoChunks
) where

import Control.Lens ((^.), _1, _2, over)

import Drasil.Database (HasUID(..), (+++), mkUid)
import Language.Drasil (HasSymbol(symbol), MayHaveUnit(getUnit),
  HasSpace(typ), Space (Actor, Natural, Real, Void, Boolean, String, Array,
  Vect, Reference), implVar, implVar', compoundPhrase, nounPhrase, nounPhraseSP,
  label, sub, Idea(getA), NamedIdea(term), Stage(..), Definition (defn), (+:+),
  Sentence (S), DefinedQuantityDict, dqdWr, implVarAU')

import Drasil.Code.CodeExpr
import Drasil.Code.CodeExpr.Development
import Drasil.Code.CodeVar (CodeVarChunk (..), CodeFuncChunk, quantvar, quantfunc,
  listToArray)
import Language.Drasil.Chunk.NamedArgument (NamedArgument, narg)
import Language.Drasil.Code.Lang (Lang(..))
import Language.Drasil.Code.ExternalLibrary
import Language.Drasil.Code.ExternalLibraryCall
import Language.Drasil.Data.ODEInfo (ODEInfo(..), ODEOptions(..), ODEMethod(..))
import Language.Drasil.Data.ODELibPckg (ODELibPckg(..), mkODELib, mkODELibNoPath)
import Language.Drasil.Mod (pubStateVar, privStateVar, FuncStmt(..))

-- SciPy Library (Python)

-- | [SciPy](https://www.scipy.org/) ODE library package.
scipyODEPckg :: ODELibPckg
scipyODEPckg :: ODELibPckg
scipyODEPckg = String
-> String
-> [DefinedQuantityDict]
-> ExternalLibrary
-> (ODEInfo -> ExternalLibraryCall)
-> [Lang]
-> ODELibPckg
mkODELibNoPath String
"SciPy" String
"1.4.1" [DefinedQuantityDict]
scipyODESymbols ExternalLibrary
scipyODE
  ODEInfo -> ExternalLibraryCall
scipyCall [Lang
Python]

scipyODE :: ExternalLibrary
scipyODE :: ExternalLibrary
scipyODE = ExternalLibrary -> ExternalLibrary
externalLib [
  Step -> StepGroup
mandatoryStep (Step -> StepGroup) -> Step -> StepGroup
forall a b. (a -> b) -> a -> b
$ FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libFunctionWithResult String
scipyImport
    CodeFuncChunk
odefunc [
      CodeFuncChunk -> [Parameter] -> Step -> Argument
functionArg CodeFuncChunk
f (Space -> Parameter
unnamedParam (Space -> Parameter) -> [Space] -> [Parameter]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Space
Real, Space -> Space
Array Space
Real])
      Step
returnExprList] CodeVarChunk
r,
  [Step] -> StepGroup
choiceStep [
    [Argument] -> Step
setIntegratorMethod [Argument
vode, String -> Argument
methodArg String
"adams", Argument
atol, Argument
rtol],
    [Argument] -> Step
setIntegratorMethod [Argument
vode, String -> Argument
methodArg String
"bdf", Argument
atol, Argument
rtol],
    [Argument] -> Step
setIntegratorMethod [CodeExpr -> Argument
lockedArg (String -> CodeExpr
forall r. LiteralC r => String -> r
str String
"dopri5"), Argument
atol, Argument
rtol]],
  [Step] -> StepGroup
mandatorySteps [FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeVarChunk -> CodeFuncChunk -> [Argument] -> FunctionInterface
libMethod String
scipyImport CodeVarChunk
r
      CodeFuncChunk
setInitVal [Space -> Argument
inlineArg Space
Real, Space -> Argument
inlineArg Space
Real],
    Step
initSolListWithVal,
    FunctionInterface
-> CodeVarChunk
-> CodeVarChunk
-> FunctionInterface
-> CodeVarChunk
-> Step
solveAndPopulateWhile (String
-> CodeVarChunk -> CodeFuncChunk -> [Argument] -> FunctionInterface
libMethod String
scipyImport CodeVarChunk
r CodeFuncChunk
successful []) CodeVarChunk
r CodeVarChunk
t
      (String
-> CodeVarChunk -> CodeFuncChunk -> [Argument] -> FunctionInterface
libMethod String
scipyImport CodeVarChunk
r CodeFuncChunk
integrateStep [Space -> Argument
inlineArg Space
Real]) CodeVarChunk
yList]]

scipyCall :: ODEInfo -> ExternalLibraryCall
scipyCall :: ODEInfo -> ExternalLibraryCall
scipyCall ODEInfo
info = ExternalLibraryCall -> ExternalLibraryCall
externalLibCall [
  StepFill -> StepGroupFill
mandatoryStepFill (StepFill -> StepGroupFill) -> StepFill -> StepGroupFill
forall a b. (a -> b) -> a -> b
$ FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill [[ParameterFill] -> StepFill -> ArgumentFill
functionArgFill
    (CodeVarChunk -> ParameterFill
unnamedParamFill (CodeVarChunk -> ParameterFill)
-> [CodeVarChunk] -> [ParameterFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ODEInfo -> CodeVarChunk
indepVar ODEInfo
info, ODEInfo -> CodeVarChunk
depVar ODEInfo
info])
    ([CodeExpr] -> StepFill
returnExprListFill ([CodeExpr] -> StepFill) -> [CodeExpr] -> StepFill
forall a b. (a -> b) -> a -> b
$ ODEInfo -> [CodeExpr]
odeSyst ODEInfo
info)],
  (Int -> StepFill -> StepGroupFill)
-> (Int, StepFill) -> StepGroupFill
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> StepFill -> StepGroupFill
choiceStepFill (ODEMethod -> (Int, StepFill)
chooseMethod (ODEMethod -> (Int, StepFill)) -> ODEMethod -> (Int, StepFill)
forall a b. (a -> b) -> a -> b
$ ODEOptions -> ODEMethod
solveMethod (ODEOptions -> ODEMethod) -> ODEOptions -> ODEMethod
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info),
  [StepFill] -> StepGroupFill
mandatoryStepsFill [FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill ([ArgumentFill] -> FunctionIntFill)
-> [ArgumentFill] -> FunctionIntFill
forall a b. (a -> b) -> a -> b
$ CodeExpr -> ArgumentFill
basicArgFill
      (CodeExpr -> ArgumentFill) -> [CodeExpr] -> [ArgumentFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [ODEInfo -> [CodeExpr]
initVal ODEInfo
info], ODEInfo -> CodeExpr
tInit ODEInfo
info],
    CodeVarChunk -> CodeExpr -> StepFill
initSolListWithValFill (ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False) ([[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [ODEInfo -> [CodeExpr]
initVal ODEInfo
info]),
    FunctionIntFill
-> CodeExpr -> FunctionIntFill -> CodeVarChunk -> StepFill
solveAndPopulateWhileFill ([ArgumentFill] -> FunctionIntFill
libCallFill []) (ODEInfo -> CodeExpr
tFinal ODEInfo
info)
    ([ArgumentFill] -> FunctionIntFill
libCallFill [CodeExpr -> ArgumentFill
basicArgFill (CodeVarChunk -> CodeVarChunk -> CodeExpr
forall r. CodeExprC r => CodeVarChunk -> CodeVarChunk -> r
field CodeVarChunk
r CodeVarChunk
t CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
$+ ODEOptions -> CodeExpr
stepSize (ODEInfo -> ODEOptions
odeOpts ODEInfo
info))])
    (ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False)]]
  where chooseMethod :: ODEMethod -> (Int, StepFill)
chooseMethod ODEMethod
Adams = (Int
0, StepFill
solveMethodFill)
        chooseMethod ODEMethod
BDF = (Int
1, StepFill
solveMethodFill)
        chooseMethod ODEMethod
RK45 = (Int
2, StepFill
solveMethodFill)
        solveMethodFill :: StepFill
solveMethodFill = FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill ([ArgumentFill] -> FunctionIntFill)
-> [ArgumentFill] -> FunctionIntFill
forall a b. (a -> b) -> a -> b
$ CodeExpr -> ArgumentFill
basicArgFill
          (CodeExpr -> ArgumentFill) -> [CodeExpr] -> [ArgumentFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ODEOptions -> CodeExpr
absTol (ODEOptions -> CodeExpr) -> ODEOptions -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info, ODEOptions -> CodeExpr
relTol (ODEOptions -> CodeExpr) -> ODEOptions -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info]

scipyImport :: String
scipyImport :: String
scipyImport = String
"scipy.integrate"

atol, rtol, vode :: Argument
vode :: Argument
vode = CodeExpr -> Argument
lockedArg (String -> CodeExpr
forall r. LiteralC r => String -> r
str String
"vode")
atol :: Argument
atol = NamedArgument -> Space -> Argument
inlineNamedArg NamedArgument
atolArg Space
Real
rtol :: Argument
rtol = NamedArgument -> Space -> Argument
inlineNamedArg NamedArgument
rtolArg Space
Real

methodArg :: String -> Argument
methodArg :: String -> Argument
methodArg = NamedArgument -> CodeExpr -> Argument
lockedNamedArg NamedArgument
mthdArg (CodeExpr -> Argument)
-> (String -> CodeExpr) -> String -> Argument
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> CodeExpr
forall r. LiteralC r => String -> r
str

setIntegratorMethod :: [Argument] -> Step
setIntegratorMethod :: [Argument] -> Step
setIntegratorMethod = FunctionInterface -> Step
callStep (FunctionInterface -> Step)
-> ([Argument] -> FunctionInterface) -> [Argument] -> Step
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> CodeVarChunk -> CodeFuncChunk -> [Argument] -> FunctionInterface
libMethod String
scipyImport CodeVarChunk
r CodeFuncChunk
setIntegrator

odeT, numpyArrayT :: Space
odeT :: Space
odeT = String -> Space
Actor String
"ode"
numpyArrayT :: Space
numpyArrayT = String -> Space
Actor String
"numpyArray"

-- | Collects variables needed for SciPy's ODEs as 'DefinedQuantityDict's.
scipyODESymbols :: [DefinedQuantityDict]
scipyODESymbols :: [DefinedQuantityDict]
scipyODESymbols = (NamedArgument -> DefinedQuantityDict)
-> [NamedArgument] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NamedArgument -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr [NamedArgument
mthdArg, NamedArgument
atolArg, NamedArgument
rtolArg]
  [DefinedQuantityDict]
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. Semigroup a => a -> a -> a
<> (CodeVarChunk -> DefinedQuantityDict)
-> [CodeVarChunk] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeVarChunk -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr [CodeVarChunk
r, CodeVarChunk
t, CodeVarChunk
y, CodeVarChunk
yList, CodeVarChunk
xAxis, CodeVarChunk
ut, CodeVarChunk
transpose]
  [DefinedQuantityDict]
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. Semigroup a => a -> a -> a
<> (CodeFuncChunk -> DefinedQuantityDict)
-> [CodeFuncChunk] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeFuncChunk -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr [CodeFuncChunk
f, CodeFuncChunk
odefunc, CodeFuncChunk
setIntegrator, CodeFuncChunk
setInitVal, CodeFuncChunk
successful, CodeFuncChunk
integrateStep,
  CodeFuncChunk
arange, CodeFuncChunk
odeintFunc]

mthdArg, atolArg, rtolArg :: NamedArgument
mthdArg :: NamedArgument
mthdArg = DefinedQuantityDict -> NamedArgument
forall q.
(Quantity q, MayHaveUnit q, Concept q) =>
q -> NamedArgument
narg (DefinedQuantityDict -> NamedArgument)
-> DefinedQuantityDict -> NamedArgument
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"method_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"chosen method for solving ODE" String
"chosen methods for solving ODE")
  String
"the chosen method for solving the ODE"
  Space
String (String -> Symbol
label String
"method")
atolArg :: NamedArgument
atolArg = DefinedQuantityDict -> NamedArgument
forall q.
(Quantity q, MayHaveUnit q, Concept q) =>
q -> NamedArgument
narg (DefinedQuantityDict -> NamedArgument)
-> DefinedQuantityDict -> NamedArgument
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"atol_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"absolute tolerance for ODE solution" String
"absolute tolerances for ODE solution")
  String
"the absolute tolerance for the ODE solution"
  Space
Real (String -> Symbol
label String
"atol")
rtolArg :: NamedArgument
rtolArg = DefinedQuantityDict -> NamedArgument
forall q.
(Quantity q, MayHaveUnit q, Concept q) =>
q -> NamedArgument
narg (DefinedQuantityDict -> NamedArgument)
-> DefinedQuantityDict -> NamedArgument
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"rtol_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"relative tolerance for ODE solution" String
"relative tolerances for ODE solution")
  String
"the relative tolerance for the ODE solution"
  Space
Real (String -> Symbol
label String
"rtol")

r, yList, xAxis, ut, transpose :: CodeVarChunk
r :: CodeVarChunk
r = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"r_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"ODE object" String
"ODE objects")
  String
"the ODE object"
  Space
odeT (String -> Symbol
label String
"r")
yList :: CodeVarChunk
yList = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"ylist_scipy")
  (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"current ODE solution as a Python list"
    String
"current ODE solutions as Python lists")
  String
"the current ODE solution converted to a Python list"
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"y.tolist()")
xAxis :: CodeVarChunk
xAxis = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"x_numpy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"Numpy value" String
"Numpy value")
  String
"the x-axis Numpy value"
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"x_axis")
ut :: CodeVarChunk
ut = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"ut_scipy")
  (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"Scipy integrated value" String
"Scipy integrated value")
  String
"the Scipy integrated value"
  Space
numpyArrayT (String -> Symbol
label String
"u_t")
transpose :: CodeVarChunk
transpose = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"transpose_numpy")
  (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"Numpy Array Transpose" String
"Numpy Array Transpose")
  String
"the Numpy Array Transpose"
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"u_t.T") -- (ccObjVar ut transpose) does not seem to work.

f, odefunc, setIntegrator, setInitVal, successful,
  integrateStep, arange, odeintFunc :: CodeFuncChunk
f :: CodeFuncChunk
f = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"f_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"function representing ODE system"
  String
"functions representing ODE system") String
"the function representing the ODE system"
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"f")
odefunc :: CodeFuncChunk
odefunc = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"ode_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"function for defining an ODE for SciPy"
  String
"functions for defining an ODE for SciPy")
  String
"the function for defining an ODE for SciPy" Space
odeT (String -> Symbol
label String
"ode")
setIntegrator :: CodeFuncChunk
setIntegrator = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"set_integrator_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method for setting SciPy integrator" String
"methods for setting SciPy integrator")
  String
"the method for setting the SciPy integrator" Space
Void (String -> Symbol
label String
"set_integrator")
setInitVal :: CodeFuncChunk
setInitVal = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"set_initial_value_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method for setting initial value for ODE for SciPy"
  String
"methods for setting initial value for ODE for SciPy")
  String
"the method for setting the initial value for the ODE for SciPy"
  Space
Void (String -> Symbol
label String
"set_initial_value")
successful :: CodeFuncChunk
successful = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"successful_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method returning True if integration is current successful"
  String
"methods returning True if integration is current successful")
  String
"the method returning True if integration is currently successful"
  Space
Boolean (String -> Symbol
label String
"successful")
integrateStep :: CodeFuncChunk
integrateStep = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"integrate_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method that performs one integration step on an ODE"
  String
"methods that perform one integration step on an ODE")
  String
"the method that performs one integration step on an ODE"
  Space
Void (String -> Symbol
label String
"integrate")
arange :: CodeFuncChunk
arange = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"arrange_numpy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method that returns evenly spaced numbers over a specified interval."
  String
"method that returns evenly spaced numbers over a specified interval.")
  String
"the method that returns evenly spaced numbers over a specified interval."
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"arange")
odeintFunc :: CodeFuncChunk
odeintFunc = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"odeint_scipy") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method that solves a system of ODE using lsoda from the FORTRAN library odepack."
  String
"method that solves a system of ODE using lsoda from the FORTRAN library odepack.")
  String
"the method that solves a system of ODEs using lsoda from the FORTRAN library odepack."
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"odeint")

-- Oslo Library (C#)

-- | [Oslo](https://www.microsoft.com/en-us/research/project/open-solving-library-for-odes/) ODE library package.
osloPckg :: ODELibPckg
osloPckg :: ODELibPckg
osloPckg = String
-> String
-> [DefinedQuantityDict]
-> ExternalLibrary
-> (ODEInfo -> ExternalLibraryCall)
-> String
-> [Lang]
-> ODELibPckg
mkODELib String
"OSLO" String
"1.2" [DefinedQuantityDict]
osloSymbols ExternalLibrary
oslo ODEInfo -> ExternalLibraryCall
osloCall
  String
"Microsoft.Research.Oslo.dll" [Lang
CSharp]

oslo :: ExternalLibrary
oslo :: ExternalLibrary
oslo = ExternalLibrary -> ExternalLibrary
externalLib [
  Step -> StepGroup
mandatoryStep (Step -> StepGroup) -> Step -> StepGroup
forall a b. (a -> b) -> a -> b
$ FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libConstructor String
osloImport
    CodeFuncChunk
vector [Space -> Argument
inlineArg Space
Real] CodeVarChunk
initv,
  [Step] -> StepGroup
choiceStep ([Step] -> StepGroup) -> [Step] -> StepGroup
forall a b. (a -> b) -> a -> b
$ (\CodeFuncChunk
s -> FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libFunctionWithResult String
osloImport CodeFuncChunk
s [Argument]
odeArgs
    CodeVarChunk
sol) (CodeFuncChunk -> Step) -> [CodeFuncChunk] -> [Step]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [CodeFuncChunk
rk547m, CodeFuncChunk
gearBDF],
  [Step] -> StepGroup
mandatorySteps (FunctionInterface -> Step
callStep (String
-> CodeVarChunk
-> CodeFuncChunk
-> [Argument]
-> CodeVarChunk
-> FunctionInterface
libMethodWithResult String
osloImport CodeVarChunk
sol
      CodeFuncChunk
solveFromToStep (Space -> Argument
inlineArg (Space -> Argument) -> [Space] -> [Argument]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Space
Real, Space
Real, Space
Real]) CodeVarChunk
points) Step -> [Step] -> [Step]
forall a. a -> [a] -> [a]
:
    CodeVarChunk
-> CodeVarChunk
-> CodeVarChunk
-> CodeVarChunk
-> CodeVarChunk
-> [Step]
populateSolListOslo CodeVarChunk
points CodeVarChunk
sp CodeVarChunk
x CodeVarChunk
xTemp CodeVarChunk
osloIdx)]

osloCall :: ODEInfo -> ExternalLibraryCall
osloCall :: ODEInfo -> ExternalLibraryCall
osloCall ODEInfo
info = ExternalLibraryCall -> ExternalLibraryCall
externalLibCall [
  StepFill -> StepGroupFill
mandatoryStepFill (StepFill -> StepGroupFill) -> StepFill -> StepGroupFill
forall a b. (a -> b) -> a -> b
$ FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill [CodeExpr -> ArgumentFill
basicArgFill (CodeExpr -> ArgumentFill) -> CodeExpr -> ArgumentFill
forall a b. (a -> b) -> a -> b
$ [[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [ODEInfo -> [CodeExpr]
initVal ODEInfo
info]],
  Int -> StepFill -> StepGroupFill
choiceStepFill (ODEMethod -> Int
forall {a}. Num a => ODEMethod -> a
chooseMethod (ODEMethod -> Int) -> ODEMethod -> Int
forall a b. (a -> b) -> a -> b
$ ODEOptions -> ODEMethod
solveMethod (ODEOptions -> ODEMethod) -> ODEOptions -> ODEMethod
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info) (StepFill -> StepGroupFill) -> StepFill -> StepGroupFill
forall a b. (a -> b) -> a -> b
$ FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$
    [ArgumentFill] -> FunctionIntFill
libCallFill [CodeExpr -> ArgumentFill
basicArgFill (CodeExpr -> ArgumentFill) -> CodeExpr -> ArgumentFill
forall a b. (a -> b) -> a -> b
$ ODEInfo -> CodeExpr
tInit ODEInfo
info,
      [ParameterFill] -> StepFill -> ArgumentFill
functionArgFill (CodeVarChunk -> ParameterFill
unnamedParamFill (CodeVarChunk -> ParameterFill)
-> [CodeVarChunk] -> [ParameterFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ODEInfo -> CodeVarChunk
indepVar ODEInfo
info, ODEInfo -> CodeVarChunk
vecDepVar ODEInfo
info]) (StepFill -> ArgumentFill) -> StepFill -> ArgumentFill
forall a b. (a -> b) -> a -> b
$
        FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill ([ArgumentFill] -> FunctionIntFill)
-> [ArgumentFill] -> FunctionIntFill
forall a b. (a -> b) -> a -> b
$ CodeExpr -> ArgumentFill
userDefinedArgFill (CodeExpr -> ArgumentFill) -> [CodeExpr] -> [ArgumentFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> ODEInfo -> [CodeExpr]
modifiedODESyst String
"arrayvec" ODEInfo
info,
      [CodeExpr] -> ArgumentFill
recordArgFill [ODEOptions -> CodeExpr
absTol (ODEOptions -> CodeExpr) -> ODEOptions -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info, ODEOptions -> CodeExpr
relTol (ODEOptions -> CodeExpr) -> ODEOptions -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info]],
  [StepFill] -> StepGroupFill
mandatoryStepsFill [
    FunctionIntFill -> StepFill
callStepFill ([ArgumentFill] -> FunctionIntFill
libCallFill ([ArgumentFill] -> FunctionIntFill)
-> [ArgumentFill] -> FunctionIntFill
forall a b. (a -> b) -> a -> b
$ CodeExpr -> ArgumentFill
basicArgFill
      (CodeExpr -> ArgumentFill) -> [CodeExpr] -> [ArgumentFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ODEInfo -> CodeExpr
tInit ODEInfo
info, ODEInfo -> CodeExpr
tFinal ODEInfo
info, ODEOptions -> CodeExpr
stepSize (ODEOptions -> CodeExpr) -> ODEOptions -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info]),
    [CodeVarChunk] -> [CodeExpr] -> StepFill
StatementF [ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False] [],
    [CodeVarChunk] -> [CodeExpr] -> StepFill
StatementF [ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False] [Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int (Integer -> CodeExpr) -> Integer -> CodeExpr
forall a b. (a -> b) -> a -> b
$ Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ [CodeExpr] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([CodeExpr] -> Int) -> [CodeExpr] -> Int
forall a b. (a -> b) -> a -> b
$ ODEInfo -> [CodeExpr]
initVal ODEInfo
info]
    ]]
  where chooseMethod :: ODEMethod -> a
chooseMethod ODEMethod
RK45 = a
0
        chooseMethod ODEMethod
BDF = a
1
        chooseMethod ODEMethod
_ = String -> a
forall a. HasCallStack => String -> a
error String
odeMethodUnavailable

odeArgs :: [Argument]
odeArgs :: [Argument]
odeArgs = [Space -> Argument
inlineArg Space
Real, CodeExpr -> Argument
lockedArg (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
initv),
  CodeFuncChunk -> [Parameter] -> Step -> Argument
functionArg CodeFuncChunk
fOslo (Space -> Parameter
unnamedParam (Space -> Parameter) -> [Space] -> [Parameter]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Space
Real, Space
vecT])
    (FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String -> CodeFuncChunk -> [Argument] -> FunctionInterface
constructAndReturn String
osloImport CodeFuncChunk
vector []),
  String
-> CodeFuncChunk -> CodeVarChunk -> [CodeVarChunk] -> Argument
recordArg String
osloImport CodeFuncChunk
options CodeVarChunk
opts [CodeVarChunk
aTol, CodeVarChunk
rTol]]

solT, vecT, optT :: Space
solT :: Space
solT = String -> Space
Actor String
"IEnumerable<SolPoint>"
vecT :: Space
vecT = String -> Space
Actor String
"Vector"
optT :: Space
optT = String -> Space
Actor String
"Options"

osloImport :: String
osloImport :: String
osloImport = String
"Microsoft.Research.Oslo"

-- | Collects variables needed for Oslo's ODEs as 'DefinedQuantityDict's.
osloSymbols :: [DefinedQuantityDict]
osloSymbols :: [DefinedQuantityDict]
osloSymbols = (CodeVarChunk -> DefinedQuantityDict)
-> [CodeVarChunk] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeVarChunk -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr [CodeVarChunk
initv, CodeVarChunk
opts, CodeVarChunk
aTol, CodeVarChunk
rTol, CodeVarChunk
sol, CodeVarChunk
points, CodeVarChunk
sp, CodeVarChunk
x, CodeVarChunk
xTemp, CodeVarChunk
osloIdx] [DefinedQuantityDict]
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. Semigroup a => a -> a -> a
<>
  (CodeFuncChunk -> DefinedQuantityDict)
-> [CodeFuncChunk] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeFuncChunk -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr [CodeFuncChunk
fOslo, CodeFuncChunk
options, CodeFuncChunk
vector, CodeFuncChunk
rk547m, CodeFuncChunk
gearBDF, CodeFuncChunk
solveFromToStep]

initv, opts, aTol, rTol, sol, points, sp, x, xTemp, osloIdx :: CodeVarChunk
initv :: CodeVarChunk
initv = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"initv_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"vector containing the initial values of the dependent variables"
  String
"vectors containing the initial values of the dependent variables")
  String
"the vector containing the initial values of the dependent variables"
  Space
vecT (String -> Symbol
label String
"initv")
opts :: CodeVarChunk
opts = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"opts_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"record containing options for ODE solving"
  String
"records containing options for ODE solving")
  String
"the record containing options for ODE solving"
  Space
optT (String -> Symbol
label String
"opts")
aTol :: CodeVarChunk
aTol = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"aTol_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"absolute tolerance for ODE solution" String
"absolute tolerances for ODE solution")
  String
"the absolute tolerance for the ODE solution"
  Space
Real (String -> Symbol
label String
"AbsoluteTolerance")
rTol :: CodeVarChunk
rTol = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"rTol_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"relative tolerance for ODE solution" String
"relative tolerances for ODE solution")
  String
"the relative tolerance for the ODE solution"
  Space
Real (String -> Symbol
label String
"RelativeTolerance")
sol :: CodeVarChunk
sol = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"sol_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"container for ODE information" String
"containers for ODE information")
  String
"the container for ODE information" Space
solT (String -> Symbol
label String
"sol")
points :: CodeVarChunk
points = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"points_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"container holding ODE solution" String
"containers holding ODE solution")
  String
"the container holding the ODE solution"
  Space
solT (String -> Symbol
label String
"points")
sp :: CodeVarChunk
sp = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"sp_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"ODE solution point"
  String
"ODE solution points") String
"the ODE solution point"
  (String -> Space
Actor String
"SolPoint") (String -> Symbol
label String
"sp")
x :: CodeVarChunk
x = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"X_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"dependent variable"
  String
"dependent variables") String
"the dependent variable"
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"X")
xTemp :: CodeVarChunk
xTemp = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"xTemp_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"temporary list for converting Oslo Vector to list"
  String
"temporary lists for converting Oslo Vector to list")
  String
"the temporary list for converting an Oslo Vector to a list"
  (Space -> Space
Vect Space
Real) (String -> Symbol
label String
"xTemp")
osloIdx :: CodeVarChunk
osloIdx = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"idx_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"index for iterating over Oslo Vector entries"
  String
"indices for iterating over Oslo Vector entries")
  String
"the index for iterating over Oslo Vector entries"
  Space
Natural (String -> Symbol
label String
"i")

-- | Oslo-specific version of 'populateSolList' that converts each
-- @Oslo.Vector@ (@sp.X@) to a @List\<double\>@ before appending it to the
-- solution list, because @Oslo.Vector@ cannot be implicitly converted to
-- @List\<double\>@.
populateSolListOslo :: CodeVarChunk -> CodeVarChunk -> CodeVarChunk
                    -> CodeVarChunk -> CodeVarChunk -> [Step]
populateSolListOslo :: CodeVarChunk
-> CodeVarChunk
-> CodeVarChunk
-> CodeVarChunk
-> CodeVarChunk
-> [Step]
populateSolListOslo CodeVarChunk
arr CodeVarChunk
el CodeVarChunk
fld CodeVarChunk
temp CodeVarChunk
i =
  [([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
Statement (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
    ([CodeVarChunk
s], []) -> CodeVarChunk -> CodeExpr -> FuncStmt
FAsg CodeVarChunk
s ([[CodeExpr]] -> CodeExpr
Matrix [[]])
    ([CodeVarChunk]
_,[CodeExpr]
_) -> String -> FuncStmt
forall a. HasCallStack => String -> a
error String
popErr),
  ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
Statement (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
    ([CodeVarChunk
s], [CodeExpr
solDim]) -> CodeVarChunk -> CodeExpr -> [FuncStmt] -> FuncStmt
FForEach CodeVarChunk
el (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
arr) [[FuncStmt] -> FuncStmt
FMulti
      [ CodeVarChunk -> CodeExpr -> FuncStmt
FDecDef CodeVarChunk
temp ([[CodeExpr]] -> CodeExpr
Matrix [[]])
      , CodeVarChunk
-> CodeExpr -> CodeExpr -> CodeExpr -> [FuncStmt] -> FuncStmt
FFor CodeVarChunk
i (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
0) CodeExpr
solDim (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
1)
        [CodeExpr -> CodeExpr -> FuncStmt
FAppend (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
temp) (CodeVarChunk -> CodeVarChunk -> CodeExpr
forall r. CodeExprC r => CodeVarChunk -> CodeVarChunk -> r
field CodeVarChunk
el CodeVarChunk
fld CodeExpr -> CodeExpr -> CodeExpr
forall r. ExprC r => r -> r -> r
`idx` CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
i)]
      , CodeExpr -> CodeExpr -> FuncStmt
FAppend (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
s) (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
temp)
      ]]
    ([CodeVarChunk]
_,[CodeExpr]
_) -> String -> FuncStmt
forall a. HasCallStack => String -> a
error String
popErr)]
  where popErr :: String
popErr = String
"Fill for populateSolListOslo should provide one CodeChunk and one dimension Expr"

fOslo, options, vector, rk547m, gearBDF, solveFromToStep :: CodeFuncChunk
fOslo :: CodeFuncChunk
fOslo = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"f_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"function representing ODE system" String
"functions representing ODE system")
  String
"the function representing the ODE system"
  Space
vecT (String -> Symbol
label String
"f")
options :: CodeFuncChunk
options = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"Options_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"constructor for Options record" String
"constructors for Options record")
  String
"the constructor for the Options record"
  Space
optT (String -> Symbol
label String
"Options")
vector :: CodeFuncChunk
vector = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"Vector_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"constructor for an OSLO Vector" String
"constructors for an OSLO Vector")
  String
"the constructor for an OSLO Vector"
  Space
vecT (String -> Symbol
label String
"Vector")
rk547m :: CodeFuncChunk
rk547m = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"RK547M_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"function for initiating an ODE to be solved by Runge-Kutta method"
  String
"functions for initiating an ODE to be solved by Runge-Kutta method")
  String
"the function for initiating an ODE to be solved by the Runge-Kutta method"
  Space
solT (String -> Symbol
label String
"Ode.RK547M")
gearBDF :: CodeFuncChunk
gearBDF = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"GearBDF_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"function for initiating an ODE to be solved by Gear's BDF method"
  String
"functions for initiating an ODE to be solved by Gear's BDF method")
  String
"the function for initiating an ODE to be solved by Gear's BDF method"
  Space
solT (String -> Symbol
label String
"Ode.GearBDF")
solveFromToStep :: CodeFuncChunk
solveFromToStep = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"SolveFromToStep_oslo") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method for solving an ODE given a time range"
  String
"methods for solving an ODE given a time range")
  String
"the method for solving an ODE given a time range"
  Space
solT (String -> Symbol
label String
"SolveFromToStep")

vecDepVar :: ODEInfo -> CodeVarChunk
vecDepVar :: ODEInfo -> CodeVarChunk
vecDepVar ODEInfo
info = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> Sentence -> Space -> Symbol -> DefinedQuantityDict
implVar' (CodeVarChunk
dv CodeVarChunk -> Getting UID CodeVarChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeVarChunk UID
forall c. HasUID c => Getter c UID
Getter CodeVarChunk UID
uid) (CodeVarChunk
dv CodeVarChunk
-> Getting (NPG Symbol) CodeVarChunk (NPG Symbol) -> NPG Symbol
forall s a. s -> Getting a s a -> a
^. Getting (NPG Symbol) CodeVarChunk (NPG Symbol)
forall c. NamedIdea c => Lens' c (NPG Symbol)
Lens' CodeVarChunk (NPG Symbol)
term)
  (CodeVarChunk
dv CodeVarChunk -> Getting Sentence CodeVarChunk Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence CodeVarChunk Sentence
forall c. Definition c => Lens' c Sentence
Lens' CodeVarChunk Sentence
defn) Space
vecT (Symbol -> Symbol -> Symbol
sub (CodeVarChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol CodeVarChunk
dv Stage
Implementation) (String -> Symbol
label String
"vec"))
  where dv :: CodeVarChunk
dv = ODEInfo -> CodeVarChunk
depVar ODEInfo
info

-- Hack required because
-- | Oslo's Vector type behaves like an array, so needs to
-- be represented as one or else will hit type errors in GOOL.
arrayVecDepVar :: ODEInfo -> CodeVarChunk
arrayVecDepVar :: ODEInfo -> CodeVarChunk
arrayVecDepVar ODEInfo
info = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> Sentence -> Space -> Symbol -> DefinedQuantityDict
implVar' (CodeVarChunk
dv CodeVarChunk -> String -> UID
forall a. HasUID a => a -> String -> UID
+++ String
"vec")
  (CodeVarChunk
dv CodeVarChunk
-> Getting (NPG Symbol) CodeVarChunk (NPG Symbol) -> NPG Symbol
forall s a. s -> Getting a s a -> a
^. Getting (NPG Symbol) CodeVarChunk (NPG Symbol)
forall c. NamedIdea c => Lens' c (NPG Symbol)
Lens' CodeVarChunk (NPG Symbol)
term) (CodeVarChunk
dv CodeVarChunk -> Getting Sentence CodeVarChunk Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence CodeVarChunk Sentence
forall c. Definition c => Lens' c Sentence
Lens' CodeVarChunk Sentence
defn) (CodeVarChunk
dv CodeVarChunk -> Getting Space CodeVarChunk Space -> Space
forall s a. s -> Getting a s a -> a
^. Getting Space CodeVarChunk Space
forall c. HasSpace c => Getter c Space
Getter CodeVarChunk Space
typ)
  (Symbol -> Symbol -> Symbol
sub (CodeVarChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol CodeVarChunk
dv Stage
Implementation) (String -> Symbol
label String
"vec"))
  where dv :: CodeVarChunk
dv = CodeVarChunk -> CodeVarChunk
listToArray (CodeVarChunk -> CodeVarChunk) -> CodeVarChunk -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ ODEInfo -> CodeVarChunk
depVar ODEInfo
info

-- Apache Commons (Java)

-- | [Apache Commons](https://commons.apache.org/) ODE library package.
apacheODEPckg :: ODELibPckg
apacheODEPckg :: ODELibPckg
apacheODEPckg = String
-> String
-> [DefinedQuantityDict]
-> ExternalLibrary
-> (ODEInfo -> ExternalLibraryCall)
-> String
-> [Lang]
-> ODELibPckg
mkODELib String
"Apache" String
"3.6.1" [DefinedQuantityDict]
apacheODESymbols ExternalLibrary
apacheODE ODEInfo -> ExternalLibraryCall
apacheODECall
  String
"lib/commons-math3-3.6.1.jar" [Lang
Java]

apacheODE :: ExternalLibrary
apacheODE :: ExternalLibrary
apacheODE = ExternalLibrary -> ExternalLibrary
externalLib [
  [Step] -> StepGroup
choiceStep [
    FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ [String]
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libConstructorMultiReqs [String
apacheImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"nonstiff." String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
adams,
      String
foiImp] CodeFuncChunk
adamsC (CodeExpr -> Argument
lockedArg (Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int Integer
3) Argument -> [Argument] -> [Argument]
forall a. a -> [a] -> [a]
: [Argument]
itArgs) CodeVarChunk
it,
    FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ [String]
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libConstructorMultiReqs [String
apacheImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"nonstiff." String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
dp54,
      String
foiImp] CodeFuncChunk
dp54C [Argument]
itArgs CodeVarChunk
it],
  [Step] -> StepGroup
mandatorySteps [FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeVarChunk -> CodeFuncChunk -> [Argument] -> FunctionInterface
libMethod String
foiImp CodeVarChunk
it CodeFuncChunk
addStepHandler [
      [String]
-> String -> CodeVarChunk -> CodeFuncChunk -> ClassInfo -> Argument
customObjArg [String
shImp, String
siImp]
        String
"Class defining additional behaviour for each step of an ODE solution"
        CodeVarChunk
stepHandler CodeFuncChunk
stepHandlerCtor (String -> [MethodInfo] -> ClassInfo
implementation String
sh [
          CodeFuncChunk -> String -> [Parameter] -> [Step] -> MethodInfo
methodInfoNoReturn CodeFuncChunk
initMethod
            String
"initializes step handler with initial conditions"
            (CodeVarChunk -> Parameter
lockedParam (CodeVarChunk -> Parameter) -> [CodeVarChunk] -> [Parameter]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [CodeVarChunk
t0, CodeVarChunk
y0, CodeVarChunk
t]) [CodeVarChunk -> CodeVarChunk -> CodeVarChunk -> Step
initSolListFromArrayJava CodeVarChunk
y0 CodeVarChunk
y0List CodeVarChunk
y0El],
          CodeFuncChunk -> String -> [Parameter] -> [Step] -> MethodInfo
methodInfoNoReturn CodeFuncChunk
handleStep
            String
"appends solution point at each ODE solution step"
            (CodeVarChunk -> Parameter
lockedParam (CodeVarChunk -> Parameter) -> [CodeVarChunk] -> [Parameter]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [CodeVarChunk
interpolator, CodeVarChunk
isLast])
            [FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeVarChunk
-> CodeFuncChunk
-> [Argument]
-> CodeVarChunk
-> FunctionInterface
libMethodWithResult String
siImp CodeVarChunk
interpolator CodeFuncChunk
getInterpState
              [] CodeVarChunk
curr,
            CodeExpr -> CodeVarChunk -> CodeVarChunk -> Step
appendCurrSolFromArrayJava (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
curr) CodeVarChunk
currList CodeVarChunk
currEl]])],
    FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeVarChunk -> CodeFuncChunk -> [Argument] -> FunctionInterface
libMethod String
foiImp CodeVarChunk
it CodeFuncChunk
integrate ([String]
-> String -> CodeVarChunk -> CodeFuncChunk -> ClassInfo -> Argument
customObjArg [String
apacheImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
      String
fode] String
"Class representing an ODE system" CodeVarChunk
ode CodeFuncChunk
odeCtor (String -> [MethodInfo] -> ClassInfo
implementation String
fode
        [CodeFuncChunk -> [Parameter] -> [Step] -> MethodInfo
constructorInfo CodeFuncChunk
odeCtor [] [],
        CodeFuncChunk
-> String -> [Parameter] -> String -> [Step] -> MethodInfo
methodInfo CodeFuncChunk
getDimension String
"returns the ODE system dimension"
          [] String
"dimension of the ODE system" [Step
fixedReturn'],
        CodeFuncChunk -> String -> [Parameter] -> [Step] -> MethodInfo
methodInfoNoReturn CodeFuncChunk
computeDerivatives
          String
"function representation of an ODE system"
          [CodeVarChunk -> Parameter
lockedParam CodeVarChunk
t, Space -> Parameter
unnamedParam (Space -> Space
Array Space
Real), Space -> Parameter
unnamedParam (Space -> Space
Array Space
Real)]
          [Step
assignArrayIndex]]) Argument -> [Argument] -> [Argument]
forall a. a -> [a] -> [a]
:
      [Space -> Argument
inlineArg Space
Real, CodeVarChunk -> Argument
preDefinedArg CodeVarChunk
currVals, Space -> Argument
inlineArg Space
Real,
        CodeVarChunk -> Argument
preDefinedArg CodeVarChunk
currVals]),
    CodeVarChunk -> Step
assignSolFromObj CodeVarChunk
stepHandler]]

apacheODECall :: ODEInfo -> ExternalLibraryCall
apacheODECall :: ODEInfo -> ExternalLibraryCall
apacheODECall ODEInfo
info = ExternalLibraryCall -> ExternalLibraryCall
externalLibCall [
  Int -> StepFill -> StepGroupFill
choiceStepFill (ODEMethod -> Int
forall {a}. Num a => ODEMethod -> a
chooseMethod (ODEMethod -> Int) -> ODEMethod -> Int
forall a b. (a -> b) -> a -> b
$ ODEOptions -> ODEMethod
solveMethod (ODEOptions -> ODEMethod) -> ODEOptions -> ODEMethod
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info) (StepFill -> StepGroupFill) -> StepFill -> StepGroupFill
forall a b. (a -> b) -> a -> b
$ FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$
    [ArgumentFill] -> FunctionIntFill
libCallFill (CodeExpr -> ArgumentFill
basicArgFill (CodeExpr -> ArgumentFill)
-> ((ODEOptions -> CodeExpr) -> CodeExpr)
-> (ODEOptions -> CodeExpr)
-> ArgumentFill
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ODEOptions -> CodeExpr) -> ODEOptions -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info) ((ODEOptions -> CodeExpr) -> ArgumentFill)
-> [ODEOptions -> CodeExpr] -> [ArgumentFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ODEOptions -> CodeExpr
stepSize, ODEOptions -> CodeExpr
stepSize, ODEOptions -> CodeExpr
absTol, ODEOptions -> CodeExpr
relTol]),
  [StepFill] -> StepGroupFill
mandatoryStepsFill [FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill [
      [StateVariable] -> ClassInfoFill -> ArgumentFill
customObjArgFill [CodeVarChunk -> StateVariable
pubStateVar (CodeVarChunk -> StateVariable) -> CodeVarChunk -> StateVariable
forall a b. (a -> b) -> a -> b
$ ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False] ([MethodInfoFill] -> ClassInfoFill
implementationFill [
        [ParameterFill] -> [StepFill] -> MethodInfoFill
methodInfoFill [] [CodeVarChunk -> StepFill
initSolListFromArrayFill (CodeVarChunk -> StepFill) -> CodeVarChunk -> StepFill
forall a b. (a -> b) -> a -> b
$ ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False], [ParameterFill] -> [StepFill] -> MethodInfoFill
methodInfoFill []
          [FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill [], CodeVarChunk -> StepFill
appendCurrSolFill (CodeVarChunk -> StepFill) -> CodeVarChunk -> StepFill
forall a b. (a -> b) -> a -> b
$ ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False]])],
    FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill ([ArgumentFill] -> FunctionIntFill)
-> [ArgumentFill] -> FunctionIntFill
forall a b. (a -> b) -> a -> b
$ [StateVariable] -> ClassInfoFill -> ArgumentFill
customObjArgFill
      (CodeVarChunk -> StateVariable
privStateVar (CodeVarChunk -> StateVariable)
-> [CodeVarChunk] -> [StateVariable]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ODEInfo -> [CodeVarChunk]
otherVars ODEInfo
info)
      ([MethodInfoFill] -> ClassInfoFill
implementationFill [
        [ParameterFill] -> [Initializer] -> [StepFill] -> MethodInfoFill
constructorInfoFill (CodeVarChunk -> ParameterFill
userDefinedParamFill (CodeVarChunk -> ParameterFill)
-> [CodeVarChunk] -> [ParameterFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ODEInfo -> [CodeVarChunk]
otherVars ODEInfo
info)
          ([CodeVarChunk] -> [CodeExpr] -> [Initializer]
forall a b. [a] -> [b] -> [(a, b)]
zip (ODEInfo -> [CodeVarChunk]
otherVars ODEInfo
info) (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy (CodeVarChunk -> CodeExpr) -> [CodeVarChunk] -> [CodeExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ODEInfo -> [CodeVarChunk]
otherVars ODEInfo
info)) [],
        [ParameterFill] -> [StepFill] -> MethodInfoFill
methodInfoFill [] [CodeExpr -> StepFill
fixedStatementFill' (CodeExpr -> StepFill) -> CodeExpr -> StepFill
forall a b. (a -> b) -> a -> b
$ Integer -> CodeExpr
forall r. LiteralC r => Integer -> r
int (Integer -> CodeExpr) -> Integer -> CodeExpr
forall a b. (a -> b) -> a -> b
$ Int -> Integer
forall a. Integral a => a -> Integer
toInteger (Int -> Integer) -> Int -> Integer
forall a b. (a -> b) -> a -> b
$ [CodeExpr] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([CodeExpr] -> Int) -> [CodeExpr] -> Int
forall a b. (a -> b) -> a -> b
$ ODEInfo -> [CodeExpr]
initVal ODEInfo
info],
        [ParameterFill] -> [StepFill] -> MethodInfoFill
methodInfoFill (CodeVarChunk -> ParameterFill
unnamedParamFill (CodeVarChunk -> ParameterFill)
-> (CodeVarChunk -> CodeVarChunk) -> CodeVarChunk -> ParameterFill
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CodeVarChunk -> CodeVarChunk
listToArray (CodeVarChunk -> ParameterFill)
-> [CodeVarChunk] -> [ParameterFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ODEInfo -> CodeVarChunk
depVar ODEInfo
info, CodeVarChunk
ddep])
          [CodeVarChunk -> [CodeExpr] -> StepFill
assignArrayIndexFill (CodeVarChunk -> CodeVarChunk
listToArray CodeVarChunk
ddep) (String -> ODEInfo -> [CodeExpr]
modifiedODESyst String
"array" ODEInfo
info)]])
      ArgumentFill -> [ArgumentFill] -> [ArgumentFill]
forall a. a -> [a] -> [a]
: (CodeExpr -> ArgumentFill) -> [CodeExpr] -> [ArgumentFill]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeExpr -> ArgumentFill
basicArgFill [ODEInfo -> CodeExpr
tInit ODEInfo
info, [[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [ODEInfo -> [CodeExpr]
initVal ODEInfo
info], ODEInfo -> CodeExpr
tFinal ODEInfo
info,
        [[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [ODEInfo -> [CodeExpr]
initVal ODEInfo
info]],
    CodeVarChunk -> StepFill
assignSolFromObjFill (CodeVarChunk -> StepFill) -> CodeVarChunk -> StepFill
forall a b. (a -> b) -> a -> b
$ ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False]]
  where chooseMethod :: ODEMethod -> a
chooseMethod ODEMethod
Adams = a
0
        chooseMethod ODEMethod
RK45 = a
1
        chooseMethod ODEMethod
_ = String -> a
forall a. HasCallStack => String -> a
error String
odeMethodUnavailable
        ddep :: CodeVarChunk
ddep = CodeVarChunk -> CodeVarChunk
diffCodeChunk (CodeVarChunk -> CodeVarChunk) -> CodeVarChunk -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ ODEInfo -> CodeVarChunk
depVar ODEInfo
info

itArgs :: [Argument]
itArgs :: [Argument]
itArgs = Space -> Argument
inlineArg (Space -> Argument) -> [Space] -> [Argument]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Space
Real, Space
Real, Space
Real, Space
Real]

apacheImport, adams, dp54, foi, foiImp, sampling, sh, shImp, si, siImp, fode :: String
apacheImport :: String
apacheImport = String
"org.apache.commons.math3.ode."
adams :: String
adams = String
"AdamsBashforthIntegrator"
dp54 :: String
dp54 = String
"DormandPrince54Integrator"
foi :: String
foi = String
"FirstOrderIntegrator"
foiImp :: String
foiImp = String
apacheImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
foi
sampling :: String
sampling = String
"sampling"
sh :: String
sh = String
"StepHandler"
shImp :: String
shImp = String
apacheImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
sampling String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"." String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
sh
si :: String
si = String
"StepInterpolator"
siImp :: String
siImp = String
apacheImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
sampling String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"." String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
si
fode :: String
fode = String
"FirstOrderDifferentialEquations"

-- | Collects variables needed for Apache's ODEs as 'DefinedQuantityDict's.
apacheODESymbols :: [DefinedQuantityDict]
apacheODESymbols :: [DefinedQuantityDict]
apacheODESymbols = (CodeVarChunk -> DefinedQuantityDict)
-> [CodeVarChunk] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeVarChunk -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr [CodeVarChunk
it, CodeVarChunk
currVals, CodeVarChunk
stepHandler, CodeVarChunk
t0, CodeVarChunk
y0, CodeVarChunk
interpolator,
  CodeVarChunk
isLast, CodeVarChunk
curr, CodeVarChunk
ode, CodeVarChunk
y0List, CodeVarChunk
y0El, CodeVarChunk
currList, CodeVarChunk
currEl] [DefinedQuantityDict]
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. Semigroup a => a -> a -> a
<> (CodeFuncChunk -> DefinedQuantityDict)
-> [CodeFuncChunk] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeFuncChunk -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr [CodeFuncChunk
adamsC, CodeFuncChunk
dp54C, CodeFuncChunk
stepHandlerCtor, CodeFuncChunk
addStepHandler,
  CodeFuncChunk
initMethod, CodeFuncChunk
handleStep, CodeFuncChunk
getInterpState, CodeFuncChunk
integrate, CodeFuncChunk
odeCtor, CodeFuncChunk
getDimension,
  CodeFuncChunk
computeDerivatives]

it, currVals, stepHandler, t0, y0, interpolator, isLast, curr, y0List, y0El,
  currList, currEl :: CodeVarChunk
it :: CodeVarChunk
it = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"it_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"integrator for solving ODEs"
  String
"integrators for solving ODEs") String
"the integrator for solving ODEs"
  (String -> Space
Actor String
foi) (String -> Symbol
label String
"it")
currVals :: CodeVarChunk
currVals = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"curr_vals_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"array holding ODE solution values for the current step"
  String
"arrays holding ODE solution values for the current step")
  String
"the array holding ODE solution values for the current step"
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"curr_vals")
stepHandler :: CodeVarChunk
stepHandler = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"stepHandler_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"ODE step handler" String
"ODE step handlers") String
"the ODE step handler"
  (String -> Space
Actor (String -> Space) -> String -> Space
forall a b. (a -> b) -> a -> b
$ String
"ODE" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
sh) (String -> Symbol
label String
"stepHandler")
t0 :: CodeVarChunk
t0 = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"t0_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase String
"initial time for ODE solving"
  String
"intial times for ODE solving") String
"the initial time for ODE solving"
   Space
Real (String -> Symbol
label String
"t0")
y0 :: CodeVarChunk
y0 = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"y0_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"array of initial values for ODE solving"
  String
"arrays of initial values for ODE solving")
  String
"the array of initial values for ODE solving" (Space -> Space
Array Space
Real) (String -> Symbol
label String
"y0")
interpolator :: CodeVarChunk
interpolator = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"interpolator_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"step interpolator for ODE solving" String
"step interpolator for ODE solving")
  String
"the step interpolator for ODE solving" (String -> Space
Actor String
si) (String -> Symbol
label String
"interpolator")
isLast :: CodeVarChunk
isLast = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"isLast_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"boolean for whether the current step is the last step"
  String
"booleans for whether the current step is the last step")
  String
"the boolean for whether the current step is the last step"
  Space
Boolean (String -> Symbol
label String
"isLast")
curr :: CodeVarChunk
curr = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"curr_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"ODE solution array for current step" String
"ODE solution arrays for current step")
  String
"the ODE solution array for the current step"
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"curr")
y0List :: CodeVarChunk
y0List = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"y0List_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"initial ODE solution list" String
"initial ODE solution lists")
  String
"the initial ODE solution converted to a Java list"
  (Space -> Space
Vect Space
Real) (String -> Symbol
label String
"y0List")
y0El :: CodeVarChunk
y0El = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"y0El_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"initial ODE solution value" String
"initial ODE solution values")
  String
"an initial ODE solution value" Space
Real (String -> Symbol
label String
"y0El")
currList :: CodeVarChunk
currList = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"currList_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"current ODE solution list" String
"current ODE solution lists")
  String
"the current ODE solution converted to a Java list"
  (Space -> Space
Vect Space
Real) (String -> Symbol
label String
"currList")
currEl :: CodeVarChunk
currEl = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"currEl_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"current ODE solution value" String
"current ODE solution values")
  String
"a current ODE solution value" Space
Real (String -> Symbol
label String
"currEl")

adamsC, dp54C, stepHandlerCtor, addStepHandler, initMethod, handleStep,
  getInterpState, integrate, getDimension, computeDerivatives :: CodeFuncChunk
adamsC :: CodeFuncChunk
adamsC = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"adams_ctor_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"constructor for an Adams-Bashforth integrator"
  String
"constructors for an Adams-Bashforth integrator")
  String
"the constructors for an Adams-Bashforth integrator"
  (String -> Space
Actor String
adams) (String -> Symbol
label String
adams)
dp54C :: CodeFuncChunk
dp54C = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"dp54_ctor_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"constructor for a Dormand-Prince 5-4 integrator"
  String
"constructors for a Dormand-Prince 5-4 integrator")
  String
"the constructors for a Dormand-Prince 5-4 integrator"
  (String -> Space
Actor String
dp54) (String -> Symbol
label String
dp54)
stepHandlerCtor :: CodeFuncChunk
stepHandlerCtor = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"StepHandler_ctor_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"constructor for StepHandler" String
"constructors for StepHandler")
  String
"the constructor for StepHandler"
  (String -> Space
Actor (String -> Space) -> String -> Space
forall a b. (a -> b) -> a -> b
$ String
"ODE" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
sh) (String -> Symbol
label (String -> Symbol) -> String -> Symbol
forall a b. (a -> b) -> a -> b
$ String
"ODE" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
sh)
addStepHandler :: CodeFuncChunk
addStepHandler = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"addStepHandler_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method for adding a step handler to an integrator"
  String
"methods for adding a step handler to an integrator")
  String
"the method for adding a step handler to an integrator"
  Space
Void (String -> Symbol
label String
"addStepHandler")
initMethod :: CodeFuncChunk
initMethod = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"init_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method to initialize step handler" String
"methods to initialize step handler")
  String
"the method to initialize the step handler" Space
Void (String -> Symbol
label String
"init")
handleStep :: CodeFuncChunk
handleStep = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"handleStep_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method to call at each ODE step" String
"methods to call at each ODE step")
  String
"the method to call at each ODE step" Space
Void (String -> Symbol
label String
"handleStep")
getInterpState :: CodeFuncChunk
getInterpState = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"getInterpolatedState_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method for getting current state during ODE solving"
  String
"methods for getting current state during ODE solving")
  String
"the method for getting the current state during ODE solving"
  (Space -> Space
Array Space
Real) (String -> Symbol
label String
"getInterpolatedState")
integrate :: CodeFuncChunk
integrate = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"integrate_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method for integrating an ODE" String
"methods for integrating an ODE")
  String
"the method for integrating an ODE" Space
Void (String -> Symbol
label String
"integrate")
getDimension :: CodeFuncChunk
getDimension = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"getDimension_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method returning the dimension of an ODE system"
  String
"methods returning the dimension of an ODE system")
  String
"the method returning the dimension of an ODE system"
  Space
Natural (String -> Symbol
label String
"getDimension")
computeDerivatives :: CodeFuncChunk
computeDerivatives = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"computeDerivatives_apache") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method encoding an ODE system" String
"methods encoding an ODE system")
  String
"the method encoding an ODE system" Space
Void (String -> Symbol
label String
"computeDerivatives")

initSolListFromArrayJava :: CodeVarChunk -> CodeVarChunk -> CodeVarChunk -> Step
initSolListFromArrayJava :: CodeVarChunk -> CodeVarChunk -> CodeVarChunk -> Step
initSolListFromArrayJava CodeVarChunk
arr CodeVarChunk
temp CodeVarChunk
el = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
Statement (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
  ([CodeVarChunk
s], []) -> [FuncStmt] -> FuncStmt
FMulti
    [ CodeVarChunk -> CodeExpr -> FuncStmt
FAsg CodeVarChunk
s ([[CodeExpr]] -> CodeExpr
Matrix [[]])
    , CodeVarChunk -> CodeExpr -> FuncStmt
FDecDef CodeVarChunk
temp ([[CodeExpr]] -> CodeExpr
Matrix [[]])
    , CodeVarChunk -> CodeExpr -> [FuncStmt] -> FuncStmt
FForEach CodeVarChunk
el (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
arr) [CodeExpr -> CodeExpr -> FuncStmt
FAppend (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
temp) (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
el)]
    , CodeExpr -> CodeExpr -> FuncStmt
FAppend (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
s) (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
temp)
    ]
  ([CodeVarChunk], [CodeExpr])
_ -> String -> FuncStmt
forall a. HasCallStack => String -> a
error String
"Fill for initSolListFromArrayJava should provide one CodeChunk and no Exprs")

appendCurrSolFromArrayJava :: CodeExpr -> CodeVarChunk -> CodeVarChunk -> Step
appendCurrSolFromArrayJava :: CodeExpr -> CodeVarChunk -> CodeVarChunk -> Step
appendCurrSolFromArrayJava CodeExpr
arr CodeVarChunk
temp CodeVarChunk
el = ([CodeVarChunk] -> [CodeExpr] -> FuncStmt) -> Step
Statement (\[CodeVarChunk]
cdchs [CodeExpr]
es -> case ([CodeVarChunk]
cdchs, [CodeExpr]
es) of
  ([CodeVarChunk
s], []) -> [FuncStmt] -> FuncStmt
FMulti
    [ CodeVarChunk -> CodeExpr -> FuncStmt
FDecDef CodeVarChunk
temp ([[CodeExpr]] -> CodeExpr
Matrix [[]])
    , CodeVarChunk -> CodeExpr -> [FuncStmt] -> FuncStmt
FForEach CodeVarChunk
el CodeExpr
arr [CodeExpr -> CodeExpr -> FuncStmt
FAppend (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
temp) (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
el)]
    , CodeExpr -> CodeExpr -> FuncStmt
FAppend (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
s) (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
temp)
    ]
  ([CodeVarChunk], [CodeExpr])
_ -> String -> FuncStmt
forall a. HasCallStack => String -> a
error String
"Fill for appendCurrSolFromArrayJava should provide one CodeChunk and no Exprs")

-- odeint (C++)

-- | [odeint](https://headmyshoulder.github.io/odeint-v2/) ODE library package.
odeintPckg :: ODELibPckg
odeintPckg :: ODELibPckg
odeintPckg = String
-> String
-> [DefinedQuantityDict]
-> ExternalLibrary
-> (ODEInfo -> ExternalLibraryCall)
-> String
-> [Lang]
-> ODELibPckg
mkODELib String
"odeint" String
"v2" [DefinedQuantityDict]
odeintSymbols ExternalLibrary
odeint ODEInfo -> ExternalLibraryCall
odeintCall String
"." [Lang
Cpp]

odeint :: ExternalLibrary
odeint :: ExternalLibrary
odeint = ExternalLibrary -> ExternalLibrary
externalLib [
  [[Step]] -> StepGroup
choiceSteps [
    [FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libConstructor (String
odeintImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"/stepper/runge_kutta_dopri5") CodeFuncChunk
rkdp5C [] CodeVarChunk
rk,
    FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libFunctionWithResult (String
odeintImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"/stepper/generation") CodeFuncChunk
makeControlled
      [Space -> Argument
inlineArg Space
Real, Space -> Argument
inlineArg Space
Real, CodeExpr -> Argument
lockedArg (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
rk)] CodeVarChunk
stepper],
    [FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String
-> CodeFuncChunk -> [Argument] -> CodeVarChunk -> FunctionInterface
libConstructor (String
odeintImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"/stepper/adams_bashforth") CodeFuncChunk
adamsBashC [] CodeVarChunk
stepper]],
  Step -> StepGroup
mandatoryStep (Step -> StepGroup) -> Step -> StepGroup
forall a b. (a -> b) -> a -> b
$ FunctionInterface -> Step
callStep (FunctionInterface -> Step) -> FunctionInterface -> Step
forall a b. (a -> b) -> a -> b
$ String -> CodeFuncChunk -> [Argument] -> FunctionInterface
libFunction (String
odeintImport String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"/integrate/integrate_const")
    CodeFuncChunk
integrateConst [
      CodeExpr -> Argument
lockedArg (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
stepper),
      [String]
-> String -> CodeVarChunk -> CodeFuncChunk -> ClassInfo -> Argument
customObjArg [] String
"Class representing an ODE system" CodeVarChunk
ode CodeFuncChunk
odeCtor
        ([MethodInfo] -> ClassInfo
customClass [CodeFuncChunk -> [Parameter] -> [Step] -> MethodInfo
constructorInfo CodeFuncChunk
odeCtor [] [],
          CodeFuncChunk -> String -> [Parameter] -> [Step] -> MethodInfo
methodInfoNoReturn CodeFuncChunk
odeOp String
"function representation of ODE system"
            [Space -> Parameter
unnamedParam (Space -> Space
Vect Space
Real), Space -> Parameter
unnamedParam (Space -> Space
Vect Space
Real), CodeVarChunk -> Parameter
lockedParam CodeVarChunk
t]
            [Step
assignArrayIndex]]),
      -- Need to declare variable holding initial value because odeint will update this variable at each step
      CodeVarChunk -> Argument
preDefinedArg CodeVarChunk
odeintCurrVals,
      Space -> Argument
inlineArg Space
Real, Space -> Argument
inlineArg Space
Real, Space -> Argument
inlineArg Space
Real,
      [String]
-> String -> CodeVarChunk -> CodeFuncChunk -> ClassInfo -> Argument
customObjArg []
        String
"Class for populating a list during an ODE solution process"
        CodeVarChunk
pop CodeFuncChunk
popCtor ([MethodInfo] -> ClassInfo
customClass [
          CodeFuncChunk -> [Parameter] -> [Step] -> MethodInfo
constructorInfo CodeFuncChunk
popCtor [Space -> Parameter
unnamedParam (Space -> Space
Vect Space
Real)] [],
          CodeFuncChunk -> String -> [Parameter] -> [Step] -> MethodInfo
methodInfoNoReturn CodeFuncChunk
popOp
            String
"appends solution point for current ODE solution step"
            [CodeVarChunk -> Parameter
lockedParam CodeVarChunk
y, CodeVarChunk -> Parameter
lockedParam CodeVarChunk
t] [CodeExpr -> Step
appendCurrSol (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy CodeVarChunk
y)]])]]

odeintCall :: ODEInfo -> ExternalLibraryCall
odeintCall :: ODEInfo -> ExternalLibraryCall
odeintCall ODEInfo
info = ExternalLibraryCall -> ExternalLibraryCall
externalLibCall [
  (Int -> [StepFill] -> StepGroupFill)
-> (Int, [StepFill]) -> StepGroupFill
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> [StepFill] -> StepGroupFill
choiceStepsFill (ODEMethod -> (Int, [StepFill])
chooseMethod (ODEMethod -> (Int, [StepFill])) -> ODEMethod -> (Int, [StepFill])
forall a b. (a -> b) -> a -> b
$ ODEOptions -> ODEMethod
solveMethod (ODEOptions -> ODEMethod) -> ODEOptions -> ODEMethod
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info),
  StepFill -> StepGroupFill
mandatoryStepFill (StepFill -> StepGroupFill) -> StepFill -> StepGroupFill
forall a b. (a -> b) -> a -> b
$ FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill ([ArgumentFill] -> FunctionIntFill)
-> [ArgumentFill] -> FunctionIntFill
forall a b. (a -> b) -> a -> b
$
    [StateVariable] -> ClassInfoFill -> ArgumentFill
customObjArgFill (CodeVarChunk -> StateVariable
privStateVar (CodeVarChunk -> StateVariable)
-> [CodeVarChunk] -> [StateVariable]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ODEInfo -> [CodeVarChunk]
otherVars ODEInfo
info) ([MethodInfoFill] -> ClassInfoFill
customClassFill [
      [ParameterFill] -> [Initializer] -> [StepFill] -> MethodInfoFill
constructorInfoFill (CodeVarChunk -> ParameterFill
userDefinedParamFill (CodeVarChunk -> ParameterFill)
-> [CodeVarChunk] -> [ParameterFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ODEInfo -> [CodeVarChunk]
otherVars ODEInfo
info)
        ([CodeVarChunk] -> [CodeExpr] -> [Initializer]
forall a b. [a] -> [b] -> [(a, b)]
zip (ODEInfo -> [CodeVarChunk]
otherVars ODEInfo
info) (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy (CodeVarChunk -> CodeExpr) -> [CodeVarChunk] -> [CodeExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ODEInfo -> [CodeVarChunk]
otherVars ODEInfo
info)) [],
      [ParameterFill] -> [StepFill] -> MethodInfoFill
methodInfoFill [CodeVarChunk -> ParameterFill
unnamedParamPBVFill (CodeVarChunk -> ParameterFill) -> CodeVarChunk -> ParameterFill
forall a b. (a -> b) -> a -> b
$ ODEInfo -> CodeVarChunk
depVar ODEInfo
info, CodeVarChunk -> ParameterFill
unnamedParamFill CodeVarChunk
ddep]
        [CodeVarChunk -> [CodeExpr] -> StepFill
assignArrayIndexFill CodeVarChunk
ddep (ODEInfo -> [CodeExpr]
odeSyst ODEInfo
info)]]) ArgumentFill -> [ArgumentFill] -> [ArgumentFill]
forall a. a -> [a] -> [a]
:
    (CodeExpr -> ArgumentFill) -> [CodeExpr] -> [ArgumentFill]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeExpr -> ArgumentFill
basicArgFill [[[CodeExpr]] -> CodeExpr
forall r. ExprC r => [[r]] -> r
matrix [ODEInfo -> [CodeExpr]
initVal ODEInfo
info], ODEInfo -> CodeExpr
tInit ODEInfo
info, ODEInfo -> CodeExpr
tFinal ODEInfo
info,
      ODEOptions -> CodeExpr
stepSize (ODEOptions -> CodeExpr) -> ODEOptions -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info] [ArgumentFill] -> [ArgumentFill] -> [ArgumentFill]
forall a. Semigroup a => a -> a -> a
<> [
    [StateVariable] -> ClassInfoFill -> ArgumentFill
customObjArgFill [CodeVarChunk -> StateVariable
privStateVar (CodeVarChunk -> StateVariable) -> CodeVarChunk -> StateVariable
forall a b. (a -> b) -> a -> b
$ ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
True]
      ([MethodInfoFill] -> ClassInfoFill
customClassFill [[ParameterFill] -> [Initializer] -> [StepFill] -> MethodInfoFill
constructorInfoFill [CodeVarChunk -> ParameterFill
unnamedParamFill (CodeVarChunk -> ParameterFill) -> CodeVarChunk -> ParameterFill
forall a b. (a -> b) -> a -> b
$ ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False]
         [(ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
True, UFunc -> CodeExpr -> CodeExpr
UnaryOp UFunc
MakeRef (CodeVarChunk -> CodeExpr
forall c. (IsChunk c, HasSymbol c) => c -> CodeExpr
forall r c. (ExprC r, IsChunk c, HasSymbol c) => c -> r
sy (CodeVarChunk -> CodeExpr) -> CodeVarChunk -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False))] [],
         [ParameterFill] -> [StepFill] -> MethodInfoFill
methodInfoFill [] [CodeVarChunk -> StepFill
appendCurrSolFill (CodeVarChunk -> StepFill) -> CodeVarChunk -> StepFill
forall a b. (a -> b) -> a -> b
$ ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
True]])]]
  where chooseMethod :: ODEMethod -> (Int, [StepFill])
chooseMethod ODEMethod
RK45 = (Int
0, FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill)
-> ([CodeExpr] -> FunctionIntFill) -> [CodeExpr] -> StepFill
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ArgumentFill] -> FunctionIntFill
libCallFill ([ArgumentFill] -> FunctionIntFill)
-> ([CodeExpr] -> [ArgumentFill]) -> [CodeExpr] -> FunctionIntFill
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (CodeExpr -> ArgumentFill) -> [CodeExpr] -> [ArgumentFill]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
          CodeExpr -> ArgumentFill
basicArgFill ([CodeExpr] -> StepFill) -> [[CodeExpr]] -> [StepFill]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[], [ODEOptions -> CodeExpr
absTol (ODEOptions -> CodeExpr) -> ODEOptions -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info, ODEOptions -> CodeExpr
relTol (ODEOptions -> CodeExpr) -> ODEOptions -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> ODEOptions
odeOpts ODEInfo
info]])
        chooseMethod ODEMethod
Adams = (Int
1, [FunctionIntFill -> StepFill
callStepFill (FunctionIntFill -> StepFill) -> FunctionIntFill -> StepFill
forall a b. (a -> b) -> a -> b
$ [ArgumentFill] -> FunctionIntFill
libCallFill []])
        chooseMethod ODEMethod
_ = String -> (Int, [StepFill])
forall a. HasCallStack => String -> a
error String
odeMethodUnavailable
        ddep :: CodeVarChunk
ddep = CodeVarChunk -> CodeVarChunk
diffCodeChunk (CodeVarChunk -> CodeVarChunk) -> CodeVarChunk -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ ODEInfo -> CodeVarChunk
depVar ODEInfo
info

odeintImport, odeNameSpace, rkdp5, adamsBash :: String
odeintImport :: String
odeintImport = String
"boost/numeric/odeint"
odeNameSpace :: String
odeNameSpace = String
"boost::numeric::odeint::"
rkdp5 :: String
rkdp5 = String
odeNameSpace String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"runge_kutta_dopri5<vector<double>>"
adamsBash :: String
adamsBash = String
odeNameSpace String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"adams_bashforth<3,vector<double>>"

popT :: Space
popT :: Space
popT = String -> Space
Actor String
"Populate"

-- | Collects variables needed for odeint's ODEs as 'DefinedQuantityDict's.
odeintSymbols :: [DefinedQuantityDict]
odeintSymbols :: [DefinedQuantityDict]
odeintSymbols = (CodeVarChunk -> DefinedQuantityDict)
-> [CodeVarChunk] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeVarChunk -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr [CodeVarChunk
odeintCurrVals, CodeVarChunk
rk, CodeVarChunk
stepper, CodeVarChunk
pop] [DefinedQuantityDict]
-> [DefinedQuantityDict] -> [DefinedQuantityDict]
forall a. Semigroup a => a -> a -> a
<> (CodeFuncChunk -> DefinedQuantityDict)
-> [CodeFuncChunk] -> [DefinedQuantityDict]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeFuncChunk -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr
  [CodeFuncChunk
rkdp5C, CodeFuncChunk
makeControlled, CodeFuncChunk
adamsBashC, CodeFuncChunk
integrateConst, CodeFuncChunk
odeOp, CodeFuncChunk
popCtor,
  CodeFuncChunk
popOp]

odeintCurrVals, rk, stepper, pop :: CodeVarChunk
odeintCurrVals :: CodeVarChunk
odeintCurrVals = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"currVals_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"vector holding ODE solution values for the current step"
  String
"vectors holding ODE solution values for the current step")
  String
"the vector holding the ODE solution values for the current step"
  (Space -> Space
Vect Space
Real) (String -> Symbol
label String
"currVals")
rk :: CodeVarChunk
rk = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"rk_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"stepper for solving ODE system using Runge-Kutta-Dopri5 method"
  String
"steppers for solving ODE system using Runge-Kutta-Dopri5 method")
  String
"the stepper for solving the ODE system using the Runge-Kutta-Dopri5 method"
  (String -> Space
Actor String
rkdp5) (String -> Symbol
label String
"rk")
stepper :: CodeVarChunk
stepper = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"stepper_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"stepper for solving ODE system" String
"steppers for solving ODE system")
  String
"the stepper for solving the ODE system" (String -> Space
Actor String
"auto") (String -> Symbol
label String
"stepper")
pop :: CodeVarChunk
pop = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"pop_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"object to populate ODE solution vector"
  String
"objects to populate ODE solution vector")
  String
"the object to populate the ODE solution vector" Space
popT (String -> Symbol
label String
"pop")

rkdp5C, makeControlled, adamsBashC, integrateConst, odeOp, popCtor,
  popOp :: CodeFuncChunk
rkdp5C :: CodeFuncChunk
rkdp5C = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"rkdp5_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"constructor for stepper using Runge-Kutta-Dopri5 method"
  String
"constructors for stepper using Runge-Kutta-Dopri5 method")
  String
"the constructor for stepper using the Runge-Kutta-Dopri5 method"
  (String -> Space
Actor String
rkdp5) (String -> Symbol
label String
rkdp5)
makeControlled :: CodeFuncChunk
makeControlled = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"make_controlled_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"function for adding error control to a stepper"
  String
"functions for adding error control to a stepper")
  String
"the function for adding error control to a stepper"
  (String -> Space
Actor String
"auto") (String -> Symbol
label (String -> Symbol) -> String -> Symbol
forall a b. (a -> b) -> a -> b
$ String
odeNameSpace String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"make_controlled")
adamsBashC :: CodeFuncChunk
adamsBashC = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"adamsBash_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"constructor for stepper using Adams-Bashforth method"
  String
"constructors for stepper using Adams-Bashforth method")
  String
"the constructor for stepper using the Adams-Bashforth method"
  (String -> Space
Actor String
adamsBash) (String -> Symbol
label String
adamsBash)
integrateConst :: CodeFuncChunk
integrateConst = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"integrate_const_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"function for integrating with a constant step size"
  String
"functions for integrating with a constant step size")
  String
"the function for integrating with a constant step size"
  Space
Void (String -> Symbol
label (String -> Symbol) -> String -> Symbol
forall a b. (a -> b) -> a -> b
$ String
odeNameSpace String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"integrate_const")
odeOp :: CodeFuncChunk
odeOp = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"ode_operator_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method defining override for calling ODE object"
  String
"methods defining override for calling ODE object")
  String
"the method defining override for calling an ODE object"
  Space
Void (String -> Symbol
label String
"operator()")
popCtor :: CodeFuncChunk
popCtor = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"Populate_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"constructor for Populate object for ODE solving with odeint"
  String
"constructors for Populate object for ODE solving with odeint")
  String
"the constructor for the Populate object for ODE solving with odeint"
  Space
popT (String -> Symbol
label String
"Populate")
popOp :: CodeFuncChunk
popOp = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"pop_operator_odeint") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"method defining override for calling Populate object"
  String
"methods defining override for calling Populate object")
  String
"the method defining override for calling a Populate object"
  Space
Void (String -> Symbol
label String
"operator()")

-- 'CodeChunk's used in multiple external ODE libraries

ode, t, y :: CodeVarChunk
-- | ODE object & definition.
ode :: CodeVarChunk
ode = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"ode_obj") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"object representing an ODE system" String
"objects representing an ODE system")
  String
"the object representing an ODE system" Space
odeObj (String -> Symbol
label String
"ode")
-- | Independent variable in an ODE.
t :: CodeVarChunk
t = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"t_ode") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"current independent variable value in ODE solution"
  String
"current independent variable value in ODE solution")
  String
"the current independent variable value in the ODE solution"
  Space
Real (String -> Symbol
label String
"t")
-- | Dependent variable in an ODE.
y :: CodeVarChunk
y = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"y_ode") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"current dependent variable value in ODE solution"
  String
"current dependent variable value in ODE solution")
  String
"the current dependent variable value in the ODE solution"
  (Space -> Space
Vect Space
Real) (String -> Symbol
label String
"y")

-- | ODE object constructor.
odeCtor :: CodeFuncChunk
odeCtor :: CodeFuncChunk
odeCtor = DefinedQuantityDict -> CodeFuncChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeFuncChunk
quantfunc (DefinedQuantityDict -> CodeFuncChunk)
-> DefinedQuantityDict -> CodeFuncChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol -> String -> Space -> Symbol -> DefinedQuantityDict
implVar (String -> UID
mkUid String
"ODE_constructor") (String -> String -> NPG Symbol
forall a. String -> String -> NPG a
nounPhrase
  String
"constructor for ODE object" String
"constructors for ODE object")
  String
"the constructor for the ODE object" Space
odeObj (String -> Symbol
label String
"ODE")

-- | ODE object.
odeObj :: Space
odeObj :: Space
odeObj = String -> Space
Actor String
"ODE"

-- | ODE method unavailable message.
odeMethodUnavailable :: String
odeMethodUnavailable :: String
odeMethodUnavailable = String
"Chosen ODE solving method is not available" String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
          String
" in chosen ODE solving library"

-- | Solution list chunk constructor. Wraps the dependent variable's type in
-- an extra 'Vect' so that the generated code declares a list-of-vectors
-- (e.g. @vector<vector<double>>@) instead of a flat list.
solListVar :: ODEInfo -> Bool -> CodeVarChunk
solListVar :: ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
isRef =
  let suffix :: String
suffix  = String
"sol" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> if Bool
isRef then String
"ref" else String
""
      np :: String
np      = (if Bool
isRef then String
"reference to the " else String
"") String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"solution list"
      desc :: String
desc    = (if Bool
isRef then String
"reference to the " else String
"") String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"list of solutions for"
      outerTp :: Space -> Space
outerTp = if Bool
isRef then Space -> Space
Reference (Space -> Space) -> (Space -> Space) -> Space -> Space
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Space -> Space
Vect else Space -> Space
Vect
  in DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol
-> Sentence
-> Maybe String
-> Space
-> Symbol
-> Maybe UnitDefn
-> DefinedQuantityDict
implVarAU' (CodeVarChunk
dv CodeVarChunk -> String -> UID
forall a. HasUID a => a -> String -> UID
+++ String
suffix)
    (NPG Symbol -> NPG Symbol -> NPG Symbol
forall ta a tb.
(NounPhrase ta a, NounPhrase tb a) =>
ta -> tb -> NPG a
compoundPhrase (CodeVarChunk
dv CodeVarChunk
-> Getting (NPG Symbol) CodeVarChunk (NPG Symbol) -> NPG Symbol
forall s a. s -> Getting a s a -> a
^. Getting (NPG Symbol) CodeVarChunk (NPG Symbol)
forall c. NamedIdea c => Lens' c (NPG Symbol)
Lens' CodeVarChunk (NPG Symbol)
term) (String -> NPG Symbol
forall a. String -> NPG a
nounPhraseSP String
np))
    (String -> Sentence
S String
desc Sentence -> Sentence -> Sentence
+:+ (CodeVarChunk
dv CodeVarChunk -> Getting Sentence CodeVarChunk Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence CodeVarChunk Sentence
forall c. Definition c => Lens' c Sentence
Lens' CodeVarChunk Sentence
defn)) (CodeVarChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA CodeVarChunk
dv)
    (Space -> Space
outerTp (CodeVarChunk
dv CodeVarChunk -> Getting Space CodeVarChunk Space -> Space
forall s a. s -> Getting a s a -> a
^. Getting Space CodeVarChunk Space
forall c. HasSpace c => Getter c Space
Getter CodeVarChunk Space
typ)) (CodeVarChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol CodeVarChunk
dv Stage
Implementation) (CodeVarChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit CodeVarChunk
dv)
  where dv :: CodeVarChunk
dv = ODEInfo -> CodeVarChunk
depVar ODEInfo
info

-- | Change in @X@ chunk constructor (where @X@ is a given argument).
diffCodeChunk :: CodeVarChunk -> CodeVarChunk
diffCodeChunk :: CodeVarChunk -> CodeVarChunk
diffCodeChunk CodeVarChunk
c = DefinedQuantityDict -> CodeVarChunk
forall c.
(Quantity c, MayHaveUnit c, Concept c) =>
c -> CodeVarChunk
quantvar (DefinedQuantityDict -> CodeVarChunk)
-> DefinedQuantityDict -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ UID
-> NPG Symbol
-> Sentence
-> Maybe String
-> Space
-> Symbol
-> Maybe UnitDefn
-> DefinedQuantityDict
implVarAU' (CodeVarChunk
c CodeVarChunk -> String -> UID
forall a. HasUID a => a -> String -> UID
+++ String
"d" )
  (NPG Symbol -> NPG Symbol -> NPG Symbol
forall ta a tb.
(NounPhrase ta a, NounPhrase tb a) =>
ta -> tb -> NPG a
compoundPhrase (String -> NPG Symbol
forall a. String -> NPG a
nounPhraseSP String
"change in") (CodeVarChunk
c CodeVarChunk
-> Getting (NPG Symbol) CodeVarChunk (NPG Symbol) -> NPG Symbol
forall s a. s -> Getting a s a -> a
^. Getting (NPG Symbol) CodeVarChunk (NPG Symbol)
forall c. NamedIdea c => Lens' c (NPG Symbol)
Lens' CodeVarChunk (NPG Symbol)
term))
  (String -> Sentence
S String
"the change in" Sentence -> Sentence -> Sentence
+:+ (CodeVarChunk
c CodeVarChunk -> Getting Sentence CodeVarChunk Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence CodeVarChunk Sentence
forall c. Definition c => Lens' c Sentence
Lens' CodeVarChunk Sentence
defn)) (CodeVarChunk -> Maybe String
forall c. Idea c => c -> Maybe String
getA CodeVarChunk
c)
  (CodeVarChunk
c CodeVarChunk -> Getting Space CodeVarChunk Space -> Space
forall s a. s -> Getting a s a -> a
^. Getting Space CodeVarChunk Space
forall c. HasSpace c => Getter c Space
Getter CodeVarChunk Space
typ) (String -> Symbol
label String
"d" Symbol -> Symbol -> Symbol
forall a. Semigroup a => a -> a -> a
<> CodeVarChunk -> Stage -> Symbol
forall c. HasSymbol c => c -> Stage -> Symbol
symbol CodeVarChunk
c Stage
Implementation) (CodeVarChunk -> Maybe UnitDefn
forall u. MayHaveUnit u => u -> Maybe UnitDefn
getUnit CodeVarChunk
c)

-- FIXME: This is surely a hack, but I can't think of a better way right now.
-- | Some libraries use an array instead of a list to internally represent the ODE.
-- So we need a way to switch the dependent variable from list to array,
-- and the array version must have a distinct UID so it can be stored in the DB.
modifiedODESyst :: String -> ODEInfo -> [CodeExpr]
modifiedODESyst :: String -> ODEInfo -> [CodeExpr]
modifiedODESyst String
sufx ODEInfo
info = CodeExpr -> CodeExpr
replaceDepVar (CodeExpr -> CodeExpr) -> [CodeExpr] -> [CodeExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ODEInfo -> [CodeExpr]
odeSyst ODEInfo
info
  where
    replaceDepVar :: CodeExpr -> CodeExpr
replaceDepVar cc :: CodeExpr
cc@(C UID
c) | UID
c UID -> UID -> Bool
forall a. Eq a => a -> a -> Bool
== ODEInfo -> CodeVarChunk
depVar ODEInfo
info CodeVarChunk -> Getting UID CodeVarChunk UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID CodeVarChunk UID
forall c. HasUID c => Getter c UID
Getter CodeVarChunk UID
uid = UID -> CodeExpr
C (UID -> CodeExpr) -> UID -> CodeExpr
forall a b. (a -> b) -> a -> b
$ ODEInfo -> CodeVarChunk
depVar ODEInfo
info CodeVarChunk -> String -> UID
forall a. HasUID a => a -> String -> UID
+++ (String
"_" String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
sufx)
                           | Bool
otherwise               = CodeExpr
cc
    replaceDepVar (AssocA AssocArithOper
a [CodeExpr]
es)           = AssocArithOper -> [CodeExpr] -> CodeExpr
AssocA AssocArithOper
a (CodeExpr -> CodeExpr
replaceDepVar (CodeExpr -> CodeExpr) -> [CodeExpr] -> [CodeExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [CodeExpr]
es)
    replaceDepVar (AssocB AssocBoolOper
b [CodeExpr]
es)           = AssocBoolOper -> [CodeExpr] -> CodeExpr
AssocB AssocBoolOper
b (CodeExpr -> CodeExpr
replaceDepVar (CodeExpr -> CodeExpr) -> [CodeExpr] -> [CodeExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [CodeExpr]
es)
    replaceDepVar (FCall UID
u [CodeExpr]
es [(UID, CodeExpr)]
nes)        = UID -> [CodeExpr] -> [(UID, CodeExpr)] -> CodeExpr
FCall UID
u (CodeExpr -> CodeExpr
replaceDepVar (CodeExpr -> CodeExpr) -> [CodeExpr] -> [CodeExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [CodeExpr]
es)
      (ASetter (UID, CodeExpr) (UID, CodeExpr) CodeExpr CodeExpr
-> (CodeExpr -> CodeExpr) -> (UID, CodeExpr) -> (UID, CodeExpr)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter (UID, CodeExpr) (UID, CodeExpr) CodeExpr CodeExpr
forall s t a b. Field2 s t a b => Lens s t a b
Lens (UID, CodeExpr) (UID, CodeExpr) CodeExpr CodeExpr
_2 CodeExpr -> CodeExpr
replaceDepVar ((UID, CodeExpr) -> (UID, CodeExpr))
-> [(UID, CodeExpr)] -> [(UID, CodeExpr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(UID, CodeExpr)]
nes)
    replaceDepVar (New UID
u [CodeExpr]
es [(UID, CodeExpr)]
nes)          = UID -> [CodeExpr] -> [(UID, CodeExpr)] -> CodeExpr
New UID
u (CodeExpr -> CodeExpr
replaceDepVar (CodeExpr -> CodeExpr) -> [CodeExpr] -> [CodeExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [CodeExpr]
es)
      (ASetter (UID, CodeExpr) (UID, CodeExpr) CodeExpr CodeExpr
-> (CodeExpr -> CodeExpr) -> (UID, CodeExpr) -> (UID, CodeExpr)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter (UID, CodeExpr) (UID, CodeExpr) CodeExpr CodeExpr
forall s t a b. Field2 s t a b => Lens s t a b
Lens (UID, CodeExpr) (UID, CodeExpr) CodeExpr CodeExpr
_2 CodeExpr -> CodeExpr
replaceDepVar ((UID, CodeExpr) -> (UID, CodeExpr))
-> [(UID, CodeExpr)] -> [(UID, CodeExpr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(UID, CodeExpr)]
nes)
    replaceDepVar (Message UID
au UID
mu [CodeExpr]
es [(UID, CodeExpr)]
nes)  = UID -> UID -> [CodeExpr] -> [(UID, CodeExpr)] -> CodeExpr
Message UID
au UID
mu (CodeExpr -> CodeExpr
replaceDepVar (CodeExpr -> CodeExpr) -> [CodeExpr] -> [CodeExpr]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [CodeExpr]
es)
      (ASetter (UID, CodeExpr) (UID, CodeExpr) CodeExpr CodeExpr
-> (CodeExpr -> CodeExpr) -> (UID, CodeExpr) -> (UID, CodeExpr)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter (UID, CodeExpr) (UID, CodeExpr) CodeExpr CodeExpr
forall s t a b. Field2 s t a b => Lens s t a b
Lens (UID, CodeExpr) (UID, CodeExpr) CodeExpr CodeExpr
_2 CodeExpr -> CodeExpr
replaceDepVar ((UID, CodeExpr) -> (UID, CodeExpr))
-> [(UID, CodeExpr)] -> [(UID, CodeExpr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(UID, CodeExpr)]
nes)
    replaceDepVar (Case Completeness
c [(CodeExpr, CodeExpr)]
cs)             = Completeness -> [(CodeExpr, CodeExpr)] -> CodeExpr
Case Completeness
c (ASetter (CodeExpr, CodeExpr) (CodeExpr, CodeExpr) CodeExpr CodeExpr
-> (CodeExpr -> CodeExpr)
-> (CodeExpr, CodeExpr)
-> (CodeExpr, CodeExpr)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter (CodeExpr, CodeExpr) (CodeExpr, CodeExpr) CodeExpr CodeExpr
forall s t a b. Field1 s t a b => Lens s t a b
Lens (CodeExpr, CodeExpr) (CodeExpr, CodeExpr) CodeExpr CodeExpr
_1 CodeExpr -> CodeExpr
replaceDepVar ((CodeExpr, CodeExpr) -> (CodeExpr, CodeExpr))
-> [(CodeExpr, CodeExpr)] -> [(CodeExpr, CodeExpr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(CodeExpr, CodeExpr)]
cs)
    replaceDepVar (Matrix [[CodeExpr]]
es)             = [[CodeExpr]] -> CodeExpr
Matrix ([[CodeExpr]] -> CodeExpr) -> [[CodeExpr]] -> CodeExpr
forall a b. (a -> b) -> a -> b
$ (CodeExpr -> CodeExpr) -> [CodeExpr] -> [CodeExpr]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CodeExpr -> CodeExpr
replaceDepVar ([CodeExpr] -> [CodeExpr]) -> [[CodeExpr]] -> [[CodeExpr]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[CodeExpr]]
es
    replaceDepVar (UnaryOp UFunc
u CodeExpr
e)           = UFunc -> CodeExpr -> CodeExpr
UnaryOp UFunc
u (CodeExpr -> CodeExpr) -> CodeExpr -> CodeExpr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e
    replaceDepVar (UnaryOpB UFuncB
u CodeExpr
e)          = UFuncB -> CodeExpr -> CodeExpr
UnaryOpB UFuncB
u (CodeExpr -> CodeExpr) -> CodeExpr -> CodeExpr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e
    replaceDepVar (UnaryOpVV UFuncVV
u CodeExpr
e)         = UFuncVV -> CodeExpr -> CodeExpr
UnaryOpVV UFuncVV
u (CodeExpr -> CodeExpr) -> CodeExpr -> CodeExpr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e
    replaceDepVar (UnaryOpVN UFuncVN
u CodeExpr
e)         = UFuncVN -> CodeExpr -> CodeExpr
UnaryOpVN UFuncVN
u (CodeExpr -> CodeExpr) -> CodeExpr -> CodeExpr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e
    replaceDepVar (ArithBinaryOp ArithBinOp
b CodeExpr
e1 CodeExpr
e2) = ArithBinOp -> CodeExpr -> CodeExpr -> CodeExpr
ArithBinaryOp ArithBinOp
b
      (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e1) (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e2)
    replaceDepVar (EqBinaryOp EqBinOp
b CodeExpr
e1 CodeExpr
e2)    = EqBinOp -> CodeExpr -> CodeExpr -> CodeExpr
EqBinaryOp EqBinOp
b
      (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e1) (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e2)
    replaceDepVar (LABinaryOp LABinOp
b CodeExpr
e1 CodeExpr
e2)    = LABinOp -> CodeExpr -> CodeExpr -> CodeExpr
LABinaryOp LABinOp
b
      (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e1) (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e2)
    replaceDepVar (OrdBinaryOp OrdBinOp
b CodeExpr
e1 CodeExpr
e2)   = OrdBinOp -> CodeExpr -> CodeExpr -> CodeExpr
OrdBinaryOp OrdBinOp
b
      (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e1) (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e2)
    replaceDepVar (VVNBinaryOp VVNBinOp
b CodeExpr
e1 CodeExpr
e2)   = VVNBinOp -> CodeExpr -> CodeExpr -> CodeExpr
VVNBinaryOp VVNBinOp
b
      (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e1) (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e2)
    replaceDepVar (VVVBinaryOp VVVBinOp
b CodeExpr
e1 CodeExpr
e2)   = VVVBinOp -> CodeExpr -> CodeExpr -> CodeExpr
VVVBinaryOp VVVBinOp
b
      (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e1) (CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e2)
    replaceDepVar (Operator AssocArithOper
ao DiscreteDomainDesc CodeExpr CodeExpr
dd CodeExpr
e)      = AssocArithOper
-> DiscreteDomainDesc CodeExpr CodeExpr -> CodeExpr -> CodeExpr
Operator AssocArithOper
ao DiscreteDomainDesc CodeExpr CodeExpr
dd (CodeExpr -> CodeExpr) -> CodeExpr -> CodeExpr
forall a b. (a -> b) -> a -> b
$ CodeExpr -> CodeExpr
replaceDepVar CodeExpr
e
    replaceDepVar CodeExpr
e = CodeExpr
e

-- | Collect all chunks related to a specific ODE
--
-- FIXME: HACK: Rather than being tied to 'ODEInfo', this should be tied to the
-- 'ODELibPckg', which contains the know-how of code generation for ODEs and
-- really knows which "ODEInfo-required-chunks" are necessary to add to the
-- `ChunkDB`. This currently throws more than necessary.
odeInfoChunks :: ODEInfo -> [DefinedQuantityDict]
odeInfoChunks :: ODEInfo -> [DefinedQuantityDict]
odeInfoChunks ODEInfo
info =
  let dv :: CodeVarChunk
dv = ODEInfo -> CodeVarChunk
depVar ODEInfo
info
  in CodeVarChunk -> DefinedQuantityDict
forall c.
(Quantity c, Concept c, MayHaveUnit c) =>
c -> DefinedQuantityDict
dqdWr (CodeVarChunk -> DefinedQuantityDict)
-> [CodeVarChunk] -> [DefinedQuantityDict]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ CodeVarChunk -> CodeVarChunk
listToArray CodeVarChunk
dv
               , ODEInfo -> CodeVarChunk
arrayVecDepVar ODEInfo
info
               , CodeVarChunk -> CodeVarChunk
diffCodeChunk CodeVarChunk
dv
               , CodeVarChunk -> CodeVarChunk
listToArray (CodeVarChunk -> CodeVarChunk) -> CodeVarChunk -> CodeVarChunk
forall a b. (a -> b) -> a -> b
$ CodeVarChunk -> CodeVarChunk
diffCodeChunk CodeVarChunk
dv
               , ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
False
               , ODEInfo -> Bool -> CodeVarChunk
solListVar ODEInfo
info Bool
True
               ]