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: */
|
---|
33 | iomodel->FetchDataToInput(elements,MaskIceLevelsetEnum);
|
---|
34 | iomodel->FetchDataToInput(elements,MaskOceanLevelsetEnum);
|
---|
35 | iomodel->FetchDataToInput(elements,MaskLandLevelsetEnum);
|
---|
36 | iomodel->FetchDataToInput(elements,SealevelriseDeltathicknessEnum);
|
---|
37 |
|
---|
38 | }/*}}}*/
|
---|
39 | void SealevelriseAnalysis::UpdateParameters(Parameters* parameters,IoModel* iomodel,int solution_enum,int analysis_enum){/*{{{*/
|
---|
40 |
|
---|
41 | int nl;
|
---|
42 | IssmDouble* love_h=NULL;
|
---|
43 | IssmDouble* love_k=NULL;
|
---|
44 |
|
---|
45 | bool elastic=false;
|
---|
46 | IssmDouble* G_elastic = NULL;
|
---|
47 | IssmDouble* G_elastic_local = NULL;
|
---|
48 | int M,m,lower_row,upper_row;
|
---|
49 | IssmDouble degacc=.01;
|
---|
50 |
|
---|
51 | int numoutputs;
|
---|
52 | char** requestedoutputs = NULL;
|
---|
53 |
|
---|
54 | /*some constant parameters: */
|
---|
55 | parameters->AddObject(iomodel->CopyConstantObject(SealevelriseReltolEnum));
|
---|
56 | parameters->AddObject(iomodel->CopyConstantObject(SealevelriseAbstolEnum));
|
---|
57 | parameters->AddObject(iomodel->CopyConstantObject(SealevelriseMaxiterEnum));
|
---|
58 | parameters->AddObject(iomodel->CopyConstantObject(SealevelriseRigidEnum));
|
---|
59 | parameters->AddObject(iomodel->CopyConstantObject(SealevelriseElasticEnum));
|
---|
60 | parameters->AddObject(iomodel->CopyConstantObject(SealevelriseEustaticEnum));
|
---|
61 |
|
---|
62 | iomodel->FetchData(&elastic,SealevelriseElasticEnum);
|
---|
63 | if(elastic){
|
---|
64 |
|
---|
65 | /*love numbers: */
|
---|
66 | iomodel->FetchData(&love_h,&nl,NULL,SealevelriseLoveHEnum);
|
---|
67 | iomodel->FetchData(&love_k,&nl,NULL,SealevelriseLoveKEnum);
|
---|
68 |
|
---|
69 | /*compute elastic green function for a range of angles*/
|
---|
70 | iomodel->FetchData(°acc,SealevelriseDegaccEnum);
|
---|
71 | M=reCast<int,IssmDouble>(180./degacc+1.);
|
---|
72 | G_elastic=xNew<IssmDouble>(M);
|
---|
73 |
|
---|
74 | /*compute combined legendre + love number (elastic green function:*/
|
---|
75 | m=DetermineLocalSize(M,IssmComm::GetComm());
|
---|
76 | GetOwnershipBoundariesFromRange(&lower_row,&upper_row,m,IssmComm::GetComm());
|
---|
77 | G_elastic_local=xNew<IssmDouble>(m);
|
---|
78 |
|
---|
79 | for(int i=lower_row;i<upper_row;i++){
|
---|
80 | IssmDouble alpha,x;
|
---|
81 | alpha= reCast<IssmDouble>(i)*degacc * PI / 180.0;
|
---|
82 |
|
---|
83 | G_elastic_local[i-lower_row]= (love_k[nl-1]-love_h[nl-1])/2.0/sin(alpha/2.0);
|
---|
84 | for (int n=0;n<nl;n++) {
|
---|
85 | IssmDouble Pn,Pn1,Pn2;
|
---|
86 | IssmDouble deltalove;
|
---|
87 |
|
---|
88 | deltalove = (love_k[n]-love_k[nl-1]-love_h[n]+love_h[nl-1]);
|
---|
89 |
|
---|
90 | if(n==0)Pn=1;
|
---|
91 | else if(n==1)Pn=cos(alpha);
|
---|
92 | else Pn= ( (2*n-1)*cos(alpha)*Pn1 - (n-1)*Pn2 ) /n;
|
---|
93 | Pn2=Pn1; Pn1=Pn;
|
---|
94 |
|
---|
95 | G_elastic_local[i-lower_row] += deltalove*Pn;
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | /*merge G_elastic_local into G_elastic:{{{*/
|
---|
100 | int* recvcounts=xNew<int>(IssmComm::GetSize());
|
---|
101 | int* displs=xNew<int>(IssmComm::GetSize());
|
---|
102 |
|
---|
103 | //recvcounts:
|
---|
104 | ISSM_MPI_Allgather(&m,1,ISSM_MPI_INT,recvcounts,1,ISSM_MPI_INT,IssmComm::GetComm());
|
---|
105 |
|
---|
106 | /*displs: */
|
---|
107 | ISSM_MPI_Allgather(&lower_row,1,ISSM_MPI_INT,displs,1,ISSM_MPI_INT,IssmComm::GetComm());
|
---|
108 |
|
---|
109 | /*All gather:*/
|
---|
110 | ISSM_MPI_Allgatherv(G_elastic_local, m, ISSM_MPI_DOUBLE, G_elastic, recvcounts, displs, ISSM_MPI_DOUBLE,IssmComm::GetComm());
|
---|
111 | /*free ressources: */
|
---|
112 | xDelete<int>(recvcounts);
|
---|
113 | xDelete<int>(displs);
|
---|
114 |
|
---|
115 | /*}}}*/
|
---|
116 |
|
---|
117 | /*Old code: {{{*/
|
---|
118 | /*for(int i=0;i<M;i++){
|
---|
119 | IssmDouble alpha,x;
|
---|
120 | alpha= reCast<IssmDouble>(i)*degacc * PI / 180.0;
|
---|
121 |
|
---|
122 | G_elastic[i]= (love_k[nl-1]-love_h[nl-1])/2.0/sin(alpha/2.0);
|
---|
123 | for (int n=0;n<nl;n++) {
|
---|
124 | IssmDouble Pn,Pn1,Pn2;
|
---|
125 | IssmDouble deltalove;
|
---|
126 |
|
---|
127 | deltalove = (love_k[n]-love_k[nl-1]-love_h[n]+love_h[nl-1]);
|
---|
128 |
|
---|
129 | if(n==0)Pn=1;
|
---|
130 | else if(n==1)Pn=cos(alpha);
|
---|
131 | else Pn= ( (2*n-1)*cos(alpha)*Pn1 - (n-1)*Pn2 ) /n;
|
---|
132 | Pn2=Pn1; Pn1=Pn;
|
---|
133 |
|
---|
134 | G_elastic[i] += deltalove*Pn;
|
---|
135 | }
|
---|
136 | }*/
|
---|
137 | /*}}}*/
|
---|
138 |
|
---|
139 | /*Avoid singularity at 0: */
|
---|
140 | G_elastic[0]=G_elastic[1];
|
---|
141 | parameters->AddObject(new DoubleVecParam(SealevelriseGElasticEnum,G_elastic,M));
|
---|
142 |
|
---|
143 | /*free ressources: */
|
---|
144 | xDelete<IssmDouble>(love_h);
|
---|
145 | xDelete<IssmDouble>(love_k);
|
---|
146 | xDelete<IssmDouble>(G_elastic);
|
---|
147 | xDelete<IssmDouble>(G_elastic_local);
|
---|
148 | }
|
---|
149 |
|
---|
150 | /*Requested outputs*/
|
---|
151 | iomodel->FetchData(&requestedoutputs,&numoutputs,SealevelriseRequestedOutputsEnum);
|
---|
152 | parameters->AddObject(new IntParam(SealevelriseNumRequestedOutputsEnum,numoutputs));
|
---|
153 | if(numoutputs)parameters->AddObject(new StringArrayParam(SealevelriseRequestedOutputsEnum,requestedoutputs,numoutputs));
|
---|
154 | iomodel->DeleteData(&requestedoutputs,numoutputs,SealevelriseRequestedOutputsEnum);
|
---|
155 |
|
---|
156 |
|
---|
157 | }/*}}}*/
|
---|
158 |
|
---|
159 | /*Finite Element Analysis*/
|
---|
160 | void SealevelriseAnalysis::Core(FemModel* femmodel){/*{{{*/
|
---|
161 | _error_("not implemented");
|
---|
162 | }/*}}}*/
|
---|
163 | ElementVector* SealevelriseAnalysis::CreateDVector(Element* element){/*{{{*/
|
---|
164 | /*Default, return NULL*/
|
---|
165 | return NULL;
|
---|
166 | }/*}}}*/
|
---|
167 | ElementMatrix* SealevelriseAnalysis::CreateJacobianMatrix(Element* element){/*{{{*/
|
---|
168 | _error_("Not implemented");
|
---|
169 | }/*}}}*/
|
---|
170 | ElementMatrix* SealevelriseAnalysis::CreateKMatrix(Element* element){/*{{{*/
|
---|
171 | _error_("not implemented yet");
|
---|
172 | }/*}}}*/
|
---|
173 | ElementVector* SealevelriseAnalysis::CreatePVector(Element* element){/*{{{*/
|
---|
174 | _error_("not implemented yet");
|
---|
175 | }/*}}}*/
|
---|
176 | void SealevelriseAnalysis::GetSolutionFromInputs(Vector<IssmDouble>* solution,Element* element){/*{{{*/
|
---|
177 | _error_("not implemented yet");
|
---|
178 | }/*}}}*/
|
---|
179 | void SealevelriseAnalysis::GradientJ(Vector<IssmDouble>* gradient,Element* element,int control_type,int control_index){/*{{{*/
|
---|
180 | _error_("Not implemented yet");
|
---|
181 | }/*}}}*/
|
---|
182 | void SealevelriseAnalysis::InputUpdateFromSolution(IssmDouble* solution,Element* element){/*{{{*/
|
---|
183 | _error_("not implemented yet");
|
---|
184 | }/*}}}*/
|
---|
185 | void SealevelriseAnalysis::UpdateConstraints(FemModel* femmodel){/*{{{*/
|
---|
186 | /*Default, do nothing*/
|
---|
187 | return;
|
---|
188 | }/*}}}*/
|
---|