1 | /*!\file IntInput.c
|
---|
2 | * \brief: implementation of the IntInput object
|
---|
3 | */
|
---|
4 |
|
---|
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 |
|
---|
14 | /*IntInput constructors and destructor*/
|
---|
15 | IntInput::IntInput(){/*{{{*/
|
---|
16 | return;
|
---|
17 | }
|
---|
18 | /*}}}*/
|
---|
19 | IntInput::IntInput(int in_enum_type,IssmInt in_value){/*{{{*/
|
---|
20 |
|
---|
21 | enum_type=in_enum_type;
|
---|
22 | value=in_value;
|
---|
23 | }
|
---|
24 | /*}}}*/
|
---|
25 | IntInput::~IntInput(){/*{{{*/
|
---|
26 | return;
|
---|
27 | }
|
---|
28 | /*}}}*/
|
---|
29 |
|
---|
30 | /*Object virtual functions definitions:*/
|
---|
31 | Object* IntInput::copy() {/*{{{*/
|
---|
32 |
|
---|
33 | return new IntInput(this->enum_type,this->value);
|
---|
34 |
|
---|
35 | }
|
---|
36 | /*}}}*/
|
---|
37 | void IntInput::DeepEcho(void){/*{{{*/
|
---|
38 |
|
---|
39 | _printf_(setw(15)<<" IntInput "<<setw(25)<<left<<EnumToStringx(this->enum_type)<<" "<<this->value<<"\n");
|
---|
40 | }
|
---|
41 | /*}}}*/
|
---|
42 | int IntInput::Id(void){ return -1; }/*{{{*/
|
---|
43 | /*}}}*/
|
---|
44 | void IntInput::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
|
---|
45 |
|
---|
46 | MARSHALLING_ENUM(IntInputEnum);
|
---|
47 |
|
---|
48 | MARSHALLING(enum_type);
|
---|
49 | MARSHALLING(value);
|
---|
50 |
|
---|
51 | }
|
---|
52 | /*}}}*/
|
---|
53 | int IntInput::ObjectEnum(void){/*{{{*/
|
---|
54 |
|
---|
55 | return IntInputEnum;
|
---|
56 |
|
---|
57 | }
|
---|
58 | /*}}}*/
|
---|
59 |
|
---|
60 | /*IntInput management*/
|
---|
61 | void IntInput::Echo(void){/*{{{*/
|
---|
62 | this->DeepEcho();
|
---|
63 | }
|
---|
64 | /*}}}*/
|
---|
65 | int IntInput::InstanceEnum(void){/*{{{*/
|
---|
66 |
|
---|
67 | return this->enum_type;
|
---|
68 |
|
---|
69 | }
|
---|
70 | /*}}}*/
|
---|
71 | Input* IntInput::SpawnSegInput(int index1,int index2){/*{{{*/
|
---|
72 |
|
---|
73 | /*output*/
|
---|
74 | IntInput* outinput=new IntInput();
|
---|
75 |
|
---|
76 | /*only copy current value*/
|
---|
77 | outinput->enum_type=this->enum_type;
|
---|
78 | outinput->value=this->value;
|
---|
79 |
|
---|
80 | /*Assign output*/
|
---|
81 | return outinput;
|
---|
82 | }
|
---|
83 | /*}}}*/
|
---|
84 | Input* IntInput::SpawnTriaInput(int index1,int index2,int index3){/*{{{*/
|
---|
85 |
|
---|
86 | /*output*/
|
---|
87 | IntInput* outinput=new IntInput();
|
---|
88 |
|
---|
89 | /*only copy current value*/
|
---|
90 | outinput->enum_type=this->enum_type;
|
---|
91 | outinput->value=this->value;
|
---|
92 |
|
---|
93 | /*Assign output*/
|
---|
94 | return outinput;
|
---|
95 | }
|
---|
96 | /*}}}*/
|
---|
97 |
|
---|
98 | /*Object functions*/
|
---|
99 | void IntInput::AXPY(Input* xinput,IssmDouble scalar){/*{{{*/
|
---|
100 |
|
---|
101 | IssmDouble dvalue;
|
---|
102 | IntInput* xintinput=NULL;
|
---|
103 |
|
---|
104 | /*xinput is of the same type, so cast it: */
|
---|
105 | xintinput=(IntInput*)xinput;
|
---|
106 |
|
---|
107 | /*Carry out the AXPY operation depending on type:*/
|
---|
108 | switch(xinput->ObjectEnum()){
|
---|
109 |
|
---|
110 | case IntInputEnum:
|
---|
111 | dvalue=(IssmDouble)this->value+scalar*(IssmDouble)xintinput->value;
|
---|
112 | this->value=reCast<int>(dvalue);
|
---|
113 | return;
|
---|
114 |
|
---|
115 | default:
|
---|
116 | _error_("not implemented yet");
|
---|
117 | }
|
---|
118 |
|
---|
119 | }
|
---|
120 | /*}}}*/
|
---|
121 | void IntInput::ChangeEnum(int newenumtype){/*{{{*/
|
---|
122 | this->enum_type=newenumtype;
|
---|
123 | }
|
---|
124 | /*}}}*/
|
---|
125 | void IntInput::Configure(Parameters* parameters){/*{{{*/
|
---|
126 | /*do nothing: */
|
---|
127 | }
|
---|
128 | /*}}}*/
|
---|
129 | void IntInput::Constrain(IssmDouble cm_min, IssmDouble cm_max){/*{{{*/
|
---|
130 |
|
---|
131 | if(!xIsNan<IssmDouble>(cm_min)) if (this->value<cm_min)this->value=reCast<int>(cm_min);
|
---|
132 | if(!xIsNan<IssmDouble>(cm_max)) if (this->value>cm_max)this->value=reCast<int>(cm_max);
|
---|
133 |
|
---|
134 | }
|
---|
135 | /*}}}*/
|
---|
136 | void IntInput::GetInputAverage(IssmDouble* pvalue){/*{{{*/
|
---|
137 | *pvalue=reCast<IssmDouble>(value);
|
---|
138 | }
|
---|
139 | /*}}}*/
|
---|
140 | void IntInput::GetInputValue(bool* pvalue){_error_("not supported yet!");}/*{{{*/
|
---|
141 | /*}}}*/
|
---|
142 | void IntInput::GetInputValue(int* pvalue){/*{{{*/
|
---|
143 | *pvalue=value;
|
---|
144 | }
|
---|
145 | /*}}}*/
|
---|
146 | void IntInput::GetInputValue(IssmDouble* pvalue){/*{{{*/
|
---|
147 | _error_("IntInput cannot return a IssmDouble in parallel");
|
---|
148 | }
|
---|
149 | /*}}}*/
|
---|
150 | void IntInput::GetInputValue(IssmDouble* pvalue,Gauss* gauss){_error_("not supported yet!");}/*{{{*/
|
---|
151 | /*}}}*/
|
---|
152 | void IntInput::GetVectorFromInputs(Vector<IssmDouble>* vector,int* doflist){/*{{{*/
|
---|
153 |
|
---|
154 | _error_("not supporte yet!");
|
---|
155 |
|
---|
156 | }
|
---|
157 | /*}}}*/
|
---|
158 | void IntInput::Scale(IssmDouble scale_factor){/*{{{*/
|
---|
159 | IssmDouble dvalue=(IssmDouble)value*scale_factor;
|
---|
160 | value=reCast<int>(dvalue);
|
---|
161 | }
|
---|
162 | /*}}}*/
|
---|
163 | void IntInput::SquareMin(IssmDouble* psquaremin,Parameters* parameters){/*{{{*/
|
---|
164 |
|
---|
165 | /*square min of an integer is the square of the integer itself: */
|
---|
166 | *psquaremin=pow((IssmDouble)value,2);
|
---|
167 | }
|
---|
168 | /*}}}*/
|
---|