Ice Sheet System Model  4.18
Code documentation
Moulin.cpp
Go to the documentation of this file.
1 
5 /*Headers*/
6 /*{{{*/
7 #ifdef HAVE_CONFIG_H
8  #include <config.h>
9 #else
10 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11 #endif
12 
13 #include "../classes.h"
14 #include "shared/shared.h"
15 #include "../../analyses/analyses.h"
16 /*}}}*/
17 
18 /*Element macros*/
19 #define NUMVERTICES 1
20 
21 /*Moulin constructors and destructor*/
22 Moulin::Moulin(){/*{{{*/
23  this->parameters=NULL;
24  this->hnode=NULL;
25  this->hvertex=NULL;
26  this->node=NULL;
27  this->helement=NULL;
28  this->element=NULL;
29 }
30 /*}}}*/
31 Moulin::Moulin(int id, int index, IoModel* iomodel){ /*{{{*/
32 
33  int pengrid_node_id;
34  int pengrid_element_id;
35 
36  /*Some checks if debugging activated*/
38  _assert_(index>=0 && index<iomodel->numberofvertices);
39  _assert_(id);
40 
41  /*id: */
42  this->id=id;
43 
44  /*hooks: */
45  pengrid_node_id=index+1;
46  pengrid_element_id=iomodel->singlenodetoelementconnectivity[index];
47  _assert_(pengrid_element_id);
48 
49  this->hnode=new Hook(&pengrid_node_id,1);
50  this->hvertex=new Hook(&pengrid_node_id,1);
51  this->helement=new Hook(&pengrid_element_id,1);
52 
53  //this->parameters: we still can't point to it, it may not even exist. Configure will handle this.
54  this->parameters=NULL;
55  this->node=NULL;
56  this->vertex=NULL;
57  this->element=NULL;
58 }
59 /*}}}*/
60 Moulin::~Moulin(){/*{{{*/
61  delete hnode;
62  delete hvertex;
63  delete helement;
64  return;
65 }
66 /*}}}*/
67 
68 /*Object virtual functions definitions:*/
69 Object* Moulin::copy() {/*{{{*/
70 
71  Moulin* pengrid=NULL;
72 
73  pengrid=new Moulin();
74 
75  /*copy fields: */
76  pengrid->id=this->id;
77 
78  /*point parameters: */
79  pengrid->parameters=this->parameters;
80 
81  /*now deal with hooks and objects: */
82  pengrid->hnode=(Hook*)this->hnode->copy();
83  pengrid->hvertex=(Hook*)this->hvertex->copy();
84  pengrid->helement=(Hook*)this->helement->copy();
85 
86  /*corresponding fields*/
87  pengrid->node =(Node*)pengrid->hnode->delivers();
88  pengrid->vertex=(Vertex*)pengrid->hvertex->delivers();
89  pengrid->element=(Element*)pengrid->helement->delivers();
90 
91  return pengrid;
92 }
93 /*}}}*/
94 void Moulin::DeepEcho(void){/*{{{*/
95 
96  _printf_("Moulin:\n");
97  _printf_(" id: " << id << "\n");
98  hnode->DeepEcho();
99  hvertex->DeepEcho();
100  helement->DeepEcho();
101  _printf_(" parameters\n");
102  parameters->DeepEcho();
103 }
104 /*}}}*/
105 void Moulin::Echo(void){/*{{{*/
106  this->DeepEcho();
107 }
108 /*}}}*/
109 int Moulin::Id(void){ return id; }/*{{{*/
110 /*}}}*/
111 void Moulin::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
112 
113  _assert_(this);
114 
115  /*ok, marshall operations: */
117  MARSHALLING(id);
118 
119  if(marshall_direction==MARSHALLING_BACKWARD){
120  this->hnode = new Hook();
121  this->hvertex = new Hook();
122  this->helement = new Hook();
123  }
124 
125  this->hnode->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
126  this->hvertex->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
127  this->helement->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
128 
129  /*corresponding fields*/
130  node =(Node*)this->hnode->delivers();
131  vertex =(Vertex*)this->hvertex->delivers();
132  element=(Element*)this->helement->delivers();
133 }
134 /*}}}*/
135 int Moulin::ObjectEnum(void){/*{{{*/
136 
137  return MoulinEnum;
138 }
139 /*}}}*/
140 
141 /*Load virtual functions definitions:*/
142 void Moulin::Configure(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){/*{{{*/
143 
144  /*Take care of hooking up all objects for this load, ie links the objects in the hooks to their respective
145  * datasets, using internal ids and offsets hidden in hooks: */
146  hnode->configure(nodesin);
147  hvertex->configure(verticesin);
148  helement->configure(elementsin);
149 
150  /*Get corresponding fields*/
151  node=(Node*)hnode->delivers();
154 
155  /*point parameters to real dataset: */
156  this->parameters=parametersin;
157 }
158 /*}}}*/
160 
161  /*recover some parameters*/
162  ElementMatrix* Ke=NULL;
163  int analysis_type;
164  this->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
165 
166  switch(analysis_type){
168  Ke = this->CreateKMatrixHydrologyGlaDS();
169  break;
171  /*do nothing: */
172  return;
174  /*do nothing: */
175  return;
177  /*do nothing: */
178  return;
179  default:
180  _error_("Don't know why we should be here");
181 
182  }
183  /*Add to global matrix*/
184  if(Ke){
185  Ke->AddToGlobal(Kff,Kfs);
186  delete Ke;
187  }
188 
189 }
190 /*}}}*/
192 
193  ElementVector* pe=NULL;
194  int analysis_type;
195  this->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
196 
197  switch(analysis_type){
199  pe = this->CreatePVectorHydrologyGlaDS();
200  break;
202  pe = this->CreatePVectorHydrologyShakti();
203  break;
206  break;
209  break;
210  default:
211  _error_("Don't know why we should be here");
212  /*No loads applied, do nothing: */
213  return;
214  }
215  if(pe){
216  pe->AddToGlobal(pf);
217  delete pe;
218  }
219 
220 }
221 /*}}}*/
222 void Moulin::GetNodesLidList(int* lidlist){/*{{{*/
223 
224  _assert_(lidlist);
225  _assert_(node);
226 
227  lidlist[0]=node->Lid();
228 }
229 /*}}}*/
230 void Moulin::GetNodesSidList(int* sidlist){/*{{{*/
231 
232  _assert_(sidlist);
233  _assert_(node);
234 
235  sidlist[0]=node->Sid();
236 }
237 /*}}}*/
238 int Moulin::GetNumberOfNodes(void){/*{{{*/
239 
240  return NUMVERTICES;
241 }
242 /*}}}*/
243 bool Moulin::IsPenalty(void){/*{{{*/
244  return false;
245 }
246 /*}}}*/
248 
249  /*Don't do anything for now*/
250 
251 }
252 /*}}}*/
254 
255  /*Don't do anything for now*/
256 }
257 /*}}}*/
258 void Moulin::ResetHooks(){/*{{{*/
259 
260  this->node=NULL;
261  this->element=NULL;
262  this->parameters=NULL;
263 
264  /*Get Element type*/
265  this->hnode->reset();
266  this->hvertex->reset();
267  this->helement->reset();
268 
269 }
270 /*}}}*/
271 void Moulin::SetCurrentConfiguration(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){/*{{{*/
272 
273 }
274 /*}}}*/
275 void Moulin::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
276 
277  /*Output */
278  int d_nz = 0;
279  int o_nz = 0;
280 
281  if(!flags[this->node->Lid()]){
282 
283  /*flag current node so that no other element processes it*/
284  flags[this->node->Lid()]=true;
285 
286  int counter=0;
287  while(flagsindices[counter]>=0) counter++;
288  flagsindices[counter]=this->node->Lid();
289 
290  /*if node is clone, we have an off-diagonal non-zero, else it is a diagonal non-zero*/
291  switch(set2_enum){
292  case FsetEnum:
293  if(node->fsize){
294  if(this->node->IsClone())
295  o_nz += 1;
296  else
297  d_nz += 1;
298  }
299  break;
300  case GsetEnum:
301  if(node->gsize){
302  if(this->node->IsClone())
303  o_nz += 1;
304  else
305  d_nz += 1;
306  }
307  break;
308  case SsetEnum:
309  if(node->ssize){
310  if(this->node->IsClone())
311  o_nz += 1;
312  else
313  d_nz += 1;
314  }
315  break;
316  default: _error_("not supported");
317  }
318  }
319 
320  /*Assign output pointers: */
321  *pd_nz=d_nz;
322  *po_nz=o_nz;
323 }
324 /*}}}*/
325 
326 /*Update virtual functions definitions:*/
327 void Moulin::InputUpdateFromConstant(IssmDouble constant, int name){/*{{{*/
328  /*Nothing*/
329 }
330 /*}}}*/
331 void Moulin::InputUpdateFromConstant(int constant, int name){/*{{{*/
332  /*Nothing updated yet*/
333 }
334 /*}}}*/
335 void Moulin::InputUpdateFromConstant(bool constant, int name){/*{{{*/
336 
337  /*Don't do anything for now*/
338 }
339 /*}}}*/
340 void Moulin::InputUpdateFromMatrixDakota(IssmDouble* matrix, int nrows, int ncols, int name, int type){/*{{{*/
341  /*Nothing updated yet*/
342 }
343 /*}}}*/
344 void Moulin::InputUpdateFromVector(IssmDouble* vector, int name, int type){/*{{{*/
345  /*Nothing updated yet*/
346 }
347 /*}}}*/
348 void Moulin::InputUpdateFromVectorDakota(IssmDouble* vector, int name, int type){/*{{{*/
349  /*Nothing updated yet*/
350 }
351 /*}}}*/
352 
354 
355  /*If this node is not the master node (belongs to another partition of the
356  * mesh), don't add the moulin input a second time*/
357  if(node->IsClone()) return NULL;
358 
359  /*Initialize Element matrix*/
360  ElementMatrix* Ke=new ElementMatrix(&node,1,this->parameters);
361 
362  /*Get all inputs and parameters*/
366  IssmDouble Am = 0.; //For now...
367 
368  /*Load vector*/
369  Ke->values[0] = - Am/(rho_water*g)/dt;
370 
371  /*Clean up and return*/
372  return Ke;
373 }
374 /*}}}*/
376 
377  /*If this node is not the master node (belongs to another partition of the
378  * mesh), don't add the moulin input a second time*/
379  if(node->IsClone()) return NULL;
380 
381  /*Initialize Element vector*/
382  ElementVector* pe=new ElementVector(&node,1,this->parameters);
383 
384  /*Get all inputs and parameters*/
388  IssmDouble Am = 0.; //For now...
389 
390  /*Get hydraulic potential*/
391  IssmDouble phi_old,moulin_load;
394 
395  pe->values[0] = moulin_load -Am/(rho_water*g) * phi_old/dt;
396 
397  /*Clean up and return*/
398  return pe;
399 }
400 /*}}}*/
402 
403  /*If this node is not the master node (belongs to another partition of the
404  * mesh), don't add the moulin input a second time*/
405  if(node->IsClone()) return NULL;
406 
407  IssmDouble moulin_load;
408 
409  /*Initialize Element matrix*/
410  ElementVector* pe=new ElementVector(&node,1,this->parameters);
411 
412  this->element->GetInputValue(&moulin_load,node,HydrologyMoulinInputEnum);
413  pe->values[0]=moulin_load;
414 
415  /*Clean up and return*/
416  return pe;
417 }
418 /*}}}*/
420 
421  /*If this node is not the master node (belongs to another partition of the
422  * mesh), don't add the moulin input a second time*/
423  if(node->IsClone()) return NULL;
424  bool isefficientlayer;
425  IssmDouble moulin_load,dt;
426  IssmDouble epl_active;
427 
428  /*Initialize Element matrix*/
429  ElementVector* pe=new ElementVector(&node,1,this->parameters);
430 
434  // Test version input in EPL when active
435  if(isefficientlayer){
437  if(reCast<bool>(epl_active)){
438  pe->values[0]=moulin_load*0.0;
439  }
440  else{
441  pe->values[0]=moulin_load*dt;
442  }
443  }
444  else{
445  pe->values[0]=moulin_load*dt;
446  }
447  /*Clean up and return*/
448  return pe;
449  }
450 /*}}}*/
452 
453  /*If this node is not the master node (belongs to another partition of the
454  * mesh), don't add the moulin input a second time*/
455  if(node->IsClone()) return NULL;
456  if(!this->node->IsActive()) return NULL;
457  IssmDouble moulin_load,dt;
458  ElementVector* pe=new ElementVector(&node,1,this->parameters);
459 
462 
463  pe->values[0]=moulin_load*dt;
464  /*Clean up and return*/
465  return pe;
466 }
467 /*}}}*/
Matrix< IssmDouble >
Moulin::CreateKMatrix
void CreateKMatrix(Matrix< IssmDouble > *Kff, Matrix< IssmDouble > *Kfs)
Definition: Moulin.cpp:159
Node::IsActive
bool IsActive(void)
Definition: Node.cpp:795
Vertices
Declaration of Vertices class.
Definition: Vertices.h:15
Moulin::hvertex
Hook * hvertex
Definition: Moulin.h:29
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmDouble
double IssmDouble
Definition: types.h:37
Moulin::CreateKMatrixHydrologyGlaDS
ElementMatrix * CreateKMatrixHydrologyGlaDS(void)
Definition: Moulin.cpp:353
Nodes
Declaration of Nodes class.
Definition: Nodes.h:19
Moulin::CreatePVectorHydrologyDCInefficient
ElementVector * CreatePVectorHydrologyDCInefficient(void)
Definition: Moulin.cpp:419
Element::FindParam
void FindParam(bool *pvalue, int paramenum)
Definition: Element.cpp:933
Moulin::id
int id
Definition: Moulin.h:25
Moulin::GetNumberOfNodes
int GetNumberOfNodes(void)
Definition: Moulin.cpp:238
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
HydrologydcMaskEplactiveNodeEnum
@ HydrologydcMaskEplactiveNodeEnum
Definition: EnumDefinitions.h:608
Moulin
Definition: Moulin.h:21
MoulinEnum
@ MoulinEnum
Definition: EnumDefinitions.h:1191
Parameters
Declaration of Parameters class.
Definition: Parameters.h:18
MaterialsRhoFreshwaterEnum
@ MaterialsRhoFreshwaterEnum
Definition: EnumDefinitions.h:263
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
TimesteppingTimeStepEnum
@ TimesteppingTimeStepEnum
Definition: EnumDefinitions.h:433
Hook::DeepEcho
void DeepEcho(void)
Definition: Hook.cpp:77
Moulin::InputUpdateFromVectorDakota
void InputUpdateFromVectorDakota(IssmDouble *vector, int name, int type)
Definition: Moulin.cpp:348
Moulin::DeepEcho
void DeepEcho()
Definition: Moulin.cpp:94
HydrologydcIsefficientlayerEnum
@ HydrologydcIsefficientlayerEnum
Definition: EnumDefinitions.h:185
Elements
Declaration of Elements class.
Definition: Elements.h:17
Moulin::PenaltyCreateKMatrix
void PenaltyCreateKMatrix(Matrix< IssmDouble > *Kff, Matrix< IssmDouble > *kfs, IssmDouble kmax)
Definition: Moulin.cpp:247
NUMVERTICES
#define NUMVERTICES
Definition: Moulin.cpp:19
Moulin::SetCurrentConfiguration
void SetCurrentConfiguration(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)
Definition: Moulin.cpp:271
SsetEnum
@ SsetEnum
Definition: EnumDefinitions.h:1282
ElementVector::values
IssmDouble * values
Definition: ElementVector.h:24
HydrologyShaktiAnalysisEnum
@ HydrologyShaktiAnalysisEnum
Definition: EnumDefinitions.h:1103
Moulin::CreatePVector
void CreatePVector(Vector< IssmDouble > *pf)
Definition: Moulin.cpp:191
Moulin::GetNodesLidList
void GetNodesLidList(int *lidlist)
Definition: Moulin.cpp:222
Moulin::helement
Hook * helement
Definition: Moulin.h:30
Moulin::CreatePVectorHydrologyShakti
ElementVector * CreatePVectorHydrologyShakti(void)
Definition: Moulin.cpp:401
Moulin::Moulin
Moulin()
Definition: Moulin.cpp:22
Moulin::hnode
Hook * hnode
Definition: Moulin.h:28
Hook::reset
void reset(void)
Definition: Hook.cpp:211
Moulin::Echo
void Echo()
Definition: Moulin.cpp:105
HydrologyDCInefficientAnalysisEnum
@ HydrologyDCInefficientAnalysisEnum
Definition: EnumDefinitions.h:1099
Moulin::vertex
Vertex * vertex
Definition: Moulin.h:34
HydrologyGlaDSAnalysisEnum
@ HydrologyGlaDSAnalysisEnum
Definition: EnumDefinitions.h:1100
Element
Definition: Element.h:41
Moulin::element
Element * element
Definition: Moulin.h:35
Node::ssize
int ssize
Definition: Node.h:46
Moulin::CreatePVectorHydrologyGlaDS
ElementVector * CreatePVectorHydrologyGlaDS(void)
Definition: Moulin.cpp:375
HydrologyMoulinInputEnum
@ HydrologyMoulinInputEnum
Definition: EnumDefinitions.h:617
Moulin::InputUpdateFromConstant
void InputUpdateFromConstant(IssmDouble constant, int name)
Definition: Moulin.cpp:327
Object
Definition: Object.h:13
Parameters::DeepEcho
void DeepEcho()
Definition: Parameters.cpp:99
ConstantsGEnum
@ ConstantsGEnum
Definition: EnumDefinitions.h:102
Hook::delivers
Object * delivers(void)
Definition: Hook.cpp:191
Materials
Declaration of Materials class.
Definition: Materials.h:16
Moulin::SetwiseNodeConnectivity
void SetwiseNodeConnectivity(int *d_nz, int *o_nz, Node *node, bool *flags, int *flagsindices, int set1_enum, int set2_enum)
Definition: Moulin.cpp:275
Hook
Definition: Hook.h:16
Hook::configure
void configure(DataSet *dataset)
Definition: Hook.cpp:145
GsetEnum
@ GsetEnum
Definition: EnumDefinitions.h:1093
MARSHALLING
#define MARSHALLING(FIELD)
Definition: Marshalling.h:29
Moulin::Id
int Id()
Definition: Moulin.cpp:109
Node::IsClone
int IsClone()
Definition: Node.cpp:801
Moulin::node
Node * node
Definition: Moulin.h:33
HydrologyDCEfficientAnalysisEnum
@ HydrologyDCEfficientAnalysisEnum
Definition: EnumDefinitions.h:1098
Hook::copy
Object * copy(void)
Definition: Hook.cpp:61
Moulin::ObjectEnum
int ObjectEnum()
Definition: Moulin.cpp:135
MARSHALLING_BACKWARD
@ MARSHALLING_BACKWARD
Definition: Marshalling.h:10
Moulin::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Moulin.cpp:111
IoModel::singlenodetoelementconnectivity
int * singlenodetoelementconnectivity
Definition: IoModel.h:100
Moulin::GetNodesSidList
void GetNodesSidList(int *sidlist)
Definition: Moulin.cpp:230
Loads
Declaration of Loads class.
Definition: Loads.h:16
Node
Definition: Node.h:23
Node::Lid
int Lid(void)
Definition: Node.cpp:618
Node::Sid
int Sid(void)
Definition: Node.cpp:622
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
Moulin::copy
Object * copy()
Definition: Moulin.cpp:69
Moulin::parameters
Parameters * parameters
Definition: Moulin.h:37
HydrologydcBasalMoulinInputEnum
@ HydrologydcBasalMoulinInputEnum
Definition: EnumDefinitions.h:602
Moulin::IsPenalty
bool IsPenalty(void)
Definition: Moulin.cpp:243
Element::GetInputValue
void GetInputValue(bool *pvalue, int enum_type)
Definition: Element.cpp:1177
Moulin::PenaltyCreatePVector
void PenaltyCreatePVector(Vector< IssmDouble > *pf, IssmDouble kmax)
Definition: Moulin.cpp:253
Parameters::FindParam
void FindParam(bool *pinteger, int enum_type)
Definition: Parameters.cpp:262
Moulin::InputUpdateFromVector
void InputUpdateFromVector(IssmDouble *vector, int name, int type)
Definition: Moulin.cpp:344
ElementVector::AddToGlobal
void AddToGlobal(Vector< IssmDouble > *pf)
Definition: ElementVector.cpp:155
Node::gsize
int gsize
Definition: Node.h:44
AnalysisTypeEnum
@ AnalysisTypeEnum
Definition: EnumDefinitions.h:36
Moulin::ResetHooks
void ResetHooks()
Definition: Moulin.cpp:258
ElementVector
Definition: ElementVector.h:20
ElementMatrix::AddToGlobal
void AddToGlobal(Matrix< IssmDouble > *Kff, Matrix< IssmDouble > *Kfs)
Definition: ElementMatrix.cpp:271
Vertex
Definition: Vertex.h:19
IoModel
Definition: IoModel.h:48
Moulin::CreatePVectorHydrologyDCEfficient
ElementVector * CreatePVectorHydrologyDCEfficient(void)
Definition: Moulin.cpp:451
FsetEnum
@ FsetEnum
Definition: EnumDefinitions.h:1075
shared.h
ElementMatrix
Definition: ElementMatrix.h:19
Vector< IssmDouble >
Moulin::~Moulin
~Moulin()
Definition: Moulin.cpp:60
HydraulicPotentialOldEnum
@ HydraulicPotentialOldEnum
Definition: EnumDefinitions.h:598
Moulin::InputUpdateFromMatrixDakota
void InputUpdateFromMatrixDakota(IssmDouble *matrix, int nrows, int ncols, int name, int type)
Definition: Moulin.cpp:340
Node::fsize
int fsize
Definition: Node.h:45
Hook::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Hook.cpp:122
ElementMatrix::values
IssmDouble * values
Definition: ElementMatrix.h:26
Moulin::Configure
void Configure(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)
Definition: Moulin.cpp:142