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

Last change on this file since 21295 was 21295, checked in by adhikari, 8 years ago

CHG: ocean_area_scaling option added to capture true eustatic rate

File size: 9.1 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 parameters->AddObject(iomodel->CopyConstantObject("md.slr.ocean_area_scaling",SealevelriseOceanAreaScalingEnum));
73
74 iomodel->FetchData(&elastic,"md.slr.elastic");
75 if(elastic){
76
77 /*love numbers: */
78 iomodel->FetchData(&love_h,&nl,NULL,"md.slr.love_h");
79 iomodel->FetchData(&love_k,&nl,NULL,"md.slr.love_k");
80 iomodel->FetchData(&love_l,&nl,NULL,"md.slr.love_l");
81
82 /*compute elastic green function for a range of angles*/
83 iomodel->FetchData(&degacc,"md.slr.degacc");
84 M=reCast<int,IssmDouble>(180./degacc+1.);
85 G_elastic=xNew<IssmDouble>(M);
86 U_elastic=xNew<IssmDouble>(M);
87 H_elastic=xNew<IssmDouble>(M);
88
89 /*compute combined legendre + love number (elastic green function:*/
90 m=DetermineLocalSize(M,IssmComm::GetComm());
91 GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,IssmComm::GetComm());
92 G_elastic_local=xNew<IssmDouble>(m);
93 U_elastic_local=xNew<IssmDouble>(m);
94 H_elastic_local=xNew<IssmDouble>(m);
95
96 for(int i=lower_row;i<upper_row;i++){
97 IssmDouble alpha,x;
98 alpha= reCast<IssmDouble>(i)*degacc * PI / 180.0;
99
100 G_elastic_local[i-lower_row]= (love_k[nl-1]-love_h[nl-1])/2.0/sin(alpha/2.0);
101 U_elastic_local[i-lower_row]= (love_h[nl-1])/2.0/sin(alpha/2.0);
102 H_elastic_local[i-lower_row]= 0;
103 IssmDouble Pn,Pn1,Pn2;
104 IssmDouble Pn_p,Pn_p1,Pn_p2;
105 for (int n=0;n<nl;n++) {
106 IssmDouble deltalove_G;
107 IssmDouble deltalove_U;
108
109 deltalove_G = (love_k[n]-love_k[nl-1]-love_h[n]+love_h[nl-1]);
110 deltalove_U = (love_h[n]-love_h[nl-1]);
111
112 /*compute legendre polynomials: P_n(cos\theta) & d P_n(cos\theta)/ d\theta: */
113 if(n==0){
114 Pn=1;
115 Pn_p=0;
116 }
117 else if(n==1){
118 Pn = cos(alpha);
119 Pn_p = 1;
120 }
121 else{
122 Pn = ( (2*n-1)*cos(alpha)*Pn1 - (n-1)*Pn2 ) /n;
123 Pn_p = ( (2*n-1)*(Pn1+cos(alpha)*Pn_p1) - (n-1)*Pn_p2 ) /n;
124 }
125 Pn2=Pn1; Pn1=Pn;
126 Pn_p2=Pn_p1; Pn_p1=Pn_p;
127
128 G_elastic_local[i-lower_row] += deltalove_G*Pn; // gravitational potential
129 U_elastic_local[i-lower_row] += deltalove_U*Pn; // vertical (up) displacement
130 H_elastic_local[i-lower_row] += sin(alpha)*love_l[n]*Pn_p; // horizontal displacements
131 }
132 }
133
134 /*merge G_elastic_local into G_elastic; U_elastic_local into U_elastic; H_elastic_local to H_elastic:{{{*/
135 int* recvcounts=xNew<int>(IssmComm::GetSize());
136 int* displs=xNew<int>(IssmComm::GetSize());
137
138 //recvcounts:
139 ISSM_MPI_Allgather(&m,1,ISSM_MPI_INT,recvcounts,1,ISSM_MPI_INT,IssmComm::GetComm());
140
141 /*displs: */
142 ISSM_MPI_Allgather(&lower_row,1,ISSM_MPI_INT,displs,1,ISSM_MPI_INT,IssmComm::GetComm());
143
144 /*All gather:*/
145 ISSM_MPI_Allgatherv(G_elastic_local, m, ISSM_MPI_DOUBLE, G_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
146 ISSM_MPI_Allgatherv(U_elastic_local, m, ISSM_MPI_DOUBLE, U_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
147 ISSM_MPI_Allgatherv(H_elastic_local, m, ISSM_MPI_DOUBLE, H_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
148 /*free ressources: */
149 xDelete<int>(recvcounts);
150 xDelete<int>(displs);
151
152 /*}}}*/
153
154 /*Avoid singularity at 0: */
155 G_elastic[0]=G_elastic[1];
156 parameters->AddObject(new DoubleVecParam(SealevelriseGElasticEnum,G_elastic,M));
157 U_elastic[0]=U_elastic[1];
158 parameters->AddObject(new DoubleVecParam(SealevelriseUElasticEnum,U_elastic,M));
159 H_elastic[0]=H_elastic[1];
160 parameters->AddObject(new DoubleVecParam(SealevelriseHElasticEnum,H_elastic,M));
161
162 /*free ressources: */
163 xDelete<IssmDouble>(love_h);
164 xDelete<IssmDouble>(love_k);
165 xDelete<IssmDouble>(love_l);
166 xDelete<IssmDouble>(G_elastic);
167 xDelete<IssmDouble>(G_elastic_local);
168 xDelete<IssmDouble>(U_elastic);
169 xDelete<IssmDouble>(U_elastic_local);
170 xDelete<IssmDouble>(H_elastic);
171 xDelete<IssmDouble>(H_elastic_local);
172 }
173
174 /*Transitions: */
175 iomodel->FetchData(&transitions,&transitions_M,&transitions_N,&ntransitions,"md.slr.transitions");
176 if(transitions){
177 parameters->AddObject(new DoubleMatArrayParam(SealevelriseTransitionsEnum,transitions,ntransitions,transitions_M,transitions_N));
178
179 for(int i=0;i<ntransitions;i++){
180 IssmDouble* transition=transitions[i];
181 xDelete<IssmDouble>(transition);
182 }
183 xDelete<IssmDouble*>(transitions);
184 xDelete<int>(transitions_M);
185 xDelete<int>(transitions_N);
186 }
187
188 /*Requested outputs*/
189 iomodel->FindConstant(&requestedoutputs,&numoutputs,"md.slr.requested_outputs");
190 parameters->AddObject(new IntParam(SealevelriseNumRequestedOutputsEnum,numoutputs));
191 if(numoutputs)parameters->AddObject(new StringArrayParam(SealevelriseRequestedOutputsEnum,requestedoutputs,numoutputs));
192 iomodel->DeleteData(&requestedoutputs,numoutputs,"md.slr.requested_outputs");
193
194
195}/*}}}*/
196
197/*Finite Element Analysis*/
198void SealevelriseAnalysis::Core(FemModel* femmodel){/*{{{*/
199 _error_("not implemented");
200}/*}}}*/
201ElementVector* SealevelriseAnalysis::CreateDVector(Element* element){/*{{{*/
202 /*Default, return NULL*/
203 return NULL;
204}/*}}}*/
205ElementMatrix* SealevelriseAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
206_error_("Not implemented");
207}/*}}}*/
208ElementMatrix* SealevelriseAnalysis::CreateKMatrix(Element* element){/*{{{*/
209 _error_("not implemented yet");
210}/*}}}*/
211ElementVector* SealevelriseAnalysis::CreatePVector(Element* element){/*{{{*/
212_error_("not implemented yet");
213}/*}}}*/
214void SealevelriseAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
215 _error_("not implemented yet");
216}/*}}}*/
217void SealevelriseAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
218 _error_("Not implemented yet");
219}/*}}}*/
220void SealevelriseAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
221
222 IssmDouble *deltaS = NULL;
223 IssmDouble *S = NULL;
224 int* sidlist = NULL;
225 int numvertices;
226
227 numvertices= element->GetNumberOfVertices();
228 sidlist=xNew<int>(numvertices);
229
230 element->GetVerticesSidList(sidlist);
231
232 deltaS = xNew<IssmDouble>(numvertices);
233 for(int i=0;i<numvertices;i++){
234 deltaS[i]=solution[sidlist[i]];
235 }
236
237 S = xNew<IssmDouble>(numvertices);
238 element->GetInputListOnVertices(S,SealevelEnum,0);
239
240 /*Add deltaS to S:*/
241 for (int i=0;i<numvertices;i++)S[i]+=deltaS[i];
242
243 /*Add S back into inputs: */
244 element->AddInput(SealevelEnum,S,P1Enum);
245
246 /*Free ressources:*/
247 xDelete<int>(sidlist);
248 xDelete<IssmDouble>(deltaS);
249 xDelete<IssmDouble>(S);
250
251}/*}}}*/
252void SealevelriseAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
253 /*Default, do nothing*/
254 return;
255}/*}}}*/
Note: See TracBrowser for help on using the repository browser.