forked from miking-lang/miking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsundials.mc
45 lines (32 loc) · 1.6 KB
/
sundials.mc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
include "string.mc"
include "tensor.mc"
type NvectorSerial
type SundialsMatrixDense
type SundialsRealArray
type SundialsNonlinearSolver
external nvectorSerialWrap : Tensor[Float] -> NvectorSerial
-- `nvectorSerialWrap t` wraps tensor `t` of rank 1 in a serial NVector.
let nvectorSerialWrap = lam t. nvectorSerialWrap t
external nvectorSerialUnwrap : NvectorSerial -> Tensor[Float]
-- `nvectorSerialUnwrap v` uwraps serial NVector `v` to a rank 1 tensor.
let nvectorSerialUnwrap = lam t. nvectorSerialUnwrap t
external sundialsMatrixDense : Int -> SundialsMatrixDense
-- `sundialsMatrixDense n` creates a square dense matrix of size `n` for use in
-- Sundials linear solvers, e.g. `idaDlsSolver`.
let sundialsMatrixDense = lam n. sundialsMatrixDense n
external sundialsMatrixDenseUnwrap ! : SundialsMatrixDense -> Tensor[Float]
-- `sundialsMatrixDenseUnwrap m` unwraps the sundials dense matrix `m` to a rank
-- 2 tensor.
let sundialsMatrixDenseUnwrap = lam m. sundialsMatrixDenseUnwrap m
external sundialsNonlinearSolverNewtonMake
: NvectorSerial -> SundialsNonlinearSolver
-- `sundialsNonlinearSolverNewtonMake` creates a generic nonlinear solver based
-- on Newtons method.
let sundialsNonlinearSolverNewtonMake =
lam y. sundialsNonlinearSolverNewtonMake y
external sundialsNonlinearSolverFixedPointMake
: Int -> NvectorSerial -> SundialsNonlinearSolver
-- `sundialsNonlinearSolverFixedPointMake` creates a generic nonlinear solver
-- for fixed-point (functional) iteration with optional Anderson acceleration.
let sundialsNonlinearSolverFixedPointMake =
lam n. lam y. sundialsNonlinearSolverFixedPointMake n y