| 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(Vec* pvec,int enum_type){{{1*/
|
|---|
| 232 | int Parameters::FindParam(Vec* pvec,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(pvec);
|
|---|
| 250 | found=1;
|
|---|
| 251 | break;
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 | return found;
|
|---|
| 255 |
|
|---|
| 256 | }
|
|---|
| 257 | /*}}}*/
|
|---|
| 258 | /*FUNCTION Parameters::FindParam(Mat* pmat,int enum_type){{{1*/
|
|---|
| 259 | int Parameters::FindParam(Mat* pmat,int enum_type){
|
|---|
| 260 |
|
|---|
| 261 | /*Go through a dataset, and find a Param* object
|
|---|
| 262 | *which parameter name is "name" : */
|
|---|
| 263 |
|
|---|
| 264 | vector<Object*>::iterator object;
|
|---|
| 265 | Param* param=NULL;
|
|---|
| 266 |
|
|---|
| 267 | int found=0;
|
|---|
| 268 |
|
|---|
| 269 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 270 |
|
|---|
| 271 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 272 | param=(Param*)(*object);
|
|---|
| 273 |
|
|---|
| 274 | if(param->EnumType()==enum_type){
|
|---|
| 275 | /*Ok, this is the one! Recover the value of this parameter: */
|
|---|
| 276 | param->GetParameterValue(pmat);
|
|---|
| 277 | found=1;
|
|---|
| 278 | break;
|
|---|
| 279 | }
|
|---|
| 280 | }
|
|---|
| 281 | return found;
|
|---|
| 282 |
|
|---|
| 283 | }
|
|---|
| 284 | /*}}}*/
|
|---|
| 285 |
|
|---|
| 286 | /*FUNCTION Parameters::SetParam(bool boolean,int enum_type);{{{1*/
|
|---|
| 287 | void Parameters::SetParam(bool boolean,int enum_type){
|
|---|
| 288 |
|
|---|
| 289 | Param* param=NULL;
|
|---|
| 290 |
|
|---|
| 291 | /*first, figure out if the param has already been created: */
|
|---|
| 292 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 293 |
|
|---|
| 294 | if(param) param->SetValue(boolean); //already exists, just set it.
|
|---|
| 295 | else this->AddObject(new BoolParam(enum_type,boolean)); //just add the new parameter.
|
|---|
| 296 | }
|
|---|
| 297 | /*}}}*/
|
|---|
| 298 | /*FUNCTION Parameters::SetParam(int integer,int enum_type);{{{1*/
|
|---|
| 299 | void Parameters::SetParam(int integer,int enum_type){
|
|---|
| 300 |
|
|---|
| 301 | Param* param=NULL;
|
|---|
| 302 |
|
|---|
| 303 | /*first, figure out if the param has already been created: */
|
|---|
| 304 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 305 |
|
|---|
| 306 | if(param) param->SetValue(integer); //already exists, just set it.
|
|---|
| 307 | else this->AddObject(new IntParam(enum_type,integer)); //just add the new parameter.
|
|---|
| 308 | }
|
|---|
| 309 | /*}}}*/
|
|---|
| 310 | /*FUNCTION Parameters::SetParam(double scalar,int enum_type);{{{1*/
|
|---|
| 311 | void Parameters::SetParam(double scalar,int enum_type){
|
|---|
| 312 |
|
|---|
| 313 | Param* param=NULL;
|
|---|
| 314 |
|
|---|
| 315 | /*first, figure out if the param has already been created: */
|
|---|
| 316 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 317 |
|
|---|
| 318 | if(param) param->SetValue(scalar); //already exists, just set it.
|
|---|
| 319 | else this->AddObject(new DoubleParam(enum_type,scalar)); //just add the new parameter.
|
|---|
| 320 | }
|
|---|
| 321 | /*}}}*/
|
|---|
| 322 | /*FUNCTION Parameters::SetParam(char* string,int enum_type);{{{1*/
|
|---|
| 323 | void Parameters::SetParam(char* string,int enum_type){
|
|---|
| 324 |
|
|---|
| 325 | Param* param=NULL;
|
|---|
| 326 |
|
|---|
| 327 | /*first, figure out if the param has already been created: */
|
|---|
| 328 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 329 |
|
|---|
| 330 | if(param) param->SetValue(string); //already exists, just set it.
|
|---|
| 331 | else this->AddObject(new StringParam(enum_type,string)); //just add the new parameter.
|
|---|
| 332 | }
|
|---|
| 333 | /*}}}*/
|
|---|
| 334 | /*FUNCTION Parameters::SetParam(char** stringarray,int M, int enum_type);{{{1*/
|
|---|
| 335 | void Parameters::SetParam(char** stringarray,int M, int enum_type){
|
|---|
| 336 |
|
|---|
| 337 | Param* param=NULL;
|
|---|
| 338 |
|
|---|
| 339 | /*first, figure out if the param has already been created: */
|
|---|
| 340 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 341 |
|
|---|
| 342 | if(param) param->SetValue(stringarray,M); //already exists, just set it.
|
|---|
| 343 | else this->AddObject(new StringArrayParam(enum_type,stringarray,M)); //just add the new parameter.
|
|---|
| 344 | }
|
|---|
| 345 | /*}}}*/
|
|---|
| 346 | /*FUNCTION Parameters::SetParam(double* doublearray,int M,int enum_type);{{{1*/
|
|---|
| 347 | void Parameters::SetParam(double* doublearray,int M, int enum_type){
|
|---|
| 348 |
|
|---|
| 349 | Param* param=NULL;
|
|---|
| 350 |
|
|---|
| 351 | /*first, figure out if the param has already been created: */
|
|---|
| 352 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 353 |
|
|---|
| 354 | if(param) param->SetValue(doublearray,M); //already exists, just set it.
|
|---|
| 355 | else this->AddObject(new DoubleVecParam(enum_type,doublearray,M)); //just add the new parameter.
|
|---|
| 356 | }
|
|---|
| 357 | /*}}}*/
|
|---|
| 358 | /*FUNCTION Parameters::SetParam(double* doublearray,int M,int N, int enum_type);{{{1*/
|
|---|
| 359 | void Parameters::SetParam(double* doublearray,int M, int N, int enum_type){
|
|---|
| 360 |
|
|---|
| 361 | Param* param=NULL;
|
|---|
| 362 |
|
|---|
| 363 | /*first, figure out if the param has already been created: */
|
|---|
| 364 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 365 |
|
|---|
| 366 | if(param) param->SetValue(doublearray,M,N); //already exists, just set it.
|
|---|
| 367 | else this->AddObject(new DoubleMatParam(enum_type,doublearray,M,N)); //just add the new parameter.
|
|---|
| 368 | }
|
|---|
| 369 | /*}}}*/
|
|---|
| 370 | /*FUNCTION Parameters::SetParam(Vec vector,int enum_type);{{{1*/
|
|---|
| 371 | void Parameters::SetParam(Vec vector,int enum_type){
|
|---|
| 372 |
|
|---|
| 373 | Param* param=NULL;
|
|---|
| 374 |
|
|---|
| 375 | /*first, figure out if the param has already been created: */
|
|---|
| 376 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 377 |
|
|---|
| 378 | if(param) param->SetValue(vector); //already exists, just set it.
|
|---|
| 379 | else this->AddObject(new PetscVecParam(enum_type,vector)); //just add the new parameter.
|
|---|
| 380 | }
|
|---|
| 381 | /*}}}*/
|
|---|
| 382 | /*FUNCTION Parameters::SetParam(Mat matrix,int enum_type);{{{1*/
|
|---|
| 383 | void Parameters::SetParam(Mat matrix,int enum_type){
|
|---|
| 384 |
|
|---|
| 385 | Param* param=NULL;
|
|---|
| 386 |
|
|---|
| 387 | /*first, figure out if the param has already been created: */
|
|---|
| 388 | param=(Param*)this->FindParamObject(enum_type);
|
|---|
| 389 |
|
|---|
| 390 | if(param) param->SetValue(matrix); //already exists, just set it.
|
|---|
| 391 | else this->AddObject(new PetscMatParam(enum_type,matrix)); //just add the new parameter.
|
|---|
| 392 | }
|
|---|
| 393 | /*}}}*/
|
|---|
| 394 |
|
|---|
| 395 | /*FUNCTION Parameters::FindParamObject{{{1*/
|
|---|
| 396 | Object* Parameters::FindParamObject(int enum_type){
|
|---|
| 397 |
|
|---|
| 398 | /*Go through a dataset, and find a Param* object
|
|---|
| 399 | *which parameter name is "name" : */
|
|---|
| 400 |
|
|---|
| 401 | vector<Object*>::iterator object;
|
|---|
| 402 | Param* param=NULL;
|
|---|
| 403 |
|
|---|
| 404 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
|---|
| 405 |
|
|---|
| 406 | /*Ok, this object is a parameter, recover it and ask which name it has: */
|
|---|
| 407 | param=(Param*)(*object);
|
|---|
| 408 |
|
|---|
| 409 | if(param->EnumType()==enum_type){
|
|---|
| 410 | /*Ok, this is the one! Return the object: */
|
|---|
| 411 | return (*object);
|
|---|
| 412 | }
|
|---|
| 413 | }
|
|---|
| 414 | return NULL;
|
|---|
| 415 | }
|
|---|
| 416 | /*}}}*/
|
|---|