OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dakota_application.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 //
3 // C++ Implementation: dakota_application
4 //
5 // Description: Used to read in an array of experimental data with column headers.
6 // For use with parameter estimation or generating polarization curves.
7 //
8 // Author: Malte Krack, Peter Dobson <pdobson@ualberta.ca>, Marc Secanell <secanell@ualberta.ca>, (C) 2009,2010
9 //
10 // Copyright: See COPYING file that comes with this distribution
11 //
12 // Created by: Malte Krack, Peter Dobson (August 2009)
13 // Last updated: January, 2010
14 //
15 //---------------------------------------------------------------------------
16 #ifndef dakota_application_h
17 #define dakota_application_h
18 
19 //deal.II:
20 #include <base/parameter_handler.h>
21 
22 //appframe:
23 #include <appframe/base.h>
24 
26 #include "experimental_data.h"
27 #include "simulation_selector.h"
28 
29 //STL libraries:
30 #include<string>
31 #include<fstream>
32 #include<iostream>
33 #include<vector>
34 
35 #ifdef _WITH_DAKOTA
36 
37 //Dakota:
38 #include <ParallelLibrary.H>
39 #include <ProblemDescDB.H>
40 #include <DakotaStrategy.H>
41 #include <DakotaModel.H>
42 #include <DirectApplicInterface.H>
43 
44 
45 namespace SIM
46 {
47 
94 class DakotaApplication
95 {
96 public:
101  DakotaApplication(boost::shared_ptr<Dakota::ProblemDescDB> global_problem_db,
102  std::string parameter_file);
103 
109  void manage_inputs(ParameterHandler& param);
110 
117  void assign_interface(Dakota::DirectApplicInterface* optimization_interface);
118 
125  void run();
126 
147  inline bool use_NLS()
148  {
149  return NLS_flag;
150  }
151 
155  Dakota::RealVector vars_results();
156 
160  Dakota::RealVector resp_results();
161 
165  void declare_parameters(ParameterHandler& param);
166 
171  void synchronize_variables(unsigned int &n_dvar, unsigned int &n_resp,
172  std::vector<std::string> &name_design_var, std::vector<std::string> &name_responses);
173 
174 private:
178  void initialize(ParameterHandler& param);
182  void write_hybrid_dakota_input_file();
186  void write_pareto_dakota_input_file();
190  void write_multi_start_dakota_input_file();
194  void write_single_method_dakota_input_file();
198  void write_method(std::stringstream& inputss, std::string& method_id, std::string method_name, std::string model_ptr);
202  void write_responses(std::stringstream& inputss, int id, std::string method_name);
206  void write_variables(std::stringstream& inputss, int id);
244  void set_all_dvar_names();
245 
250  void check_dvar_names() const;
255  DeclException2(DesignVariableNotFoundInFCSTDesignVariables,
256  std::string,
257  std::string,
258  << "A " << arg1 << " with name \"" << arg2 << "\" is not stored in available FCST design variables. Please define the variable in DakotaApplication class and in set_parameters in the appropriate class");
259 
263  bool a_gradients;
271  bool n_gradients;
288  std::string n_gradient_type;
292  bool hessians;
293 
341  unsigned int n_dvar;
345  unsigned int n_obj;
349  unsigned int n_nl_con;
353  unsigned int n_eq_con;
357  unsigned int n_con;
361  unsigned int n_resp;
365  std::vector<std::string> name_design_var;
369  std::vector<std::string> all_name_design_var;
374  std::vector<std::string> name_responses;
375 
379  std::string input_file;
383  boost::shared_ptr<Dakota::ProblemDescDB> problem_db;
384 
385  //DAKOTA variables
389  std::string dakota_version;
390 
398  bool use_dakota_input_file;
402  std::string dakota_input;
410  std::string optimization_strategy;
418  std::string optimization_method;
422  bool NLS_flag;
428  bool scaling;
432  std::string NLS_data_file;
436  int max_iter;
440  int max_f_eval;
444  double convergence_tol;
448  double constraint_tol;
452  int rand_pareto_weights;
456  int rand_start_points;
460  std::string hybrid_strategy;
464  int n_hybrid_methods;
468  std::vector<std::string> hybrid_opt_method;
472  std::vector<std::string> method_list;
476  std::vector<std::string> model_ptr;
480  std::vector<double> tol;
484  std::vector<double> eval_max;
488  std::vector<double> iter_max;
489 
490 
496  std::vector<int> part_design_var;
500  double step_to_boundary;
504  double grad_tol;
508  std::string merit_function;
512  double trust_rad;
516  double abs_conv_tol;
520  double x_conv_tol;
524  double false_conv_tol;
528  int m_data_points;
529 
533  double solution_target;
537  double final_solutions;
541  double min_boxsize_limit;
545  double volume_boxsize_limit;
546 
547 
551  Dakota::StringArray dakota_name_design_var;
555  Dakota::RealVector ip_design_var;
559  Dakota::RealVector lb_design_var;
563  Dakota::RealVector ub_design_var;
567  Dakota::RealVector scale_design_var;
571  Dakota::StringArray scale_types;
575  Dakota::RealVector step_design_var;
579  Dakota::RealVector lb_nl_constraint;
583  Dakota::RealVector ub_nl_constraint;
587  Dakota::RealVector eq_constraint;
597  Dakota::Strategy selected_strategy;
598 
602  double centering_param;
603 
627  double initial_delta;
628  double threshold_delta;
629  double contraction_factor;
630 //
631 // /**
632 // * Optimization - OPT++ Search method .
633 // */
634 // std::string search_method;
635 // bool changing_search_method;
636 
637 
638 
639 
671 
675 
679 
684 
689 
693 
698