Skip to content

Commit feee402

Browse files
all resize with multiscale
1 parent a6c5fc3 commit feee402

File tree

3 files changed

+74
-70
lines changed

3 files changed

+74
-70
lines changed

src/caches.jl

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,33 @@ function alg_cache{T,algType<:StochasticCompositeAlgorithm}(alg::algType,u,ΔW,
1414
end
1515

1616
immutable EMConstantCache <: StochasticDiffEqConstantCache end
17-
immutable EMCache{uType} <: StochasticDiffEqMutableCache
17+
immutable EMCache{uType,rateType} <: StochasticDiffEqMutableCache
1818
u::uType
1919
uprev::uType
2020
tmp::uType
21-
utmp2::uType
21+
rtmp1::rateType
22+
rtmp2::rateType
2223
end
2324

2425
u_cache(c::EMCache) = ()
25-
du_cache(c::EMCache) = (c.utmp2,)
26+
du_cache(c::EMCache) = (c.rtmp1,c.rtmp2)
2627

2728
alg_cache(alg::EM,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits,uprev,f,t,::Type{Val{false}}) = EMConstantCache()
2829

2930
function alg_cache(alg::EM,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits,uprev,f,t,::Type{Val{true}})
30-
tmp = similar(u); utmp2 = similar(u)
31-
EMCache(u,uprev,tmp,utmp2)
31+
tmp = similar(u); rtmp1 = zeros(rate_prototype); rtmp2 = zeros(rate_prototype)
32+
EMCache(u,uprev,tmp,rtmp1,rtmp2)
3233
end
3334

3435
immutable RKMilConstantCache <: StochasticDiffEqConstantCache end
35-
immutable RKMilCache{uType} <: StochasticDiffEqMutableCache
36+
immutable RKMilCache{uType,rateType} <: StochasticDiffEqMutableCache
3637
u::uType
3738
uprev::uType
38-
du1::uType
39-
du2::uType
40-
K::uType
39+
du1::rateType
40+
du2::rateType
41+
K::rateType
4142
tmp::uType
42-
L::uType
43+
L::rateType
4344
end
4445

4546
u_cache(c::RKMilCache) = ()
@@ -48,36 +49,37 @@ du_cache(c::RKMilCache) = (c.du1,c.du2,c.K,c.L)
4849
alg_cache(alg::RKMil,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits,uprev,f,t,::Type{Val{false}}) = RKMilConstantCache()
4950

5051
function alg_cache(alg::RKMil,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits,uprev,f,t,::Type{Val{true}})
51-
du1 = similar(u); du2 = similar(u)
52-
K = similar(u); tmp = similar(u); L = similar(u)
52+
du1 = zeros(rate_prototype); du2 = zeros(rate_prototype)
53+
K = zeros(rate_prototype); tmp = similar(u); L = zeros(rate_prototype)
5354
RKMilCache(u,uprev,du1,du2,K,tmp,L)
5455
end
5556

5657
immutable SRA1ConstantCache <: StochasticDiffEqConstantCache end
5758
alg_cache(alg::SRA1,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits,uprev,f,t,::Type{Val{false}}) = SRA1ConstantCache()
5859

59-
immutable SRA1Cache{randType,uType} <: StochasticDiffEqMutableCache
60+
immutable SRA1Cache{randType,rateType,uType} <: StochasticDiffEqMutableCache
6061
u::uType
6162
uprev::uType
6263
chi2::randType
6364
tmp1::uType
64-
E₁::uType
65-
E₂::uType
66-
gt::uType
67-
k₁::uType
68-
k₂::uType
69-
gpdt::uType
65+
E₁::rateType
66+
E₂::rateType
67+
gt::rateType
68+
k₁::rateType
69+
k₂::rateType
70+
gpdt::rateType
7071
tmp::uType
7172
end
7273

7374
u_cache(c::SRA1Cache) = ()
74-
du_cache(c::SRA1Cache) = (c.chi2,c.tmp1,c.E₁,c.E₂,c.gt,c.k₁,c.k₂,c.gpdt)
75+
du_cache(c::SRA1Cache) = (c.chi2,c.E₁,c.E₂,c.gt,c.k₁,c.k₂,c.gpdt)
76+
user_cache(c::SRA1Cache) = (c.u,c.uprev,c.tmp,c.tmp1)
7577

7678
function alg_cache(alg::SRA1,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits,uprev,f,t,::Type{Val{true}})
7779
chi2 = similar(ΔW)
7880
tmp1 = zeros(u)
79-
E₁ = zeros(u); gt = zeros(u); gpdt = zeros(u)
80-
E₂ = zeros(u); k₁ = zeros(u); k₂ = zeros(u)
81+
E₁ = zeros(rate_prototype); gt = zeros(rate_prototype); gpdt = zeros(rate_prototype)
82+
E₂ = zeros(rate_prototype); k₁ = zeros(rate_prototype); k₂ = zeros(rate_prototype)
8183
tmp = zeros(u)
8284
SRA1Cache(u,uprev,chi2,tmp1,E₁,E₂,gt,k₁,k₂,gpdt,tmp)
8385
end
@@ -105,38 +107,39 @@ function alg_cache(alg::SRA,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits
105107
SRAConstantCache(alg.tableau,rate_prototype)
106108
end
107109

108-
immutable SRACache{uType,tabType} <: StochasticDiffEqMutableCache
110+
immutable SRACache{uType,rateType,tabType} <: StochasticDiffEqMutableCache
109111
u::uType
110112
uprev::uType
111113
H0::Vector{uType}
112-
A0temp::uType
113-
B0temp::uType
114-
ftmp::uType
115-
gtmp::uType
116-
chi2::uType
117-
atemp::uType
118-
btemp::uType
119-
E₁::uType
120-
E₁temp::uType
121-
E₂::uType
114+
A0temp::rateType
115+
B0temp::rateType
116+
ftmp::rateType
117+
gtmp::rateType
118+
chi2::rateType
119+
atemp::rateType
120+
btemp::rateType
121+
E₁::rateType
122+
E₁temp::rateType
123+
E₂::rateType
122124
tmp::uType
123125
tab::tabType
124126
end
125127

126128
u_cache(c::SRACache) = ()
127129
du_cache(c::SRACache) = (c.A0temp,c.B0temp,c.ftmp,c.gtmp,c.chi2,c.chi2,c.atemp,
128-
c.btemp,c.E₁,c.E₁temp,c.E₂,c.H0...)
130+
c.btemp,c.E₁,c.E₁temp,c.E₂)
131+
user_cache(c::SRACache) = (c.u,c.uprev,c.tmp,c.H0...)
129132

130133
function alg_cache(alg::SRA,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits,uprev,f,t,::Type{Val{true}})
131134
H0 = Vector{typeof(u)}(0)
132135
tab = SRAConstantCache(alg.tableau,rate_prototype)
133136
for i = 1:tab.stages
134137
push!(H0,zeros(u))
135138
end
136-
A0temp = zeros(u); B0temp = zeros(u)
137-
ftmp = zeros(u); gtmp = zeros(u); chi2 = zeros(u)
138-
atemp = zeros(u); btemp = zeros(u); E₂ = zeros(u); E₁temp = zeros(u)
139-
E₁ = zeros(u)
139+
A0temp = zeros(rate_prototype); B0temp = zeros(rate_prototype)
140+
ftmp = zeros(rate_prototype); gtmp = zeros(rate_prototype); chi2 = zeros(rate_prototype)
141+
atemp = zeros(rate_prototype); btemp = zeros(rate_prototype); E₂ = zeros(rate_prototype); E₁temp = zeros(rate_prototype)
142+
E₁ = zeros(rate_prototype)
140143
tmp = zeros(u)
141144
SRACache(u,uprev,H0,A0temp,B0temp,ftmp,gtmp,chi2,atemp,btemp,E₁,E₁temp,E₂,tmp,tab)
142145
end
@@ -171,26 +174,26 @@ function alg_cache(alg::SRI,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits
171174
SRIConstantCache(alg.tableau,rate_prototype,alg.error_terms)
172175
end
173176

174-
immutable SRICache{randType,uType,tabType} <: StochasticDiffEqMutableCache
177+
immutable SRICache{randType,uType,rateType,tabType} <: StochasticDiffEqMutableCache
175178
u::uType
176179
uprev::uType
177180
H0::Vector{uType}
178181
H1::Vector{uType}
179-
A0temp::uType
180-
A1temp::uType
181-
B0temp::uType
182-
B1temp::uType
183-
A0temp2::uType
184-
A1temp2::uType
185-
B0temp2::uType
186-
B1temp2::uType
187-
atemp::uType
188-
btemp::uType
189-
E₁::uType
190-
E₂::uType
191-
E₁temp::uType
192-
ftemp::uType
193-
gtemp::uType
182+
A0temp::rateType
183+
A1temp::rateType
184+
B0temp::rateType
185+
B1temp::rateType
186+
A0temp2::rateType
187+
A1temp2::rateType
188+
B0temp2::rateType
189+
B1temp2::rateType
190+
atemp::rateType
191+
btemp::rateType
192+
E₁::rateType
193+
E₂::rateType
194+
E₁temp::rateType
195+
ftemp::rateType
196+
gtemp::rateType
194197
chi1::randType
195198
chi2::randType
196199
chi3::randType
@@ -201,9 +204,8 @@ end
201204
u_cache(c::SRICache) = ()
202205
du_cache(c::SRICache) = (c.A0temp,c.A1temp,c.B0temp,c.B1temp,c.A0temp2,c.A1temp2,
203206
c.B0temp2,c.B1temp2,c.atemp,c.btemp,c.E₁,c.E₂,c.E₁temp,
204-
c.ftemp,c.gtemp,c.chi1,c.chi2,c.chi3,
205-
c.H0...,c.H1...)
206-
207+
c.ftemp,c.gtemp,c.chi1,c.chi2,c.chi3)
208+
user_cache(c::SRICache) = (c.u,c.uprev,c.tmp,c.H0...,c.H1...)
207209

208210
function alg_cache(alg::SRI,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits,uprev,f,t,::Type{Val{true}})
209211
H0 = Vector{typeof(u)}(0)
@@ -214,13 +216,13 @@ function alg_cache(alg::SRI,u,ΔW,ΔZ,rate_prototype,uEltypeNoUnits,tTypeNoUnits
214216
push!(H1,zeros(u))
215217
end
216218
#TODO Reduce memory
217-
A0temp = zeros(u); A1temp = zeros(u)
218-
B0temp = zeros(u); B1temp = zeros(u)
219-
A0temp2 = zeros(u); A1temp2 = zeros(u)
220-
B0temp2 = zeros(u); B1temp2 = zeros(u)
221-
atemp = zeros(u); btemp = zeros(u)
222-
E₁ = zeros(u); E₂ = zeros(u); E₁temp = zeros(u)
223-
ftemp = zeros(u); gtemp = zeros(u)
219+
A0temp = zeros(rate_prototype); A1temp = zeros(rate_prototype)
220+
B0temp = zeros(rate_prototype); B1temp = zeros(rate_prototype)
221+
A0temp2 = zeros(rate_prototype); A1temp2 = zeros(rate_prototype)
222+
B0temp2 = zeros(rate_prototype); B1temp2 = zeros(rate_prototype)
223+
atemp = zeros(rate_prototype); btemp = zeros(rate_prototype)
224+
E₁ = zeros(rate_prototype); E₂ = zeros(rate_prototype); E₁temp = zeros(rate_prototype)
225+
ftemp = zeros(rate_prototype); gtemp = zeros(rate_prototype)
224226
chi1 = similar(ΔW); chi2 = similar(ΔW); chi3 = similar(ΔW)
225227
tmp = zeros(u)
226228
SRICache(u,uprev,H0,H1,A0temp,A1temp,B0temp,B1temp,A0temp2,A1temp2,B0temp2,B1temp2,

src/integrators/low_order.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
end
66

77
@inline function perform_step!(integrator,cache::EMCache,f=integrator.f)
8-
@unpack tmp,utmp2 = cache
8+
@unpack rtmp1,rtmp2 = cache
99
@unpack t,dt,uprev,u,ΔW = integrator
10-
integrator.f(t,uprev,tmp)
11-
integrator.g(t,uprev,utmp2)
10+
integrator.f(t,uprev,rtmp1)
11+
integrator.g(t,uprev,rtmp2)
1212
for i in eachindex(u)
13-
u[i] = @muladd uprev[i] + dt*tmp[i] + utmp2[i]*ΔW[i]
13+
u[i] = @muladd uprev[i] + dt*rtmp1[i] + rtmp2[i]*ΔW[i]
1414
end
1515
@pack integrator = t,dt,u
1616
end

src/integrators/sri.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
B1temp[k] = @muladd B1temp[k] + B₁[j,i]*gtemp[k]
2727
end
2828
end
29-
H0[i] = uprev + A0temp*dt + B0temp.*chi2
30-
H1[i] = uprev + A1temp*dt + B1temp*integrator.sqdt
29+
for k in eachindex(u)
30+
H0[i][k] = uprev[k] + A0temp[k]*dt + B0temp[k]*chi2[k]
31+
H1[i][k] = uprev[k] + A1temp[k]*dt + B1temp[k]*integrator.sqdt
32+
end
3133
end
3234
fill!(atemp,zero(eltype(integrator.u)))
3335
fill!(btemp,zero(eltype(integrator.u)))

0 commit comments

Comments
 (0)