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

◆ Counts

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 117 of file reference_counter.h.

Constructor & Destructor Documentation

◆ RBParametrized()

libMesh::RBParametrized::RBParametrized ( )

Constructor.

Definition at line 37 of file rb_parametrized.C.

38  :
39  verbose_mode(false),
41 {
42  parameters.clear();
45 }

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

◆ ~RBParametrized()

libMesh::RBParametrized::~RBParametrized ( )
virtual

Destructor.

Definition at line 47 of file rb_parametrized.C.

48 {
49  this->clear();
50 }

References clear().

Member Function Documentation

◆ clear()

void libMesh::RBParametrized::clear ( )
virtual

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 106 of file reference_counter.C.

107 {
108  _enable_print_counter = false;
109  return;
110 }

References libMesh::ReferenceCounter::_enable_print_counter.

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

◆ enable_print_counter_info()

void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

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

Definition at line 100 of file reference_counter.C.

101 {
102  _enable_print_counter = true;
103  return;
104 }

References libMesh::ReferenceCounter::_enable_print_counter.

◆ get_closest_value()

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 433 of file rb_parametrized.C.

434 {
435  if (list_of_values.empty())
436  libmesh_error_msg("Error: list_of_values is empty.");
437 
438  Real min_distance = std::numeric_limits<Real>::max();
439  Real closest_val = 0.;
440  for (const auto & current_value : list_of_values)
441  {
442  Real distance = std::abs(value - current_value);
443  if (distance < min_distance)
444  {
445  min_distance = distance;
446  closest_val = current_value;
447  }
448  }
449 
450  return closest_val;
451 }

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

Referenced by is_value_in_list().

◆ get_discrete_parameter_values()

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 381 of file rb_parametrized.C.

382 {
384  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_discrete_parameter_values");
385 
387 }

References _discrete_parameter_values, and parameters_initialized.

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder(), get_n_discrete_params(), initialize_parameters(), print_discrete_parameter_values(), valid_params(), and write_discrete_parameter_values_to_file().

◆ get_info()

std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

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 (const auto & pr : _counts)
59  {
60  const std::string name(pr.first);
61  const unsigned int creations = pr.second.first;
62  const unsigned int destructions = pr.second.second;
63 
64  oss << "| " << name << " reference count information:\n"
65  << "| Creations: " << creations << '\n'
66  << "| Destructions: " << destructions << '\n';
67  }
68 
69  oss << " ---------------------------------------------------------------------------- \n";
70 
71  return oss.str();
72 
73 #else
74 
75  return "";
76 
77 #endif
78 }

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

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

◆ get_n_continuous_params()

unsigned int libMesh::RBParametrized::get_n_continuous_params ( ) const

Get the number of continuous parameters.

Definition at line 125 of file rb_parametrized.C.

126 {
128  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_n_continuous_params");
129 
131 
132  return static_cast<unsigned int>(get_n_params() - get_n_discrete_params());
133 }

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().

◆ get_n_discrete_params()

unsigned int libMesh::RBParametrized::get_n_discrete_params ( ) const

Get the number of discrete parameters.

Definition at line 135 of file rb_parametrized.C.

136 {
138  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_n_discrete_params");
139 
140  return cast_int<unsigned int>
142 }

References get_discrete_parameter_values(), and parameters_initialized.

Referenced by libMesh::RBDataSerialization::add_parameter_ranges_to_builder(), get_n_continuous_params(), and write_discrete_parameter_values_to_file().

◆ get_n_params()

unsigned int libMesh::RBParametrized::get_n_params ( ) const

Get the number of parameters.

Definition at line 115 of file rb_parametrized.C.

116 {
118  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_n_params");
119 
120  libmesh_assert_equal_to ( parameters_min.n_parameters(), parameters_max.n_parameters() );
121 
122  return parameters_min.n_parameters();
123 }

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::RBSCMConstruction::print_info(), libMesh::RBConstruction::print_info(), and valid_params().

◆ get_parameter_max()

Real libMesh::RBParametrized::get_parameter_max ( const std::string &  param_name) const

