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

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

Adjustments to Petsc version 3

File size: 2.6 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 _error_("%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
68 #if _PETSC_VERSION_ == 2
69 PetscOptionsDestroy();
70 PetscOptionsCreate();
71 //PetscOptionsCheckInitial_Private();
72 //PetscOptionsCheckInitial_Components();
73 PetscOptionsSetFromOptions();
74 PetscOptionsInsertMultipleString(string); //our patch
75 #else
76 PetscOptionsSetFromOptions();
77 PetscOptionsClear();
78 //PetscOptionsSetFromOptions();
79 PetscOptionsInsertMultipleString(string); //our patch
80 #endif
81
82
83 /*Free ressources:{{{1*/
84 xfree((void**)&analyses);
85 for(i=0;i<numanalyses;i++){
86 string=strings[i];
87 xfree((void**)&string);
88 }
89 xfree((void**)&strings);
90 /*}}}*/
91
92}
Note: See TracBrowser for help on using the repository browser.