Ice Sheet System Model  4.18
Code documentation
Functions
solutionsequence_la.cpp File Reference

: numerical core of la solutions More...

#include "../toolkits/toolkits.h"
#include "../classes/classes.h"
#include "../shared/shared.h"
#include "../modules/modules.h"

Go to the source code of this file.

Functions

void solutionsequence_la (FemModel *femmodel)
 

Detailed Description

: numerical core of la solutions

Definition in file solutionsequence_la.cpp.

Function Documentation

◆ solutionsequence_la()

void solutionsequence_la ( FemModel femmodel)

Definition at line 10 of file solutionsequence_la.cpp.

10  {
11 
12  /*intermediary: */
13  Matrix<IssmDouble>* Kff = NULL;
14  Matrix<IssmDouble>* Kfs = NULL;
15  Vector<IssmDouble>* ug = NULL;
16  Vector<IssmDouble>* uf = NULL;
17  Vector<IssmDouble>* pf = NULL;
18  Vector<IssmDouble>* df = NULL;
19  Vector<IssmDouble>* ys = NULL;
20  Vector<IssmDouble>* pug = NULL;
21  Vector<IssmDouble>* pug_old = NULL;
22  IssmDouble eps_rel,r,theta; // 0<theta<.5 -> .15<theta<.45
23  int max_nonlinear_iterations;
24  bool vel_converged = false;
25  bool pressure_converged = false;
26 
27  /*Create analysis*/
28  StressbalanceAnalysis* stressanalysis = new StressbalanceAnalysis();
29  UzawaPressureAnalysis* pressureanalysis = new UzawaPressureAnalysis();
31 
32  /*Recover parameters: */
34  femmodel->parameters->FindParam(&max_nonlinear_iterations,StressbalanceMaxiterEnum);
35 
36  /*Update constraints*/
38 
39  /*Convergence criterion*/
40  int count = 0;
41  int count_local = 0;
42  Vector<IssmDouble>* vel = NULL;
43  Vector<IssmDouble>* vel_old = NULL;
44  Vector<IssmDouble>* vel_old_local = NULL;
47 
48  while(true){
49  count++;
50 
51  /*save pointer to old velocity*/
52  delete vel_old;vel_old=vel->Duplicate(); vel->Copy(vel_old);
53  delete pug_old;pug_old=pug;
54  pressure_converged=false; vel_converged=false;
55 
56  while(true){
57  count_local++;
58  delete vel_old_local;vel_old_local=vel;
59  /*Solve KU=F*/
61  SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel);
63  Reduceloadx(pf, Kfs, ys); delete Kfs;
64 
66  Solverx(&uf, Kff, pf, NULL, df, femmodel->parameters);
68 
69  delete Kff; delete pf; delete df;
70  Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete uf; delete ys;
71 
72  /*Update solution*/
73  InputUpdateFromSolutionx(femmodel,ug); delete ug;
75  /*Check for convergence*/
76  Vector<IssmDouble>* dvel_local=vel_old_local->Duplicate(); vel_old_local->Copy(dvel_local); dvel_local->AYPX(vel,-1.0);
77  IssmDouble ndu=dvel_local->Norm(NORM_TWO); delete dvel_local;
78  IssmDouble nu =vel_old_local->Norm(NORM_TWO);
79  if (xIsNan<IssmDouble>(ndu) || xIsNan<IssmDouble>(nu)) _error_("convergence criterion is NaN!");
80  if((ndu/nu)<eps_rel){
81  if(VerboseConvergence()) _printf0_(setw(50) << left << " Convergence criterion: norm(du)/norm(u)" << ndu/nu*100 << " < " << eps_rel*100 << " %\n");
82  break;
83  }
84  else{
85  if(VerboseConvergence()) _printf0_(setw(50) << left << " Convergence criterion: norm(du)/norm(u)" << ndu/nu*100 << " > " << eps_rel*100 << " %\n");
86  }
87  if(count_local>=max_nonlinear_iterations){
88  _printf0_(" maximum number of nonlinear iterations (" << max_nonlinear_iterations << ") exceeded\n");
89  break;
90  }
91  }
92  count_local=0;
93 
95  SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel);
97  Reduceloadx(pf, Kfs, ys); delete Kfs;
98 
100  Solverx(&uf, Kff, pf, NULL, df, femmodel->parameters);
102 
103  delete Kff; delete pf; delete df;
104  Mergesolutionfromftogx(&pug, uf,ys,femmodel->nodes,femmodel->parameters); delete uf; delete ys;
105 
106  /*Update solution*/
107  InputUpdateFromSolutionx(femmodel,pug); delete pug;
109 
110  /*Check for convergence*/
111  Vector<IssmDouble>* dvel=vel_old_local->Duplicate(); vel_old_local->Copy(dvel); dvel->AYPX(vel,-1.0);
112  IssmDouble ndu=dvel->Norm(NORM_TWO); delete dvel;
113  IssmDouble nu =vel_old_local->Norm(NORM_TWO);
114  if (xIsNan<IssmDouble>(ndu) || xIsNan<IssmDouble>(nu)) _error_("convergence criterion is NaN!");
115  if((ndu/nu)<eps_rel){
116  if(VerboseConvergence()) _printf0_(setw(50) << left << " Convergence criterion: norm(du)/norm(u)" << ndu/nu*100 << " < " << eps_rel*100 << " %\n");
117  vel_converged=true;
118  }
119  else{
120  if(VerboseConvergence()) _printf0_(setw(50) << left << " Convergence criterion: norm(du)/norm(u)" << ndu/nu*100 << " > " << eps_rel*100 << " %\n");
121  vel_converged=false;
122  }
123  Vector<IssmDouble>* dup=pug_old->Duplicate(); pug_old->Copy(dup); dup->AYPX(pug,-1.0);
124  IssmDouble ndp=dup->Norm(NORM_TWO); delete dup;
125  IssmDouble np =pug_old->Norm(NORM_TWO);
126  if (xIsNan<IssmDouble>(ndp) || xIsNan<IssmDouble>(np)) _error_("convergence criterion is NaN!");
127  if((ndp/np)<eps_rel){
128  if(VerboseConvergence()) _printf0_(setw(50) << left << " Convergence criterion: norm(dp)/norm(p)" << ndp/np*100 << " < " << eps_rel*100 << " %\n");
129  pressure_converged=true;
130  }
131  else{
132  if(VerboseConvergence()) _printf0_(setw(50) << left << " Convergence criterion: norm(dp/)/norm(p)" << ndp/np*100 << " > " << eps_rel*100 << " %\n");
133  pressure_converged=false;
134  }
135 
136  if(pressure_converged && vel_converged) break;
137  if(count>=max_nonlinear_iterations){
138  _printf0_(" maximum number of nonlinear iterations (" << max_nonlinear_iterations << ") exceeded\n");
139  break;
140  }
141  }
142 
143  if(VerboseConvergence()) _printf0_("\n total number of iterations: " << count-1 << "\n");
144 
145  delete pug;
146  delete pug_old;
147  delete vel;
148  delete vel_old;
149  delete vel_old_local;
150  delete stressanalysis;
151  delete pressureanalysis;
152 }
Matrix< IssmDouble >
SOLVER
#define SOLVER
Definition: Profiler.h:16
StressbalanceAnalysis
Definition: StressbalanceAnalysis.h:11
Mergesolutionfromftogx
void Mergesolutionfromftogx(Vector< IssmDouble > **pug, Vector< IssmDouble > *uf, Vector< IssmDouble > *ys, Nodes *nodes, Parameters *parameters, bool flag_ys0)
Definition: Mergesolutionfromftogx.cpp:8
IssmDouble
double IssmDouble
Definition: types.h:37
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
StressbalanceAnalysisEnum
@ StressbalanceAnalysisEnum
Definition: EnumDefinitions.h:1285
VerboseConvergence
bool VerboseConvergence(void)
Definition: Verbosity.cpp:26
FemModel::parameters
Parameters * parameters
Definition: FemModel.h:46
GetVectorFromInputsx
void GetVectorFromInputsx(IssmDouble **pvector, int *pvector_size, FemModel *femmodel, int name)
Definition: GetVectorFromInputsx.cpp:81
PressureEnum
@ PressureEnum
Definition: EnumDefinitions.h:664
Solverx
void Solverx(Vector< IssmDouble > **puf, Matrix< IssmDouble > *Kff, Vector< IssmDouble > *pf, Vector< IssmDouble > *uf0, Vector< IssmDouble > *df, Parameters *parameters)
Definition: Solverx.cpp:15
Vector::Duplicate
Vector< doubletype > * Duplicate(void)
Definition: Vector.h:230
NORM_TWO
@ NORM_TWO
Definition: toolkitsenums.h:15
StressbalanceMaxiterEnum
@ StressbalanceMaxiterEnum
Definition: EnumDefinitions.h:407
Vector::Norm
doubletype Norm(NormMode norm_type)
Definition: Vector.h:342
UzawaPressureAnalysisEnum
@ UzawaPressureAnalysisEnum
Definition: EnumDefinitions.h:1320
FemModel::UpdateConstraintsx
void UpdateConstraintsx(void)
Definition: FemModel.cpp:3027
FemModel::nodes
Nodes * nodes
Definition: FemModel.h:56
StressbalanceReltolEnum
@ StressbalanceReltolEnum
Definition: EnumDefinitions.h:410
Profiler::Stop
void Stop(int tagenum, bool dontmpisync=true)
Definition: Profiler.cpp:179
VertexPIdEnum
@ VertexPIdEnum
Definition: EnumDefinitions.h:1324
Reduceloadx
void Reduceloadx(Vector< IssmDouble > *pf, Matrix< IssmDouble > *Kfs, Vector< IssmDouble > *y_s, bool flag_ys0)
Definition: Reduceloadx.cpp:14
UzawaPressureAnalysis
Definition: UzawaPressureAnalysis.h:11
Vector::AYPX
void AYPX(Vector *X, doubletype a)
Definition: Vector.h:267
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
Profiler::Start
void Start(int tagenum, bool dontmpisync=true)
Definition: Profiler.cpp:139
InputUpdateFromSolutionx
void InputUpdateFromSolutionx(FemModel *femmodel, Vector< IssmDouble > *solution)
Definition: InputUpdateFromSolutionx.cpp:9
VxEnum
@ VxEnum
Definition: EnumDefinitions.h:846
FemModel::SetCurrentConfiguration
void SetCurrentConfiguration(int configuration_type)
Definition: FemModel.cpp:634
Parameters::FindParam
void FindParam(bool *pinteger, int enum_type)
Definition: Parameters.cpp:262
Vector::Copy
void Copy(Vector *to)
Definition: Vector.h:319
CreateNodalConstraintsx
void CreateNodalConstraintsx(Vector< IssmDouble > **pys, Nodes *nodes)
Definition: CreateNodalConstraintsx.cpp:10
SystemMatricesx
void SystemMatricesx(Matrix< IssmDouble > **pKff, Matrix< IssmDouble > **pKfs, Vector< IssmDouble > **ppf, Vector< IssmDouble > **pdf, IssmDouble *pkmax, FemModel *femmodel, bool isAllocated)
Definition: SystemMatricesx.cpp:10
FemModel::profiler
Profiler * profiler
Definition: FemModel.h:42
Vector< IssmDouble >
femmodel
FemModel * femmodel
Definition: esmfbinders.cpp:16