Get maximum allowable value of parameter param_name.

Definition at line 198 of file rb_parametrized.C.

199 {
201  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameter_max");
202 
203  return parameters_max.get_value(param_name);
204 }

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

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

◆ get_parameter_min()

Real libMesh::RBParametrized::get_parameter_min ( const std::string &  param_name) const

Get minimum allowable value of parameter param_name.

Definition at line 190 of file rb_parametrized.C.

191 {
193  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameter_min");
194 
195  return parameters_min.get_value(param_name);
196 }

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

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

◆ get_parameter_names()

std::set< std::string > libMesh::RBParametrized::get_parameter_names ( ) const

Get a set that stores the parameter names.

Definition at line 144 of file rb_parametrized.C.

145 {
147  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameter_names");
148 
149  std::set<std::string> parameter_names;
150  parameters_min.get_parameter_names(parameter_names);
151 
152  return parameter_names;
153 }

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

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

◆ get_parameters()

const RBParameters & libMesh::RBParametrized::get_parameters ( ) const

Get the current parameters.

Definition at line 166 of file rb_parametrized.C.

167 {
169  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_current_parameters");
170 
171  return parameters;
172 }

References parameters, and parameters_initialized.

Referenced by libMesh::TransientRBConstruction::add_scaled_mass_matrix(), 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().

◆ get_parameters_max()

const RBParameters & libMesh::RBParametrized::get_parameters_max ( ) const

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

Definition at line 182 of file rb_parametrized.C.

183 {
185  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameters_max");
186 
187  return parameters_max;
188 }

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().

◆ get_parameters_min()

const RBParameters & libMesh::RBParametrized::get_parameters_min ( ) const

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

Definition at line 174 of file rb_parametrized.C.

175 {
177  libmesh_error_msg("Error: parameters not initialized in RBParametrized::get_parameters_min");
178 
179  return parameters_min;
180 }

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().

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectedinherited

Increments the construction counter.

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

Definition at line 181 of file reference_counter.h.

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }

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

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectedinherited

Increments the destruction counter.

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

Definition at line 194 of file reference_counter.h.

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }

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

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

◆ initialize_parameters() [1/2]

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.

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  for (const auto & pr : mu_min_in)
74  {
75  const std::string & param_name = pr.first;
76  if (mu_min_in.get_value(param_name) > mu_max_in.get_value(param_name))
77  libmesh_error_msg(err_string);
78  }
79  }
80  }
81 
82  parameters_min = mu_min_in;
83  parameters_max = mu_max_in;
84 
85  // Add in min/max values due to the discrete parameters
86  for (const auto & pr : discrete_parameter_values)
87  {
88  if (pr.second.empty())
89  libmesh_error_msg("Error: List of discrete parameters for " << pr.first << " is empty.");
90 
91  Real min_val = *std::min_element(pr.second.begin(), pr.second.end());
92  Real max_val = *std::max_element(pr.second.begin(), pr.second.end());
93 
94  libmesh_assert_less_equal(min_val,max_val);
95 
96  parameters_min.set_value(pr.first, min_val);
97  parameters_max.set_value(pr.first, max_val);
98  }
99 
100  _discrete_parameter_values = discrete_parameter_values;
101 
102  parameters_initialized = true;
103 
104  // Initialize the current parameters to parameters_min
106 }

References _discrete_parameter_values, 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 libMesh::RBConstruction::enrich_basis_from_rhs_terms(), 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().

◆ initialize_parameters() [2/2]

void libMesh::RBParametrized::initialize_parameters ( const RBParametrized rb_parametrized)

Initialize the parameter ranges and set current_parameters.

Definition at line 108 of file rb_parametrized.C.

109 {
110  initialize_parameters(rb_parametrized.get_parameters_min(),
111  rb_parametrized.get_parameters_max(),
112  rb_parametrized.get_discrete_parameter_values());
113 }

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

◆ is_discrete_parameter()

bool libMesh::RBParametrized::is_discrete_parameter ( const std::string &  mu_name) const

Is parameter mu_name discrete?

