@@ -40,6 +40,7 @@ function convU0(uvec)
4040 m[:,:,3] = vec2matrix(uvec[2Nx*Ny+1:3*Nx*Ny])
4141 return m
4242end
43+
4344#Model Parameters---------------------------------------------------------------------------------------------------------------------
4445#Model size
4546const Nx = 66;
@@ -58,7 +59,7 @@ const τ0 = 0.4;
5859const Dc = get_parameterDistribution(0.004,1e2*0.004);
5960const a = 0.015;
6061const b = get_parameterDistribution(0.02,0.01);
61- #ODE----------------------------------------------------------------------------------------------------------------------------------
62+
6263function 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
9495end
95- #Initial Conditions---------------------------------------------------------------------------------------------------------------------------
96+
9697function 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
108109end
109- #ODE Speed-up----------------------------------------------------------------------------------------------------------------
110- #copy of https://docs.sciml.ai/SciMLBenchmarksOutput/stable/StiffODE/Bruss/
110+
111111input = rand(Ny,Nx,3);
112112output = similar(input);
113113sparsity_pattern = Symbolics.jacobian_sparsity(f0,output,input,nothing,0.0);
@@ -123,23 +123,23 @@ cb2 = DiscreteCallback(is_end,terminate!,save_positions=(false,false))
123123solver = KenCarp47(linsolve=KLUFactorization());
124124abstol = 1e-12;
125125reltol = 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+
130127u0 = get_IC();
131128tspan = (0.0,1e9);
132129prob1 = ODEProblem(f,u0,tspan,nothing);
133130sys = 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);
135133global 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
136134u1 = sol.u[end];
137135t1 = sol.t[end];
138136test_sol1 = TestSolution(sol)
139137#code (2): high cumulative velocity (>0.01) following phase (1)
140138tspan = (0.0,1e4);
141139prob2 = 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);
143143global 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
144144u2 = sol.u[end];
145145t2 = t1 + sol.t[end];
0 commit comments