Ice Sheet System Model  4.18
Code documentation
Neumannflux.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 "shared/shared.h"
14 #include "../classes.h"
15 /*}}}*/
16 
17 /*Load macros*/
18 #define NUMVERTICES 2
19 #define NUMNODES_BOUNDARY 2
20 
21 /*Neumannflux constructors and destructor*/
23  this->parameters = NULL;
24  this->helement = NULL;
25  this->element = NULL;
26  this->hnodes = NULL;
27  this->hvertices = NULL;
28  this->nodes = NULL;
29 }
30 /*}}}*/
31 Neumannflux::Neumannflux(int neumannflux_id,int i,IoModel* iomodel,int* segments){/*{{{*/
32 
33  /*Some sanity checks*/
34  _assert_(segments);
35 
36  /*neumannflux constructor data: */
37  int neumannflux_elem_id;
38  int neumannflux_vertex_ids[2];
39  int neumannflux_node_ids[2];
40 
41  /*1: Get vertices ids*/
42  neumannflux_vertex_ids[0]=segments[3*i+0];
43  neumannflux_vertex_ids[1]=segments[3*i+1];
44 
45  /*2: Get the ids of the nodes*/
46  neumannflux_node_ids[0]=neumannflux_vertex_ids[0];
47  neumannflux_node_ids[1]=neumannflux_vertex_ids[1];
48 
49  /*Get element id*/
50  neumannflux_elem_id = segments[3*i+2];
51 
52  /*Ok, we have everything to build the object: */
53  this->id=neumannflux_id;
54 
55  /*Hooks: */
56  this->hnodes =new Hook(&neumannflux_node_ids[0],2);
57  this->hvertices =new Hook(&neumannflux_vertex_ids[0],2);
58  this->helement =new Hook(&neumannflux_elem_id,1);
59 
60  //this->parameters: we still can't point to it, it may not even exist. Configure will handle this.
61  this->parameters=NULL;
62  this->element=NULL;
63  this->nodes=NULL;
64 }
65 /*}}}*/
67  this->parameters=NULL;
68  delete helement;
69  delete hnodes;
70  delete hvertices;
71 }
72 /*}}}*/
73 
74 /*Object virtual functions definitions:*/
76 
77  Neumannflux* neumannflux=NULL;
78 
79  neumannflux=new Neumannflux();
80 
81  /*copy fields: */
82  neumannflux->id=this->id;
83 
84  /*point parameters: */
85  neumannflux->parameters=this->parameters;
86 
87  /*now deal with hooks and objects: */
88  neumannflux->hnodes = (Hook*)this->hnodes->copy();
89  neumannflux->hvertices = (Hook*)this->hvertices->copy();
90  neumannflux->helement = (Hook*)this->helement->copy();
91 
92  /*corresponding fields*/
93  neumannflux->nodes = (Node**)neumannflux->hnodes->deliverp();
94  neumannflux->vertices = (Vertex**)neumannflux->hvertices->deliverp();
95  neumannflux->element = (Element*)neumannflux->helement->delivers();
96 
97  return neumannflux;
98 }
99 /*}}}*/
100 void Neumannflux::DeepEcho(void){/*{{{*/
101 
102  _printf_("Neumannflux:\n");
103  _printf_(" id: " << id << "\n");
104  hnodes->DeepEcho();
105  hvertices->DeepEcho();
106  helement->DeepEcho();
107  _printf_(" parameters\n");
108  if(parameters)
109  parameters->DeepEcho();
110  else
111  _printf_(" NULL\n");
112 }
113 /*}}}*/
114 void Neumannflux::Echo(void){/*{{{*/
115  _printf_("Neumannflux:\n");
116  _printf_(" id: " << id << "\n");
117  hnodes->Echo();
118  hvertices->Echo();
119  helement->Echo();
120  _printf_(" parameters: " << parameters << "\n");
121 }
122 /*}}}*/
123 int Neumannflux::Id(void){/*{{{*/
124  return id;
125 }
126 /*}}}*/
127 void Neumannflux::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
128 
129  _assert_(this);
130 
131  /*ok, marshall operations: */
133  MARSHALLING(id);
134 
135  if(marshall_direction==MARSHALLING_BACKWARD){
136  this->hnodes = new Hook();
137  this->hvertices = new Hook();
138  this->helement = new Hook();
139  }
140 
141  this->hnodes->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
142  this->helement->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
143  this->hvertices->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
144 
145  /*corresponding fields*/
146  nodes =(Node**)this->hnodes->deliverp();
147  vertices =(Vertex**)this->hvertices->deliverp();
148  element =(Element*)this->helement->delivers();
149 
150 }
151 /*}}}*/
152 int Neumannflux::ObjectEnum(void){/*{{{*/
153 
154  return NeumannfluxEnum;
155 
156 }
157 /*}}}*/
158 
159 /*Load virtual functions definitions:*/
160 void Neumannflux::Configure(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){/*{{{*/
161 
162  /*Take care of hooking up all objects for this element, ie links the objects in the hooks to their respective
163  * datasets, using internal ids and offsets hidden in hooks: */
164  hnodes->configure((DataSet*)nodesin);
165  hvertices->configure((DataSet*)verticesin);
166  helement->configure((DataSet*)elementsin);
167 
168  /*Initialize hooked fields*/
169  this->nodes = (Node**)hnodes->deliverp();
170  this->vertices = (Vertex**)hvertices->deliverp();
171  this->element = (Element*)helement->delivers();
172 
173  /*point parameters to real dataset: */
174  this->parameters=parametersin;
175 }
176 /*}}}*/
178 
179  /*recover some parameters*/
180  ElementMatrix* Ke=NULL;
181  int analysis_type;
182  this->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
183 
184  /*Just branch to the correct element stiffness matrix generator, according to the type of analysis we are carrying out: */
185  switch(analysis_type){
187  /*Nothing!*/
188  break;
190  /*Nothing!*/
191  break;
192  default:
193  _error_("analysis " << analysis_type << " (" << EnumToStringx(analysis_type) << ") not supported yet");
194  }
195 
196  /*Add to global matrix*/
197  if(Ke){
198  Ke->AddToGlobal(Kff,Kfs);
199  delete Ke;
200  }
201 
202 }
203 /*}}}*/
205 
206  /*recover some parameters*/
207  ElementVector* pe=NULL;
208  int analysis_type;
209  this->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
210 
211  switch(analysis_type){
214  break;
217  break;
218  default:
219  _error_("analysis " << analysis_type << " (" << EnumToStringx(analysis_type) << ") not supported yet");
220  }
221 
222  /*Add to global matrix*/
223  if(pe){
224  pe->AddToGlobal(pf);
225  delete pe;
226  }
227 
228 }
229 /*}}}*/
230 void Neumannflux::GetNodesLidList(int* lidlist){/*{{{*/
231 
232  _assert_(lidlist);
233  _assert_(nodes);
234 
235  for(int i=0;i<NUMNODES_BOUNDARY;i++) lidlist[i]=nodes[i]->Lid();
236 }
237 /*}}}*/
238 void Neumannflux::GetNodesSidList(int* sidlist){/*{{{*/
239 
240  _assert_(sidlist);
241  _assert_(nodes);
242 
243  for(int i=0;i<NUMNODES_BOUNDARY;i++) sidlist[i]=nodes[i]->Sid();
244 }
245 /*}}}*/
247 
248  return NUMNODES_BOUNDARY;
249 }
250 /*}}}*/
251 bool Neumannflux::IsPenalty(void){/*{{{*/
252  return false;
253 }
254 /*}}}*/
256 
257  /*No stiffness loads applied, do nothing: */
258  return;
259 
260 }
261 /*}}}*/
263 
264  /*No penalty loads applied, do nothing: */
265  return;
266 
267 }
268 /*}}}*/
270 
271  this->nodes=NULL;
272  this->vertices=NULL;
273  this->element=NULL;
274  this->parameters=NULL;
275 
276  /*Get Element type*/
277  this->hnodes->reset();
278  this->hvertices->reset();
279  this->helement->reset();
280 
281 }
282 /*}}}*/
283 void Neumannflux::SetCurrentConfiguration(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){/*{{{*/
284 
285 }
286 /*}}}*/
287 void Neumannflux::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
288 
289  /*Output */
290  int d_nz = 0;
291  int o_nz = 0;
292 
293  /*Loop over all nodes*/
294  for(int i=0;i<this->GetNumberOfNodes();i++){
295 
296  if(!flags[this->nodes[i]->Lid()]){
297 
298  /*flag current node so that no other element processes it*/
299  flags[this->nodes[i]->Lid()]=true;
300 
301  int counter=0;
302  while(flagsindices[counter]>=0) counter++;
303  flagsindices[counter]=this->nodes[i]->Lid();
304 
305  /*if node is clone, we have an off-diagonal non-zero, else it is a diagonal non-zero*/
306  switch(set2_enum){
307  case FsetEnum:
308  if(nodes[i]->fsize){
309  if(this->nodes[i]->IsClone())
310  o_nz += 1;
311  else
312  d_nz += 1;
313  }
314  break;
315  case GsetEnum:
316  if(nodes[i]->gsize){
317  if(this->nodes[i]->IsClone())
318  o_nz += 1;
319  else
320  d_nz += 1;
321  }
322  break;
323  case SsetEnum:
324  if(nodes[i]->ssize){
325  if(this->nodes[i]->IsClone())
326  o_nz += 1;
327  else
328  d_nz += 1;
329  }
330  break;
331  default: _error_("not supported");
332  }
333  }
334  }
335 
336  /*Assign output pointers: */
337  *pd_nz=d_nz;
338  *po_nz=o_nz;
339 }
340 /*}}}*/
341 
342 /*Neumannflux management*/
344 
345  /* constants*/
346  const int numdof=2;
347 
348  /* Intermediaries*/
349  IssmDouble Jdet,flux;
350  IssmDouble xyz_list[NUMVERTICES][3];
351  IssmDouble basis[numdof];
352 
353  /*Initialize Load Vector and return if necessary*/
354  Tria* tria=(Tria*)element;
355  _assert_(tria->FiniteElement()==P1Enum);
356  if(!tria->IsIceInElement() || tria->IsFloating()) return NULL;
357 
358  /*Initialize Element vector and other vectors*/
360 
361  /*Retrieve all inputs and parameters*/
363  Input2* flux_input = tria->GetInput2(HydrologyNeumannfluxEnum); _assert_(flux_input);
364 
365  /*Check wether it is an inflow or outflow BC (0 is the middle of the segment)*/
366  int index1=tria->GetVertexIndex(vertices[0]);
367  int index2=tria->GetVertexIndex(vertices[1]);
368 
369  /* Start looping on the number of gaussian points: */
370  GaussTria* gauss=new GaussTria(index1,index2,2);
371  for(int ig=gauss->begin();ig<gauss->end();ig++){
372 
373  gauss->GaussPoint(ig);
374 
375  tria->GetSegmentJacobianDeterminant(&Jdet,&xyz_list[0][0],gauss);
376  tria->GetSegmentNodalFunctions(&basis[0],gauss,index1,index2,tria->FiniteElement());
377  flux_input->GetInputValue(&flux,gauss);
378 
379  for(int i=0;i<numdof;i++) pe->values[i] += gauss->weight*Jdet*flux*basis[i];
380  }
381 
382  /*Clean up and return*/
383  delete gauss;
384  return pe;
385 }
386 /*}}}*/
388 
389  /* constants*/
390  const int numdof=2;
391 
392  /* Intermediaries*/
393  IssmDouble Jdet,flux;
394  IssmDouble xyz_list[NUMVERTICES][3];
395  IssmDouble basis[numdof];
396 
397  /*Initialize Load Vector and return if necessary*/
398  Tria* tria=(Tria*)element;
399  _assert_(tria->FiniteElement()==P1Enum);
400  if(!tria->IsIceInElement() || tria->IsFloating()) return NULL;
401 
402  /*Initialize Element vector and other vectors*/
404 
405  /*Retrieve all inputs and parameters*/
407  Input2* flux_input = tria->GetInput2(HydrologyNeumannfluxEnum); _assert_(flux_input);
408 
409  /*Check wether it is an inflow or outflow BC (0 is the middle of the segment)*/
410  int index1=tria->GetVertexIndex(vertices[0]);
411  int index2=tria->GetVertexIndex(vertices[1]);
412 
413  /* Start looping on the number of gaussian points: */
414  GaussTria* gauss=new GaussTria(index1,index2,2);
415  for(int ig=gauss->begin();ig<gauss->end();ig++){
416 
417  gauss->GaussPoint(ig);
418 
419  tria->GetSegmentJacobianDeterminant(&Jdet,&xyz_list[0][0],gauss);
420  tria->GetSegmentNodalFunctions(&basis[0],gauss,index1,index2,tria->FiniteElement());
421  flux_input->GetInputValue(&flux,gauss);
422 
423  for(int i=0;i<numdof;i++) pe->values[i] += gauss->weight*Jdet*flux*basis[i];
424  }
425 
426  /*Clean up and return*/
427  delete gauss;
428  return pe;
429 }
430 /*}}}*/
Matrix< IssmDouble >
Vertices
Declaration of Vertices class.
Definition: Vertices.h:15
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
Neumannflux::Echo
void Echo()
Definition: Neumannflux.cpp:114
IssmDouble
double IssmDouble
Definition: types.h:37
Nodes
Declaration of Nodes class.
Definition: Nodes.h:19
Neumannflux::hnodes
Hook * hnodes
Definition: Neumannflux.h:25
TriaRef::GetSegmentJacobianDeterminant
void GetSegmentJacobianDeterminant(IssmDouble *Jdet, IssmDouble *xyz_list, Gauss *gauss)
Definition: TriaRef.cpp:229
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
Hook::deliverp
Object ** deliverp(void)
Definition: Hook.cpp:187
Parameters
Declaration of Parameters class.
Definition: Parameters.h:18
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
Hook::DeepEcho
void DeepEcho(void)
Definition: Hook.cpp:77
Elements
Declaration of Elements class.
Definition: Elements.h:17
SsetEnum
@ SsetEnum
Definition: EnumDefinitions.h:1282
Neumannflux::PenaltyCreatePVector
void PenaltyCreatePVector(Vector< IssmDouble > *pf, IssmDouble kmax)
Definition: Neumannflux.cpp:262
ElementVector::values
IssmDouble * values
Definition: ElementVector.h:24
Neumannflux::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Neumannflux.cpp:127
HydrologyShaktiAnalysisEnum
@ HydrologyShaktiAnalysisEnum
Definition: EnumDefinitions.h:1103
GaussTria::begin
int begin(void)
Definition: GaussTria.cpp:356
Element::IsFloating
bool IsFloating()
Definition: Element.cpp:1987
Neumannflux::GetNodesLidList
void GetNodesLidList(int *lidlist)
Definition: Neumannflux.cpp:230
Neumannflux::SetwiseNodeConnectivity
void SetwiseNodeConnectivity(int *d_nz, int *o_nz, Node *node, bool *flags, int *flagsindices, int set1_enum, int set2_enum)
Definition: Neumannflux.cpp:287
Neumannflux::hvertices
Hook * hvertices
Definition: Neumannflux.h:26
Neumannflux::CreateKMatrix
void CreateKMatrix(Matrix< IssmDouble > *Kff, Matrix< IssmDouble > *Kfs)
Definition: Neumannflux.cpp:177
TriaRef::GetSegmentNodalFunctions
void GetSegmentNodalFunctions(IssmDouble *basis, Gauss *gauss, int index1, int index2, int finiteelement)
Definition: TriaRef.cpp:243
Hook::reset
void reset(void)
Definition: Hook.cpp:211
HydrologyNeumannfluxEnum
@ HydrologyNeumannfluxEnum
Definition: EnumDefinitions.h:618
Neumannflux::GetNumberOfNodes
int GetNumberOfNodes(void)
Definition: Neumannflux.cpp:246
Neumannflux::parameters
Parameters * parameters
Definition: Neumannflux.h:32
Neumannflux::PenaltyCreateKMatrix
void PenaltyCreateKMatrix(Matrix< IssmDouble > *Kff, Matrix< IssmDouble > *kfs, IssmDouble kmax)
Definition: Neumannflux.cpp:255
Neumannflux::id
int id
Definition: Neumannflux.h:21
HydrologyGlaDSAnalysisEnum
@ HydrologyGlaDSAnalysisEnum
Definition: EnumDefinitions.h:1100
Element
Definition: Element.h:41
P1Enum
@ P1Enum
Definition: EnumDefinitions.h:662
GaussTria
Definition: GaussTria.h:12
NeumannfluxEnum
@ NeumannfluxEnum
Definition: EnumDefinitions.h:657
Object
Definition: Object.h:13
NUMVERTICES
#define NUMVERTICES
Definition: Neumannflux.cpp:18
Parameters::DeepEcho
void DeepEcho()
Definition: Parameters.cpp:99
Hook::delivers
Object * delivers(void)
Definition: Hook.cpp:191
Neumannflux
Definition: Neumannflux.h:18
Materials
Declaration of Materials class.
Definition: Materials.h:16
Neumannflux::IsPenalty
bool IsPenalty(void)
Definition: Neumannflux.cpp:251
Neumannflux::CreatePVectorHydrologyGlaDS
ElementVector * CreatePVectorHydrologyGlaDS(void)
Definition: Neumannflux.cpp:387
Neumannflux::Neumannflux
Neumannflux()
Definition: Neumannflux.cpp:22
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
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
Neumannflux::helement
Hook * helement
Definition: Neumannflux.h:24
Neumannflux::GetNodesSidList
void GetNodesSidList(int *sidlist)
Definition: Neumannflux.cpp:238
GaussTria::GaussPoint
void GaussPoint(int ig)
Definition: GaussTria.cpp:479
Neumannflux::nodes
Node ** nodes
Definition: Neumannflux.h:31
GetVerticesCoordinates
void GetVerticesCoordinates(IssmDouble *xyz, Vertex **vertices, int numvertices, bool spherical)
Definition: Vertex.cpp:225
Tria::FiniteElement
int FiniteElement(void)
Definition: Tria.cpp:1318
Hook::copy
Object * copy(void)
Definition: Hook.cpp:61
Neumannflux::DeepEcho
void DeepEcho()
Definition: Neumannflux.cpp:100
Neumannflux::ObjectEnum
int ObjectEnum()
Definition: Neumannflux.cpp:152
Input2
Definition: Input2.h:18
MARSHALLING_BACKWARD
@ MARSHALLING_BACKWARD
Definition: Marshalling.h:10
Neumannflux::CreatePVectorHydrologyShakti
ElementVector * CreatePVectorHydrologyShakti(void)
Definition: Neumannflux.cpp:343
Neumannflux::Configure
void Configure(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)
Definition: Neumannflux.cpp:160
Neumannflux::vertices
Vertex ** vertices
Definition: Neumannflux.h:30
Element::IsIceInElement
bool IsIceInElement()
Definition: Element.cpp:2021
Loads
Declaration of Loads class.
Definition: Loads.h:16
Neumannflux::copy
Object * copy()
Definition: Neumannflux.cpp:75
Node
Definition: Node.h:23
Node::Lid
int Lid(void)
Definition: Node.cpp:618
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
Tria
Definition: Tria.h:29
Neumannflux::element
Element * element
Definition: Neumannflux.h:29
NUMNODES_BOUNDARY
#define NUMNODES_BOUNDARY
Definition: Neumannflux.cpp:19
Parameters::FindParam
void FindParam(bool *pinteger, int enum_type)
Definition: Parameters.cpp:262
ElementVector::AddToGlobal
void AddToGlobal(Vector< IssmDouble > *pf)
Definition: ElementVector.cpp:155
AnalysisTypeEnum
@ AnalysisTypeEnum
Definition: EnumDefinitions.h:36
Neumannflux::Id
int Id()
Definition: Neumannflux.cpp:123
Neumannflux::~Neumannflux
~Neumannflux()
Definition: Neumannflux.cpp:66
ElementVector
Definition: ElementVector.h:20
ElementMatrix::AddToGlobal
void AddToGlobal(Matrix< IssmDouble > *Kff, Matrix< IssmDouble > *Kfs)
Definition: ElementMatrix.cpp:271
Hook::Echo
void Echo(void)
Definition: Hook.cpp:104
Input2::GetInputValue
virtual void GetInputValue(IssmDouble *pvalue, Gauss *gauss)
Definition: Input2.h:38
Vertex
Definition: Vertex.h:19
Gauss::weight
IssmDouble weight
Definition: Gauss.h:11
IoModel
Definition: IoModel.h:48
Neumannflux::ResetHooks
void ResetHooks()
Definition: Neumannflux.cpp:269
FsetEnum
@ FsetEnum
Definition: EnumDefinitions.h:1075
DataSet
Declaration of DataSet class.
Definition: DataSet.h:14
shared.h
ElementMatrix
Definition: ElementMatrix.h:19
Vector< IssmDouble >
Neumannflux::CreatePVector
void CreatePVector(Vector< IssmDouble > *pf)
Definition: Neumannflux.cpp:204
Tria::GetInput2
Input2 * GetInput2(int enumtype)
Definition: Tria.cpp:1880
Tria::GetVertexIndex
int GetVertexIndex(Vertex *vertex)
Definition: Tria.cpp:2368
Neumannflux::SetCurrentConfiguration
void SetCurrentConfiguration(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)
Definition: Neumannflux.cpp:283
Hook::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Hook.cpp:122