Ice Sheet System Model  4.18
Code documentation
ControlInput2.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 "./ControlInput2.h"
12 #include "./ElementInput2.h"
13 #include "./TriaInput2.h"
14 #include "./PentaInput2.h"
15 //#include "../../toolkits/objects/Vector.h"
16 
17 /*ControlInput2 constructors and destructor*/
19  control_id = 0;
20  values = NULL;
21  savedvalues = NULL;
22  minvalues = NULL;
23  maxvalues = NULL;
24  gradient = NULL;
25 }
26 /*}}}*/
27 ControlInput2::ControlInput2(int nbe, int nbv,int input_layout_enum,int interp,int id){/*{{{*/
28 
29  this->control_id = id;
30  this->layout_enum = input_layout_enum;
31 
32  _assert_(interp==P1Enum);
33 
34  switch(this->layout_enum){
35  case TriaInput2Enum:
36  this->values =new TriaInput2(nbe,nbv,interp);
37  this->savedvalues=new TriaInput2(nbe,nbv,interp);
38  this->minvalues =new TriaInput2(nbe,nbv,interp);
39  this->maxvalues =new TriaInput2(nbe,nbv,interp);
40  this->gradient =new TriaInput2(nbe,nbv,interp);
41  break;
42  case PentaInput2Enum:
43  this->values =new PentaInput2(nbe,nbv,interp);
44  this->savedvalues=new PentaInput2(nbe,nbv,interp);
45  this->minvalues =new PentaInput2(nbe,nbv,interp);
46  this->maxvalues =new PentaInput2(nbe,nbv,interp);
47  this->gradient =new PentaInput2(nbe,nbv,interp);
48  break;
49  default:
50  _error_("Input of Enum \"" << EnumToStringx(input_layout_enum) << "\" not supported yet by ControlInput2");
51  }
52 }
53 /*}}}*/
55  if(values) delete values;
56  if(savedvalues) delete savedvalues;
57  if(minvalues) delete minvalues;
58  if(maxvalues) delete maxvalues;
59  if(gradient) delete gradient;
60 }
61 /*}}}*/
62 
63 /*Object virtual functions definitions:*/
65 
66  ControlInput2* output=NULL;
67 
68  output = new ControlInput2();
69  output->enum_type=this->enum_type;
70  output->control_id=this->control_id;
71  output->layout_enum = this->control_id;
72 
73  if(values) output->values = xDynamicCast<ElementInput2*>(this->values->copy());
74  if(savedvalues) output->savedvalues = xDynamicCast<ElementInput2*>(this->savedvalues->copy());
75  if(minvalues) output->minvalues = xDynamicCast<ElementInput2*>(this->minvalues->copy());
76  if(maxvalues) output->maxvalues = xDynamicCast<ElementInput2*>(this->maxvalues->copy());
77  if(gradient) output->gradient = xDynamicCast<ElementInput2*>(this->gradient->copy());
78 
79  return output;
80 }
81 /*}}}*/
82 void ControlInput2::DeepEcho(void){/*{{{*/
83 
84  _printf_("ControlInput2:\n");
85  _printf_(setw(15)<<" ControlInput2 "<<setw(25)<<left<<EnumToStringx(this->enum_type)<<"\n");
86  _printf_(setw(15)<<" ControlInput2 "<<setw(25)<<left<<EnumToStringx(this->layout_enum)<<"\n");
87  _printf_("---values: \n"); if (values) values->Echo();
88  _printf_("---savedvalues: \n");if (savedvalues) savedvalues->Echo();
89  _printf_("---minvalues: \n"); if (minvalues) minvalues->Echo();
90  _printf_("---maxvalues: \n"); if (maxvalues) maxvalues->Echo();
91  _printf_("---gradient: \n"); if (gradient){ gradient->Echo();} else{_printf_(" Not set yet\n");}
92 }
93 /*}}}*/
94 void ControlInput2::Echo(void){/*{{{*/
95  this->DeepEcho();
96 }
97 /*}}}*/
98 int ControlInput2::Id(void){ return -1; }/*{{{*/
99 /*}}}*/
100 void ControlInput2::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
101 
103  _error_("Not implemented");
104 }
105 /*}}}*/
106 int ControlInput2::ObjectEnum(void){/*{{{*/
107 
108  return ControlInput2Enum;
109 
110 }
111 /*}}}*/
112 
113 void ControlInput2::SetControl(int interp,int numindices,int* indices,IssmDouble* values_in,IssmDouble* values_min,IssmDouble* values_max){/*{{{*/
114 
115  _assert_(this);
116 
117  /*Set input*/
118  //TriaInput2* input = xDynamicCast<TriaInput2*>(this->inputs[id]);
119  this->values->SetInput(interp,numindices,indices,values_in);
120  this->minvalues->SetInput(interp,numindices,indices,values_min);
121  this->maxvalues->SetInput(interp,numindices,indices,values_max);
122 }
123 /*}}}*/
124 void ControlInput2::SetGradient(int interp,int numindices,int* indices,IssmDouble* values_in){/*{{{*/
125 
126  _assert_(this);
127  _assert_(this->gradient);
128  this->gradient->SetInput(interp,numindices,indices,values_in);
129 }
130 /*}}}*/
131 void ControlInput2::SetGradient(int interp,int numindices,int* indices,IssmDouble* values_in,int n){/*{{{*/
132 
133  if(this->values->ObjectEnum()!=TransientInput2Enum)_error_("you are in the wrong place, go home");
134  _assert_(this);
135  _assert_(this->gradient);
136  _error_("S");
137 
138  //TransientInput2* transient_input = xDynamicCast<TransientInput2*>(this->gradient);
139  //TransientInput2* values_input = xDynamicCast<TransientInput2*>(this->values);
140  //if(values_input->numtimesteps==transient_input->numtimesteps){
141  // TransientInput* new_trans_input = new TransientInput2(ControlInputGradEnum);
142  // IssmDouble time = transient_input->GetTimeByOffset(timestep);
143  // for(int i=0;i<transient_input->numtimesteps;i++){
144  // if(transient_input->timesteps[i]==time) new_trans_input->AddTimeInput(xDynamicCast<TriaInput*>(gradient_in),time);
145  // else {
146  // Input2* input = transient_input->GetTimeInput(transient_input->timesteps[i]);
147  // new_trans_input->AddTimeInput(xDynamicCast<TriaInput2*>(input),transient_input->timesteps[i]);
148  // }
149  // }
150  // this->gradient=new_trans_input;
151  //}
152  //else{
153  // IssmDouble time = values_input->GetTimeByOffset(timestep);
154  // transient_input->AddTimeInput(gradient_in,time);
155  //}
156 
157 
158  //NEW??
159  //this->gradient->SetInput(interp,numindices,indices,values_in);
160 }
161 /*}}}*/
163 
164  /*Cast and return*/
165  if(this->values->ObjectEnum()!=TriaInput2Enum){
166  _error_("Cannot return a TriaInput2");
167  }
168  return xDynamicCast<TriaInput2*>(this->values);
169 
170 }
171 /*}}}*/
173 
174  /*Cast and return*/
175  if(this->values->ObjectEnum()!=PentaInput2Enum){
176  _error_("Cannot return a PentaInput2");
177  }
178  return xDynamicCast<PentaInput2*>(this->values);
179 
180 }
181 /*}}}*/
182 ElementInput2* ControlInput2::GetInput2(const char* data){/*{{{*/
183 
184  if(strcmp(data,"value")==0){
185  _assert_(values);
186  return values;
187  }
188  else if(strcmp(data,"savedvalues")==0){
190  return values;
191  }
192  else if (strcmp(data,"lowerbound")==0){
194  return minvalues;
195  }
196  else if (strcmp(data,"upperbound")==0){
198  return maxvalues;
199  }
200  else if (strcmp(data,"gradient")==0){
202  return gradient;
203  }
204  else{
205  _error_("Data " << data << " not supported yet");
206  }
207 
208 }
209 /*}}}*/
ElementInput2::SetInput
virtual void SetInput(int interp_in, int row, IssmDouble value_in)=0
TransientInput2Enum
@ TransientInput2Enum
Definition: EnumDefinitions.h:1315
ControlInput2::ControlInput2
ControlInput2()
Definition: ControlInput2.cpp:18
_assert_
#define _assert_(ignore)
Definition: exceptions.h:37
IssmDouble
double IssmDouble
Definition: types.h:37
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
ControlInput2::copy
Input2 * copy()
Definition: ControlInput2.cpp:64
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
ControlInput2
Definition: ControlInput2.h:13
ControlInput2Enum
@ ControlInput2Enum
Definition: EnumDefinitions.h:1018
ElementInput2.h
ControlInput2::ObjectEnum
int ObjectEnum()
Definition: ControlInput2.cpp:106
ControlInput2::GetTriaInput
TriaInput2 * GetTriaInput()
Definition: ControlInput2.cpp:162
ControlInput2::SetGradient
void SetGradient(int interp, int numindices, int *indices, IssmDouble *values_in)
Definition: ControlInput2.cpp:124
ControlInput2::Echo
void Echo()
Definition: ControlInput2.cpp:94
ElementInput2
Definition: ElementInput2.h:7
P1Enum
@ P1Enum
Definition: EnumDefinitions.h:662
ControlInput2.h
: header file for triavertexinput object
ControlInput2::Id
int Id()
Definition: ControlInput2.cpp:98
TriaInput2.h
ControlInput2::GetInput2
ElementInput2 * GetInput2(const char *data)
Definition: ControlInput2.cpp:182
TriaInput2Enum
@ TriaInput2Enum
Definition: EnumDefinitions.h:1124
ControlInput2::savedvalues
ElementInput2 * savedvalues
Definition: ControlInput2.h:22
PentaInput2.h
ControlInput2::SetControl
void SetControl(int interp, int numindices, int *indices, IssmDouble *values_in, IssmDouble *values_min, IssmDouble *values_max)
Definition: ControlInput2.cpp:113
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
TriaInput2
Definition: TriaInput2.h:8
ElementInput2::Echo
virtual void Echo()=0
PentaInput2
Definition: PentaInput2.h:8
ControlInput2::maxvalues
ElementInput2 * maxvalues
Definition: ControlInput2.h:20
ControlInput2::values
ElementInput2 * values
Definition: ControlInput2.h:23
ControlInput2::GetPentaInput
PentaInput2 * GetPentaInput()
Definition: ControlInput2.cpp:172
Input2
Definition: Input2.h:18
ControlInput2::minvalues
ElementInput2 * minvalues
Definition: ControlInput2.h:21
ControlInput2::enum_type
int enum_type
Definition: ControlInput2.h:17
PentaInput2Enum
@ PentaInput2Enum
Definition: EnumDefinitions.h:1125
ElementInput2::ObjectEnum
virtual int ObjectEnum()=0
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
ControlInput2::~ControlInput2
~ControlInput2()
Definition: ControlInput2.cpp:54
ControlInput2::gradient
ElementInput2 * gradient
Definition: ControlInput2.h:19
ElementInput2::copy
virtual Input2 * copy()=0
ControlInput2::layout_enum
int layout_enum
Definition: ControlInput2.h:18
ControlInput2::DeepEcho
void DeepEcho()
Definition: ControlInput2.cpp:82
ControlInput2::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: ControlInput2.cpp:100
ControlInput2::control_id
int control_id
Definition: ControlInput2.h:16