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/rb_parametrized.h"
25 #include "libmesh/rb_theta_expansion.h"
26 #include "libmesh/rb_theta.h"
27 
28 // libMesh includes
29 #include "libmesh/system.h"
30 #include "libmesh/numeric_vector.h"
31 #include "libmesh/linear_solver.h"
32 #include "libmesh/perf_log.h"
33 
34 // C++ includes
35 #include <set>
36 
37 namespace libMesh
38 {
39 
53 template<class Base>
54 class RBConstructionBase : public Base, public RBParametrized
55 {
56 public:
57 
63  const std::string & name,
64  const unsigned int number);
65 
69  virtual ~RBConstructionBase ();
70 
75 
79  sys_type & system () { return *this; }
80 
85  virtual void clear ();
86 
91 
96 
101 
106 
112  virtual void initialize_training_parameters(const RBParameters & mu_min,
113  const RBParameters & mu_max,
114  unsigned int n_training_parameters,
115  std::map<std::string, bool> log_param_scale,
116  bool deterministic=true);
117 
121  virtual void load_training_set(std::map<std::string, std::vector<Number>> & new_training_set);
122 
127  void broadcast_parameters(unsigned int proc_id);
128 
132  void set_training_random_seed(unsigned int seed);
133 
146  void set_deterministic_training_parameter_name(const std::string & name);
147 
151  const std::string & get_deterministic_training_parameter_name() const;
152 
156  void set_deterministic_training_parameter_repeats(unsigned int repeats);
157 
162 
163 protected:
164 
169  virtual void init_data ();
170 
174  RBParameters get_params_from_training_set(unsigned int index);
175 
179  void set_params_from_training_set(unsigned int index);
180 
184  virtual void set_params_from_training_set_and_broadcast(unsigned int index);
185 
192  std::pair<numeric_index_type, Real> & error_pair);
193 
197  static void generate_training_parameters_random(const Parallel::Communicator & communicator,
198  std::map<std::string, bool> log_param_scale,
199  std::map<std::string, NumericVector<Number> * > & training_parameters_in,
200  unsigned int n_training_samples_in,
201  const RBParameters & min_parameters,
202  const RBParameters & max_parameters,
204  bool serial_training_set=false);
205 
211  std::map<std::string, bool> log_param_scale,
212  std::map<std::string, NumericVector<Number> * > & training_parameters_in,
213  unsigned int n_training_samples_in,
214  const RBParameters & min_parameters,
215  const RBParameters & max_parameters,
216  bool serial_training_set=false);
217 
218 
219  //----------- PROTECTED DATA MEMBERS -----------//
220 
228 
235 
236 
237 private:
238 
244 
248  std::map<std::string, NumericVector<Number> * > training_parameters;
249 
257 
258 };
259 
260 } // namespace libMesh
261 
262 
263 #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:39
static void generate_training_parameters_random(const Parallel::Communicator &communicator, std::map< std::string, bool > log_param_scale, std::map< std::string, NumericVector< Number > * > &training_parameters_in, unsigned int n_training_samples_in, const RBParameters &min_parameters, const RBParameters &max_parameters, int training_parameters_random_seed=-1, bool serial_training_set=false)
Static helper function for generating a randomized set of parameters.
numeric_index_type get_local_n_training_samples() const
Get the total number of training samples local to this processor.
bool training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.
This is the EquationSystems class.
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
UniquePtr< NumericVector< Number > > inner_product_storage_vector
We keep an extra temporary vector that is useful for performing inner products (avoids unnecessary me...
void broadcast_parameters(unsigned int proc_id)
Broadcasts parameters on processor proc_id to all processors.
MPI_Comm communicator
Communicator object for talking with subsets of processors.
Definition: parallel.h:181
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...
The libMesh namespace provides an interface to certain functionality in the library.
virtual void set_params_from_training_set_and_broadcast(unsigned int index)
Load the specified training parameter and then broadcast to all processors.
numeric_index_type get_n_training_samples() const
Get the total number of training samples.
RBConstructionBase< Base > sys_type
The type of system.
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
void set_deterministic_training_parameter_repeats(unsigned int repeats)
Set the number of times each sample of the deterministic training parameter is repeated.
unsigned int get_deterministic_training_parameter_repeats() const
Get the number of times each sample of the deterministic training parameter is repeated.
dof_id_type numeric_index_type
Definition: id_types.h:92
void set_params_from_training_set(unsigned int index)
Set parameters to the RBParameters stored in index index of the training set.
RBConstructionBase(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
virtual void initialize_training_parameters(const RBParameters &mu_min, const RBParameters &mu_max, unsigned int n_training_parameters, std::map< std::string, bool > log_param_scale, bool deterministic=true)
Initialize the parameter ranges and indicate whether deterministic or random training parameters shou...
std::map< std::string, NumericVector< Number > * > training_parameters
The training samples.
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:42
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...
numeric_index_type get_first_local_training_index() const
Get the first local index of the training parameters.
void set_training_random_seed(unsigned int seed)
Set the seed that is used to randomly generate training parameters.
RBParameters get_params_from_training_set(unsigned int index)
Return the RBParameters in index index of training set.
This class is part of the rbOOmit framework.
numeric_index_type get_last_local_training_index() const
Get the last local index of the training parameters.
virtual ~RBConstructionBase()
Destructor.
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...
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...
virtual void init_data()
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used...
virtual void load_training_set(std::map< std::string, std::vector< Number >> &new_training_set)
Overwrite the training parameters with new_training_set.
virtual void clear()
Clear all the data structures associated with the system.
static void generate_training_parameters_deterministic(const Parallel::Communicator &communicator, std::map< std::string, bool > log_param_scale, std::map< std::string, NumericVector< Number > * > &training_parameters_in, unsigned int n_training_samples_in, const RBParameters &min_parameters, const RBParameters &max_parameters, bool serial_training_set=false)
Static helper function for generating a deterministic set of parameters.