source: issm/trunk/src/c/Container/Parameters.cpp@ 6213

Last change on this file since 6213 was 6213, checked in by Mathieu Morlighem, 14 years ago

Prepared ISSM for multivariable CM, Added modules/ModelProcessorx/Control/UpdateElementsAndMaterialsControl.cpp

File size: 13.7 KB
Line 
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
23using namespace std;
24/*}}}*/
25
26/*Object constructors and destructor*/
27/*FUNCTION Parameters::Parameters(){{{1*/
28Parameters::Parameters(){
29 return;
30}
31/*}}}*/
32/*FUNCTION Parameters::Parameters(int in_enum){{{1*/
33Parameters::Parameters(int in_enum): DataSet(in_enum){
34 //do nothing;
35 return;
36}
37/*}}}*/
38/*FUNCTION Parameters::~Parameters(){{{1*/
39Parameters::~Parameters(){
40 return;
41}
42/*}}}*/
43
44/*Object management*/
45/*FUNCTION Parameters::FindParam(bool* pbool,int enum_type){{{1*/
46int 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*/
72int 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*/
98int 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*/
124int 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*/
151int 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(int** pintarray,int* pM,int enum_type){{{1*/
178int Parameters::FindParam(int** pintarray,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(pintarray,pM);
196 found=1;
197 break;
198 }
199 }
200 return found;
201
202}
203/*}}}*/
204/*FUNCTION Parameters::FindParam(double** pdoublearray,int* pM,int enum_type){{{1*/
205int Parameters::FindParam(double** pdoublearray,int* pM, 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);
223 found=1;
224 break;
225 }
226 }
227 return found;
228
229}
230/*}}}*/
231/*FUNCTION Parameters::FindParam(double** pdoublearray,int* pM, int* pN,int enum_type){{{1*/
232int Parameters::FindParam(double** pdoublearray,int* pM, int* pN,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(pdoublearray,pM,pN);
250 found=1;
251 break;
252 }
253 }
254 return found;
255
256}
257/*}}}*/
258/*FUNCTION Parameters::FindParam(double*** parray,int* pM,int** pmdims_array,int** pndims_array,int enum_type){{{1*/
259int Parameters::FindParam(double*** parray,int* pM,int** pmdims_array,int** pndims_array,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(parray,pM,pmdims_array,pndims_array);
277 found=1;
278 break;
279 }
280 }
281 return found;
282}
283/*}}}*/
284/*FUNCTION Parameters::FindParam(Vec* pvec,int enum_type){{{1*/
285int Parameters::FindParam(Vec* pvec,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(pvec);
303 found=1;
304 break;
305 }
306 }
307 return found;
308
309}
310/*}}}*/
311/*FUNCTION Parameters::FindParam(Mat* pmat,int enum_type){{{1*/
312int Parameters::FindParam(Mat* pmat,int enum_type){
313
314 /*Go through a dataset, and find a Param* object
315 *which parameter name is "name" : */
316
317 vector<Object*>::iterator object;
318 Param* param=NULL;
319
320 int found=0;
321
322 for ( object=objects.begin() ; object < objects.end(); object++ ){
323
324 /*Ok, this object is a parameter, recover it and ask which name it has: */
325 param=(Param*)(*object);
326
327 if(param->EnumType()==enum_type){
328 /*Ok, this is the one! Recover the value of this parameter: */
329 param->GetParameterValue(pmat);
330 found=1;
331 break;
332 }
333 }
334 return found;
335
336}
337/*}}}*/
338/*FUNCTION Parameters::FindParam(FILE** pfid,int enum_type){{{1*/
339int Parameters::FindParam(FILE** pfid,int enum_type){
340
341 /*Go through a dataset, and find a Param* object
342 *which parameter name is "name" : */
343
344 vector<Object*>::iterator object;
345 Param* param=NULL;
346
347 int found=0;
348
349 for ( object=objects.begin() ; object < objects.end(); object++ ){
350
351 /*Ok, this object is a parameter, recover it and ask which name it has: */
352 param=(Param*)(*object);
353
354 if(param->EnumType()==enum_type){
355 /*Ok, this is the one! Recover the value of this parameter: */
356 param->GetParameterValue(pfid);
357 found=1;
358 break;
359 }
360 }
361 return found;
362}
363/*}}}*/
364
365/*FUNCTION Parameters::SetParam(bool boolean,int enum_type);{{{1*/
366void Parameters::SetParam(bool boolean,int enum_type){
367
368 Param* param=NULL;
369
370 /*first, figure out if the param has already been created: */
371 param=(Param*)this->FindParamObject(enum_type);
372
373 if(param) param->SetValue(boolean); //already exists, just set it.
374 else this->AddObject(new BoolParam(enum_type,boolean)); //just add the new parameter.
375}
376/*}}}*/
377/*FUNCTION Parameters::SetParam(int integer,int enum_type);{{{1*/
378void Parameters::SetParam(int integer,int enum_type){
379
380 Param* param=NULL;
381
382 /*first, figure out if the param has already been created: */
383 param=(Param*)this->FindParamObject(enum_type);
384
385 if(param) param->SetValue(integer); //already exists, just set it.
386 else this->AddObject(new IntParam(enum_type,integer)); //just add the new parameter.
387}
388/*}}}*/
389/*FUNCTION Parameters::SetParam(double scalar,int enum_type);{{{1*/
390void Parameters::SetParam(double scalar,int enum_type){
391
392 Param* param=NULL;
393
394 /*first, figure out if the param has already been created: */
395 param=(Param*)this->FindParamObject(enum_type);
396
397 if(param) param->SetValue(scalar); //already exists, just set it.
398 else this->AddObject(new DoubleParam(enum_type,scalar)); //just add the new parameter.
399}
400/*}}}*/
401/*FUNCTION Parameters::SetParam(char* string,int enum_type);{{{1*/
402void Parameters::SetParam(char* string,int enum_type){
403
404 Param* param=NULL;
405
406 /*first, figure out if the param has already been created: */
407 param=(Param*)this->FindParamObject(enum_type);
408
409 if(param) param->SetValue(string); //already exists, just set it.
410 else this->AddObject(new StringParam(enum_type,string)); //just add the new parameter.
411}
412/*}}}*/
413/*FUNCTION Parameters::SetParam(char** stringarray,int M, int enum_type);{{{1*/
414void Parameters::SetParam(char** stringarray,int M, int enum_type){
415
416 Param* param=NULL;
417
418 /*first, figure out if the param has already been created: */
419 param=(Param*)this->FindParamObject(enum_type);
420
421 if(param) param->SetValue(stringarray,M); //already exists, just set it.
422 else this->AddObject(new StringArrayParam(enum_type,stringarray,M)); //just add the new parameter.
423}
424/*}}}*/
425/*FUNCTION Parameters::SetParam(double* doublearray,int M,int enum_type);{{{1*/
426void Parameters::SetParam(double* doublearray,int M, int enum_type){
427
428 Param* param=NULL;
429
430 /*first, figure out if the param has already been created: */
431 param=(Param*)this->FindParamObject(enum_type);
432
433 if(param) param->SetValue(doublearray,M); //already exists, just set it.
434 else this->AddObject(new DoubleVecParam(enum_type,doublearray,M)); //just add the new parameter.
435}
436/*}}}*/
437/*FUNCTION Parameters::SetParam(double* doublearray,int M,int N, int enum_type);{{{1*/
438void Parameters::SetParam(double* doublearray,int M, int N, int enum_type){
439
440 Param* param=NULL;
441
442 /*first, figure out if the param has already been created: */
443 param=(Param*)this->FindParamObject(enum_type);
444
445 if(param) param->SetValue(doublearray,M,N); //already exists, just set it.
446 else this->AddObject(new DoubleMatParam(enum_type,doublearray,M,N)); //just add the new parameter.
447}
448/*}}}*/
449/*FUNCTION Parameters::SetParam(Vec vector,int enum_type);{{{1*/
450void Parameters::SetParam(Vec vector,int enum_type){
451
452 Param* param=NULL;
453
454 /*first, figure out if the param has already been created: */
455 param=(Param*)this->FindParamObject(enum_type);
456
457 if(param) param->SetValue(vector); //already exists, just set it.
458 else this->AddObject(new PetscVecParam(enum_type,vector)); //just add the new parameter.
459}
460/*}}}*/
461/*FUNCTION Parameters::SetParam(Mat matrix,int enum_type);{{{1*/
462void Parameters::SetParam(Mat matrix,int enum_type){
463
464 Param* param=NULL;
465
466 /*first, figure out if the param has already been created: */
467 param=(Param*)this->FindParamObject(enum_type);
468
469 if(param) param->SetValue(matrix); //already exists, just set it.
470 else this->AddObject(new PetscMatParam(enum_type,matrix)); //just add the new parameter.
471}
472/*}}}*/
473/*FUNCTION Parameters::SetParam(FILE* fid,int enum_type);{{{1*/
474void Parameters::SetParam(FILE* fid,int enum_type){
475
476 Param* param=NULL;
477
478 /*first, figure out if the param has already been created: */
479 param=(Param*)this->FindParamObject(enum_type);
480
481 if(param) param->SetValue(fid); //already exists, just set it.
482 else this->AddObject(new FileParam(enum_type,fid)); //just add the new parameter.
483}
484/*}}}*/
485
486/*FUNCTION Parameters::FindParamObject{{{1*/
487Object* Parameters::FindParamObject(int enum_type){
488
489 /*Go through a dataset, and find a Param* object
490 *which parameter name is "name" : */
491
492 vector<Object*>::iterator object;
493 Param* param=NULL;
494
495 for ( object=objects.begin() ; object < objects.end(); object++ ){
496
497 /*Ok, this object is a parameter, recover it and ask which name it has: */
498 param=(Param*)(*object);
499
500 if(param->EnumType()==enum_type){
501 /*Ok, this is the one! Return the object: */
502 return (*object);
503 }
504 }
505 return NULL;
506}
507/*}}}*/
Note: See TracBrowser for help on using the repository browser.