libMesh
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Static Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
libMesh::RBParametrized Class Reference

This class is part of the rbOOmit framework. More...

#include <rb_parametrized.h>

Inheritance diagram for libMesh::RBParametrized:
[legend]

Public Member Functions

 RBParametrized ()
 Constructor. More...
 
virtual ~RBParametrized ()
 Destructor. More...
 
virtual void clear ()
 Clear all the data structures associated with the system. More...
 
void initialize_parameters (const RBParameters &mu_min_in, const RBParameters &mu_max_in, const std::map< std::string, std::vector< Real >> &discrete_parameter_values)
 Initialize the parameter ranges and set current_parameters. More...
 
void initialize_parameters (const RBParametrized &rb_parametrized)
 Initialize the parameter ranges and set current_parameters. More...
 
unsigned int get_n_params () const
 Get the number of parameters. More...
 
unsigned int get_n_continuous_params () const
 Get the number of continuous parameters. More...
 
unsigned int get_n_discrete_params () const
 Get the number of discrete parameters. More...
 
std::set< std::string > get_parameter_names () const
 Get a set that stores the parameter names. More...
 
const RBParametersget_parameters () const
 Get the current parameters. More...
 
void set_parameters (const RBParameters &params)
 Set the current parameters to params. More...
 
const RBParametersget_parameters_min () const
 Get an RBParameters object that specifies the minimum allowable value for each parameter. More...
 
const RBParametersget_parameters_max () const
 Get an RBParameters object that specifies the maximum allowable value for each parameter. More...
 
Real get_parameter_min (const std::string &param_name) const
 Get minimum allowable value of parameter param_name. More...
 
Real get_parameter_max (const std::string &param_name) const
 Get maximum allowable value of parameter param_name. More...
 
void print_parameters () const
 Print the current parameters. More...
 
void write_parameter_data_to_files (const std::string &continuous_param_file_name, const std::string &discrete_param_file_name, const bool write_binary_data)
 Write out the parameter ranges to files. More...
 
void read_parameter_data_from_files (const std::string &continuous_param_file_name, const std::string &discrete_param_file_name, const bool read_binary_data)
 Read in the parameter ranges from files. More...
 
bool is_discrete_parameter (const std::string &mu_name) const
 Is parameter mu_name discrete? More...
 
const std::map< std::string, std::vector< Real > > & get_discrete_parameter_values () const
 Get a const reference to the discrete parameter values. More...
 
void print_discrete_parameter_values () const
 Print out all the discrete parameter values. More...
 

Static Public Member Functions

static Real get_closest_value (Real value, const std::vector< Real > &list_of_values)
 
static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Public Attributes

bool verbose_mode
 Public boolean to toggle verbose mode. More...
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

void increment_constructor_count (const std::string &name)
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name)
 Increments the destruction counter. More...
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int_n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter = true
 Flag to control whether reference count information is printed when print_info is called. More...
 

Private Member Functions

void write_parameter_ranges_to_file (const std::string &file_name, const bool write_binary)
 Write out the parameter ranges to file. More...
 
void write_discrete_parameter_values_to_file (const std::string &file_name, const bool write_binary_data)
 Write out the discrete parameter values to file. More...
 
void read_parameter_ranges_from_file (const std::string &file_name, const bool read_binary, RBParameters &param_min, RBParameters &param_max)
 Read in the parameter ranges from file. More...
 
void read_discrete_parameter_values_from_file (const std::string &file_name, const bool read_binary_data, std::map< std::string, std::vector< Real >> &discrete_parameter_values_in)
 Read in the discrete parameter values from file, if we have any. More...
 
bool valid_params (const RBParameters &params)
 Helper function to check that params is valid. More...
 

Static Private Member Functions

static bool is_value_in_list (Real value, const std::vector< Real > &list_of_values, Real tol)
 Helper function to check if the specified value is in the list of values (within a tolerance given by tol). More...
 

Private Attributes

bool parameters_initialized
 Flag indicating whether the parameters have been initialized. More...
 
RBParameters parameters
 Vector storing the current parameters. More...
 
RBParameters parameters_min
 Vectors that define the ranges (min and max) for the parameters. More...
 
RBParameters parameters_max
 
std::map< std::string, std::vector< Real > > _discrete_parameter_values
 Map that defines the allowable values of any discrete parameters. More...
 

Detailed Description

This class is part of the rbOOmit framework.

This class defines basic functionality of a parametrized object.

Author
David J. Knezevic
Date
2011

Definition at line 44 of file rb_parametrized.h.

Member Typedef Documentation

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 119 of file reference_counter.h.

Constructor & Destructor Documentation

libMesh::RBParametrized::RBParametrized ( )

Constructor.

Definition at line 37 of file rb_parametrized.C.

References libMesh::RBParameters::clear(), parameters, parameters_max, and parameters_min.

