[19102] | 1 | Index: ../trunk-jpl/src/c/solutionsequences/solutionsequence_fct.cpp
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- ../trunk-jpl/src/c/solutionsequences/solutionsequence_fct.cpp (revision 18349)
|
---|
| 4 | +++ ../trunk-jpl/src/c/solutionsequences/solutionsequence_fct.cpp (revision 18350)
|
---|
| 5 | @@ -111,6 +111,53 @@
|
---|
| 6 | *pdmax = dmax;
|
---|
| 7 | *pLHS = LHS;
|
---|
| 8 | }/*}}}*/
|
---|
| 9 | +void CreateRHS(Vec* pRHS,Mat K,Mat D,Vec Ml,Vec u,IssmDouble theta,IssmDouble deltat,IssmDouble dmax,FemModel* femmodel,int configuration_type){/*{{{*/
|
---|
| 10 | + /*Create Left Hand side of Lower order solution
|
---|
| 11 | + *
|
---|
| 12 | + * RHS = [ML + (1 − theta) deltaT L^n] u^n
|
---|
| 13 | + *
|
---|
| 14 | + * where L = K + D
|
---|
| 15 | + *
|
---|
| 16 | + */
|
---|
| 17 | +
|
---|
| 18 | + /*Intermediaries*/
|
---|
| 19 | + Vec Ku = NULL;
|
---|
| 20 | + Vec Du = NULL;
|
---|
| 21 | + Vec RHS = NULL;
|
---|
| 22 | + int dof;
|
---|
| 23 | + IssmDouble d;
|
---|
| 24 | +
|
---|
| 25 | + /*Initialize vectors*/
|
---|
| 26 | + VecDuplicate(u,&Ku);
|
---|
| 27 | + VecDuplicate(u,&Du);
|
---|
| 28 | + VecDuplicate(u,&RHS);
|
---|
| 29 | +
|
---|
| 30 | + /*Create RHS = M*u + (1-theta)*deltat*K*u + (1-theta)*deltat*D*u*/
|
---|
| 31 | + MatMult(K,u,Ku);
|
---|
| 32 | + MatMult(D,u,Du);
|
---|
| 33 | + VecPointwiseMult(RHS,Ml,u);
|
---|
| 34 | + VecAXPBYPCZ(RHS,(1-theta)*deltat,(1-theta)*deltat,1,Ku,Du);
|
---|
| 35 | + VecFree(&Ku);
|
---|
| 36 | + VecFree(&Du);
|
---|
| 37 | +
|
---|
| 38 | + /*Penalize Dirichlet boundary*/
|
---|
| 39 | + for(int i=0;i<femmodel->constraints->Size();i++){
|
---|
| 40 | + Constraint* constraint=(Constraint*)femmodel->constraints->GetObjectByOffset(i);
|
---|
| 41 | + if(constraint->InAnalysis(configuration_type)){
|
---|
| 42 | + constraint->PenaltyDofAndValue(&dof,&d,femmodel->nodes,femmodel->parameters);
|
---|
| 43 | + d = d*dmax;
|
---|
| 44 | + if(dof!=-1){
|
---|
| 45 | + VecSetValues(RHS,1,&dof,(const double*)&d,INSERT_VALUES);
|
---|
| 46 | + }
|
---|
| 47 | + }
|
---|
| 48 | + }
|
---|
| 49 | + VecAssemblyBegin(RHS);
|
---|
| 50 | + VecAssemblyEnd( RHS);
|
---|
| 51 | +
|
---|
| 52 | + /*Assign output pointer*/
|
---|
| 53 | + *pRHS = RHS;
|
---|
| 54 | +
|
---|
| 55 | +}/*}}}*/
|
---|
| 56 | #endif
|
---|
| 57 | void solutionsequence_fct(FemModel* femmodel){
|
---|
| 58 |
|
---|
| 59 | @@ -120,18 +167,15 @@
|
---|
| 60 | Matrix<IssmDouble>* Mc = NULL;
|
---|
| 61 | Vector<IssmDouble>* ug = NULL;
|
---|
| 62 | Vector<IssmDouble>* uf = NULL;
|
---|
| 63 | - Vector<IssmDouble>* ys = NULL;
|
---|
| 64 |
|
---|
| 65 | - IssmDouble theta,deltat,dmax=0.;
|
---|
| 66 | - int dof,ncols,ncols2,ncols3,rstart,rend;
|
---|
| 67 | - int configuration_type,analysis_type;
|
---|
| 68 | - double d,mi;
|
---|
| 69 | + IssmDouble theta,deltat,dmax;
|
---|
| 70 | + int dof,ncols,ncols2,rstart,rend;
|
---|
| 71 | + int configuration_type;
|
---|
| 72 | + double d;
|
---|
| 73 | int* cols = NULL;
|
---|
| 74 | int* cols2 = NULL;
|
---|
| 75 | - int* cols3 = NULL;
|
---|
| 76 | double* vals = NULL;
|
---|
| 77 | double* vals2 = NULL;
|
---|
| 78 | - double* vals3 = NULL;
|
---|
| 79 |
|
---|
| 80 | /*Create analysis*/
|
---|
| 81 | MasstransportAnalysis* analysis = new MasstransportAnalysis();
|
---|
| 82 | @@ -139,7 +183,6 @@
|
---|
| 83 | /*Recover parameters: */
|
---|
| 84 | femmodel->parameters->FindParam(&deltat,TimesteppingTimeStepEnum);
|
---|
| 85 | femmodel->parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
|
---|
| 86 | - femmodel->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
|
---|
| 87 | femmodel->UpdateConstraintsx();
|
---|
| 88 | theta = 0.5;
|
---|
| 89 |
|
---|
| 90 | @@ -151,6 +194,8 @@
|
---|
| 91 | /*Convert matrices to PETSc matrices*/
|
---|
| 92 | Mat D_petsc = NULL;
|
---|
| 93 | Mat LHS = NULL;
|
---|
| 94 | + Vec RHS = NULL;
|
---|
| 95 | + Vec u = NULL;
|
---|
| 96 | Mat K_petsc = K->pmatrix->matrix;
|
---|
| 97 | Vec Ml_petsc = Ml->pvector->vector;
|
---|
| 98 | Mat Mc_petsc = Mc->pmatrix->matrix;
|
---|
| 99 | @@ -166,35 +211,9 @@
|
---|
| 100 | GetSolutionFromInputsx(&ug,femmodel);
|
---|
| 101 | Reducevectorgtofx(&uf, ug, femmodel->nodes,femmodel->parameters);
|
---|
| 102 | delete ug;
|
---|
| 103 | - Vec u = uf->pvector->vector;
|
---|
| 104 | - Vec Ku = NULL;
|
---|
| 105 | - Vec Du = NULL;
|
---|
| 106 | - Vec RHS = NULL;
|
---|
| 107 | - VecDuplicate(u,&Ku);
|
---|
| 108 | - VecDuplicate(u,&Du);
|
---|
| 109 | - VecDuplicate(u,&RHS);
|
---|
| 110 | - MatMult(K_petsc,u,Ku);
|
---|
| 111 | - MatMult(D_petsc,u,Du);
|
---|
| 112 | - VecPointwiseMult(RHS,Ml_petsc,u);
|
---|
| 113 | - VecAXPBYPCZ(RHS,(1-theta)*deltat,(1-theta)*deltat,1,Ku,Du);// RHS = M*u + (1-theta)*deltat*K*u + (1-theta)*deltat*D*u
|
---|
| 114 | - VecFree(&Ku);
|
---|
| 115 | - VecFree(&Du);
|
---|
| 116 | + CreateRHS(&RHS,K_petsc,D_petsc,Ml_petsc,uf->pvector->vector,theta,deltat,dmax,femmodel,configuration_type);
|
---|
| 117 | delete uf;
|
---|
| 118 |
|
---|
| 119 | - /*Penalize Dirichlet boundary*/
|
---|
| 120 | - for(int i=0;i<femmodel->constraints->Size();i++){
|
---|
| 121 | - Constraint* constraint=(Constraint*)femmodel->constraints->GetObjectByOffset(i);
|
---|
| 122 | - if(constraint->InAnalysis(analysis_type)){
|
---|
| 123 | - constraint->PenaltyDofAndValue(&dof,&d,femmodel->nodes,femmodel->parameters);
|
---|
| 124 | - d = d*dmax;
|
---|
| 125 | - if(dof!=-1){
|
---|
| 126 | - VecSetValues(RHS,1,&dof,(const double*)&d,INSERT_VALUES);
|
---|
| 127 | - }
|
---|
| 128 | - }
|
---|
| 129 | - }
|
---|
| 130 | - VecAssemblyBegin(RHS);
|
---|
| 131 | - VecAssemblyEnd( RHS);
|
---|
| 132 | -
|
---|
| 133 | /*Go solve!*/
|
---|
| 134 | SolverxPetsc(&u,LHS,RHS,NULL,NULL, femmodel->parameters);
|
---|
| 135 | MatFree(&LHS);
|
---|
| 136 | @@ -324,9 +343,8 @@
|
---|
| 137 | uf =new Vector<IssmDouble>(u);
|
---|
| 138 | VecFree(&u);
|
---|
| 139 |
|
---|
| 140 | - Mergesolutionfromftogx(&ug, uf,ys,femmodel->nodes,femmodel->parameters);delete uf; delete ys;
|
---|
| 141 | - InputUpdateFromSolutionx(femmodel,ug);
|
---|
| 142 | - delete ug;
|
---|
| 143 | + InputUpdateFromSolutionx(femmodel,uf);
|
---|
| 144 | + delete uf;
|
---|
| 145 |
|
---|
| 146 | #else
|
---|
| 147 | _error_("PETSc needs to be installed");
|
---|