libMesh
rb_construction_base.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_BASE_H
21 #define LIBMESH_RB_CONSTRUCTION_BASE_H
22 
23 // rbOOmit includes
24 #include "libmesh/id_types.h"
25 #include "libmesh/rb_parametrized.h"
26 #include "libmesh/rb_theta_expansion.h"
27 #include "libmesh/rb_theta.h"
28 
29 // libMesh includes
30 #include "libmesh/system.h"
31 #include "libmesh/numeric_vector.h"
32 #include "libmesh/linear_solver.h"
33 #include "libmesh/perf_log.h"
34 
35 // C++ includes
36 #include <set>
37 
38 namespace libMesh
39 {
40 
54 template<class Base>
55 class RBConstructionBase : public Base, public RBParametrized
56 {
57 public:
58 
63  const std::string & name,
64  const unsigned int number);
65 
75  RBConstructionBase (const RBConstructionBase &) = delete;
77  virtual ~RBConstructionBase ();
78 
83 
87  sys_type & system () { return *this; }
88 
93  virtual void clear ();
94 
100  void set_quiet_mode(bool quiet_mode_in)
101  { this->quiet_mode = quiet_mode_in; }
102 
106  bool is_quiet() const
107  { return this->quiet_mode; }
108 
113 
118 
123 
128 
136  virtual void initialize_training_parameters(const RBParameters & mu_min,
137  const RBParameters & mu_max,
138  const unsigned int n_global_training_samples,
139  const std::map<std::string, bool> & log_param_scale,
140  const bool deterministic=true);
141 
146  virtual void load_training_set(const std::map<std::string, std::vector<RBParameter>> & new_training_set);
147 
152  void set_training_parameter_values(const std::string & param_name, const std::vector<RBParameter> & values);
153 
159  void broadcast_parameters(const unsigned int proc_id);
160 
164  void set_training_random_seed(int seed);
165 
178  void set_deterministic_training_parameter_name(const std::string & name);
179 
183  const std::string & get_deterministic_training_parameter_name() const;
184 
192  static std::pair<std::size_t, std::size_t>
194  const std::map<std::string, bool> & log_param_scale,
195  std::map<std::string, std::vector<RBParameter>> & local_training_parameters_in,
196  const unsigned int n_global_training_samples_in,
197  const RBParameters & min_parameters,
198  const RBParameters & max_parameters,
199  const int training_parameters_random_seed=-1,
200  const bool serial_training_set=false);
201 
210  static std::pair<std::size_t, std::size_t>
212  const std::map<std::string, bool> & log_param_scale,
213  std::map<std::string, std::vector<RBParameter>> & local_training_parameters_in,
214  const unsigned int n_global_training_samples_in,
215  const RBParameters & min_parameters,
216  const RBParameters & max_parameters,
217  const bool serial_training_set=false);
218 
219 protected:
220 
225  virtual void init_data ();
226 
232  RBParameters get_params_from_training_set(unsigned int global_index);
233 
237  void set_params_from_training_set(unsigned int global_index);
238 
242  virtual void set_params_from_training_set_and_broadcast(unsigned int global_index);
243 
249  static void get_global_max_error_pair(const Parallel::Communicator & communicator,
250  std::pair<numeric_index_type, Real> & error_pair);
251 
252 
253  //----------- PROTECTED DATA MEMBERS -----------//
254 
260 
268 
274  std::unique_ptr<NumericVector<Number>> inner_product_storage_vector;
275 
276 
277 private:
278 
284 
292  std::map<std::string, std::vector<RBParameter>> _training_parameters;
293 
302 
310 };
311 
312 } // namespace libMesh
313 
314 
315 #endif // LIBMESH_RB_CONSTRUCTION_BASE_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
numeric_index_type get_first_local_training_index() const
Get the first local index of the training parameters.
This is the EquationSystems class.
static std::pair< std::size_t, std::size_t > generate_training_parameters_random(const Parallel::Communicator &communicator, const std::map< std::string, bool > &log_param_scale, std::map< std::string, std::vector< RBParameter >> &local_training_parameters_in, const unsigned int n_global_training_samples_in, const RBParameters &min_parameters, const RBParameters &max_parameters, const int training_parameters_random_seed=-1, const bool serial_training_set=false)
Static helper function for generating a randomized set of parameters.
bool quiet_mode
Flag to indicate whether we print out extra information during the Offline stage. ...
static std::pair< std::size_t, std::size_t > generate_training_parameters_deterministic(const Parallel::Communicator &communicator, const std::map< std::string, bool > &log_param_scale, std::map< std::string, std::vector< RBParameter >> &local_training_parameters_in, const unsigned int n_global_training_samples_in, const RBParameters &min_parameters, const RBParameters &max_parameters, const bool serial_training_set=false)
Static helper function for generating a deterministic set of parameters.
void set_quiet_mode(bool quiet_mode_in)
Set the quiet_mode flag.
bool is_quiet() const
Is the system in quiet mode?
static void get_global_max_error_pair(const Parallel::Communicator &communicator, std::pair< numeric_index_type, Real > &error_pair)
Static function to return the error pair (index,error) that is corresponds to the largest error on al...
void set_training_parameter_values(const std::string &param_name, const std::vector< RBParameter > &values)
Overwrite the local training samples for param_name using values.
The libMesh namespace provides an interface to certain functionality in the library.
void broadcast_parameters(const unsigned int proc_id)
Broadcasts parameters from processor proc_id to all processors.
std::unique_ptr< NumericVector< Number > > inner_product_storage_vector
We keep an extra temporary vector that is useful for performing inner products (avoids unnecessary me...
RBConstructionBase< Base > sys_type
The type of system.
virtual void load_training_set(const std::map< std::string, std::vector< RBParameter >> &new_training_set)
Overwrite the training parameters with new_training_set.
numeric_index_type _first_local_index
The first sample-vector index from the global vector which is stored in the _training_parameters on t...
virtual void initialize_training_parameters(const RBParameters &mu_min, const RBParameters &mu_max, const unsigned int n_global_training_samples, const std::map< std::string, bool > &log_param_scale, const bool deterministic=true)
Initialize the parameter ranges and indicate whether deterministic or random training parameters shou...
void set_training_random_seed(int seed)
Set the seed that is used to randomly generate training parameters.
dof_id_type numeric_index_type
Definition: id_types.h:99
numeric_index_type _n_local_training_samples
RBConstructionBase(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
numeric_index_type get_last_local_training_index() const
Get the last local index of the training parameters.
numeric_index_type get_local_n_training_samples() const
Get the total number of training samples local to this processor.
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:52
numeric_index_type get_n_training_samples() const
Get the number of global training samples.
This class extends EigenSystem to allow a simple way of solving (standard or generalized) eigenvalue ...
void set_params_from_training_set(unsigned int global_index)
Set parameters to the RBParameters stored in index global_index of the global training set...
void set_deterministic_training_parameter_name(const std::string &name)
In some cases we only want to allow discrete parameter values, instead of parameters that may take an...
This class is part of the rbOOmit framework.
RBConstructionBase & operator=(RBConstructionBase &&)=delete
const std::string & get_deterministic_training_parameter_name() const
Get the name of the parameter that we will generate deterministic training parameters for...
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors...
RBParameters get_params_from_training_set(unsigned int global_index)
Return the RBParameters in index global_index of the global training set.
This class is part of the rbOOmit framework.
int _training_parameters_random_seed
If < 0, use std::time() * processor_id() to seed the random number generator for the training paramet...
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.
virtual void init_data()
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used...
numeric_index_type _n_global_training_samples
virtual void set_params_from_training_set_and_broadcast(unsigned int global_index)
Load the specified training parameter and then broadcast to all processors.
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.
virtual void clear()
Clear all the data structures associated with the system.