Ice Sheet System Model  4.18
Code documentation
DatasetInput2.cpp
Go to the documentation of this file.
1 
4 /*Headers*/
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 "./DatasetInput2.h"
12 #include "./TriaInput2.h"
13 #include "./PentaInput2.h"
14 #include "./TransientInput2.h"
15 
16 /*DatasetInput2 constructors and destructor*/
18  this->inputs = NULL;
19  this->numids = 0;
20  this->ids = NULL;
21  this->numberofelements_local = -1;
22  this->numberofvertices_local = -1;
23 }
24 /*}}}*/
25 DatasetInput2::DatasetInput2(int nbe, int nbv){/*{{{*/
26  this->inputs = NULL;
27  this->numids = 0;
28  this->ids = NULL;
29  this->numberofelements_local = nbe;
30  this->numberofvertices_local = nbv;
31 }
32 /*}}}*/
34  xDelete<int>(this->ids);
35  for(int i=0;i<this->numids;i++){
36  delete this->inputs[i];
37  }
38  xDelete<Input2*>(this->inputs);
39 }
40 /*}}}*/
41 
42 /*Object virtual functions definitions:*/
44 
45  DatasetInput2* output=NULL;
46 
47  output = new DatasetInput2();
48  output->numids=this->numids;
49  if(this->numids>0){
50  output->ids=xNew<int>(output->numids);
51  xMemCpy(output->ids,this->ids,output->numids);
52  output->inputs = xNew<Input2*>(this->numids);
53  for(int i=0;i<this->numids;i++){
54  output->inputs[i] = this->inputs[i]->copy();
55  }
56  }
57 
58  return output;
59 }
60 /*}}}*/
61 void DatasetInput2::Configure(Parameters* params){/*{{{*/
62  for(int i=0;i<this->numids;i++){
63  this->inputs[i]->Configure(params);
64  }
65 }
66 /*}}}*/
67 void DatasetInput2::DeepEcho(void){/*{{{*/
68 
69  _printf_("DatasetInput2:\n");
70  _printf_(" numids:"<< this->numids<< "\n");
71  _printf_(" ids: ");
72  for(int i=0;i<this->numids;i++) _printf_(this->ids[i]<<" ("<<EnumToStringx(this->ids[i])<<") ");
73  _printf_("\n");
74  //_printf_(" inputs: \n"); inputs->Echo();
75 }
76 /*}}}*/
77 void DatasetInput2::Echo(void){/*{{{*/
78  this->DeepEcho();
79 }
80 /*}}}*/
81 int DatasetInput2::Id(void){ return -1; }/*{{{*/
82 /*}}}*/
83 void DatasetInput2::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
84 
86 
91  //if (marshall_direction == MARSHALLING_BACKWARD) inputs = new Inputs();
92  //inputs->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
93  _error_("not implemented");
94 
95 }
96 /*}}}*/
97 int DatasetInput2::ObjectEnum(void){/*{{{*/
98  return DatasetInput2Enum;
99 }/*}}}*/
100 
101 void DatasetInput2::SetTriaInput(int id,int interp_in,int numinds,int* rows,IssmDouble* values_in){ /*{{{*/
102 
103  int index = -1;
104  for(int i=0;i<this->numids;i++){
105  if(this->ids[i] == id) index = i;
106  }
107 
108  /*Create new input if not found*/
109  if(index == -1){
110  int* new_ids = xNew<int>(this->numids+1);
111  if(this->numids) xMemCpy(new_ids,this->ids,this->numids);
112  new_ids[this->numids] = id;
113 
114  Input2** new_inputs = xNew<Input2*>(this->numids+1);
115  if(this->numids) xMemCpy(new_inputs,this->inputs,this->numids);
116  new_inputs[this->numids] = new TriaInput2(this->numberofelements_local,this->numberofvertices_local,interp_in);
117  index = this->numids;
118 
119  xDelete<int>(this->ids);
120  this->ids = new_ids;
121  xDelete<Input2*>(this->inputs);
122  this->inputs = new_inputs;
123 
124  this->numids ++;
125  }
126 
127  /*Set input*/
128  if(this->inputs[index]->ObjectEnum()!=TriaInput2Enum) _error_("cannot add Element values to a "<<EnumToStringx(this->inputs[index]->ObjectEnum()));
129  TriaInput2* input = xDynamicCast<TriaInput2*>(this->inputs[index]);
130  input->SetInput(interp_in,numinds,rows,values_in);
131 
132 }
133 /*}}}*/
134 void DatasetInput2::SetPentaInput(int id,int interp_in,int numinds,int* rows,IssmDouble* values_in){ /*{{{*/
135 
136  int index = -1;
137  for(int i=0;i<this->numids;i++){
138  if(this->ids[i] == id) index = i;
139  }
140 
141  /*Create new input if not found*/
142  if(index == -1){
143  int* new_ids = xNew<int>(this->numids+1);
144  if(this->numids) xMemCpy(new_ids,this->ids,this->numids);
145  new_ids[this->numids] = id;
146 
147  Input2** new_inputs = xNew<Input2*>(this->numids+1);
148  if(this->numids) xMemCpy(new_inputs,this->inputs,this->numids);
149  new_inputs[this->numids] = new PentaInput2(this->numberofelements_local,this->numberofvertices_local,interp_in);
150  index = this->numids;
151 
152  xDelete<int>(this->ids);
153  this->ids = new_ids;
154  xDelete<Input2*>(this->inputs);
155  this->inputs = new_inputs;
156 
157  this->numids ++;
158  }
159 
160  /*Set input*/
161  if(this->inputs[index]->ObjectEnum()!=PentaInput2Enum) _error_("cannot add Element values to a "<<EnumToStringx(this->inputs[index]->ObjectEnum()));
162  PentaInput2* input = xDynamicCast<PentaInput2*>(this->inputs[index]);
163  input->SetInput(interp_in,numinds,rows,values_in);
164 
165 }
166 /*}}}*/
167 TransientInput2* DatasetInput2::SetTransientInput(int id,IssmDouble* times,int numtimes){ /*{{{*/
168 
169  int index = -1;
170  for(int i=0;i<this->numids;i++){
171  if(this->ids[i] == id) index = i;
172  }
173 
174  /*Create new input if not found*/
175  if(index == -1){
176  int* new_ids = xNew<int>(this->numids+1);
177  if(this->numids) xMemCpy(new_ids,this->ids,this->numids);
178  new_ids[this->numids] = id;
179 
180  Input2** new_inputs = xNew<Input2*>(this->numids+1);
181  if(this->numids) xMemCpy(new_inputs,this->inputs,this->numids);
182  new_inputs[this->numids] = new TransientInput2(NoneEnum,this->numberofelements_local,this->numberofvertices_local,times,numtimes);
183  index = this->numids;
184 
185  xDelete<int>(this->ids);
186  this->ids = new_ids;
187  xDelete<Input2*>(this->inputs);
188  this->inputs = new_inputs;
189 
190  this->numids ++;
191  }
192 
193  /*Set input*/
194  if(this->inputs[index]->ObjectEnum()!=TransientInput2Enum) _error_("cannot add values to a "<<EnumToStringx(this->inputs[index]->ObjectEnum()));
195  TransientInput2* input = xDynamicCast<TransientInput2*>(this->inputs[index]);
196  return input;
197 }
198 /*}}}*/
199 void DatasetInput2::GetInputValue(IssmDouble* pvalue,Gauss* gauss,int id){ /*{{{*/
200 
201  int index = -1;
202  for(int i=0;i<this->numids;i++){
203  if(this->ids[i] == id) index = i;
204  }
205 
206  /*Create new input if not found*/
207  if(index == -1){
208  this->Echo();
209  _error_("Could not find input "<<id<<" ("<<EnumToStringx(id)<<"?) in DatasetInput");
210  }
211 
212  Input2* input = this->inputs[index];
213 
214  if(this->inputs[index]->ObjectEnum()==TransientInput2Enum){
215  input = xDynamicCast<TransientInput2*>(this->inputs[index])->current_input;
216  }
217 
218  input->GetInputValue(pvalue,gauss);
219 
220 }
221 /*}}}*/
223 
224  _assert_(offset>=0 && offset<this->numids);
225  _assert_(this->inputs[offset]);
226 
227  /*Cast and return*/
228  if(this->inputs[offset]->ObjectEnum()==TransientInput2Enum){
229  return xDynamicCast<TransientInput2*>(this->inputs[offset])->GetTriaInput();
230  }
231  if(this->inputs[offset]->ObjectEnum()!=TriaInput2Enum){
232  _error_("Cannot return a TriaInput2");
233  }
234  return xDynamicCast<TriaInput2*>(this->inputs[offset]);
235 
236 }/*}}}*/
238 
239  _assert_(offset>=0 && offset<this->numids);
240  _assert_(this->inputs[offset]);
241 
242  /*Cast and return*/
243  if(this->inputs[offset]->ObjectEnum()==TransientInput2Enum){
244  return xDynamicCast<TransientInput2*>(this->inputs[offset])->GetPentaInput();
245  }
246  if(this->inputs[offset]->ObjectEnum()!=PentaInput2Enum){
247  _error_("Cannot return a PentaInput2");
248  }
249  return xDynamicCast<PentaInput2*>(this->inputs[offset]);
250 
251 }/*}}}*/
DatasetInput2::Echo
void Echo()
Definition: DatasetInput2.cpp:77
TransientInput2Enum
@ TransientInput2Enum
Definition: EnumDefinitions.h:1315
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
DatasetInput2::numids
int numids
Definition: DatasetInput2.h:17
IssmDouble
double IssmDouble
Definition: types.h:37
DatasetInput2
Definition: DatasetInput2.h:14
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
DatasetInput2Enum
@ DatasetInput2Enum
Definition: EnumDefinitions.h:1031
Parameters
Declaration of Parameters class.
Definition: Parameters.h:18
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
DatasetInput2::Id
int Id()
Definition: DatasetInput2.cpp:81
PentaInput2::SetInput
void SetInput(int interp_in, int row, IssmDouble value_in)
Definition: PentaInput2.cpp:154
TransientInput2
Definition: TransientInput2.h:13
DatasetInput2::Configure
void Configure(Parameters *params)
Definition: DatasetInput2.cpp:61
Input2::copy
virtual Input2 * copy()=0
DatasetInput2::GetInputValue
void GetInputValue(IssmDouble *pvalue, Gauss *gauss, int index)
Definition: DatasetInput2.cpp:199
DatasetInput2::SetPentaInput
void SetPentaInput(int id, int interp_in, int numinds, int *rows, IssmDouble *values_in)
Definition: DatasetInput2.cpp:134
DatasetInput2::SetTriaInput
void SetTriaInput(int interp_in, int numinds, int *rows, IssmDouble *values_in)
MARSHALLING_DYNAMIC
#define MARSHALLING_DYNAMIC(FIELD, TYPE, SIZE)
Definition: Marshalling.h:61
TriaInput2.h
TriaInput2Enum
@ TriaInput2Enum
Definition: EnumDefinitions.h:1124
PentaInput2.h
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
TriaInput2
Definition: TriaInput2.h:8
DatasetInput2::numberofvertices_local
int numberofvertices_local
Definition: DatasetInput2.h:21
MARSHALLING
#define MARSHALLING(FIELD)
Definition: Marshalling.h:29
DatasetInput2::GetPentaInputByOffset
PentaInput2 * GetPentaInputByOffset(int i)
Definition: DatasetInput2.cpp:237
DatasetInput2::numberofelements_local
int numberofelements_local
Definition: DatasetInput2.h:20
DatasetInput2::copy
Input2 * copy()
Definition: DatasetInput2.cpp:43
PentaInput2
Definition: PentaInput2.h:8
Input2::Configure
virtual void Configure(Parameters *parameters)
Definition: Input2.h:30
Input2
Definition: Input2.h:18
DatasetInput2::DeepEcho
void DeepEcho()
Definition: DatasetInput2.cpp:67
DatasetInput2::SetTransientInput
TransientInput2 * SetTransientInput(int id, IssmDouble *times, int numtimes)
Definition: DatasetInput2.cpp:167
PentaInput2Enum
@ PentaInput2Enum
Definition: EnumDefinitions.h:1125
NoneEnum
@ NoneEnum
Definition: EnumDefinitions.h:1202
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
DatasetInput2::DatasetInput2
DatasetInput2()
Definition: DatasetInput2.cpp:17
TriaInput2::SetInput
void SetInput(int interp_in, int row, IssmDouble value_in)
Definition: TriaInput2.cpp:141
Input2::GetInputValue
virtual void GetInputValue(IssmDouble *pvalue, Gauss *gauss)
Definition: Input2.h:38
TransientInput2.h
: header file for transientinput object
xMemCpy
T * xMemCpy(T *dest, const T *src, unsigned int size)
Definition: MemOps.h:152
DatasetInput2::ObjectEnum
int ObjectEnum()
Definition: DatasetInput2.cpp:97
Gauss
Definition: Gauss.h:8
DatasetInput2.h
: header file for datasetinput object
DatasetInput2::inputs
Input2 ** inputs
Definition: DatasetInput2.h:18
DatasetInput2::ids
int * ids
Definition: DatasetInput2.h:19
DatasetInput2::GetTriaInputByOffset
TriaInput2 * GetTriaInputByOffset(int i)
Definition: DatasetInput2.cpp:222
DatasetInput2::~DatasetInput2
~DatasetInput2()
Definition: DatasetInput2.cpp:33
DatasetInput2::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: DatasetInput2.cpp:83