[3702] | 1 | /*
|
---|
| 2 | * \file Inputs.c
|
---|
| 3 | * \brief: implementation of the Inputs class, derived from DataSet class
|
---|
| 4 | */
|
---|
| 5 |
|
---|
[12365] | 6 | /*Headers: {{{*/
|
---|
[3702] | 7 | #ifdef HAVE_CONFIG_H
|
---|
[9320] | 8 | #include <config.h>
|
---|
[3702] | 9 | #else
|
---|
| 10 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[14953] | 13 | #include "./Inputs.h"
|
---|
| 14 | #include "../classes/objects/Inputs/Input.h"
|
---|
[3702] | 15 | #include "../shared/shared.h"
|
---|
[14960] | 16 | #include "../shared/Enum/Enum.h"
|
---|
[3702] | 17 |
|
---|
| 18 | using namespace std;
|
---|
| 19 | /*}}}*/
|
---|
| 20 |
|
---|
| 21 | /*Object constructors and destructor*/
|
---|
[12365] | 22 | /*FUNCTION Inputs::Inputs(){{{*/
|
---|
[3702] | 23 | Inputs::Inputs(){
|
---|
| 24 | return;
|
---|
| 25 | }
|
---|
| 26 | /*}}}*/
|
---|
[12365] | 27 | /*FUNCTION Inputs::~Inputs(){{{*/
|
---|
[3702] | 28 | Inputs::~Inputs(){
|
---|
| 29 | return;
|
---|
| 30 | }
|
---|
| 31 | /*}}}*/
|
---|
| 32 |
|
---|
| 33 | /*Object management*/
|
---|
[12365] | 34 | /*FUNCTION Inputs::GetInputValue(bool* pvalue,int enum-type){{{*/
|
---|
[10135] | 35 | void Inputs::GetInputValue(bool* pvalue,int enum_type){
|
---|
[3702] | 36 |
|
---|
| 37 | vector<Object*>::iterator object;
|
---|
| 38 | Input* input=NULL;
|
---|
[3861] | 39 | bool found=false;
|
---|
[3702] | 40 |
|
---|
| 41 | /*Go through inputs and check whether any input with the same name is already in: */
|
---|
| 42 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 43 |
|
---|
[13797] | 44 | input=dynamic_cast<Input*>(*object);
|
---|
[9883] | 45 | if (input->InstanceEnum()==enum_type){
|
---|
[3861] | 46 | found=true;
|
---|
| 47 | break;
|
---|
| 48 | }
|
---|
[3702] | 49 | }
|
---|
| 50 |
|
---|
[3861] | 51 | if (!found){
|
---|
[3702] | 52 | /*we could not find an input with the correct enum type. No defaults values were provided,
|
---|
| 53 | * error out: */
|
---|
[13056] | 54 | _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")");
|
---|
[3702] | 55 | }
|
---|
| 56 |
|
---|
[4547] | 57 | /*Ok, we have an input if we made it here, request the input to return the value: */
|
---|
[10135] | 58 | input->GetInputValue(pvalue);
|
---|
[4547] | 59 |
|
---|
[3702] | 60 | }
|
---|
| 61 | /*}}}*/
|
---|
[12365] | 62 | /*FUNCTION Inputs::GetInputValue(int* pvalue,int enum-type){{{*/
|
---|
[10135] | 63 | void Inputs::GetInputValue(int* pvalue,int enum_type){
|
---|
[3702] | 64 |
|
---|
| 65 | vector<Object*>::iterator object;
|
---|
| 66 | Input* input=NULL;
|
---|
[3861] | 67 | bool found=false;
|
---|
[3702] | 68 |
|
---|
| 69 | /*Go through inputs and check whether any input with the same name is already in: */
|
---|
| 70 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 71 |
|
---|
[13797] | 72 | input=dynamic_cast<Input*>(*object);
|
---|
[9883] | 73 | if (input->InstanceEnum()==enum_type){
|
---|
[3861] | 74 | found=true;
|
---|
| 75 | break;
|
---|
| 76 | }
|
---|
[3702] | 77 | }
|
---|
| 78 |
|
---|
[3861] | 79 | if (!found){
|
---|
[4547] | 80 | /*we could not find an input with the correct enum type. No defaults values were provided,
|
---|
| 81 | * error out: */
|
---|
[13056] | 82 | _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")");
|
---|
[3702] | 83 | }
|
---|
| 84 |
|
---|
[4547] | 85 | /*Ok, we have an input if we made it here, request the input to return the value: */
|
---|
[10135] | 86 | input->GetInputValue(pvalue);
|
---|
[4547] | 87 |
|
---|
[3702] | 88 | }
|
---|
| 89 | /*}}}*/
|
---|
[12466] | 90 | /*FUNCTION Inputs::GetInputValue(IssmDouble* pvalue,int enum-type){{{*/
|
---|
| 91 | void Inputs::GetInputValue(IssmDouble* pvalue,int enum_type){
|
---|
[3830] | 92 |
|
---|
| 93 | vector<Object*>::iterator object;
|
---|
| 94 | Input* input=NULL;
|
---|
[3861] | 95 | bool found=false;
|
---|
[3830] | 96 |
|
---|
| 97 | /*Go through inputs and check whether any input with the same name is already in: */
|
---|
| 98 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 99 |
|
---|
[13797] | 100 | input=dynamic_cast<Input*>(*object);
|
---|
[9883] | 101 | if (input->InstanceEnum()==enum_type){
|
---|
[3861] | 102 | found=true;
|
---|
| 103 | break;
|
---|
| 104 | }
|
---|
[3830] | 105 | }
|
---|
| 106 |
|
---|
[3861] | 107 | if (!found){
|
---|
[3830] | 108 | /*we could not find an input with the correct enum type. No defaults values were provided,
|
---|
| 109 | * error out: */
|
---|
[13056] | 110 | _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")");
|
---|
[3830] | 111 | }
|
---|
| 112 |
|
---|
| 113 | /*Ok, we have an input if we made it here, request the input to return the value: */
|
---|
[10135] | 114 | input->GetInputValue(pvalue);
|
---|
[3830] | 115 |
|
---|
| 116 | }
|
---|
| 117 | /*}}}*/
|
---|
[12365] | 118 | /*FUNCTION Inputs::GetInputAverage{{{*/
|
---|
[12466] | 119 | void Inputs::GetInputAverage(IssmDouble* pvalue,int enum_type){
|
---|
[3702] | 120 |
|
---|
| 121 | vector<Object*>::iterator object;
|
---|
| 122 | Input* input=NULL;
|
---|
[3861] | 123 | bool found=false;
|
---|
[3702] | 124 |
|
---|
| 125 | /*Go through inputs and check whether any input with the same name is already in: */
|
---|
| 126 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 127 |
|
---|
[13797] | 128 | input=dynamic_cast<Input*>(*object);
|
---|
[9883] | 129 | if (input->InstanceEnum()==enum_type){
|
---|
[3861] | 130 | found=true;
|
---|
| 131 | break;
|
---|
| 132 | }
|
---|
[3702] | 133 | }
|
---|
| 134 |
|
---|
[3861] | 135 | if (!found){
|
---|
[3702] | 136 | /*we could not find an input with the correct enum type. No defaults values were provided,
|
---|
| 137 | * error out: */
|
---|
[13056] | 138 | _error_("could not find input with enum type " << enum_type << " (" << EnumToStringx(enum_type) << ")");
|
---|
[3702] | 139 | }
|
---|
| 140 |
|
---|
| 141 | /*Ok, we have an input if we made it here, request the input to return the value: */
|
---|
[10135] | 142 | input->GetInputAverage(pvalue);
|
---|
[3702] | 143 |
|
---|
| 144 | }
|
---|
| 145 | /*}}}*/
|
---|
[12365] | 146 | /*FUNCTION Inputs::AddInput{{{*/
|
---|
[3702] | 147 | int Inputs::AddInput(Input* in_input){
|
---|
| 148 |
|
---|
| 149 | /*First, go through dataset of inputs and check whether any input
|
---|
| 150 | * with the same name is already in. If so, erase the corresponding
|
---|
| 151 | * object before adding this new one: */
|
---|
| 152 | vector<Object*>::iterator object;
|
---|
| 153 | Input* input=NULL;
|
---|
| 154 |
|
---|
[4995] | 155 | /*In debugging mode, check that the input is not a NULL pointer*/
|
---|
[6412] | 156 | _assert_(in_input);
|
---|
[4995] | 157 |
|
---|
[3702] | 158 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 159 |
|
---|
[13797] | 160 | input=dynamic_cast<Input*>(*object);
|
---|
[3702] | 161 |
|
---|
[9883] | 162 | if (input->InstanceEnum()==in_input->InstanceEnum()){
|
---|
[3702] | 163 | this->DeleteObject(input);
|
---|
| 164 | break;
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 | this->AddObject(in_input);
|
---|
[4905] | 168 |
|
---|
| 169 | return 1;
|
---|
[3702] | 170 | }
|
---|
| 171 | /*}}}*/
|
---|
[12365] | 172 | /*FUNCTION Inputs::ChangeEnum{{{*/
|
---|
[4943] | 173 | void Inputs::ChangeEnum(int oldenumtype,int newenumtype){
|
---|
| 174 |
|
---|
| 175 | /*Go through dataset of inputs and look for input with
|
---|
| 176 | * same enum as input enum, once found, just change its name */
|
---|
| 177 | vector<Object*>::iterator object;
|
---|
| 178 | Input* input=NULL;
|
---|
| 179 |
|
---|
| 180 | /*Delete existing input of newenumtype if it exists*/
|
---|
| 181 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
[13797] | 182 | input=dynamic_cast<Input*>(*object);
|
---|
[4943] | 183 |
|
---|
[9883] | 184 | if (input->InstanceEnum()==newenumtype){
|
---|
[4943] | 185 | this->DeleteObject(input);
|
---|
| 186 | break;
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | /*Change enum_type of input of oldenumtype*/
|
---|
| 191 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 192 |
|
---|
[13797] | 193 | input=dynamic_cast<Input*>(*object);
|
---|
[4943] | 194 |
|
---|
[9883] | 195 | if (input->InstanceEnum()==oldenumtype){
|
---|
[4943] | 196 | input->ChangeEnum(newenumtype);
|
---|
| 197 | break;
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 | /*}}}*/
|
---|
[12365] | 202 | /*FUNCTION Inputs::ConstrainMin{{{*/
|
---|
[12466] | 203 | void Inputs::ConstrainMin(int constrain_enum, IssmDouble minimum){
|
---|
[13622] | 204 |
|
---|
[5017] | 205 | /*Find x and y inputs: */
|
---|
[13798] | 206 | Input* constrain_input=dynamic_cast<Input*>(this->GetInput(constrain_enum));
|
---|
[5017] | 207 |
|
---|
| 208 | /*some checks: */
|
---|
[13056] | 209 | if(!constrain_input) _error_("input " << EnumToStringx(constrain_enum) << " could not be found!");
|
---|
[5017] | 210 |
|
---|
| 211 | /*Apply ContrainMin: */
|
---|
| 212 | constrain_input->ConstrainMin(minimum);
|
---|
| 213 | }
|
---|
| 214 | /*}}}*/
|
---|
[12365] | 215 | /*FUNCTION Inputs::InfinityNorm{{{*/
|
---|
[12466] | 216 | IssmDouble Inputs::InfinityNorm(int enumtype){
|
---|
[5537] | 217 |
|
---|
| 218 | /*Output*/
|
---|
[12466] | 219 | IssmDouble norm;
|
---|
[5537] | 220 |
|
---|
| 221 | /*Get input*/
|
---|
[13797] | 222 | Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
|
---|
[5537] | 223 |
|
---|
| 224 | /*Apply ContrainMin: */
|
---|
| 225 | if (input){
|
---|
| 226 | norm=input->InfinityNorm();
|
---|
| 227 | }
|
---|
| 228 | else{
|
---|
| 229 | norm=0;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | /*Return output*/
|
---|
| 233 | return norm;
|
---|
| 234 | }
|
---|
| 235 | /*}}}*/
|
---|
[12365] | 236 | /*FUNCTION Inputs::Max{{{*/
|
---|
[12466] | 237 | IssmDouble Inputs::Max(int enumtype){
|
---|
[5659] | 238 |
|
---|
| 239 | /*Output*/
|
---|
[12466] | 240 | IssmDouble max;
|
---|
[5659] | 241 |
|
---|
| 242 | /*Get input*/
|
---|
[13797] | 243 | Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
|
---|
[5659] | 244 |
|
---|
| 245 | /*Apply ContrainMin: */
|
---|
| 246 | if (input){
|
---|
| 247 | max=input->Max();
|
---|
| 248 | }
|
---|
| 249 | else{
|
---|
[13056] | 250 | _error_("Input " << EnumToStringx(enumtype) << " not found");
|
---|
[5659] | 251 | }
|
---|
| 252 |
|
---|
| 253 | /*Return output*/
|
---|
| 254 | return max;
|
---|
| 255 | }
|
---|
| 256 | /*}}}*/
|
---|
[12365] | 257 | /*FUNCTION Inputs::MaxAbs{{{*/
|
---|
[12466] | 258 | IssmDouble Inputs::MaxAbs(int enumtype){
|
---|
[5659] | 259 |
|
---|
| 260 | /*Output*/
|
---|
[12466] | 261 | IssmDouble max;
|
---|
[5659] | 262 |
|
---|
| 263 | /*Get input*/
|
---|
[13797] | 264 | Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
|
---|
[5659] | 265 |
|
---|
| 266 | /*Apply ContrainMin: */
|
---|
| 267 | if (input){
|
---|
| 268 | max=input->MaxAbs();
|
---|
| 269 | }
|
---|
| 270 | else{
|
---|
[13056] | 271 | _error_("Input " << EnumToStringx(enumtype) << " not found");
|
---|
[5659] | 272 | }
|
---|
| 273 |
|
---|
| 274 | /*Return output*/
|
---|
| 275 | return max;
|
---|
| 276 | }
|
---|
| 277 | /*}}}*/
|
---|
[12365] | 278 | /*FUNCTION Inputs::Min{{{*/
|
---|
[12466] | 279 | IssmDouble Inputs::Min(int enumtype){
|
---|
[5659] | 280 |
|
---|
| 281 | /*Output*/
|
---|
[12466] | 282 | IssmDouble min;
|
---|
[5659] | 283 |
|
---|
| 284 | /*Get input*/
|
---|
[13797] | 285 | Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
|
---|
[5659] | 286 |
|
---|
| 287 | /*Apply ContrainMin: */
|
---|
| 288 | if (input){
|
---|
| 289 | min=input->Min();
|
---|
| 290 | }
|
---|
| 291 | else{
|
---|
[13056] | 292 | _error_("Input " << EnumToStringx(enumtype) << " not found");
|
---|
[5659] | 293 | }
|
---|
| 294 |
|
---|
| 295 | /*Return output*/
|
---|
| 296 | return min;
|
---|
| 297 | }
|
---|
| 298 | /*}}}*/
|
---|
[12365] | 299 | /*FUNCTION Inputs::MinAbs{{{*/
|
---|
[12466] | 300 | IssmDouble Inputs::MinAbs(int enumtype){
|
---|
[5659] | 301 |
|
---|
| 302 | /*Output*/
|
---|
[12466] | 303 | IssmDouble min;
|
---|
[5659] | 304 |
|
---|
| 305 | /*Get input*/
|
---|
[13797] | 306 | Input* input=dynamic_cast<Input*>(this->GetInput(enumtype));
|
---|
[5659] | 307 |
|
---|
| 308 | /*Apply ContrainMin: */
|
---|
| 309 | if (input){
|
---|
| 310 | min=input->MinAbs();
|
---|
| 311 | }
|
---|
| 312 | else{
|
---|
[13056] | 313 | _error_("Input " << EnumToStringx(enumtype) << " not found");
|
---|
[5659] | 314 | }
|
---|
| 315 |
|
---|
| 316 | /*Return output*/
|
---|
| 317 | return min;
|
---|
| 318 | }
|
---|
| 319 | /*}}}*/
|
---|
[12365] | 320 | /*FUNCTION Inputs::GetInput{{{*/
|
---|
[3869] | 321 | Input* Inputs::GetInput(int enum_name){
|
---|
| 322 |
|
---|
| 323 | vector<Object*>::iterator object;
|
---|
| 324 | Input* input=NULL;
|
---|
| 325 |
|
---|
| 326 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 327 |
|
---|
[13797] | 328 | input=dynamic_cast<Input*>(*object);
|
---|
[3869] | 329 |
|
---|
[9883] | 330 | if (input->InstanceEnum()==enum_name){
|
---|
[3869] | 331 | return input;
|
---|
| 332 | }
|
---|
| 333 | }
|
---|
[4042] | 334 | return NULL;
|
---|
[3869] | 335 | }
|
---|
| 336 | /*}}}*/
|
---|
[12365] | 337 | /*FUNCTION Inputs::DeleteInput{{{*/
|
---|
[4905] | 338 | int Inputs::DeleteInput(int enum_type){
|
---|
| 339 |
|
---|
| 340 | vector<Object*>::iterator object;
|
---|
| 341 | Input* input=NULL;
|
---|
| 342 |
|
---|
| 343 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 344 |
|
---|
[13797] | 345 | input=dynamic_cast<Input*>(*object);
|
---|
[4905] | 346 |
|
---|
[9883] | 347 | if (input->InstanceEnum()==enum_type){
|
---|
[4905] | 348 | this->DeleteObject(input);
|
---|
| 349 | break;
|
---|
| 350 | }
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | return 1;
|
---|
| 354 |
|
---|
| 355 | }
|
---|
| 356 | /*}}}*/
|
---|
[12365] | 357 | /*FUNCTION Inputs::DuplicateInput{{{*/
|
---|
[4943] | 358 | void Inputs::DuplicateInput(int original_enum,int new_enum){
|
---|
[3702] | 359 |
|
---|
[4943] | 360 | /*Make a copy of the original input: */
|
---|
[13813] | 361 | Input* original=dynamic_cast<Input*>(this->GetInput(original_enum));
|
---|
[13056] | 362 | if(!original)_error_("could not find input with enum: " << EnumToStringx(original_enum));
|
---|
[13813] | 363 | Input* copy=dynamic_cast<Input*>(original->copy());
|
---|
[3702] | 364 |
|
---|
[4943] | 365 | /*Change copy enum to reinitialized_enum: */
|
---|
| 366 | copy->ChangeEnum(new_enum);
|
---|
[3857] | 367 |
|
---|
[4943] | 368 | /*Add copy into inputs, it will wipe off the one already there: */
|
---|
[13797] | 369 | this->AddInput(dynamic_cast<Input*>(copy));
|
---|
[3732] | 370 | }
|
---|
[3702] | 371 | /*}}}*/
|
---|
[12365] | 372 | /*FUNCTION Inputs::SpawnTriaInputs{{{*/
|
---|
[3847] | 373 | Inputs* Inputs::SpawnTriaInputs(int* indices){
|
---|
| 374 |
|
---|
| 375 | /*Intermediary*/
|
---|
| 376 | vector<Object*>::iterator object;
|
---|
| 377 | Input* inputin=NULL;
|
---|
| 378 | Input* inputout=NULL;
|
---|
| 379 |
|
---|
| 380 | /*Output*/
|
---|
| 381 | Inputs* newinputs=new Inputs();
|
---|
| 382 |
|
---|
| 383 | /*Go through inputs and call Spawn function*/
|
---|
| 384 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 385 |
|
---|
| 386 | /*Create new input*/
|
---|
[13797] | 387 | inputin=dynamic_cast<Input*>(*object);
|
---|
[3847] | 388 | inputout=inputin->SpawnTriaInput(indices);
|
---|
| 389 |
|
---|
| 390 | /*Add input to new inputs*/
|
---|
| 391 | newinputs->AddObject(inputout);
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 | /*Assign output pointer*/
|
---|
| 395 | return newinputs;
|
---|
| 396 | }
|
---|
| 397 | /*}}}*/
|
---|
[12365] | 398 | /*FUNCTION Inputs::AXPY{{{*/
|
---|
[12466] | 399 | void Inputs::AXPY(int MeshYEnum, IssmDouble scalar, int MeshXEnum){
|
---|
[13622] | 400 |
|
---|
[4967] | 401 | /*Find x and y inputs: */
|
---|
[13813] | 402 | Input* xinput=dynamic_cast<Input*>(this->GetInput(MeshXEnum));
|
---|
| 403 | Input* yinput=dynamic_cast<Input*>(this->GetInput(MeshYEnum));
|
---|
[4967] | 404 |
|
---|
| 405 | /*some checks: */
|
---|
[13056] | 406 | if(!xinput) _error_("input " << EnumToStringx(MeshXEnum) << " could not be found!");
|
---|
| 407 | if(!yinput) _error_("input " << EnumToStringx(MeshYEnum) << " could not be found!");
|
---|
[4967] | 408 |
|
---|
| 409 | /*Apply AXPY: */
|
---|
| 410 | yinput->AXPY(xinput,scalar);
|
---|
| 411 | }
|
---|
| 412 | /*}}}*/
|
---|
[12365] | 413 | /*FUNCTION Inputs::Configure{{{*/
|
---|
[8363] | 414 | void Inputs::Configure(Parameters* parameters){
|
---|
| 415 |
|
---|
| 416 | vector<Object*>::iterator object;
|
---|
| 417 | Input* input=NULL;
|
---|
| 418 |
|
---|
| 419 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 420 |
|
---|
[13797] | 421 | input=dynamic_cast<Input*>(*object);
|
---|
[8363] | 422 | input->Configure(parameters);
|
---|
| 423 |
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | }
|
---|
| 427 | /*}}}*/
|
---|