[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);
|
---|
[26744] | 34 | iomodel->FetchDataToInput(inputs,elements,"md.initialization.sealevel",SealevelEnum,0);
|
---|
[25836] | 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 | }/*}}}*/
|
---|
[26744] | 61 | void Balancethickness2Analysis::PreCore(FemModel* femmodel){/*{{{*/
|
---|
| 62 | _error_("not implemented yet");
|
---|
| 63 | }/*}}}*/
|
---|
[17831] | 64 | ElementVector* Balancethickness2Analysis::CreateDVector(Element* element){/*{{{*/
|
---|
| 65 | /*Default, return NULL*/
|
---|
| 66 | return NULL;
|
---|
| 67 | }/*}}}*/
|
---|
| 68 | ElementMatrix* Balancethickness2Analysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
| 69 | _error_("Not implemented");
|
---|
| 70 | }/*}}}*/
|
---|
| 71 | ElementMatrix* Balancethickness2Analysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
| 72 |
|
---|
| 73 | /*Intermediaries */
|
---|
[22758] | 74 | IssmDouble yts = 365*24*3600.;
|
---|
| 75 | IssmDouble Jdet,vx,vy,vel;
|
---|
[17831] | 76 | IssmDouble* xyz_list = NULL;
|
---|
| 77 |
|
---|
| 78 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 79 | int numnodes = element->GetNumberOfNodes();
|
---|
| 80 |
|
---|
| 81 | /*Initialize Element vector and other vectors*/
|
---|
[18301] | 82 | ElementMatrix* Ke = element->NewElementMatrix();
|
---|
| 83 | IssmDouble* dbasis = xNew<IssmDouble>(2*numnodes);
|
---|
[17831] | 84 |
|
---|
| 85 | /*Retrieve all inputs and parameters*/
|
---|
| 86 | element->GetVerticesCoordinates(&xyz_list);
|
---|
[25836] | 87 | Input* vx_input = element->GetInput(VxEnum); _assert_(vx_input);
|
---|
| 88 | Input* vy_input = element->GetInput(VyEnum); _assert_(vy_input);
|
---|
[17831] | 89 |
|
---|
[22758] | 90 | /*Get element characteristic length*/
|
---|
| 91 | IssmDouble h = element->CharacteristicLength();
|
---|
| 92 |
|
---|
[17831] | 93 | /* Start looping on the number of gaussian points: */
|
---|
| 94 | Gauss* gauss=element->NewGauss(2);
|
---|
[25836] | 95 | while(gauss->next()){
|
---|
[17831] | 96 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
[17850] | 97 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
[22758] | 98 | vx_input->GetInputValue(&vx,gauss);
|
---|
| 99 | vy_input->GetInputValue(&vy,gauss);
|
---|
[17831] | 100 |
|
---|
[22758] | 101 | /*make sure are diffusivisty is large enough*/
|
---|
| 102 | vel = sqrt(vx*vx+vy*vy);
|
---|
| 103 | if(sqrt(vx*vx+vy*vy)==0.){
|
---|
| 104 | vx = 0.1/yts;
|
---|
| 105 | vy = 0.1/yts;
|
---|
| 106 | vel = sqrt(vx*vx+vy*vy);
|
---|
| 107 | }
|
---|
| 108 | else if(vel<30./yts){
|
---|
| 109 | vx = 0.;//vx/vel*0.01;
|
---|
| 110 | vy = 0.;//vy/vel*0.01;
|
---|
| 111 | vel = sqrt(vx*vx+vy*vy);
|
---|
| 112 | vel = 30./yts*500000.;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[17831] | 115 | for(int i=0;i<numnodes;i++){
|
---|
| 116 | for(int j=0;j<numnodes;j++){
|
---|
[22758] | 117 | Ke->values[i*numnodes+j] += gauss->weight*Jdet*(
|
---|
| 118 | (vx*dbasis[0*numnodes+i] + vy*dbasis[1*numnodes+i])*(vx*dbasis[0*numnodes+j] + vy*dbasis[1*numnodes+j])
|
---|
| 119 | + vel/500000.*(dbasis[0*numnodes+i]*dbasis[0*numnodes+j] + dbasis[1*numnodes+i]*dbasis[1*numnodes+j]));
|
---|
[17831] | 120 | }
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | /*Clean up and return*/
|
---|
| 125 | xDelete<IssmDouble>(xyz_list);
|
---|
[18301] | 126 | xDelete<IssmDouble>(dbasis);
|
---|
[17831] | 127 | delete gauss;
|
---|
| 128 | return Ke;
|
---|
| 129 | }/*}}}*/
|
---|
| 130 | ElementVector* Balancethickness2Analysis::CreatePVector(Element* element){/*{{{*/
|
---|
| 131 |
|
---|
[22758] | 132 | return NULL;
|
---|
[17831] | 133 | /*Intermediaries */
|
---|
[22758] | 134 | IssmDouble dhdt[2],mb[2],ms[2],Jdet;
|
---|
[17831] | 135 | IssmDouble* xyz_list = NULL;
|
---|
| 136 |
|
---|
| 137 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 138 | int numnodes = element->GetNumberOfNodes();
|
---|
| 139 |
|
---|
| 140 | /*Initialize Element vector and other vectors*/
|
---|
| 141 | ElementVector* pe = element->NewElementVector();
|
---|
| 142 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 143 |
|
---|
| 144 | /*Retrieve all inputs and parameters*/
|
---|
| 145 | element->GetVerticesCoordinates(&xyz_list);
|
---|
[25836] | 146 | Input* ms_input = element->GetInput(SmbMassBalanceEnum); _assert_(ms_input);
|
---|
| 147 | Input* mb_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(mb_input);
|
---|
| 148 | Input* dhdt_input = element->GetInput(BalancethicknessThickeningRateEnum); _assert_(dhdt_input);
|
---|
[17831] | 149 |
|
---|
| 150 | /* Start looping on the number of gaussian points: */
|
---|
| 151 | Gauss* gauss=element->NewGauss(2);
|
---|
[25836] | 152 | while(gauss->next()){
|
---|
[17831] | 153 |
|
---|
| 154 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
| 155 | element->NodalFunctions(basis,gauss);
|
---|
| 156 |
|
---|
[22758] | 157 | ms_input->GetInputDerivativeValue(&ms[0],xyz_list,gauss);
|
---|
[17831] | 158 |
|
---|
[22758] | 159 | ms_input->GetInputDerivativeValue(&ms[0],xyz_list,gauss);
|
---|
| 160 | mb_input->GetInputDerivativeValue(&mb[0],xyz_list,gauss);
|
---|
| 161 | dhdt_input->GetInputDerivativeValue(&dhdt[0],xyz_list,gauss);
|
---|
| 162 |
|
---|
| 163 | for(int i=0;i<numnodes;i++) pe->values[i]+=0*Jdet*gauss->weight*(
|
---|
| 164 | (ms[0]+ms[1]-mb[0]-mb[1]-dhdt[0]-dhdt[1])*basis[i]
|
---|
[19105] | 165 | );
|
---|
[17831] | 166 | }
|
---|
| 167 |
|
---|
| 168 | /*Clean up and return*/
|
---|
| 169 | xDelete<IssmDouble>(xyz_list);
|
---|
| 170 | xDelete<IssmDouble>(basis);
|
---|
| 171 | delete gauss;
|
---|
| 172 | return pe;
|
---|
| 173 | }/*}}}*/
|
---|
[19105] | 174 | void Balancethickness2Analysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
[22758] | 175 | element->GetSolutionFromInputsOneDof(solution,ThicknessEnum);
|
---|
[17831] | 176 | }/*}}}*/
|
---|
[25836] | 177 | void Balancethickness2Analysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_interp,int control_index){/*{{{*/
|
---|
[18301] | 178 | _error_("Not implemented yet");
|
---|
| 179 | }/*}}}*/
|
---|
[19105] | 180 | void Balancethickness2Analysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
[17831] | 181 |
|
---|
[22758] | 182 | element->InputUpdateFromSolutionOneDof(solution,ThicknessEnum);
|
---|
[17831] | 183 |
|
---|
| 184 | }/*}}}*/
|
---|
[19105] | 185 | void Balancethickness2Analysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
[17831] | 186 | /*Default, do nothing*/
|
---|
| 187 | return;
|
---|
| 188 | }/*}}}*/
|
---|