Definition at line 373 of file rb_parametrized.C.

374 {
376  libmesh_error_msg("Error: parameters not initialized in RBParametrized::is_discrete_parameter");
377 
378  return (_discrete_parameter_values.find(mu_name) != _discrete_parameter_values.end());
379 }

References _discrete_parameter_values, and parameters_initialized.

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

◆ is_value_in_list()

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 453 of file rb_parametrized.C.

454 {
455  Real closest_value = get_closest_value(value, list_of_values);
456 
457  // Check if relative tolerance is satisfied
458  Real rel_error = std::abs(value - closest_value) / std::abs(value);
459  if (rel_error <= tol)
460  {
461  return true;
462  }
463 
464  // If relative tolerance isn't satisfied, we should still check an absolute
465  // error, since relative tolerance can be misleading if value is close to zero
466  Real abs_error = std::abs(value - closest_value);
467  return (abs_error <= tol);
468 }

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

Referenced by valid_params().

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 83 of file reference_counter.h.

84  { return _n_objects; }

References libMesh::ReferenceCounter::_n_objects.

◆ print_discrete_parameter_values()

void libMesh::RBParametrized::print_discrete_parameter_values ( ) const

Print out all the discrete parameter values.

Definition at line 389 of file rb_parametrized.C.

390 {
391  for (const auto & pr : get_discrete_parameter_values())
392  {
393  libMesh::out << "Discrete parameter " << pr.first << ", values: ";
394 
395  const std::vector<Real> & values = pr.second;
396  for (const auto & value : values)
397  libMesh::out << value << " ";
398  libMesh::out << std::endl;
399  }
400 }

References get_discrete_parameter_values(), libMesh::out, and value.

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

◆ print_info()

void libMesh::ReferenceCounter::print_info ( std::ostream &  out = libMesh::out)
staticinherited

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

Definition at line 87 of file reference_counter.C.

88 {
90  out_stream << ReferenceCounter::get_info();
91 }

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

◆ print_parameters()

void libMesh::RBParametrized::print_parameters ( ) const

Print the current parameters.

Definition at line 206 of file rb_parametrized.C.

207 {
209  libmesh_error_msg("Error: parameters not initialized in RBParametrized::print_current_parameters");
210 
211  get_parameters().print();
212 }

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

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

◆ read_discrete_parameter_values_from_file()

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 340 of file rb_parametrized.C.

343 {
344  // read in the discrete parameters, if we have any
345  std::ifstream check_if_file_exists(file_name.c_str());
346  if (check_if_file_exists.good())
347  {
348  // The reading mode: DECODE for binary, READ for ASCII
349  XdrMODE mode = read_binary_data ? DECODE : READ;
350 
351  // Read in the parameter ranges
352  Xdr discrete_parameter_values_in(file_name, mode);
353  unsigned int n_discrete_params;
354  discrete_parameter_values_in >> n_discrete_params;
355 
356  for (unsigned int i=0; i<n_discrete_params; i++)
357  {
358  std::string param_name;
359  discrete_parameter_values_in >> param_name;
360 
361  unsigned int n_discrete_values;
362  discrete_parameter_values_in >> n_discrete_values;
363 
364  std::vector<Real> discrete_values(n_discrete_values);
365  for (auto & val : discrete_values)
366  discrete_parameter_values_in >> val;
367 
368  discrete_parameter_values[param_name] = discrete_values;
369  }
370  }
371 }

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

Referenced by read_parameter_data_from_files().

◆ read_parameter_data_from_files()

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 284 of file rb_parametrized.C.

287 {
288  RBParameters param_min;
289  RBParameters param_max;
290  read_parameter_ranges_from_file(continuous_param_file_name,
291  read_binary_data,
292  param_min,
293  param_max);
294 
295  std::map<std::string, std::vector<Real>> discrete_parameter_values_in;
296  read_discrete_parameter_values_from_file(discrete_param_file_name,
297  read_binary_data,
298  discrete_parameter_values_in);
299 
300  initialize_parameters(param_min, param_max, discrete_parameter_values_in);
301 }

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().

