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