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:       NonDC3FunctionTrain
10 //- Description: Iterator for the
11 //- Owner:       Alex Gorodetsky, Sandia National Laboratories
12 
13 #ifndef NOND_C3_FUNCTION_TRAIN_H
14 #define NOND_C3_FUNCTION_TRAIN_H
15 
16 // #include "DakotaNonD.hpp
17 
18 #include "NonDExpansion.hpp"
19 
20 namespace Dakota {
21 
22 /// Nonintrusive uncertainty quantification with the C3 library ...
23 
24 /** The NonDC3FunctionTrain class uses ... */
25 
26 class NonDC3FunctionTrain: public NonDExpansion
27 {
28 public:
29 
30   //
31   //- Heading: Constructors and destructor
32   //
33 
34   /// standard constructor
35   NonDC3FunctionTrain(ProblemDescDB& problem_db, Model& model);
36   /// destructor
37   ~NonDC3FunctionTrain();
38 
39 protected:
40 
41   //
42   //- Heading: Constructors
43   //
44 
45   /// base constructor for DB construction of multilevel/multifidelity PCE
46   /// (method_name is not necessary, rather it is just a convenient overload
47   /// allowing the derived ML FT class to bypass the standard FT ctor)
48   NonDC3FunctionTrain(unsigned short method_name, ProblemDescDB& problem_db,
49 		      Model& model);
50 
51   //
52   //- Heading: Virtual function redefinitions
53   //
54 
55   void resolve_inputs(short& u_space_type, short& data_order);
56   void initialize_u_space_model();
57 
58   size_t collocation_points() const;
59 
60   // TODO
61   //void compute_expansion();
62   // perform a forward uncertainty propagation using PCE/SC methods
63   //void core_run();
64 
65   void push_increment();
66   void update_samples_from_order_increment();
67   //void update_samples_from_order_decrement();
68   void sample_allocation_metric(Real& regress_metric, Real power);
69 
70   /// override certain print functions
71   void print_moments(std::ostream& s);
72   void print_sobol_indices(std::ostream& s);
73 
74   //
75   //- Heading: Member function definitions
76   //
77 
78   /// check model definition (redirect function_train model to surr-based UQ)
79   void check_surrogate();
80   /// assign c3AdvancementType based on user inputs for adapt_{rank,order}
81   /// (fine-grained augmentation to refine{Type,Control} = uniform p-refinement)
82   void resolve_refinement();
83 
84   /// configure u_space_sampler and approx_type based on regression
85   /// specification
86   bool config_regression(size_t colloc_pts, size_t regress_size, int seed,
87 			 Iterator& u_space_sampler, Model& g_u_model);
88 
89   /// Publish options from C3 input specification (not needed if model-driven
90   /// specification: already extracted by iteratedModel)
91   void initialize_c3_db_options();
92   /// Publish configuration data for initial function train cores, prior to
93   /// any adaptation
94   void initialize_c3_start_rank(size_t start_rank);
95   /// Publish configuration data for initial function train cores, prior to
96   /// any adaptation
97   void initialize_c3_start_orders(const UShortArray& start_orders);
98 
99   /// Publish configuration data for initial function train cores, prior to
100   /// any adaptation
101   void push_c3_start_rank(size_t start_rank);
102   /// Publish configuration data for initial function train cores, prior to
103   /// any adaptation
104   void push_c3_max_rank(size_t max_rank);
105   /// Publish configuration data for initial function train cores, prior to
106   /// any adaptation
107   void push_c3_start_orders(const UShortArray& start_orders);
108   /// Publish configuration data for initial function train cores, prior to
109   /// any adaptation
110   void push_c3_max_order(unsigned short max_order);
111   /// Publish random seed for internal C3 use
112   void push_c3_seed(int seed);
113 
114   //
115   //- Heading: Data
116   //
117 
118   /// user-specified file for importing build points
119   String importBuildPointsFile;
120 
121   /// scalar specification for initial rank (prior to adapt_rank)
122   size_t startRankSpec;
123   /// scalar specification for maximum rank (bounds adapt_rank)
124   size_t maxRankSpec;
125   /// scalar specification for initial basis order (prior to uniform refinement)
126   unsigned short startOrderSpec;
127   /// scalar specification for maximum basis order (bounds uniform refinement)
128   unsigned short maxOrderSpec;
129 
130   /// type of advancement used by (uniform) refinement: START_{RANK,ORDER} or
131   /// MAX_{RANK,ORDER,RANK_ORDER}
132   short c3AdvancementType;
133 
134 private:
135 
136   //
137   //- Heading: Member function definitions
138   //
139 
140   /// return the regression size used for different refinement options
141   size_t regression_size();
142 
143   //static int qoi_eval(size_t num_samp,        // number of evaluations
144   // 			const double* var_sets, // num_vars x num_evals
145   // 			double* qoi_sets,       // num_fns x num_evals
146   // 			void* args);            // optional arguments
147 
148   //
149   //- Heading: Data
150   //
151 
152   /// user specification for collocation_points
153   size_t collocPtsSpec;
154 
155   // for decremented order without recomputation from previous ranks
156   //int prevSamplesOnModel;
157 
158   // pointer to the active object instance used within the static evaluator
159   // functions in order to avoid the need for static data
160   //static NonDC3FunctionTrain* c3Instance;
161 };
162 
163 
collocation_points() const164 inline size_t NonDC3FunctionTrain::collocation_points() const
165 { return collocPtsSpec; }
166 
167 } // namespace Dakota
168 
169 #endif
170