Ice Sheet System Model  4.18
Code documentation
PentaInput2.cpp
Go to the documentation of this file.
1 
5 #ifdef HAVE_CONFIG_H
6  #include <config.h>
7 #else
8 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
9 #endif
10 
11 #include "../classes.h"
12 #include "../../shared/shared.h"
13 #include "./PentaInput2.h"
14 
15 /*PentaInput2 constructors and destructor*/
17 
18  this->numberofelements_local = -1;
19  this->numberofvertices_local = -1;
20  this->isserved = false;
21  this->isserved_collapsed= 0;
22  this->M = -1;
23  this->N = -1;
24  this->values = NULL;
25  this->element_values = NULL;
26 
27 }/*}}}*/
28 PentaInput2::PentaInput2(int nbe_in,int nbv_in,int interp_in){/*{{{*/
29 
30  _assert_(nbe_in>0);
31  _assert_(nbe_in<1e11);
32  _assert_(nbv_in>0);
33  _assert_(nbv_in<1e11);
34  this->numberofelements_local = nbe_in;
35  this->numberofvertices_local = nbv_in;
36  this->isserved = false;
37  this->isserved_collapsed = 0;
38 
39  /*Reset takes care of the rest*/
40  this->Reset(interp_in);
41 
42 }/*}}}*/
44  if(this->element_values) xDelete<IssmDouble>(this->element_values);
45  if(this->values) xDelete<IssmDouble>(this->values);
46 }
47 /*}}}*/
48 void PentaInput2::Reset(int interp_in){/*{{{*/
49 
50  /*Clean up*/
51  if(this->values) xDelete<IssmDouble>(this->values);
52  if(this->element_values) xDelete<IssmDouble>(this->element_values);
53 
54  /*Set interpolation*/
55  this->interpolation = interp_in;
56 
57  /*Create Sizes*/
58  if(this->interpolation==P1Enum){
59  this->M = this->numberofvertices_local;
60  this->N = 1;
61  }
62  else{
63  this->M = this->numberofelements_local;
64  this->N = PentaRef::NumberofNodes(interp_in);
65  }
66 
67  /*Allocate Pointers*/
68  this->values = xNewZeroInit<IssmDouble>(this->M*this->N);
69  this->element_values = xNewZeroInit<IssmDouble>(PentaRef::NumberofNodes(interp_in));
70 }/*}}}*/
71 
72 /*Object virtual functions definitions:*/
74 
75  /*Create output*/
77 
78  /*Copy values*/
79  xMemCpy<IssmDouble>(output->values,this->values,this->M*this->N);
80 
81  /*Return output*/
82  return output;
83 
84 }
85 /*}}}*/
86 void PentaInput2::DeepEcho(void){/*{{{*/
87  _printf_("PentaInput2 Echo:\n");
88  _printf_(" interpolation: "<<EnumToStringx(this->interpolation)<<"\n");
89  _printf_(" nbe_local: "<<this->numberofvertices_local<<"\n");
90  _printf_(" nbv_local: "<<this->numberofelements_local<<"\n");
91  _printf_(" Size: "<<M<<"x"<<N<<"\n");
92  _printf_(" isserved: "<<(isserved?"true":"false") << "\n");
93  _printf_(" isserved_collapsed: "<<isserved_collapsed << "\n");
94  if(isserved){
95  _printf_(" current values: ");
97  _printf_("[ ");
98  for(int i=0;i<3;i++) _printf_(" "<<this->element_values[i]);
99  _printf_("] ("<<EnumToStringx(this->interpolation)<<")\n");
100  }
101  else{
102  _printf_("[ ");
103  for(int i=0;i<PentaRef::NumberofNodes(this->interpolation);i++) _printf_(" "<<this->element_values[i]);
104  _printf_("] ("<<EnumToStringx(this->interpolation)<<")\n");
105  }
106  }
107 }
108 /*}}}*/
109 void PentaInput2::Echo(void){/*{{{*/
110  _printf_(setw(15)<<" PentaInput "<<setw(25)<<left<<EnumToStringx(-1));
111  if(isserved){
112  if(isserved_collapsed){
113  _printf_("[ ");
114  for(int i=0;i<3;i++) _printf_(" "<<this->element_values[i]);
115  _printf_("] ("<<EnumToStringx(this->interpolation)<<")\n");
116  }
117  else{
118  _printf_("[ ");
119  for(int i=0;i<PentaRef::NumberofNodes(this->interpolation);i++) _printf_(" "<<this->element_values[i]);
120  _printf_("] ("<<EnumToStringx(this->interpolation)<<")\n");
121  }
122  }
123 }
124 /*}}}*/
125 int PentaInput2::Id(void){/*{{{*/
126  return -1;
127 }/*}}}*/
128 void PentaInput2::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
129 
133  MARSHALLING(this->interpolation);
134  MARSHALLING(this->M);
135  MARSHALLING(this->N);
136  this->isserved = false;
137  this->isserved_collapsed = 0;
138  if(this->M*this->N){
139  MARSHALLING_DYNAMIC(this->values,IssmDouble,this->M*this->N);
140  }
141  else this->values = NULL;
142 
143  if(marshall_direction == MARSHALLING_BACKWARD){
144  this->element_values = xNewZeroInit<IssmDouble>(PentaRef::NumberofNodes(this->interpolation));
145  }
146 }
147 /*}}}*/
148 int PentaInput2::ObjectEnum(void){/*{{{*/
149  return PentaInput2Enum;
150 }
151 /*}}}*/
152 
153 /*PentaInput2 management*/
154 void PentaInput2::SetInput(int interp_in,int row,IssmDouble value_in){/*{{{*/
155 
156  _assert_(this);
157  _assert_(row>=0);
158  _assert_(row<this->M);
159  _assert_(this->N==1);
160 
161  this->values[row] = value_in;
162  this->isserved = false;
163 }
164 /*}}}*/
165 void PentaInput2::SetInput(int interp_in,int numindices,int* indices,IssmDouble* values_in){/*{{{*/
166 
167  _assert_(this);
168  if(interp_in==P1Enum && this->interpolation==P1Enum){
169  _assert_(this->N==1);
170  for(int i=0;i<numindices;i++){
171  int row = indices[i];
172  _assert_(row>=0);
173  _assert_(row<this->M);
174  this->values[row] = values_in[i];
175  }
176  }
177  else if(this->interpolation!=P1Enum && interp_in==P1Enum){
178  this->Reset(interp_in);
179  for(int i=0;i<numindices;i++){
180  int row = indices[i];
181  _assert_(row>=0);
182  _assert_(row<this->M);
183  this->values[row] = values_in[i];
184  }
185  }
186  else{
187  _error_("not supported");
188  }
189 
190  this->isserved = false;
191 }
192 /*}}}*/
193 void PentaInput2::SetInput(int interp_in,int row,int numindices,IssmDouble* values_in){/*{{{*/
194 
195  _assert_(this);
196  if(interp_in==this->interpolation){
197  _assert_(this->N==numindices);
198  }
199  else{
200  this->Reset(interp_in);
201  _assert_(this->N==numindices);
202  }
203  for(int i=0;i<numindices;i++) this->values[row*this->N+i] = values_in[i];
204 
205  this->isserved = false;
206 }
207 /*}}}*/
208 void PentaInput2::Serve(int numindices,int* indices){/*{{{*/
209 
210  _assert_(this);
211  _assert_(this->N==1);
212 
213  for(int i=0;i<numindices;i++){
214  int row = indices[i];
215  _assert_(row>=0);
216  _assert_(row<this->M);
217  this->element_values[i] = this->values[row];
218  }
219 
220  /*Set input as served*/
221  this->isserved = true;
222  this->isserved_collapsed = 0;
223 }
224 /*}}}*/
225 void PentaInput2::Serve(int row,int numindices){/*{{{*/
226 
227  _assert_(this);
228  _assert_(this->N==numindices);
229  _assert_(row<this->M);
230  _assert_(row>=0);
231 
232  for(int i=0;i<numindices;i++){
233  this->element_values[i] = this->values[row*this->N+i];
234  }
235 
236  /*Set input as served*/
237  this->isserved = true;
238  this->isserved_collapsed = 0;
239 }/*}}}*/
240 void PentaInput2::ServeCollapsed(int row,int state){/*{{{*/
241 
242  _assert_(this);
243  _assert_(this->N>=3);
244  _assert_(row<this->M);
245  _assert_(row>=0);
246 
247  if(state==1){
248  for(int i=0;i<3;i++) this->element_values[i] = this->values[row*this->N+i];
249  for(int i=3;i<6;i++) this->element_values[i] = 0.;
250  }
251  else if(state==2){
252  for(int i=0;i<3;i++) this->element_values[i] = this->values[row*this->N+3+i];
253  for(int i=3;i<6;i++) this->element_values[i] = 0.;
254  }
255  else{
256  _error_("not supported");
257  }
258 
259  /*Set input as served*/
260  this->isserved = true;
261  this->isserved_collapsed = state;
262 }/*}}}*/
263 void PentaInput2::SetServeCollapsed(int state){/*{{{*/
264  this->isserved_collapsed = state;
265 }/*}}}*/
267  return this->interpolation;
268 }/*}}}*/
270  _assert_(this);
271  _assert_(this->isserved);
272 
273  /*Output*/
274  IssmDouble value = 0.;
275 
276  if(this->isserved_collapsed){
277  if(this->interpolation==P0Enum){
278  value = this->element_values[0];
279  }
280  else{
281  /*Assume P1...*/
282  value = 1./3.*(this->element_values[0] + this->element_values[1] + this->element_values[2]);
283  }
284  }
285  else{
286  int numnodes = this->NumberofNodes(this->interpolation);
287  IssmDouble numnodesd = reCast<int,IssmDouble>(numnodes);
288 
289  for(int i=0;i<numnodes;i++) value+=this->element_values[i];
290  value = value/numnodesd;
291  }
292 
293  *pvalue=value;
294 }/*}}}*/
296  _assert_(this);
297  _assert_(this->isserved);
298 
299  int numnodes = this->NumberofNodes(this->interpolation);
300  if(this->isserved_collapsed) numnodes = 3;
301  IssmDouble min=this->element_values[0];
302 
303  for(int i=1;i<numnodes;i++){
304  if(this->element_values[i]<min) min=this->element_values[i];
305  }
306  return min;
307 }/*}}}*/
309  _assert_(this);
310  _assert_(this->isserved);
311 
312  int numnodes = this->NumberofNodes(this->interpolation);
313  if(this->isserved_collapsed) numnodes = 3;
314  IssmDouble max=this->element_values[0];
315 
316  for(int i=1;i<numnodes;i++){
317  if(this->element_values[i]>max) max=this->element_values[i];
318  }
319  return max;
320 }/*}}}*/
322  _assert_(this);
323  _assert_(this->isserved);
324 
325  int numnodes = this->NumberofNodes(this->interpolation);
326  if(this->isserved_collapsed) numnodes = 3;
327  IssmDouble maxabs=fabs(this->element_values[0]);
328 
329  for(int i=1;i<numnodes;i++){
330  if(fabs(this->element_values[i])>maxabs) maxabs=fabs(this->element_values[i]);
331  }
332  return maxabs;
333 }/*}}}*/
334 void PentaInput2::GetInputDerivativeValue(IssmDouble* derivativevalues, IssmDouble* xyz_list, Gauss* gauss){/*{{{*/
335  _assert_(this);
336  _assert_(this->isserved);
337  if(this->isserved_collapsed){
338  _assert_(gauss->Enum()==GaussTriaEnum);
339  if(this->interpolation==P0Enum){
340  derivativevalues[0] = 0.;
341  derivativevalues[1] = 0.;
342  }
343  else{
344  TriaRef temp;
345  temp.GetInputDerivativeValue(derivativevalues,this->element_values,xyz_list,(GaussTria*)gauss,P1Enum);
346  }
347  }
348  else{
349  _assert_(gauss->Enum()==GaussPentaEnum);
350  PentaRef::GetInputDerivativeValue(derivativevalues,this->element_values,xyz_list,(GaussPenta*)gauss,this->interpolation);
351  }
352 }/*}}}*/
353 void PentaInput2::GetInputValue(IssmDouble* pvalue,Gauss* gauss){/*{{{*/
354  _assert_(this);
355  _assert_(this->isserved);
356  if(this->isserved_collapsed){
357  _assert_(gauss->Enum()==GaussTriaEnum);
358  if(this->interpolation==P0Enum){
359  *pvalue = this->element_values[0];
360  }
361  else{
362  TriaRef temp;
363  temp.GetInputValue(pvalue,this->element_values,(GaussTria*)gauss,P1Enum);
364  }
365  }
366  else{
367  _assert_(gauss->Enum()==GaussPentaEnum);
369  }
370 }/*}}}*/
372  return 1;
373 }
374 /*}}}*/
376  if(this->interpolation==P0Enum || this->interpolation==P0DGEnum){
377  return P0Enum;
378  }
379  return P1Enum;
380 }/*}}}*/
382  return this->N;
383 }
384 /*}}}*/
386 
387  for(int i=0;i<this->M*this->N;i++) this->values[i] = alpha*this->values[i];
388  for(int i=0;i<PentaRef::NumberofNodes(this->interpolation);i++) this->element_values[i] = alpha*this->element_values[i];
389 }
390 /*}}}*/
392 
393  for(int i=0;i<this->M*this->N;i++) this->values[i] = pow(this->values[i],alpha);
394  for(int i=0;i<PentaRef::NumberofNodes(this->interpolation);i++) this->element_values[i] = pow(this->element_values[i],alpha);
395 }
396 /*}}}*/
398 
399  /*xinput is of the same type, so cast it: */
400  if(xinput->ObjectEnum()!=PentaInput2Enum) _error_("Operation not permitted because xinput is of type " << EnumToStringx(xinput->ObjectEnum()));
401  PentaInput2* xpentainput=xDynamicCast<PentaInput2*>(xinput);
402  if(xpentainput->GetInterpolation()!=this->interpolation) _error_("Operation not permitted because xinput is of type " << EnumToStringx(xinput->ObjectEnum()));
403 
404  /*Carry out the AXPY operation depending on type:*/
405  for(int i=0;i<this->M*this->N;i++) this->values[i] = alpha*xpentainput->values[i] + this->values[i];
406  for(int i=0;i<PentaRef::NumberofNodes(this->interpolation);i++) this->element_values[i] = alpha*xpentainput->element_values[i] + this->element_values[i];
407 }
408 /*}}}*/
409 void PentaInput2::PointWiseMult(Input2* xinput){/*{{{*/
410 
411  /*xinput is of the same type, so cast it: */
412  if(xinput->ObjectEnum()!=PentaInput2Enum) _error_("Operation not permitted because xinput is of type " << EnumToStringx(xinput->ObjectEnum()));
413  PentaInput2* xpentainput=xDynamicCast<PentaInput2*>(xinput);
414  if(xpentainput->GetInterpolation()!=this->interpolation) _error_("Operation not permitted because xinput is of type " << EnumToStringx(xinput->ObjectEnum()));
415 
416  /* we need to check that the vector sizes are identical*/
417  if(xpentainput->M!=this->M||xpentainput->N!=this->N) _error_("Operation not permitted because the inputs have different sizes");
418 
419  /*Carry out the pointwise operation depending on type:*/
420  for(int i=0;i<this->M*this->N;i++) this->values[i] = xpentainput->values[i] * this->values[i];
421  for(int i=0;i<PentaRef::NumberofNodes(this->interpolation);i++) this->element_values[i] = xpentainput->element_values[i] * this->element_values[i];
422 }
423 /*}}}*/
424 
425 /*Object functions*/
PentaInput2::GetInputValue
void GetInputValue(IssmDouble *pvalue, Gauss *gauss)
Definition: PentaInput2.cpp:353
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmDouble
double IssmDouble
Definition: types.h:37
PentaInput2::GetResultArraySize
int GetResultArraySize(void)
Definition: PentaInput2.cpp:371
PentaInput2::GetInterpolation
int GetInterpolation()
Definition: PentaInput2.cpp:266
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
PentaInput2::Reset
void Reset(int interp_in)
Definition: PentaInput2.cpp:48
PentaInput2::SetInput
void SetInput(int interp_in, int row, IssmDouble value_in)
Definition: PentaInput2.cpp:154
P0Enum
@ P0Enum
Definition: EnumDefinitions.h:661
PentaInput2::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: PentaInput2.cpp:128
PentaInput2::GetInputDerivativeValue
void GetInputDerivativeValue(IssmDouble *derivativevalues, IssmDouble *xyz_list, Gauss *gauss)
Definition: PentaInput2.cpp:334
PentaInput2::Serve
void Serve(int numindices, int *indices)
Definition: PentaInput2.cpp:208
PentaInput2::AXPY
void AXPY(Input2 *xinput, IssmDouble scalar)
Definition: PentaInput2.cpp:397
ElementInput2::interpolation
int interpolation
Definition: ElementInput2.h:12
PentaInput2::ObjectEnum
int ObjectEnum()
Definition: PentaInput2.cpp:148
PentaInput2::GetInputMin
IssmDouble GetInputMin()
Definition: PentaInput2.cpp:295
ElementInput2::numberofelements_local
int numberofelements_local
Definition: ElementInput2.h:10
P0DGEnum
@ P0DGEnum
Definition: EnumDefinitions.h:1214
MARSHALLING_DYNAMIC
#define MARSHALLING_DYNAMIC(FIELD, TYPE, SIZE)
Definition: Marshalling.h:61
P1Enum
@ P1Enum
Definition: EnumDefinitions.h:662
PentaInput2::Echo
void Echo()
Definition: PentaInput2.cpp:109
GaussTria
Definition: GaussTria.h:12
PentaInput2::PointWiseMult
void PointWiseMult(Input2 *xinput)
Definition: PentaInput2.cpp:409
PentaInput2::ServeCollapsed
void ServeCollapsed(int row, int state)
Definition: PentaInput2.cpp:240
PentaRef::NumberofNodes
int NumberofNodes(int finiteelement)
Definition: PentaRef.cpp:1216
PentaInput2::SetServeCollapsed
void SetServeCollapsed(int)
Definition: PentaInput2.cpp:263
PentaInput2.h
PentaInput2::Scale
void Scale(IssmDouble scalar)
Definition: PentaInput2.cpp:385
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
GaussPenta
Definition: GaussPenta.h:13
PentaInput2::copy
Input2 * copy()
Definition: PentaInput2.cpp:73
PentaInput2::isserved_collapsed
int isserved_collapsed
Definition: PentaInput2.h:11
alpha
IssmDouble alpha(IssmDouble x, IssmDouble y, IssmDouble z, int testid)
Definition: fsanalyticals.cpp:221
MARSHALLING
#define MARSHALLING(FIELD)
Definition: Marshalling.h:29
ElementInput2::values
IssmDouble * values
Definition: ElementInput2.h:15
PentaInput2::Pow
void Pow(IssmDouble scalar)
Definition: PentaInput2.cpp:391
PentaInput2::GetInputMax
IssmDouble GetInputMax()
Definition: PentaInput2.cpp:308
Gauss::Enum
virtual int Enum(void)=0
PentaInput2
Definition: PentaInput2.h:8
TriaRef::GetInputDerivativeValue
void GetInputDerivativeValue(IssmDouble *pp, IssmDouble *plist, IssmDouble *xyz_list, Gauss *gauss, int finiteelement)
Definition: TriaRef.cpp:34
PentaRef::GetInputDerivativeValue
void GetInputDerivativeValue(IssmDouble *pvalues, IssmDouble *plist, IssmDouble *xyz_list, Gauss *gauss, int finiteelement)
Definition: PentaRef.cpp:131
Object::ObjectEnum
virtual int ObjectEnum()=0
Input2
Definition: Input2.h:18
MARSHALLING_BACKWARD
@ MARSHALLING_BACKWARD
Definition: Marshalling.h:10
PentaInput2::Id
int Id()
Definition: PentaInput2.cpp:125
PentaInput2::GetResultNumberOfNodes
int GetResultNumberOfNodes(void)
Definition: PentaInput2.cpp:381
PentaInput2::DeepEcho
void DeepEcho()
Definition: PentaInput2.cpp:86
PentaInput2Enum
@ PentaInput2Enum
Definition: EnumDefinitions.h:1125
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
PentaInput2::GetResultInterpolation
int GetResultInterpolation(void)
Definition: PentaInput2.cpp:375
min
IssmDouble min(IssmDouble a, IssmDouble b)
Definition: extrema.cpp:14
ElementInput2::N
int N
Definition: ElementInput2.h:13
TriaRef::GetInputValue
void GetInputValue(IssmDouble *pp, IssmDouble *plist, Gauss *gauss, int finiteelement)
Definition: TriaRef.cpp:68
GaussTriaEnum
@ GaussTriaEnum
Definition: EnumDefinitions.h:1081
PentaInput2::GetInputAverage
void GetInputAverage(IssmDouble *pvalue)
Definition: PentaInput2.cpp:269
ElementInput2::element_values
IssmDouble * element_values
Definition: ElementInput2.h:18
TriaRef
Definition: TriaRef.h:11
ElementInput2::numberofvertices_local
int numberofvertices_local
Definition: ElementInput2.h:11
ElementInput2::M
int M
Definition: ElementInput2.h:13
max
IssmDouble max(IssmDouble a, IssmDouble b)
Definition: extrema.cpp:24
PentaRef::GetInputValue
void GetInputValue(IssmDouble *pvalue, IssmDouble *plist, Gauss *gauss, int finiteelement)
Definition: PentaRef.cpp:169
PentaInput2::GetInputMaxAbs
IssmDouble GetInputMaxAbs()
Definition: PentaInput2.cpp:321
ElementInput2::isserved
bool isserved
Definition: ElementInput2.h:14
Gauss
Definition: Gauss.h:8
PentaInput2::PentaInput2
PentaInput2()
Definition: PentaInput2.cpp:16
PentaInput2::~PentaInput2
~PentaInput2()
Definition: PentaInput2.cpp:43
GaussPentaEnum
@ GaussPentaEnum
Definition: EnumDefinitions.h:1078