[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 |
|
---|
[18619] | 35 |
|
---|
[7637] | 36 | /*Recover parameters: */
|
---|
[15771] | 37 | femmodel->parameters->FindParam(&min_mechanical_constraints,StressbalanceRiftPenaltyThresholdEnum);
|
---|
| 38 | femmodel->parameters->FindParam(&max_nonlinear_iterations,StressbalanceMaxiterEnum);
|
---|
[18619] | 39 | femmodel->parameters->FindParam(&eps_res,StressbalanceRestolEnum);
|
---|
| 40 | femmodel->parameters->FindParam(&eps_rel,StressbalanceReltolEnum);
|
---|
| 41 | femmodel->parameters->FindParam(&eps_abs,StressbalanceAbstolEnum);
|
---|
[8815] | 42 | femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
|
---|
[13693] | 43 | femmodel->UpdateConstraintsx();
|
---|
[8803] | 44 |
|
---|
[7637] | 45 | /*Were loads requested as output? : */
|
---|
[13877] | 46 | if(conserve_loads){
|
---|
| 47 | savedloads = static_cast<Loads*>(femmodel->loads->Copy());
|
---|
| 48 | }
|
---|
[7637] | 49 |
|
---|
| 50 | count=1;
|
---|
[11284] | 51 | converged=false;
|
---|
[7637] | 52 |
|
---|
| 53 | /*Start non-linear iteration using input velocity: */
|
---|
[15849] | 54 | GetSolutionFromInputsx(&ug,femmodel);
|
---|
[8803] | 55 | Reducevectorgtofx(&uf, ug, femmodel->nodes,femmodel->parameters);
|
---|
[7637] | 56 |
|
---|
| 57 | //Update once again the solution to make sure that vx and vxold are similar (for next step in transient or steadystate)
|
---|
[15849] | 58 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
---|
[19740] | 59 | //InputUpdateFromSolutionx(femmodel,ug);
|
---|
[7637] | 60 |
|
---|
| 61 | for(;;){
|
---|
| 62 |
|
---|
| 63 | //save pointer to old velocity
|
---|
[14891] | 64 | delete old_uf;old_uf=uf;
|
---|
[15197] | 65 | delete ug;
|
---|
[7637] | 66 |
|
---|
[16126] | 67 | SystemMatricesx(&Kff,&Kfs,&pf,&df,NULL,femmodel);
|
---|
[8815] | 68 | CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
|
---|
[14891] | 69 | Reduceloadx(pf, Kfs, ys); delete Kfs;
|
---|
[7637] | 70 | Solverx(&uf, Kff, pf, old_uf, df, femmodel->parameters);
|
---|
[14891] | 71 | Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete ys;
|
---|
[11293] | 72 |
|
---|
[18619] | 73 | convergence(&converged,Kff,pf,uf,old_uf,eps_res,eps_rel,eps_abs); delete Kff; delete pf; delete df;
|
---|
[15849] | 74 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
---|
| 75 | InputUpdateFromSolutionx(femmodel,ug);
|
---|
[7637] | 76 |
|
---|
[15849] | 77 | ConstraintsStatex(&constraints_converged,&num_unstable_constraints,femmodel);
|
---|
[15100] | 78 | if(VerboseConvergence()) _printf0_(" number of unstable constraints: " << num_unstable_constraints << "\n");
|
---|
[7637] | 79 |
|
---|
| 80 | //rift convergence
|
---|
| 81 | if (!constraints_converged) {
|
---|
| 82 | if (converged){
|
---|
[11284] | 83 | if (num_unstable_constraints <= min_mechanical_constraints) converged=true;
|
---|
| 84 | else converged=false;
|
---|
[7637] | 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /*Increase count: */
|
---|
| 89 | count++;
|
---|
[12271] | 90 | if(converged==true){
|
---|
| 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);
|
---|
[7637] | 98 | break;
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[15100] | 102 | if(VerboseConvergence()) _printf0_("\n total number of iterations: " << count-1 << "\n");
|
---|
[11322] | 103 |
|
---|
[7637] | 104 | /*clean-up*/
|
---|
[13877] | 105 | if(conserve_loads){
|
---|
| 106 | delete femmodel->loads;
|
---|
| 107 | femmodel->loads=savedloads;
|
---|
| 108 | }
|
---|
[14891] | 109 | delete uf;
|
---|
| 110 | delete ug;
|
---|
| 111 | delete old_uf;
|
---|
[7637] | 112 | }
|
---|