Skip to content

Commit 061244e

Browse files
SpringBlockNonLinearResistance.jmd fixes
1 parent bffb41c commit 061244e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

benchmarks/ComplicatedPDE/SpringBlockNonLinearResistance.jmd

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function convU0(uvec)
4040
m[:,:,3] = vec2matrix(uvec[2Nx*Ny+1:3*Nx*Ny])
4141
return m
4242
end
43+
4344
#Model Parameters---------------------------------------------------------------------------------------------------------------------
4445
#Model size
4546
const Nx = 66;
@@ -58,7 +59,7 @@ const τ0 = 0.4;
5859
const Dc = get_parameterDistribution(0.004,1e2*0.004);
5960
const a = 0.015;
6061
const b = get_parameterDistribution(0.02,0.01);
61-
#ODE----------------------------------------------------------------------------------------------------------------------------------
62+
6263
function f0(du,u,p,t)
6364
#du+dθ-----------------------------------------------------------------------
6465
@inbounds for i in 1:Nx, j in 1:Ny
@@ -92,7 +93,7 @@ function f0(du,u,p,t)
9293
du[Ny,Nx,2] = @. 1/m*kc*(u[Ny,Nx-1,1]+u[Ny-1,Nx,1]-2*u[Ny,Nx,1]) - 1/m*kp*u[Ny,Nx,1] - 1/m*σn[Ny,Nx]*a*asinh(u[Ny,Nx,2]/2/v0*exp((τ0+b[Ny,Nx]*log(v0*abs(u[Ny,Nx,3])/Dc[Ny,Nx]))/a))
9394
end
9495
end
95-
#Initial Conditions---------------------------------------------------------------------------------------------------------------------------
96+
9697
function get_IC()
9798
#derives initial conditions from equilibrium + perturbation of the initial position using GaussianRandomFields
9899
probN = NonlinearProblem(f,input, nothing);
@@ -106,8 +107,7 @@ function get_IC()
106107
u0[:,:,1] = (1.0.+0.001.-1e-7.*s[1:Ny,1:Nx]).*u0[:,:,1] #makes sure only forward acceleration takes place when launching the simulation
107108
return u0
108109
end
109-
#ODE Speed-up----------------------------------------------------------------------------------------------------------------
110-
#copy of https://docs.sciml.ai/SciMLBenchmarksOutput/stable/StiffODE/Bruss/
110+
111111
input = rand(Ny,Nx,3);
112112
output = similar(input);
113113
sparsity_pattern = Symbolics.jacobian_sparsity(f0,output,input,nothing,0.0);
@@ -123,23 +123,23 @@ cb2 = DiscreteCallback(is_end,terminate!,save_positions=(false,false))
123123
solver = KenCarp47(linsolve=KLUFactorization());
124124
abstol = 1e-12;
125125
reltol = 1e-8;
126-
#--------------------------------------------------------------------------------------------------------------------------------
127-
#Solve the ODE in 2 parts: (1) low cumulative velocity (<0.01) phase, (2) high cumulative velocity (>0.01) phase. When interested in multiple stick (1) and slip (2) phases, the code of (1) and (2) would typically run within a `while`-loop
128-
#for Work-Precision Diagram, use either (1)+(2); or just (2)
129-
#code (1): From u0 to onset of high cumulative velocity (>0.01)
126+
130127
u0 = get_IC();
131128
tspan = (0.0,1e9);
132129
prob1 = ODEProblem(f,u0,tspan,nothing);
133130
sys = modelingtoolkitize(prob1);
134-
prob_mtk1 = ODEProblem(modelingtoolkitize(prob1),[],tspan,jac=true,sparse=true);
131+
sys_simplified = structural_simplify(sys)
132+
prob_mtk1 = ODEProblem(sys_simplified,[],tspan,jac=true,sparse=true);
135133
global sol,tcpu, bytes, gctime, memallocs = @timed solve(prob_mtk1,solver,reltol = reltol,abstol = abstol,maxiters = Int(1e12),save_everystep = false,dtmin = 1e-20,callback = cb1); #about 55 sec
136134
u1 = sol.u[end];
137135
t1 = sol.t[end];
138136
test_sol1 = TestSolution(sol)
139137
#code (2): high cumulative velocity (>0.01) following phase (1)
140138
tspan = (0.0,1e4);
141139
prob2 = ODEProblem(f,convU0(u1),tspan,nothing);
142-
prob_mtk2 = ODEProblem(modelingtoolkitize(prob2),[],tspan,jac=true,sparse=true);
140+
sys2 = modelingtoolkitize(prob2);
141+
sys2_simplified = structural_simplify(sys2)
142+
prob_mtk2 = ODEProblem(sys2_simplified,[],tspan,jac=true,sparse=true);
143143
global sol,tcpu, bytes, gctime, memallocs = @timed solve(prob_mtk2,solver,reltol = reltol,abstol = abstol,maxiters = Int(1e12),save_everystep = false,dtmin = 1e-20,callback = cb2); #about 175 sec
144144
u2 = sol.u[end];
145145
t2 = t1 + sol.t[end];

0 commit comments

Comments
 (0)