| 1 | /*!\file: DakotaPlugin.cpp (see DakotaPlugin.h for explanations)
|
|---|
| 2 | * \brief header file for derived DirectApplicInterface class.
|
|---|
| 3 | * \sa SpwanCore.cpp and \sa qmu.cpp
|
|---|
| 4 | *
|
|---|
| 5 | * This class needs to be understood simultaneously with qmu.cpp and SpwanCore.cpp.
|
|---|
| 6 | * This call is derived from the Dakota DirectApplicInterface class. This is the
|
|---|
| 7 | * only way to plug ISSM's own routines into the Dakota engine. The derived class
|
|---|
| 8 | * has one function called derived_map_ac, which is called by Dakota to drive the
|
|---|
| 9 | * entire snesitivity analysis.
|
|---|
| 10 | *
|
|---|
| 11 | * We use this routine (which gets variables, variable_descriptors from the Dakota
|
|---|
| 12 | * engine, and requests responses from the ISSM solution sequences), to call our
|
|---|
| 13 | * own solutoin cores. This routines calls the SpawnCore routine, which will drive
|
|---|
| 14 | * the entire computations.
|
|---|
| 15 | */
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | #ifdef HAVE_CONFIG_H
|
|---|
| 19 | #include <config.h>
|
|---|
| 20 | #else
|
|---|
| 21 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
|---|
| 22 | #endif
|
|---|
| 23 |
|
|---|
| 24 | /*Standard ISSM includes: */
|
|---|
| 25 | #include "../../shared/shared.h"
|
|---|
| 26 | #include "../../include/include.h"
|
|---|
| 27 | #include "../classes.h"
|
|---|
| 28 | #include "../../modules/Dakotax/Dakotax.h"
|
|---|
| 29 |
|
|---|
| 30 | /*Standard includes: */
|
|---|
| 31 | #include <string>
|
|---|
| 32 |
|
|---|
| 33 | #ifdef _HAVE_DAKOTA_ //only works if dakota library has been compiled in.
|
|---|
| 34 |
|
|---|
| 35 | //Dakota headers
|
|---|
| 36 | #include "DakotaResponse.H"
|
|---|
| 37 | #include "ParamResponsePair.H"
|
|---|
| 38 | #include "DakotaPlugin.h"
|
|---|
| 39 | #include "system_defs.h"
|
|---|
| 40 | #include "ProblemDescDB.H"
|
|---|
| 41 | #include "ParallelLibrary.H"
|
|---|
| 42 |
|
|---|
| 43 | namespace SIM {
|
|---|
| 44 |
|
|---|
| 45 | //constructor
|
|---|
| 46 | DakotaPlugin::DakotaPlugin(const Dakota::ProblemDescDB& problem_db,void* in_femmodel):Dakota::DirectApplicInterface(problem_db){
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | femmodel=in_femmodel;
|
|---|
| 50 | counter=0;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | //destructor
|
|---|
| 54 | DakotaPlugin::~DakotaPlugin(){ /* Virtual destructor handles referenceCount at Interface level. */ }
|
|---|
| 55 |
|
|---|
| 56 | int DakotaPlugin::derived_map_ac(const Dakota::String& driver) {
|
|---|
| 57 |
|
|---|
| 58 | int i;
|
|---|
| 59 | IssmDouble* variables=NULL;
|
|---|
| 60 | char** variable_descriptors=NULL;
|
|---|
| 61 | char* variable_descriptor=NULL;
|
|---|
| 62 | IssmDouble* responses=NULL;
|
|---|
| 63 |
|
|---|
| 64 | /*increae counter: */
|
|---|
| 65 | counter++;
|
|---|
| 66 |
|
|---|
| 67 | /*Before launching analysis, we need to transfer the dakota inputs into Issm
|
|---|
| 68 | *readable variables: */
|
|---|
| 69 |
|
|---|
| 70 | /*First, the variables: */
|
|---|
| 71 | variables=xNew<IssmDouble>(numACV);
|
|---|
| 72 | for(i=0;i<numACV;i++){
|
|---|
| 73 | variables[i]=xC[i];
|
|---|
| 74 | }
|
|---|
| 75 | /*The descriptors: */
|
|---|
| 76 | variable_descriptors=xNew<char*>(numACV);
|
|---|
| 77 | for(i=0;i<numACV;i++){
|
|---|
| 78 | string label=xCLabels[i];
|
|---|
| 79 | variable_descriptor=xNew<char>(strlen(label.c_str())+1);
|
|---|
| 80 | memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char));
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 | variable_descriptors[i]=variable_descriptor;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | /*Initialize responses: */
|
|---|
| 87 | responses=xNewZeroInit<IssmDouble>(numFns);
|
|---|
| 88 |
|
|---|
| 89 | /*run core solution: */
|
|---|
| 90 | SpawnCore(responses,numFns, variables,variable_descriptors,numACV,femmodel,counter);
|
|---|
| 91 |
|
|---|
| 92 | /*populate responses: */
|
|---|
| 93 | for(i=0;i<numFns;i++){
|
|---|
| 94 | fnVals[i]=responses[i];
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 | /*Free ressources:*/
|
|---|
| 99 | xDelete<IssmDouble>(variables);
|
|---|
| 100 | for(i=0;i<numACV;i++){
|
|---|
| 101 | variable_descriptor=variable_descriptors[i];
|
|---|
| 102 | xDelete<char>(variable_descriptor);
|
|---|
| 103 | }
|
|---|
| 104 | xDelete<char*>(variable_descriptors);
|
|---|
| 105 | xDelete<IssmDouble>(responses);
|
|---|
| 106 |
|
|---|
| 107 | return 0;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 | int DakotaPlugin::GetCounter(){
|
|---|
| 112 | return counter;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | } // namespace SIM
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | #endif //only works if dakota library has been compiled in.
|
|---|