-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
sde_problems.jl
49 lines (44 loc) · 1.54 KB
/
sde_problems.jl
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
46
47
48
49
struct StandardSDEProblem end
struct SDEProblem{uType,tType,isinplace,NP,F,G,C,MM,ND} <: AbstractSDEProblem{uType,tType,isinplace,ND}
f::F
g::G
u0::uType
tspan::Tuple{tType,tType}
noise::NP
callback::C
mass_matrix::MM
noise_rate_prototype::ND
seed::UInt64
function SDEProblem{iip}(f,g,u0,tspan,problem_type=StandardSDEProblem();
noise_rate_prototype = nothing,
noise= nothing, seed = UInt64(0),
callback = nothing,mass_matrix=I) where {iip}
if mass_matrix == I && typeof(f) <: Tuple
_mm = ((I for i in 1:length(f))...)
else
_mm = mass_matrix
end
new{typeof(u0),promote_type(map(typeof,tspan)...),
iip,typeof(noise),typeof(f),typeof(g),
typeof(callback),typeof(_mm),
typeof(noise_rate_prototype)}(
f,g,u0,tspan,noise,callback,_mm,
noise_rate_prototype,seed)
end
end
function SDEProblem(f,g,u0,tspan;kwargs...)
iip = typeof(f)<: Tuple ? isinplace(f[2],3) : isinplace(f,3)
SDEProblem{iip}(f,g,u0,tspan;kwargs...)
end
abstract type AbstractSplitSDEProblem end
struct SplitSDEProblem{iip} <: AbstractSplitSDEProblem end
# u' = Au + f
function SplitSDEProblem(f1,f2,g,u0,tspan;kwargs...)
iip = isinplace(f2,3)
SplitSDEProblem{iip}(f1,f2,g,u0,tspan;kwargs...)
end
function SplitSDEProblem{iip}(f1,f2,g,u0,tspan;
func_cache=nothing,kwargs...) where iip
iip ? _func_cache = similar(u0) : _func_cache = nothing
SDEProblem{iip}(SplitFunction{iip}(f1,f2,_func_cache),g,u0,tspan,SplitSDEProblem{iip}();kwargs...)
end