[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 | }/*}}}*/
|
---|
| 17 | void Balancethickness2Analysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
|
---|
| 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 | }/*}}}*/
|
---|
| 25 | void Balancethickness2Analysis::UpdateElements(Elements* elements,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
---|
| 26 |
|
---|
| 27 | /*Finite element type*/
|
---|
| 28 | int finiteelement = P1Enum;
|
---|
| 29 |
|
---|
[19105] | 30 | /*Load variables in element*/
|
---|
[21341] | 31 | iomodel->FetchDataToInput(elements,"md.geometry.thickness",ThicknessEnum);
|
---|
| 32 | iomodel->FetchDataToInput(elements,"md.geometry.surface",SurfaceEnum);
|
---|
| 33 | iomodel->FetchDataToInput(elements,"md.geometry.base",BaseEnum);
|
---|
| 34 | iomodel->FetchDataToInput(elements,"md.slr.sealevel",SealevelEnum,0);
|
---|
| 35 | iomodel->FetchDataToInput(elements,"md.mask.ice_levelset",MaskIceLevelsetEnum);
|
---|
[22758] | 36 | iomodel->FetchDataToInput(elements,"md.initialization.vx",VxEnum);
|
---|
| 37 | iomodel->FetchDataToInput(elements,"md.initialization.vy",VyEnum);
|
---|
[21341] | 38 | iomodel->FetchDataToInput(elements,"md.basalforcings.groundedice_melting_rate",BasalforcingsGroundediceMeltingRateEnum);
|
---|
| 39 | iomodel->FetchDataToInput(elements,"md.smb.mass_balance",SmbMassBalanceEnum);
|
---|
| 40 | iomodel->FetchDataToInput(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);
|
---|
| 47 | element->Update(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);
|
---|
[22758] | 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);
|
---|
| 92 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 93 | gauss->GaussPoint(ig);
|
---|
| 94 | element->NodalFunctionsDerivatives(dbasis,xyz_list,gauss);
|
---|
[17850] | 95 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
[22758] | 96 | vx_input->GetInputValue(&vx,gauss);
|
---|
| 97 | vy_input->GetInputValue(&vy,gauss);
|
---|
[17831] | 98 |
|
---|
[22758] | 99 | /*make sure are diffusivisty is large enough*/
|
---|
| 100 | vel = sqrt(vx*vx+vy*vy);
|
---|
| 101 | if(sqrt(vx*vx+vy*vy)==0.){
|
---|
| 102 | vx = 0.1/yts;
|
---|
| 103 | vy = 0.1/yts;
|
---|
| 104 | vel = sqrt(vx*vx+vy*vy);
|
---|
| 105 | }
|
---|
| 106 | else if(vel<30./yts){
|
---|
| 107 | vx = 0.;//vx/vel*0.01;
|
---|
| 108 | vy = 0.;//vy/vel*0.01;
|
---|
| 109 | vel = sqrt(vx*vx+vy*vy);
|
---|
| 110 | vel = 30./yts*500000.;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[17831] | 113 | for(int i=0;i<numnodes;i++){
|
---|
| 114 | for(int j=0;j<numnodes;j++){
|
---|
[22758] | 115 | Ke->values[i*numnodes+j] += gauss->weight*Jdet*(
|
---|
| 116 | (vx*dbasis[0*numnodes+i] + vy*dbasis[1*numnodes+i])*(vx*dbasis[0*numnodes+j] + vy*dbasis[1*numnodes+j])
|
---|
| 117 | + vel/500000.*(dbasis[0*numnodes+i]*dbasis[0*numnodes+j] + dbasis[1*numnodes+i]*dbasis[1*numnodes+j]));
|
---|
[17831] | 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | /*Clean up and return*/
|
---|
| 123 | xDelete<IssmDouble>(xyz_list);
|
---|
[18301] | 124 | xDelete<IssmDouble>(dbasis);
|
---|
[17831] | 125 | delete gauss;
|
---|
| 126 | return Ke;
|
---|
| 127 | }/*}}}*/
|
---|
| 128 | ElementVector* Balancethickness2Analysis::CreatePVector(Element* element){/*{{{*/
|
---|
| 129 |
|
---|
[22758] | 130 | return NULL;
|
---|
[17831] | 131 | /*Intermediaries */
|
---|
[22758] | 132 | IssmDouble dhdt[2],mb[2],ms[2],Jdet;
|
---|
[17831] | 133 | IssmDouble* xyz_list = NULL;
|
---|
| 134 |
|
---|
| 135 | /*Fetch number of nodes and dof for this finite element*/
|
---|
| 136 | int numnodes = element->GetNumberOfNodes();
|
---|
| 137 |
|
---|
| 138 | /*Initialize Element vector and other vectors*/
|
---|
| 139 | ElementVector* pe = element->NewElementVector();
|
---|
| 140 | IssmDouble* basis = xNew<IssmDouble>(numnodes);
|
---|
| 141 |
|
---|
| 142 | /*Retrieve all inputs and parameters*/
|
---|
| 143 | element->GetVerticesCoordinates(&xyz_list);
|
---|
[20500] | 144 | Input* ms_input = element->GetInput(SmbMassBalanceEnum); _assert_(ms_input);
|
---|
[19105] | 145 | Input* mb_input = element->GetInput(BasalforcingsGroundediceMeltingRateEnum); _assert_(mb_input);
|
---|
| 146 | Input* dhdt_input = element->GetInput(BalancethicknessThickeningRateEnum); _assert_(dhdt_input);
|
---|
[17831] | 147 |
|
---|
| 148 | /* Start looping on the number of gaussian points: */
|
---|
| 149 | Gauss* gauss=element->NewGauss(2);
|
---|
| 150 | for(int ig=gauss->begin();ig<gauss->end();ig++){
|
---|
| 151 | gauss->GaussPoint(ig);
|
---|
| 152 |
|
---|
| 153 | element->JacobianDeterminant(&Jdet,xyz_list,gauss);
|
---|
| 154 | element->NodalFunctions(basis,gauss);
|
---|
| 155 |
|
---|
[22758] | 156 | ms_input->GetInputDerivativeValue(&ms[0],xyz_list,gauss);
|
---|
[17831] | 157 |
|
---|
[22758] | 158 | ms_input->GetInputDerivativeValue(&ms[0],xyz_list,gauss);
|
---|
| 159 | mb_input->GetInputDerivativeValue(&mb[0],xyz_list,gauss);
|
---|
| 160 | dhdt_input->GetInputDerivativeValue(&dhdt[0],xyz_list,gauss);
|
---|
| 161 |
|
---|
| 162 | for(int i=0;i<numnodes;i++) pe->values[i]+=0*Jdet*gauss->weight*(
|
---|
| 163 | (ms[0]+ms[1]-mb[0]-mb[1]-dhdt[0]-dhdt[1])*basis[i]
|
---|
[19105] | 164 | );
|
---|
[17831] | 165 | }
|
---|
| 166 |
|
---|
| 167 | /*Clean up and return*/
|
---|
| 168 | xDelete<IssmDouble>(xyz_list);
|
---|
| 169 | xDelete<IssmDouble>(basis);
|
---|
| 170 | delete gauss;
|
---|
| 171 | return pe;
|
---|
| 172 | }/*}}}*/
|
---|
[19105] | 173 | void Balancethickness2Analysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
[22758] | 174 | element->GetSolutionFromInputsOneDof(solution,ThicknessEnum);
|
---|
[17831] | 175 | }/*}}}*/
|
---|
[19105] | 176 | void Balancethickness2Analysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
|
---|
[18301] | 177 | _error_("Not implemented yet");
|
---|
| 178 | }/*}}}*/
|
---|
[19105] | 179 | void Balancethickness2Analysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
[17831] | 180 |
|
---|
[22758] | 181 | element->InputUpdateFromSolutionOneDof(solution,ThicknessEnum);
|
---|
[17831] | 182 |
|
---|
| 183 | }/*}}}*/
|
---|
[19105] | 184 | void Balancethickness2Analysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
[17831] | 185 | /*Default, do nothing*/
|
---|
| 186 | return;
|
---|
| 187 | }/*}}}*/
|
---|