| 1 | /*!\file: solutionsequence_nonlinear.cpp
|
|---|
| 2 | * \brief: core of a non-linear solution, using fixed-point method
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #include "./solutionsequences.h"
|
|---|
| 6 | #include "../toolkits/toolkits.h"
|
|---|
| 7 | #include "../classes/classes.h"
|
|---|
| 8 | #include "../shared/shared.h"
|
|---|
| 9 | #include "../modules/modules.h"
|
|---|
| 10 |
|
|---|
| 11 | void solutionsequence_nonlinear(FemModel* femmodel,bool conserve_loads){
|
|---|
| 12 |
|
|---|
| 13 | /*intermediary: */
|
|---|
| 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;
|
|---|
| 22 |
|
|---|
| 23 | Loads* savedloads=NULL;
|
|---|
| 24 | bool converged;
|
|---|
| 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;
|
|---|
| 32 | int configuration_type;
|
|---|
| 33 |
|
|---|
| 34 | /*Recover parameters: */
|
|---|
| 35 | femmodel->parameters->FindParam(&min_mechanical_constraints,StressbalanceRiftPenaltyThresholdEnum);
|
|---|
| 36 | femmodel->parameters->FindParam(&max_nonlinear_iterations,StressbalanceMaxiterEnum);
|
|---|
| 37 | femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
|
|---|
| 38 | femmodel->UpdateConstraintsx();
|
|---|
| 39 |
|
|---|
| 40 | /*Were loads requested as output? : */
|
|---|
| 41 | if(conserve_loads){
|
|---|
| 42 | savedloads = static_cast<Loads*>(femmodel->loads->Copy());
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | count=1;
|
|---|
| 46 | converged=false;
|
|---|
| 47 |
|
|---|
| 48 | /*Start non-linear iteration using input velocity: */
|
|---|
| 49 | GetSolutionFromInputsx(&ug,femmodel);
|
|---|
| 50 | Reducevectorgtofx(&uf, ug, femmodel->nodes,femmodel->parameters);
|
|---|
| 51 |
|
|---|
| 52 | //Update once again the solution to make sure that vx and vxold are similar (for next step in transient or steadystate)
|
|---|
| 53 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
|---|
| 54 | InputUpdateFromSolutionx(femmodel,ug);
|
|---|
| 55 |
|
|---|
| 56 | for(;;){
|
|---|
| 57 |
|
|---|
| 58 | //save pointer to old velocity
|
|---|
| 59 | delete old_uf;old_uf=uf;
|
|---|
| 60 | delete ug;
|
|---|
| 61 |
|
|---|
| 62 | femmodel->SystemMatricesx(&Kff, &Kfs, &pf, &df, NULL);
|
|---|
| 63 | CreateNodalConstraintsx(&ys,femmodel->nodes,configuration_type);
|
|---|
| 64 | Reduceloadx(pf, Kfs, ys); delete Kfs;
|
|---|
| 65 | Solverx(&uf, Kff, pf, old_uf, df, femmodel->parameters);
|
|---|
| 66 | Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete ys;
|
|---|
| 67 |
|
|---|
| 68 | convergence(&converged,Kff,pf,uf,old_uf,femmodel->parameters); delete Kff; delete pf; delete df;
|
|---|
| 69 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
|---|
| 70 | InputUpdateFromSolutionx(femmodel,ug);
|
|---|
| 71 |
|
|---|
| 72 | ConstraintsStatex(&constraints_converged,&num_unstable_constraints,femmodel);
|
|---|
| 73 | if(VerboseConvergence()) _printf0_(" number of unstable constraints: " << num_unstable_constraints << "\n");
|
|---|
| 74 |
|
|---|
| 75 | //rift convergence
|
|---|
| 76 | if (!constraints_converged) {
|
|---|
| 77 | if (converged){
|
|---|
| 78 | if (num_unstable_constraints <= min_mechanical_constraints) converged=true;
|
|---|
| 79 | else converged=false;
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | /*Increase count: */
|
|---|
| 84 | count++;
|
|---|
| 85 | if(converged==true){
|
|---|
| 86 | bool max_iteration_state=false;
|
|---|
| 87 | int tempStep=1;
|
|---|
| 88 | IssmDouble tempTime=1.0;
|
|---|
| 89 | femmodel->results->AddObject(new GenericExternalResult<bool>(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, tempStep, tempTime));
|
|---|
| 90 | break;
|
|---|
| 91 | }
|
|---|
| 92 | if(count>=max_nonlinear_iterations){
|
|---|
| 93 | _printf0_(" maximum number of nonlinear iterations (" << max_nonlinear_iterations << ") exceeded\n");
|
|---|
| 94 | converged=true;
|
|---|
| 95 | InputUpdateFromConstantx(femmodel,converged,ConvergedEnum);
|
|---|
| 96 | InputUpdateFromSolutionx(femmodel,ug);
|
|---|
| 97 | bool max_iteration_state=true;
|
|---|
| 98 | int tempStep=1;
|
|---|
| 99 | IssmDouble tempTime=1.0;
|
|---|
| 100 | femmodel->results->AddObject(new GenericExternalResult<bool>(femmodel->results->Size()+1, MaxIterationConvergenceFlagEnum, max_iteration_state, tempStep, tempTime));
|
|---|
| 101 | break;
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | if(VerboseConvergence()) _printf0_("\n total number of iterations: " << count-1 << "\n");
|
|---|
| 106 |
|
|---|
| 107 | /*clean-up*/
|
|---|
| 108 | if(conserve_loads){
|
|---|
| 109 | delete femmodel->loads;
|
|---|
| 110 | femmodel->loads=savedloads;
|
|---|
| 111 | }
|
|---|
| 112 | delete uf;
|
|---|
| 113 | delete ug;
|
|---|
| 114 | delete old_uf;
|
|---|
| 115 | }
|
|---|