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