source: issm/trunk-jpl/src/jl/core/solutionsequences.jl@ 26738

Last change on this file since 26738 was 26738, checked in by Mathieu Morlighem, 3 years ago

CHG: account for passive elements now if the ice levelset crosses the domain

File size: 3.8 KB
Line 
1function solutionsequence_linear(femmodel::FemModel,analysis::Analysis) # {{{
2
3 #First, update constraints in case the levelset has changed
4 UpdateConstraintsx(femmodel, analysis)
5
6 #Get new matrices
7 Kff, Kfs, pf = SystemMatricesx(femmodel,analysis)
8
9 #Enforce constraints
10 ys = CreateNodalConstraintsx(femmodel.nodes)
11 Reduceloadx!(pf, Kfs, ys)
12
13 #Solve!
14 uf = Solverx(Kff, pf)
15
16 #Merge uf with ys and update inputs
17 gsize = NumberOfDofs(femmodel.nodes,GsetEnum)
18 ug = IssmVector(gsize)
19 Mergesolutionfromftogx(ug, uf, ys, femmodel.nodes)
20
21 InputUpdateFromSolutionx(analysis, ug, femmodel)
22
23end# }}}
24function solutionsequence_nonlinear(femmodel::FemModel,analysis::Analysis,maxiter::Int64,restol::Float64,reltol::Float64,abstol::Float64) # {{{
25
26 #First, update constraints in case the levelset has changed
27 UpdateConstraintsx(femmodel, analysis)
28
29 #Initialize number of iterations
30 count = 0
31 converged = false
32
33 #Get existing solution
34 ug = GetSolutionFromInputsx(analysis,femmodel)
35 uf = Reducevectorgtofx(ug,femmodel.nodes)
36
37 #Update once again the solution to make sure that vx and vxold are similar (for next step in transient or steadystate)
38 InputUpdateFromSolutionx(analysis,ug,femmodel)
39
40 #Loop until we reach convergence
41 while(~converged)
42
43 #Get new matrices
44 Kff, Kfs, pf = SystemMatricesx(femmodel,analysis)
45
46 #Enforce constraints
47 ys = CreateNodalConstraintsx(femmodel.nodes)
48 Reduceloadx!(pf, Kfs, ys)
49
50 #Solve!
51 old_uf = uf
52 uf = Solverx(Kff, pf, old_uf)
53
54 #Merge uf with ys
55 Mergesolutionfromftogx(ug, uf, ys, femmodel.nodes)
56
57 #Check for convergence
58 converged = convergence(Kff,pf,uf,old_uf,restol,reltol,abstol)
59 InputUpdateFromSolutionx(analysis,ug,femmodel)
60
61 #Increase count
62 count += 1
63 if(count>=maxiter)
64 println(" maximum number of nonlinear iterations (",maxiter,") exceeded")
65 converged = true
66 end
67 end
68
69 print("\n total number of iterations: ", count, "\n")
70
71end# }}}
72function convergence(Kff::IssmMatrix, pf::IssmVector, uf::IssmVector, old_uf::IssmVector, restol::Float64, reltol::Float64, abstol::Float64)#{{{
73
74 print(" checking convergence\n");
75
76 #If solution vector is empty, return true
77 if(IsEmpty(uf))
78 return true
79 end
80
81 #Convergence criterion #1: force equilibrium (Mandatory)
82 #compute K[n]U[n-1] - F
83 KUold = Duplicate(uf); MatMult!(Kff,old_uf,KUold)
84 KUoldF = Duplicate(KUold); VecCopy!(KUold, KUoldF); AXPY!(KUoldF, -1.0, pf)
85 nKUoldF = Norm(KUoldF,2)
86 nF = Norm(pf,2)
87 res = nKUoldF/nF
88 if ~isfinite(res)
89 println("norm nf = ", nF, " and norm kuold = ",nKUoldF)
90 error("mechanical equilibrium convergence criterion is not finite!")
91 end
92 if(res<restol)
93 print(" mechanical equilibrium convergence criterion ", res*100, " < ", restol*100, " %\n")
94 converged=true
95 else
96 print(" mechanical equilibrium convergence criterion ", res*100, " > ", restol*100, " %\n")
97 converged=false;
98 end
99
100 #Convergence criterion #2: norm(du)/norm(u)
101 if ~isnan(reltol)
102 duf = Duplicate(old_uf); VecCopy!(old_uf,duf); AXPY!(duf, -1.0, uf)
103 ndu = Norm(duf, 2); nu = Norm(old_uf, 2)
104 if ~isfinite(ndu) | ~isfinite(nu)
105 error("convergence criterion is not finite!")
106 end
107 if((ndu/nu)<reltol)
108 print(" Convergence criterion: norm(du)/norm(u) ", ndu/nu*100, " < ", reltol*100, " %\n")
109 else
110 print(" Convergence criterion: norm(du)/norm(u) ", ndu/nu*100, " > ", reltol*100, " %\n")
111 converged=false;
112 end
113 end
114
115 #Convergence criterion #3: max(du)
116 if ~isnan(abstol)
117 duf = Duplicate(old_uf); VecCopy!(old_uf,duf); AXPY!(duf, -1.0, uf)
118 nduinf= Norm(duf, 3)
119 if ~isfinite(nduinf)
120 error("convergence criterion is not finite!")
121 end
122 if(nduinf<abstol)
123 print(" Convergence criterion: max(du) ", nduinf, " < ", abstol, "\n")
124 else
125 print(" Convergence criterion: max(du) ", nduinf, " > ", abstol, "\n")
126 converged=false;
127 end
128 end
129
130 return converged
131
132end#}}}
Note: See TracBrowser for help on using the repository browser.