source: issm/trunk/src/c/shared/Numerics/PetscOptionsFromAnalysis.cpp@ 6020

Last change on this file since 6020 was 6020, checked in by Eric.Larour, 14 years ago

Fixed bug with Double instead of DoubleVec Param being load for the analyses.
Some other quick fixes.

File size: 2.4 KB
Line 
1/*!\file: PetscOptionsFromAnalysis.cpp
2 * \brief: change petsc options using analysis type and parameters
3 */
4
5#ifdef HAVE_CONFIG_H
6 #include "config.h"
7#else
8#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
9#endif
10
11#include "../../objects/objects.h"
12#include "../../Container/Parameters.h"
13#include "../../toolkits/toolkits.h"
14
15void PetscOptionsFromAnalysis(Parameters* parameters,int analysis_type){
16
17 int dummy;
18 double* analyses=NULL;
19 char** strings=NULL;
20 int numanalyses;
21 char* string=NULL;
22 int found=-1;
23 int i;
24
25 numanalyses=0;
26 parameters->FindParam(&strings,&numanalyses,PetscOptionsStringsEnum);
27
28 #ifdef _SERIAL_ //do not take this away, because ISSM loads analyses as a Double Param instead of a DoubleVec Param when running with only 1 analysis
29 if(numanalyses==1){ analyses=(double*)xmalloc(1*sizeof(double)); parameters->FindParam(analyses,PetscOptionsAnalysesEnum);
30 }
31 else parameters->FindParam(&analyses,&dummy,PetscOptionsAnalysesEnum);
32 #else
33 parameters->FindParam(&analyses,&dummy,PetscOptionsAnalysesEnum);
34 #endif
35
36 if(numanalyses==0)return; //we did not find petsc options, don't bother.
37
38 /*ok, go through analyses and figure out if it corresponds to our analysis_type: */
39 found=-1;
40 for(i=0;i<numanalyses;i++){
41 if (analyses[i]==analysis_type){
42 /*found the analysis, get out of here: */
43 found=i;
44 break;
45 }
46 }
47 if(found==-1){
48 /*still haven't found a list of petsc options, go find the default one, for analysis type NoneAnalysisEnum: */
49 for(i=0;i<numanalyses;i++){
50 if (analyses[i]==NoneAnalysisEnum){
51 /*found the default analysis, get out of here: */
52 found=i;
53 break;
54 }
55 }
56 }
57 if (found==-1){
58 /*ok, we did not find anything, this is not good! error out: */
59 ISSMERROR("%s%s","could find neither a default analysis nor analysis ",EnumToString(analysis_type));
60 }
61
62 /*ok, grab the petsc option string: */
63 string=strings[found];
64
65 /*now, reset the options database with this string. Taken from petsc/install/src/sys/objects/pinit.c. This
66 *capability is not covered by Petsc!: */
67 PetscOptionsDestroy();
68 PetscOptionsCreate();
69 //PetscOptionsCheckInitial_Private();
70 //PetscOptionsCheckInitial_Components();
71 PetscOptionsSetFromOptions();
72 PetscOptionsInsertMultipleString(string); //our patch
73
74 /*Free ressources:{{{1*/
75 xfree((void**)&analyses);
76 for(i=0;i<numanalyses;i++){
77 string=strings[i];
78 xfree((void**)&string);
79 }
80 xfree((void**)&strings);
81 /*}}}*/
82
83}
Note: See TracBrowser for help on using the repository browser.