Ice Sheet System Model  4.18
Code documentation
IssmDirectApplicInterface.h
Go to the documentation of this file.
1 
32 /*Issm Configuration: {{{*/
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #else
36 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
37 #endif
38 /*}}}*/
39 
40 #if !defined(_WRAPPERS_) && defined(_HAVE_DAKOTA_) && (_DAKOTA_MAJOR_ <= 5) //this only works for Dakota <=5, which had no effective parallel capabilities yet.
41 
42 /*Dakota include files:{{{*/
43 #if (_DAKOTA_MAJOR_ < 5 || (_DAKOTA_MAJOR_ == 5 && _DAKOTA_MINOR_ < 3))
44 #include <DirectApplicInterface.H>
45 #include <DakotaResponse.H>
46 #include <ParamResponsePair.H>
47 #include <system_defs.h>
48 #include <ProblemDescDB.H>
49 #include <ParallelLibrary.H>
50 #else
51 #include <DirectApplicInterface.hpp>
52 #include <DakotaResponse.hpp>
53 #include <ParamResponsePair.hpp>
54 #include <ProblemDescDB.hpp>
55 #include <ParallelLibrary.hpp>
56 #endif
57 /*}}}*/
58 
59 int DakotaSpawnCore(double* d_responses, int d_numresponses, double* d_variables, char** d_variables_descriptors,int d_numvariables, void* void_femmodel,int counter);
60 
61 /*IssmDirectApplicInterface class */
62 namespace SIM {
63  class IssmDirectApplicInterface: public Dakota::DirectApplicInterface{
64  public:
65  /*these fields are used by core solutions: */
66  void *femmodel;
67  int counter;
68  /*Constructors/Destructors*/
69  IssmDirectApplicInterface(const Dakota::ProblemDescDB& problem_db,void* in_femmodel):Dakota::DirectApplicInterface(problem_db){/*{{{*/
70  femmodel = in_femmodel;
71  counter = 0;
72  }/*}}}*/
73  ~IssmDirectApplicInterface(){/*{{{*/
74  /* Virtual destructor handles referenceCount at Interface level. */
75  }/*}}}*/
76  protected:
77  /*execute the input filter portion of a direct evaluation invocation*/
78  //int derived_map_if(const Dakota::String& if_name);
79  /*execute an analysis code portion of a direct evaluation invocation*/
80  int derived_map_ac(const Dakota::String& driver){/*{{{*/
81 
82  int i;
83  IssmDouble* variables=NULL;
84  char** variable_descriptors=NULL;
85  char* variable_descriptor=NULL;
86  IssmDouble* responses=NULL;
87 
88  /*increae counter: */
89  counter++;
90 
91  /*Before launching analysis, we need to transfer the dakota inputs into Issm
92  *readable variables: */
93 
94  /*First, the variables: */
95  variables=xNew<IssmDouble>(numACV);
96  for(i=0;i<numACV;i++){
97  variables[i]=xC[i];
98  }
99  /*The descriptors: */
100  variable_descriptors=xNew<char*>(numACV);
101  for(i=0;i<numACV;i++){
102  std::string label=xCLabels[i];
103  variable_descriptor=xNew<char>(strlen(label.c_str())+1);
104  memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char));
105 
106  variable_descriptors[i]=variable_descriptor;
107  }
108 
109  /*Initialize responses: */
110  responses=xNewZeroInit<IssmDouble>(numFns);
111 
112  /*run core solution: */
113  DakotaSpawnCore(responses,numFns, variables,variable_descriptors,numACV,femmodel,counter);
114 
115  /*populate responses: */
116  for(i=0;i<numFns;i++){
117  fnVals[i]=responses[i];
118  }
119 
120  /*Free ressources:*/
121  xDelete<IssmDouble>(variables);
122  for(i=0;i<numACV;i++){
123  variable_descriptor=variable_descriptors[i];
124  xDelete<char>(variable_descriptor);
125  }
126  xDelete<char*>(variable_descriptors);
127  xDelete<IssmDouble>(responses);
128 
129  return 0;
130  }/*}}}*/
131  /*execute the output filter portion of a direct evaluation invocation*/
132  //int derived_map_of(const Dakota::String& of_name);
133  /*add for issm: */
134  int GetCounter(){/*{{{*/
135  return counter;
136  }/*}}}*/
137  private:
138  };
139 }
140 #endif
IssmDouble
double IssmDouble
Definition: types.h:37
femmodel
FemModel * femmodel
Definition: esmfbinders.cpp:16