libMesh
rb_evaluation.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_EVALUATION_H
21 #define LIBMESH_RB_EVALUATION_H
22 
23 // rbOOmit includes
24 #include "libmesh/rb_parametrized.h"
25 
26 // libMesh includes
27 #include "libmesh/dense_matrix.h"
28 #include "libmesh/dense_vector.h"
29 #include "libmesh/parallel_object.h"
30 
31 // C++ includes
32 #include <memory>
33 
34 namespace libMesh
35 {
36 
37 class System;
38 template <typename T> class NumericVector;
39 class RBThetaExpansion;
40 
51  public ParallelObject
52 {
53 public:
54 
59 
66  RBEvaluation (RBEvaluation &&) = default;
67  RBEvaluation (const RBEvaluation &) = delete;
68  RBEvaluation & operator= (const RBEvaluation &) = delete;
69  RBEvaluation & operator= (RBEvaluation &&) = default;
70  virtual ~RBEvaluation ();
71 
76  virtual void clear() override;
77 
81  void set_rb_theta_expansion(RBThetaExpansion & rb_theta_expansion_in);
82 
88 
93 
100  virtual void resize_data_structures(const unsigned int Nmax,
101  bool resize_error_bound_data=true);
102 
106  NumericVector<Number> & get_basis_function(unsigned int i);
107  const NumericVector<Number> & get_basis_function(unsigned int i) const;
108 
118  virtual Real rb_solve(unsigned int N);
119 
124  virtual Real rb_solve(unsigned int N,
125  const std::vector<Number> * evaluated_thetas);
126 
132 
137  virtual Real compute_residual_dual_norm(const unsigned int N);
138 
143  virtual Real compute_residual_dual_norm(const unsigned int N,
144  const std::vector<Number> * evaluated_thetas);
145 
151  virtual Real residual_scaling_denom(Real alpha_LB);
152 
163  Real eval_output_dual_norm(unsigned int n, const RBParameters & mu);
164 
170  Real eval_output_dual_norm(unsigned int n, const std::vector<Number> * evaluated_thetas);
171 
177 
181  virtual unsigned int get_n_basis_functions() const
182  { return cast_int<unsigned int>(basis_functions.size()); }
183 
188  virtual void set_n_basis_functions(unsigned int n_bfs);
189 
195  virtual void clear_riesz_representors();
196 
203  virtual void legacy_write_offline_data_to_files(const std::string & directory_name = "offline_data",
204  const bool write_binary_data=true);
205 
212  virtual void legacy_read_offline_data_from_files(const std::string & directory_name = "offline_data",
213  bool read_error_bound_data=true,
214  const bool read_binary_data=true);
215 
223  virtual void write_out_basis_functions(System & sys,
224  const std::string & directory_name = "offline_data",
225  const bool write_binary_basis_functions = true);
226 
231  static void write_out_vectors(System & sys,
232  std::vector<NumericVector<Number>*> & vectors,
233  const std::string & directory_name = "offline_data",
234  const std::string & data_name = "bf",
235  const bool write_binary_basis_functions = true);
236 
244  virtual void read_in_basis_functions(System & sys,
245  const std::string & directory_name = "offline_data",
246  const bool read_binary_basis_functions = true);
247 
253  static void read_in_vectors(System & sys,
254  std::vector<std::unique_ptr<NumericVector<Number>>> & vectors,
255  const std::string & directory_name,
256  const std::string & data_name,
257  const bool read_binary_vectors);
258 
266  std::vector<std::vector<std::unique_ptr<NumericVector<Number>>> *> multiple_vectors,
267  const std::vector<std::string> & multiple_directory_names,
268  const std::vector<std::string> & multiple_data_names,
269  const bool read_binary_vectors);
270 
271  //----------- PUBLIC DATA MEMBERS -----------//
272 
277  std::vector<std::unique_ptr<NumericVector<Number>>> basis_functions;
278 
283  std::vector<RBParameters> greedy_param_list;
284 
292 
296  std::vector<DenseMatrix<Number>> RB_Aq_vector;
297 
301  std::vector<DenseVector<Number>> RB_Fq_vector;
302 
307 
311  std::vector<std::vector<DenseVector<Number>>> RB_output_vectors;
312 
317  std::vector<Number > RB_outputs;
318  std::vector<Real > RB_output_error_bounds;
319 
326  std::vector<Number> Fq_representor_innerprods;
327 
335  std::vector<std::vector<std::vector<Number>>> Fq_Aq_representor_innerprods;
336  std::vector<std::vector<std::vector<Number>>> Aq_Aq_representor_innerprods;
337 
344  std::vector<std::vector<Number >> output_dual_innerprods;
345 
352  std::vector<std::vector<std::unique_ptr<NumericVector<Number>>>> Aq_representor;
353 
359 
364 
365 protected:
366 
370  static void assert_file_exists(const std::string & file_name);
371 
372 private:
373 
381 
387  void check_evaluated_thetas_size(const std::vector<Number> * evaluated_thetas) const;
388 };
389 
390 }
391 
392 #endif // LIBMESH_RB_EVALUATION_H
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > Aq_representor
Vector storing the residual representors associated with the left-hand side.
bool compute_RB_inner_product
Boolean flag to indicate whether we compute the RB_inner_product_matrix.
bool evaluate_RB_error_bound
Boolean to indicate whether we evaluate a posteriori error bounds when rb_solve is called...
virtual void write_out_basis_functions(System &sys, const std::string &directory_name="offline_data", const bool write_binary_basis_functions=true)
Write out all the basis functions to file.
std::vector< Number > Fq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online...
virtual void resize_data_structures(const unsigned int Nmax, bool resize_error_bound_data=true)
Resize and clear the data vectors corresponding to the value of Nmax.
DenseVector< Number > RB_solution
The RB solution vector.
DenseMatrix< Number > RB_inner_product_matrix
The inner product matrix.
std::vector< std::unique_ptr< NumericVector< Number > > > basis_functions
The libMesh vectors storing the finite element coefficients of the RB basis functions.
virtual Real compute_residual_dual_norm(const unsigned int N)
Compute the dual norm of the residual for the solution saved in RB_solution_vector.
const Parallel::Communicator & comm() const
std::vector< std::vector< Number > > output_dual_innerprods
The vector storing the dual norm inner product terms for each output.
virtual Real get_error_bound_normalization()
static void read_in_vectors_from_multiple_files(System &sys, std::vector< std::vector< std::unique_ptr< NumericVector< Number >>> *> multiple_vectors, const std::vector< std::string > &multiple_directory_names, const std::vector< std::string > &multiple_data_names, const bool read_binary_vectors)
Performs read_in_vectors for a list of directory names and data names.
The libMesh namespace provides an interface to certain functionality in the library.
std::vector< RBParameters > greedy_param_list
The list of parameters selected by the Greedy algorithm in generating the Reduced Basis associated wi...
static void read_in_vectors(System &sys, std::vector< std::unique_ptr< NumericVector< Number >>> &vectors, const std::string &directory_name, const std::string &data_name, const bool read_binary_vectors)
Same as read_in_basis_functions, except in this case we pass in the vectors to be written...
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
RBEvaluation(const Parallel::Communicator &comm)
Constructor.
Definition: rb_evaluation.C:48
std::vector< DenseVector< Number > > RB_Fq_vector
Dense vector for the RHS.
static void write_out_vectors(System &sys, std::vector< NumericVector< Number > *> &vectors, const std::string &directory_name="offline_data", const std::string &data_name="bf", const bool write_binary_basis_functions=true)
Same as write_out_basis_functions, except in this case we pass in the vectors to be written...
virtual Real get_stability_lower_bound()
Get a lower bound for the stability constant (e.g.
virtual void legacy_write_offline_data_to_files(const std::string &directory_name="offline_data", const bool write_binary_data=true)
Write out all the data to text files in order to segregate the Offline stage from the Online stage...
virtual void legacy_read_offline_data_from_files(const std::string &directory_name="offline_data", bool read_error_bound_data=true, const bool read_binary_data=true)
Read in the saved Offline reduced basis data to initialize the system for Online solves.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
NumericVector< Number > & get_basis_function(unsigned int i)
Get a reference to the i^th basis function.
std::vector< Real > RB_output_error_bounds
virtual void read_in_basis_functions(System &sys, const std::string &directory_name="offline_data", const bool read_binary_basis_functions=true)
Read in all the basis functions from file.
virtual void set_n_basis_functions(unsigned int n_bfs)
Set the number of basis functions.
Definition: rb_evaluation.C:75
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:52
An object whose state is distributed along a set of processors.
virtual Real residual_scaling_denom(Real alpha_LB)
Specifies the residual scaling on the denominator to be used in the a posteriori error bound...
void set_rb_theta_expansion(RBThetaExpansion &rb_theta_expansion_in)
Set the RBThetaExpansion object.
Definition: rb_evaluation.C:80
std::vector< std::vector< std::vector< Number > > > Fq_Aq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online...
virtual Real rb_solve(unsigned int N)
Perform online solve with the N RB basis functions, for the set of parameters in current_params, where 0 <= N <= RB_size.
This class is part of the rbOOmit framework.
Definition: rb_evaluation.h:50
virtual void clear_riesz_representors()
Clear all the Riesz representors that are used to compute the RB residual (and hence error bound)...
std::vector< DenseMatrix< Number > > RB_Aq_vector
Dense matrices for the RB computations.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
RBEvaluation & operator=(const RBEvaluation &)=delete
Real eval_output_dual_norm(unsigned int n, const RBParameters &mu)
Evaluate the dual norm of output n for the current parameters.
static void assert_file_exists(const std::string &file_name)
Helper function that checks if file_name exists.
This class is part of the rbOOmit framework.
virtual unsigned int get_n_basis_functions() const
Get the current number of basis functions.
virtual void clear() override
Clear this RBEvaluation object.
Definition: rb_evaluation.C:59
void check_evaluated_thetas_size(const std::vector< Number > *evaluated_thetas) const
For interfaces like rb_solve() and compute_residual_dual_norm() that optinally take a vector of "pre-...
std::vector< Number > RB_outputs
The vectors storing the RB output values and corresponding error bounds.
RBThetaExpansion * rb_theta_expansion
A pointer to to the object that stores the theta expansion.
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the rb_theta_expansion.
Definition: rb_evaluation.C:85
std::vector< std::vector< std::vector< Number > > > Aq_Aq_representor_innerprods
bool is_rb_theta_expansion_initialized() const
std::vector< std::vector< DenseVector< Number > > > RB_output_vectors
The vectors storing the RB output vectors.