38  :
39  verbose_mode(false),
41 {
42  parameters.clear();
45 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
RBParameters parameters_min
Vectors that define the ranges (min and max) for the parameters.
bool verbose_mode
Public boolean to toggle verbose mode.
void clear()
Clear this object.
Definition: rb_parameters.C:40
RBParameters parameters
Vector storing the current parameters.
libMesh::RBParametrized::~RBParametrized ( )
virtual

Destructor.

Definition at line 47 of file rb_parametrized.C.

References clear().

48 {
49  this->clear();
50 }
virtual void clear()
Clear all the data structures associated with the system.

Member Function Documentation

void libMesh::RBParametrized::clear ( )
virtual

Clear all the data structures associated with the system.

Reimplemented in libMesh::RBConstruction, libMesh::RBConstructionBase< Base >, libMesh::RBConstructionBase< LinearImplicitSystem >, libMesh::RBConstructionBase< CondensedEigenSystem >, libMesh::RBSCMConstruction, libMesh::TransientSystem< RBConstruction >, libMesh::RBEIMConstruction, libMesh::TransientRBConstruction, libMesh::RBEIMEvaluation, libMesh::TransientRBEvaluation, and libMesh::RBEvaluation.

Definition at line 52 of file rb_parametrized.C.

References libMesh::RBParameters::clear(), parameters, parameters_initialized, parameters_max, and parameters_min.

Referenced by libMesh::RBConstructionBase< Base >::clear(), and ~RBParametrized().

53 {
54  parameters.clear();
57  parameters_initialized = false;
58 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
RBParameters parameters_min
Vectors that define the ranges (min and max) for the parameters.
void clear()
Clear this object.
Definition: rb_parameters.C:40
RBParameters parameters
Vector storing the current parameters.
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 107 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::LibMeshInit::LibMeshInit(), and libMesh::ReferenceCounter::n_objects().

108 {
109  _enable_print_counter = false;
110  return;
111 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

Definition at line 101 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

Referenced by libMesh::ReferenceCounter::n_objects().

102 {
103  _enable_print_counter = true;
104  return;
105 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
Real libMesh::RBParametrized::get_closest_value ( Real  value,
const std::vector< Real > &  list_of_values 
)
static
Returns
The closest entry to value from list_of_values.

Definition at line 464 of file rb_parametrized.C.

References std::abs(), distance(), std::max(), and libMesh::Real.

Referenced by libMesh::RBConstructionBase< Base >::initialize_training_parameters(), and is_value_in_list().

465 {
466  if (list_of_values.empty())
467  libmesh_error_msg("Error: list_of_values is empty.");
468 
469  std::vector<Real>::const_iterator it = list_of_values.begin();
470  std::vector<Real>::const_iterator it_end = list_of_values.end();
471 
472  Real min_distance = std::numeric_limits<Real>::max();
473  Real closest_val = 0.;
474  for ( ; it != it_end; ++it)
475  {
476  Real distance = std::abs(value - *it);
477  if (distance < min_distance)
478  {
479  min_distance = distance;
480  closest_val = *it;
481  }
482  }
483 
484  return closest_val;
485 }
double abs(double a)
long double max(long double a, double b)
Real distance(const Point &p)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const bool value
Definition: xdr_io.C:108
const std::map< std::string, std::vector< Real > > & libMesh::RBParametrized::get_discrete_parameter_values ( ) const

Get a const reference to the discrete parameter values.

Definition at line 403 of file rb_parametrized.C.

References _discrete_parameter_values, and parameters_initialized.

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder(), get_n_discrete_params(), initialize_parameters(), libMesh::RBConstructionBase< Base >::initialize_training_parameters(), print_discrete_parameter_values(), valid_params(), and write_discrete_parameter_values_to_file().

404 {
406  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_discrete_parameter_values");
407 
409 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
std::map< std::string, std::vector< Real > > _discrete_parameter_values
Map that defines the allowable values of any discrete parameters.
std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

References libMesh::ReferenceCounter::_counts, and libMesh::Quality::name().

Referenced by libMesh::ReferenceCounter::print_info().

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (Counts::iterator it = _counts.begin();
59  it != _counts.end(); ++it)
60  {
61  const std::string name(it->first);
62  const unsigned int creations = it->second.first;
63  const unsigned int destructions = it->second.second;
64 
65  oss << "| " << name << " reference count information:\n"
66  << "| Creations: " << creations << '\n'
67  << "| Destructions: " << destructions << '\n';
68  }
69 
70  oss << " ---------------------------------------------------------------------------- \n";
71 
72  return oss.str();
73 
74 #else
75 
76  return "";
77 
78 #endif
79 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
static Counts _counts
Actually holds the data.
unsigned int libMesh::RBParametrized::get_n_continuous_params ( ) const

Get the number of continuous parameters.

Definition at line 133 of file rb_parametrized.C.

References get_n_discrete_params(), get_n_params(), libMesh::libmesh_assert(), and parameters_initialized.

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder(), and write_parameter_ranges_to_file().

134 {
136  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_n_continuous_params");
137 
139 
140  return static_cast<unsigned int>(get_n_params() - get_n_discrete_params());
141 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
unsigned int get_n_params() const
Get the number of parameters.
libmesh_assert(j)
unsigned int get_n_discrete_params() const
Get the number of discrete parameters.
unsigned int libMesh::RBParametrized::get_n_discrete_params ( ) const

Get the number of discrete parameters.

Definition at line 143 of file rb_parametrized.C.

References get_discrete_parameter_values(), and parameters_initialized.

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder(), get_n_continuous_params(), libMesh::RBConstructionBase< Base >::initialize_training_parameters(), and write_discrete_parameter_values_to_file().

144 {
146  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_n_discrete_params");
147 
148  return cast_int<unsigned int>
150 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
const std::map< std::string, std::vector< Real > > & get_discrete_parameter_values() const
Get a const reference to the discrete parameter values.
unsigned int libMesh::RBParametrized::get_n_params ( ) const

Get the number of parameters.

Definition at line 123 of file rb_parametrized.C.

References libMesh::RBParameters::n_parameters(), parameters_initialized, parameters_max, and parameters_min.

Referenced by libMesh::RBConstruction::compute_max_error_bound(), libMesh::RBEIMTheta::evaluate(), get_n_continuous_params(), libMesh::RBConstructionBase< Base >::load_training_set(), libMesh::RBSCMConstruction::print_info(), libMesh::RBConstruction::print_info(), and valid_params().

124 {
126  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_n_params");
127 
128  libmesh_assert_equal_to ( parameters_min.n_parameters(), parameters_max.n_parameters() );
129 
130  return parameters_min.n_parameters();
131 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
unsigned int n_parameters() const
Get the number of parameters that have been added.
Definition: rb_parameters.C:62
RBParameters parameters_min
Vectors that define the ranges (min and max) for the parameters.
Real libMesh::RBParametrized::get_parameter_max ( const std::string &  param_name) const

Get maximum allowable value of parameter param_name.

Definition at line 206 of file rb_parametrized.C.

References libMesh::RBParameters::get_value(), parameters_initialized, and parameters_max.

Referenced by libMesh::RBSCMConstruction::print_info(), libMesh::RBConstruction::print_info(), and valid_params().

207 {
209  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameter_max");
210 
211  return parameters_max.get_value(param_name);
212 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
Real get_value(const std::string &param_name) const
Get the value of the specific parameter.
Definition: rb_parameters.C:45
Real libMesh::RBParametrized::get_parameter_min ( const std::string &  param_name) const

Get minimum allowable value of parameter param_name.

Definition at line 198 of file rb_parametrized.C.

References libMesh::RBParameters::get_value(), parameters_initialized, and parameters_min.

Referenced by libMesh::RBSCMConstruction::print_info(), libMesh::RBConstruction::print_info(), and valid_params().

199 {
201  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameter_min");
202 
203  return parameters_min.get_value(param_name);
204 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
Real get_value(const std::string &param_name) const
Get the value of the specific parameter.
Definition: rb_parameters.C:45
RBParameters parameters_min
Vectors that define the ranges (min and max) for the parameters.
std::set< std::string > libMesh::RBParametrized::get_parameter_names ( ) const

Get a set that stores the parameter names.

Definition at line 152 of file rb_parametrized.C.

References libMesh::RBParameters::get_parameter_names(), parameters_initialized, and parameters_min.

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder().

153 {
155  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameter_names");
156 
157  std::set<std::string> parameter_names;
158  parameters_min.get_parameter_names(parameter_names);
159 
160  return parameter_names;
161 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
void get_parameter_names(std::set< std::string > &param_names) const
Fill param_names with the names of the parameters.
Definition: rb_parameters.C:68
RBParameters parameters_min
Vectors that define the ranges (min and max) for the parameters.
const RBParameters & libMesh::RBParametrized::get_parameters ( ) const

Get the current parameters.

Definition at line 174 of file rb_parametrized.C.

References parameters, and parameters_initialized.

Referenced by libMesh::TransientRBConstruction::add_scaled_mass_matrix(), libMesh::RBConstructionBase< Base >::broadcast_parameters(), libMesh::TransientRBEvaluation::cache_online_residual_terms(), libMesh::RBEIMConstruction::compute_best_fit_error(), libMesh::RBEvaluation::compute_residual_dual_norm(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::RBSCMConstruction::enrich_C_J(), libMesh::RBEIMConstruction::enrich_RB_space(), libMesh::RBEIMTheta::evaluate(), libMesh::RBEIMEvaluation::evaluate_parametrized_function(), libMesh::RBSCMConstruction::evaluate_stability_constant(), libMesh::RBConstruction::get_RB_error_bound(), libMesh::RBSCMEvaluation::get_SCM_LB(), libMesh::RBSCMEvaluation::get_SCM_UB(), SimpleRBEvaluation::get_stability_lower_bound(), libMesh::RBConstruction::greedy_termination_test(), libMesh::RBSCMEvaluation::legacy_read_offline_data_from_files(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::RBSCMConstruction::print_info(), libMesh::RBConstruction::print_info(), print_parameters(), libMesh::RBSCMConstruction::process_parameters_file(), libMesh::TransientRBEvaluation::rb_solve(), libMesh::RBEvaluation::rb_solve(), libMesh::RBEIMEvaluation::rb_solve(), libMesh::RBSCMEvaluation::save_current_parameters(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::TransientRBConstruction::truth_solve(), libMesh::RBEIMConstruction::truth_solve(), libMesh::RBConstruction::truth_solve(), libMesh::TransientRBEvaluation::uncached_compute_residual_dual_norm(), and libMesh::RBConstruction::update_greedy_param_list().

175 {
177  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_current_parameters");
178 
179  return parameters;
180 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
RBParameters parameters
Vector storing the current parameters.
const RBParameters & libMesh::RBParametrized::get_parameters_max ( ) const

Get an RBParameters object that specifies the maximum allowable value for each parameter.

Definition at line 190 of file rb_parametrized.C.

References parameters_initialized, and parameters_max.

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder(), initialize_parameters(), libMesh::RBSCMConstruction::process_parameters_file(), libMesh::RBConstruction::set_rb_construction_parameters(), and write_parameter_ranges_to_file().

191 {
193  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameters_max");
194 
195  return parameters_max;
196 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
const RBParameters & libMesh::RBParametrized::get_parameters_min ( ) const

Get an RBParameters object that specifies the minimum allowable value for each parameter.

Definition at line 182 of file rb_parametrized.C.

References parameters_initialized, and parameters_min.

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder(), initialize_parameters(), libMesh::RBSCMConstruction::process_parameters_file(), libMesh::RBConstruction::set_rb_construction_parameters(), and write_parameter_ranges_to_file().

183 {
185  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameters_min");
186 
187  return parameters_min;
188 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
RBParameters parameters_min
Vectors that define the ranges (min and max) for the parameters.
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
protectedinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 185 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

186 {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189 
190  p.first++;
191 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:29
static Counts _counts
Actually holds the data.
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
protectedinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 198 of file reference_counter.h.

References libMesh::ReferenceCounter::_counts, libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCounter::n_objects(), and libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

199 {
200  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
201  std::pair<unsigned int, unsigned int> & p = _counts[name];
202 
203  p.second++;
204 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:39
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:29
static Counts _counts
Actually holds the data.
void libMesh::RBParametrized::initialize_parameters ( const RBParameters mu_min_in,
const RBParameters mu_max_in,
const std::map< std::string, std::vector< Real >> &  discrete_parameter_values 
)

Initialize the parameter ranges and set current_parameters.

Definition at line 60 of file rb_parametrized.C.

References _discrete_parameter_values, libMesh::RBParameters::begin(), libMesh::RBParameters::end(), libMesh::RBParameters::get_value(), libMesh::RBParameters::n_parameters(), parameters_initialized, parameters_max, parameters_min, libMesh::Real, set_parameters(), and libMesh::RBParameters::set_value().

Referenced by initialize_parameters(), libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set(), libMesh::RBDataDeserialization::load_parameter_ranges(), libMesh::RBSCMConstruction::perform_SCM_greedy(), libMesh::RBSCMConstruction::process_parameters_file(), read_parameter_data_from_files(), libMesh::RBConstruction::set_rb_construction_parameters(), and libMesh::RBConstruction::train_reduced_basis().

63 {
64  // Check that the min/max vectors are valid
65  {
66  const std::string err_string = "Error: Invalid mu_min/mu_max in RBParameters constructor.";
67  bool valid_min_max = (mu_min_in.n_parameters() == mu_max_in.n_parameters());
68  if (!valid_min_max)
69  libmesh_error_msg(err_string);
70 
71  else
72  {
73  RBParameters::const_iterator it = mu_min_in.begin();
74  RBParameters::const_iterator it_end = mu_min_in.end();
75  for ( ; it != it_end; ++it)
76  {
77  std::string param_name = it->first;
78  if (mu_min_in.get_value(param_name) > mu_max_in.get_value(param_name))
79  libmesh_error_msg(err_string);
80  }
81  }
82  }
83 
84  parameters_min = mu_min_in;
85  parameters_max = mu_max_in;
86 
87  // Add in min/max values due to the discrete parameters
88  {
89  std::map<std::string, std::vector<Real>>::const_iterator it =
90  discrete_parameter_values.begin();
91  const std::map<std::string, std::vector<Real>>::const_iterator it_end =
92  discrete_parameter_values.end();
93  for ( ; it != it_end; ++it)
94  {
95  if (it->second.empty())
96  libmesh_error_msg("Error: List of discrete parameters for " << it->first << " is empty.");
97 
98  Real min_val = *std::min_element(it->second.begin(), it->second.end());
99  Real max_val = *std::max_element(it->second.begin(), it->second.end());
100 
101  libmesh_assert_less_equal(min_val,max_val);
102 
103  parameters_min.set_value(it->first, min_val);
104  parameters_max.set_value(it->first, max_val);
105  }
106 
107  _discrete_parameter_values = discrete_parameter_values;
108  }
109 
110  parameters_initialized = true;
111 
112  // Initialize the current parameters to parameters_min
114 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
RBParameters parameters_min
Vectors that define the ranges (min and max) for the parameters.
void set_parameters(const RBParameters &params)
Set the current parameters to params.
std::map< std::string, std::vector< Real > > _discrete_parameter_values
Map that defines the allowable values of any discrete parameters.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_value(const std::string &param_name, Real value)
Set the value of the specified parameter.
Definition: rb_parameters.C:57
const_iterator begin() const
Get a constant iterator to beginning of this RBParameters object.
Definition: rb_parameters.C:80
std::map< std::string, Real >::const_iterator const_iterator
Definition: rb_parameters.h:57
void libMesh::RBParametrized::initialize_parameters ( const RBParametrized rb_parametrized)

Initialize the parameter ranges and set current_parameters.

Definition at line 116 of file rb_parametrized.C.

References get_discrete_parameter_values(), get_parameters_max(), get_parameters_min(), and initialize_parameters().

117 {
118  initialize_parameters(rb_parametrized.get_parameters_min(),
119  rb_parametrized.get_parameters_max(),
120  rb_parametrized.get_discrete_parameter_values());
121 }
void initialize_parameters(const RBParameters &mu_min_in, const RBParameters &mu_max_in, const std::map< std::string, std::vector< Real >> &discrete_parameter_values)
Initialize the parameter ranges and set current_parameters.
bool libMesh::RBParametrized::is_discrete_parameter ( const std::string &  mu_name) const

Is parameter mu_name discrete?

Definition at line 395 of file rb_parametrized.C.

References _discrete_parameter_values, and parameters_initialized.

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder(), libMesh::RBConstructionBase< Base >::initialize_training_parameters(), libMesh::RBConstruction::print_info(), valid_params(), and write_parameter_ranges_to_file().

396 {
398  libmesh_error_msg("Error: parameters not initialized in RBParametrized::is_discrete_parameter");
399 
400  return (_discrete_parameter_values.find(mu_name) != _discrete_parameter_values.end());
401 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
std::map< std::string, std::vector< Real > > _discrete_parameter_values
Map that defines the allowable values of any discrete parameters.
bool libMesh::RBParametrized::is_value_in_list ( Real  value,
const std::vector< Real > &  list_of_values,
Real  tol 
)
staticprivate

Helper function to check if the specified value is in the list of values (within a tolerance given by tol).

Definition at line 487 of file rb_parametrized.C.

References std::abs(), get_closest_value(), and libMesh::Real.

Referenced by valid_params().

488 {
489  Real closest_value = get_closest_value(value, list_of_values);
490 
491  // Check if relative tolerance is satisfied
492  Real rel_error = std::abs(value - closest_value) / std::abs(value);
493  if (rel_error <= tol)
494  {
495  return true;
496  }
497 
498  // If relative tolerance isn't satisfied, we should still check an absolute
499  // error, since relative tolerance can be misleading if value is close to zero
500  Real abs_error = std::abs(value - closest_value);
501  return (abs_error <= tol);
502 }
double abs(double a)
static Real get_closest_value(Real value, const std::vector< Real > &list_of_values)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const bool value
Definition: xdr_io.C:108
static unsigned int libMesh::ReferenceCounter::n_objects ( )
staticinherited
void libMesh::RBParametrized::print_discrete_parameter_values ( ) const

Print out all the discrete parameter values.

Definition at line 411 of file rb_parametrized.C.

References get_discrete_parameter_values(), and libMesh::out.

Referenced by libMesh::RBSCMConstruction::print_info(), and libMesh::RBConstruction::print_info().

412 {
413  std::map<std::string, std::vector<Real>>::const_iterator it =
415  const std::map<std::string, std::vector<Real>>::const_iterator it_end =
417 
418  for ( ; it != it_end; ++it)
419  {
420  libMesh::out << "Discrete parameter " << it->first << ", values: ";
421 
422  std::vector<Real> values = it->second;
423  for (std::size_t i=0; i<values.size(); i++)
424  libMesh::out << values[i] << " ";
425  libMesh::out << std::endl;
426  }
427 }
OStreamProxy out
const std::map< std::string, std::vector< Real > > & get_discrete_parameter_values() const
Get a const reference to the discrete parameter values.
void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

Definition at line 88 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

Referenced by libMesh::LibMeshInit::LibMeshInit().

89 {
91  out_stream << ReferenceCounter::get_info();
92 }
static std::string get_info()
Gets a string containing the reference information.
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
void libMesh::RBParametrized::print_parameters ( ) const

Print the current parameters.

Definition at line 214 of file rb_parametrized.C.

References get_parameters(), parameters_initialized, and libMesh::RBParameters::print().

Referenced by libMesh::RBConstruction::train_reduced_basis().

215 {
217  libmesh_error_msg("Error: parameters not initialized in RBParametrized::print_current_parameters");
218 
219  get_parameters().print();
220 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
void print() const
Print the parameters.
const RBParameters & get_parameters() const
Get the current parameters.
void libMesh::RBParametrized::read_discrete_parameter_values_from_file ( const std::string &  file_name,
const bool  read_binary_data,
std::map< std::string, std::vector< Real >> &  discrete_parameter_values_in 
)
private

Read in the discrete parameter values from file, if we have any.

Definition at line 357 of file rb_parametrized.C.

References libMesh::DECODE, libMesh::READ, and libMesh::Real.

Referenced by read_parameter_data_from_files().

360 {
361  // read in the discrete parameters, if we have any
362  std::ifstream check_if_file_exists(file_name.c_str());
363  if (check_if_file_exists.good())
364  {
365  // The reading mode: DECODE for binary, READ for ASCII
366  XdrMODE mode = read_binary_data ? DECODE : READ;
367 
368  // Read in the parameter ranges
369  Xdr discrete_parameter_values_in(file_name, mode);
370  unsigned int n_discrete_params;
371  discrete_parameter_values_in >> n_discrete_params;
372 
373  for (unsigned int i=0; i<n_discrete_params; i++)
374  {
375  std::string param_name;
376  discrete_parameter_values_in >> param_name;
377 
378  unsigned int n_discrete_values;
379  discrete_parameter_values_in >> n_discrete_values;
380 
381  std::vector<Real> discrete_values(n_discrete_values);
382  for (std::size_t j=0; j<discrete_values.size(); j++)
383  {
384  Real param_value;
385  discrete_parameter_values_in >> param_value;
386 
387  discrete_values[j] = param_value;
388  }
389 
390  discrete_parameter_values[param_name] = discrete_values;
391  }
392  }
393 }
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:32
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void libMesh::RBParametrized::read_parameter_data_from_files ( const std::string &  continuous_param_file_name,
const std::string &  discrete_param_file_name,
const bool  read_binary_data 
)

Read in the parameter ranges from files.

Definition at line 301 of file rb_parametrized.C.

References initialize_parameters(), read_discrete_parameter_values_from_file(), and read_parameter_ranges_from_file().

Referenced by libMesh::RBEvaluation::legacy_read_offline_data_from_files(), and libMesh::RBSCMEvaluation::legacy_read_offline_data_from_files().

304 {
305  RBParameters param_min;
306  RBParameters param_max;
307  read_parameter_ranges_from_file(continuous_param_file_name,
308  read_binary_data,
309  param_min,
310  param_max);
311 
312  std::map<std::string, std::vector<Real>> discrete_parameter_values_in;
313  read_discrete_parameter_values_from_file(discrete_param_file_name,
314  read_binary_data,
315  discrete_parameter_values_in);
316 
317  initialize_parameters(param_min, param_max, discrete_parameter_values_in);
318 }
void read_parameter_ranges_from_file(const std::string &file_name, const bool read_binary, RBParameters &param_min, RBParameters &param_max)
Read in the parameter ranges from file.
void read_discrete_parameter_values_from_file(const std::string &file_name, const bool read_binary_data, std::map< std::string, std::vector< Real >> &discrete_parameter_values_in)
Read in the discrete parameter values from file, if we have any.
void initialize_parameters(const RBParameters &mu_min_in, const RBParameters &mu_max_in, const std::map< std::string, std::vector< Real >> &discrete_parameter_values)
Initialize the parameter ranges and set current_parameters.
void libMesh::RBParametrized::read_parameter_ranges_from_file ( const std::string &  file_name,
const bool  read_binary,
RBParameters param_min,
RBParameters param_max 
)
private

Read in the parameter ranges from file.

Initialize parameters to the "minimum" parameter values.

Definition at line 320 of file rb_parametrized.C.

References libMesh::Xdr::close(), libMesh::DECODE, libMesh::READ, libMesh::Real, and libMesh::RBParameters::set_value().

Referenced by read_parameter_data_from_files().

324 {
325  // The reading mode: DECODE for binary, READ for ASCII
326  XdrMODE mode = read_binary_data ? DECODE : READ;
327 
328  // Read in the parameter ranges
329  Xdr parameter_ranges_in(file_name, mode);
330  unsigned int n_continuous_params;
331  parameter_ranges_in >> n_continuous_params;
332 
333  for (unsigned int i=0; i<n_continuous_params; i++)
334  {
335  std::string param_name;
336  Real param_value;
337 
338  parameter_ranges_in >> param_name;
339  parameter_ranges_in >> param_value;
340 
341  param_min.set_value(param_name, param_value);
342  }
343  for (unsigned int i=0; i<n_continuous_params; i++)
344  {
345  std::string param_name;
346  Real param_value;
347 
348  parameter_ranges_in >> param_name;
349  parameter_ranges_in >> param_value;
350 
351  param_max.set_value(param_name, param_value);
352  }
353 
354  parameter_ranges_in.close();
355 }
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:32
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void libMesh::RBParametrized::set_parameters ( const RBParameters params)

Set the current parameters to params.

Definition at line 163 of file rb_parametrized.C.

References parameters, parameters_initialized, and valid_params().

Referenced by libMesh::RBConstructionBase< Base >::broadcast_parameters(), libMesh::RBEIMConstruction::compute_best_fit_error(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::RBEIMConstruction::enrich_RB_space(), libMesh::RBEIMTheta::evaluate(), libMesh::RBConstruction::get_RB_error_bound(), SimpleRBEvaluation::get_stability_lower_bound(), initialize_parameters(), libMesh::RBSCMEvaluation::reload_current_parameters(), libMesh::RBSCMEvaluation::set_current_parameters_from_C_J(), libMesh::RBConstructionBase< Base >::set_params_from_training_set(), and libMesh::RBEIMConstruction::truth_solve().

164 {
166  libmesh_error_msg("Error: parameters not initialized in RBParametrized::set_current_parameters");
167 
168  valid_params(params); // Terminates if params has the wrong number of parameters
169 
170  // Make a copy of params (default assignment operator just does memberwise copy, which is sufficient here)
171  this->parameters = params;
172 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
bool valid_params(const RBParameters &params)
Helper function to check that params is valid.
RBParameters parameters
Vector storing the current parameters.
bool libMesh::RBParametrized::valid_params ( const RBParameters params)
private

Helper function to check that params is valid.

Definition at line 429 of file rb_parametrized.C.

References libMesh::RBParameters::begin(), libMesh::RBParameters::end(), get_discrete_parameter_values(), get_n_params(), get_parameter_max(), get_parameter_min(), libMesh::RBParameters::get_value(), is_discrete_parameter(), is_value_in_list(), libMesh::RBParameters::n_parameters(), libMesh::out, libMesh::TOLERANCE, libMesh::Quality::valid(), and verbose_mode.

Referenced by set_parameters().

430 {
431  if (params.n_parameters() != get_n_params())
432  libmesh_error_msg("Error: Number of parameters don't match");
433 
434  else
435  {
436  bool valid = true;
437  RBParameters::const_iterator it = params.begin();
438  RBParameters::const_iterator it_end = params.end();
439  for ( ; it != it_end; ++it)
440  {
441  std::string param_name = it->first;
442  valid = valid && ( (get_parameter_min(param_name) <= params.get_value(param_name)) &&
443  (params.get_value(param_name) <= get_parameter_max(param_name)) );
444 
445  if (is_discrete_parameter(param_name))
446  {
447  // make sure params.get_value(param_name) is sufficiently close
448  // to one of the discrete parameter values
449  valid = valid && is_value_in_list(params.get_value(param_name),
450  get_discrete_parameter_values().find(param_name)->second,
451  TOLERANCE);
452  }
453  }
454 
455  if (!valid && verbose_mode)
456  {
457  libMesh::out << "Warning: parameter is outside parameter range" << std::endl;
458  }
459 
460  return valid;
461  }
462 }
unsigned int get_n_params() const
Get the number of parameters.
bool is_discrete_parameter(const std::string &mu_name) const
Is parameter mu_name discrete?
static const Real TOLERANCE
static bool is_value_in_list(Real value, const std::vector< Real > &list_of_values, Real tol)
Helper function to check if the specified value is in the list of values (within a tolerance given by...
Real get_parameter_max(const std::string &param_name) const
Get maximum allowable value of parameter param_name.
bool verbose_mode
Public boolean to toggle verbose mode.
OStreamProxy out
const std::map< std::string, std::vector< Real > > & get_discrete_parameter_values() const
Get a const reference to the discrete parameter values.
std::vector< ElemQuality > valid(const ElemType t)
Returns all valid quality metrics for element type t.
Definition: elem_quality.C:321
std::map< std::string, Real >::const_iterator const_iterator
Definition: rb_parameters.h:57
Real get_parameter_min(const std::string &param_name) const
Get minimum allowable value of parameter param_name.
void libMesh::RBParametrized::write_discrete_parameter_values_to_file ( const std::string &  file_name,
const bool  write_binary_data 
)
private

Write out the discrete parameter values to file.

Definition at line 268 of file rb_parametrized.C.

References libMesh::ENCODE, get_discrete_parameter_values(), get_n_discrete_params(), libMesh::Real, and libMesh::WRITE.

Referenced by write_parameter_data_to_files().

270 {
271  // write out the discrete parameters, if we have any
272  if (get_n_discrete_params() > 0)
273  {
274  // The writing mode: ENCODE for binary, WRITE for ASCII
275  XdrMODE mode = write_binary_data ? ENCODE : WRITE;
276 
277  Xdr discrete_parameters_out(file_name, mode);
278  unsigned int n_discrete_params = get_n_discrete_params();
279  discrete_parameters_out << n_discrete_params;
280 
281  std::map<std::string, std::vector<Real>>::const_iterator discrete_it =
283  const std::map<std::string, std::vector<Real>>::const_iterator discrete_it_end =
285  for ( ; discrete_it != discrete_it_end; ++discrete_it)
286  {
287  std::string param_name = discrete_it->first;
288  unsigned int n_discrete_values = cast_int<unsigned int>
289  (discrete_it->second.size());
290  discrete_parameters_out << param_name << n_discrete_values;
291 
292  for (unsigned int i=0; i<n_discrete_values; i++)
293  {
294  Real discrete_value = discrete_it->second[i];
295  discrete_parameters_out << discrete_value;
296  }
297  }
298  }
299 }
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:32
unsigned int get_n_discrete_params() const
Get the number of discrete parameters.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::map< std::string, std::vector< Real > > & get_discrete_parameter_values() const
Get a const reference to the discrete parameter values.
void libMesh::RBParametrized::write_parameter_data_to_files ( const std::string &  continuous_param_file_name,
const std::string &  discrete_param_file_name,
const bool  write_binary_data 
)

Write out the parameter ranges to files.

Definition at line 222 of file rb_parametrized.C.

References write_discrete_parameter_values_to_file(), and write_parameter_ranges_to_file().

Referenced by libMesh::RBEvaluation::legacy_write_offline_data_to_files(), and libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files().

225 {
226  write_parameter_ranges_to_file(continuous_param_file_name, write_binary_data);
227  write_discrete_parameter_values_to_file(discrete_param_file_name, write_binary_data);
228 }
void write_discrete_parameter_values_to_file(const std::string &file_name, const bool write_binary_data)
Write out the discrete parameter values to file.
void write_parameter_ranges_to_file(const std::string &file_name, const bool write_binary)
Write out the parameter ranges to file.
void libMesh::RBParametrized::write_parameter_ranges_to_file ( const std::string &  file_name,
const bool  write_binary 
)
private

Write out the parameter ranges to file.

Definition at line 230 of file rb_parametrized.C.

References libMesh::RBParameters::begin(), libMesh::Xdr::close(), libMesh::ENCODE, libMesh::RBParameters::end(), get_n_continuous_params(), get_parameters_max(), get_parameters_min(), is_discrete_parameter(), libMesh::Real, and libMesh::WRITE.

Referenced by write_parameter_data_to_files().

232 {
233  // The writing mode: ENCODE for binary, WRITE for ASCII
234  XdrMODE mode = write_binary_data ? ENCODE : WRITE;
235 
236  // Write out the parameter ranges
237  Xdr parameter_ranges_out(file_name, mode);
238  unsigned int n_continuous_params = get_n_continuous_params();
239  parameter_ranges_out << n_continuous_params;
240 
243  it = get_parameters_min().begin();
244  it_end = get_parameters_min().end();
245  for ( ; it != it_end; ++it)
246  {
247  std::string param_name = it->first;
248  if (!is_discrete_parameter(param_name))
249  {
250  Real param_value = it->second;
251  parameter_ranges_out << param_name << param_value;
252  }
253  }
254  it = get_parameters_max().begin();
255  it_end = get_parameters_max().end();
256  for ( ; it != it_end; ++it)
257  {
258  std::string param_name = it->first;
259  if (!is_discrete_parameter(param_name))
260  {
261  Real param_value = it->second;
262  parameter_ranges_out << param_name << param_value;
263  }
264  }
265  parameter_ranges_out.close();
266 }
const RBParameters & get_parameters_max() const
Get an RBParameters object that specifies the maximum allowable value for each parameter.
bool is_discrete_parameter(const std::string &mu_name) const
Is parameter mu_name discrete?
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:32
const_iterator end() const
Get a constant iterator to the end of this RBParameters object.
Definition: rb_parameters.C:85
const RBParameters & get_parameters_min() const
Get an RBParameters object that specifies the minimum allowable value for each parameter.
unsigned int get_n_continuous_params() const
Get the number of continuous parameters.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const_iterator begin() const
Get a constant iterator to beginning of this RBParameters object.
Definition: rb_parameters.C:80
std::map< std::string, Real >::const_iterator const_iterator
Definition: rb_parameters.h:57

Member Data Documentation

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited
std::map<std::string, std::vector<Real> > libMesh::RBParametrized::_discrete_parameter_values
private

Map that defines the allowable values of any discrete parameters.

Definition at line 235 of file rb_parametrized.h.

Referenced by get_discrete_parameter_values(), initialize_parameters(), and is_discrete_parameter().

bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 143 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 137 of file reference_counter.h.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

Definition at line 132 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

RBParameters libMesh::RBParametrized::parameters
private

Vector storing the current parameters.

Definition at line 224 of file rb_parametrized.h.

Referenced by clear(), get_parameters(), RBParametrized(), and set_parameters().

bool libMesh::RBParametrized::parameters_initialized
private
RBParameters libMesh::RBParametrized::parameters_max
private
RBParameters libMesh::RBParametrized::parameters_min
private

Vectors that define the ranges (min and max) for the parameters.

Definition at line 229 of file rb_parametrized.h.

Referenced by clear(), get_n_params(), get_parameter_min(), get_parameter_names(), get_parameters_min(), initialize_parameters(), and RBParametrized().

bool libMesh::RBParametrized::verbose_mode

Public boolean to toggle verbose mode.

Definition at line 170 of file rb_parametrized.h.

Referenced by valid_params().


The documentation for this class was generated from the following files: