[586] | 1 | /*!\file: DakotaPlugin.cpp (see DakotaPlugin.h for explanations)
|
---|
[805] | 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.
|
---|
[586] | 15 | */
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | #ifdef HAVE_CONFIG_H
|
---|
[9320] | 19 | #include <config.h>
|
---|
[586] | 20 | #else
|
---|
| 21 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
| 22 | #endif
|
---|
| 23 |
|
---|
[662] | 24 | /*Standard ISSM includes: */
|
---|
[12837] | 25 | #include "../../shared/shared.h"
|
---|
| 26 | #include "../../include/include.h"
|
---|
| 27 | #include "../classes.h"
|
---|
| 28 | #include "../../modules/Dakotax/Dakotax.h"
|
---|
[662] | 29 |
|
---|
| 30 | /*Standard includes: */
|
---|
[586] | 31 | #include <string>
|
---|
| 32 |
|
---|
[662] | 33 | #ifdef _HAVE_DAKOTA_ //only works if dakota library has been compiled in.
|
---|
[586] | 34 |
|
---|
[662] | 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 |
|
---|
[586] | 43 | namespace SIM {
|
---|
| 44 |
|
---|
| 45 | //constructor
|
---|
[4042] | 46 | DakotaPlugin::DakotaPlugin(const Dakota::ProblemDescDB& problem_db,void* in_femmodel):Dakota::DirectApplicInterface(problem_db){
|
---|
[586] | 47 |
|
---|
[962] | 48 |
|
---|
[4042] | 49 | femmodel=in_femmodel;
|
---|
[803] | 50 | counter=0;
|
---|
[586] | 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;
|
---|
[12354] | 59 | IssmDouble* variables=NULL;
|
---|
[586] | 60 | char** variable_descriptors=NULL;
|
---|
| 61 | char* variable_descriptor=NULL;
|
---|
[12354] | 62 | IssmDouble* responses=NULL;
|
---|
[586] | 63 |
|
---|
[803] | 64 | /*increae counter: */
|
---|
| 65 | counter++;
|
---|
| 66 |
|
---|
[586] | 67 | /*Before launching analysis, we need to transfer the dakota inputs into Issm
|
---|
| 68 | *readable variables: */
|
---|
| 69 |
|
---|
| 70 | /*First, the variables: */
|
---|
[12354] | 71 | variables=xNew<IssmDouble>(numACV);
|
---|
[586] | 72 | for(i=0;i<numACV;i++){
|
---|
| 73 | variables[i]=xC[i];
|
---|
| 74 | }
|
---|
| 75 | /*The descriptors: */
|
---|
[12457] | 76 | variable_descriptors=xNew<char*>(numACV);
|
---|
[586] | 77 | for(i=0;i<numACV;i++){
|
---|
| 78 | string label=xCLabels[i];
|
---|
[12457] | 79 | variable_descriptor=xNew<char>(strlen(label.c_str())+1);
|
---|
[9338] | 80 | memcpy(variable_descriptor,label.c_str(),(strlen(label.c_str())+1)*sizeof(char));
|
---|
[9336] | 81 |
|
---|
[586] | 82 |
|
---|
| 83 | variable_descriptors[i]=variable_descriptor;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /*Initialize responses: */
|
---|
[12446] | 87 | responses=xNewZeroInit<IssmDouble>(numFns);
|
---|
[586] | 88 |
|
---|
| 89 | /*run core solution: */
|
---|
[4491] | 90 | SpawnCore(responses,numFns, variables,variable_descriptors,numACV,femmodel,counter);
|
---|
[586] | 91 |
|
---|
| 92 | /*populate responses: */
|
---|
| 93 | for(i=0;i<numFns;i++){
|
---|
| 94 | fnVals[i]=responses[i];
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | /*Free ressources:*/
|
---|
[12354] | 99 | xDelete<IssmDouble>(variables);
|
---|
[586] | 100 | for(i=0;i<numACV;i++){
|
---|
| 101 | variable_descriptor=variable_descriptors[i];
|
---|
[12457] | 102 | xDelete<char>(variable_descriptor);
|
---|
[586] | 103 | }
|
---|
[12457] | 104 | xDelete<char*>(variable_descriptors);
|
---|
[12354] | 105 | xDelete<IssmDouble>(responses);
|
---|
[586] | 106 |
|
---|
| 107 | return 0;
|
---|
| 108 | }
|
---|
[803] | 109 |
|
---|
[586] | 110 |
|
---|
[803] | 111 | int DakotaPlugin::GetCounter(){
|
---|
| 112 | return counter;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[586] | 115 | } // namespace SIM
|
---|
[662] | 116 |
|
---|
| 117 |
|
---|
| 118 | #endif //only works if dakota library has been compiled in.
|
---|