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

Last change on this file since 15849 was 15849, checked in by seroussi, 12 years ago

CHG: moved some modules back to src/modules and simplified some prototypes

File size: 3.7 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
[13877]23 Loads* savedloads=NULL;
[11284]24 bool converged;
[7637]25 int constraints_converged;
26 int num_unstable_constraints;
27 int count;
28
29 /*parameters:*/
30 int min_mechanical_constraints;
31 int max_nonlinear_iterations;
[13877]32 int configuration_type;
[7637]33
34 /*Recover parameters: */
[15771]35 femmodel->parameters->FindParam(&min_mechanical_constraints,StressbalanceRiftPenaltyThresholdEnum);
36 femmodel->parameters->FindParam(&max_nonlinear_iterations,StressbalanceMaxiterEnum);
[8815]37 femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
[13693]38 femmodel->UpdateConstraintsx();
[8803]39
[7637]40 /*Were loads requested as output? : */
[13877]41 if(conserve_loads){
42 savedloads = static_cast<Loads*>(femmodel->loads->Copy());
43 }
[7637]44
45 count=1;
[11284]46 converged=false;
[7637]47
48 /*Start non-linear iteration using input velocity: */
[15849]49 GetSolutionFromInputsx(&ug,femmodel);
[8803]50 Reducevectorgtofx(&uf, ug, femmodel->nodes,femmodel->parameters);
[7637]51
52 //Update once again the solution to make sure that vx and vxold are similar (for next step in transient or steadystate)
[15849]53 InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
54 InputUpdateFromSolutionx(femmodel,ug);
[7637]55
56 for(;;){
57
58 //save pointer to old velocity
[14891]59 delete old_uf;old_uf=uf;
[15197]60 delete ug;
[7637]61
[13877]62 femmodel->SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL);
[8815]63 CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
[14891]64 Reduceloadx(pf, Kfs, ys); delete Kfs;
[7637]65 Solverx(&uf, Kff, pf, old_uf, df, femmodel->parameters);
[14891]66 Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete ys;
[11293]67
[14891]68 convergence(&converged,Kff,pf,uf,old_uf,femmodel->parameters); delete Kff; delete pf; delete df;
[15849]69 InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
70 InputUpdateFromSolutionx(femmodel,ug);
[7637]71
[15849]72 ConstraintsStatex(&constraints_converged,&num_unstable_constraints,femmodel);
[15100]73 if(VerboseConvergence()) _printf0_(" number of unstable constraints: " << num_unstable_constraints << "\n");
[7637]74
75 //rift convergence
76 if (!constraints_converged) {
77 if (converged){
[11284]78 if (num_unstable_constraints <= min_mechanical_constraints) converged=true;
79 else converged=false;
[7637]80 }
81 }
82
83 /*Increase count: */
84 count++;
[12271]85 if(converged==true){
86 bool max_iteration_state=false;
87 int tempStep=1;
[12477]88 IssmDouble tempTime=1.0;
[13325]89 femmodel->results->AddObject(new GenericExternalResult<bool>(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, tempStep, tempTime));
[12271]90 break;
91 }
[7637]92 if(count>=max_nonlinear_iterations){
[15104]93 _printf0_(" maximum number of nonlinear iterations (" << max_nonlinear_iterations << ") exceeded\n");
[11347]94 converged=true;
[15849]95 InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
96 InputUpdateFromSolutionx(femmodel,ug);
[12271]97 bool max_iteration_state=true;
98 int tempStep=1;
[12477]99 IssmDouble tempTime=1.0;
[13325]100 femmodel->results->AddObject(new GenericExternalResult<bool>(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, tempStep, tempTime));
[7637]101 break;
102 }
103 }
104
[15100]105 if(VerboseConvergence()) _printf0_("\n total number of iterations: " << count-1 << "\n");
[11322]106
[7637]107 /*clean-up*/
[13877]108 if(conserve_loads){
109 delete femmodel->loads;
110 femmodel->loads=savedloads;
111 }
[14891]112 delete uf;
113 delete ug;
114 delete old_uf;
[7637]115}
Note: See TracBrowser for help on using the repository browser.