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:       HierarchSurrBasedLocalMinimizer
10 //- Description: A local optimization algorithm that uses multiple model forms
11 //-              and discretization levels to accelerate convergence of a high-
12 //-              fidelity, finely-resolved model.
13 //- Owner:       Mike Eldred
14 //- Checked by:
15 //- Version: $Id: HierarchSurrBasedLocalMinimizer.hpp 6879 2010-07-30 01:05:11Z mseldre $
16 
17 #ifndef HIERARCH_SURR_BASED_LOCAL_MINIMIZER_H
18 #define HIERARCH_SURR_BASED_LOCAL_MINIMIZER_H
19 
20 #include "SurrBasedLocalMinimizer.hpp"
21 #include "HierarchSurrModel.hpp"
22 #include "DakotaModel.hpp"
23 #include "SurrBasedLevelData.hpp"
24 
25 namespace Dakota {
26 
27 
28 /// Class for multilevel-multifidelity optimization algorithm
29 
30 /** This minimizer uses SurrogateModel(s) to perform minimization leveraging
31     multiple model forms and discretization levels. */
32 
33 
34 /**
35  * \brief A version of TraitsBase specialized for multilevel-multifidelity minimizer
36  *
37  */
38 
39 class HierarchSurrBasedLocalTraits: public TraitsBase
40 {
41   public:
42 
43   /// default constructor
HierarchSurrBasedLocalTraits()44   HierarchSurrBasedLocalTraits() { }
45 
46   /// destructor
~HierarchSurrBasedLocalTraits()47   virtual ~HierarchSurrBasedLocalTraits() { }
48 
49   /// A temporary query used in the refactor
is_derived()50   virtual bool is_derived() { return true; }
51 
52   /// Return the flag indicating whether method supports continuous variables
supports_continuous_variables()53   bool supports_continuous_variables() { return true; }
54 
55   /// Return the flag indicating whether method supports linear equalities
supports_linear_equality()56   bool supports_linear_equality() { return true; }
57 
58   /// Return the flag indicating whether method supports linear inequalities
supports_linear_inequality()59   bool supports_linear_inequality() { return true; }
60 
61   /// Return the flag indicating whether method supports nonlinear equalities
supports_nonlinear_equality()62   bool supports_nonlinear_equality() { return true; }
63 
64   /// Return the flag indicating whether method supports nonlinear inequalities
supports_nonlinear_inequality()65   bool supports_nonlinear_inequality() { return true; }
66 };
67 
68 
69 class HierarchSurrBasedLocalMinimizer: public SurrBasedLocalMinimizer
70 {
71 public:
72 
73   //
74   //- Heading: Constructor and destructor
75   //
76 
77   /// constructor
78   HierarchSurrBasedLocalMinimizer(ProblemDescDB& problem_db, Model& model);
79   /// destructor
80   ~HierarchSurrBasedLocalMinimizer();
81 
82 protected:
83 
84   //
85   //- Heading: Virtual function redefinitions
86   //
87 
88   void pre_run();
89   void post_run(std::ostream& s);
90 
91   SurrBasedLevelData& trust_region();
92 
93   void update_trust_region();
94 
95   void build();
96   void minimize();
97   void verify();
98 
99   unsigned short converged();
100 
101 private:
102 
103   //
104   //- Heading: Convenience member functions
105   //
106 
107   /// build the hierarchical approximation for a particular level by
108   /// computing center truth within the HierarchSurrModel
109   void build_center_truth(size_t tr_index);
110 
111   /// Retrieve or evaluate SurrBasedLevelData::responseCenterTruthUncorrected
112   void find_center_truth(size_t tr_index, bool search_db = false);
113   /// Retrieve or evaluate SurrBasedLevelData::responseCenterApproxUncorrected
114   void find_center_approx(size_t tr_index);
115   /// Retrieve or evaluate SurrBasedLevelData::responseStarTruthUncorrected
116   void find_star_truth(size_t tr_index, bool search_db = false);
117   /// Retrieve or evaluate SurrBasedLevelData::responseStarApproxUncorrected
118   void find_star_approx(size_t tr_index);
119 
120   /// apply recursive corrections to SurrBasedLevelData::
121   /// responseCenterTruthUncorrected and store in SurrBasedLevelData::
122   /// responseCenterTruthCorrected
123   void correct_center_truth(size_t tr_index);
124   /// apply recursive corrections to SurrBasedLevelData::
125   /// responseStarTruthUncorrected and store in SurrBasedLevelData::
126   /// responseStarTruthCorrected
127   void correct_star_truth(size_t tr_index);
128   /// apply recursive corrections to SurrBasedLevelData::
129   /// responseCenterApproxUncorrected and store in SurrBasedLevelData::
130   /// responseCenterApproxCorrected
131   void correct_center_approx(size_t tr_index);
132   /// apply recursive corrections to SurrBasedLevelData::
133   /// responseStarApproxUncorrected and store in SurrBasedLevelData::
134   /// responseStarApproxCorrected
135   void correct_star_approx(size_t tr_index);
136 
137   /// activate model forms and, optionally, discretization levels within
138   /// the HierarchSurrModel associated with trustRegions[tr_index]
139   void set_model_states(size_t tr_index);
140 
141   /// update trust region bounds, recurring top-down from tr_index_start
142   void update_trust_region(size_t tr_index_start);
143   /// Verify approximate step with truth model for trust region level tr_index
144   void verify(size_t tr_index);
145 
146   // MG/Opt functions:
147 
148   RealVector multigrid_recursion(const RealVector &xk, int k);
149 
150   void multigrid_driver(const Variables &x0);
151 
152   RealVector optimize(const RealVector &x, int max_iter, int index);
153 
154   RealVector linesearch(const RealVector &xk, const RealVector &pk,
155                         double alpha0);
156 
157   //
158   //- Heading: Data members
159   //
160 
161   /// number of ordered model fidelities within iteratedModel
162   /// (a HierarchSurrModel)
163   size_t numFid;
164 
165   /// number of discretization levels per ordered model fidelity
166   SizetArray numLev;
167   /// flag indicating presence of more than one level per fidelity
168   bool multiLev;
169 
170   /// index for trustRegions at which the minimization is performed
171   size_t minimizeIndex;
172 
173   std::vector<SurrBasedLevelData> trustRegions;
174   bool nestedTrustRegions;
175 
176   // pointer to MLMF instance used in static member functions
177   //static HierarchSurrBasedLocalMinimizer* mlmfInstance;
178 };
179 
180 
trust_region()181 inline SurrBasedLevelData& HierarchSurrBasedLocalMinimizer::trust_region()
182 { return trustRegions[minimizeIndex]; }
183 
184 
set_model_states(size_t tr_index)185 inline void HierarchSurrBasedLocalMinimizer::set_model_states(size_t tr_index)
186 {
187   SurrBasedLevelData& tr = trustRegions[tr_index];
188   UShortArray hf_lf_key;
189   Pecos::DiscrepancyCalculator::
190     form_key(tr.data_group(), tr.truth_model_form(), tr.truth_model_level(),
191 	     tr.approx_model_form(), tr.approx_model_level(), hf_lf_key);
192   iteratedModel.active_model_key(hf_lf_key);
193 }
194 
195 
update_trust_region()196 inline void HierarchSurrBasedLocalMinimizer::update_trust_region()
197 { update_trust_region(trustRegions.size() - 1); }
198 
199 
verify()200 inline void HierarchSurrBasedLocalMinimizer::verify()
201 { verify(minimizeIndex); }
202 
203 
converged()204 inline unsigned short HierarchSurrBasedLocalMinimizer::converged()
205 {
206   size_t last_tr = trustRegions.size() - 1;
207   return trustRegions[last_tr].converged(); // TR state at truth level
208 }
209 
210 } // namespace Dakota
211 
212 #endif
213