◆ read_parameter_ranges_from_file()

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 303 of file rb_parametrized.C.

307 {
308  // The reading mode: DECODE for binary, READ for ASCII
309  XdrMODE mode = read_binary_data ? DECODE : READ;
310 
311  // Read in the parameter ranges
312  Xdr parameter_ranges_in(file_name, mode);
313  unsigned int n_continuous_params;
314  parameter_ranges_in >> n_continuous_params;
315 
316  for (unsigned int i=0; i<n_continuous_params; i++)
317  {
318  std::string param_name;
319  Real param_value;
320 
321  parameter_ranges_in >> param_name;
322  parameter_ranges_in >> param_value;
323 
324  param_min.set_value(param_name, param_value);
325  }
326  for (unsigned int i=0; i<n_continuous_params; i++)
327  {
328  std::string param_name;
329  Real param_value;
330 
331  parameter_ranges_in >> param_name;
332  parameter_ranges_in >> param_value;
333 
334  param_max.set_value(param_name, param_value);
335  }
336 
337  parameter_ranges_in.close();
338 }

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

Referenced by read_parameter_data_from_files().

◆ set_parameters()

void libMesh::RBParametrized::set_parameters ( const RBParameters params)

Set the current parameters to params.

Definition at line 155 of file rb_parametrized.C.

156 {
158  libmesh_error_msg("Error: parameters not initialized in RBParametrized::set_current_parameters");
159 
160  valid_params(params); // Terminates if params has the wrong number of parameters
161 
162  // Make a copy of params (default assignment operator just does memberwise copy, which is sufficient here)
163  this->parameters = params;
164 }

References parameters, parameters_initialized, and valid_params().

Referenced by 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(), and libMesh::RBEIMConstruction::truth_solve().

◆ valid_params()

bool libMesh::RBParametrized::valid_params ( const RBParameters params)
private

Helper function to check that params is valid.

Definition at line 402 of file rb_parametrized.C.

403 {
404  if (params.n_parameters() != get_n_params())
405  libmesh_error_msg("Error: Number of parameters don't match");
406 
407  else
408  {
409  bool valid = true;
410  for (const auto & pr : params)
411  {
412  const std::string & param_name = pr.first;
413  valid = valid && ( (get_parameter_min(param_name) <= params.get_value(param_name)) &&
414  (params.get_value(param_name) <= get_parameter_max(param_name)) );
415 
416  if (is_discrete_parameter(param_name))
417  {
418  // make sure params.get_value(param_name) is sufficiently close
419  // to one of the discrete parameter values
420  valid = valid && is_value_in_list(params.get_value(param_name),
421  get_discrete_parameter_values().find(param_name)->second,
422  TOLERANCE);
423  }
424  }
425 
426  if (!valid && verbose_mode)
427  libMesh::out << "Warning: parameter is outside parameter range" << std::endl;
428 
429  return valid;
430  }
431 }

References get_discrete_parameter_values(), get_n_params(), get_parameter_max(), get_parameter_min(), 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().

◆ write_discrete_parameter_values_to_file()

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 255 of file rb_parametrized.C.

257 {
258  // write out the discrete parameters, if we have any
259  if (get_n_discrete_params() > 0)
260  {
261  // The writing mode: ENCODE for binary, WRITE for ASCII
262  XdrMODE mode = write_binary_data ? ENCODE : WRITE;
263 
264  Xdr discrete_parameters_out(file_name, mode);
265  unsigned int n_discrete_params = get_n_discrete_params();
266  discrete_parameters_out << n_discrete_params;
267 
268  for (const auto & pr : get_discrete_parameter_values())
269  {
270  std::string param_name = pr.first;
271  unsigned int n_discrete_values = cast_int<unsigned int>
272  (pr.second.size());
273  discrete_parameters_out << param_name << n_discrete_values;
274 
275  for (unsigned int i=0; i<n_discrete_values; i++)
276  {
277  Real discrete_value = pr.second[i];
278  discrete_parameters_out << discrete_value;
279  }
280  }
281  }
282 }

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

