source: issm/trunk-jpl/src/c/analyses/SealevelriseAnalysis.cpp@ 20999

Last change on this file since 20999 was 20999, checked in by adhikari, 9 years ago

CHG: added capabilities to compute absolute sea level and 3D crustal motion

File size: 9.0 KB
Line 
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*/
8void SealevelriseAnalysis::CreateConstraints(Constraints* constraints,IoModel* iomodel){/*{{{*/
9 /*No constraints*/
10}/*}}}*/
11void SealevelriseAnalysis::CreateLoads(Loads* loads, IoModel* iomodel){/*{{{*/
12 /*No loads*/
13}/*}}}*/
14void SealevelriseAnalysis::CreateNodes(Nodes* nodes,IoModel* iomodel){/*{{{*/
15 ::CreateNodes(nodes,iomodel,SealevelriseAnalysisEnum,P1Enum);
16}/*}}}*/
17int SealevelriseAnalysis::DofsPerNode(int** doflist,int domaintype,int approximation){/*{{{*/
18 return 1;
19}/*}}}*/
20void 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: */
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);
36 iomodel->FetchDataToInput(elements,"md.slr.deltathickness",SealevelriseDeltathicknessEnum);
37 iomodel->FetchDataToInput(elements,"md.slr.sealevel",SealevelEnum,0);
38
39}/*}}}*/
40void SealevelriseAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
41
42 int nl;
43 IssmDouble* love_h=NULL;
44 IssmDouble* love_k=NULL;
45 IssmDouble* love_l=NULL;
46
47 bool elastic=false;
48 IssmDouble* G_elastic = NULL;
49 IssmDouble* G_elastic_local = NULL;
50 IssmDouble* U_elastic = NULL;
51 IssmDouble* U_elastic_local = NULL;
52 IssmDouble* H_elastic = NULL;
53 IssmDouble* H_elastic_local = NULL;
54 int M,m,lower_row,upper_row;
55 IssmDouble degacc=.01;
56
57 int numoutputs;
58 char** requestedoutputs = NULL;
59
60 /*transition vectors: */
61 IssmDouble **transitions = NULL;
62 int *transitions_M = NULL;
63 int *transitions_N = NULL;
64 int ntransitions;
65
66 /*some constant parameters: */
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));
72
73 iomodel->FetchData(&elastic,"md.slr.elastic");
74 if(elastic){
75
76 /*love numbers: */
77 iomodel->FetchData(&love_h,&nl,NULL,"md.slr.love_h");
78 iomodel->FetchData(&love_k,&nl,NULL,"md.slr.love_k");
79 iomodel->FetchData(&love_l,&nl,NULL,"md.slr.love_l");
80
81 /*compute elastic green function for a range of angles*/
82 iomodel->FetchData(&degacc,"md.slr.degacc");
83 M=reCast<int,IssmDouble>(180./degacc+1.);
84 G_elastic=xNew<IssmDouble>(M);
85 U_elastic=xNew<IssmDouble>(M);
86 H_elastic=xNew<IssmDouble>(M);
87
88 /*compute combined legendre + love number (elastic green function:*/
89 m=DetermineLocalSize(M,IssmComm::GetComm());
90 GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,IssmComm::GetComm());
91 G_elastic_local=xNew<IssmDouble>(m);
92 U_elastic_local=xNew<IssmDouble>(m);
93 H_elastic_local=xNew<IssmDouble>(m);
94
95 for(int i=lower_row;i<upper_row;i++){
96 IssmDouble alpha,x;
97 alpha= reCast<IssmDouble>(i)*degacc * PI / 180.0;
98
99 G_elastic_local[i-lower_row]= (love_k[nl-1]-love_h[nl-1])/2.0/sin(alpha/2.0);
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;
102 IssmDouble Pn,Pn1,Pn2;
103 IssmDouble Pn_p,Pn_p1,Pn_p2;
104 for (int n=0;n<nl;n++) {
105 IssmDouble deltalove_G;
106 IssmDouble deltalove_U;
107
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 }
124 Pn2=Pn1; Pn1=Pn;
125 Pn_p2=Pn_p1; Pn_p1=Pn_p;
126
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
130 }
131 }
132
133 /*merge G_elastic_local into G_elastic; U_elastic_local into U_elastic; H_elastic_local to H_elastic:{{{*/
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());
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());
147 /*free ressources: */
148 xDelete<int>(recvcounts);
149 xDelete<int>(displs);
150
151 /*}}}*/
152
153 /*Avoid singularity at 0: */
154 G_elastic[0]=G_elastic[1];
155 parameters->AddObject(new DoubleVecParam(SealevelriseGElasticEnum,G_elastic,M));
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));
160
161 /*free ressources: */
162 xDelete<IssmDouble>(love_h);
163 xDelete<IssmDouble>(love_k);
164 xDelete<IssmDouble>(love_l);
165 xDelete<IssmDouble>(G_elastic);
166 xDelete<IssmDouble>(G_elastic_local);
167 xDelete<IssmDouble>(U_elastic);
168 xDelete<IssmDouble>(U_elastic_local);
169 xDelete<IssmDouble>(H_elastic);
170 xDelete<IssmDouble>(H_elastic_local);
171 }
172
173 /*Transitions: */
174 iomodel->FetchData(&transitions,&transitions_M,&transitions_N,&ntransitions,"md.slr.transitions");
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);
183 xDelete<int>(transitions_M);
184 xDelete<int>(transitions_N);
185 }
186
187 /*Requested outputs*/
188 iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.slr.requested_outputs");
189 parameters->AddObject(new IntParam(SealevelriseNumRequestedOutputsEnum,numoutputs));
190 if(numoutputs)parameters->AddObject(new StringArrayParam(SealevelriseRequestedOutputsEnum,requestedoutputs,numoutputs));
191 iomodel->DeleteData(&requestedoutputs,numoutputs,"md.slr.requested_outputs");
192
193
194}/*}}}*/
195
196/*Finite Element Analysis*/
197void SealevelriseAnalysis::Core(FemModel* femmodel){/*{{{*/
198 _error_("not implemented");
199}/*}}}*/
200ElementVector* SealevelriseAnalysis::CreateDVector(Element* element){/*{{{*/
201 /*Default, return NULL*/
202 return NULL;
203}/*}}}*/
204ElementMatrix* SealevelriseAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
205_error_("Not implemented");
206}/*}}}*/
207ElementMatrix* SealevelriseAnalysis::CreateKMatrix(Element* element){/*{{{*/
208 _error_("not implemented yet");
209}/*}}}*/
210ElementVector* SealevelriseAnalysis::CreatePVector(Element* element){/*{{{*/
211_error_("not implemented yet");
212}/*}}}*/
213void SealevelriseAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
214 _error_("not implemented yet");
215}/*}}}*/
216void SealevelriseAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
217 _error_("Not implemented yet");
218}/*}}}*/
219void SealevelriseAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
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);
237 element->GetInputListOnVertices(S,SealevelEnum,0);
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: */
243 element->AddInput(SealevelEnum,S,P1Enum);
244
245 /*Free ressources:*/
246 xDelete<int>(sidlist);
247 xDelete<IssmDouble>(deltaS);
248 xDelete<IssmDouble>(S);
249
250}/*}}}*/
251void SealevelriseAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
252 /*Default, do nothing*/
253 return;
254}/*}}}*/
Note: See TracBrowser for help on using the repository browser.