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