source: issm/trunk/src/c/modules/GroundinglineMigrationx/GroundinglineMigrationxUtils.cpp@ 10355

Last change on this file since 10355 was 10355, checked in by seroussi, 13 years ago

merged soft and agressive migration

File size: 9.1 KB
RevLine 
[10300]1/*!\file GroundinglineMigrationx
[7312]2 * \brief: migration grounding line position.
3 */
4
[10300]5#include "./GroundinglineMigrationx.h"
6#include "./GroundinglineMigrationxLocal.h"
[7312]7#include "../../shared/shared.h"
[9761]8#include "../../io/io.h"
[7312]9#include "../../include/include.h"
10#include "../../toolkits/toolkits.h"
11#include "../../EnumDefinitions/EnumDefinitions.h"
12
[9211]13/*FUNCTION PotentialSheetUngrounding {{{1*/
[10354]14double* PotentialSheetUngrounding(Elements* elements,Vertices* vertices,Parameters* parameters){
[7312]15
[10354]16 int i,numberofvertices;
17 double* vertices_potentially_ungrounding = NULL;
[10355]18 Vec vec_vertices_potentially_ungrounding = NULL;
[10354]19 Element* element = NULL;
[7312]20
[10354]21 /*Initialize vector with number of vertices*/
22 numberofvertices=vertices->NumberOfVertices();
23 vec_vertices_potentially_ungrounding=NewVec(numberofvertices); //grounded vertex that could start floating
[7323]24
[10354]25 /*Fill vector vertices_potentially_floating: */
[7323]26 for(i=0;i<elements->Size();i++){
27 element=(Element*)elements->GetObjectByOffset(i);
[10354]28 element->PotentialSheetUngrounding(vec_vertices_potentially_ungrounding);
[7323]29 }
30
31 /*Assemble vector: */
[10354]32 VecAssemblyBegin(vec_vertices_potentially_ungrounding);
33 VecAssemblyEnd(vec_vertices_potentially_ungrounding);
[7323]34
35 /*Serialize vector: */
[10354]36 VecToMPISerial(&vertices_potentially_ungrounding,vec_vertices_potentially_ungrounding);
[7323]37
[10354]38 /*free ressouces and return: */
39 VecFree(&vec_vertices_potentially_ungrounding);
40 return vertices_potentially_ungrounding;
[7323]41}
42/*}}}*/
[9211]43/*FUNCTION PropagateShelfIntoConnexIceSheet {{{1*/
44double* PropagateShelfIntoConnexIceSheet(Elements* elements,Nodes* nodes,Parameters* parameters,double* potential_sheet_ungrounding){
[7323]45
[7312]46 int i;
[7323]47 Element* element=NULL;
48 int numnods;
49 int analysis_type;
50 Vec vec_nodes_on_iceshelf=NULL;
51 double* nodes_on_iceshelf=NULL;
52 int nflipped,local_nflipped;
53 double* elements_touching_iceshelf=NULL;
54
55 /*recover parameters: */
56 parameters->FindParam(&analysis_type,AnalysisTypeEnum);
57
58 /*recover vec_nodes_on_iceshelf: */
59 vec_nodes_on_iceshelf=CreateNodesOnIceShelf(nodes,analysis_type);
60
61 nflipped=1; //bootstrap
62 while(nflipped){
63
64 /*get a list of potential elements that have nodes on ice shelf: */
65 elements_touching_iceshelf=CreateElementTouchingIceShelf(elements,vec_nodes_on_iceshelf);
66
67 /*now, go through elements_touching_iceshelf, and if they have nodes inside potential_sheet_ungrounding,
68 * flag it: */
69 local_nflipped=0;
70
71 /*serialize vec_nodes_on_iceshelf, needed by element's UpdatePotentialSheetUngrounding routine, to figure out if
72 * nodes have flipped from grounded to ungrounded: */
73 VecToMPISerial(&nodes_on_iceshelf,vec_nodes_on_iceshelf);
[7333]74
[7323]75 for(i=0;i<elements->Size();i++){
76 element=(Element*)elements->GetObjectByOffset(i);
77 if(elements_touching_iceshelf[element->Sid()]){
[7333]78 local_nflipped+=element->UpdatePotentialSheetUngrounding(potential_sheet_ungrounding,vec_nodes_on_iceshelf,nodes_on_iceshelf);
[7323]79 }
80 }
81
82 MPI_Allreduce(&local_nflipped,&nflipped,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
[7333]83 _printf_(VerboseConvergence()," number of grounded vertices connected to grounding line: %i\n",nflipped);
[7323]84
85 /*Avoid leaks: */
86 xfree((void**)&nodes_on_iceshelf);
[7340]87 xfree((void**)&elements_touching_iceshelf);
[7333]88
89 /*Assemble:*/
90 VecAssemblyBegin(vec_nodes_on_iceshelf);
91 VecAssemblyEnd(vec_nodes_on_iceshelf);
[7323]92 }
93
94 /*Serialize: */
95 VecToMPISerial(&nodes_on_iceshelf,vec_nodes_on_iceshelf);
96
97 /*Free ressources:*/
98 VecFree(&vec_nodes_on_iceshelf);
99 xfree((void**)&elements_touching_iceshelf);
100
101 return nodes_on_iceshelf;
102}
103/*}}}*/
[10309]104/*FUNCTION CreateElementOnGroundingline {{{1*/
[10300]105bool* CreateElementOnGroundingline(Elements* elements,double* element_on_iceshelf){
[7323]106
[10309]107 int i,j;
[7312]108 Element *element = NULL;
109 bool *element_on_gl = NULL;
110 bool ongl=false;
111 int *neighboorsids = NULL;
112 int sid;
113 int shelf;
114
115 /*Go through elements, and look for elements that can possibly have a grounding line migration. These
116 * are elements that touch the grounding line: */
117 element_on_gl=(bool*)xmalloc(elements->Size()*sizeof(bool));
118
119 for(i=0;i<elements->Size();i++){
120 element=(Element*)elements->GetObjectByOffset(i);
121
122 sid=element->Sid();
123 neighboorsids=element->GetHorizontalNeighboorSids();
124
125 shelf=(int)element_on_iceshelf[sid];
126 ongl=false;
127 for(j=0;j<3;j++){
128 if (neighboorsids[j]<0)continue; //this neighboor does not exist
129 if ((shelf==1) & (element_on_iceshelf[neighboorsids[j]]==1))continue; //both this element and this neighboor are on th ice shelf
130 if ((shelf==0) & (element_on_iceshelf[neighboorsids[j]]==0))continue; //both this element and this neighboor are on the ice sheet
131 ongl=true; //neighboor j is on a different location than us, ie we are touching the grounding line.
132 }
133 element_on_gl[i]=ongl;
134 }
135
136 return element_on_gl;
137}
[7323]138/*}}}*/
[9211]139/*FUNCTION CreateElementOnIceShelf {{{1*/
140double* CreateElementOnIceShelf(Elements* elements){
[7312]141
142 int i;
143 Element* element=NULL;
144 Vec vec_element_on_iceshelf=NULL;
145 double* element_on_iceshelf=NULL;
146
[10143]147 /*Create vector holding all the elements IsFloating flags: */
[7312]148 vec_element_on_iceshelf=NewVec(elements->NumberOfElements(),true);
149
150 /*Loop through elements, and fill vec_element_on_iceshelf: */
151 for(i=0;i<elements->Size();i++){
152 element=(Element*)elements->GetObjectByOffset(i);
[10143]153 VecSetValue(vec_element_on_iceshelf,element->Sid(),(int)element->IsFloating(),INSERT_VALUES);
[7312]154 }
155
156 /*Assemble vector: */
157 VecAssemblyBegin(vec_element_on_iceshelf);
158 VecAssemblyEnd(vec_element_on_iceshelf);
159
160 /*Serialize vector: */
161 VecToMPISerial(&element_on_iceshelf,vec_element_on_iceshelf);
162
163 /*free ressouces: */
164 VecFree(&vec_element_on_iceshelf);
165
166 return element_on_iceshelf;
167}
[7323]168/*}}}*/
[9211]169/*FUNCTION CreateElementTouchingIceShelf {{{1*/
170double* CreateElementTouchingIceShelf(Elements* elements,Vec vec_nodes_on_iceshelf){
[7312]171
172 int i;
173 Element* element=NULL;
174 Vec vec_element_touching_iceshelf=NULL;
[7340]175 double* nodes_on_iceshelf=NULL;
176
177 /*output: */
[7312]178 double* element_touching_iceshelf=NULL;
179
[7323]180 /*serialize: */
181 VecToMPISerial(&nodes_on_iceshelf,vec_nodes_on_iceshelf);
182
[10143]183 /*Create vector holding all the elements IsFloating flags: */
[7312]184 vec_element_touching_iceshelf=NewVec(elements->NumberOfElements(),true);
185
186 /*Loop through elements, and fill vec_element_touching_iceshelf: */
187 for(i=0;i<elements->Size();i++){
188 element=(Element*)elements->GetObjectByOffset(i);
[7323]189 VecSetValue(vec_element_touching_iceshelf,element->Sid(),element->IsNodeOnShelfFromFlags(nodes_on_iceshelf)?1.0:0.0,INSERT_VALUES);
[7312]190 }
191
192 /*Assemble vector: */
193 VecAssemblyBegin(vec_element_touching_iceshelf);
194 VecAssemblyEnd(vec_element_touching_iceshelf);
195
196 /*Serialize vector: */
197 VecToMPISerial(&element_touching_iceshelf,vec_element_touching_iceshelf);
198
199 /*free ressouces: */
200 VecFree(&vec_element_touching_iceshelf);
[7323]201 xfree((void**)&nodes_on_iceshelf);
[7312]202
203 return element_touching_iceshelf;
204}
[7323]205/*}}}*/
[9211]206/*FUNCTION UpdateShelfStatus {{{1*/
207int UpdateShelfStatus(Elements* elements,Nodes* nodes,Parameters* parameters,double* element_touching_iceshelf){
[7312]208
209 int i;
210 Element* element=NULL;
[8816]211 int configuration_type;
[7312]212 int numnods;
213 Vec vec_new_shelf_nodes=NULL;
214 double* new_shelf_nodes=NULL;
215
216 /*output: */
217 int local_nflipped=0;
218 int nflipped=0;
219
220 /*recover parameters: */
[8816]221 parameters->FindParam(&configuration_type,ConfigurationTypeEnum);
[7312]222
223 /*First, initialize vec_new_shelf_nodes, which will track which nodes have changed status: */
[8816]224 numnods=nodes->NumberOfNodes(configuration_type);
[7312]225 vec_new_shelf_nodes=NewVec(numnods);
226
227 /*Ok, now go through the elements that have gone through grounding line migration,
228 * and update their flags: */
229 for(i=0;i<elements->Size();i++){
230 element=(Element*)elements->GetObjectByOffset(i);
231 if(element_touching_iceshelf[element->Sid()]){
232 local_nflipped+=element->UpdateShelfStatus(vec_new_shelf_nodes);
233 }
234 }
235 MPI_Allreduce(&local_nflipped,&nflipped,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
236
237 /*Serialize vec_new_shelf_nodes: */
238 VecToMPISerial(&new_shelf_nodes,vec_new_shelf_nodes);
239
240 /*Now, go through ALL elements, and update the status of the nodes, to propagate what happened at the grounding line: */
241 /*Carry out grounding line migration for those elements: */
242 for(i=0;i<elements->Size();i++){
243 element=(Element*)elements->GetObjectByOffset(i);
244 element->UpdateShelfFlags(new_shelf_nodes);
245 }
246
247 /*Free ressources: */
248 VecFree(&vec_new_shelf_nodes);
249 xfree((void**)&new_shelf_nodes);
250
251 return nflipped;
252}
[7323]253/*}}}*/
[9211]254/*FUNCTION CreateNodesOnIceShelf {{{1*/
255Vec CreateNodesOnIceShelf(Nodes* nodes,int configuration_type){
[7312]256
[7323]257 /*output: */
258 Vec nodes_on_iceshelf=NULL;
[7312]259
[7323]260 /*intermediary: */
261 int numnods;
262 int i;
263 Node* node=NULL;
[7312]264
[7323]265 /*First, initialize nodes_on_iceshelf, which will track which nodes have changed status: */
[8816]266 numnods=nodes->NumberOfNodes(configuration_type);
[7323]267 nodes_on_iceshelf=NewVec(numnods);
[7312]268
[7323]269 /*Loop through nodes, and fill nodes_on_iceshelf: */
270 for(i=0;i<nodes->Size();i++){
271 node=(Node*)nodes->GetObjectByOffset(i);
[8816]272 if(node->InAnalysis(configuration_type)){
[10143]273 if(node->IsFloating()){
[7333]274 VecSetValue(nodes_on_iceshelf,node->Sid(),1.0,INSERT_VALUES);
275 }
276 }
[7323]277 }
[7312]278
[7323]279 /*Assemble vector: */
280 VecAssemblyBegin(nodes_on_iceshelf);
281 VecAssemblyEnd(nodes_on_iceshelf);
[7312]282
[7323]283 return nodes_on_iceshelf;
[7312]284}
[7323]285/*}}}*/
Note: See TracBrowser for help on using the repository browser.