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
25 
26 // libMesh includes
28 #include "libmesh/dense_vector.h"
29 #include "libmesh/dense_matrix.h"
30 #include "libmesh/dg_fem_context.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 () override;
129 
133  virtual std::string system_type () const 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  void enrich_basis_from_rhs_terms(const bool resize_rb_eval_data=true);
167 
173  virtual Real compute_max_error_bound();
174 
179  const RBParameters & get_greedy_parameter(unsigned int i);
180 
184  void set_rel_training_tolerance(Real new_training_tolerance)
185  {this->rel_training_tolerance = new_training_tolerance; }
187 
191  void set_abs_training_tolerance(Real new_training_tolerance)
192  {this->abs_training_tolerance = new_training_tolerance; }
194 
198  void set_normalize_rb_bound_in_greedy(bool normalize_rb_bound_in_greedy_in)
199  {this->normalize_rb_bound_in_greedy = normalize_rb_bound_in_greedy_in; }
201 
206  unsigned int get_Nmax() const { return Nmax; }
207  virtual void set_Nmax(unsigned int Nmax);
208 
213  virtual void load_basis_function(unsigned int i);
214 
219  virtual void load_rb_solution();
220 
228 
235 
241 
245  SparseMatrix<Number> * get_Aq(unsigned int q);
246 
250  SparseMatrix<Number> * get_non_dirichlet_Aq(unsigned int q);
251 
257 
267  virtual void initialize_rb_construction(bool skip_matrix_assembly=false,
268  bool skip_vector_assembly=false);
269 
273  NumericVector<Number> * get_Fq(unsigned int q);
274 
279 
285 
289  NumericVector<Number> * get_output_vector(unsigned int n, unsigned int q_l);
290 
294  NumericVector<Number> * get_non_dirichlet_output_vector(unsigned int n, unsigned int q_l);
295 
299  virtual void get_all_matrices(std::map<std::string, SparseMatrix<Number> *> & all_matrices);
300 
304  virtual void get_all_vectors(std::map<std::string, NumericVector<Number> *> & all_vectors);
305 
309  virtual void get_output_vectors(std::map<std::string, NumericVector<Number> *> & all_vectors);
310 
316  virtual void assemble_affine_expansion(bool skip_matrix_assembly,
317  bool skip_vector_assembly);
318 
322  void assemble_inner_product_matrix(SparseMatrix<Number> * input_matrix, bool apply_dof_constraints=true);
323 
327  void assemble_Aq_matrix(unsigned int q, SparseMatrix<Number> * input_matrix, bool apply_dof_constraints=true);
328 
332  void assemble_Fq_vector(unsigned int q, NumericVector<Number> * input_vector, bool apply_dof_constraints=true);
333 
338  void add_scaled_Aq(Number scalar, unsigned int q_a,
339  SparseMatrix<Number> * input_matrix,
340  bool symmetrize);
341 
347  virtual void write_riesz_representors_to_files(const std::string & riesz_representors_dir,
348  const bool write_binary_residual_representors);
349 
356  virtual void read_riesz_representors_from_files(const std::string & riesz_representors_dir,
357  const bool write_binary_residual_representors);
358 
359 
367  virtual void recompute_all_residual_terms(const bool compute_inner_products=true);
368 
373  virtual void process_parameters_file(const std::string & parameters_filename);
374 
379  void set_rb_construction_parameters(unsigned int n_training_samples_in,
380  bool deterministic_training_in,
381  unsigned int training_parameters_random_seed_in,
382  bool quiet_mode_in,
383  unsigned int Nmax_in,
384  Real rel_training_tolerance_in,
385  Real abs_training_tolerance_in,
386  bool normalize_rb_error_bound_in_greedy_in,
387  RBParameters mu_min_in,
388  RBParameters mu_max_in,
389  std::map<std::string, std::vector<Real>> discrete_parameter_values_in,
390  std::map<std::string,bool> log_scaling);
391 
395  virtual void print_info();
396 
403 
411  unsigned int get_delta_N() const { return delta_N; }
412 
416  void set_inner_product_assembly(ElemAssembly & inner_product_assembly_in);
417 
422 
428 
433  static std::unique_ptr<DirichletBoundary> build_zero_dirichlet_boundary_object();
434 
439  void set_convergence_assertion_flag(bool flag);
440 
441  //----------- PUBLIC DATA MEMBERS -----------//
442 
450  std::vector<Real> training_error_bounds;
451 
457  std::unique_ptr<LinearSolver<Number>> inner_product_solver;
458 
466 
470  std::unique_ptr<SparseMatrix<Number>> inner_product_matrix;
471 
476  std::vector<Number > truth_outputs;
477 
482  std::vector<std::vector<Number >> output_dual_innerprods;
483 
490  std::vector<std::unique_ptr<NumericVector<Number>>> Fq_representor;
491 
499  std::vector<Number> Fq_representor_innerprods;
500 
509 
517 
524 
532 
540 
547 
554 
561 
562 protected:
563 
568  virtual void allocate_data_structures();
569 
574  virtual void truth_assembly();
575 
581  virtual std::unique_ptr<DGFEMContext> build_context();
582 
589 
594  virtual bool greedy_termination_test(Real abs_greedy_error,
595  Real initial_greedy_error,
596  int count);
597 
603 
612  ElemAssembly * elem_assembly,
613  SparseMatrix<Number> * input_matrix,
614  NumericVector<Number> * input_vector,
615  bool symmetrize=false,
616  bool apply_dof_constraints=true);
617 
624 
631  virtual void assemble_misc_matrices();
632 
637  virtual void assemble_all_affine_operators();
638 
642  virtual void assemble_all_affine_vectors();
643 
647  virtual void assemble_all_output_vectors();
648 
652  virtual void compute_output_dual_innerprods();
653 
666  virtual void compute_Fq_representor_innerprods(bool compute_inner_products=true);
667 
672  virtual void enrich_RB_space();
673 
678  virtual void update_system();
679 
685  virtual Real get_RB_error_bound();
686 
690  virtual void update_RB_system_matrices();
691 
699  virtual void update_residual_terms(bool compute_inner_products=true);
700 
707  virtual void init_context(FEMContext &) {}
708 
713  bool get_convergence_assertion_flag() const;
714 
719  void check_convergence(LinearSolver<Number> & input_solver);
720 
721  //----------- PROTECTED DATA MEMBERS -----------//
722 
727  unsigned int Nmax;
728 
733  unsigned int delta_N;
734 
741 
747 
748 private:
749 
750  //----------- PRIVATE DATA MEMBERS -----------//
751 
758 
764 
769 
773  std::vector<std::unique_ptr<SparseMatrix<Number>>> Aq_vector;
774 
779  std::vector<std::unique_ptr<NumericVector<Number>>> Fq_vector;
780 
785  std::vector<std::vector<std::unique_ptr<NumericVector<Number>>>> outputs_vector;
786 
792  std::vector<std::unique_ptr<SparseMatrix<Number>>> non_dirichlet_Aq_vector;
793  std::vector<std::unique_ptr<NumericVector<Number>>> non_dirichlet_Fq_vector;
794  std::vector<std::vector<std::unique_ptr<NumericVector<Number>>>> non_dirichlet_outputs_vector;
795  std::unique_ptr<SparseMatrix<Number>> non_dirichlet_inner_product_matrix;
796 
803 
809 
810 };
811 
812 } // namespace libMesh
813 
814 #endif // LIBMESH_RB_CONSTRUCTION_H
virtual void update_residual_terms(bool compute_inner_products=true)
virtual void initialize_rb_construction(bool skip_matrix_assembly=false, bool skip_vector_assembly=false)
Manages multiples systems of equations.
virtual void write_riesz_representors_to_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors)
std::vector< Real > training_error_bounds
virtual void set_Nmax(unsigned int Nmax)
virtual void read_riesz_representors_from_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors)
std::vector< std::unique_ptr< NumericVector< Number > > > Fq_representor
NumericVector< Number > * get_Fq(unsigned int q)
virtual std::string system_type() const override
SparseMatrix< Number > * get_non_dirichlet_Aq_if_avail(unsigned int q)
SparseMatrix< Number > * get_Aq(unsigned int q)
virtual bool greedy_termination_test(Real abs_greedy_error, Real initial_greedy_error, int count)
RBConstruction(EquationSystems &es, const std::string &name, const unsigned int number)
virtual std::unique_ptr< DGFEMContext > build_context()
virtual void process_parameters_file(const std::string &parameters_filename)
SparseMatrix< Number > * get_non_dirichlet_Aq(unsigned int q)
virtual void assemble_all_affine_operators()
virtual void truth_assembly()
void enrich_basis_from_rhs_terms(const bool resize_rb_eval_data=true)
std::vector< std::vector< Number > > output_dual_innerprods
virtual void recompute_all_residual_terms(const bool compute_inner_products=true)
bool get_convergence_assertion_flag() const
RBConstructionBase< LinearImplicitSystem > Parent
void add_scaled_Aq(Number scalar, unsigned int q_a, SparseMatrix< Number > *input_matrix, bool symmetrize)
std::unique_ptr< SparseMatrix< Number > > inner_product_matrix
const RBParameters & get_greedy_parameter(unsigned int i)
virtual void assemble_affine_expansion(bool skip_matrix_assembly, bool skip_vector_assembly)
std::vector< Number > Fq_representor_innerprods
virtual Real compute_max_error_bound()
NumericVector< Number > * get_non_dirichlet_Fq(unsigned int q)
virtual void init_context(FEMContext &)
NumericVector< Number > * get_non_dirichlet_Fq_if_avail(unsigned int q)
virtual void clear() override
std::vector< std::unique_ptr< NumericVector< Number > > > non_dirichlet_Fq_vector
void assemble_inner_product_matrix(SparseMatrix< Number > *input_matrix, bool apply_dof_constraints=true)
LinearSolver< Number > * extra_linear_solver
virtual void load_basis_function(unsigned int i)
unsigned int number() const
Definition: system.h:2025
virtual void compute_Fq_representor_innerprods(bool compute_inner_products=true)
virtual void assemble_all_affine_vectors()
virtual void update_RB_system_matrices()
void set_rb_assembly_expansion(RBAssemblyExpansion &rb_assembly_expansion_in)
virtual void assemble_all_output_vectors()
std::unique_ptr< SparseMatrix< Number > > non_dirichlet_inner_product_matrix
void print_basis_function_orthogonality()
unsigned int get_Nmax() const
static std::unique_ptr< DirichletBoundary > build_zero_dirichlet_boundary_object()
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)
SparseMatrix< Number > * get_inner_product_matrix()
RBThetaExpansion & get_rb_theta_expansion()
void assemble_Fq_vector(unsigned int q, NumericVector< Number > *input_vector, bool apply_dof_constraints=true)
virtual void enrich_RB_space()
virtual void load_rb_solution()
virtual Real truth_solve(int plot_solution)
virtual void set_context_solution_vec(NumericVector< Number > &vec)
virtual void update_system()
unsigned int get_delta_N() const
virtual void allocate_data_structures()
SparseMatrix< Number > * get_non_dirichlet_inner_product_matrix()
void set_inner_product_assembly(ElemAssembly &inner_product_assembly_in)
virtual void get_all_matrices(std::map< std::string, SparseMatrix< Number > *> &all_matrices)
std::vector< std::unique_ptr< SparseMatrix< Number > > > Aq_vector
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)
ElemAssembly & get_inner_product_assembly()
void set_convergence_assertion_flag(bool flag)
virtual Real get_RB_error_bound()
bool is_rb_eval_initialized() const
virtual SparseMatrix< Number > & get_matrix_for_output_dual_solves()
virtual void compute_output_dual_innerprods()
RBEvaluation & get_rb_evaluation()
virtual void print_info()
void set_abs_training_tolerance(Real new_training_tolerance)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
ElemAssembly * inner_product_assembly
RBAssemblyExpansion & get_rb_assembly_expansion()
void check_convergence(LinearSolver< Number > &input_solver)
std::unique_ptr< LinearSolver< Number > > inner_product_solver
void set_normalize_rb_bound_in_greedy(bool normalize_rb_bound_in_greedy_in)
std::vector< std::unique_ptr< NumericVector< Number > > > Fq_vector
std::vector< Number > truth_outputs
virtual void assemble_misc_matrices()
std::vector< std::unique_ptr< SparseMatrix< Number > > > non_dirichlet_Aq_vector
void set_rel_training_tolerance(Real new_training_tolerance)
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > non_dirichlet_outputs_vector
void assemble_Aq_matrix(unsigned int q, SparseMatrix< Number > *input_matrix, bool apply_dof_constraints=true)
RBAssemblyExpansion * rb_assembly_expansion
virtual void get_output_vectors(std::map< std::string, NumericVector< Number > *> &all_vectors)
const std::string & name() const
Definition: system.h:2017
void set_rb_evaluation(RBEvaluation &rb_eval_in)
SparseMatrix< Number > * get_non_dirichlet_inner_product_matrix_if_avail()
NumericVector< Number > * get_non_dirichlet_output_vector(unsigned int n, unsigned int q_l)
virtual void solve_for_matrix_and_rhs(LinearSolver< Number > &input_solver, SparseMatrix< Number > &input_matrix, NumericVector< Number > &input_rhs)
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
NumericVector< Number > * get_output_vector(unsigned int n, unsigned int q_l)
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
virtual void get_all_vectors(std::map< std::string, NumericVector< Number > *> &all_vectors)
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > outputs_vector
void zero_constrained_dofs_on_vector(NumericVector< Number > &vector)