$extrastylesheet
rb_construction.h
Go to the documentation of this file.
00001 // rbOOmit: An implementation of the Certified Reduced Basis method.
00002 // Copyright (C) 2009, 2010 David J. Knezevic
00003 
00004 // This file is part of rbOOmit.
00005 
00006 // rbOOmit is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License, or (at your option) any later version.
00010 
00011 // rbOOmit is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 #ifndef LIBMESH_RB_CONSTRUCTION_H
00021 #define LIBMESH_RB_CONSTRUCTION_H
00022 
00023 // rbOOmit includes
00024 #include "libmesh/rb_construction_base.h"
00025 #include "libmesh/rb_evaluation.h"
00026 
00027 // libMesh includes
00028 #include "libmesh/linear_implicit_system.h"
00029 #include "libmesh/dense_vector.h"
00030 #include "libmesh/dense_matrix.h"
00031 #include "libmesh/dg_fem_context.h"
00032 #include "libmesh/elem_assembly.h"
00033 #include "libmesh/dirichlet_boundaries.h"
00034 
00035 // C++ includes
00036 
00037 namespace libMesh
00038 {
00039 
00040 class RBThetaExpansion;
00041 class RBAssemblyExpansion;
00042 
00054 // ------------------------------------------------------------
00055 // RBConstruction class definition
00056 
00057 class RBConstruction : public RBConstructionBase<LinearImplicitSystem>
00058 {
00059 public:
00060 
00065   RBConstruction (EquationSystems& es,
00066                   const std::string& name,
00067                   const unsigned int number);
00068 
00072   virtual ~RBConstruction ();
00073 
00077   typedef RBConstruction sys_type;
00078 
00082   void set_rb_evaluation(RBEvaluation& rb_eval_in);
00083 
00087   RBEvaluation& get_rb_evaluation();
00088 
00092   bool is_rb_eval_initialized() const;
00093 
00098   RBThetaExpansion& get_rb_theta_expansion();
00099 
00103   void set_rb_assembly_expansion(RBAssemblyExpansion& rb_assembly_expansion_in);
00104 
00108   RBAssemblyExpansion& get_rb_assembly_expansion();
00109 
00113   sys_type & system () { return *this; }
00114 
00118   typedef RBConstructionBase<LinearImplicitSystem> Parent;
00119 
00124   virtual void clear ();
00125 
00129   virtual std::string system_type () const;
00130 
00137   virtual Real truth_solve(int plot_solution);
00138 
00155   virtual Real train_reduced_basis(const std::string& directory_name = "offline_data",
00156                                    const bool resize_rb_eval_data=true);
00157 
00163   virtual Real compute_max_error_bound();
00164 
00169   const RBParameters& get_greedy_parameter(unsigned int i);
00170 
00174   void set_training_tolerance(Real new_training_tolerance)
00175   {this->training_tolerance = new_training_tolerance; }
00176   Real get_training_tolerance() { return training_tolerance; }
00177 
00182   unsigned int get_Nmax() const    { return Nmax; }
00183   virtual void set_Nmax(unsigned int Nmax);
00184 
00190   void set_quiet_mode(bool quiet_mode_in)
00191   { this->quiet_mode = quiet_mode_in; }
00192 
00196   bool is_quiet() const
00197   { return this->quiet_mode; }
00198 
00203   virtual void load_basis_function(unsigned int i);
00204 
00209   virtual void load_rb_solution();
00210 
00217   SparseMatrix<Number>* get_inner_product_matrix();
00218 
00227   SparseMatrix<Number>* get_non_dirichlet_inner_product_matrix();
00228 
00232   SparseMatrix<Number>* get_Aq(unsigned int q);
00233 
00237   SparseMatrix<Number>* get_non_dirichlet_Aq(unsigned int q);
00238 
00248   virtual void initialize_rb_construction(bool skip_matrix_assembly=false,
00249                                           bool skip_vector_assembly=false);
00250 
00254   NumericVector<Number>* get_Fq(unsigned int q);
00255 
00259   NumericVector<Number>* get_non_dirichlet_Fq(unsigned int q);
00260 
00264   NumericVector<Number>* get_output_vector(unsigned int n, unsigned int q_l);
00265 
00269   NumericVector<Number>* get_non_dirichlet_output_vector(unsigned int n, unsigned int q_l);
00270 
00274   virtual void get_all_matrices(std::map<std::string, SparseMatrix<Number>*>& all_matrices);
00275 
00279   virtual void get_all_vectors(std::map<std::string, NumericVector<Number>*>& all_vectors);
00280 
00284   virtual void get_output_vectors(std::map<std::string, NumericVector<Number>*>& all_vectors);
00285 
00291   virtual void assemble_affine_expansion(bool skip_matrix_assembly,
00292                                          bool skip_vector_assembly);
00293 
00297   void assemble_inner_product_matrix(SparseMatrix<Number>* input_matrix, bool apply_dof_constraints=true);
00298 
00302   void assemble_constraint_matrix(SparseMatrix<Number>* input_matrix);
00303 
00307   void assemble_and_add_constraint_matrix(SparseMatrix<Number>* input_matrix);
00308 
00312   void assemble_Aq_matrix(unsigned int q, SparseMatrix<Number>* input_matrix, bool apply_dof_constraints=true);
00313 
00317   void assemble_Fq_vector(unsigned int q, NumericVector<Number>* input_vector, bool apply_dof_constraints=true);
00318 
00323   void add_scaled_Aq(Number scalar, unsigned int q_a,
00324                      SparseMatrix<Number>* input_matrix,
00325                      bool symmetrize);
00326 
00332   virtual void write_riesz_representors_to_files(const std::string& riesz_representors_dir,
00333                                                  const bool write_binary_residual_representors);
00334 
00341   virtual void read_riesz_representors_from_files(const std::string& riesz_representors_dir,
00342                                                   const bool write_binary_residual_representors);
00343 
00344 
00352   virtual void recompute_all_residual_terms(const bool compute_inner_products=true);
00353 
00358   virtual void process_parameters_file(const std::string& parameters_filename);
00359 
00364   void set_rb_construction_parameters(
00365                                       unsigned int n_training_samples_in,
00366                                       bool deterministic_training_in,
00367                                       std::string alternative_solver_in,
00368                                       bool reuse_preconditioner_in,
00369                                       bool use_relative_bound_in_greedy_in,
00370                                       bool write_data_during_training_in,
00371                                       unsigned int training_parameters_random_seed_in,
00372                                       bool quiet_mode_in,
00373                                       unsigned int Nmax_in,
00374                                       Real training_tolerance_in,
00375                                       RBParameters mu_min_in,
00376                                       RBParameters mu_max_in,
00377                                       std::map< std::string, std::vector<Real> > discrete_parameter_values_in,
00378                                       std::map<std::string,bool> log_scaling);
00379 
00383   virtual void print_info();
00384 
00390   void print_basis_function_orthogonality();
00391 
00399   unsigned int get_delta_N() const { return delta_N; }
00400 
00404   void set_inner_product_assembly(ElemAssembly& inner_product_assembly_in);
00405 
00409   ElemAssembly& get_inner_product_assembly();
00410 
00414   void set_constraint_assembly(ElemAssembly& constraint_assembly_in);
00415 
00419   ElemAssembly& get_constraint_assembly();
00420 
00425   void zero_constrained_dofs_on_vector(NumericVector<Number>& vector);
00426 
00431   static UniquePtr<DirichletBoundary> build_zero_dirichlet_boundary_object();
00432 
00437   void set_convergence_assertion_flag(bool flag);
00438 
00439   //----------- PUBLIC DATA MEMBERS -----------//
00440 
00448   std::vector<Real> training_error_bounds;
00449 
00455   UniquePtr< LinearSolver<Number> > inner_product_solver;
00456 
00461   LinearSolver<Number> *original_linear_solver;
00462 
00467   bool use_inner_product_solver;
00468 
00472   UniquePtr< SparseMatrix<Number> > inner_product_matrix;
00473 
00478   UniquePtr< SparseMatrix<Number> > non_dirichlet_inner_product_matrix;
00479 
00484   UniquePtr< SparseMatrix<Number> > constraint_matrix;
00485 
00490   std::vector< Number > truth_outputs;
00491 
00496   std::vector< std::vector< Number > > output_dual_innerprods;
00497 
00504   std::vector< NumericVector<Number>* > Fq_representor;
00505 
00513   std::vector<Number> Fq_representor_innerprods;
00514 
00519   bool constrained_problem;
00520 
00525   bool reuse_preconditioner;
00526 
00532   bool use_relative_bound_in_greedy;
00533 
00540   bool exit_on_repeated_greedy_parameters;
00541 
00547   bool write_data_during_training;
00548 
00554   bool impose_internal_dirichlet_BCs;
00555 
00561   bool impose_internal_fluxes;
00562 
00569   bool compute_RB_inner_product;
00570 
00576   bool store_non_dirichlet_operators;
00577 
00584   bool enforce_constraints_exactly;
00585 
00591   bool use_empty_rb_solve_in_greedy;
00592 
00598   bool Fq_representor_innerprods_computed;
00599 
00600 protected:
00601 
00606   virtual void allocate_data_structures();
00607 
00612   virtual void truth_assembly();
00613 
00619   virtual UniquePtr<DGFEMContext> build_context();
00620 
00626   virtual void assemble_matrix_for_output_dual_solves();
00627 
00632   virtual bool greedy_termination_test(Real training_greedy_error, int count);
00633 
00638   void update_greedy_param_list();
00639 
00647   void add_scaled_matrix_and_vector(Number scalar,
00648                                     ElemAssembly* elem_assembly,
00649                                     SparseMatrix<Number>* input_matrix,
00650                                     NumericVector<Number>* input_vector,
00651                                     bool symmetrize=false,
00652                                     bool apply_dof_constraints=true);
00653 
00659   virtual void set_context_solution_vec(NumericVector<Number>& vec);
00660 
00667   virtual void assemble_misc_matrices();
00668 
00673   virtual void assemble_all_affine_operators();
00674 
00678   virtual void assemble_all_affine_vectors();
00679 
00683   virtual void assemble_all_output_vectors();
00684 
00688   virtual void compute_output_dual_innerprods();
00689 
00702   virtual void compute_Fq_representor_innerprods(bool compute_inner_products=true);
00703 
00708   virtual void enrich_RB_space();
00709 
00714   virtual void update_system();
00715 
00720   virtual Real get_RB_error_bound();
00721 
00725   virtual void update_RB_system_matrices();
00726 
00734   virtual void update_residual_terms(bool compute_inner_products=true);
00735 
00742   virtual void init_context(FEMContext& ) {}
00743 
00748   bool get_convergence_assertion_flag() const;
00749 
00754   void check_convergence();
00755 
00756   //----------- PROTECTED DATA MEMBERS -----------//
00757 
00762   unsigned int Nmax;
00763 
00768   unsigned int delta_N;
00769 
00774   bool quiet_mode;
00775 
00781   bool output_dual_innerprods_computed;
00782 
00787   bool assert_convergence;
00788 
00789 private:
00790 
00791   //----------- PRIVATE DATA MEMBERS -----------//
00792 
00798   RBEvaluation* rb_eval;
00799 
00804   RBAssemblyExpansion* rb_assembly_expansion;
00805 
00809   ElemAssembly* inner_product_assembly;
00810 
00815   ElemAssembly* constraint_assembly;
00816 
00820   std::vector< SparseMatrix<Number>* > Aq_vector;
00821 
00826   std::vector< NumericVector<Number>* > Fq_vector;
00827 
00832   std::vector< std::vector< NumericVector<Number>* > > outputs_vector;
00833 
00839   std::vector< SparseMatrix<Number>* > non_dirichlet_Aq_vector;
00840   std::vector< NumericVector<Number>* > non_dirichlet_Fq_vector;
00841   std::vector< std::vector< NumericVector<Number>* > > non_dirichlet_outputs_vector;
00842 
00846   Real training_tolerance;
00847 
00848 };
00849 
00850 } // namespace libMesh
00851 
00852 #endif // LIBMESH_RB_CONSTRUCTION_H