[17831] | 1 | #include "./Balancethickness2Analysis.h"
|
---|
| 2 | #include "../toolkits/toolkits.h"
|
---|
| 3 | #include "../classes/classes.h"
|
---|
| 4 | #include "../shared/shared.h"
|
---|
| 5 | #include "../modules/modules.h"
|
---|
| 6 |
|
---|
| 7 | /*Model processing*/
|
---|
[19105] | 8 | void Balancethickness2Analysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
| 9 |
|
---|
| 10 | int finiteelement = P1Enum;
|
---|
[21341] | 11 | IoModelToConstraintsx(constraints,iomodel,"md.balancethickness.spcthickness",Balancethickness2AnalysisEnum,finiteelement);
|
---|
[19105] | 12 |
|
---|
| 13 | }/*}}}*/
|
---|
| 14 | void Balancethickness2Analysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
| 15 |
|
---|
| 16 | }/*}}}*/
|
---|
[24313] | 17 | void Balancethickness2Analysis::CreateNodes(Nodes* nodes,IoModel* iomodel,bool isamr){/*{{{*/
|
---|
[19105] | 18 |
|
---|
| 19 | int finiteelement = P1Enum;
|
---|
| 20 | ::CreateNodes(nodes,iomodel,Balancethickness2AnalysisEnum,finiteelement);
|
---|
| 21 | }/*}}}*/
|
---|
[17831] | 22 | int Balancethickness2Analysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
|
---|
| 23 | return 1;
|
---|
| 24 | }/*}}}*/
|
---|
[25836] | 25 | void Balancethickness2Analysis::UpdateElements(Elements* elements,Inputs* inputs,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
---|
[17831] | 26 |
|
---|
| 27 | /*Finite element type*/
|
---|
| 28 | int finiteelement = P1Enum;
|
---|
| 29 |
|
---|
[19105] | 30 | /*Load variables in element*/
|
---|
[25836] | 31 | iomodel->FetchDataToInput(inputs,elements,"md.geometry.thickness",ThicknessEnum);
|
---|
| 32 | iomodel->FetchDataToInput(inputs,elements,"md.geometry.surface",SurfaceEnum);
|
---|
| 33 | iomodel->FetchDataToInput(inputs,elements,"md.geometry.base",BaseEnum);
|
---|
| 34 | iomodel->FetchDataToInput(inputs,elements,"md.solidearth.initialsealevel",SealevelEnum,0);
|
---|
| 35 | iomodel->FetchDataToInput(inputs,elements,"md.mask.ice_levelset",MaskIceLevelsetEnum);
|
---|
| 36 | iomodel->FetchDataToInput(inputs,elements,"md.initialization.vx",VxEnum);
|
---|
| 37 | iomodel->FetchDataToInput(inputs,elements,"md.initialization.vy",VyEnum);
|
---|
| 38 | iomodel->FetchDataToInput(inputs,elements,"md.basalforcings.groundedice_melting_rate",BasalforcingsGroundediceMeltingRateEnum);
|
---|
| 39 | iomodel->FetchDataToInput(inputs,elements,"md.smb.mass_balance",SmbMassBalanceEnum);
|
---|
| 40 | iomodel->FetchDataToInput(inputs,elements,"md.balancethickness.thickening_rate",BalancethicknessThickeningRateEnum);
|
---|
[19105] | 41 |
|
---|
[17831] | 42 | /*Update elements: */
|
---|
| 43 | int counter=0;
|
---|
| 44 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
| 45 | if(iomodel->my_elements[i]){
|
---|
| 46 | Element* element=(Element*)elements->GetObjectByOffset(counter);
|
---|
[25836] | 47 | element->Update(inputs,i,iomodel,analysis_counter,analysis_type,finiteelement);
|
---|
[19105] | 48 |
|
---|
[17831] | 49 | counter++;
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | }/*}}}*/
|
---|
[19105] | 54 | void Balancethickness2Analysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
---|
[17831] | 55 | }/*}}}*/
|
---|
| 56 |
|
---|
| 57 | /*Finite Element Analysis*/
|
---|
| 58 | void Balancethickness2Analysis::Core(FemModel* femmodel){/*{{{*/
|
---|
| 59 | _error_("not implemented yet");
|
---|
| 60 | }/*}}}*/
|
---|
| 61 | ElementVector* Balancethickness2Analysis::CreateDVector(Element* element){/*{{{*/
|
---|
| 62 | /*Default, return NULL*/
|
---|
| 63 | return NULL;
|
---|
| 64 | }/*}}}*/
|
---|
| 65 | ElementMatrix* Balancethickness2Analysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
| 66 | _error_("Not implemented");
|
---|
| 67 | }/*}}}*/
|
---|
| 68 | ElementMatrix* Balancethickness2Analysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
| 69 |
|
---|
| 70 | /*Intermediaries */
|
---|
[22758] | 71 | IssmDouble yts = 365*24*3600.;
|
---|
| 72 | IssmDouble Jdet,vx,vy,vel;
|
---|
[17831] | 73 | IssmDouble* xyz_list = NULL;
|
---|
| 74 |
|
---|
| 75 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 76 | int numnodes = element->GetNumberOfNodes();
|
---|
| 77 |
|
---|
| 78 | /*Initialize Element vector and other vectors*/
|
---|
[18301] | 79 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
| 80 | IssmDouble* dbasis = xNew<IssmDouble>(2*numnodes);
|
---|
[17831] | 81 |
|
---|
| 82 | /*Retrieve all inputs and parameters*/
|
---|
| 83 | element->GetVerticesCoordinates(&xyz_list);
|
---|
[25836] | 84 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 85 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
[17831] | 86 |
|
---|
[22758] | 87 | /*Get element characteristic length*/
|
---|
| 88 | IssmDouble h = element->CharacteristicLength();
|
---|
| 89 |
|
---|
[17831] | 90 | /* Start looping on the number of gaussian points: */
|
---|
| 91 | Gauss* gauss=element->NewGauss(2);
|
---|
[25836] | 92 | while(gauss->next()){
|
---|
[17831] | 93 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
[17850] | 94 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
[22758] | 95 | vx_input->GetInputValue(&vx,gauss);
|
---|
| 96 | vy_input->GetInputValue(&vy,gauss);
|
---|
[17831] | 97 |
|
---|
[22758] | 98 | /*make sure are diffusivisty is large enough*/
|
---|
| 99 | vel = sqrt(vx*vx+vy*vy);
|
---|
| 100 | if(sqrt(vx*vx+vy*vy)==0.){
|
---|
| 101 | vx = 0.1/yts;
|
---|
| 102 | vy = 0.1/yts;
|
---|
| 103 | vel = sqrt(vx*vx+vy*vy);
|
---|
| 104 | }
|
---|
| 105 | else if(vel<30./yts){
|
---|
| 106 | vx = 0.;//vx/vel*0.01;
|
---|
| 107 | vy = 0.;//vy/vel*0.01;
|
---|
| 108 | vel = sqrt(vx*vx+vy*vy);
|
---|
| 109 | vel = 30./yts*500000.;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[17831] | 112 | for(int i=0;i<numnodes;i++){
|
---|
| 113 | for(int j=0;j<numnodes;j++){
|
---|
[22758] | 114 | Ke->values[i*numnodes+j] += gauss->weight*Jdet*(
|
---|
| 115 | (vx*dbasis[0*numnodes+i] + vy*dbasis[1*numnodes+i])*(vx*dbasis[0*numnodes+j] + vy*dbasis[1*numnodes+j])
|
---|
| 116 | + vel/500000.*(dbasis[0*numnodes+i]*dbasis[0*numnodes+j] + dbasis[1*numnodes+i]*dbasis[1*numnodes+j]));
|
---|
[17831] | 117 | }
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | /*Clean up and return*/
|
---|
| 122 | xDelete<IssmDouble>(xyz_list);
|
---|
[18301] | 123 | xDelete<IssmDouble>(dbasis);
|
---|
[17831] | 124 | delete gauss;
|
---|
| 125 | return Ke;
|
---|
| 126 | }/*}}}*/
|
---|
| 127 | ElementVector* Balancethickness2Analysis::CreatePVector(Element* element){/*{{{*/
|
---|
| 128 |
|
---|
[22758] | 129 | return NULL;
|
---|
[17831] | 130 | /*Intermediaries */
|
---|
[22758] | 131 | IssmDouble dhdt[2],mb[2],ms[2],Jdet;
|
---|
[17831] | 132 | IssmDouble* xyz_list = NULL;
|
---|
| 133 |
|
---|
| 134 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 135 | int numnodes = element->GetNumberOfNodes();
|
---|
| 136 |
|
---|
| 137 | /*Initialize Element vector and other vectors*/
|
---|
| 138 | ElementVector* pe = element->NewElementVector();
|
---|
| 139 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 140 |
|
---|
| 141 | /*Retrieve all inputs and parameters*/
|
---|
| 142 | element->GetVerticesCoordinates(&xyz_list);
|
---|
[25836] | 143 | Input* ms_input = element->GetInput(SmbMassBalanceEnum); _assert_(ms_input);
|
---|
| 144 | Input* mb_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(mb_input);
|
---|
| 145 | Input* dhdt_input = element->GetInput(BalancethicknessThickeningRateEnum); _assert_(dhdt_input);
|
---|
[17831] | 146 |
|
---|
| 147 | /* Start looping on the number of gaussian points: */
|
---|
| 148 | Gauss* gauss=element->NewGauss(2);
|
---|
[25836] | 149 | while(gauss->next()){
|
---|
[17831] | 150 |
|
---|
| 151 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
| 152 | element->NodalFunctions(basis,gauss);
|
---|
| 153 |
|
---|
[22758] | 154 | ms_input->GetInputDerivativeValue(&ms[0],xyz_list,gauss);
|
---|
[17831] | 155 |
|
---|
[22758] | 156 | ms_input->GetInputDerivativeValue(&ms[0],xyz_list,gauss);
|
---|
| 157 | mb_input->GetInputDerivativeValue(&mb[0],xyz_list,gauss);
|
---|
| 158 | dhdt_input->GetInputDerivativeValue(&dhdt[0],xyz_list,gauss);
|
---|
| 159 |
|
---|
| 160 | for(int i=0;i<numnodes;i++) pe->values[i]+=0*Jdet*gauss->weight*(
|
---|
| 161 | (ms[0]+ms[1]-mb[0]-mb[1]-dhdt[0]-dhdt[1])*basis[i]
|
---|
[19105] | 162 | );
|
---|
[17831] | 163 | }
|
---|
| 164 |
|
---|
| 165 | /*Clean up and return*/
|
---|
| 166 | xDelete<IssmDouble>(xyz_list);
|
---|
| 167 | xDelete<IssmDouble>(basis);
|
---|
| 168 | delete gauss;
|
---|
| 169 | return pe;
|
---|
| 170 | }/*}}}*/
|
---|
[19105] | 171 | void Balancethickness2Analysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
[22758] | 172 | element->GetSolutionFromInputsOneDof(solution,ThicknessEnum);
|
---|
[17831] | 173 | }/*}}}*/
|
---|
[25836] | 174 | void Balancethickness2Analysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_interp,int control_index){/*{{{*/
|
---|
[18301] | 175 | _error_("Not implemented yet");
|
---|
| 176 | }/*}}}*/
|
---|
[19105] | 177 | void Balancethickness2Analysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
[17831] | 178 |
|
---|
[22758] | 179 | element->InputUpdateFromSolutionOneDof(solution,ThicknessEnum);
|
---|
[17831] | 180 |
|
---|
| 181 | }/*}}}*/
|
---|
[19105] | 182 | void Balancethickness2Analysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
[17831] | 183 | /*Default, do nothing*/
|
---|
| 184 | return;
|
---|
| 185 | }/*}}}*/
|
---|