| 1 | /*
|
|---|
| 2 | * \file Parameters.cpp
|
|---|
| 3 | * \brief: Implementation of the Parameters class, derived from DataSet class.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*Headers: {{{*/
|
|---|
| 7 | #ifdef HAVE_CONFIG_H
|
|---|
| 8 | #include <config.h>
|
|---|
| 9 | #else
|
|---|
| 10 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| 13 | #include <vector>
|
|---|
| 14 | #include <functional>
|
|---|
| 15 | #include <algorithm>
|
|---|
| 16 | #include <iostream>
|
|---|
| 17 |
|
|---|
| 18 | #include "./Parameters.h"
|
|---|
| 19 | #include "./Param.h"
|
|---|
| 20 |
|
|---|
| 21 | #include "./BoolParam.h"
|
|---|
| 22 | #include "./DoubleMatParam.h"
|
|---|
| 23 | #include "./DataSetParam.h"
|
|---|
| 24 | #include "./DoubleParam.h"
|
|---|
| 25 | #include "./DoubleVecParam.h"
|
|---|
| 26 | #include "./IntParam.h"
|
|---|
| 27 | #include "./IntVecParam.h"
|
|---|
| 28 | #include "./IntMatParam.h"
|
|---|
| 29 | #include "./FileParam.h"
|
|---|
| 30 | #include "./MatrixParam.h"
|
|---|
| 31 | #include "./VectorParam.h"
|
|---|
| 32 | #include "./StringArrayParam.h"
|
|---|
| 33 | #include "./StringParam.h"
|
|---|
| 34 | #include "./DoubleMatArrayParam.h"
|
|---|
| 35 | #include "./TransientParam.h"
|
|---|
| 36 |
|
|---|
| 37 | #include "../../shared/shared.h"
|
|---|
| 38 | #include "../../toolkits/toolkits.h"
|
|---|
| 39 |
|
|---|
| 40 | using namespace std;
|
|---|
| 41 | /*}}}*/
|
|---|
| 42 |
|
|---|
| 43 | /*Object constructors and destructor*/
|
|---|
| 44 | Parameters::Parameters(){/*{{{*/
|
|---|
| 45 | for(int i=0;i<NUMPARAMS;i++) this->params[i] = NULL;
|
|---|
| 46 | return;
|
|---|
| 47 | }
|
|---|
| 48 | /*}}}*/
|
|---|
| 49 | Parameters::~Parameters(){/*{{{*/
|
|---|
| 50 | for(int i=0;i<NUMPARAMS;i++){
|
|---|
| 51 | if(this->params[i]) delete this->params[i];
|
|---|
| 52 | }
|
|---|
| 53 | return;
|
|---|
| 54 | }
|
|---|
| 55 | /*}}}*/
|
|---|
| 56 |
|
|---|
| 57 | void Parameters::AddObject(Param* newparam){/*{{{*/
|
|---|
| 58 |
|
|---|
| 59 | /*Get Enum from Param*/
|
|---|
| 60 | _assert_(newparam);
|
|---|
| 61 | int param_enum = newparam->InstanceEnum();
|
|---|
| 62 |
|
|---|
| 63 | /*Get index in array*/
|
|---|
| 64 | #ifdef _ISSM_DEBUG_
|
|---|
| 65 | if(param_enum<=ParametersSTARTEnum) _error_("Enum "<<EnumToStringx(param_enum)<<" should appear after ParametersSTARTEnum");
|
|---|
| 66 | if(param_enum>=ParametersENDEnum) _error_("Enum "<<EnumToStringx(param_enum)<<" should appear before ParametersENDEnum");
|
|---|
| 67 | #endif
|
|---|
| 68 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 69 |
|
|---|
| 70 | /*Delete param if it already exists*/
|
|---|
| 71 | if(this->params[index]){
|
|---|
| 72 | delete this->params[index];
|
|---|
| 73 | this->params[index] = NULL;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | /*Add param to array*/
|
|---|
| 77 | this->params[index] = newparam;
|
|---|
| 78 | }
|
|---|
| 79 | /*}}}*/
|
|---|
| 80 | Parameters* Parameters::Copy(void){/*{{{*/
|
|---|
| 81 |
|
|---|
| 82 | Parameters* output = new Parameters();
|
|---|
| 83 |
|
|---|
| 84 | for(int i=0;i<NUMPARAMS;i++){
|
|---|
| 85 | if(this->params[i]){
|
|---|
| 86 | output->params[i]=this->params[i]->copy();
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | return output;
|
|---|
| 91 | }
|
|---|
| 92 | /*}}}*/
|
|---|
| 93 | void Parameters::DeepEcho(void){/*{{{*/
|
|---|
| 94 | _error_("not implemented yet");
|
|---|
| 95 | }
|
|---|
| 96 | /*}}}*/
|
|---|
| 97 | void Parameters::Echo(void){/*{{{*/
|
|---|
| 98 | _error_("not implemented yet");
|
|---|
| 99 | }
|
|---|
| 100 | /*}}}*/
|
|---|
| 101 | void Parameters::Marshall(char** pmarshalled_data, int* pmarshalled_data_size, int marshall_direction){/*{{{*/
|
|---|
| 102 |
|
|---|
| 103 | int obj_enum=-1;
|
|---|
| 104 | int num_params=0;
|
|---|
| 105 |
|
|---|
| 106 | MARSHALLING_ENUM(ParametersEnum);
|
|---|
| 107 |
|
|---|
| 108 | if(marshall_direction==MARSHALLING_FORWARD || marshall_direction==MARSHALLING_SIZE){
|
|---|
| 109 |
|
|---|
| 110 | /*Marshall num_params first*/
|
|---|
| 111 | for(int i=0;i<NUMPARAMS;i++){
|
|---|
| 112 | if(this->params[i]) num_params++;
|
|---|
| 113 | }
|
|---|
| 114 | MARSHALLING(num_params);
|
|---|
| 115 |
|
|---|
| 116 | /*Marshall Parameters one by one now*/
|
|---|
| 117 | for(int i=0;i<NUMPARAMS;i++){
|
|---|
| 118 | if(this->params[i]){
|
|---|
| 119 | obj_enum = this->params[i]->ObjectEnum();
|
|---|
| 120 | MARSHALLING(obj_enum);
|
|---|
| 121 | this->params[i]->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 | }
|
|---|
| 125 | else{
|
|---|
| 126 |
|
|---|
| 127 | /*Get number of params marshalled*/
|
|---|
| 128 | MARSHALLING(num_params);
|
|---|
| 129 |
|
|---|
| 130 | /*Recover parameters one by one*/
|
|---|
| 131 | for(int i=0;i<num_params;i++){
|
|---|
| 132 |
|
|---|
| 133 | /*Recover enum of object first: */
|
|---|
| 134 | MARSHALLING(obj_enum);
|
|---|
| 135 |
|
|---|
| 136 | if(obj_enum==DoubleParamEnum){
|
|---|
| 137 | DoubleParam* doubleparam=NULL;
|
|---|
| 138 | doubleparam=new DoubleParam();
|
|---|
| 139 | doubleparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 140 | this->AddObject(doubleparam);
|
|---|
| 141 | }
|
|---|
| 142 | else if(obj_enum==IntParamEnum){
|
|---|
| 143 | IntParam* intparam=NULL;
|
|---|
| 144 | intparam=new IntParam();
|
|---|
| 145 | intparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 146 | this->AddObject(intparam);
|
|---|
| 147 | }
|
|---|
| 148 | else if(obj_enum==IntMatParamEnum){
|
|---|
| 149 | IntMatParam* intmparam=NULL;
|
|---|
| 150 | intmparam=new IntMatParam();
|
|---|
| 151 | intmparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 152 | this->AddObject(intmparam);
|
|---|
| 153 | }
|
|---|
| 154 | else if(obj_enum==IntVecParamEnum){
|
|---|
| 155 | IntVecParam* intvparam=NULL;
|
|---|
| 156 | intvparam=new IntVecParam();
|
|---|
| 157 | intvparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 158 | this->AddObject(intvparam);
|
|---|
| 159 | }
|
|---|
| 160 | else if(obj_enum==BoolParamEnum){
|
|---|
| 161 | BoolParam* boolparam=NULL;
|
|---|
| 162 | boolparam=new BoolParam();
|
|---|
| 163 | boolparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 164 | this->AddObject(boolparam);
|
|---|
| 165 | }
|
|---|
| 166 | else if(obj_enum==DataSetParamEnum){
|
|---|
| 167 | DataSetParam* dsparam=NULL;
|
|---|
| 168 | dsparam=new DataSetParam();
|
|---|
| 169 | dsparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 170 | this->AddObject(dsparam);
|
|---|
| 171 | }
|
|---|
| 172 | else if(obj_enum==DoubleMatArrayParamEnum){
|
|---|
| 173 | DoubleMatArrayParam* dmaparam=NULL;
|
|---|
| 174 | dmaparam=new DoubleMatArrayParam();
|
|---|
| 175 | dmaparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 176 | this->AddObject(dmaparam);
|
|---|
| 177 | }
|
|---|
| 178 | else if(obj_enum==DoubleMatParamEnum){
|
|---|
| 179 | DoubleMatParam* dmparam=NULL;
|
|---|
| 180 | dmparam=new DoubleMatParam();
|
|---|
| 181 | dmparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 182 | this->AddObject(dmparam);
|
|---|
| 183 | }
|
|---|
| 184 | else if(obj_enum==DoubleVecParamEnum){
|
|---|
| 185 | DoubleVecParam* dvparam=NULL;
|
|---|
| 186 | dvparam=new DoubleVecParam();
|
|---|
| 187 | dvparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 188 | this->AddObject(dvparam);
|
|---|
| 189 | }
|
|---|
| 190 | else if(obj_enum==FileParamEnum){
|
|---|
| 191 | FileParam* fileparam=NULL;
|
|---|
| 192 | fileparam=new FileParam();
|
|---|
| 193 | fileparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 194 | delete fileparam;
|
|---|
| 195 | /* No need to add this object, the pointer is not valid
|
|---|
| 196 | The FemModel should reset all FileParams in the restart function */
|
|---|
| 197 | }
|
|---|
| 198 | else if(obj_enum==StringParamEnum){
|
|---|
| 199 | StringParam* sparam=NULL;
|
|---|
| 200 | sparam=new StringParam();
|
|---|
| 201 | sparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 202 | this->AddObject(sparam);
|
|---|
| 203 | }
|
|---|
| 204 | else if(obj_enum==StringArrayParamEnum){
|
|---|
| 205 | StringArrayParam* saparam=NULL;
|
|---|
| 206 | saparam=new StringArrayParam();
|
|---|
| 207 | saparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 208 | this->AddObject(saparam);
|
|---|
| 209 | }
|
|---|
| 210 | else if(obj_enum==TransientParamEnum){
|
|---|
| 211 | TransientParam* transparam=NULL;
|
|---|
| 212 | transparam=new TransientParam();
|
|---|
| 213 | transparam->Marshall(pmarshalled_data,pmarshalled_data_size,marshall_direction);
|
|---|
| 214 | this->AddObject(transparam);
|
|---|
| 215 | }
|
|---|
| 216 | else if(obj_enum==GenericParamEnum){
|
|---|
| 217 | /*Skip for now (we don't want to Marhsall Comms*/
|
|---|
| 218 | }
|
|---|
| 219 | }
|
|---|
| 220 | }
|
|---|
| 221 | }
|
|---|
| 222 | /*}}}*/
|
|---|
| 223 |
|
|---|
| 224 | /*Object management*/
|
|---|
| 225 | void Parameters::Delete(int param_enum){/*{{{*/
|
|---|
| 226 |
|
|---|
| 227 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 228 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 229 |
|
|---|
| 230 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 231 | if(this->params[index]){
|
|---|
| 232 | delete this->params[index];
|
|---|
| 233 | this->params[index] = NULL;
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | return;
|
|---|
| 237 | }
|
|---|
| 238 | /*}}}*/
|
|---|
| 239 | bool Parameters::Exist(int param_enum){/*{{{*/
|
|---|
| 240 |
|
|---|
| 241 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 242 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 243 |
|
|---|
| 244 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 245 | if(this->params[index]) return true;
|
|---|
| 246 |
|
|---|
| 247 | return false;
|
|---|
| 248 | }
|
|---|
| 249 | /*}}}*/
|
|---|
| 250 | void Parameters::FindParam(bool* pbool,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 251 |
|
|---|
| 252 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 253 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 254 |
|
|---|
| 255 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 256 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 257 | this->params[index]->GetParameterValue(pbool);
|
|---|
| 258 | }
|
|---|
| 259 | /*}}}*/
|
|---|
| 260 | void Parameters::FindParam(int* pinteger,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 261 |
|
|---|
| 262 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 263 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 264 |
|
|---|
| 265 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 266 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 267 | this->params[index]->GetParameterValue(pinteger);
|
|---|
| 268 | }
|
|---|
| 269 | /*}}}*/
|
|---|
| 270 | void Parameters::FindParam(IssmDouble* pscalar,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 271 |
|
|---|
| 272 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 273 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 274 |
|
|---|
| 275 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 276 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 277 | this->params[index]->GetParameterValue(pscalar);
|
|---|
| 278 | }
|
|---|
| 279 | /*}}}*/
|
|---|
| 280 | void Parameters::FindParam(IssmDouble* pscalar, int param_enum,IssmDouble time){ _assert_(this);/*{{{*/
|
|---|
| 281 |
|
|---|
| 282 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 283 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 284 |
|
|---|
| 285 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 286 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 287 | this->params[index]->GetParameterValue(pscalar,time);
|
|---|
| 288 | }
|
|---|
| 289 | /*}}}*/
|
|---|
| 290 | void Parameters::FindParam(char** pstring,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 291 |
|
|---|
| 292 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 293 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 294 |
|
|---|
| 295 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 296 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 297 | this->params[index]->GetParameterValue(pstring);
|
|---|
| 298 |
|
|---|
| 299 | }
|
|---|
| 300 | /*}}}*/
|
|---|
| 301 | void Parameters::FindParam(char*** pstringarray,int* pM,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 302 |
|
|---|
| 303 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 304 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 305 |
|
|---|
| 306 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 307 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 308 | this->params[index]->GetParameterValue(pstringarray,pM);
|
|---|
| 309 | }
|
|---|
| 310 | /*}}}*/
|
|---|
| 311 | void Parameters::FindParam(int** pintarray,int* pM, int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 312 |
|
|---|
| 313 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 314 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 315 |
|
|---|
| 316 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 317 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 318 | this->params[index]->GetParameterValue(pintarray,pM);
|
|---|
| 319 |
|
|---|
| 320 | }
|
|---|
| 321 | /*}}}*/
|
|---|
| 322 | void Parameters::FindParam(int** pintarray,int* pM,int *pN,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 323 |
|
|---|
| 324 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 325 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 326 |
|
|---|
| 327 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 328 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 329 | this->params[index]->GetParameterValue(pintarray,pM,pN);
|
|---|
| 330 |
|
|---|
| 331 | }
|
|---|
| 332 | /*}}}*/
|
|---|
| 333 | void Parameters::FindParam(IssmDouble** pIssmDoublearray,int* pM, int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 334 |
|
|---|
| 335 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 336 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 337 |
|
|---|
| 338 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 339 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 340 | this->params[index]->GetParameterValue(pIssmDoublearray,pM);
|
|---|
| 341 | }
|
|---|
| 342 | /*}}}*/
|
|---|
| 343 | void Parameters::FindParam(IssmDouble** pIssmDoublearray,int* pM, int* pN,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 344 |
|
|---|
| 345 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 346 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 347 |
|
|---|
| 348 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 349 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 350 | this->params[index]->GetParameterValue(pIssmDoublearray,pM,pN);
|
|---|
| 351 | }
|
|---|
| 352 | /*}}}*/
|
|---|
| 353 | void Parameters::FindParam(IssmDouble*** parray,int* pM,int** pmdims_array,int** pndims_array,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 354 |
|
|---|
| 355 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 356 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 357 |
|
|---|
| 358 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 359 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 360 | this->params[index]->GetParameterValue(parray,pM,pmdims_array,pndims_array);
|
|---|
| 361 | }
|
|---|
| 362 | /*}}}*/
|
|---|
| 363 | void Parameters::FindParam(Vector<IssmDouble>** pvec,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 364 |
|
|---|
| 365 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 366 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 367 |
|
|---|
| 368 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 369 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 370 | this->params[index]->GetParameterValue(pvec);
|
|---|
| 371 | }
|
|---|
| 372 | /*}}}*/
|
|---|
| 373 | void Parameters::FindParam(Matrix<IssmDouble>** pmat,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 374 |
|
|---|
| 375 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 376 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 377 |
|
|---|
| 378 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 379 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 380 | this->params[index]->GetParameterValue(pmat);
|
|---|
| 381 | }
|
|---|
| 382 | /*}}}*/
|
|---|
| 383 | void Parameters::FindParam(FILE** pfid,int param_enum){ _assert_(this);/*{{{*/
|
|---|
| 384 |
|
|---|
| 385 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 386 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 387 |
|
|---|
| 388 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 389 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 390 | this->params[index]->GetParameterValue(pfid);
|
|---|
| 391 | }
|
|---|
| 392 | /*}}}*/
|
|---|
| 393 | void Parameters::FindParam(DataSet** pdataset,int param_enum){ /*{{{*/
|
|---|
| 394 | _assert_(this);
|
|---|
| 395 |
|
|---|
| 396 | _assert_(param_enum>ParametersSTARTEnum);
|
|---|
| 397 | _assert_(param_enum<ParametersENDEnum);
|
|---|
| 398 |
|
|---|
| 399 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 400 | if(!this->params[index]) _error_("Parameter " << EnumToStringx(param_enum) <<" not set");
|
|---|
| 401 | this->params[index]->GetParameterValue(pdataset);
|
|---|
| 402 | }
|
|---|
| 403 | /*}}}*/
|
|---|
| 404 |
|
|---|
| 405 | void Parameters::SetParam(bool boolean,int enum_type){/*{{{*/
|
|---|
| 406 |
|
|---|
| 407 | Param* param=NULL;
|
|---|
| 408 |
|
|---|
| 409 | /*first, figure out if the param has already been created: */
|
|---|
| 410 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 411 |
|
|---|
| 412 | if(param) param->SetValue(boolean); //already exists, just set it.
|
|---|
| 413 | else this->AddObject(new BoolParam(enum_type,boolean)); //just add the new parameter.
|
|---|
| 414 | }
|
|---|
| 415 | /*}}}*/
|
|---|
| 416 | void Parameters::SetParam(int integer,int enum_type){/*{{{*/
|
|---|
| 417 |
|
|---|
| 418 | Param* param=NULL;
|
|---|
| 419 |
|
|---|
| 420 | /*first, figure out if the param has already been created: */
|
|---|
| 421 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 422 |
|
|---|
| 423 | if(param) param->SetValue(integer); //already exists, just set it.
|
|---|
| 424 | else this->AddObject(new IntParam(enum_type,integer)); //just add the new parameter.
|
|---|
| 425 | }
|
|---|
| 426 | /*}}}*/
|
|---|
| 427 | void Parameters::SetParam(IssmDouble scalar,int enum_type){/*{{{*/
|
|---|
| 428 |
|
|---|
| 429 | Param* param=NULL;
|
|---|
| 430 |
|
|---|
| 431 | /*first, figure out if the param has already been created: */
|
|---|
| 432 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 433 |
|
|---|
| 434 | if(param) param->SetValue(scalar); //already exists, just set it.
|
|---|
| 435 | else this->AddObject(new DoubleParam(enum_type,scalar)); //just add the new parameter.
|
|---|
| 436 | }
|
|---|
| 437 | /*}}}*/
|
|---|
| 438 | void Parameters::SetParam(char* string,int enum_type){/*{{{*/
|
|---|
| 439 |
|
|---|
| 440 | Param* param=NULL;
|
|---|
| 441 |
|
|---|
| 442 | /*first, figure out if the param has already been created: */
|
|---|
| 443 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 444 |
|
|---|
| 445 | if(param) param->SetValue(string); //already exists, just set it.
|
|---|
| 446 | else this->AddObject(new StringParam(enum_type,string)); //just add the new parameter.
|
|---|
| 447 | }
|
|---|
| 448 | /*}}}*/
|
|---|
| 449 | void Parameters::SetParam(char** stringarray,int M, int enum_type){/*{{{*/
|
|---|
| 450 |
|
|---|
| 451 | Param* param=NULL;
|
|---|
| 452 |
|
|---|
| 453 | /*first, figure out if the param has already been created: */
|
|---|
| 454 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 455 |
|
|---|
| 456 | if(param) param->SetValue(stringarray,M); //already exists, just set it.
|
|---|
| 457 | else this->AddObject(new StringArrayParam(enum_type,stringarray,M)); //just add the new parameter.
|
|---|
| 458 | }
|
|---|
| 459 | /*}}}*/
|
|---|
| 460 | void Parameters::SetParam(IssmDouble* IssmDoublearray,int M, int enum_type){/*{{{*/
|
|---|
| 461 |
|
|---|
| 462 | Param* param=NULL;
|
|---|
| 463 |
|
|---|
| 464 | /*first, figure out if the param has already been created: */
|
|---|
| 465 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 466 |
|
|---|
| 467 | if(param) param->SetValue(IssmDoublearray,M); //already exists, just set it.
|
|---|
| 468 | else this->AddObject(new DoubleVecParam(enum_type,IssmDoublearray,M)); //just add the new parameter.
|
|---|
| 469 | }
|
|---|
| 470 | /*}}}*/
|
|---|
| 471 | void Parameters::SetParam(IssmDouble* IssmDoublearray,int M, int N, int enum_type){/*{{{*/
|
|---|
| 472 |
|
|---|
| 473 | Param* param=NULL;
|
|---|
| 474 |
|
|---|
| 475 | /*first, figure out if the param has already been created: */
|
|---|
| 476 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 477 |
|
|---|
| 478 | if(param) param->SetValue(IssmDoublearray,M,N); //already exists, just set it.
|
|---|
| 479 | else this->AddObject(new DoubleMatParam(enum_type,IssmDoublearray,M,N)); //just add the new parameter.
|
|---|
| 480 | }
|
|---|
| 481 | /*}}}*/
|
|---|
| 482 | void Parameters::SetParam(int* intarray,int M, int enum_type){/*{{{*/
|
|---|
| 483 |
|
|---|
| 484 | Param* param=NULL;
|
|---|
| 485 |
|
|---|
| 486 | /*first, figure out if the param has already been created: */
|
|---|
| 487 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 488 |
|
|---|
| 489 | if(param) param->SetValue(intarray,M); //already exists, just set it.
|
|---|
| 490 | else this->AddObject(new IntVecParam(enum_type,intarray,M)); //just add the new parameter.
|
|---|
| 491 | }
|
|---|
| 492 | /*}}}*/
|
|---|
| 493 | void Parameters::SetParam(int* intarray,int M, int N, int enum_type){/*{{{*/
|
|---|
| 494 |
|
|---|
| 495 | Param* param=NULL;
|
|---|
| 496 |
|
|---|
| 497 | /*first, figure out if the param has already been created: */
|
|---|
| 498 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 499 |
|
|---|
| 500 | if(param) param->SetValue(intarray,M,N); //already exists, just set it.
|
|---|
| 501 | else this->AddObject(new IntMatParam(enum_type,intarray,M,N)); //just add the new parameter.
|
|---|
| 502 | }
|
|---|
| 503 | /*}}}*/
|
|---|
| 504 | void Parameters::SetParam(Vector<IssmDouble>* vector,int enum_type){/*{{{*/
|
|---|
| 505 |
|
|---|
| 506 | Param* param=NULL;
|
|---|
| 507 |
|
|---|
| 508 | /*first, figure out if the param has already been created: */
|
|---|
| 509 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 510 |
|
|---|
| 511 | if(param) param->SetValue(vector); //already exists, just set it.
|
|---|
| 512 | else this->AddObject(new VectorParam(enum_type,vector)); //just add the new parameter.
|
|---|
| 513 | }
|
|---|
| 514 | /*}}}*/
|
|---|
| 515 | void Parameters::SetParam(Matrix<IssmDouble>* matrix,int enum_type){/*{{{*/
|
|---|
| 516 |
|
|---|
| 517 | Param* param=NULL;
|
|---|
| 518 |
|
|---|
| 519 | /*first, figure out if the param has already been created: */
|
|---|
| 520 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 521 |
|
|---|
| 522 | if(param) param->SetValue(matrix); //already exists, just set it.
|
|---|
| 523 | else this->AddObject(new MatrixParam(enum_type,matrix)); //just add the new parameter.
|
|---|
| 524 | }
|
|---|
| 525 | /*}}}*/
|
|---|
| 526 | void Parameters::SetParam(FILE* fid,int enum_type){/*{{{*/
|
|---|
| 527 |
|
|---|
| 528 | Param* param=NULL;
|
|---|
| 529 |
|
|---|
| 530 | /*first, figure out if the param has already been created: */
|
|---|
| 531 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 532 |
|
|---|
| 533 | if(param) param->SetValue(fid); //already exists, just set it.
|
|---|
| 534 | else this->AddObject(new FileParam(enum_type,fid)); //just add the new parameter.
|
|---|
| 535 | }
|
|---|
| 536 | /*}}}*/
|
|---|
| 537 | void Parameters::SetParam(DataSet* dataset,int enum_type){/*{{{*/
|
|---|
| 538 |
|
|---|
| 539 | Param* param=NULL;
|
|---|
| 540 |
|
|---|
| 541 | /*first, figure out if the param has already been created: */
|
|---|
| 542 | param=xDynamicCast<Param*>(this->FindParamObject(enum_type));
|
|---|
| 543 |
|
|---|
| 544 | if(param) param->SetValue(dataset); //already exists, just set it.
|
|---|
| 545 | else this->AddObject(new DataSetParam(enum_type,dataset)); //just add the new parameter.
|
|---|
| 546 | }
|
|---|
| 547 | /*}}}*/
|
|---|
| 548 |
|
|---|
| 549 | Param* Parameters::FindParamObject(int param_enum){/*{{{*/
|
|---|
| 550 |
|
|---|
| 551 | #ifdef _ISSM_DEBUG_
|
|---|
| 552 | if(param_enum<=ParametersSTARTEnum) _error_("Enum "<<EnumToStringx(param_enum)<<" should appear after ParametersSTARTEnum");
|
|---|
| 553 | if(param_enum>=ParametersENDEnum) _error_("Enum "<<EnumToStringx(param_enum)<<" should appear before ParametersENDEnum");
|
|---|
| 554 | #endif
|
|---|
| 555 |
|
|---|
| 556 | int index = param_enum - ParametersSTARTEnum -1;
|
|---|
| 557 | return this->params[index];
|
|---|
| 558 | }
|
|---|
| 559 | /*}}}*/
|
|---|
| 560 |
|
|---|
| 561 | /*Methods relating to parameters: */
|
|---|
| 562 | char* OptionsFromAnalysis(Parameters* parameters,int analysis_type){ /*{{{*/
|
|---|
| 563 |
|
|---|
| 564 | /* figure out ISSM options for current analysis, return a string. */
|
|---|
| 565 |
|
|---|
| 566 | /*output: */
|
|---|
| 567 | char* outstring=NULL;
|
|---|
| 568 |
|
|---|
| 569 | /*intermediary: */
|
|---|
| 570 | int dummy;
|
|---|
| 571 | IssmDouble *analyses = NULL;
|
|---|
| 572 | char **strings = NULL;
|
|---|
| 573 | char *string = NULL;
|
|---|
| 574 | int numanalyses;
|
|---|
| 575 | int found = -1;
|
|---|
| 576 | int i;
|
|---|
| 577 |
|
|---|
| 578 | numanalyses=0;
|
|---|
| 579 | parameters->FindParam(&strings,&numanalyses,ToolkitsOptionsStringsEnum);
|
|---|
| 580 |
|
|---|
| 581 | parameters->FindParam(&analyses,&dummy,ToolkitsOptionsAnalysesEnum);
|
|---|
| 582 |
|
|---|
| 583 | if(numanalyses==0)return NULL; //we did not find petsc options, don't bother.
|
|---|
| 584 |
|
|---|
| 585 | /*ok, go through analyses and figure out if it corresponds to our analysis_type: */
|
|---|
| 586 | for(i=0;i<numanalyses;i++){
|
|---|
| 587 | if(analyses[i]==analysis_type){
|
|---|
| 588 | found=i;
|
|---|
| 589 | break;
|
|---|
| 590 | }
|
|---|
| 591 | }
|
|---|
| 592 | if(found==-1){
|
|---|
| 593 | /*still haven't found a list of petsc options, go find the default one, for analysis type DefaultAnalysisEnum: */
|
|---|
| 594 | for(i=0;i<numanalyses;i++){
|
|---|
| 595 | if(analyses[i]==DefaultAnalysisEnum){
|
|---|
| 596 | found=i;
|
|---|
| 597 | break;
|
|---|
| 598 | }
|
|---|
| 599 | }
|
|---|
| 600 | }
|
|---|
| 601 | if (found==-1){
|
|---|
| 602 | _error_("could find neither a default analysis nor analysis " << EnumToStringx(analysis_type));
|
|---|
| 603 | }
|
|---|
| 604 |
|
|---|
| 605 | /*ok, grab the option string: */
|
|---|
| 606 | outstring=xNew<char>(strlen(strings[found])+1);
|
|---|
| 607 | strcpy(outstring,strings[found]);
|
|---|
| 608 |
|
|---|
| 609 | /*Free ressources*/
|
|---|
| 610 | xDelete<IssmDouble>(analyses);
|
|---|
| 611 | for(i=0;i<numanalyses;i++){
|
|---|
| 612 | string=strings[i];
|
|---|
| 613 | xDelete<char>(string);
|
|---|
| 614 | }
|
|---|
| 615 | xDelete<char*>(strings);
|
|---|
| 616 | return outstring;
|
|---|
| 617 | }
|
|---|
| 618 | /*}}}*/
|
|---|
| 619 | void ToolkitsOptionsFromAnalysis(Parameters* parameters,int analysis_type){ /*{{{*/
|
|---|
| 620 |
|
|---|
| 621 | /*!\file: ToolkitsOptionsFromAnalysis.cpp
|
|---|
| 622 | * \brief: for each analysis, setup the issmoptions string.
|
|---|
| 623 | * This is mainly for the case where we run our toolkits using petsc. In this case, we need to
|
|---|
| 624 | * plug our toolkits options directly into the petsc options database. This is the case for each analysis type
|
|---|
| 625 | * and parameters
|
|---|
| 626 | */
|
|---|
| 627 |
|
|---|
| 628 | char* options=NULL;
|
|---|
| 629 |
|
|---|
| 630 | /*Recover first the options string for this analysis: */
|
|---|
| 631 | options=OptionsFromAnalysis(parameters,analysis_type);
|
|---|
| 632 |
|
|---|
| 633 | /*Initialize our Toolkit Options: */
|
|---|
| 634 | ToolkitOptions::Init(options);
|
|---|
| 635 |
|
|---|
| 636 | #ifdef _HAVE_PETSC_
|
|---|
| 637 | /*In case we are using PETSC, we do not rely on issmoptions. Instead, we dump issmoptions into the Petsc
|
|---|
| 638 | * options database: */
|
|---|
| 639 |
|
|---|
| 640 | #if _PETSC_MAJOR_ == 2
|
|---|
| 641 | PetscOptionsDestroy();
|
|---|
| 642 | PetscOptionsCreate();
|
|---|
| 643 | //PetscOptionsCheckInitial_Private();
|
|---|
| 644 | //PetscOptionsCheckInitial_Components();
|
|---|
| 645 | PetscOptionsSetFromOptions();
|
|---|
| 646 | PetscOptionsInsertMultipleString(options); //our patch
|
|---|
| 647 | #else
|
|---|
| 648 | #if (_PETSC_MINOR_>=7)
|
|---|
| 649 | PetscOptionsSetFromOptions(NULL);
|
|---|
| 650 | PetscOptionsClear(NULL);
|
|---|
| 651 | #else
|
|---|
| 652 | PetscOptionsSetFromOptions();
|
|---|
| 653 | PetscOptionsClear();
|
|---|
| 654 | #endif
|
|---|
| 655 | //PetscOptionsSetFromOptions();
|
|---|
| 656 | PetscOptionsInsertMultipleString(options); //our patch
|
|---|
| 657 | #endif
|
|---|
| 658 |
|
|---|
| 659 | #endif
|
|---|
| 660 |
|
|---|
| 661 | xDelete<char>(options);
|
|---|
| 662 | }
|
|---|
| 663 | /*}}}*/
|
|---|