source: issm/trunk-jpl/src/c/solvers/solver_newton.cpp@ 14167

Last change on this file since 14167 was 14167, checked in by Mathieu Morlighem, 12 years ago

NEW: fixed newton iteration solver (only one iteration needed)

File size: 4.2 KB
RevLine 
[11322]1/*!\file: solver_nonlinear.cpp
2 * \brief: core of a non-linear solution, using fixed-point method
3 */
4
5#include "../toolkits/toolkits.h"
[12832]6#include "../classes/objects/objects.h"
[11322]7#include "../io/io.h"
8#include "../EnumDefinitions/EnumDefinitions.h"
9#include "../modules/modules.h"
10#include "../solutions/solutions.h"
11#include "./solvers.h"
12
13void solver_newton(FemModel* femmodel){
14
15 /*intermediary: */
[11327]16 bool converged;
17 int count;
[12477]18 IssmDouble kmax;
[13216]19 Matrix<IssmDouble>* Kff = NULL;
20 Matrix<IssmDouble>* Kfs = NULL;
21 Matrix<IssmDouble>* Jff = NULL;
22 Vector<IssmDouble>* ug = NULL;
23 Vector<IssmDouble>* old_ug = NULL;
24 Vector<IssmDouble>* uf = NULL;
25 Vector<IssmDouble>* old_uf = NULL;
26 Vector<IssmDouble>* duf = NULL;
27 Vector<IssmDouble>* pf = NULL;
28 Vector<IssmDouble>* pJf = NULL;
29 Vector<IssmDouble>* df = NULL;
30 Vector<IssmDouble>* ys = NULL;
[11322]31
32 /*parameters:*/
33 int max_nonlinear_iterations;
34 int configuration_type;
35
36 /*Recover parameters: */
37 femmodel->parameters->FindParam(&max_nonlinear_iterations,DiagnosticMaxiterEnum);
38 femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
[13693]39 femmodel->UpdateConstraintsx();
[11322]40
41 count=1;
42 converged=false;
43
44 /*Start non-linear iteration using input velocity: */
45 GetSolutionFromInputsx(&ug,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters);
46 Reducevectorgtofx(&uf,ug,femmodel->nodes,femmodel->parameters);
47
48 //Update once again the solution to make sure that vx and vxold are similar (for next step in transient or steadystate)
49 InputUpdateFromConstantx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,converged,ConvergedEnum);
50 InputUpdateFromSolutionx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,ug);
51
52 for(;;){
53
[11679]54 xdelete(&old_ug);old_ug=ug;
55 xdelete(&old_uf);old_uf=uf;
[11322]56
[11324]57 /*Solver forward model*/
[14167]58 if(count==1){
59 femmodel->SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL);
60 CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
61 Reduceloadx(pf,Kfs,ys);xdelete(&Kfs);
62 Solverx(&uf,Kff,pf,old_uf,df,femmodel->parameters);xdelete(&df);
63 Mergesolutionfromftogx(&ug,uf,ys,femmodel->nodes,femmodel->parameters);xdelete(&ys);
64 InputUpdateFromSolutionx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,ug);xdelete(&ug);
65 xdelete(&old_ug);old_ug=ug;
66 xdelete(&old_uf);old_uf=uf;
67 }
68 uf=old_uf->Duplicate(); old_uf->Copy(uf);
69
70 /*Prepare next iteration using Newton's method*/
71 femmodel->SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL);xdelete(&df);
[11322]72 CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
[14167]73 Reduceloadx(pf,Kfs,ys); xdelete(&Kfs);
74
75 pJf=pf->Duplicate();
76 Kff->MatMult(uf,pJf);// xdelete(&Kff);
77 pJf->Scale(-1.0); pJf->AXPY(pf,+1.0); //xdelete(&pf);
78
79 femmodel->CreateJacobianMatrixx(&Jff,kmax);
80 Solverx(&duf,Jff,pJf,NULL,NULL,femmodel->parameters); xdelete(&Jff); xdelete(&pJf);
81 uf->AXPY(duf, 1.0); xdelete(&duf);
[11679]82 Mergesolutionfromftogx(&ug,uf,ys,femmodel->nodes,femmodel->parameters);xdelete(&ys);
[14167]83 InputUpdateFromSolutionx(femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,ug);
[11322]84
[11324]85 /*Check convergence*/
86 convergence(&converged,Kff,pf,uf,old_uf,femmodel->parameters);
[11679]87 xdelete(&Kff); xdelete(&pf);
[12271]88 if(converged==true){
89 bool max_iteration_state=false;
90 int tempStep=1;
[12477]91 IssmDouble tempTime=1.0;
[13325]92 femmodel->results->AddObject(new GenericExternalResult<bool>(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, tempStep, tempTime));
[12271]93 break;
94 }
[11322]95 if(count>=max_nonlinear_iterations){
[12519]96 _pprintLine_(" maximum number of Newton iterations (" << max_nonlinear_iterations << ") exceeded");
[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));
[11322]101 break;
102 }
[11324]103
[11332]104 count++;
[11322]105 }
106
[12515]107 if(VerboseConvergence()) _pprintLine_("\n total number of iterations: " << count-1);
[11322]108
109 /*clean-up*/
[11679]110 xdelete(&uf);
111 xdelete(&ug);
112 xdelete(&old_ug);
113 xdelete(&old_uf);
[11322]114}
Note: See TracBrowser for help on using the repository browser.