| 1 | /*
|
|---|
| 2 | * \file Parameters.c
|
|---|
| 3 | * \brief: implementation of the Parameters class, derived from DataSet class
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*Headers: {{{1*/
|
|---|
| 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 "./DataSet.h"
|
|---|
| 19 | #include "../shared/shared.h"
|
|---|
| 20 | #include "../include/include.h"
|
|---|
| 21 | #include "../EnumDefinitions/EnumDefinitions.h"
|
|---|
| 22 |
|
|---|
| 23 | using namespace std;
|
|---|
| 24 | /*}}}*/
|
|---|
| 25 |
|
|---|
| 26 | /*Object constructors and destructor*/
|
|---|
| 27 | /*FUNCTION Parameters::Parameters(){{{1*/
|
|---|
| 28 | Parameters::Parameters(){
|
|---|
| 29 | return;
|
|---|
| 30 | }
|
|---|
| 31 | /*}}}*/
|
|---|
| 32 | /*FUNCTION Parameters::Parameters(int in_enum){{{1*/
|
|---|
| 33 | Parameters::Parameters(int in_enum): DataSet(in_enum){
|
|---|
| 34 | //do nothing;
|
|---|
| 35 | return;
|
|---|
| 36 | }
|
|---|
| 37 | /*}}}*/
|
|---|
| 38 | /*FUNCTION Parameters::~Parameters(){{{1*/
|
|---|
| 39 | Parameters::~Parameters(){
|
|---|
| 40 | return;
|
|---|
| 41 | }
|
|---|
| 42 | /*}}}*/
|
|---|
| 43 |
|
|---|
| 44 | /*Object management*/
|
|---|
| 45 | /*FUNCTION Parameters::FindParam(bool* pbool,int enum_type){{{1*/
|
|---|
| 46 | int Parameters::FindParam(bool* pbool,int enum_type){
|
|---|
| 47 |
|
|---|
| 48 | /*Go through a dataset, and find a Param* object
|
|---|
| 49 | *which parameter name is "name" : */
|
|---|
| 50 |
|
|---|
| 51 | vector<Object*>::iterator object;
|
|---|
| 52 | Param* param=NULL;
|
|---|
| 53 |
|
|---|
| 54 | int found=0;
|
|---|
| 55 |
|
|---|
| 56 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 57 |
|
|---|
| 58 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 59 | param=(Param*)(*object);
|
|---|
| 60 |
|
|---|
| 61 | if(param->EnumType()==enum_type){
|
|---|
| 62 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 63 | param->GetParameterValue(pbool);
|
|---|
| 64 | found=1;
|
|---|
| 65 | break;
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 | return found;
|
|---|
| 69 | }
|
|---|
| 70 | /*}}}*/
|
|---|
| 71 | /*FUNCTION Parameters::FindParam(int* pinteger,int enum_type){{{1*/
|
|---|
| 72 | int Parameters::FindParam(int* pinteger,int enum_type){
|
|---|
| 73 |
|
|---|
| 74 | /*Go through a dataset, and find a Param* object
|
|---|
| 75 | *which parameter name is "name" : */
|
|---|
| 76 |
|
|---|
| 77 | vector<Object*>::iterator object;
|
|---|
| 78 | Param* param=NULL;
|
|---|
| 79 |
|
|---|
| 80 | int found=0;
|
|---|
| 81 |
|
|---|
| 82 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 83 |
|
|---|
| 84 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 85 | param=(Param*)(*object);
|
|---|
| 86 |
|
|---|
| 87 | if(param->EnumType()==enum_type){
|
|---|
| 88 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 89 | param->GetParameterValue(pinteger);
|
|---|
| 90 | found=1;
|
|---|
| 91 | break;
|
|---|
| 92 | }
|
|---|
| 93 | }
|
|---|
| 94 | return found;
|
|---|
| 95 | }
|
|---|
| 96 | /*}}}*/
|
|---|
| 97 | /*FUNCTION Parameters::FindParam(double* pscalar, int enum_type){{{1*/
|
|---|
| 98 | int Parameters::FindParam(double* pscalar, int enum_type){
|
|---|
| 99 |
|
|---|
| 100 | /*Go through a dataset, and find a Param* object
|
|---|
| 101 | *which parameter name is "name" : */
|
|---|
| 102 |
|
|---|
| 103 | vector<Object*>::iterator object;
|
|---|
| 104 | Param* param=NULL;
|
|---|
| 105 |
|
|---|
| 106 | int found=0;
|
|---|
| 107 |
|
|---|
| 108 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 109 |
|
|---|
| 110 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 111 | param=(Param*)(*object);
|
|---|
| 112 |
|
|---|
| 113 | if(param->EnumType()==enum_type){
|
|---|
| 114 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 115 | param->GetParameterValue(pscalar);
|
|---|
| 116 | found=1;
|
|---|
| 117 | break;
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 | return found;
|
|---|
| 121 | }
|
|---|
| 122 | /*}}}*/
|
|---|
| 123 | /*FUNCTION Parameters::FindParam(char** pstring,int enum_type){{{1*/
|
|---|
| 124 | int Parameters::FindParam(char** pstring,int enum_type){
|
|---|
| 125 |
|
|---|
| 126 | /*Go through a dataset, and find a Param* object
|
|---|
| 127 | *which parameter name is "name" : */
|
|---|
| 128 |
|
|---|
| 129 | vector<Object*>::iterator object;
|
|---|
| 130 | Param* param=NULL;
|
|---|
| 131 |
|
|---|
| 132 | int found=0;
|
|---|
| 133 |
|
|---|
| 134 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 135 |
|
|---|
| 136 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 137 | param=(Param*)(*object);
|
|---|
| 138 |
|
|---|
| 139 | if(param->EnumType()==enum_type){
|
|---|
| 140 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 141 | param->GetParameterValue(pstring);
|
|---|
| 142 | found=1;
|
|---|
| 143 | break;
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 | return found;
|
|---|
| 147 |
|
|---|
| 148 | }
|
|---|
| 149 | /*}}}*/
|
|---|
| 150 | /*FUNCTION Parameters::FindParam(char*** pstringarray,int* pM,int enum_type){{{1*/
|
|---|
| 151 | int Parameters::FindParam(char*** pstringarray,int* pM,int enum_type){
|
|---|
| 152 |
|
|---|
| 153 | /*Go through a dataset, and find a Param* object
|
|---|
| 154 | *which parameter name is "name" : */
|
|---|
| 155 |
|
|---|
| 156 | vector<Object*>::iterator object;
|
|---|
| 157 | Param* param=NULL;
|
|---|
| 158 |
|
|---|
| 159 | int found=0;
|
|---|
| 160 |
|
|---|
| 161 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 162 |
|
|---|
| 163 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 164 | param=(Param*)(*object);
|
|---|
| 165 |
|
|---|
| 166 | if(param->EnumType()==enum_type){
|
|---|
| 167 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 168 | param->GetParameterValue(pstringarray,pM);
|
|---|
| 169 | found=1;
|
|---|
| 170 | break;
|
|---|
| 171 | }
|
|---|
| 172 | }
|
|---|
| 173 | return found;
|
|---|
| 174 |
|
|---|
| 175 | }
|
|---|
| 176 | /*}}}*/
|
|---|
| 177 | /*FUNCTION Parameters::FindParam(double** pdoublearray,int* pM,int enum_type){{{1*/
|
|---|
| 178 | int Parameters::FindParam(double** pdoublearray,int* pM, int enum_type){
|
|---|
| 179 |
|
|---|
| 180 | /*Go through a dataset, and find a Param* object
|
|---|
| 181 | *which parameter name is "name" : */
|
|---|
| 182 |
|
|---|
| 183 | vector<Object*>::iterator object;
|
|---|
| 184 | Param* param=NULL;
|
|---|
| 185 |
|
|---|
| 186 | int found=0;
|
|---|
| 187 |
|
|---|
| 188 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 189 |
|
|---|
| 190 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 191 | param=(Param*)(*object);
|
|---|
| 192 |
|
|---|
| 193 | if(param->EnumType()==enum_type){
|
|---|
| 194 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 195 | param->GetParameterValue(pdoublearray,pM);
|
|---|
| 196 | found=1;
|
|---|
| 197 | break;
|
|---|
| 198 | }
|
|---|
| 199 | }
|
|---|
| 200 | return found;
|
|---|
| 201 |
|
|---|
| 202 | }
|
|---|
| 203 | /*}}}*/
|
|---|
| 204 | /*FUNCTION Parameters::FindParam(double** pdoublearray,int* pM, int* pN,int enum_type){{{1*/
|
|---|
| 205 | int Parameters::FindParam(double** pdoublearray,int* pM, int* pN,int enum_type){
|
|---|
| 206 |
|
|---|
| 207 | /*Go through a dataset, and find a Param* object
|
|---|
| 208 | *which parameter name is "name" : */
|
|---|
| 209 |
|
|---|
| 210 | vector<Object*>::iterator object;
|
|---|
| 211 | Param* param=NULL;
|
|---|
| 212 |
|
|---|
| 213 | int found=0;
|
|---|
| 214 |
|
|---|
| 215 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 216 |
|
|---|
| 217 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 218 | param=(Param*)(*object);
|
|---|
| 219 |
|
|---|
| 220 | if(param->EnumType()==enum_type){
|
|---|
| 221 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 222 | param->GetParameterValue(pdoublearray,pM,pN);
|
|---|
| 223 | found=1;
|
|---|
| 224 | break;
|
|---|
| 225 | }
|
|---|
| 226 | }
|
|---|
| 227 | return found;
|
|---|
| 228 |
|
|---|
| 229 | }
|
|---|
| 230 | /*}}}*/
|
|---|
| 231 | /*FUNCTION Parameters::FindParam(double*** parray,int* pM,int** pmdims_array,int** pndims_array,int enum_type){{{1*/
|
|---|
| 232 | int Parameters::FindParam(double*** parray,int* pM,int** pmdims_array,int** pndims_array,int enum_type){
|
|---|
| 233 |
|
|---|
| 234 | /*Go through a dataset, and find a Param* object
|
|---|
| 235 | *which parameter name is "name" : */
|
|---|
| 236 |
|
|---|
| 237 | vector<Object*>::iterator object;
|
|---|
| 238 | Param* param=NULL;
|
|---|
| 239 |
|
|---|
| 240 | int found=0;
|
|---|
| 241 |
|
|---|
| 242 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 243 |
|
|---|
| 244 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 245 | param=(Param*)(*object);
|
|---|
| 246 |
|
|---|
| 247 | if(param->EnumType()==enum_type){
|
|---|
| 248 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 249 | param->GetParameterValue(parray,pM,pmdims_array,pndims_array);
|
|---|
| 250 | found=1;
|
|---|
| 251 | break;
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 | return found;
|
|---|
| 255 | }
|
|---|
| 256 | /*}}}*/
|
|---|
| 257 | /*FUNCTION Parameters::FindParam(Vec* pvec,int enum_type){{{1*/
|
|---|
| 258 | int Parameters::FindParam(Vec* pvec,int enum_type){
|
|---|
| 259 |
|
|---|
| 260 | /*Go through a dataset, and find a Param* object
|
|---|
| 261 | *which parameter name is "name" : */
|
|---|
| 262 |
|
|---|
| 263 | vector<Object*>::iterator object;
|
|---|
| 264 | Param* param=NULL;
|
|---|
| 265 |
|
|---|
| 266 | int found=0;
|
|---|
| 267 |
|
|---|
| 268 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 269 |
|
|---|
| 270 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 271 | param=(Param*)(*object);
|
|---|
| 272 |
|
|---|
| 273 | if(param->EnumType()==enum_type){
|
|---|
| 274 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 275 | param->GetParameterValue(pvec);
|
|---|
| 276 | found=1;
|
|---|
| 277 | break;
|
|---|
| 278 | }
|
|---|
| 279 | }
|
|---|
| 280 | return found;
|
|---|
| 281 |
|
|---|
| 282 | }
|
|---|
| 283 | /*}}}*/
|
|---|
| 284 | /*FUNCTION Parameters::FindParam(Mat* pmat,int enum_type){{{1*/
|
|---|
| 285 | int Parameters::FindParam(Mat* pmat,int enum_type){
|
|---|
| 286 |
|
|---|
| 287 | /*Go through a dataset, and find a Param* object
|
|---|
| 288 | *which parameter name is "name" : */
|
|---|
| 289 |
|
|---|
| 290 | vector<Object*>::iterator object;
|
|---|
| 291 | Param* param=NULL;
|
|---|
| 292 |
|
|---|
| 293 | int found=0;
|
|---|
| 294 |
|
|---|
| 295 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 296 |
|
|---|
| 297 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 298 | param=(Param*)(*object);
|
|---|
| 299 |
|
|---|
| 300 | if(param->EnumType()==enum_type){
|
|---|
| 301 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 302 | param->GetParameterValue(pmat);
|
|---|
| 303 | found=1;
|
|---|
| 304 | break;
|
|---|
| 305 | }
|
|---|
| 306 | }
|
|---|
| 307 | return found;
|
|---|
| 308 |
|
|---|
| 309 | }
|
|---|
| 310 | /*}}}*/
|
|---|
| 311 |
|
|---|
| 312 | /*FUNCTION Parameters::SetParam(bool boolean,int enum_type);{{{1*/
|
|---|
| 313 | void Parameters::SetParam(bool boolean,int enum_type){
|
|---|
| 314 |
|
|---|
| 315 | Param* param=NULL;
|
|---|
| 316 |
|
|---|
| 317 | /*first, figure out if the param has already been created: */
|
|---|
| 318 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 319 |
|
|---|
| 320 | if(param) param->SetValue(boolean); //already exists, just set it.
|
|---|
| 321 | else this->AddObject(new BoolParam(enum_type,boolean)); //just add the new parameter.
|
|---|
| 322 | }
|
|---|
| 323 | /*}}}*/
|
|---|
| 324 | /*FUNCTION Parameters::SetParam(int integer,int enum_type);{{{1*/
|
|---|
| 325 | void Parameters::SetParam(int integer,int enum_type){
|
|---|
| 326 |
|
|---|
| 327 | Param* param=NULL;
|
|---|
| 328 |
|
|---|
| 329 | /*first, figure out if the param has already been created: */
|
|---|
| 330 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 331 |
|
|---|
| 332 | if(param) param->SetValue(integer); //already exists, just set it.
|
|---|
| 333 | else this->AddObject(new IntParam(enum_type,integer)); //just add the new parameter.
|
|---|
| 334 | }
|
|---|
| 335 | /*}}}*/
|
|---|
| 336 | /*FUNCTION Parameters::SetParam(double scalar,int enum_type);{{{1*/
|
|---|
| 337 | void Parameters::SetParam(double scalar,int enum_type){
|
|---|
| 338 |
|
|---|
| 339 | Param* param=NULL;
|
|---|
| 340 |
|
|---|
| 341 | /*first, figure out if the param has already been created: */
|
|---|
| 342 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 343 |
|
|---|
| 344 | if(param) param->SetValue(scalar); //already exists, just set it.
|
|---|
| 345 | else this->AddObject(new DoubleParam(enum_type,scalar)); //just add the new parameter.
|
|---|
| 346 | }
|
|---|
| 347 | /*}}}*/
|
|---|
| 348 | /*FUNCTION Parameters::SetParam(char* string,int enum_type);{{{1*/
|
|---|
| 349 | void Parameters::SetParam(char* string,int enum_type){
|
|---|
| 350 |
|
|---|
| 351 | Param* param=NULL;
|
|---|
| 352 |
|
|---|
| 353 | /*first, figure out if the param has already been created: */
|
|---|
| 354 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 355 |
|
|---|
| 356 | if(param) param->SetValue(string); //already exists, just set it.
|
|---|
| 357 | else this->AddObject(new StringParam(enum_type,string)); //just add the new parameter.
|
|---|
| 358 | }
|
|---|
| 359 | /*}}}*/
|
|---|
| 360 | /*FUNCTION Parameters::SetParam(char** stringarray,int M, int enum_type);{{{1*/
|
|---|
| 361 | void Parameters::SetParam(char** stringarray,int M, int enum_type){
|
|---|
| 362 |
|
|---|
| 363 | Param* param=NULL;
|
|---|
| 364 |
|
|---|
| 365 | /*first, figure out if the param has already been created: */
|
|---|
| 366 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 367 |
|
|---|
| 368 | if(param) param->SetValue(stringarray,M); //already exists, just set it.
|
|---|
| 369 | else this->AddObject(new StringArrayParam(enum_type,stringarray,M)); //just add the new parameter.
|
|---|
| 370 | }
|
|---|
| 371 | /*}}}*/
|
|---|
| 372 | /*FUNCTION Parameters::SetParam(double* doublearray,int M,int enum_type);{{{1*/
|
|---|
| 373 | void Parameters::SetParam(double* doublearray,int M, int enum_type){
|
|---|
| 374 |
|
|---|
| 375 | Param* param=NULL;
|
|---|
| 376 |
|
|---|
| 377 | /*first, figure out if the param has already been created: */
|
|---|
| 378 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 379 |
|
|---|
| 380 | if(param) param->SetValue(doublearray,M); //already exists, just set it.
|
|---|
| 381 | else this->AddObject(new DoubleVecParam(enum_type,doublearray,M)); //just add the new parameter.
|
|---|
| 382 | }
|
|---|
| 383 | /*}}}*/
|
|---|
| 384 | /*FUNCTION Parameters::SetParam(double* doublearray,int M,int N, int enum_type);{{{1*/
|
|---|
| 385 | void Parameters::SetParam(double* doublearray,int M, int N, int enum_type){
|
|---|
| 386 |
|
|---|
| 387 | Param* param=NULL;
|
|---|
| 388 |
|
|---|
| 389 | /*first, figure out if the param has already been created: */
|
|---|
| 390 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 391 |
|
|---|
| 392 | if(param) param->SetValue(doublearray,M,N); //already exists, just set it.
|
|---|
| 393 | else this->AddObject(new DoubleMatParam(enum_type,doublearray,M,N)); //just add the new parameter.
|
|---|
| 394 | }
|
|---|
| 395 | /*}}}*/
|
|---|
| 396 | /*FUNCTION Parameters::SetParam(Vec vector,int enum_type);{{{1*/
|
|---|
| 397 | void Parameters::SetParam(Vec vector,int enum_type){
|
|---|
| 398 |
|
|---|
| 399 | Param* param=NULL;
|
|---|
| 400 |
|
|---|
| 401 | /*first, figure out if the param has already been created: */
|
|---|
| 402 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 403 |
|
|---|
| 404 | if(param) param->SetValue(vector); //already exists, just set it.
|
|---|
| 405 | else this->AddObject(new PetscVecParam(enum_type,vector)); //just add the new parameter.
|
|---|
| 406 | }
|
|---|
| 407 | /*}}}*/
|
|---|
| 408 | /*FUNCTION Parameters::SetParam(Mat matrix,int enum_type);{{{1*/
|
|---|
| 409 | void Parameters::SetParam(Mat matrix,int enum_type){
|
|---|
| 410 |
|
|---|
| 411 | Param* param=NULL;
|
|---|
| 412 |
|
|---|
| 413 | /*first, figure out if the param has already been created: */
|
|---|
| 414 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 415 |
|
|---|
| 416 | if(param) param->SetValue(matrix); //already exists, just set it.
|
|---|
| 417 | else this->AddObject(new PetscMatParam(enum_type,matrix)); //just add the new parameter.
|
|---|
| 418 | }
|
|---|
| 419 | /*}}}*/
|
|---|
| 420 |
|
|---|
| 421 | /*FUNCTION Parameters::FindParamObject{{{1*/
|
|---|
| 422 | Object* Parameters::FindParamObject(int enum_type){
|
|---|
| 423 |
|
|---|
| 424 | /*Go through a dataset, and find a Param* object
|
|---|
| 425 | *which parameter name is "name" : */
|
|---|
| 426 |
|
|---|
| 427 | vector<Object*>::iterator object;
|
|---|
| 428 | Param* param=NULL;
|
|---|
| 429 |
|
|---|
| 430 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 431 |
|
|---|
| 432 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 433 | param=(Param*)(*object);
|
|---|
| 434 |
|
|---|
| 435 | if(param->EnumType()==enum_type){
|
|---|
| 436 | /*Ok, this is the one! Return the object: */
|
|---|
| 437 | return (*object);
|
|---|
| 438 | }
|
|---|
| 439 | }
|
|---|
| 440 | return NULL;
|
|---|
| 441 | }
|
|---|
| 442 | /*}}}*/
|
|---|