source: issm/trunk-jpl/src/c/solutionsequences/solutionsequence_nonlinear.cpp@ 26468

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

CHG: removing extraneous lines

File size: 4.5 KB
RevLine 
[14992]1/*!\file: solutionsequence_nonlinear.cpp
[7637]2 * \brief: core of a non-linear solution, using fixed-point method
3 */
4
[15055]5#include "./solutionsequences.h"
[7637]6#include "../toolkits/toolkits.h"
[15002]7#include "../classes/classes.h"
8#include "../shared/shared.h"
[7637]9#include "../modules/modules.h"
10
[14992]11void solutionsequence_nonlinear(FemModel* femmodel,bool conserve_loads){
[7637]12
13 /*intermediary: */
[13216]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;
[13622]22
[7637]23 int constraints_converged;
24 int num_unstable_constraints;
25
26 /*parameters:*/
27 int min_mechanical_constraints;
28 int max_nonlinear_iterations;
[13877]29 int configuration_type;
[18619]30 IssmDouble eps_res,eps_rel,eps_abs;
[7637]31
32 /*Recover parameters: */
[15771]33 femmodel->parameters->FindParam(&min_mechanical_constraints,StressbalanceRiftPenaltyThresholdEnum);
34 femmodel->parameters->FindParam(&max_nonlinear_iterations,StressbalanceMaxiterEnum);
[18619]35 femmodel->parameters->FindParam(&eps_res,StressbalanceRestolEnum);
36 femmodel->parameters->FindParam(&eps_rel,StressbalanceReltolEnum);
37 femmodel->parameters->FindParam(&eps_abs,StressbalanceAbstolEnum);
[8815]38 femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
[13693]39 femmodel->UpdateConstraintsx();
[8803]40
[7637]41 /*Were loads requested as output? : */
[25549]42 Loads* savedloads=NULL;
[13877]43 if(conserve_loads){
44 savedloads = static_cast<Loads*>(femmodel->loads->Copy());
45 }
[7637]46
[25549]47 int count=0;
48 bool converged=false;
[7637]49
50 /*Start non-linear iteration using input velocity: */
[15849]51 GetSolutionFromInputsx(&ug,femmodel);
[8803]52 Reducevectorgtofx(&uf, ug, femmodel->nodes,femmodel->parameters);
[7637]53
[24680]54 /*Update once again the solution to make sure that vx and vxold are similar (for next step in transient or steadystate)*/
[15849]55 InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
[19746]56 InputUpdateFromSolutionx(femmodel,ug);
[7637]57
[24680]58 /*allocate the matrices once and reuse them per iteration*/
59 if(femmodel->loads->numrifts == 0){
60 AllocateSystemMatricesx(&Kff,&Kfs,&df,&pf,femmodel);
61 }
[24679]62
[7637]63 for(;;){
64
65 //save pointer to old velocity
[14891]66 delete old_uf;old_uf=uf;
[15197]67 delete ug;
[7637]68
[24680]69 if(femmodel->loads->numrifts){
70 AllocateSystemMatricesx(&Kff,&Kfs,&df,&pf,femmodel);
71 }
[24679]72 SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel, true);
[23587]73 CreateNodalConstraintsx(&ys,femmodel->nodes);
[24679]74 Reduceloadx(pf, Kfs, ys);
[22551]75 femmodel->profiler->Start(SOLVER);
[7637]76 Solverx(&uf, Kff, pf, old_uf, df, femmodel->parameters);
[22551]77 femmodel->profiler->Stop(SOLVER);
[26468]78
[14891]79 Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete ys;
[11293]80
[24679]81 convergence(&converged,Kff,pf,uf,old_uf,eps_res,eps_rel,eps_abs);
[15849]82 InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
83 InputUpdateFromSolutionx(femmodel,ug);
[7637]84
[24681]85 /*Clean up if rifts*/
86 if(femmodel->loads->numrifts){
87 delete Kfs; delete Kff; delete pf; delete df;
88 }
89
[15849]90 ConstraintsStatex(&constraints_converged,&num_unstable_constraints,femmodel);
[15100]91 if(VerboseConvergence()) _printf0_(" number of unstable constraints: " << num_unstable_constraints << "\n");
[7637]92
93 //rift convergence
94 if (!constraints_converged) {
95 if (converged){
[11284]96 if (num_unstable_constraints <= min_mechanical_constraints) converged=true;
97 else converged=false;
[7637]98 }
99 }
[26468]100
[7637]101 /*Increase count: */
102 count++;
[12271]103 if(converged==true){
[25531]104 femmodel->results->AddResult(new GenericExternalResult<int>(femmodel->results->Size()+1,StressbalanceConvergenceNumStepsEnum,count));
[12271]105 break;
106 }
[7637]107 if(count>=max_nonlinear_iterations){
[15104]108 _printf0_(" maximum number of nonlinear iterations (" << max_nonlinear_iterations << ") exceeded\n");
[11347]109 converged=true;
[25531]110 femmodel->results->AddResult(new GenericExternalResult<int>(femmodel->results->Size()+1,StressbalanceConvergenceNumStepsEnum,max_nonlinear_iterations));
[15849]111 InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
112 InputUpdateFromSolutionx(femmodel,ug);
[7637]113 break;
114 }
[24679]115
[24681]116 /*Set the matrix entries to zero if we do an other iteration*/
117 if(femmodel->loads->numrifts==0){
118 Kff->SetZero();
119 Kfs->SetZero();
120 df->Set(0);
121 pf->Set(0);
122 }
[7637]123 }
124
[24681]125 /*delete matrices after the iteration loop*/
126 if(femmodel->loads->numrifts==0){
127 delete Kff; delete pf; delete df; delete Kfs;
128 }
[24679]129
[21451]130 if(VerboseConvergence()) _printf0_("\n total number of iterations: " << count << "\n");
[11322]131
[7637]132 /*clean-up*/
[13877]133 if(conserve_loads){
134 delete femmodel->loads;
[23488]135 int index=femmodel->AnalysisIndex(configuration_type);
136 femmodel->loads_list[index]=savedloads;
[13877]137 femmodel->loads=savedloads;
138 }
[14891]139 delete uf;
140 delete ug;
141 delete old_uf;
[7637]142}
Note: See TracBrowser for help on using the repository browser.