52 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
58 #include "../toolkits/toolkits.h"
59 #include "../shared/shared.h"
60 #include "../classes/classes.h"
61 #include "../modules/modules.h"
63 #if defined(_HAVE_DAKOTA_) && (_DAKOTA_MAJOR_ <= 5) //this only works for Dakota <=5, which had no effective parallel capabilities yet.
65 #if (_DAKOTA_MAJOR_ < 5 || (_DAKOTA_MAJOR_ == 5 && _DAKOTA_MINOR_ < 3))
66 #include <ParallelLibrary.H>
67 #include <ProblemDescDB.H>
68 #include <DakotaStrategy.H>
69 #include <DakotaModel.H>
70 #include <DakotaInterface.H>
72 #include <ParallelLibrary.hpp>
73 #include <ProblemDescDB.hpp>
74 #include <DakotaStrategy.hpp>
75 #include <DakotaModel.hpp>
76 #include <DakotaInterface.hpp>
80 void DakotaFree(
double** pvariables,
char*** pvariables_descriptors,
char*** presponses_descriptors,
int numvariables,
int numresponses){
87 double *variables = NULL;
88 char **variables_descriptors = NULL;
89 char **responses_descriptors = NULL;
93 variables=*pvariables;
94 variables_descriptors=*pvariables_descriptors;
95 responses_descriptors=*presponses_descriptors;
102 xDelete<double>(variables);
103 for(i=0;i<numvariables;i++){
104 string=variables_descriptors[i];
105 xDelete<char>(
string);
107 xDelete<char*>(variables_descriptors);
111 for(i=0;i<numresponses;i++){
112 string=responses_descriptors[i];
113 xDelete<char>(
string);
116 xDelete<char*>(responses_descriptors);
119 *pvariables=variables;
120 *pvariables_descriptors=variables_descriptors;
121 *presponses_descriptors=responses_descriptors;
123 void DakotaMPI_Bcast(
double** pvariables,
char*** pvariables_descriptors,
int* pnumvariables,
int* pnumresponses){
133 double* variables=NULL;
134 char** variables_descriptors=NULL;
146 variables=*pvariables;
147 variables_descriptors=*pvariables_descriptors;
148 numvariables=*pnumvariables;
149 numresponses=*pnumresponses;
155 if(my_rank!=0)variables=xNew<double>(numvariables);
160 variables_descriptors=xNew<char*>(numvariables);
162 for(i=0;i<numvariables;i++){
164 string=variables_descriptors[i];
165 string_length=(strlen(
string)+1)*
sizeof(
char);
168 if(my_rank!=0)
string=xNew<char>(string_length);
170 if(my_rank!=0)variables_descriptors[i]=string;
177 *pnumvariables=numvariables;
178 *pvariables=variables;
179 *pvariables_descriptors=variables_descriptors;
180 *pnumresponses=numresponses;
182 int DakotaSpawnCore(
double* d_responses,
int d_numresponses,
double* d_variables,
char** d_variables_descriptors,
int d_numvariables,
void* void_femmodel,
int counter){
186 char **responses_descriptors = NULL;
187 int numresponsedescriptors;
189 bool control_analysis =
false;
190 void (*solutioncore)(
FemModel*) = NULL;
192 bool nodakotacore =
true;
196 if(counter==-1)
return 0;
210 DakotaMPI_Bcast(&d_variables,&d_variables_descriptors,&d_numvariables,&d_numresponses);
224 femmodel->DakotaResponsesx(d_responses,responses_descriptors,numresponsedescriptors,d_numresponses);
231 DakotaFree(&d_variables,&d_variables_descriptors,&responses_descriptors, d_numvariables, numresponsedescriptors);
242 char *dakota_input_file = NULL;
243 char *dakota_output_file = NULL;
244 char *dakota_error_file = NULL;
245 Dakota::ModelLIter ml_iter;
259 char* dakotamode=xNew<char>(strlen(
"serial")+1);
260 xMemCpy<char>(dakotamode,
"serial",strlen(
"serial")+1);
261 Dakota::ParallelLibrary parallel_lib(dakotamode);
262 Dakota::ProblemDescDB problem_db(parallel_lib);
263 xDelete<char>(dakotamode);
268 problem_db.manage_inputs(dakota_input_file);
270 parallel_lib.specify_outputs_restart(dakota_output_file,dakota_error_file,NULL,NULL);
274 Dakota::Strategy selected_strategy(problem_db);
278 Dakota::ModelList& models = problem_db.model_list();
280 for (ml_iter = models.begin(); ml_iter != models.end(); ml_iter++) {
282 Dakota::Interface&
interface = ml_iter->interface();
285 problem_db.set_db_model_nodes(ml_iter->model_id());
288 interface.assign_rep(
new SIM::IssmDirectApplicInterface(problem_db,(
void*)
femmodel),
false);
293 selected_strategy.run_strategy();
296 DakotaSpawnCore(NULL,0, NULL,NULL,0,
femmodel,-1);
302 if(!DakotaSpawnCore(NULL,0, NULL,NULL,0,
femmodel,0))
break;
307 xDelete<char>(dakota_input_file);
308 xDelete<char>(dakota_error_file);
309 xDelete<char>(dakota_output_file);
314 _error_(
"dakota_core for versions of Dakota >=6 should not be used anymore! Use instead the issm_dakota executable!");