Referenced by write_parameter_data_to_files().

◆ write_parameter_data_to_files()

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 214 of file rb_parametrized.C.

217 {
218  write_parameter_ranges_to_file(continuous_param_file_name, write_binary_data);
219  write_discrete_parameter_values_to_file(discrete_param_file_name, write_binary_data);
220 }

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().

◆ write_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 222 of file rb_parametrized.C.

224 {
225  // The writing mode: ENCODE for binary, WRITE for ASCII
226  XdrMODE mode = write_binary_data ? ENCODE : WRITE;
227 
228  // Write out the parameter ranges
229  Xdr parameter_ranges_out(file_name, mode);
230  unsigned int n_continuous_params = get_n_continuous_params();
231  parameter_ranges_out << n_continuous_params;
232 
233  for (const auto & pr : get_parameters_min())
234  {
235  std::string param_name = pr.first;
236  if (!is_discrete_parameter(param_name))
237  {
238  Real param_value = pr.second;
239  parameter_ranges_out << param_name << param_value;
240  }
241  }
242 
243  for (const auto & pr : get_parameters_max())
244  {
245  std::string param_name = pr.first;
246  if (!is_discrete_parameter(param_name))
247  {
248  Real param_value = pr.second;
249  parameter_ranges_out << param_name << param_value;
250  }
251  }
252  parameter_ranges_out.close();
253 }

References libMesh::Xdr::close(), libMesh::ENCODE, 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().

Member Data Documentation

◆ _counts

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

◆ _discrete_parameter_values

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().

◆ _enable_print_counter

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 141 of file reference_counter.h.

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

◆ _mutex

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

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 of file reference_counter.h.

◆ _n_objects

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 130 of file reference_counter.h.

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

◆ parameters

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().

◆ parameters_initialized

bool libMesh::RBParametrized::parameters_initialized
private

◆ parameters_max

RBParameters libMesh::RBParametrized::parameters_max
private

◆ parameters_min

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().

