1 | /*!\file: solutionsequence_nonlinear.cpp
|
---|
2 | * \brief: core of a non-linear solution, using fixed-point method
|
---|
3 | */
|
---|
4 |
|
---|
5 | #include "./solutionsequences.h"
|
---|
6 | #include "../toolkits/toolkits.h"
|
---|
7 | #include "../classes/classes.h"
|
---|
8 | #include "../shared/shared.h"
|
---|
9 | #include "../modules/modules.h"
|
---|
10 |
|
---|
11 | void solutionsequence_nonlinear(FemModel* femmodel,bool conserve_loads){
|
---|
12 |
|
---|
13 | /*intermediary: */
|
---|
14 | Matrix<IssmDouble>* Kff = NULL;
|
---|
15 | Matrix<IssmDouble>* Kfs = NULL;
|
---|
16 | Vector<IssmDouble>* ug = NULL;
|
---|
17 | Vector<IssmDouble>* uf = NULL;
|
---|
18 | Vector<IssmDouble>* old_uf = NULL;
|
---|
19 | Vector<IssmDouble>* pf = NULL;
|
---|
20 | Vector<IssmDouble>* df = NULL;
|
---|
21 | Vector<IssmDouble>* ys = NULL;
|
---|
22 |
|
---|
23 | Vec res;
|
---|
24 | double resNorm;
|
---|
25 |
|
---|
26 |
|
---|
27 | Loads* savedloads=NULL;
|
---|
28 | bool converged;
|
---|
29 | int constraints_converged;
|
---|
30 | int num_unstable_constraints;
|
---|
31 | int count;
|
---|
32 |
|
---|
33 | /*parameters:*/
|
---|
34 | int min_mechanical_constraints;
|
---|
35 | int max_nonlinear_iterations;
|
---|
36 | int configuration_type;
|
---|
37 | IssmDouble eps_res,eps_rel,eps_abs;
|
---|
38 |
|
---|
39 | /*Recover parameters: */
|
---|
40 | femmodel->parameters->FindParam(&min_mechanical_constraints,StressbalanceRiftPenaltyThresholdEnum);
|
---|
41 | femmodel->parameters->FindParam(&max_nonlinear_iterations,StressbalanceMaxiterEnum);
|
---|
42 | femmodel->parameters->FindParam(&eps_res,StressbalanceRestolEnum);
|
---|
43 | femmodel->parameters->FindParam(&eps_rel,StressbalanceReltolEnum);
|
---|
44 | femmodel->parameters->FindParam(&eps_abs,StressbalanceAbstolEnum);
|
---|
45 | femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
|
---|
46 | femmodel->UpdateConstraintsx();
|
---|
47 |
|
---|
48 | /*Were loads requested as output? : */
|
---|
49 | if(conserve_loads){
|
---|
50 | savedloads = static_cast<Loads*>(femmodel->loads->Copy());
|
---|
51 | }
|
---|
52 |
|
---|
53 | count=0;
|
---|
54 | converged=false;
|
---|
55 |
|
---|
56 | /*Start non-linear iteration using input velocity: */
|
---|
57 | GetSolutionFromInputsx(&ug,femmodel);
|
---|
58 | Reducevectorgtofx(&uf, ug, femmodel->nodes,femmodel->parameters);
|
---|
59 |
|
---|
60 | //Update once again the solution to make sure that vx and vxold are similar (for next step in transient or steadystate)
|
---|
61 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
---|
62 | InputUpdateFromSolutionx(femmodel,ug);
|
---|
63 |
|
---|
64 | for(;;){
|
---|
65 |
|
---|
66 | //save pointer to old velocity
|
---|
67 | delete old_uf;old_uf=uf;
|
---|
68 | delete ug;
|
---|
69 |
|
---|
70 | SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel);
|
---|
71 | CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
|
---|
72 | Reduceloadx(pf, Kfs, ys); delete Kfs;
|
---|
73 | femmodel->profiler->Start(SOLVER);
|
---|
74 | Solverx(&uf, Kff, pf, old_uf, df, femmodel->parameters);
|
---|
75 | femmodel->profiler->Stop(SOLVER);
|
---|
76 |
|
---|
77 |
|
---|
78 | // VecDuplicate(uf->pvector->vector,&res);
|
---|
79 | // VecCopy(uf->pvector->vector,res);
|
---|
80 | // VecAssemblyBegin(res);
|
---|
81 | // VecAssemblyEnd(res);
|
---|
82 | // VecScale(pf->pvector->vector,-1.);
|
---|
83 | // MatMultAdd(Kff->pmatrix->matrix,uf->pvector->vector,pf->pvector->vector,res);
|
---|
84 | // VecScale(pf->pvector->vector,-1.);
|
---|
85 | // VecView(pf->pvector->vector,PETSC_VIEWER_STDOUT_WORLD);
|
---|
86 | // VecNorm(res,NORM_INFINITY,&resNorm);
|
---|
87 | // PetscPrintf(PETSC_COMM_WORLD,"Count = %d, Res. norm: %g\n", count,resNorm);
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 | Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete ys;
|
---|
93 |
|
---|
94 | convergence(&converged,Kff,pf,uf,old_uf,eps_res,eps_rel,eps_abs); delete Kff; delete pf; delete df;
|
---|
95 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
---|
96 | InputUpdateFromSolutionx(femmodel,ug);
|
---|
97 |
|
---|
98 | ConstraintsStatex(&constraints_converged,&num_unstable_constraints,femmodel);
|
---|
99 | if(VerboseConvergence()) _printf0_(" number of unstable constraints: " << num_unstable_constraints << "\n");
|
---|
100 |
|
---|
101 | //rift convergence
|
---|
102 | if (!constraints_converged) {
|
---|
103 | if (converged){
|
---|
104 | if (num_unstable_constraints <= min_mechanical_constraints) converged=true;
|
---|
105 | else converged=false;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*Increase count: */
|
---|
110 | count++;
|
---|
111 | if(converged==true){
|
---|
112 | femmodel->results->AddResult(new GenericExternalResult<IssmDouble>(femmodel->results->Size()+1,StressbalanceConvergenceNumStepsEnum,count));
|
---|
113 | break;
|
---|
114 | }
|
---|
115 | if(count>=max_nonlinear_iterations){
|
---|
116 | _printf0_(" maximum number of nonlinear iterations (" << max_nonlinear_iterations << ") exceeded\n");
|
---|
117 | converged=true;
|
---|
118 | femmodel->results->AddResult(new GenericExternalResult<IssmDouble>(femmodel->results->Size()+1,StressbalanceConvergenceNumStepsEnum,max_nonlinear_iterations));
|
---|
119 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
---|
120 | InputUpdateFromSolutionx(femmodel,ug);
|
---|
121 | break;
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | if(VerboseConvergence()) _printf0_("\n total number of iterations: " << count << "\n");
|
---|
126 |
|
---|
127 | /*clean-up*/
|
---|
128 | if(conserve_loads){
|
---|
129 | delete femmodel->loads;
|
---|
130 | femmodel->loads=savedloads;
|
---|
131 | }
|
---|
132 | delete uf;
|
---|
133 | delete ug;
|
---|
134 | delete old_uf;
|
---|
135 | }
|
---|