| [3683] | 1 | /*!\file IntInput.c
|
|---|
| 2 | * \brief: implementation of the IntInput object
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #ifdef HAVE_CONFIG_H
|
|---|
| [9320] | 6 | #include <config.h>
|
|---|
| [3683] | 7 | #else
|
|---|
| 8 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
|---|
| 9 | #endif
|
|---|
| 10 |
|
|---|
| [15012] | 11 | #include "../classes.h"
|
|---|
| 12 | #include "../../shared/shared.h"
|
|---|
| [3683] | 13 |
|
|---|
| [4248] | 14 | /*IntInput constructors and destructor*/
|
|---|
| [18064] | 15 | IntInput::IntInput(){/*{{{*/
|
|---|
| [3683] | 16 | return;
|
|---|
| 17 | }
|
|---|
| 18 | /*}}}*/
|
|---|
| [18064] | 19 | IntInput::IntInput(int in_enum_type,IssmInt in_value){/*{{{*/
|
|---|
| [3683] | 20 |
|
|---|
| 21 | enum_type=in_enum_type;
|
|---|
| 22 | value=in_value;
|
|---|
| 23 | }
|
|---|
| 24 | /*}}}*/
|
|---|
| [18064] | 25 | IntInput::~IntInput(){/*{{{*/
|
|---|
| [3683] | 26 | return;
|
|---|
| 27 | }
|
|---|
| 28 | /*}}}*/
|
|---|
| 29 |
|
|---|
| [4248] | 30 | /*Object virtual functions definitions:*/
|
|---|
| [20827] | 31 | Object* IntInput::copy() {/*{{{*/
|
|---|
| 32 |
|
|---|
| 33 | return new IntInput(this->enum_type,this->value);
|
|---|
| 34 |
|
|---|
| 35 | }
|
|---|
| 36 | /*}}}*/
|
|---|
| [18064] | 37 | void IntInput::DeepEcho(void){/*{{{*/
|
|---|
| [3683] | 38 |
|
|---|
| [16656] | 39 | _printf_(setw(15)<<" IntInput "<<setw(25)<<left<<EnumToStringx(this->enum_type)<<" "<<this->value<<"\n");
|
|---|
| [3683] | 40 | }
|
|---|
| 41 | /*}}}*/
|
|---|
| [19254] | 42 | int IntInput::Id(void){ return -1; }/*{{{*/
|
|---|
| [3683] | 43 | /*}}}*/
|
|---|
| [19254] | 44 | void IntInput::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
|
|---|
| [4248] | 45 |
|
|---|
| [19254] | 46 | MARSHALLING_ENUM(IntInputEnum);
|
|---|
| 47 |
|
|---|
| 48 | MARSHALLING(enum_type);
|
|---|
| 49 | MARSHALLING(value);
|
|---|
| 50 |
|
|---|
| 51 | }
|
|---|
| 52 | /*}}}*/
|
|---|
| [20827] | 53 | int IntInput::ObjectEnum(void){/*{{{*/
|
|---|
| [19254] | 54 |
|
|---|
| [20827] | 55 | return IntInputEnum;
|
|---|
| 56 |
|
|---|
| 57 | }
|
|---|
| 58 | /*}}}*/
|
|---|
| 59 |
|
|---|
| [4248] | 60 | /*IntInput management*/
|
|---|
| [18064] | 61 | void IntInput::Echo(void){/*{{{*/
|
|---|
| [4248] | 62 | this->DeepEcho();
|
|---|
| 63 | }
|
|---|
| 64 | /*}}}*/
|
|---|
| [18064] | 65 | int IntInput::InstanceEnum(void){/*{{{*/
|
|---|
| [4248] | 66 |
|
|---|
| 67 | return this->enum_type;
|
|---|
| 68 |
|
|---|
| 69 | }
|
|---|
| 70 | /*}}}*/
|
|---|
| [20827] | 71 | Input* IntInput::SpawnSegInput(int index1,int index2){/*{{{*/
|
|---|
| [17513] | 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 | /*}}}*/
|
|---|
| [20827] | 84 | Input* IntInput::SpawnTriaInput(int index1,int index2,int index3){/*{{{*/
|
|---|
| [16382] | 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 | /*}}}*/
|
|---|
| [13622] | 97 |
|
|---|
| [3683] | 98 | /*Object functions*/
|
|---|
| [18064] | 99 | void IntInput::AXPY(Input* xinput,IssmDouble scalar){/*{{{*/
|
|---|
| [4048] | 100 |
|
|---|
| [12530] | 101 | IssmDouble dvalue;
|
|---|
| [4048] | 102 | IntInput* xintinput=NULL;
|
|---|
| 103 |
|
|---|
| 104 | /*xinput is of the same type, so cast it: */
|
|---|
| [4050] | 105 | xintinput=(IntInput*)xinput;
|
|---|
| [4048] | 106 |
|
|---|
| [4174] | 107 | /*Carry out the AXPY operation depending on type:*/
|
|---|
| [9883] | 108 | switch(xinput->ObjectEnum()){
|
|---|
| [4048] | 109 |
|
|---|
| [4174] | 110 | case IntInputEnum:
|
|---|
| [12530] | 111 | dvalue=(IssmDouble)this->value+scalar*(IssmDouble)xintinput->value;
|
|---|
| [12555] | 112 | this->value=reCast<int>(dvalue);
|
|---|
| [4174] | 113 | return;
|
|---|
| 114 |
|
|---|
| 115 | default:
|
|---|
| [13056] | 116 | _error_("not implemented yet");
|
|---|
| [4174] | 117 | }
|
|---|
| 118 |
|
|---|
| [4048] | 119 | }
|
|---|
| 120 | /*}}}*/
|
|---|
| [20827] | 121 | void IntInput::ChangeEnum(int newenumtype){/*{{{*/
|
|---|
| 122 | this->enum_type=newenumtype;
|
|---|
| 123 | }
|
|---|
| 124 | /*}}}*/
|
|---|
| 125 | void IntInput::Configure(Parameters* parameters){/*{{{*/
|
|---|
| 126 | /*do nothing: */
|
|---|
| 127 | }
|
|---|
| 128 | /*}}}*/
|
|---|
| [18064] | 129 | void IntInput::Constrain(IssmDouble cm_min, IssmDouble cm_max){/*{{{*/
|
|---|
| [4048] | 130 |
|
|---|
| [12555] | 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);
|
|---|
| [4048] | 133 |
|
|---|
| 134 | }
|
|---|
| 135 | /*}}}*/
|
|---|
| [21759] | 136 | void IntInput::GetInputAverage(IssmDouble* pvalue){/*{{{*/
|
|---|
| 137 | *pvalue=reCast<IssmDouble>(value);
|
|---|
| 138 | }
|
|---|
| 139 | /*}}}*/
|
|---|
| [20827] | 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 | /*}}}*/
|
|---|
| [18064] | 152 | void IntInput::GetVectorFromInputs(Vector<IssmDouble>* vector,int* doflist){/*{{{*/
|
|---|
| [4048] | 153 |
|
|---|
| [13056] | 154 | _error_("not supporte yet!");
|
|---|
| [4048] | 155 |
|
|---|
| 156 | }
|
|---|
| 157 | /*}}}*/
|
|---|
| [20827] | 158 | void IntInput::Scale(IssmDouble scale_factor){/*{{{*/
|
|---|
| 159 | IssmDouble dvalue=(IssmDouble)value*scale_factor;
|
|---|
| 160 | value=reCast<int>(dvalue);
|
|---|
| [8363] | 161 | }
|
|---|
| 162 | /*}}}*/
|
|---|
| [20827] | 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 | /*}}}*/
|
|---|