source: issm/trunk-jpl/src/c/solvers/solver_thermal_nonlinear.cpp@ 13216

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

NEW: large change to the code, to adapt to ADOLC requirements.

This change relates to the introduction of template classes and functions for the
Option.h abstract class. This is needed, because we want to make the Matlab
API independent from the libCore objects, which are dependent on the IssmDouble*
ADOLC type (adouble), when the Matlab API is dependent on the IssmPDouble* type (double).

To make them independent, we need to be able to specify at run time Options, Matrix and
Vector objects that hold either IssmDouble or IssmPDouble objects. The only way to do
that is through the use of templated classes for Option.h, Matrix and Vector.

The change gets rid of a lot of useless code (especially in the classes/objects/Options
directory), by introducing template versions of the same code.

The bulk of the changes to src/modules and src/mex modules is to adapt to this
new runtime declaration of templated Matrix, Vector and Option objects.

File size: 3.5 KB
Line 
1/*!\file: solver_thermal_nonlinear.cpp
2 * \brief: core of the thermal solution
3 */
4
5#include "../toolkits/toolkits.h"
6#include "../classes/objects/objects.h"
7#include "../io/io.h"
8#include "../EnumDefinitions/EnumDefinitions.h"
9#include "../modules/modules.h"
10
11void solver_thermal_nonlinear(FemModel* femmodel){
12
13 /*solution : */
14 Vector<IssmDouble>* tg=NULL;
15 Vector<IssmDouble>* tf=NULL;
16 Vector<IssmDouble>* tf_old=NULL;
17 Vector<IssmDouble>* ys=NULL;
18 IssmDouble melting_offset;
19
20 /*intermediary: */
21 Matrix<IssmDouble>* Kff=NULL;
22 Matrix<IssmDouble>* Kfs=NULL;
23 Vector<IssmDouble>* pf=NULL;
24 Vector<IssmDouble>* df=NULL;
25
26 bool converged;
27 int constraints_converged;
28 int num_unstable_constraints;
29 int count;
30 int thermal_penalty_threshold;
31 int thermal_maxiter;
32
33 /*parameters:*/
34 int kflag,pflag;
35 bool lowmem=0;
36 int configuration_type;
37
38
39 /*Recover parameters: */
40 kflag=1; pflag=1;
41 femmodel->parameters->FindParam(&lowmem,SettingsLowmemEnum);
42 femmodel->parameters->FindParam(&thermal_penalty_threshold,ThermalPenaltyThresholdEnum);
43 femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
44 femmodel->parameters->FindParam(&thermal_maxiter,ThermalMaxiterEnum);
45
46 count=1;
47 converged=false;
48
49 if(VerboseSolution()) _pprintLine_("starting direct shooting method");
50 InputUpdateFromConstantx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,true,ResetPenaltiesEnum);
51 InputUpdateFromConstantx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,false,ConvergedEnum);
52 UpdateConstraintsx(femmodel->nodes,femmodel->constraints,femmodel->parameters);
53
54 for(;;){
55
56 SystemMatricesx(&Kff, &Kfs, &pf,&df, &melting_offset,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
57 CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
58 Reduceloadx(pf, Kfs, ys); xdelete(&Kfs); xdelete(&tf);
59 Solverx(&tf, Kff, pf,tf_old, df, femmodel->parameters);
60 xdelete(&tf_old); tf_old=tf->Duplicate();
61 xdelete(&Kff);xdelete(&pf);xdelete(&tg); xdelete(&df);
62 Mergesolutionfromftogx(&tg, tf,ys,femmodel->nodes,femmodel->parameters); xdelete(&ys);
63 InputUpdateFromSolutionx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,tg);
64
65 ConstraintsStatex(&constraints_converged, &num_unstable_constraints, femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
66
67 if (!converged){
68 if(VerboseConvergence()) _pprintLine_(" #unstable constraints = " << num_unstable_constraints);
69 if (num_unstable_constraints <= thermal_penalty_threshold)converged=true;
70 if (count>=thermal_maxiter){
71 converged=true;
72 _pprintLine_(" maximum number of iterations (" << thermal_maxiter << ") exceeded");
73 }
74 }
75 count++;
76
77 InputUpdateFromConstantx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,converged,ConvergedEnum);
78
79 if(converged)break;
80 }
81
82 InputUpdateFromSolutionx(femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,tg);
83 InputUpdateFromConstantx( femmodel->elements,femmodel->nodes, femmodel->vertices, femmodel->loads, femmodel->materials, femmodel->parameters,melting_offset,MeltingOffsetEnum);
84
85 /*Free ressources: */
86 xdelete(&tg);
87 xdelete(&tf);
88 xdelete(&tf_old);
89 xdelete(&ys);
90}
Note: See TracBrowser for help on using the repository browser.