[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] | 11 | void 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;
|
---|
[18619] | 33 | IssmDouble eps_res,eps_rel,eps_abs;
|
---|
[7637] | 34 |
|
---|
| 35 | /*Recover parameters: */
|
---|
[15771] | 36 | femmodel->parameters->FindParam(&min_mechanical_constraints,StressbalanceRiftPenaltyThresholdEnum);
|
---|
| 37 | femmodel->parameters->FindParam(&max_nonlinear_iterations,StressbalanceMaxiterEnum);
|
---|
[18619] | 38 | femmodel->parameters->FindParam(&eps_res,StressbalanceRestolEnum);
|
---|
| 39 | femmodel->parameters->FindParam(&eps_rel,StressbalanceReltolEnum);
|
---|
| 40 | femmodel->parameters->FindParam(&eps_abs,StressbalanceAbstolEnum);
|
---|
[8815] | 41 | femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
|
---|
[13693] | 42 | femmodel->UpdateConstraintsx();
|
---|
[8803] | 43 |
|
---|
[7637] | 44 | /*Were loads requested as output? : */
|
---|
[13877] | 45 | if(conserve_loads){
|
---|
| 46 | savedloads = static_cast<Loads*>(femmodel->loads->Copy());
|
---|
| 47 | }
|
---|
[7637] | 48 |
|
---|
[20962] | 49 | count=0;
|
---|
[11284] | 50 | converged=false;
|
---|
[7637] | 51 |
|
---|
| 52 | /*Start non-linear iteration using input velocity: */
|
---|
[15849] | 53 | GetSolutionFromInputsx(&ug,femmodel);
|
---|
[8803] | 54 | Reducevectorgtofx(&uf, ug, femmodel->nodes,femmodel->parameters);
|
---|
[7637] | 55 |
|
---|
| 56 | //Update once again the solution to make sure that vx and vxold are similar (for next step in transient or steadystate)
|
---|
[15849] | 57 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
---|
[19746] | 58 | InputUpdateFromSolutionx(femmodel,ug);
|
---|
[7637] | 59 |
|
---|
[24679] | 60 | // allocate the matrices once and reuce them per iteration
|
---|
| 61 | AllocateSystemMatricesx(&Kff,&Kfs,&df,&pf,femmodel);
|
---|
| 62 |
|
---|
[7637] | 63 | for(;;){
|
---|
| 64 |
|
---|
| 65 | //save pointer to old velocity
|
---|
[14891] | 66 | delete old_uf;old_uf=uf;
|
---|
[15197] | 67 | delete ug;
|
---|
[7637] | 68 |
|
---|
[24679] | 69 | SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel, true);
|
---|
[23587] | 70 | CreateNodalConstraintsx(&ys,femmodel->nodes);
|
---|
[24679] | 71 | Reduceloadx(pf, Kfs, ys);
|
---|
[22551] | 72 | femmodel->profiler->Start(SOLVER);
|
---|
[7637] | 73 | Solverx(&uf, Kff, pf, old_uf, df, femmodel->parameters);
|
---|
[22551] | 74 | femmodel->profiler->Stop(SOLVER);
|
---|
[23197] | 75 |
|
---|
[14891] | 76 | Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete ys;
|
---|
[11293] | 77 |
|
---|
[24679] | 78 | convergence(&converged,Kff,pf,uf,old_uf,eps_res,eps_rel,eps_abs);
|
---|
[15849] | 79 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
---|
| 80 | InputUpdateFromSolutionx(femmodel,ug);
|
---|
[7637] | 81 |
|
---|
[15849] | 82 | ConstraintsStatex(&constraints_converged,&num_unstable_constraints,femmodel);
|
---|
[15100] | 83 | if(VerboseConvergence()) _printf0_(" number of unstable constraints: " << num_unstable_constraints << "\n");
|
---|
[7637] | 84 |
|
---|
| 85 | //rift convergence
|
---|
| 86 | if (!constraints_converged) {
|
---|
| 87 | if (converged){
|
---|
[11284] | 88 | if (num_unstable_constraints <= min_mechanical_constraints) converged=true;
|
---|
| 89 | else converged=false;
|
---|
[7637] | 90 | }
|
---|
| 91 | }
|
---|
[23197] | 92 |
|
---|
[7637] | 93 | /*Increase count: */
|
---|
| 94 | count++;
|
---|
[12271] | 95 | if(converged==true){
|
---|
[20576] | 96 | femmodel->results->AddResult(new GenericExternalResult<IssmDouble>(femmodel->results->Size()+1,StressbalanceConvergenceNumStepsEnum,count));
|
---|
[12271] | 97 | break;
|
---|
| 98 | }
|
---|
[7637] | 99 | if(count>=max_nonlinear_iterations){
|
---|
[15104] | 100 | _printf0_(" maximum number of nonlinear iterations (" << max_nonlinear_iterations << ") exceeded\n");
|
---|
[11347] | 101 | converged=true;
|
---|
[20576] | 102 | femmodel->results->AddResult(new GenericExternalResult<IssmDouble>(femmodel->results->Size()+1,StressbalanceConvergenceNumStepsEnum,max_nonlinear_iterations));
|
---|
[15849] | 103 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
---|
| 104 | InputUpdateFromSolutionx(femmodel,ug);
|
---|
[7637] | 105 | break;
|
---|
| 106 | }
|
---|
[24679] | 107 |
|
---|
| 108 | // Set the matrix entries to zero if we do an other iteration
|
---|
| 109 | Kff->SetZero();
|
---|
| 110 | Kfs->SetZero();
|
---|
| 111 | df->Set(0);
|
---|
| 112 | pf->Set(0);
|
---|
[7637] | 113 | }
|
---|
| 114 |
|
---|
[24679] | 115 | // delete matrices after the iteration loop
|
---|
| 116 | delete Kff; delete pf; delete df;
|
---|
| 117 | delete Kfs;
|
---|
| 118 |
|
---|
[21451] | 119 | if(VerboseConvergence()) _printf0_("\n total number of iterations: " << count << "\n");
|
---|
[11322] | 120 |
|
---|
[7637] | 121 | /*clean-up*/
|
---|
[13877] | 122 | if(conserve_loads){
|
---|
| 123 | delete femmodel->loads;
|
---|
[23488] | 124 | int index=femmodel->AnalysisIndex(configuration_type);
|
---|
| 125 | femmodel->loads_list[index]=savedloads;
|
---|
[13877] | 126 | femmodel->loads=savedloads;
|
---|
| 127 | }
|
---|
[14891] | 128 | delete uf;
|
---|
| 129 | delete ug;
|
---|
| 130 | delete old_uf;
|
---|
[7637] | 131 | }
|
---|