◆ verbose_mode

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:
libMesh::RBParametrized::get_parameters_min
const RBParameters & get_parameters_min() const
Get an RBParameters object that specifies the minimum allowable value for each parameter.
Definition: rb_parametrized.C:174
libMesh::RBParametrized::_discrete_parameter_values
std::map< std::string, std::vector< Real > > _discrete_parameter_values
Map that defines the allowable values of any discrete parameters.
Definition: rb_parametrized.h:235
libMesh::RBParameters::print
void print() const
Print the parameters.
Definition: rb_parameters.C:134
libMesh::RBParametrized::get_closest_value
static Real get_closest_value(Real value, const std::vector< Real > &list_of_values)
Definition: rb_parametrized.C:433
libMesh::RBParametrized::read_discrete_parameter_values_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.
Definition: rb_parametrized.C:340
libMesh::RBParametrized::get_n_params
unsigned int get_n_params() const
Get the number of parameters.
Definition: rb_parametrized.C:115
libMesh::RBParametrized::verbose_mode
bool verbose_mode
Public boolean to toggle verbose mode.
Definition: rb_parametrized.h:170
libMesh::RBParametrized::clear
virtual void clear()
Clear all the data structures associated with the system.
Definition: rb_parametrized.C:52
libMesh::ReferenceCounter::_counts
static Counts _counts
Actually holds the data.
Definition: reference_counter.h:122
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::ReferenceCounter::_n_objects
static Threads::atomic< unsigned int > _n_objects
The number of objects.
Definition: reference_counter.h:130
libMesh::WRITE
Definition: enum_xdr_mode.h:40
libMesh::RBParametrized::set_parameters
void set_parameters(const RBParameters &params)
Set the current parameters to params.
Definition: rb_parametrized.C:155
libMesh::RBParametrized::get_n_discrete_params
unsigned int get_n_discrete_params() const
Get the number of discrete parameters.
Definition: rb_parametrized.C:135
libMesh::ReferenceCounter::get_info
static std::string get_info()
Gets a string containing the reference information.
Definition: reference_counter.C:47
libMesh::RBParametrized::parameters_max
RBParameters parameters_max
Definition: rb_parametrized.h:230
libMesh::RBParameters::n_parameters
unsigned int n_parameters() const
Get the number of parameters that have been added.
Definition: rb_parameters.C:63
libMesh::RBParametrized::get_n_continuous_params
unsigned int get_n_continuous_params() const
Get the number of continuous parameters.
Definition: rb_parametrized.C:125
libMesh::RBParametrized::get_parameters_max
const RBParameters & get_parameters_max() const
Get an RBParameters object that specifies the maximum allowable value for each parameter.
Definition: rb_parametrized.C:182
libMesh::RBParametrized::get_parameters
const RBParameters & get_parameters() const
Get the current parameters.
Definition: rb_parametrized.C:166
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::RBParametrized::get_parameter_max
Real get_parameter_max(const std::string &param_name) const
Get maximum allowable value of parameter param_name.
Definition: rb_parametrized.C:198
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::XdrMODE
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:35
libMesh::DECODE
Definition: enum_xdr_mode.h:39
libMesh::Threads::spin_mtx
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:29
libMesh::RBParameters::set_value
void set_value(const std::string &param_name, Real value)
Set the value of the specified parameter.
Definition: rb_parameters.C:47
libMesh::RBParametrized::parameters_min
RBParameters parameters_min
Vectors that define the ranges (min and max) for the parameters.
Definition: rb_parametrized.h:229
libMesh::READ
Definition: enum_xdr_mode.h:41
libMesh::RBParametrized::write_discrete_parameter_values_to_file
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.
Definition: rb_parametrized.C:255
libMesh::RBParameters::get_parameter_names
void get_parameter_names(std::set< std::string > &param_names) const
Fill param_names with the names of the parameters.
Definition: rb_parameters.C:69
libMesh::Quality::valid
std::vector< ElemQuality > valid(const ElemType t)
Returns all valid quality metrics for element type t.
Definition: elem_quality.C:324
libMesh::ENCODE
Definition: enum_xdr_mode.h:38
distance
Real distance(const Point &p)
Definition: subdomains_ex3.C:50
libMesh::RBParametrized::initialize_parameters
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.
Definition: rb_parametrized.C:60
libMesh::RBParametrized::read_parameter_ranges_from_file
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.
Definition: rb_parametrized.C:303
libMesh::RBParametrized::parameters
RBParameters parameters
Vector storing the current parameters.
Definition: rb_parametrized.h:224
libMesh::RBParametrized::valid_params
bool valid_params(const RBParameters &params)
Helper function to check that params is valid.
Definition: rb_parametrized.C:402
value
static const bool value
Definition: xdr_io.C:56
libMesh::RBParametrized::get_discrete_parameter_values
const std::map< std::string, std::vector< Real > > & get_discrete_parameter_values() const
Get a const reference to the discrete parameter values.
Definition: rb_parametrized.C:381
libMesh::RBParametrized::parameters_initialized
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
Definition: rb_parametrized.h:219
libMesh::RBParameters::clear
void clear()
Clear this object.
Definition: rb_parameters.C:35
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::RBParametrized::is_value_in_list
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...
Definition: rb_parametrized.C:453
libMesh::ReferenceCounter::_enable_print_counter
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called.
Definition: reference_counter.h:141
libMesh::out
OStreamProxy out
libMesh::RBParametrized::write_parameter_ranges_to_file
void write_parameter_ranges_to_file(const std::string &file_name, const bool write_binary)
Write out the parameter ranges to file.
Definition: rb_parametrized.C:222
libMesh::RBParametrized::is_discrete_parameter
bool is_discrete_parameter(const std::string &mu_name) const
Is parameter mu_name discrete?
Definition: rb_parametrized.C:373
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::RBParameters::get_value
Real get_value(const std::string &param_name) const
Get the value of the specific parameter.
Definition: rb_parameters.C:41
libMesh::RBParametrized::get_parameter_min
Real get_parameter_min(const std::string &param_name) const
Get minimum allowable value of parameter param_name.
Definition: rb_parametrized.C:190