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

Last change on this file since 17055 was 17055, checked in by Eric.Larour, 11 years ago

CHG: make sure that start time is the one set in timestepping, not 0.

File size: 3.9 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
[16126]62 SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel);
[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;
[17055]87 int step; IssmDouble time;
88 femmodel->parameters->FindParam(&time,TimeEnum);
89 femmodel->parameters->FindParam(&step,StepEnum);
90 femmodel->results->AddObject(new GenericExternalResult<bool>(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, step, time));
[12271]91 break;
92 }
[7637]93 if(count>=max_nonlinear_iterations){
[15104]94 _printf0_(" maximum number of nonlinear iterations (" << max_nonlinear_iterations << ") exceeded\n");
[11347]95 converged=true;
[15849]96 InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
97 InputUpdateFromSolutionx(femmodel,ug);
[12271]98 bool max_iteration_state=true;
[17055]99 int step; IssmDouble time;
100 femmodel->parameters->FindParam(&time,TimeEnum);
101 femmodel->parameters->FindParam(&step,StepEnum);
102 femmodel->results->AddObject(new GenericExternalResult<bool>(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, step, time));
[7637]103 break;
104 }
105 }
106
[15100]107 if(VerboseConvergence()) _printf0_("\n total number of iterations: " << count-1 << "\n");
[11322]108
[7637]109 /*clean-up*/
[13877]110 if(conserve_loads){
111 delete femmodel->loads;
112 femmodel->loads=savedloads;
113 }
[14891]114 delete uf;
115 delete ug;
116 delete old_uf;
[7637]117}
Note: See TracBrowser for help on using the repository browser.