[19984] | 1 | #include "./SealevelriseAnalysis.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*/
|
---|
| 8 | void SealevelriseAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
|
---|
| 9 | /*No constraints*/
|
---|
| 10 | }/*}}}*/
|
---|
| 11 | void SealevelriseAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
|
---|
| 12 | /*No loads*/
|
---|
| 13 | }/*}}}*/
|
---|
| 14 | void SealevelriseAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
|
---|
| 15 | ::CreateNodes(nodes,iomodel,SealevelriseAnalysisEnum,P1Enum);
|
---|
| 16 | }/*}}}*/
|
---|
| 17 | int SealevelriseAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
|
---|
| 18 | return 1;
|
---|
| 19 | }/*}}}*/
|
---|
| 20 | void SealevelriseAnalysis::UpdateElements(Elements* elements,IoModel* iomodel,int analysis_counter,int analysis_type){/*{{{*/
|
---|
| 21 |
|
---|
| 22 | /*Update elements: */
|
---|
| 23 | int counter=0;
|
---|
| 24 | for(int i=0;i<iomodel->numberofelements;i++){
|
---|
| 25 | if(iomodel->my_elements[i]){
|
---|
| 26 | Element* element=(Element*)elements->GetObjectByOffset(counter);
|
---|
| 27 | element->Update(i,iomodel,analysis_counter,analysis_type,P1Enum);
|
---|
| 28 | counter++;
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | /*Create inputs: */
|
---|
[20690] | 33 | iomodel->FetchDataToInput(elements,"md.mask.ice_levelset",MaskIceLevelsetEnum);
|
---|
| 34 | iomodel->FetchDataToInput(elements,"md.mask.ocean_levelset",MaskOceanLevelsetEnum);
|
---|
| 35 | iomodel->FetchDataToInput(elements,"md.mask.land_levelset",MaskLandLevelsetEnum);
|
---|
[20704] | 36 | iomodel->FetchDataToInput(elements,"md.slr.deltathickness",SealevelriseDeltathicknessEnum);
|
---|
[20690] | 37 | iomodel->FetchDataToInput(elements,"md.slr.sealevel",SealevelEnum,0);
|
---|
[19984] | 38 |
|
---|
| 39 | }/*}}}*/
|
---|
| 40 | void SealevelriseAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
---|
| 41 |
|
---|
[19986] | 42 | int nl;
|
---|
[19984] | 43 | IssmDouble* love_h=NULL;
|
---|
| 44 | IssmDouble* love_k=NULL;
|
---|
[20999] | 45 | IssmDouble* love_l=NULL;
|
---|
[19986] | 46 |
|
---|
[20029] | 47 | bool elastic=false;
|
---|
[20028] | 48 | IssmDouble* G_elastic = NULL;
|
---|
[20033] | 49 | IssmDouble* G_elastic_local = NULL;
|
---|
[20999] | 50 | IssmDouble* U_elastic = NULL;
|
---|
| 51 | IssmDouble* U_elastic_local = NULL;
|
---|
| 52 | IssmDouble* H_elastic = NULL;
|
---|
| 53 | IssmDouble* H_elastic_local = NULL;
|
---|
[20033] | 54 | int M,m,lower_row,upper_row;
|
---|
| 55 | IssmDouble degacc=.01;
|
---|
[19984] | 56 |
|
---|
[20036] | 57 | int numoutputs;
|
---|
| 58 | char** requestedoutputs = NULL;
|
---|
| 59 |
|
---|
[20136] | 60 | /*transition vectors: */
|
---|
| 61 | IssmDouble **transitions = NULL;
|
---|
| 62 | int *transitions_M = NULL;
|
---|
| 63 | int *transitions_N = NULL;
|
---|
| 64 | int ntransitions;
|
---|
| 65 |
|
---|
[19986] | 66 | /*some constant parameters: */
|
---|
[20690] | 67 | parameters->AddObject(iomodel->CopyConstantObject("md.slr.reltol",SealevelriseReltolEnum));
|
---|
| 68 | parameters->AddObject(iomodel->CopyConstantObject("md.slr.abstol",SealevelriseAbstolEnum));
|
---|
| 69 | parameters->AddObject(iomodel->CopyConstantObject("md.slr.maxiter",SealevelriseMaxiterEnum));
|
---|
| 70 | parameters->AddObject(iomodel->CopyConstantObject("md.slr.rigid",SealevelriseRigidEnum));
|
---|
| 71 | parameters->AddObject(iomodel->CopyConstantObject("md.slr.elastic",SealevelriseElasticEnum));
|
---|
[19986] | 72 |
|
---|
[20690] | 73 | iomodel->FetchData(&elastic,"md.slr.elastic");
|
---|
[20029] | 74 | if(elastic){
|
---|
[19984] | 75 |
|
---|
[20029] | 76 | /*love numbers: */
|
---|
[20690] | 77 | iomodel->FetchData(&love_h,&nl,NULL,"md.slr.love_h");
|
---|
| 78 | iomodel->FetchData(&love_k,&nl,NULL,"md.slr.love_k");
|
---|
[20999] | 79 | iomodel->FetchData(&love_l,&nl,NULL,"md.slr.love_l");
|
---|
[20022] | 80 |
|
---|
[20029] | 81 | /*compute elastic green function for a range of angles*/
|
---|
[20690] | 82 | iomodel->FetchData(°acc,"md.slr.degacc");
|
---|
[20034] | 83 | M=reCast<int,IssmDouble>(180./degacc+1.);
|
---|
[20029] | 84 | G_elastic=xNew<IssmDouble>(M);
|
---|
[20999] | 85 | U_elastic=xNew<IssmDouble>(M);
|
---|
| 86 | H_elastic=xNew<IssmDouble>(M);
|
---|
[20044] | 87 |
|
---|
| 88 | /*compute combined legendre + love number (elastic green function:*/
|
---|
[20033] | 89 | m=DetermineLocalSize(M,IssmComm::GetComm());
|
---|
| 90 | GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,IssmComm::GetComm());
|
---|
| 91 | G_elastic_local=xNew<IssmDouble>(m);
|
---|
[20999] | 92 | U_elastic_local=xNew<IssmDouble>(m);
|
---|
| 93 | H_elastic_local=xNew<IssmDouble>(m);
|
---|
[20033] | 94 |
|
---|
| 95 | for(int i=lower_row;i<upper_row;i++){
|
---|
[20029] | 96 | IssmDouble alpha,x;
|
---|
| 97 | alpha= reCast<IssmDouble>(i)*degacc * PI / 180.0;
|
---|
| 98 |
|
---|
[20033] | 99 | G_elastic_local[i-lower_row]= (love_k[nl-1]-love_h[nl-1])/2.0/sin(alpha/2.0);
|
---|
[20999] | 100 | U_elastic_local[i-lower_row]= (love_h[nl-1])/2.0/sin(alpha/2.0);
|
---|
| 101 | H_elastic_local[i-lower_row]= 0;
|
---|
[20054] | 102 | IssmDouble Pn,Pn1,Pn2;
|
---|
[20999] | 103 | IssmDouble Pn_p,Pn_p1,Pn_p2;
|
---|
[20033] | 104 | for (int n=0;n<nl;n++) {
|
---|
[20999] | 105 | IssmDouble deltalove_G;
|
---|
| 106 | IssmDouble deltalove_U;
|
---|
[20033] | 107 |
|
---|
[20999] | 108 | deltalove_G = (love_k[n]-love_k[nl-1]-love_h[n]+love_h[nl-1]);
|
---|
| 109 | deltalove_U = (love_h[n]-love_h[nl-1]);
|
---|
| 110 |
|
---|
| 111 | /*compute legendre polynomials: P_n(cos\theta) & d P_n(cos\theta)/ d\theta: */
|
---|
| 112 | if(n==0){
|
---|
| 113 | Pn=1;
|
---|
| 114 | Pn_p=0;
|
---|
| 115 | }
|
---|
| 116 | else if(n==1){
|
---|
| 117 | Pn = cos(alpha);
|
---|
| 118 | Pn_p = 1;
|
---|
| 119 | }
|
---|
| 120 | else{
|
---|
| 121 | Pn = ( (2*n-1)*cos(alpha)*Pn1 - (n-1)*Pn2 ) /n;
|
---|
| 122 | Pn_p = ( (2*n-1)*(Pn1+cos(alpha)*Pn_p1) - (n-1)*Pn_p2 ) /n;
|
---|
| 123 | }
|
---|
[20033] | 124 | Pn2=Pn1; Pn1=Pn;
|
---|
[20999] | 125 | Pn_p2=Pn_p1; Pn_p1=Pn_p;
|
---|
[20033] | 126 |
|
---|
[20999] | 127 | G_elastic_local[i-lower_row] += deltalove_G*Pn; // gravitational potential
|
---|
| 128 | U_elastic_local[i-lower_row] += deltalove_U*Pn; // vertical (up) displacement
|
---|
| 129 | H_elastic_local[i-lower_row] += sin(alpha)*love_l[n]*Pn_p; // horizontal displacements
|
---|
[20033] | 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[20999] | 133 | /*merge G_elastic_local into G_elastic; U_elastic_local into U_elastic; H_elastic_local to H_elastic:{{{*/
|
---|
[20033] | 134 | int* recvcounts=xNew<int>(IssmComm::GetSize());
|
---|
| 135 | int* displs=xNew<int>(IssmComm::GetSize());
|
---|
| 136 |
|
---|
| 137 | //recvcounts:
|
---|
| 138 | ISSM_MPI_Allgather(&m,1,ISSM_MPI_INT,recvcounts,1,ISSM_MPI_INT,IssmComm::GetComm());
|
---|
| 139 |
|
---|
| 140 | /*displs: */
|
---|
| 141 | ISSM_MPI_Allgather(&lower_row,1,ISSM_MPI_INT,displs,1,ISSM_MPI_INT,IssmComm::GetComm());
|
---|
| 142 |
|
---|
| 143 | /*All gather:*/
|
---|
| 144 | ISSM_MPI_Allgatherv(G_elastic_local, m, ISSM_MPI_DOUBLE, G_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
---|
[20999] | 145 | ISSM_MPI_Allgatherv(U_elastic_local, m, ISSM_MPI_DOUBLE, U_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
---|
| 146 | ISSM_MPI_Allgatherv(H_elastic_local, m, ISSM_MPI_DOUBLE, H_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
---|
[20033] | 147 | /*free ressources: */
|
---|
| 148 | xDelete<int>(recvcounts);
|
---|
| 149 | xDelete<int>(displs);
|
---|
| 150 |
|
---|
| 151 | /*}}}*/
|
---|
| 152 |
|
---|
[20029] | 153 | /*Avoid singularity at 0: */
|
---|
| 154 | G_elastic[0]=G_elastic[1];
|
---|
| 155 | parameters->AddObject(new DoubleVecParam(SealevelriseGElasticEnum,G_elastic,M));
|
---|
[20999] | 156 | U_elastic[0]=U_elastic[1];
|
---|
| 157 | parameters->AddObject(new DoubleVecParam(SealevelriseUElasticEnum,U_elastic,M));
|
---|
| 158 | H_elastic[0]=H_elastic[1];
|
---|
| 159 | parameters->AddObject(new DoubleVecParam(SealevelriseHElasticEnum,H_elastic,M));
|
---|
[20028] | 160 |
|
---|
[20029] | 161 | /*free ressources: */
|
---|
| 162 | xDelete<IssmDouble>(love_h);
|
---|
| 163 | xDelete<IssmDouble>(love_k);
|
---|
[20999] | 164 | xDelete<IssmDouble>(love_l);
|
---|
[20029] | 165 | xDelete<IssmDouble>(G_elastic);
|
---|
[20033] | 166 | xDelete<IssmDouble>(G_elastic_local);
|
---|
[20999] | 167 | xDelete<IssmDouble>(U_elastic);
|
---|
| 168 | xDelete<IssmDouble>(U_elastic_local);
|
---|
| 169 | xDelete<IssmDouble>(H_elastic);
|
---|
| 170 | xDelete<IssmDouble>(H_elastic_local);
|
---|
[20029] | 171 | }
|
---|
[20036] | 172 |
|
---|
[20136] | 173 | /*Transitions: */
|
---|
[20690] | 174 | iomodel->FetchData(&transitions,&transitions_M,&transitions_N,&ntransitions,"md.slr.transitions");
|
---|
[20136] | 175 | if(transitions){
|
---|
| 176 | parameters->AddObject(new DoubleMatArrayParam(SealevelriseTransitionsEnum,transitions,ntransitions,transitions_M,transitions_N));
|
---|
| 177 |
|
---|
| 178 | for(int i=0;i<ntransitions;i++){
|
---|
| 179 | IssmDouble* transition=transitions[i];
|
---|
| 180 | xDelete<IssmDouble>(transition);
|
---|
| 181 | }
|
---|
| 182 | xDelete<IssmDouble*>(transitions);
|
---|
[20138] | 183 | xDelete<int>(transitions_M);
|
---|
| 184 | xDelete<int>(transitions_N);
|
---|
[20136] | 185 | }
|
---|
| 186 |
|
---|
[20036] | 187 | /*Requested outputs*/
|
---|
[20690] | 188 | iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.slr.requested_outputs");
|
---|
[20036] | 189 | parameters->AddObject(new IntParam(SealevelriseNumRequestedOutputsEnum,numoutputs));
|
---|
| 190 | if(numoutputs)parameters->AddObject(new StringArrayParam(SealevelriseRequestedOutputsEnum,requestedoutputs,numoutputs));
|
---|
[20690] | 191 | iomodel->DeleteData(&requestedoutputs,numoutputs,"md.slr.requested_outputs");
|
---|
[20029] | 192 |
|
---|
[20036] | 193 |
|
---|
[19984] | 194 | }/*}}}*/
|
---|
| 195 |
|
---|
| 196 | /*Finite Element Analysis*/
|
---|
| 197 | void SealevelriseAnalysis::Core(FemModel* femmodel){/*{{{*/
|
---|
| 198 | _error_("not implemented");
|
---|
| 199 | }/*}}}*/
|
---|
| 200 | ElementVector* SealevelriseAnalysis::CreateDVector(Element* element){/*{{{*/
|
---|
| 201 | /*Default, return NULL*/
|
---|
| 202 | return NULL;
|
---|
| 203 | }/*}}}*/
|
---|
| 204 | ElementMatrix* SealevelriseAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
| 205 | _error_("Not implemented");
|
---|
| 206 | }/*}}}*/
|
---|
| 207 | ElementMatrix* SealevelriseAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
| 208 | _error_("not implemented yet");
|
---|
| 209 | }/*}}}*/
|
---|
| 210 | ElementVector* SealevelriseAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
| 211 | _error_("not implemented yet");
|
---|
| 212 | }/*}}}*/
|
---|
| 213 | void SealevelriseAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
| 214 | _error_("not implemented yet");
|
---|
| 215 | }/*}}}*/
|
---|
| 216 | void SealevelriseAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
|
---|
| 217 | _error_("Not implemented yet");
|
---|
| 218 | }/*}}}*/
|
---|
| 219 | void SealevelriseAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
[20153] | 220 |
|
---|
| 221 | IssmDouble *deltaS = NULL;
|
---|
| 222 | IssmDouble *S = NULL;
|
---|
| 223 | int* sidlist = NULL;
|
---|
| 224 | int numvertices;
|
---|
| 225 |
|
---|
| 226 | numvertices= element->GetNumberOfVertices();
|
---|
| 227 | sidlist=xNew<int>(numvertices);
|
---|
| 228 |
|
---|
| 229 | element->GetVerticesSidList(sidlist);
|
---|
| 230 |
|
---|
| 231 | deltaS = xNew<IssmDouble>(numvertices);
|
---|
| 232 | for(int i=0;i<numvertices;i++){
|
---|
| 233 | deltaS[i]=solution[sidlist[i]];
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | S = xNew<IssmDouble>(numvertices);
|
---|
[20154] | 237 | element->GetInputListOnVertices(S,SealevelEnum,0);
|
---|
[20153] | 238 |
|
---|
| 239 | /*Add deltaS to S:*/
|
---|
| 240 | for (int i=0;i<numvertices;i++)S[i]+=deltaS[i];
|
---|
| 241 |
|
---|
| 242 | /*Add S back into inputs: */
|
---|
[20154] | 243 | element->AddInput(SealevelEnum,S,P1Enum);
|
---|
[20153] | 244 |
|
---|
| 245 | /*Free ressources:*/
|
---|
| 246 | xDelete<int>(sidlist);
|
---|
| 247 | xDelete<IssmDouble>(deltaS);
|
---|
| 248 | xDelete<IssmDouble>(S);
|
---|
| 249 |
|
---|
[19984] | 250 | }/*}}}*/
|
---|
| 251 | void SealevelriseAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
| 252 | /*Default, do nothing*/
|
---|
| 253 | return;
|
---|
| 254 | }/*}}}*/
|
---|