1 /* _______________________________________________________________________ 2 3 DAKOTA: Design Analysis Kit for Optimization and Terascale Applications 4 Copyright 2014-2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 5 This software is distributed under the GNU Lesser General Public License. 6 For more information, see the README file in the top Dakota directory. 7 _______________________________________________________________________ */ 8 9 //- Class: SerialDirectApplicInterface 10 //- Description: Derived class for the case when analysis code simulators are 11 //- linked into the code and may be invoked directly 12 //- Owner: Mike Eldred 13 //- Version: $Id: PluginSerialDirectApplicInterface.hpp 6492 2009-12-19 00:04:28Z briadam $ 14 15 #ifndef PLUGIN_SERIAL_DIRECT_APPLIC_INTERFACE_H 16 #define PLUGIN_SERIAL_DIRECT_APPLIC_INTERFACE_H 17 18 #include "DirectApplicInterface.hpp" 19 20 21 /// A sample namespace for derived classes that use assign_rep() to 22 /// plug facilities into DAKOTA. 23 24 /** A typical use of plug-ins with assign_rep() is to publish a 25 simulation interface for use in library mode See \ref DakLibrary 26 for more information. */ 27 28 namespace SIM { 29 30 /// Sample derived interface class for testing serial simulator 31 /// plug-ins using assign_rep(). 32 33 /** The plug-in SerialDirectApplicInterface resides in namespace SIM 34 and uses a copy of rosenbrock() to perform serial parameter to 35 response mappings. It is used to demonstrate plugging in a serial 36 direct analysis driver into Dakota in library mode. Test input 37 files can then use an analysis_driver of "plugin_rosenbrock". */ 38 class SerialDirectApplicInterface: public Dakota::DirectApplicInterface 39 { 40 public: 41 42 // 43 //- Heading: Constructor and destructor 44 // 45 46 /// constructor 47 SerialDirectApplicInterface(const Dakota::ProblemDescDB& problem_db); 48 /// destructor 49 ~SerialDirectApplicInterface(); 50 51 protected: 52 53 // 54 //- Heading: Virtual function redefinitions 55 // 56 57 // execute the input filter portion of a direct evaluation invocation 58 //int derived_map_if(const Dakota::String& if_name); 59 60 /// execute an analysis code portion of a direct evaluation invocation 61 int derived_map_ac(const Dakota::String& ac_name); 62 63 // execute the output filter portion of a direct evaluation invocation 64 //int derived_map_of(const Dakota::String& of_name); 65 66 /// no-op hides base error; job batching occurs within 67 /// wait_local_evaluations() 68 void derived_map_asynch(const Dakota::ParamResponsePair& pair); 69 70 /// evaluate the batch of jobs contained in prp_queue 71 void wait_local_evaluations(Dakota::PRPQueue& prp_queue); 72 /// invokes wait_local_evaluations() (no special nowait support) 73 void test_local_evaluations(Dakota::PRPQueue& prp_queue); 74 75 /// no-op hides default run-time error checks at DirectApplicInterface level 76 void set_communicators_checks(int max_eval_concurrency); 77 78 private: 79 80 // 81 //- Heading: Convenience functions 82 // 83 84 /// Rosenbrock plug-in test function 85 int rosenbrock(const Dakota::RealVector& c_vars, short asv, 86 Dakota::Real& fn_val, Dakota::RealVector& fn_grad, 87 Dakota::RealSymMatrix& fn_hess); 88 89 // 90 //- Heading: Data 91 // 92 93 }; 94 95 96 inline SerialDirectApplicInterface:: SerialDirectApplicInterface(const Dakota::ProblemDescDB & problem_db)97SerialDirectApplicInterface(const Dakota::ProblemDescDB& problem_db): 98 Dakota::DirectApplicInterface(problem_db) 99 { } 100 101 ~SerialDirectApplicInterface()102inline SerialDirectApplicInterface::~SerialDirectApplicInterface() 103 { } 104 105 106 inline void SerialDirectApplicInterface:: derived_map_asynch(const Dakota::ParamResponsePair & pair)107derived_map_asynch(const Dakota::ParamResponsePair& pair) 108 { 109 // no-op (just hides base class error throw). Jobs are run exclusively within 110 // wait_local_evaluations(), prior to there existing true batch processing 111 // facilities. 112 } 113 114 115 /** For use by ApplicationInterface::serve_evaluations_asynch(), which can 116 provide a batch processing capability within message passing schedulers 117 (called using chain IteratorScheduler::run_iterator() --> Model::serve() 118 --> ApplicationInterface::serve_evaluations() 119 --> ApplicationInterface::serve_evaluations_asynch()). */ 120 inline void SerialDirectApplicInterface:: test_local_evaluations(Dakota::PRPQueue & prp_queue)121test_local_evaluations(Dakota::PRPQueue& prp_queue) 122 { wait_local_evaluations(prp_queue); } 123 124 125 // Hide default run-time error checks at DirectApplicInterface level 126 inline void SerialDirectApplicInterface:: set_communicators_checks(int max_eval_concurrency)127set_communicators_checks(int max_eval_concurrency) 128 { } 129 130 } // namespace Dakota 131 132 #endif 133