-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from JuliaDiffEq/double_implicit
Noise implicit methods
- Loading branch information
Showing
10 changed files
with
620 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
mutable struct ISSEMCache{uType,rateType,J,JC,UF,uEltypeNoUnits,noiseRateType,F} <: StochasticDiffEqMutableCache | ||
u::uType | ||
uprev::uType | ||
du1::rateType | ||
fsalfirst::rateType | ||
k::rateType | ||
z::uType | ||
dz::uType | ||
tmp::uType | ||
gtmp::noiseRateType | ||
gtmp2::rateType | ||
J::J | ||
W::J | ||
jac_config::JC | ||
linsolve::F | ||
uf::UF | ||
ηold::uEltypeNoUnits | ||
κ::uEltypeNoUnits | ||
tol::uEltypeNoUnits | ||
newton_iters::Int | ||
end | ||
|
||
u_cache(c::ISSEMCache) = (c.uprev2,c.z,c.dz) | ||
du_cache(c::ISSEMCache) = (c.k,c.fsalfirst) | ||
|
||
function alg_cache(alg::ISSEM,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype, | ||
uEltypeNoUnits,uBottomEltype,tTypeNoUnits,uprev,f,t,::Type{Val{true}}) | ||
du1 = zeros(rate_prototype) | ||
J = zeros(uEltypeNoUnits,length(u),length(u)) # uEltype? | ||
W = similar(J) | ||
z = similar(u) | ||
dz = similar(u); tmp = similar(u); gtmp = similar(noise_rate_prototype) | ||
fsalfirst = zeros(rate_prototype) | ||
k = zeros(rate_prototype) | ||
|
||
uf = DiffEqDiffTools.UJacobianWrapper(f,t,p) | ||
linsolve = alg.linsolve(Val{:init},uf,u) | ||
jac_config = build_jac_config(alg,f,uf,du1,uprev,u,tmp,dz) | ||
ηold = one(uEltypeNoUnits) | ||
|
||
if alg.κ != nothing | ||
κ = alg.κ | ||
else | ||
κ = uEltypeNoUnits(1//100) | ||
end | ||
if alg.tol != nothing | ||
tol = alg.tol | ||
else | ||
reltol = 1e-1 # TODO: generalize | ||
tol = min(0.03,first(reltol)^(0.5)) | ||
end | ||
|
||
if is_diagonal_noise(prob) | ||
gtmp2 = gtmp | ||
else | ||
gtmp2 = similar(rate_prototype) | ||
end | ||
|
||
ISSEMCache(u,uprev,du1,fsalfirst,k,z,dz,tmp,gtmp,gtmp2,J,W,jac_config,linsolve,uf, | ||
ηold,κ,tol,10000) | ||
end | ||
|
||
mutable struct ISSEMConstantCache{F,uEltypeNoUnits} <: StochasticDiffEqConstantCache | ||
uf::F | ||
ηold::uEltypeNoUnits | ||
κ::uEltypeNoUnits | ||
tol::uEltypeNoUnits | ||
newton_iters::Int | ||
end | ||
|
||
function alg_cache(alg::ISSEM,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype, | ||
uEltypeNoUnits,uBottomEltype,tTypeNoUnits,uprev,f,t,::Type{Val{false}}) | ||
uf = DiffEqDiffTools.UDerivativeWrapper(f,t,p) | ||
ηold = one(uEltypeNoUnits) | ||
|
||
if alg.κ != nothing | ||
κ = alg.κ | ||
else | ||
κ = uEltypeNoUnits(1//100) | ||
end | ||
if alg.tol != nothing | ||
tol = alg.tol | ||
else | ||
reltol = 1e-1 # TODO: generalize | ||
tol = min(0.03,first(reltol)^(0.5)) | ||
end | ||
|
||
ISSEMConstantCache(uf,ηold,κ,tol,100000) | ||
end | ||
|
||
mutable struct ISSEulerHeunCache{uType,rateType,J,JC,UF,uEltypeNoUnits,noiseRateType,F} <: StochasticDiffEqMutableCache | ||
u::uType | ||
uprev::uType | ||
du1::rateType | ||
fsalfirst::rateType | ||
k::rateType | ||
z::uType | ||
dz::uType | ||
tmp::uType | ||
gtmp::noiseRateType | ||
gtmp2::rateType | ||
gtmp3::noiseRateType | ||
J::J | ||
W::J | ||
jac_config::JC | ||
linsolve::F | ||
uf::UF | ||
ηold::uEltypeNoUnits | ||
κ::uEltypeNoUnits | ||
tol::uEltypeNoUnits | ||
newton_iters::Int | ||
end | ||
|
||
u_cache(c::ISSEulerHeunCache) = (c.uprev2,c.z,c.dz) | ||
du_cache(c::ISSEulerHeunCache) = (c.k,c.fsalfirst) | ||
|
||
function alg_cache(alg::ISSEulerHeun,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype, | ||
uEltypeNoUnits,uBottomEltype,tTypeNoUnits,uprev,f,t,::Type{Val{true}}) | ||
du1 = zeros(rate_prototype) | ||
J = zeros(uEltypeNoUnits,length(u),length(u)) # uEltype? | ||
W = similar(J) | ||
z = similar(u) | ||
dz = similar(u); tmp = similar(u); gtmp = similar(noise_rate_prototype) | ||
fsalfirst = zeros(rate_prototype) | ||
k = zeros(rate_prototype) | ||
|
||
uf = DiffEqDiffTools.UJacobianWrapper(f,t,p) | ||
linsolve = alg.linsolve(Val{:init},uf,u) | ||
jac_config = build_jac_config(alg,f,uf,du1,uprev,u,tmp,dz) | ||
ηold = one(uEltypeNoUnits) | ||
|
||
if alg.κ != nothing | ||
κ = alg.κ | ||
else | ||
κ = uEltypeNoUnits(1//100) | ||
end | ||
if alg.tol != nothing | ||
tol = alg.tol | ||
else | ||
reltol = 1e-1 # TODO: generalize | ||
tol = min(0.03,first(reltol)^(0.5)) | ||
end | ||
|
||
gtmp2 = similar(rate_prototype) | ||
|
||
if is_diagonal_noise(prob) | ||
gtmp3 = gtmp2 | ||
else | ||
gtmp3 = similar(noise_rate_prototype) | ||
end | ||
|
||
ISSEulerHeunCache(u,uprev,du1,fsalfirst,k,z,dz,tmp,gtmp,gtmp2,gtmp3, | ||
J,W,jac_config,linsolve,uf,ηold,κ,tol,10000) | ||
end | ||
|
||
mutable struct ISSEulerHeunConstantCache{F,uEltypeNoUnits} <: StochasticDiffEqConstantCache | ||
uf::F | ||
ηold::uEltypeNoUnits | ||
κ::uEltypeNoUnits | ||
tol::uEltypeNoUnits | ||
newton_iters::Int | ||
end | ||
|
||
function alg_cache(alg::ISSEulerHeun,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype, | ||
uEltypeNoUnits,uBottomEltype,tTypeNoUnits,uprev,f,t,::Type{Val{false}}) | ||
uf = DiffEqDiffTools.UDerivativeWrapper(f,t,p) | ||
ηold = one(uEltypeNoUnits) | ||
|
||
if alg.κ != nothing | ||
κ = alg.κ | ||
else | ||
κ = uEltypeNoUnits(1//100) | ||
end | ||
if alg.tol != nothing | ||
tol = alg.tol | ||
else | ||
reltol = 1e-1 # TODO: generalize | ||
tol = min(0.03,first(reltol)^(0.5)) | ||
end | ||
|
||
ISSEulerHeunConstantCache(uf,ηold,κ,tol,100000) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.