Ice Sheet System Model  4.18
Code documentation
Penpair.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 /*}}}*/
16 
17 /*Element macros*/
18 #define NUMVERTICES 2
19 
20 /*Penpair constructors and destructor*/
22 
23  this->hnodes=NULL;
24  this->nodes=NULL;
25  this->parameters=NULL;
26  return;
27 }
28 /*}}}*/
29 Penpair::Penpair(int penpair_id, int* penpair_node_ids){/*{{{*/
30 
31  this->id=penpair_id;
32  this->hnodes=new Hook(penpair_node_ids,2);
33  this->parameters=NULL;
34  this->nodes=NULL;
35 
36  return;
37 }
38 /*}}}*/
40  delete hnodes;
41  return;
42 }
43 /*}}}*/
44 
45 /*Object virtual functions definitions:*/
46 Object* Penpair::copy() {/*{{{*/
47 
48  Penpair* penpair=NULL;
49 
50  penpair=new Penpair();
51 
52  /*copy fields: */
53  penpair->id=this->id;
54 
55  /*now deal with hooks and objects: */
56  penpair->hnodes=(Hook*)this->hnodes->copy();
57  penpair->nodes =(Node**)penpair->hnodes->deliverp();
58 
59  /*point parameters: */
60  penpair->parameters=this->parameters;
61 
62  return penpair;
63 
64 }
65 /*}}}*/
66 void Penpair::DeepEcho(void){/*{{{*/
67 
68  _printf_("Penpair:\n");
69  _printf_(" id: " << id << "\n");
70  hnodes->DeepEcho();
71 
72  return;
73 }
74 /*}}}*/
75 void Penpair::Echo(void){/*{{{*/
76 
77  _printf_("Penpair:\n");
78  _printf_(" id: " << id << "\n");
79  hnodes->Echo();
80 
81  return;
82 }
83 /*}}}*/
84 int Penpair::Id(void){ return id; }/*{{{*/
85 /*}}}*/
86 void Penpair::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
87 
88  _assert_(this);
89 
90  /*ok, marshall operations: */
92  MARSHALLING(id);
93 
94  if(marshall_direction==MARSHALLING_BACKWARD){
95  this->hnodes = new Hook();
96  }
97  this->hnodes->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
98 
99  /*corresponding fields*/
100  nodes = (Node**)this->hnodes->deliverp();
101 
102 }
103 /*}}}*/
104 int Penpair::ObjectEnum(void){/*{{{*/
105 
106  return PenpairEnum;
107 }
108 /*}}}*/
109 
110 /*Load virtual functions definitions:*/
111 void Penpair::Configure(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){/*{{{*/
112 
113  /*Take care of hooking up all objects for this element, ie links the objects in the hooks to their respective
114  * datasets, using internal ids and offsets hidden in hooks: */
115  hnodes->configure((DataSet*)nodesin);
116 
117  /*Initialize hooked fields*/
118  this->nodes =(Node**)hnodes->deliverp();
119 
120  /*point parameters to real dataset: */
121  this->parameters=parametersin;
122 
123 }
124 /*}}}*/
126  this->CreateKMatrix(Jff,NULL);
127 }
128 /*}}}*/
130  /*If you code this piece, don't forget that a penalty will be inactive if it is dealing with clone nodes*/
131  /*No loads applied, do nothing: */
132  return;
133 
134 }
135 /*}}}*/
137 
138  /*No loads applied, do nothing: */
139  return;
140 
141 }
142 /*}}}*/
143 void Penpair::GetNodesLidList(int* lidlist){/*{{{*/
144 
145  _assert_(lidlist);
146  _assert_(nodes);
147 
148  for(int i=0;i<NUMVERTICES;i++) lidlist[i]=nodes[i]->Lid();
149 }
150 /*}}}*/
151 void Penpair::GetNodesSidList(int* sidlist){/*{{{*/
152 
153  _assert_(sidlist);
154  _assert_(nodes);
155 
156  for(int i=0;i<NUMVERTICES;i++) sidlist[i]=nodes[i]->Sid();
157 }
158 /*}}}*/
159 int Penpair::GetNumberOfNodes(void){/*{{{*/
160 
161  return NUMVERTICES;
162 }
163 /*}}}*/
164 bool Penpair::IsPenalty(void){/*{{{*/
165  return true;
166 }
167 /*}}}*/
169  this->PenaltyCreateKMatrix(Jff,NULL,kmax);
170 }
171 /*}}}*/
173 
174  /*Retrieve parameters: */
175  ElementMatrix* Ke=NULL;
176  int analysis_type;
177  this->parameters->FindParam(&analysis_type,AnalysisTypeEnum);
178 
179  switch(analysis_type){
182  break;
185  break;
186  default:
187  _error_("analysis " << analysis_type << " (" << EnumToStringx(analysis_type) << ") not supported yet");
188  }
189 
190  /*Add to global Vector*/
191  if(Ke){
192  Ke->AddToGlobal(Kff,Kfs);
193  delete Ke;
194  }
195 }
196 /*}}}*/
198  /*No loads applied, do nothing: */
199  return;
200 }
201 /*}}}*/
202 void Penpair::ResetHooks(){/*{{{*/
203 
204  this->nodes=NULL;
205  this->parameters=NULL;
206 
207  /*Get Element type*/
208  this->hnodes->reset();
209 
210 }
211 /*}}}*/
212 void Penpair::SetCurrentConfiguration(Elements* elementsin,Loads* loadsin,Nodes* nodesin,Vertices* verticesin,Materials* materialsin,Parameters* parametersin){/*{{{*/
213 
214 }
215 /*}}}*/
216 void Penpair::SetwiseNodeConnectivity(int* pd_nz,int* po_nz,Node* node,bool* flags,int* flagsindices,int set1_enum,int set2_enum){/*{{{*/
217 
218  /*Output */
219  int d_nz = 0;
220  int o_nz = 0;
221 
222  /*Loop over all nodes*/
223  for(int i=0;i<NUMVERTICES;i++){
224 
225  if(!flags[this->nodes[i]->Lid()]){
226 
227  /*flag current node so that no other element processes it*/
228  flags[this->nodes[i]->Lid()]=true;
229 
230  int counter=0;
231  while(flagsindices[counter]>=0) counter++;
232  flagsindices[counter]=this->nodes[i]->Lid();
233 
234  /*if node is clone, we have an off-diagonal non-zero, else it is a diagonal non-zero*/
235  switch(set2_enum){
236  case FsetEnum:
237  if(nodes[i]->fsize){
238  if(this->nodes[i]->IsClone())
239  o_nz += 1;
240  else
241  d_nz += 1;
242  }
243  break;
244  case GsetEnum:
245  if(nodes[i]->gsize){
246  if(this->nodes[i]->IsClone())
247  o_nz += 1;
248  else
249  d_nz += 1;
250  }
251  break;
252  case SsetEnum:
253  if(nodes[i]->ssize){
254  if(this->nodes[i]->IsClone())
255  o_nz += 1;
256  else
257  d_nz += 1;
258  }
259  break;
260  default: _error_("not supported");
261  }
262  }
263  }
264 
265  /*Assign output pointers: */
266  *pd_nz=d_nz;
267  *po_nz=o_nz;
268 }
269 /*}}}*/
270 
271 /*Update virtual functions definitions:*/
272 void Penpair::InputUpdateFromConstant(IssmDouble constant, int name){/*{{{*/
273  /*Nothing updated yet*/
274 }
275 /*}}}*/
276 void Penpair::InputUpdateFromConstant(int constant, int name){/*{{{*/
277  /*Nothing updated yet*/
278 }
279 /*}}}*/
280 void Penpair::InputUpdateFromConstant(bool constant, int name){/*{{{*/
281  /*Nothing updated yet*/
282 }
283 /*}}}*/
284 void Penpair::InputUpdateFromVector(IssmDouble* vector, int name, int type){/*{{{*/
285  /*Nothing updated yet*/
286 }
287 /*}}}*/
288 
289 /*Penpair management:*/
291 
292  const int numdof=NUMVERTICES*1;
293  IssmDouble penalty_factor;
294 
295  /*Initialize Element vector and return if necessary*/
297 
298  /*recover parameters: */
300 
301  //Create elementary matrix: add penalty to
302  Ke->values[0*numdof+0]=+kmax*pow(10.,penalty_factor);
303  Ke->values[0*numdof+1]=-kmax*pow(10.,penalty_factor);
304  Ke->values[1*numdof+0]=-kmax*pow(10.,penalty_factor);
305  Ke->values[1*numdof+1]=+kmax*pow(10.,penalty_factor);
306 
307  /*Clean up and return*/
308  return Ke;
309 }
310 /*}}}*/
312 
313  int numdof,numdof2,N;
314  IssmDouble penalty_offset;
315 
316  /*Initialize Element vector and return if necessary*/
318 
319  /*recover parameters: */
321 
322  /*Get number of dof for these two nodes*/
325  N=NUMVERTICES*numdof;
326 
327  /*Add penalty to Element matrix*/
328  for(int i=0;i<numdof;i++){
329  Ke->values[ i*N+i ]=+kmax*pow(10.,penalty_offset);
330  Ke->values[ i*N+numdof+i]=-kmax*pow(10.,penalty_offset);
331  Ke->values[(numdof+i)*N+i ]=-kmax*pow(10.,penalty_offset);
332  Ke->values[(numdof+i)*N+numdof+i]=+kmax*pow(10.,penalty_offset);
333  }
334 
335  /*Clean up and return*/
336  return Ke;
337 }
338 /*}}}*/
340 
341  int approximation0=nodes[0]->GetApproximation();
342  int approximation1=nodes[1]->GetApproximation();
343 
344  switch(approximation0){
346  switch(approximation1){
349  default: _error_("Approximation "<<EnumToStringx(approximation1)<<" not supported yet");
350  }
351  case HOApproximationEnum:
352  switch(approximation1){
355  default: _error_("Approximation "<<EnumToStringx(approximation1)<<" not supported yet");
356  }
357  case FSvelocityEnum:
358  switch(approximation1){
361  default: _error_("Approximation "<<EnumToStringx(approximation1)<<" not supported yet");
362  }
364  switch(approximation1){
367  }
368  default: _error_("Approximation "<<EnumToStringx(approximation0)<<" not supported yet");
369  }
370 }
371 /*}}}*/
373 
374  int numdof,numdof2,N;
375  IssmDouble penalty_offset;
376 
377  /*Initialize Element vector and return if necessary*/
379 
380  /*recover parameters: */
382 
383  /*Get number of dof for these two nodes*/
386  _assert_(numdof==numdof2);
387  N=NUMVERTICES*numdof;
388 
389  /*Add penalty to Element matrix*/
390  for(int i=0;i<numdof;i++){
391  Ke->values[ i*N+i ]=+kmax*pow(10.,penalty_offset);
392  Ke->values[ i*N+numdof+i]=-kmax*pow(10.,penalty_offset);
393  Ke->values[(numdof+i)*N+i ]=-kmax*pow(10.,penalty_offset);
394  Ke->values[(numdof+i)*N+numdof+i]=+kmax*pow(10.,penalty_offset);
395  }
396 
397  /*Clean up and return*/
398  return Ke;
399 }
400 /*}}}*/
Matrix< IssmDouble >
Vertices
Declaration of Vertices class.
Definition: Vertices.h:15
Penpair::Id
int Id()
Definition: Penpair.cpp:84
Penpair::GetNodesSidList
void GetNodesSidList(int *sidlist)
Definition: Penpair.cpp:151
Penpair::GetNodesLidList
void GetNodesLidList(int *lidlist)
Definition: Penpair.cpp:143
StressbalancePenaltyFactorEnum
@ StressbalancePenaltyFactorEnum
Definition: EnumDefinitions.h:409
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmDouble
double IssmDouble
Definition: types.h:37
HOApproximationEnum
@ HOApproximationEnum
Definition: EnumDefinitions.h:1095
Nodes
Declaration of Nodes class.
Definition: Nodes.h:19
Penpair::Configure
void Configure(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)
Definition: Penpair.cpp:111
MasstransportAnalysisEnum
@ MasstransportAnalysisEnum
Definition: EnumDefinitions.h:1163
StressbalanceAnalysisEnum
@ StressbalanceAnalysisEnum
Definition: EnumDefinitions.h:1285
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
Penpair::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Penpair.cpp:86
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
Penpair::PenaltyCreateKMatrixStressbalanceHoriz
ElementMatrix * PenaltyCreateKMatrixStressbalanceHoriz(IssmDouble kmax)
Definition: Penpair.cpp:339
Node::GetApproximation
int GetApproximation()
Definition: Node.cpp:731
Elements
Declaration of Elements class.
Definition: Elements.h:17
Penpair::~Penpair
~Penpair()
Definition: Penpair.cpp:39
Penpair::CreateKMatrix
void CreateKMatrix(Matrix< IssmDouble > *Kff, Matrix< IssmDouble > *Kfs)
Definition: Penpair.cpp:129
SsetEnum
@ SsetEnum
Definition: EnumDefinitions.h:1282
Penpair::copy
Object * copy()
Definition: Penpair.cpp:46
PenpairEnum
@ PenpairEnum
Definition: EnumDefinitions.h:1230
Penpair::DeepEcho
void DeepEcho()
Definition: Penpair.cpp:66
Penpair::CreatePVector
void CreatePVector(Vector< IssmDouble > *pf)
Definition: Penpair.cpp:136
Penpair::Penpair
Penpair()
Definition: Penpair.cpp:21
Penpair::PenaltyCreatePVector
void PenaltyCreatePVector(Vector< IssmDouble > *pf, IssmDouble kmax)
Definition: Penpair.cpp:197
Penpair::InputUpdateFromConstant
void InputUpdateFromConstant(IssmDouble constant, int name)
Definition: Penpair.cpp:272
FSApproximationEnum
@ FSApproximationEnum
Definition: EnumDefinitions.h:1060
Hook::reset
void reset(void)
Definition: Hook.cpp:211
Penpair::SetCurrentConfiguration
void SetCurrentConfiguration(Elements *elements, Loads *loads, Nodes *nodes, Vertices *vertices, Materials *materials, Parameters *parameters)
Definition: Penpair.cpp:212
Penpair::PenaltyCreateKMatrixStressbalanceSSAHO
ElementMatrix * PenaltyCreateKMatrixStressbalanceSSAHO(IssmDouble kmax)
Definition: Penpair.cpp:372
Object
Definition: Object.h:13
Penpair::IsPenalty
bool IsPenalty(void)
Definition: Penpair.cpp:164
NoneApproximationEnum
@ NoneApproximationEnum
Definition: EnumDefinitions.h:1201
Materials
Declaration of Materials class.
Definition: Materials.h:16
Penpair
Definition: Penpair.h:16
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
NUMVERTICES
#define NUMVERTICES
Definition: Penpair.cpp:18
Penpair::ResetHooks
void ResetHooks()
Definition: Penpair.cpp:202
Penpair::nodes
Node ** nodes
Definition: Penpair.h:21
Penpair::InputUpdateFromVector
void InputUpdateFromVector(IssmDouble *vector, int name, int type)
Definition: Penpair.cpp:284
Hook::copy
Object * copy(void)
Definition: Hook.cpp:61
FSvelocityEnum
@ FSvelocityEnum
Definition: EnumDefinitions.h:1063
MARSHALLING_BACKWARD
@ MARSHALLING_BACKWARD
Definition: Marshalling.h:10
Penpair::hnodes
Hook * hnodes
Definition: Penpair.h:20
Penpair::GetNumberOfNodes
int GetNumberOfNodes(void)
Definition: Penpair.cpp:159
Loads
Declaration of Loads class.
Definition: Loads.h:16
Node
Definition: Node.h:23
Node::Lid
int Lid(void)
Definition: Node.cpp:618
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
Penpair::CreateJacobianMatrix
void CreateJacobianMatrix(Matrix< IssmDouble > *Jff)
Definition: Penpair.cpp:125
Penpair::PenaltyCreateKMatrixMasstransport
ElementMatrix * PenaltyCreateKMatrixMasstransport(IssmDouble kmax)
Definition: Penpair.cpp:290
Penpair::ObjectEnum
int ObjectEnum()
Definition: Penpair.cpp:104
Penpair::PenaltyCreateJacobianMatrix
void PenaltyCreateJacobianMatrix(Matrix< IssmDouble > *Jff, IssmDouble kmax)
Definition: Penpair.cpp:168
Penpair::PenaltyCreateKMatrix
void PenaltyCreateKMatrix(Matrix< IssmDouble > *Kff, Matrix< IssmDouble > *Kfs, IssmDouble kmax)
Definition: Penpair.cpp:172
Parameters::FindParam
void FindParam(bool *pinteger, int enum_type)
Definition: Parameters.cpp:262
SSAApproximationEnum
@ SSAApproximationEnum
Definition: EnumDefinitions.h:1255
AnalysisTypeEnum
@ AnalysisTypeEnum
Definition: EnumDefinitions.h:36
Penpair::SetwiseNodeConnectivity
void SetwiseNodeConnectivity(int *d_nz, int *o_nz, Node *node, bool *flags, int *flagsindices, int set1_enum, int set2_enum)
Definition: Penpair.cpp:216
ElementMatrix::AddToGlobal
void AddToGlobal(Matrix< IssmDouble > *Kff, Matrix< IssmDouble > *Kfs)
Definition: ElementMatrix.cpp:271
Hook::Echo
void Echo(void)
Definition: Hook.cpp:104
FsetEnum
@ FsetEnum
Definition: EnumDefinitions.h:1075
DataSet
Declaration of DataSet class.
Definition: DataSet.h:14
Penpair::PenaltyCreateKMatrixStressbalanceFS
ElementMatrix * PenaltyCreateKMatrixStressbalanceFS(IssmDouble kmax)
Definition: Penpair.cpp:311
Penpair::id
int id
Definition: Penpair.h:19
MasstransportPenaltyFactorEnum
@ MasstransportPenaltyFactorEnum
Definition: EnumDefinitions.h:247
shared.h
ElementMatrix
Definition: ElementMatrix.h:19
Vector< IssmDouble >
Penpair::parameters
Parameters * parameters
Definition: Penpair.h:22
Node::GetNumberOfDofs
int GetNumberOfDofs(int approximation_enum, int setenum)
Definition: Node.cpp:741
Penpair::Echo
void Echo()
Definition: Penpair.cpp:75
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