Ice Sheet System Model  4.18
Code documentation
Massfluxatgate.h
Go to the documentation of this file.
1 
5 #ifndef _MASSFLUXATGATE_H_
6 #define _MASSFLUXATGATE_H_
7 
8 /*Headers:*/
9 /*{{{*/
10 #include "./Definition.h"
11 #include "../datastructures/datastructures.h"
12 #include "./Elements/Element.h"
13 #include "./Elements/Elements.h"
14 #include "./FemModel.h"
15 /*}}}*/
16 
17 template <class doubletype>
18 class Massfluxatgate: public Object, public Definition{
19 
20  public:
21 
23  char* name;
25  doubletype *x1;
26  doubletype *y1;
27  doubletype *x2;
28  doubletype *y2;
29  int* elements;
30 
31  /*Massfluxatgate constructors, destructors :*/
32  Massfluxatgate(){/*{{{*/
33  this->definitionenum = -1;
34  this->name = 0;
35  this->numsegments = 0;
36  this->segments = 0;
37  }
38  /*}}}*/
39  Massfluxatgate(char* in_name, int in_definitionenum, int in_numsegments, doubletype* in_segments) {/*{{{*/
40 
41  int i;
42 
43  this->definitionenum=in_definitionenum;
44 
45  this->name = xNew<char>(strlen(in_name)+1);
46  xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
47 
48  this->numsegments=in_numsegments;
49 
50  if(this->numsegments){
51  this->x1=xNew<doubletype>(this->numsegments);
52  this->x2=xNew<doubletype>(this->numsegments);
53  this->y1=xNew<doubletype>(this->numsegments);
54  this->y2=xNew<doubletype>(this->numsegments);
55  this->elements=xNew<int>(this->numsegments);
56 
57  for(i=0;i<this->numsegments;i++){
58  this->x1[i]=in_segments[5*i+0];
59  this->y1[i]=in_segments[5*i+1];
60  this->x2[i]=in_segments[5*i+2];
61  this->y2[i]=in_segments[5*i+3];
62  this->elements[i]=reCast<int,doubletype>(in_segments[5*i+4]);
63  }
64  }
65  }
66  /*}}}*/
67  Massfluxatgate(char* in_name, int in_definitionenum, int in_numsegments, doubletype* in_x1, doubletype* in_y1, doubletype* in_x2, doubletype* in_y2,int* in_elements){/*{{{*/
68 
69  this->definitionenum=in_definitionenum;
70  this->name = xNew<char>(strlen(in_name)+1);
71  xMemCpy<char>(this->name,in_name,strlen(in_name)+1);
72 
73  this->numsegments=in_numsegments;
74 
75  if(this->numsegments){
76  this->x1=xNew<doubletype>(this->numsegments); xMemCpy<doubletype>(this->x1,in_x1,this->numsegments);
77  this->y1=xNew<doubletype>(this->numsegments); xMemCpy<doubletype>(this->y1,in_y1,this->numsegments);
78  this->x2=xNew<doubletype>(this->numsegments); xMemCpy<doubletype>(this->x2,in_x2,this->numsegments);
79  this->y2=xNew<doubletype>(this->numsegments); xMemCpy<doubletype>(this->y2,in_y2,this->numsegments);
80  this->elements=xNew<int>(this->numsegments); xMemCpy<int>(this->elements,in_elements,this->numsegments);
81 
82  }
83  }
84  /*}}}*/
85  ~Massfluxatgate(){/*{{{*/
86  if(this->numsegments){
87  xDelete<doubletype>(this->x1);
88  xDelete<doubletype>(this->y1);
89  xDelete<doubletype>(this->x2);
90  xDelete<doubletype>(this->y2);
91  xDelete<int>(this->elements);
92  }
93  xDelete<char>(this->name);
94  }
95  /*}}}*/
96 
97  /*Object virtual function resolutoin: */
98  Object* copy() {/*{{{*/
99  return new Massfluxatgate(this->name,this->definitionenum,this->numsegments,this->x1,this->y1,this->x2,this->y2,this->elements);
100  }
101  /*}}}*/
102  void DeepEcho(void){/*{{{*/
103  this->Echo();
104  }
105  /*}}}*/
106  void Echo(void){/*{{{*/
107  _printf_(" Massfluxatgate: " << name << " " << this->definitionenum << "\n");
108  _printf_(" numsegments: " << numsegments << "\n");
109  if(numsegments){
110  _printf_(" element: x1, y1, x2, y2:\n");
111  for(int i=0;i<numsegments;i++){
112  _printf_(elements[i] << " " << x1[i] << " " << y1[i] << " " << x2[i] << " " << y2[i] << "\n");
113  }
114  }
115  }
116  /*}}}*/
117  int Id(void){/*{{{*/
118  return -1;
119  }
120  /*}}}*/
121  int ObjectEnum(void){/*{{{*/
122  return MassfluxatgateEnum;
123  }
124  /*}}}*/
125  void Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){/*{{{*/
126  _error_("not implemented yet!");
127  }
128  /*}}}*/
129  /*Definition virtual function resolutoin: */
130  int DefinitionEnum(){/*{{{*/
131 
132  return this->definitionenum;
133  }
134  /*}}}*/
135  char* Name(){/*{{{*/
136 
137  char* name2=xNew<char>(strlen(this->name)+1);
138  xMemCpy(name2,this->name,strlen(this->name)+1);
139 
140  return name2;
141  }
142  /*}}}*/
144 
145  int i,j;
146  Element *element = NULL;
147  IssmDouble mass_flux = 0;
148  IssmDouble all_mass_flux = 0;
149 
150  /*Go through segments, and then elements, and figure out which elements belong to a segment.
151  * When we find one, use the element to compute the mass flux on the segment: */
152  for(i=0;i<numsegments;i++){
153  for(j=0;j<femmodel->elements->Size();j++){
155  if (element->Id()==this->elements[i]){
156  /*We found the element which owns this segment, use it to compute the mass flux: */
157  mass_flux+=element->MassFlux(x1[i],y1[i],x2[i],y2[i],elements[i]);
158  break;
159  }
160  }
161  }
162 
163  ISSM_MPI_Allreduce ( (void*)&mass_flux,(void*)&all_mass_flux,1,ISSM_MPI_DOUBLE,ISSM_MPI_SUM,IssmComm::GetComm());
164  mass_flux=all_mass_flux;
165  return mass_flux;
166  }
167  /*}}}*/
168 };
169 
170 #endif /* _MASSFLUXATGATE_H_ */
DataSet::Size
int Size()
Definition: DataSet.cpp:399
Massfluxatgate
Definition: Massfluxatgate.h:18
Massfluxatgate::x2
doubletype * x2
Definition: Massfluxatgate.h:27
Massfluxatgate::y1
doubletype * y1
Definition: Massfluxatgate.h:26
Massfluxatgate::ObjectEnum
int ObjectEnum(void)
Definition: Massfluxatgate.h:121
IssmDouble
double IssmDouble
Definition: types.h:37
ISSM_MPI_Allreduce
int ISSM_MPI_Allreduce(void *sendbuf, void *recvbuf, int count, ISSM_MPI_Datatype datatype, ISSM_MPI_Op op, ISSM_MPI_Comm comm)
Definition: issmmpi.cpp:116
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
Massfluxatgate::Massfluxatgate
Massfluxatgate()
Definition: Massfluxatgate.h:32
ISSM_MPI_SUM
#define ISSM_MPI_SUM
Definition: issmmpi.h:134
IssmComm::GetComm
static ISSM_MPI_Comm GetComm(void)
Definition: IssmComm.cpp:30
Massfluxatgate::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: Massfluxatgate.h:125
Massfluxatgate::Id
int Id(void)
Definition: Massfluxatgate.h:117
Element::MassFlux
virtual IssmDouble MassFlux(IssmDouble *segment)=0
Massfluxatgate::Response
IssmDouble Response(FemModel *femmodel)
Definition: Massfluxatgate.h:143
Massfluxatgate::definitionenum
int definitionenum
Definition: Massfluxatgate.h:22
MassfluxatgateEnum
@ MassfluxatgateEnum
Definition: EnumDefinitions.h:1162
Element
Definition: Element.h:41
Elements.h
Massfluxatgate::name
char * name
Definition: Massfluxatgate.h:23
Massfluxatgate::Massfluxatgate
Massfluxatgate(char *in_name, int in_definitionenum, int in_numsegments, doubletype *in_x1, doubletype *in_y1, doubletype *in_x2, doubletype *in_y2, int *in_elements)
Definition: Massfluxatgate.h:67
ISSM_MPI_DOUBLE
#define ISSM_MPI_DOUBLE
Definition: issmmpi.h:125
Element.h
abstract class for Element object This class is a place holder for the Tria and the Penta elements....
Object
Definition: Object.h:13
Massfluxatgate::y2
doubletype * y2
Definition: Massfluxatgate.h:28
Element::Id
int Id()
Definition: Element.cpp:1620
Massfluxatgate::~Massfluxatgate
~Massfluxatgate()
Definition: Massfluxatgate.h:85
Massfluxatgate::DeepEcho
void DeepEcho(void)
Definition: Massfluxatgate.h:102
Definition
Definition: Definition.h:10
Massfluxatgate::DefinitionEnum
int DefinitionEnum()
Definition: Massfluxatgate.h:130
FemModel::elements
Elements * elements
Definition: FemModel.h:44
Massfluxatgate::Massfluxatgate
Massfluxatgate(char *in_name, int in_definitionenum, int in_numsegments, doubletype *in_segments)
Definition: Massfluxatgate.h:39
Massfluxatgate::elements
int * elements
Definition: Massfluxatgate.h:29
FemModel
Definition: FemModel.h:31
Massfluxatgate::Name
char * Name()
Definition: Massfluxatgate.h:135
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
DataSet::GetObjectByOffset
Object * GetObjectByOffset(int offset)
Definition: DataSet.cpp:334
FemModel.h
Massfluxatgate::x1
doubletype * x1
Definition: Massfluxatgate.h:25
Massfluxatgate::Echo
void Echo(void)
Definition: Massfluxatgate.h:106
Massfluxatgate::copy
Object * copy()
Definition: Massfluxatgate.h:98
Definition.h
xMemCpy
T * xMemCpy(T *dest, const T *src, unsigned int size)
Definition: MemOps.h:152
Massfluxatgate::numsegments
int numsegments
Definition: Massfluxatgate.h:24
femmodel
FemModel * femmodel
Definition: esmfbinders.cpp:16