libMesh
Loading...
Searching...
No Matches
rb_eim_construction.h
Go to the documentation of this file.
1// rbOOmit: An implementation of the Certified Reduced Basis method.
2// Copyright (C) 2009, 2010 David J. Knezevic
3
4// This file is part of rbOOmit.
5
6// rbOOmit is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 2.1 of the License, or (at your option) any later version.
10
11// rbOOmit is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15
16// You should have received a copy of the GNU Lesser General Public
17// License along with this library; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20#ifndef LIBMESH_RB_EIM_CONSTRUCTION_H
21#define LIBMESH_RB_EIM_CONSTRUCTION_H
22
23// rbOOmit includes
24#include "libmesh/rb_construction.h"
25#include "libmesh/rb_assembly_expansion.h"
26#include "libmesh/rb_eim_assembly.h"
27#include "libmesh/rb_eim_evaluation.h"
28
29// libMesh includes
30#include "libmesh/mesh_function.h"
31#include "libmesh/coupling_matrix.h"
32
33// C++ includes
34#include <unordered_map>
35#include <map>
36#include <string>
37#include <memory>
38#include <vector>
39
40namespace libMesh
41{
42
49{
52 unsigned int side_index;
53 unsigned int comp_index;
54 unsigned int qp_index;
55};
56
68{
69public:
70
72
78 const std::string & name,
79 const unsigned int number);
80
91
96
101
106
110 virtual void clear() override;
111
115 void set_rb_eim_evaluation(RBEIMEvaluation & rb_eim_eval_in);
116
121
126
132
137 virtual void process_parameters_file (const std::string & parameters_filename);
138
143 void set_rb_construction_parameters(unsigned int n_training_samples_in,
144 bool deterministic_training_in,
145 int training_parameters_random_seed_in,
146 bool quiet_mode_in,
147 unsigned int Nmax_in,
148 Real rel_training_tolerance_in,
149 Real abs_training_tolerance_in,
150 const RBParameters & mu_min_in,
151 const RBParameters & mu_max_in,
152 const std::map<std::string, std::vector<Real>> & discrete_parameter_values_in,
153 const std::map<std::string,bool> & log_scaling,
154 std::map<std::string, std::vector<RBParameter>> * training_sample_list=nullptr);
155
160 virtual void set_best_fit_type_flag (const std::string & best_fit_type_string);
161
165 virtual void print_info();
166
173
179
187
195
202 virtual void initialize_eim_assembly_objects();
203
207 std::vector<std::unique_ptr<ElemAssembly>> & get_eim_assembly_objects();
208
215 virtual std::unique_ptr<ElemAssembly> build_eim_assembly(unsigned int bf_index) = 0;
216
220 virtual void init_context(FEMContext &);
221
225 void set_rel_training_tolerance(Real new_training_tolerance);
227
231 void set_abs_training_tolerance(Real new_training_tolerance);
233
238 unsigned int get_Nmax() const;
239 virtual void set_Nmax(unsigned int Nmax);
240
248 void enable_set_Nmax_from_n_snapshots(int increment);
249
255
261
271
276 const QpDataMap & get_parametrized_function_from_training_set(unsigned int training_index) const;
277 const SideQpDataMap & get_side_parametrized_function_from_training_set(unsigned int training_index) const;
278 const NodeDataMap & get_node_parametrized_function_from_training_set(unsigned int training_index) const;
279
283 const std::unordered_map<dof_id_type, std::vector<Real> > & get_local_quad_point_JxW();
284 const std::map<std::pair<dof_id_type,unsigned int>, std::vector<Real> > & get_local_side_quad_point_JxW();
285
290
295
303
304protected:
305
322 bool add_basis_function,
323 EimPointData * eim_point_data);
324
329 bool add_basis_function,
330 EimPointData * eim_point_data);
331
335 bool enrich_eim_approximation_on_interiors(const QpDataMap & interior_pf,
336 bool add_basis_function,
337 EimPointData * eim_point_data);
338
345 void update_eim_matrices(bool set_eim_error_indicator);
346
347private:
348
354 std::pair<Real, unsigned int> compute_max_eim_error();
355
361
366 void initialize_qp_data();
367
377 Number inner_product(const QpDataMap & v, const QpDataMap & w, bool apply_comp_scaling);
378
382 Number side_inner_product(const SideQpDataMap & v, const SideQpDataMap & w, bool apply_comp_scaling);
383
387 Number node_inner_product(const NodeDataMap & v, const NodeDataMap & w, bool apply_comp_scaling);
388
393 template <class DataMap>
394 Real get_max_abs_value(const DataMap & v) const
395 {
396 Real max_value = 0.;
397
398 for (const auto & pr : v)
399 {
400 const auto & v_comp_and_qp = pr.second;
401
402 for (const auto & comp : index_range(v_comp_and_qp))
403 {
404 Real comp_scaling = 1.;
406 {
407 // Make sure that _component_scaling_in_training_set is initialized
408 libmesh_error_msg_if(comp >= _component_scaling_in_training_set.size(),
409 "Invalid vector index");
410 comp_scaling = _component_scaling_in_training_set[comp];
411 }
412
413 const std::vector<Number> & v_qp = v_comp_and_qp[comp];
414 for (Number value : v_qp)
415 max_value = std::max(max_value, std::abs(value * comp_scaling));
416 }
417 }
418
419 comm().max(max_value);
420 return max_value;
421 }
422
427 Real get_node_max_abs_value(const NodeDataMap & v) const;
428
432 void enrich_eim_approximation(unsigned int training_index,
433 bool add_basis_function,
434 EimPointData * eim_point_data);
435
439 template<class DataMap>
440 static void scale_parametrized_function(DataMap & local_pf,
441 Number scaling_factor)
442 {
443 for (auto & pr : local_pf)
444 {
445 auto & comp_and_qp = pr.second;
446
447 for (unsigned int comp : index_range(comp_and_qp))
448 {
449 std::vector<Number> & qp_values = comp_and_qp[comp];
450
451 for (unsigned int qp : index_range(qp_values))
452 {
453 qp_values[qp] *= scaling_factor;
454 }
455 }
456 }
457 }
458
464 static void scale_node_parametrized_function(NodeDataMap & local_pf,
465 Number scaling_factor);
466
470 static unsigned int get_random_int_0_to_n(unsigned int n);
471
478
484
488 unsigned int _Nmax;
489
501
507
513
518
523 std::vector<std::unique_ptr<ElemAssembly>> _rb_eim_assembly_objects;
524
537
544
551
557
562
571
583 std::unordered_map<dof_id_type, std::vector<Point> > _local_quad_point_locations;
584 std::unordered_map<dof_id_type, std::vector<Real> > _local_quad_point_JxW;
585 std::unordered_map<dof_id_type, subdomain_id_type > _local_quad_point_subdomain_ids;
586
594 std::unordered_map<dof_id_type, std::vector<std::vector<Point>> > _local_quad_point_locations_perturbations;
595
599 std::map<std::pair<dof_id_type,unsigned int>, std::vector<Point> > _local_side_quad_point_locations;
600 std::map<std::pair<dof_id_type,unsigned int>, std::vector<Real> > _local_side_quad_point_JxW;
601 std::map<std::pair<dof_id_type,unsigned int>, subdomain_id_type > _local_side_quad_point_subdomain_ids;
602 std::map<std::pair<dof_id_type,unsigned int>, boundary_id_type > _local_side_quad_point_boundary_ids;
603 std::map<std::pair<dof_id_type,unsigned int>, std::vector<std::vector<Point>> > _local_side_quad_point_locations_perturbations;
604
608 std::unordered_map<dof_id_type, Point > _local_node_locations;
609 std::unordered_map<dof_id_type, boundary_id_type > _local_node_boundary_ids;
610
618 std::map<std::pair<dof_id_type,unsigned int>, unsigned int > _local_side_quad_point_side_types;
619
620};
621
622} // namespace libMesh
623
624#endif // LIBMESH_RB_EIM_CONSTRUCTION_H
void max(const T &r, T &o, Request &req) const
Defines a dense matrix for use in Finite Element-type computations.
This is the EquationSystems class.
This class provides all data required for a physics package (e.g.
Definition fem_context.h:63
const Parallel::Communicator & comm() const
This class is part of the rbOOmit framework.
This class is part of the rbOOmit framework.
void store_eim_solutions_for_training_set()
Get the EIM solution vector at all parametrized functions in the training set.
void initialize_eim_construction()
Perform initialization of this object to prepare for running train_eim_approximation().
std::vector< std::unique_ptr< ElemAssembly > > & get_eim_assembly_objects()
virtual void initialize_eim_assembly_objects()
Build a vector of ElemAssembly objects that accesses the basis functions stored in this RBEIMConstruc...
unsigned int get_n_parametrized_functions_for_training() const
Get the number of parametrized functions used for training.
void update_eim_matrices(bool set_eim_error_indicator)
Update the matrices used in training the EIM approximation.
std::vector< QpDataMap > _local_parametrized_functions_for_training
The parametrized functions that are used for training.
RBEIMEvaluation * _rb_eim_eval
The RBEIMEvaluation object that we use to perform the EIM training.
Number node_inner_product(const NodeDataMap &v, const NodeDataMap &w, bool apply_comp_scaling)
Same as inner_product() except for node data.
Real _rel_training_tolerance
Relative and absolute tolerances for training the EIM approximation.
void set_rb_eim_evaluation(RBEIMEvaluation &rb_eim_eval_in)
Set the RBEIMEvaluation object.
bool enrich_eim_approximation_on_sides(const SideQpDataMap &side_pf, bool add_basis_function, EimPointData *eim_point_data)
Implementation of enrich_eim_approximation() for the case of element sides.
static void scale_parametrized_function(DataMap &local_pf, Number scaling_factor)
Scale all values in pf by scaling_factor.
EimPointData get_random_point(const QpDataMap &v)
Helper function that identifies a random EIM point from v.
virtual void init_context(FEMContext &)
Pre-request FE data needed for calculations.
void set_rb_construction_parameters(unsigned int n_training_samples_in, bool deterministic_training_in, int training_parameters_random_seed_in, bool quiet_mode_in, unsigned int Nmax_in, Real rel_training_tolerance_in, Real abs_training_tolerance_in, const RBParameters &mu_min_in, const RBParameters &mu_max_in, const std::map< std::string, std::vector< Real > > &discrete_parameter_values_in, const std::map< std::string, bool > &log_scaling, std::map< std::string, std::vector< RBParameter > > *training_sample_list=nullptr)
Set the state of this RBConstruction object based on the arguments to this function.
RBEIMEvaluation::NodeDataMap NodeDataMap
Type of the data structure used to map from node id -> [n_vars] data.
void enable_set_Nmax_from_n_snapshots(int increment)
Call this method to set _set_Nmax_from_n_snapshots=true and _Nmax_from_n_snapshots_increment=incremen...
void initialize_qp_data()
Initialize the data associated with each quad point (location, JxW, etc.) so that we can use this in ...
RBEIMConstruction(RBEIMConstruction &&)=default
Special functions.
void set_rel_training_tolerance(Real new_training_tolerance)
Get/set the relative tolerance for the basis training.
void set_abs_training_tolerance(Real new_training_tolerance)
Get/set the absolute tolerance for the basis training.
const NodeDataMap & get_node_parametrized_function_from_training_set(unsigned int training_index) const
unsigned int _max_abs_value_in_training_set_index
The training sample index at which we found _max_abs_value_in_training_set.
Number inner_product(const QpDataMap &v, const QpDataMap &w, bool apply_comp_scaling)
Evaluate the inner product of vec1 and vec2 which specify values at quadrature points.
static void scale_node_parametrized_function(NodeDataMap &local_pf, Number scaling_factor)
Scale all values in pf by scaling_factor The templated function above handles the elem and side cases...
std::vector< SideQpDataMap > _local_side_parametrized_functions_for_training
Same as _local_parametrized_functions_for_training except for side data.
virtual void set_Nmax(unsigned int Nmax)
std::unordered_map< dof_id_type, boundary_id_type > _local_node_boundary_ids
std::unordered_map< dof_id_type, std::vector< Point > > _local_quad_point_locations
The quadrature point locations, quadrature point weights (JxW), and subdomain IDs on every element lo...
static unsigned int get_random_int_0_to_n(unsigned int n)
Static helper function that is used by get_random_point().
BEST_FIT_TYPE best_fit_type_flag
Enum that indicates which type of "best fit" algorithm we should use.
EimPointData get_random_point_from_training_sample()
Get a random point using the 0^th training sample as input to get_random_point().
virtual Real train_eim_approximation_with_greedy()
Generate the EIM approximation for the specified parametrized function using the Greedy Algorithm.
std::unordered_map< dof_id_type, Point > _local_node_locations
Same as above except for node data.
std::pair< Real, unsigned int > compute_max_eim_error()
Find the training sample that has the largest EIM approximation error based on the current EIM approx...
std::unordered_map< dof_id_type, subdomain_id_type > _local_quad_point_subdomain_ids
void reinit_eim_projection_matrix()
Zero the _eim_projection_matrix and resize it to be get_Nmax() x get_Nmax().
unsigned int _Nmax
Maximum number of EIM basis functions we are willing to use.
const std::unordered_map< dof_id_type, std::vector< Real > > & get_local_quad_point_JxW()
Get the interior and side quadrature weights.
void apply_normalization_to_solution_snapshots()
Rescale solution snapshots so that they all have unity norm.
bool enrich_eim_approximation_on_nodes(const NodeDataMap &node_pf, bool add_basis_function, EimPointData *eim_point_data)
Implementation of enrich_eim_approximation() for the case of element nodes.
RBEIMConstruction(const RBEIMConstruction &)=delete
RBEIMConstruction & operator=(const RBEIMConstruction &)=delete
Number side_inner_product(const SideQpDataMap &v, const SideQpDataMap &w, bool apply_comp_scaling)
Same as inner_product() except for side data.
Real get_max_abs_value_in_training_set() const
Get the maximum value (across all processors) from the parametrized functions in the training set.
Real _max_abs_value_in_training_set
Maximum value in _local_parametrized_functions_for_training across all processors.
std::vector< Real > _component_scaling_in_training_set
Keep track of a scaling factor for each component of the parametrized functions in the training set w...
std::map< std::pair< dof_id_type, unsigned int >, std::vector< std::vector< Point > > > _local_side_quad_point_locations_perturbations
DenseMatrix< Number > _eim_projection_matrix
The matrix we use in order to perform L2 projections of parametrized functions as part of EIM trainin...
bool enrich_eim_approximation_on_interiors(const QpDataMap &interior_pf, bool add_basis_function, EimPointData *eim_point_data)
Implementation of enrich_eim_approximation() for the case of element interiors.
std::vector< NodeDataMap > _local_node_parametrized_functions_for_training
Same as _local_parametrized_functions_for_training except for node data.
std::vector< std::unique_ptr< ElemAssembly > > _rb_eim_assembly_objects
The vector of assembly objects that are created to point to this RBEIMConstruction.
std::unordered_map< dof_id_type, std::vector< std::vector< Point > > > _local_quad_point_locations_perturbations
EIM approximations often arise when applying a geometric mapping to a Reduced Basis formulation.
void disable_set_Nmax_from_n_snapshots()
Call this method to set _set_Nmax_from_n_snapshots=false and reset _Nmax_from_n_snapshots_increment t...
bool _set_Nmax_from_n_snapshots
If _set_Nmax_from_n_snapshots=true, then we overrule Nmax to be Nmax += _Nmax_from_n_snapshots_increm...
virtual Real train_eim_approximation()
Generate the EIM approximation for the specified parametrized function using either POD or the Greedy...
unsigned int get_Nmax() const
Get/set Nmax, the maximum number of RB functions we are willing to compute.
virtual Real train_eim_approximation_with_POD()
Generate the EIM approximation for the specified parametrized function using Proper Orthogonal Decomp...
std::unordered_map< dof_id_type, std::vector< Real > > _local_quad_point_JxW
Real get_node_max_abs_value(const NodeDataMap &v) const
Get the maximum absolute value from a vector stored in the format that we use for basis functions.
std::map< std::pair< dof_id_type, unsigned int >, std::vector< Point > > _local_side_quad_point_locations
Same as above except for side data.
RBEIMEvaluation::QpDataMap QpDataMap
Type of the data structure used to map from (elem id) -> [n_vars][n_qp] data.
std::map< std::pair< dof_id_type, unsigned int >, boundary_id_type > _local_side_quad_point_boundary_ids
RBEIMEvaluation & get_rb_eim_evaluation()
Get a reference to the RBEvaluation object.
Real get_max_abs_value(const DataMap &v) const
Get the maximum absolute value from a vector stored in the format that we use for basis functions.
virtual void print_info()
Print out info that describes the current setup of this RBConstruction.
virtual void clear() override
Clear this object.
void enrich_eim_approximation(unsigned int training_index, bool add_basis_function, EimPointData *eim_point_data)
Add a new basis function to the EIM approximation.
std::map< std::pair< dof_id_type, unsigned int >, unsigned int > _local_side_quad_point_side_types
For side data, we also store "side type" info.
void initialize_parametrized_functions_in_training_set()
Compute and store the parametrized function for each parameter in the training set at all the stored ...
const std::map< std::pair< dof_id_type, unsigned int >, std::vector< Real > > & get_local_side_quad_point_JxW()
std::map< std::pair< dof_id_type, unsigned int >, subdomain_id_type > _local_side_quad_point_subdomain_ids
const SideQpDataMap & get_side_parametrized_function_from_training_set(unsigned int training_index) const
RBEIMEvaluation::SideQpDataMap SideQpDataMap
Type of the data structure used to map from (elem id,side_index) -> [n_vars][n_qp] data.
std::map< std::pair< dof_id_type, unsigned int >, std::vector< Real > > _local_side_quad_point_JxW
const QpDataMap & get_parametrized_function_from_training_set(unsigned int training_index) const
Get a const reference to the specified parametrized function from the training set.
virtual void process_parameters_file(const std::string &parameters_filename)
Read parameters in from file and set up this system accordingly.
virtual std::unique_ptr< ElemAssembly > build_eim_assembly(unsigned int bf_index)=0
Build an element assembly object that will access basis function bf_index.
virtual void set_best_fit_type_flag(const std::string &best_fit_type_string)
Specify which type of "best fit" we use to guide the EIM greedy algorithm.
This class enables evaluation of an Empirical Interpolation Method (EIM) approximation.
const std::set< unsigned int > & scale_components_in_enrichment() const
Get _scale_components_in_enrichment.
std::map< std::pair< dof_id_type, unsigned int >, std::vector< std::vector< Number > > > SideQpDataMap
Type of the data structure used to map from (elem id, side index) -> [n_vars][n_qp] data.
std::map< dof_id_type, std::vector< std::vector< Number > > > QpDataMap
Type of the data structure used to map from (elem id) -> [n_vars][n_qp] data.
std::map< dof_id_type, std::vector< Number > > NodeDataMap
Type of the data structure used to map from (node id) -> [n_vars] data.
This class is part of the rbOOmit framework.
const std::string & name() const
Definition system.h:2385
unsigned int number() const
Definition system.h:2393
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
int8_t boundary_id_type
Definition id_types.h:51
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This struct is used to encapsulate the arguments required to specify an EIM point that we may add to ...
static const bool value
Definition xdr_io.C:55