libMesh
rb_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_CONSTRUCTION_H
21 #define LIBMESH_RB_CONSTRUCTION_H
22 
23 // rbOOmit includes
24 #include "libmesh/rb_construction_base.h"
25 
26 // libMesh includes
27 #include "libmesh/linear_implicit_system.h"
28 #include "libmesh/dense_vector.h"
29 #include "libmesh/dense_matrix.h"
30 #include "libmesh/dg_fem_context.h"
31 #include "libmesh/dirichlet_boundaries.h"
32 
33 // C++ includes
34 
35 namespace libMesh
36 {
37 
38 class RBThetaExpansion;
39 class RBAssemblyExpansion;
40 class RBEvaluation;
41 class ElemAssembly;
42 
53 class RBConstruction : public RBConstructionBase<LinearImplicitSystem>
54 {
55 public:
56 
62  const std::string & name,
63  const unsigned int number);
64 
68  virtual ~RBConstruction ();
69 
74 
79  virtual void solve_for_matrix_and_rhs (LinearSolver<Number> & input_solver,
80  SparseMatrix<Number> & input_matrix,
81  NumericVector<Number> & input_rhs);
82 
86  void set_rb_evaluation(RBEvaluation & rb_eval_in);
87 
92 
96  bool is_rb_eval_initialized() const;
97 
103 
107  void set_rb_assembly_expansion(RBAssemblyExpansion & rb_assembly_expansion_in);
108 
113 
117  sys_type & system () { return *this; }
118 
123 
128  virtual void clear () libmesh_override;
129 
133  virtual std::string system_type () const libmesh_override;
134 
141  virtual Real truth_solve(int plot_solution);
142 
159  virtual Real train_reduced_basis(const bool resize_rb_eval_data=true);
160 
166  virtual Real compute_max_error_bound();
167 
172  const RBParameters & get_greedy_parameter(unsigned int i);
173 
177  void set_rel_training_tolerance(Real new_training_tolerance)
178  {this->rel_training_tolerance = new_training_tolerance; }
180 
184  void set_abs_training_tolerance(Real new_training_tolerance)
185  {this->abs_training_tolerance = new_training_tolerance; }
187 
192  {this->normalize_rb_bound_in_greedy = normalize_rb_bound_in_greedy; }
194 
199  unsigned int get_Nmax() const { return Nmax; }
200  virtual void set_Nmax(unsigned int Nmax);
201 
207  void set_quiet_mode(bool quiet_mode_in)
208  { this->quiet_mode = quiet_mode_in; }
209 
213  bool is_quiet() const
214  { return this->quiet_mode; }
215 
220  virtual void load_basis_function(unsigned int i);
221 
226  virtual void load_rb_solution();
227 
235 
239  SparseMatrix<Number> * get_Aq(unsigned int q);
240 
244  SparseMatrix<Number> * get_non_dirichlet_Aq(unsigned int q);
245 
255  virtual void initialize_rb_construction(bool skip_matrix_assembly=false,
256  bool skip_vector_assembly=false);
257 
261  NumericVector<Number> * get_Fq(unsigned int q);
262 
267 
271  NumericVector<Number> * get_output_vector(unsigned int n, unsigned int q_l);
272 
276  NumericVector<Number> * get_non_dirichlet_output_vector(unsigned int n, unsigned int q_l);
277 
281  virtual void get_all_matrices(std::map<std::string, SparseMatrix<Number> *> & all_matrices);
282 
286  virtual void get_all_vectors(std::map<std::string, NumericVector<Number> *> & all_vectors);
287 
291  virtual void get_output_vectors(std::map<std::string, NumericVector<Number> *> & all_vectors);
292 
298  virtual void assemble_affine_expansion(bool skip_matrix_assembly,
299  bool skip_vector_assembly);
300 
304  void assemble_inner_product_matrix(SparseMatrix<Number> * input_matrix, bool apply_dof_constraints=true);
305 
309  void assemble_Aq_matrix(unsigned int q, SparseMatrix<Number> * input_matrix, bool apply_dof_constraints=true);
310 
314  void assemble_Fq_vector(unsigned int q, NumericVector<Number> * input_vector, bool apply_dof_constraints=true);
315 
320  void add_scaled_Aq(Number scalar, unsigned int q_a,
321  SparseMatrix<Number> * input_matrix,
322  bool symmetrize);
323 
329  virtual void write_riesz_representors_to_files(const std::string & riesz_representors_dir,
330  const bool write_binary_residual_representors);
331 
338  virtual void read_riesz_representors_from_files(const std::string & riesz_representors_dir,
339  const bool write_binary_residual_representors);
340 
341 
349  virtual void recompute_all_residual_terms(const bool compute_inner_products=true);
350 
355  virtual void process_parameters_file(const std::string & parameters_filename);
356 
361  void set_rb_construction_parameters(unsigned int n_training_samples_in,
362  bool deterministic_training_in,
363  unsigned int training_parameters_random_seed_in,
364  bool quiet_mode_in,
365  unsigned int Nmax_in,
366  Real rel_training_tolerance_in,
367  Real abs_training_tolerance_in,
368  bool normalize_rb_error_bound_in_greedy_in,
369  RBParameters mu_min_in,
370  RBParameters mu_max_in,
371  std::map<std::string, std::vector<Real>> discrete_parameter_values_in,
372  std::map<std::string,bool> log_scaling);
373 
377  virtual void print_info();
378 
385 
393  unsigned int get_delta_N() const { return delta_N; }
394 
398  void set_inner_product_assembly(ElemAssembly & inner_product_assembly_in);
399 
404 
410 
416 
421  void set_convergence_assertion_flag(bool flag);
422 
423  //----------- PUBLIC DATA MEMBERS -----------//
424 
432  std::vector<Real> training_error_bounds;
433 
440 
448 
453 
458  std::vector<Number > truth_outputs;
459 
464  std::vector<std::vector<Number >> output_dual_innerprods;
465 
472  std::vector<NumericVector<Number> * > Fq_representor;
473 
481  std::vector<Number> Fq_representor_innerprods;
482 
490 
497 
505 
512 
519 
526 
527 protected:
528 
533  virtual void allocate_data_structures();
534 
539  virtual void truth_assembly();
540 
547 
554 
559  virtual bool greedy_termination_test(Real abs_greedy_error,
560  Real initial_greedy_error,
561  int count);
562 
568 
577  ElemAssembly * elem_assembly,
578  SparseMatrix<Number> * input_matrix,
579  NumericVector<Number> * input_vector,
580  bool symmetrize=false,
581  bool apply_dof_constraints=true);
582 
589 
596  virtual void assemble_misc_matrices();
597 
602  virtual void assemble_all_affine_operators();
603 
607  virtual void assemble_all_affine_vectors();
608 
612  virtual void assemble_all_output_vectors();
613 
617  virtual void compute_output_dual_innerprods();
618 
631  virtual void compute_Fq_representor_innerprods(bool compute_inner_products=true);
632 
637  virtual void enrich_RB_space();
638 
643  virtual void update_system();
644 
650  virtual Real get_RB_error_bound();
651 
655  virtual void update_RB_system_matrices();
656 
664  virtual void update_residual_terms(bool compute_inner_products=true);
665 
672  virtual void init_context(FEMContext &) {}
673 
678  bool get_convergence_assertion_flag() const;
679 
684  void check_convergence(LinearSolver<Number> & input_solver);
685 
686  //----------- PROTECTED DATA MEMBERS -----------//
687 
692  unsigned int Nmax;
693 
698  unsigned int delta_N;
699 
705 
712 
718 
719 private:
720 
721  //----------- PRIVATE DATA MEMBERS -----------//
722 
729 
735 
740 
744  std::vector<SparseMatrix<Number> * > Aq_vector;
745 
750  std::vector<NumericVector<Number> * > Fq_vector;
751 
756  std::vector<std::vector<NumericVector<Number> * >> outputs_vector;
757 
763  std::vector<SparseMatrix<Number> * > non_dirichlet_Aq_vector;
764  std::vector<NumericVector<Number> * > non_dirichlet_Fq_vector;
765  std::vector<std::vector<NumericVector<Number> * >> non_dirichlet_outputs_vector;
766 
773 
779 
780 };
781 
782 } // namespace libMesh
783 
784 #endif // LIBMESH_RB_CONSTRUCTION_H
virtual void read_riesz_representors_from_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors)
Read in all the Riesz representor data from files.
bool normalize_rb_bound_in_greedy
This boolean indicates if we normalize the RB error in the greedy using RBEvaluation::get_error_bound...
virtual void initialize_rb_construction(bool skip_matrix_assembly=false, bool skip_vector_assembly=false)
Allocate all the data structures necessary for the construction stage of the RB method.
std::vector< SparseMatrix< Number > * > non_dirichlet_Aq_vector
We may also need a second set of matrices/vectors that do not have the Dirichlet boundary conditions ...
This is the EquationSystems class.
std::vector< Real > training_error_bounds
Vector storing the values of the error bound for each parameter in the training set — the parameter ...
virtual void get_all_vectors(std::map< std::string, NumericVector< Number > * > &all_vectors)
Get a map that stores pointers to all of the vectors.
virtual void truth_assembly()
Assemble the truth matrix and right-hand side for current_parameters.
bool assert_convergence
A boolean flag to indicate whether to check for proper convergence after each solve.
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
Train the reduced basis.
virtual ~RBConstruction()
Destructor.
virtual Real truth_solve(int plot_solution)
Perform a "truth" solve, i.e.
RBConstruction(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
bool get_convergence_assertion_flag() const
Getter for the flag determining if convergence should be checked after each solve.
SparseMatrix< Number > * get_Aq(unsigned int q)
Get a pointer to Aq.
bool compute_RB_inner_product
Boolean flag to indicate whether we compute the RB_inner_product_matrix.
virtual void set_context_solution_vec(NumericVector< Number > &vec)
Set current_local_solution = vec so that we can access vec from FEMContext during assembly...
std::vector< std::vector< Number > > output_dual_innerprods
The vector storing the dual norm inner product terms for each output.
ElemAssembly & get_inner_product_assembly()
virtual bool greedy_termination_test(Real abs_greedy_error, Real initial_greedy_error, int count)
Function that indicates when to terminate the Greedy basis training.
RBConstructionBase< LinearImplicitSystem > Parent
The type of the parent.
void add_scaled_Aq(Number scalar, unsigned int q_a, SparseMatrix< Number > *input_matrix, bool symmetrize)
Add the scaled q^th affine matrix to input_matrix.
const RBParameters & get_greedy_parameter(unsigned int i)
Return the parameters chosen during the i^th step of the Greedy algorithm.
The libMesh namespace provides an interface to certain functionality in the library.
NumericVector< Number > * get_Fq(unsigned int q)
Get a pointer to Fq.
std::vector< Number > Fq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online...
virtual std::string system_type() const libmesh_override
UniquePtr< SparseMatrix< Number > > inner_product_matrix
The inner product matrix.
UniquePtr< LinearSolver< Number > > inner_product_solver
We store an extra linear solver object which we can optionally use for solving all systems in which t...
const std::string & name() const
Definition: system.h:1998
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
virtual void init_context(FEMContext &)
Initialize the FEMContext prior to performing an element loop.
virtual Real compute_max_error_bound()
(i) Compute the a posteriori error bound for each set of parameters in the training set...
unsigned int get_Nmax() const
Get/set Nmax, the maximum number of RB functions we are willing to compute.
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
void set_quiet_mode(bool quiet_mode_in)
Set the quiet_mode flag.
void assemble_inner_product_matrix(SparseMatrix< Number > *input_matrix, bool apply_dof_constraints=true)
Assemble the inner product matrix and store it in input_matrix.
virtual void get_output_vectors(std::map< std::string, NumericVector< Number > * > &all_vectors)
Get a map that stores pointers to all of the vectors.
LinearSolver< Number > * extra_linear_solver
Also, we store a pointer to an extra linear solver.
virtual void recompute_all_residual_terms(const bool compute_inner_products=true)
This function computes all of the residual representors, can be useful when restarting a basis traini...
virtual void load_basis_function(unsigned int i)
Load the i^th RB function into the RBConstruction solution vector.
bool is_rb_eval_initialized() const
virtual void solve_for_matrix_and_rhs(LinearSolver< Number > &input_solver, SparseMatrix< Number > &input_matrix, NumericVector< Number > &input_rhs)
Assembles & solves the linear system A*x=b for the specified matrix input_matrix and right-hand side ...
bool impose_internal_fluxes
Boolean flag to indicate whether we impose "fluxes" (i.e.
bool Fq_representor_innerprods_computed
A boolean flag to indicate whether or not the Fq representor norms have already been computed — used...
bool use_empty_rb_solve_in_greedy
A boolean flag to indicate whether or not we initialize the Greedy algorithm by performing rb_solves ...
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the RBThetaExpansion object that that belongs to rb_eval.
std::vector< std::vector< NumericVector< Number > * > > non_dirichlet_outputs_vector
void set_rb_assembly_expansion(RBAssemblyExpansion &rb_assembly_expansion_in)
Set the rb_assembly_expansion object.
virtual void get_all_matrices(std::map< std::string, SparseMatrix< Number > * > &all_matrices)
Get a map that stores pointers to all of the matrices.
void update_greedy_param_list()
Update the list of Greedily chosen parameters with current_parameters.
Real rel_training_tolerance
Relative and absolute tolerances for training reduced basis using the Greedy scheme.
void print_basis_function_orthogonality()
Print out a matrix that shows the orthogonality of the RB basis functions.
RBAssemblyExpansion & get_rb_assembly_expansion()
void set_rb_construction_parameters(unsigned int n_training_samples_in, bool deterministic_training_in, unsigned int training_parameters_random_seed_in, bool quiet_mode_in, unsigned int Nmax_in, Real rel_training_tolerance_in, Real abs_training_tolerance_in, bool normalize_rb_error_bound_in_greedy_in, RBParameters mu_min_in, RBParameters mu_max_in, std::map< std::string, std::vector< Real >> discrete_parameter_values_in, std::map< std::string, bool > log_scaling)
Set the state of this RBConstruction object based on the arguments to this function.
SparseMatrix< Number > * get_inner_product_matrix()
Get a pointer to inner_product_matrix.
virtual void update_RB_system_matrices()
Compute the reduced basis matrices for the current basis.
virtual void update_residual_terms(bool compute_inner_products=true)
Compute the terms that are combined `online&#39; to determine the dual norm of the residual.
void assemble_Fq_vector(unsigned int q, NumericVector< Number > *input_vector, bool apply_dof_constraints=true)
Assemble the q^th affine vector and store it in input_matrix.
RBConstruction sys_type
The type of system.
virtual void update_system()
Update the system after enriching the RB space; this calls a series of functions to update the system...
std::vector< std::vector< NumericVector< Number > * > > outputs_vector
The libMesh vectors that define the output functionals.
virtual SparseMatrix< Number > & get_matrix_for_output_dual_solves()
Return the matrix for the output residual dual norm solves.
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:61
virtual void print_info()
Print out info that describes the current setup of this RBConstruction.
NumericVector< Number > * get_non_dirichlet_Fq(unsigned int q)
Get a pointer to non-Dirichlet Fq.
virtual Real get_RB_error_bound()
std::vector< NumericVector< Number > * > Fq_representor
Vector storing the residual representors associated with the right-hand side.
SparseMatrix< Number > * get_non_dirichlet_Aq(unsigned int q)
Get a pointer to non_dirichlet_Aq.
void set_normalize_rb_bound_in_greedy(bool normalize_rb_bound_in_greedy)
Get/set the boolean to indicate if we normalize the RB error in the greedy.
void set_inner_product_assembly(ElemAssembly &inner_product_assembly_in)
Set the rb_assembly_expansion object.
void add_scaled_matrix_and_vector(Number scalar, ElemAssembly *elem_assembly, SparseMatrix< Number > *input_matrix, NumericVector< Number > *input_vector, bool symmetrize=false, bool apply_dof_constraints=true)
This function loops over the mesh and applies the specified interior and/or boundary assembly routine...
void set_convergence_assertion_flag(bool flag)
Setter for the flag determining if convergence should be checked after each solve.
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:42
unsigned int delta_N
The number of basis functions that we add at each greedy step.
RBEvaluation * rb_eval
The current RBEvaluation object we are using to perform the Evaluation stage of the reduced basis met...
This class is part of the rbOOmit framework.
Definition: rb_evaluation.h:50
void set_abs_training_tolerance(Real new_training_tolerance)
Get/set the absolute tolerance for the basis training.
std::vector< SparseMatrix< Number > * > Aq_vector
Vector storing the Q_a matrices from the affine expansion.
bool store_non_dirichlet_operators
Boolean flag to indicate whether we store a second copy of each affine operator and vector which does...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool is_quiet() const
Is the system in quiet mode?
ElemAssembly * inner_product_assembly
Pointer to inner product assembly.
void check_convergence(LinearSolver< Number > &input_solver)
Check if the linear solver reports convergence.
static UniquePtr< DirichletBoundary > build_zero_dirichlet_boundary_object()
It&#39;s helpful to be able to generate a DirichletBoundary that stores a ZeroFunction in order to impose...
unsigned int number() const
Definition: system.h:2006
unsigned int get_delta_N() const
Get delta_N, the number of basis functions we add to the RB space per iteration of the greedy algorit...
This class stores the set of ElemAssembly functor objects that define the "parameter-independent expa...
ElemAssembly provides a per-element (interior and boundary) assembly functionality.
Definition: elem_assembly.h:38
std::vector< Number > truth_outputs
Vector storing the truth output values from the most recent truth solve.
virtual void compute_Fq_representor_innerprods(bool compute_inner_products=true)
Compute the terms that are combined `online&#39; to determine the dual norm of the residual.
virtual void set_Nmax(unsigned int Nmax)
void set_rel_training_tolerance(Real new_training_tolerance)
Get/set the relative tolerance for the basis training.
virtual void write_riesz_representors_to_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors)
Write out all the Riesz representor data to files.
virtual void assemble_all_output_vectors()
Assemble and store the output vectors.
void assemble_Aq_matrix(unsigned int q, SparseMatrix< Number > *input_matrix, bool apply_dof_constraints=true)
Assemble the q^th affine matrix and store it in input_matrix.
This class is part of the rbOOmit framework.
virtual void process_parameters_file(const std::string &parameters_filename)
Read in from the file specified by parameters_filename and set the this system&#39;s member variables acc...
RBAssemblyExpansion * rb_assembly_expansion
This member holds the (parameter independent) assembly functors that define the "affine expansion" of...
virtual void clear() libmesh_override
Clear all the data structures associated with the system.
This class is part of the rbOOmit framework.
NumericVector< Number > * get_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to the n^th output.
RBEvaluation & get_rb_evaluation()
Get a reference to the RBEvaluation object.
bool quiet_mode
Flag to indicate whether we print out extra information during the Offline stage. ...
virtual void assemble_misc_matrices()
Assemble and store all the inner-product matrix, the constraint matrix (for constrained problems) and...
virtual void load_rb_solution()
Load the RB solution from the most recent solve with rb_eval into this system&#39;s solution vector...
void set_rb_evaluation(RBEvaluation &rb_eval_in)
Set the RBEvaluation object.
virtual void compute_output_dual_innerprods()
Compute and store the dual norm of each output functional.
bool exit_on_repeated_greedy_parameters
Boolean flag to indicate whether we exit the greedy if we select the same parameters twice in a row...
std::vector< NumericVector< Number > * > non_dirichlet_Fq_vector
virtual UniquePtr< DGFEMContext > build_context()
Builds a DGFEMContext object with enough information to do evaluations on each element.
bool output_dual_innerprods_computed
A boolean flag to indicate whether or not the output dual norms have already been computed — used to...
std::vector< NumericVector< Number > * > Fq_vector
Vector storing the Q_f vectors in the affine decomposition of the right-hand side.
virtual void enrich_RB_space()
Add a new basis function to the RB space.
virtual void assemble_all_affine_vectors()
Assemble and store the affine RHS vectors.
NumericVector< Number > * get_non_dirichlet_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to non-Dirichlet output vector.
virtual void allocate_data_structures()
Helper function that actually allocates all the data structures required by this class.
unsigned int Nmax
Maximum number of reduced basis functions we are willing to use.
virtual void assemble_affine_expansion(bool skip_matrix_assembly, bool skip_vector_assembly)
Assemble the matrices and vectors for this system.
void zero_constrained_dofs_on_vector(NumericVector< Number > &vector)
It is sometimes useful to be able to zero vector entries that correspond to constrained dofs...
virtual void assemble_all_affine_operators()
Assemble and store all Q_a affine operators as well as the inner-product matrix.