-
Notifications
You must be signed in to change notification settings - Fork 4
/
GroundinglineMigrationx.cpp
184 lines (152 loc) · 6.98 KB
/
GroundinglineMigrationx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*!\file GroundinglineMigrationx
* \brief: migration grounding line position.
*/
#include "../../shared/shared.h"
#include "../../toolkits/toolkits.h"
#include "../../classes/classes.h"
#include "./GroundinglineMigrationx.h"
void GroundinglineMigrationx(Elements* elements,Nodes* nodes, Vertices* vertices,Loads* loads,Materials* materials, Parameters* parameters){
int migration_style;
IssmDouble *vertices_potentially_ungrounding = NULL;
IssmDouble *phi_ungrounding = NULL;
/*retrieve parameters: */
parameters->FindParam(&migration_style,GroundinglineMigrationEnum);
if(migration_style==NoneEnum) return;
if(VerboseModule()) _printf0_(" Migrating grounding line based on "<<EnumToStringx(migration_style)<<"\n");
switch(migration_style){
case SoftMigrationEnum:
ToolkitsOptionsFromAnalysis(parameters,DefaultAnalysisEnum);
/*Create flag for grounded vertices above the hydrostatic equilibrium: */
vertices_potentially_ungrounding=PotentialUngrounding(elements,vertices,parameters);
/*propagate ice shelf into connex areas of the ice sheet that potentially want to unground: */
phi_ungrounding=PropagateFloatingiceToGroundedNeighbors(elements,nodes,vertices,parameters,vertices_potentially_ungrounding);
break;
case ContactEnum:
ToolkitsOptionsFromAnalysis(parameters,DefaultAnalysisEnum);
phi_ungrounding=ContactFSLevelset(elements,vertices);
break;
case SubelementMigrationEnum:
case AggressiveMigrationEnum:
case GroundingOnlyEnum:
/*Nothing additional to do here, MigrateGroundingLine takes care of everything*/
break;
default:
_error_("Grounding line migration "<<EnumToStringx(migration_style) << " not supported yet!");
}
/*Migrate grounding line : */
for(Object* & object : elements->objects){
Element* element=xDynamicCast<Element*>(object);
element->MigrateGroundingLine(phi_ungrounding);
}
/*free ressouces: */
xDelete<IssmDouble>(vertices_potentially_ungrounding);
xDelete<IssmDouble>(phi_ungrounding);
}
IssmDouble* ContactFSLevelset(Elements* elements,Vertices* vertices){ /*{{{*/
Vector<IssmDouble>* vertex_sigmann = NULL;
Vector<IssmDouble>* vertex_waterpressure = NULL;
IssmDouble* serial_vertex_sigmann = NULL;
IssmDouble* serial_vertex_waterpressure = NULL;
IssmDouble* phi = NULL;
/*Initialize vector with number of vertices*/
int numberofvertices = vertices->NumberOfVertices();
vertex_sigmann = new Vector<IssmDouble>(numberofvertices);
vertex_waterpressure = new Vector<IssmDouble>(numberofvertices);
phi = xNew<IssmDouble>(numberofvertices);
/*Fill vector vertices_potentially_floating: */
for(Object* & object : elements->objects){
Element* element=xDynamicCast<Element*>(object);
element->FSContactMigration(vertex_sigmann,vertex_waterpressure);
}
/*Assemble vector and serialize */
vertex_sigmann->Assemble();
vertex_waterpressure->Assemble();
serial_vertex_sigmann=vertex_sigmann->ToMPISerial();
serial_vertex_waterpressure=vertex_waterpressure->ToMPISerial();
for(int i=0;i<numberofvertices;i++){
if (serial_vertex_waterpressure[i] > serial_vertex_sigmann[i]) phi[i]=-1;
else phi[i]=1;
}
/*free ressouces and return: */
delete vertex_sigmann;
delete vertex_waterpressure;
xDelete<IssmDouble>(serial_vertex_sigmann);
xDelete<IssmDouble>(serial_vertex_waterpressure);
return phi;
}
/*}}}*/
IssmDouble* PotentialUngrounding(Elements* elements,Vertices* vertices,Parameters* parameters){ /*{{{*/
int i,numberofvertices;
IssmDouble* vertices_potentially_ungrounding = NULL;
Vector<IssmDouble>* vec_vertices_potentially_ungrounding = NULL;
Element* element = NULL;
/*Initialize vector with number of vertices*/
numberofvertices=vertices->NumberOfVertices();
vec_vertices_potentially_ungrounding=new Vector<IssmDouble>(numberofvertices); //grounded vertex that could start floating
/*Fill vector vertices_potentially_floating: */
for(Object* & object : elements->objects){
element=xDynamicCast<Element*>(object);
element->PotentialUngrounding(vec_vertices_potentially_ungrounding);
}
/*Assemble vector and serialize */
vec_vertices_potentially_ungrounding->Assemble();
vertices_potentially_ungrounding=vec_vertices_potentially_ungrounding->ToMPISerial();
/*free ressouces and return: */
delete vec_vertices_potentially_ungrounding;
return vertices_potentially_ungrounding;
}
/*}}}*/
IssmDouble* PropagateFloatingiceToGroundedNeighbors(Elements* elements,Nodes* nodes,Vertices* vertices,Parameters* parameters,IssmDouble* vertices_potentially_ungrounding){ /*{{{*/
int i,analysis_type;
int nflipped,local_nflipped;
IssmDouble* phi = NULL;
IssmDouble* elements_neighboring_floatingce = NULL;
Vector<IssmDouble>* vec_elements_neighboring_floatingice = NULL;
Vector<IssmDouble>* vec_phi = NULL;
Element* element = NULL;
/*recover parameters: */
parameters->FindParam(&analysis_type,AnalysisTypeEnum);
/*recover vec_phi*/
vec_phi=new Vector<IssmDouble>(vertices->NumberOfVertices());
for(Object* & object : elements->objects){
Element* element=xDynamicCast<Element*>(object);
element->GetVectorFromInputs(vec_phi,MaskOceanLevelsetEnum,VertexPIdEnum);
}
vec_phi->Assemble();
phi=vec_phi->ToMPISerial();
nflipped=1; //bootstrap
while(nflipped){
/*Vector of size number of elements*/
vec_elements_neighboring_floatingice=new Vector<IssmDouble>(elements->NumberOfElements(),true);
/*Figure out if any of the nodes of the element will be floating -> elements neighbouting the floating ice*/
for(Object* & object : elements->objects){
element=xDynamicCast<Element*>(object);
vec_elements_neighboring_floatingice->SetValue(element->Sid(),element->IsNodeOnShelfFromFlags(phi)?1.0:0.0,INS_VAL);
}
/*Assemble vector and serialize: */
vec_elements_neighboring_floatingice->Assemble();
elements_neighboring_floatingce=vec_elements_neighboring_floatingice->ToMPISerial();
/*Go through elements_neighboring_floatingce, and update vector of the nodes that will start floating*/
local_nflipped=0;
for(Object* & object : elements->objects){
element=xDynamicCast<Element*>(object);
if(reCast<int,IssmDouble>(elements_neighboring_floatingce[element->Sid()])){
local_nflipped+=element->UpdatePotentialUngrounding(vertices_potentially_ungrounding,vec_phi,phi);
}
}
vec_phi->Assemble();
ISSM_MPI_Allreduce(&local_nflipped,&nflipped,1,ISSM_MPI_INT,ISSM_MPI_SUM,IssmComm::GetComm());
if(VerboseConvergence()) _printf0_(" Additional number of vertices allowed to unground: " << nflipped << "\n");
/*Avoid leaks: */
xDelete<IssmDouble>(elements_neighboring_floatingce);
xDelete<IssmDouble>(phi);
/*Assemble and serialize:*/
delete vec_elements_neighboring_floatingice;
phi=vec_phi->ToMPISerial();
}
/*Free resources:*/
delete vec_phi;
xDelete<IssmDouble>(elements_neighboring_floatingce);
return phi;
}
/*}}}*/