libMesh
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
libMesh::RBConstructionBase< Base > Class Template Reference

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

#include <rb_construction_base.h>

Inheritance diagram for libMesh::RBConstructionBase< Base >:
[legend]

Public Types

typedef RBConstructionBase< Base > sys_type
 The type of system. More...
 

Public Member Functions

 RBConstructionBase (EquationSystems &es, const std::string &name, const unsigned int number)
 Constructor. More...
 
 RBConstructionBase (RBConstructionBase &&)=default
 Special functions. More...
 
RBConstructionBaseoperator= (RBConstructionBase &&)=delete
 
 RBConstructionBase (const RBConstructionBase &)=delete
 
RBConstructionBaseoperator= (const RBConstructionBase &)=delete
 
virtual ~RBConstructionBase ()
 
sys_typesystem ()
 
virtual void clear ()
 Clear all the data structures associated with the system. More...
 
void set_quiet_mode (bool quiet_mode_in)
 Set the quiet_mode flag. More...
 
bool is_quiet () const
 Is the system in quiet mode? More...
 
void set_normalize_solution_snapshots (bool value)
 Set the boolean option that indicates if we normalization solution snapshots or not. More...
 
numeric_index_type get_n_training_samples () const
 Get the number of global training samples. More...
 
numeric_index_type get_local_n_training_samples () const
 Get the total number of training samples local to this processor. More...
 
numeric_index_type get_first_local_training_index () const
 Get the first local index of the training parameters. More...
 
numeric_index_type get_last_local_training_index () const
 Get the last local index of the training parameters. More...
 
virtual void initialize_training_parameters (const RBParameters &mu_min, const RBParameters &mu_max, const unsigned int n_global_training_samples, const std::map< std::string, bool > &log_param_scale, const bool deterministic=true)
 Initialize the parameter ranges and indicate whether deterministic or random training parameters should be used and whether or not we want the parameters to be scaled logarithmically. More...
 
virtual void load_training_set (const std::map< std::string, std::vector< RBParameter >> &new_training_set)
 Overwrite the training parameters with new_training_set. More...
 
void set_training_parameter_values (const std::string &param_name, const std::vector< RBParameter > &values)
 Overwrite the local training samples for param_name using values. More...
 
void broadcast_parameters (const unsigned int proc_id)
 Broadcasts parameters from processor proc_id to all processors. More...
 
void set_training_random_seed (int seed)
 Set the seed that is used to randomly generate training parameters. More...
 
void set_deterministic_training_parameter_name (const std::string &name)
 In some cases we only want to allow discrete parameter values, instead of parameters that may take any value in a specified interval. More...
 
const std::string & get_deterministic_training_parameter_name () const
 Get the name of the parameter that we will generate deterministic training parameters for. 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...
 
bool set_parameters (const RBParameters &params)
 Set the current parameters to params The parameters are checked for validity; an error is thrown if the number of parameters or samples is different than expected. 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 std::pair< std::size_t, std::size_t > generate_training_parameters_random (const Parallel::Communicator &communicator, const std::map< std::string, bool > &log_param_scale, std::map< std::string, std::vector< RBParameter >> &local_training_parameters_in, const unsigned int n_global_training_samples_in, const RBParameters &min_parameters, const RBParameters &max_parameters, const int training_parameters_random_seed=-1, const bool serial_training_set=false)
 Static helper function for generating a randomized set of parameters. More...
 
static std::pair< std::size_t, std::size_t > generate_training_parameters_deterministic (const Parallel::Communicator &communicator, const std::map< std::string, bool > &log_param_scale, std::map< std::string, std::vector< RBParameter >> &local_training_parameters_in, const unsigned int n_global_training_samples_in, const RBParameters &min_parameters, const RBParameters &max_parameters, const bool serial_training_set=false)
 Static helper function for generating a deterministic set of parameters. More...
 
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_stream=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

virtual void init_data ()
 Initializes the member data fields associated with the system, so that, e.g., assemble() may be used. More...
 
RBParameters get_params_from_training_set (unsigned int global_index)
 Return the RBParameters in index global_index of the global training set. More...
 
void set_params_from_training_set (unsigned int global_index)
 Set parameters to the RBParameters stored in index global_index of the global training set. More...
 
virtual void set_params_from_training_set_and_broadcast (unsigned int global_index)
 Load the specified training parameter and then broadcast to all processors. More...
 
void increment_constructor_count (const std::string &name) noexcept
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name) noexcept
 Increments the destruction counter. More...
 

Static Protected Member Functions

static void get_global_max_error_pair (const Parallel::Communicator &communicator, std::pair< numeric_index_type, Real > &error_pair)
 Static function to return the error pair (index,error) that is corresponds to the largest error on all processors. More...
 

Protected Attributes

bool quiet_mode
 Flag to indicate whether we print out extra information during the Offline stage. More...
 
bool serial_training_set
 This boolean flag indicates whether or not the training set should be the same on all processors. More...
 
bool _normalize_solution_snapshots
 Set this boolean to true if we want to normalize solution snapshots used in training to have norm of 1. More...
 
std::unique_ptr< NumericVector< Number > > inner_product_storage_vector
 We keep an extra temporary vector that is useful for performing inner products (avoids unnecessary memory allocation/deallocation). 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 Attributes

bool _training_parameters_initialized
 Boolean flag to indicate whether or not the parameter ranges have been initialized. More...
 
std::map< std::string, std::vector< RBParameter > > _training_parameters
 The training samples for each parameter. More...
 
numeric_index_type _first_local_index
 The first sample-vector index from the global vector which is stored in the _training_parameters on this processor. More...
 
numeric_index_type _n_local_training_samples
 
numeric_index_type _n_global_training_samples
 
int _training_parameters_random_seed
 If < 0, use std::time() * processor_id() to seed the random number generator for the training parameters (default). More...
 

Detailed Description

template<class Base>
class libMesh::RBConstructionBase< Base >

This class is part of the rbOOmit framework.

This is the base class for the Construction stage of the certified reduced basis (RB) method. We template the Base class so that we can derive from the appropriate libMesh System type (e.g. LinearImplicitSystem for standard reduced basis, EigenSystem for SCM) at compile time.

Author
David J. Knezevic
Date
2009

Definition at line 55 of file rb_construction_base.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 119 of file reference_counter.h.

◆ sys_type

template<class Base>
typedef RBConstructionBase<Base> libMesh::RBConstructionBase< Base >::sys_type

The type of system.

Definition at line 82 of file rb_construction_base.h.

Constructor & Destructor Documentation

◆ RBConstructionBase() [1/3]

template<class Base >
libMesh::RBConstructionBase< Base >::RBConstructionBase ( EquationSystems es,
const std::string &  name,
const unsigned int  number 
)

Constructor.

Definition at line 95 of file rb_construction_base.C.

98  : Base(es, name_in, number_in),
99  quiet_mode(true),
100  serial_training_set(false),
106  _training_parameters_random_seed(-1) // by default, use std::time to seed RNG
107 {
108 }
bool quiet_mode
Flag to indicate whether we print out extra information during the Offline stage. ...
bool _normalize_solution_snapshots
Set this boolean to true if we want to normalize solution snapshots used in training to have norm of ...
numeric_index_type _first_local_index
The first sample-vector index from the global vector which is stored in the _training_parameters on t...
numeric_index_type _n_local_training_samples
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors...
int _training_parameters_random_seed
If < 0, use std::time() * processor_id() to seed the random number generator for the training paramet...
numeric_index_type _n_global_training_samples
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.

◆ RBConstructionBase() [2/3]

template<class Base>
libMesh::RBConstructionBase< Base >::RBConstructionBase ( RBConstructionBase< Base > &&  )
default

Special functions.

  • This class has the same restrictions as the union of its potential base classes (currently LinearImplicitSystem and EigenSystem).
  • Destructor is defaulted out-of-line.

◆ RBConstructionBase() [3/3]

template<class Base>
libMesh::RBConstructionBase< Base >::RBConstructionBase ( const RBConstructionBase< Base > &  )
delete

◆ ~RBConstructionBase()

template<class Base >
libMesh::RBConstructionBase< Base >::~RBConstructionBase ( )
virtualdefault

Member Function Documentation

◆ broadcast_parameters()

template<class Base >
void libMesh::RBConstructionBase< Base >::broadcast_parameters ( const unsigned int  proc_id)

Broadcasts parameters from processor proc_id to all processors.

This broadcasts the RBParameters object from .get_parameters(), and then sets it on all processors with .set_parameters().

Definition at line 720 of file rb_construction_base.C.

721 {
722  libmesh_assert_less (proc_id, this->n_processors());
723 
724  // create a copy of the current parameters
725  RBParameters current_parameters = get_parameters();
726  libmesh_error_msg_if(current_parameters.n_samples()!=1,
727  "Only single-sample RBParameter objects can be broadcast.");
728 
729  // Serialize the current_parameters to current_parameters_vector in order to broadcast.
730  // We handle multiple samples and vector values.
731  // However, the vector values are assumed to remain the same size across samples.
732  const std::size_t nparams = current_parameters.n_parameters();
733  const std::size_t nsamples = current_parameters.n_samples();
734 
735  // First we get the sizes of all the parameter value vectors.
736  std::vector<std::size_t> param_value_sizes;
737  param_value_sizes.reserve(nparams);
738  for (const auto & pr : current_parameters)
739  param_value_sizes.push_back(pr.second[0].size());
740 
741  // Broadcast the sizes vector and reserve memory.
742  this->comm().broadcast(param_value_sizes, proc_id);
743  std::size_t buffsize = std::accumulate(param_value_sizes.cbegin(), param_value_sizes.cend(), 0ul);
744  std::vector<Real> serialized_parameters;
745  serialized_parameters.reserve(buffsize);
746 
747  // Then we serialize the parameters/sample/value vectors into a single vector.
748  for (const auto & pr : current_parameters)
749  {
750  for (const auto sample_idx : make_range(nsamples))
751  serialized_parameters.insert(serialized_parameters.end(),
752  pr.second[sample_idx].cbegin(),
753  pr.second[sample_idx].cend());
754  }
755 
756  // Do the broadcasts.
757  this->comm().broadcast(serialized_parameters, proc_id);
758 
759  // Deserialize into the copy of the RBParameters object.
760  std::size_t param_idx = 0;
761  auto val_idx = serialized_parameters.cbegin();
762  for (const auto & pr : current_parameters)
763  {
764  const std::size_t param_value_size = param_value_sizes[param_idx];
765  for (const auto sample_idx: make_range(nsamples))
766  {
767  auto end_val_idx = std::next(val_idx,param_value_size);
768  RBParameter sample_val(val_idx, end_val_idx);
769  current_parameters.set_value(pr.first, sample_idx, sample_val);
770  val_idx = end_val_idx;
771  }
772  ++param_idx;
773  }
774 
775  // Overwrite the parameters globally.
776  set_parameters(current_parameters);
777 }
std::vector< Real > RBParameter
Typedef for an individual RB parameter.
Definition: rb_parameters.h:39
const RBParameters & get_parameters() const
Get the current parameters.
bool set_parameters(const RBParameters &params)
Set the current parameters to params The parameters are checked for validity; an error is thrown if t...
static const unsigned int next[3]
A lookup table for the increment modulo 3 operation, for iterating through the three nodes per elemen...
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140

◆ clear()

template<class Base >
void libMesh::RBConstructionBase< Base >::clear ( )
virtual

Clear all the data structures associated with the system.

Reimplemented from libMesh::RBParametrized.

Reimplemented in libMesh::RBConstruction, libMesh::RBEIMConstruction, libMesh::TransientSystem< RBConstruction >, libMesh::RBSCMConstruction, and libMesh::TransientRBConstruction.

Definition at line 114 of file rb_construction_base.C.

Referenced by libMesh::RBEIMConstruction::clear().

115 {
116  // clear the parent data
117  Base::clear();
119  _training_parameters.clear();
120 }
virtual void clear()
Clear all the data structures associated with the system.
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = false;
103  return;
104 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ 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 94 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

95 {
96  _enable_print_counter = true;
97  return;
98 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ generate_training_parameters_deterministic()

template<class Base >
std::pair< std::size_t, std::size_t > libMesh::RBConstructionBase< Base >::generate_training_parameters_deterministic ( const Parallel::Communicator communicator,
const std::map< std::string, bool > &  log_param_scale,
std::map< std::string, std::vector< RBParameter >> &  local_training_parameters_in,
const unsigned int  n_global_training_samples_in,
const RBParameters min_parameters,
const RBParameters max_parameters,
const bool  serial_training_set = false 
)
static

Static helper function for generating a deterministic set of parameters.

Only works with 1 or 2 parameters (as defined by the lengths of min/max parameters vectors), otherwise throws an error. The parameter n_global_training_samples_in is the total number of parameters to generate, and they will be split across all the processors (unless serial_training_set=true) in the local_training_parameters_in map.

Returns
a pair of {first_local_index,last_local_index}

Definition at line 572 of file rb_construction_base.C.

579 {
580  libmesh_assert_equal_to ( min_parameters.n_parameters(), max_parameters.n_parameters() );
581  const unsigned int num_params = min_parameters.n_parameters();
582 
583  if (num_params == 0)
584  return {0,0};
585 
586  if (num_params > 3)
587  libmesh_not_implemented_msg("ERROR: Deterministic training sample generation "
588  "not implemented for more than three parameters.");
589 
590  // TODO - we don't support vector-data here yet. This would only apply in the case where
591  // min or max are vector-valued, and all the generated points need to stay within those ranges.
592  // But typically we expect that if we're calling this function, we only have 1 min and 1 max,
593  // so the generated values are single-valued as well. The .get_value() calls will throw an error
594  // if this is not the case.
595 
596  // Reinitialize training_parameters_in (but don't remove existing keys!)
597  const auto &[n_local_training_samples, first_local_index] =
598  calculate_n_local_samples_and_index(communicator, n_global_training_samples_in,
600  const auto last_local_index = first_local_index + n_local_training_samples;
601  for (const auto & pr : min_parameters)
602  local_training_parameters_in[pr.first] = std::vector<RBParameter>(n_local_training_samples);
603 
604  // n_training_samples_per_param has 3 entries, but entries after "num_params"
605  // are unused so we just set their value to 1. We need to set it to 1 (rather
606  // than 0) so that we don't skip the inner part of the triply-nested loop over
607  // n_training_samples_per_param below.
608  std::vector<unsigned int> n_training_samples_per_param(3);
609  for (unsigned int param=0; param<3; param++)
610  {
611  if (param < num_params)
612  {
613  n_training_samples_per_param[param] =
614  static_cast<unsigned int>( std::round(std::pow(static_cast<Real>(n_global_training_samples_in), 1./num_params)) );
615  }
616  else
617  {
618  n_training_samples_per_param[param] = 1;
619  }
620  }
621 
622  {
623  // The current implementation assumes that we have the same number of
624  // samples in each parameter, so we check that n_training_samples_in
625  // is consistent with this assumption.
626  unsigned int total_samples_check = 1;
627  for (unsigned int n_samples : n_training_samples_per_param)
628  {
629  total_samples_check *= n_samples;
630  }
631 
632  libmesh_error_msg_if(total_samples_check != n_global_training_samples_in,
633  "Error: Number of training samples = "
634  << n_global_training_samples_in
635  << " does not enable a uniform grid of samples with "
636  << num_params << " parameters. Try "
637  << total_samples_check << " samples instead?");
638  }
639 
640  // First we make a list of training samples associated with each parameter,
641  // then we take a tensor product to obtain the final set of training samples.
642  std::vector<std::vector<Real>> training_samples_per_param(num_params);
643  {
644  unsigned int i = 0;
645  for (const auto & pr : min_parameters)
646  {
647  const std::string & param_name = pr.first;
648  const bool use_log_scaling = libmesh_map_find(log_param_scale, param_name);
649  Real min_param = min_parameters.get_value(param_name);
650  Real max_param = max_parameters.get_value(param_name);
651 
652  training_samples_per_param[i].resize(n_training_samples_per_param[i]);
653 
654  for (unsigned int j=0; j<n_training_samples_per_param[i]; j++)
655  {
656  // Generate log10 scaled training parameters
657  if (use_log_scaling)
658  {
659  Real epsilon = 1.e-6; // Prevent rounding errors triggering asserts
660  Real log_min = std::log10(min_param + epsilon);
661  Real log_range = std::log10( (max_param-epsilon) / (min_param+epsilon) );
662  Real step_size = log_range /
663  std::max((unsigned int)1,(n_training_samples_per_param[i]-1));
664 
665  if (j<(n_training_samples_per_param[i]-1))
666  {
667  training_samples_per_param[i][j] = std::pow(10., log_min + j*step_size );
668  }
669  else
670  {
671  // due to rounding error, the last parameter can be slightly
672  // bigger than max_parameters, hence snap back to the max
673  training_samples_per_param[i][j] = max_param;
674  }
675  }
676  else
677  {
678  // Generate linearly scaled training parameters
679  Real step_size = (max_param - min_param) /
680  std::max((unsigned int)1,(n_training_samples_per_param[i]-1));
681  training_samples_per_param[i][j] = j*step_size + min_param;
682  }
683 
684  }
685  i++;
686  }
687  }
688 
689  // Now load into training_samples_in
690  {
691  std::vector<unsigned int> indices(3);
692  unsigned int index_count = 0;
693  for (indices[0]=0; indices[0]<n_training_samples_per_param[0]; indices[0]++)
694  {
695  for (indices[1]=0; indices[1]<n_training_samples_per_param[1]; indices[1]++)
696  {
697  for (indices[2]=0; indices[2]<n_training_samples_per_param[2]; indices[2]++)
698  {
699  unsigned int param_count = 0;
700  for (const auto & pr : min_parameters)
701  {
702  std::vector<RBParameter> & training_vector =
703  libmesh_map_find(local_training_parameters_in, pr.first);
704  if (first_local_index <= index_count && index_count < last_local_index)
705  training_vector[index_count - first_local_index] =
706  {training_samples_per_param[param_count][indices[param_count]]};
707 
708  param_count++;
709  }
710  index_count++;
711  }
712  }
713  }
714  }
715  return {first_local_index, first_local_index+n_local_training_samples};
716 }
T pow(const T &x)
Definition: utility.h:328
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors...

◆ generate_training_parameters_random()

template<class Base >
std::pair< std::size_t, std::size_t > libMesh::RBConstructionBase< Base >::generate_training_parameters_random ( const Parallel::Communicator communicator,
const std::map< std::string, bool > &  log_param_scale,
std::map< std::string, std::vector< RBParameter >> &  local_training_parameters_in,
const unsigned int  n_global_training_samples_in,
const RBParameters min_parameters,
const RBParameters max_parameters,
const int  training_parameters_random_seed = -1,
const bool  serial_training_set = false 
)
static

Static helper function for generating a randomized set of parameters.

The parameter n_global_training_samples_in is the total number of parameters to generate, and they will be split across all the processors (unless serial_training_set=true) in the local_training_parameters_in map.

Returns
a pair of {first_local_index,last_local_index}

Definition at line 472 of file rb_construction_base.C.

480 {
481  const unsigned int num_params = min_parameters.n_parameters();
482  libmesh_error_msg_if(num_params!=max_parameters.n_parameters(),
483  "Number of parameters must be identical for min/max.");
484 
485  // Clear training_parameters_in
486  local_training_parameters_in.clear();
487 
488  if (num_params == 0)
489  return {0,0};
490 
491  if (training_parameters_random_seed < 0)
492  {
493  if (!serial_training_set)
494  {
495  // seed the random number generator with the system time
496  // and the processor ID so that the seed is different
497  // on different processors
498  std::srand( static_cast<unsigned>( std::time(0)*(1+communicator.rank()) ));
499  }
500  else
501  {
502  // seed the random number generator with the system time
503  // only so that the seed is the same on all processors
504  //
505  // Note that we broadcast the time on processor 0 to make
506  // sure all processors agree.
507  unsigned int current_time = static_cast<unsigned>( std::time(0) );
508  communicator.broadcast(current_time, 0);
509  std::srand(current_time);
510  }
511  }
512  else
513  {
514  if (!serial_training_set)
515  {
516  // seed the random number generator with the provided value
517  // and the processor ID so that the seed is different
518  // on different processors
519  std::srand( static_cast<unsigned>( training_parameters_random_seed*(1+communicator.rank()) ));
520  }
521  else
522  {
523  // seed the random number generator with the provided value
524  // so that the seed is the same on all processors
525  std::srand( static_cast<unsigned>( training_parameters_random_seed ));
526  }
527  }
528 
529  // TODO - we don't support vector-data here yet. This would only apply in the case where
530  // min or max are vector-valued, and all the generated points need to stay within those ranges.
531  // But typically we expect that if we're calling this function, we only have 1 min and 1 max,
532  // so the generated values are single-valued as well. The .get_value() calls will throw an error
533  // if this is not the case.
534 
535  // initialize training_parameters_in
536  const auto & [n_local_training_samples, first_local_index] =
537  calculate_n_local_samples_and_index(communicator, n_global_training_samples_in,
539  for (const auto & pr : min_parameters)
540  local_training_parameters_in[pr.first] = std::vector<RBParameter>(n_local_training_samples);
541 
542  // finally, set the values
543  for (auto & [param_name, sample_vector] : local_training_parameters_in)
544  {
545  for (auto i : make_range(n_local_training_samples))
546  {
547  Real random_number = static_cast<Real>(std::rand()) / RAND_MAX; // in range [0,1]
548 
549  // Generate log10 scaled training parameters
550  if (libmesh_map_find(log_param_scale, param_name))
551  {
552  Real log_min = std::log10(min_parameters.get_value(param_name));
553  Real log_range = std::log10(max_parameters.get_value(param_name) / min_parameters.get_value(param_name));
554 
555  sample_vector[i] = {std::pow(Real(10.), log_min + random_number*log_range )};
556  }
557  // Generate linearly scaled training parameters
558  else
559  {
560  sample_vector[i] = {
561  random_number * (max_parameters.get_value(param_name) -
562  min_parameters.get_value(param_name)) +
563  min_parameters.get_value(param_name)};
564  }
565  }
566  }
567  return {first_local_index, first_local_index+n_local_training_samples};
568 }
T pow(const T &x)
Definition: utility.h:328
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
DIE A HORRIBLE DEATH HERE typedef MPI_Comm communicator
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors...

◆ get_closest_value()

Real libMesh::RBParametrized::get_closest_value ( Real  value,
const std::vector< Real > &  list_of_values 
)
staticinherited
Returns
The closest entry to value from list_of_values.

Definition at line 446 of file rb_parametrized.C.

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

Referenced by libMesh::RBParametrized::is_value_in_list().

447 {
448  libmesh_error_msg_if(list_of_values.empty(), "Error: list_of_values is empty.");
449 
450  Real min_distance = std::numeric_limits<Real>::max();
451  Real closest_val = 0.;
452  for (const auto & current_value : list_of_values)
453  {
454  Real distance = std::abs(value - current_value);
455  if (distance < min_distance)
456  {
457  min_distance = distance;
458  closest_val = current_value;
459  }
460  }
461 
462  return closest_val;
463 }
Real distance(const Point &p)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const bool value
Definition: xdr_io.C:54

◆ get_deterministic_training_parameter_name()

template<class Base>
const std::string& libMesh::RBConstructionBase< Base >::get_deterministic_training_parameter_name ( ) const

Get the name of the parameter that we will generate deterministic training parameters for.

◆ get_discrete_parameter_values()

const std::map< std::string, std::vector< Real > > & libMesh::RBParametrized::get_discrete_parameter_values ( ) const
inherited

Get a const reference to the discrete parameter values.

Definition at line 373 of file rb_parametrized.C.

References libMesh::RBParametrized::_discrete_parameter_values, and libMesh::RBParametrized::parameters_initialized.

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

374 {
375  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_discrete_parameter_values");
376 
378 }
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.

◆ get_first_local_training_index()

template<class Base >
numeric_index_type libMesh::RBConstructionBase< Base >::get_first_local_training_index ( ) const

Get the first local index of the training parameters.

Definition at line 191 of file rb_construction_base.C.

192 {
193  libmesh_error_msg_if(!_training_parameters_initialized,
194  "Error: training parameters must first be initialized.");
195 
196  // First we check if there are no parameters here, and in that case we
197  // return 0 for a serial training set and comm().rank() for a parallel
198  // training set. This is consistent with get_n_training_samples(), and
199  // avoids accessing training_parameters.begin() when training_parameters
200  // is empty.
201  if (_training_parameters.empty())
202  {
204  return 0;
205  else
206  return this->comm().rank();
207  }
208 
209  return _first_local_index;
210 }
numeric_index_type _first_local_index
The first sample-vector index from the global vector which is stored in the _training_parameters on t...
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors...
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.

◆ get_global_max_error_pair()

template<class Base >
void libMesh::RBConstructionBase< Base >::get_global_max_error_pair ( const Parallel::Communicator communicator,
std::pair< numeric_index_type, Real > &  error_pair 
)
staticprotected

Static function to return the error pair (index,error) that is corresponds to the largest error on all processors.

Definition at line 134 of file rb_construction_base.C.

136 {
137  // Set error_pair.second to the maximum global value and also
138  // find which processor contains the maximum value
139  unsigned int proc_ID_index;
140  communicator.maxloc(error_pair.second, proc_ID_index);
141 
142  // Then broadcast error_pair.first from proc_ID_index
143  communicator.broadcast(error_pair.first, proc_ID_index);
144 }
DIE A HORRIBLE DEATH HERE typedef MPI_Comm communicator

◆ 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.

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 (const auto & [name, cd] : _counts)
59  oss << "| " << name << " reference count information:\n"
60  << "| Creations: " << cd.first << '\n'
61  << "| Destructions: " << cd.second << '\n';
62 
63  oss << " ---------------------------------------------------------------------------- \n";
64 
65  return oss.str();
66 
67 #else
68 
69  return "";
70 
71 #endif
72 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
static Counts _counts
Actually holds the data.

◆ get_last_local_training_index()

template<class Base >
numeric_index_type libMesh::RBConstructionBase< Base >::get_last_local_training_index ( ) const

Get the last local index of the training parameters.

Definition at line 213 of file rb_construction_base.C.

214 {
215  libmesh_error_msg_if(!_training_parameters_initialized,
216  "Error: training parameters must first be initialized.");
217 
218  if (_training_parameters.empty())
219  return 0;
220 
222 }
numeric_index_type _first_local_index
The first sample-vector index from the global vector which is stored in the _training_parameters on t...
numeric_index_type _n_local_training_samples
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.

◆ get_local_n_training_samples()

template<class Base >
numeric_index_type libMesh::RBConstructionBase< Base >::get_local_n_training_samples ( ) const

Get the total number of training samples local to this processor.

Definition at line 175 of file rb_construction_base.C.

176 {
177  libmesh_error_msg_if(!_training_parameters_initialized,
178  "Error: training parameters must first be initialized.");
179 
180  // First we check if there are no parameters here, and in that case we
181  // return 1 for both serial and parallel training sets. This is consistent
182  // with get_n_training_samples(), and avoids accessing
183  // training_parameters.begin() when training_parameters is empty.
184  if (_training_parameters.empty())
185  return 1;
186 
188 }
numeric_index_type _n_local_training_samples
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.

◆ get_n_continuous_params()

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

Get the number of continuous parameters.

Definition at line 112 of file rb_parametrized.C.

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

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

113 {
114  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_n_continuous_params");
115 
117 
118  return static_cast<unsigned int>(get_n_params() - get_n_discrete_params());
119 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
unsigned int get_n_discrete_params() const
Get the number of discrete parameters.
libmesh_assert(ctx)
unsigned int get_n_params() const
Get the number of parameters.

◆ get_n_discrete_params()

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

Get the number of discrete parameters.

Definition at line 121 of file rb_parametrized.C.

References libMesh::RBParametrized::get_discrete_parameter_values(), and libMesh::RBParametrized::parameters_initialized.

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

122 {
123  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_n_discrete_params");
124 
125  return cast_int<unsigned int>
127 }
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.

◆ get_n_params()

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

Get the number of parameters.

Definition at line 103 of file rb_parametrized.C.

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

Referenced by libMesh::RBParametrized::check_if_valid_params(), libMesh::RBEIMConstruction::compute_max_eim_error(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::RBParametrized::get_n_continuous_params(), libMesh::RBSCMConstruction::print_info(), libMesh::RBEIMConstruction::print_info(), libMesh::RBConstruction::print_info(), libMesh::RBEIMEvaluation::set_eim_error_indicator_active(), and libMesh::RBConstruction::train_reduced_basis_with_POD().

104 {
105  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_n_params");
106 
107  libmesh_assert_equal_to ( parameters_min.n_parameters(), parameters_max.n_parameters() );
108 
109  return parameters_min.n_parameters();
110 }
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.
unsigned int n_parameters() const
Get the number of parameters that have been added.

◆ get_n_training_samples()

template<class Base >
numeric_index_type libMesh::RBConstructionBase< Base >::get_n_training_samples ( ) const

Get the number of global training samples.

Definition at line 153 of file rb_construction_base.C.

154 {
155  libmesh_error_msg_if(!_training_parameters_initialized,
156  "Error: training parameters must first be initialized.");
157 
158  // First we check if there are no parameters here, and in that case we
159  // return 1 since a single training sample is sufficient to generate an
160  // RB approximation if there are no parameters. Note that in parallel,
161  // and when we don't have a serial training set, set return comm().size()
162  // so that each processor is assigned a single (empty) training sample.
163  if (_training_parameters.empty())
164  {
166  return 1;
167  else
168  return this->comm().size();
169  }
170 
172 }
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors...
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.
numeric_index_type _n_global_training_samples
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.

◆ get_parameter_max()

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

Get maximum allowable value of parameter param_name.

Definition at line 185 of file rb_parametrized.C.

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

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

186 {
187  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_parameter_max");
188 
189  return parameters_max.get_value(param_name);
190 }
Real get_value(const std::string &param_name) const
Get the value of the specified parameter, throw an error if it does not exist.
Definition: rb_parameters.C:65
bool parameters_initialized
Flag indicating whether the parameters have been initialized.

◆ get_parameter_min()

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

Get minimum allowable value of parameter param_name.

Definition at line 178 of file rb_parametrized.C.

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

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

179 {
180  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_parameter_min");
181 
182  return parameters_min.get_value(param_name);
183 }
Real get_value(const std::string &param_name) const
Get the value of the specified parameter, throw an error if it does not exist.
Definition: rb_parameters.C:65
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.

◆ get_parameter_names()

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

Get a set that stores the parameter names.

Deprecated:
to avoid making it too easy to create copies that in most circumstances aren't needed. If this functionality really is required, call get_parameters_min().get_parameters_map() and loop over the keys directly.

Definition at line 130 of file rb_parametrized.C.

References libMesh::RBParametrized::parameters_initialized, and libMesh::RBParametrized::parameters_min.

131 {
132  libmesh_deprecated();
133  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_parameter_names");
134 
135  std::set<std::string> parameter_names;
136  for (const auto & pr : parameters_min)
137  parameter_names.insert(pr.first);
138 
139  return parameter_names;
140 }
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.

◆ get_parameters()

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

Get the current parameters.

Definition at line 157 of file rb_parametrized.C.

References libMesh::RBParametrized::parameters, and libMesh::RBParametrized::parameters_initialized.

Referenced by libMesh::TransientRBConstruction::add_scaled_mass_matrix(), libMesh::TransientRBEvaluation::cache_online_residual_terms(), libMesh::RBEvaluation::compute_residual_dual_norm(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::RBSCMConstruction::enrich_C_J(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_interiors(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_nodes(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_sides(), libMesh::RBEvaluation::eval_output_dual_norm(), 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::RBEIMConstruction::initialize_parametrized_functions_in_training_set(), libMesh::RBSCMEvaluation::legacy_read_offline_data_from_files(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::RBConstruction::preevaluate_thetas(), libMesh::RBSCMConstruction::print_info(), libMesh::RBEIMConstruction::print_info(), libMesh::RBConstruction::print_info(), libMesh::RBParametrized::print_parameters(), libMesh::RBSCMConstruction::process_parameters_file(), libMesh::TransientRBEvaluation::rb_solve(), libMesh::RBEvaluation::rb_solve(), libMesh::RBSCMEvaluation::save_current_parameters(), libMesh::RBEIMConstruction::train_eim_approximation_with_greedy(), libMesh::RBEIMConstruction::train_eim_approximation_with_POD(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::TransientRBConstruction::truth_solve(), libMesh::RBConstruction::truth_solve(), libMesh::TransientRBEvaluation::uncached_compute_residual_dual_norm(), and libMesh::RBConstruction::update_greedy_param_list().

158 {
159  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_parameters");
160 
161  return parameters;
162 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
RBParameters parameters
Vector storing the current parameters.

◆ get_parameters_max()

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

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

Definition at line 171 of file rb_parametrized.C.

References libMesh::RBParametrized::parameters_initialized, and libMesh::RBParametrized::parameters_max.

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

172 {
173  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_parameters_max");
174 
175  return parameters_max;
176 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.

◆ get_parameters_min()

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

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

Definition at line 164 of file rb_parametrized.C.

References libMesh::RBParametrized::parameters_initialized, and libMesh::RBParametrized::parameters_min.

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

165 {
166  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::get_parameters_min");
167 
168  return parameters_min;
169 }
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.

◆ get_params_from_training_set()

template<class Base >
RBParameters libMesh::RBConstructionBase< Base >::get_params_from_training_set ( unsigned int  global_index)
protected

Return the RBParameters in index global_index of the global training set.

Why do we use an index here? RBParameters supports loading the full sample set. This seems probably unnecessary now to load individually. Maybe it's a memory issue?

Definition at line 231 of file rb_construction_base.C.

232 {
233  libmesh_error_msg_if(!_training_parameters_initialized,
234  "Error: training parameters must first be initialized.");
235 
236  // If the _training_parameters are empty, return an empty RBParameters.
237  // Otherwise, create a new RBParameters object from the single sample requested.
238  RBParameters params;
239  if (!_training_parameters.empty())
240  {
241  libmesh_error_msg_if((global_index < this->get_first_local_training_index()) ||
242  (global_index >= this->get_last_local_training_index()),
243  "Error: index "
244  << global_index
245  << " must be within range: "
247  << " - "
248  << this->get_last_local_training_index());
249 
250  const numeric_index_type local_index = global_index - get_first_local_training_index();
251  for (const auto & [param_name, sample_vector] : _training_parameters)
252  params.set_value(param_name, sample_vector[local_index]);
253 
254  // Copy all extra values into the new RBParameters.
255  // We assume that the samples may be indexed differently for extra parameters,
256  // so we don't just copy the local_index value.
257  const auto & mine = get_parameters();
258  for (const auto & [key, extra_sample_vector] :
259  as_range(mine.extra_begin(), mine.extra_end()))
260  {
261  for (const auto idx : index_range(extra_sample_vector))
262  params.set_extra_value(key, idx, extra_sample_vector[idx]);
263  }
264  }
265 
266  return params;
267 }
numeric_index_type get_first_local_training_index() const
Get the first local index of the training parameters.
dof_id_type numeric_index_type
Definition: id_types.h:99
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
Definition: simple_range.h:57
numeric_index_type get_last_local_training_index() const
Get the last local index of the training parameters.
const RBParameters & get_parameters() const
Get the current parameters.
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:117
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
A useful inline function which replaces the macros used previously.

◆ increment_constructor_count()

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

Increments the construction counter.

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

Definition at line 183 of file reference_counter.h.

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

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

184 {
185  libmesh_try
186  {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189  p.first++;
190  }
191  libmesh_catch (...)
192  {
193  auto stream = libMesh::err.get();
194  stream->exceptions(stream->goodbit); // stream must not throw
195  libMesh::err << "Encountered unrecoverable error while calling "
196  << "ReferenceCounter::increment_constructor_count() "
197  << "for a(n) " << name << " object." << std::endl;
198  std::terminate();
199  }
200 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
OStreamProxy err
static Counts _counts
Actually holds the data.
streamT * get()
Rather than implement every ostream/ios/ios_base function, we&#39;ll be lazy and make esoteric uses go th...
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:30

◆ increment_destructor_count()

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

Increments the destruction counter.

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

Definition at line 207 of file reference_counter.h.

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

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

208 {
209  libmesh_try
210  {
211  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
212  std::pair<unsigned int, unsigned int> & p = _counts[name];
213  p.second++;
214  }
215  libmesh_catch (...)
216  {
217  auto stream = libMesh::err.get();
218  stream->exceptions(stream->goodbit); // stream must not throw
219  libMesh::err << "Encountered unrecoverable error while calling "
220  << "ReferenceCounter::increment_destructor_count() "
221  << "for a(n) " << name << " object." << std::endl;
222  std::terminate();
223  }
224 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
OStreamProxy err
static Counts _counts
Actually holds the data.
streamT * get()
Rather than implement every ostream/ios/ios_base function, we&#39;ll be lazy and make esoteric uses go th...
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:30

◆ init_data()

template<class Base >
void libMesh::RBConstructionBase< Base >::init_data ( )
protectedvirtual

Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.

Reimplemented in SimpleRBConstruction, SimpleRBConstruction, SimpleRBConstruction, SimpleRBConstruction, SimpleRBConstruction, SimpleRBConstruction, ElasticityRBConstruction, SimpleEIMConstruction, and SimpleEIMConstruction.

Definition at line 123 of file rb_construction_base.C.

124 {
125  Base::init_data();
126 
127  // Initialize the inner product storage vector, which is useful for
128  // storing intermediate results when evaluating inner products
130  inner_product_storage_vector->init (this->n_dofs(), this->n_local_dofs(), false, PARALLEL);
131 }
std::unique_ptr< NumericVector< Number > > inner_product_storage_vector
We keep an extra temporary vector that is useful for performing inner products (avoids unnecessary me...
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...

◆ 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 
)
inherited

Initialize the parameter ranges and set current_parameters.

Parameter ranges are inclusive. The input min/max RBParameters should have exactly 1 sample each. Vector-valued samples are not currently supported for the min/max parameters or for discrete parameters.

Definition at line 53 of file rb_parametrized.C.

References libMesh::RBParametrized::_discrete_parameter_values, libMesh::RBParameters::begin_serialized(), libMesh::RBParameters::end_serialized(), libMesh::RBParameters::n_parameters(), libMesh::RBParameters::n_samples(), libMesh::Quality::name(), libMesh::RBParametrized::parameters_initialized, libMesh::RBParametrized::parameters_max, libMesh::RBParametrized::parameters_min, libMesh::Real, libMesh::RBParametrized::set_parameters(), and libMesh::RBParameters::set_value().

Referenced by libMesh::RBConstruction::enrich_basis_from_rhs_terms(), libMesh::RBParametrized::initialize_parameters(), libMesh::RBDataDeserialization::load_parameter_ranges(), libMesh::RBSCMConstruction::perform_SCM_greedy(), libMesh::RBSCMConstruction::process_parameters_file(), libMesh::RBParametrized::read_parameter_data_from_files(), libMesh::RBEIMConstruction::set_rb_construction_parameters(), libMesh::RBConstruction::set_rb_construction_parameters(), RBParametersTest::testRBParametrized(), libMesh::RBEIMConstruction::train_eim_approximation_with_greedy(), libMesh::RBEIMConstruction::train_eim_approximation_with_POD(), libMesh::RBConstruction::train_reduced_basis_with_greedy(), and libMesh::RBConstruction::train_reduced_basis_with_POD().

56 {
57  // Check that the min/max vectors have the same size.
58  libmesh_error_msg_if(mu_min_in.n_parameters() != mu_max_in.n_parameters(),
59  "Error: Invalid mu_min/mu_max in initialize_parameters(), different number of parameters.");
60  libmesh_error_msg_if(mu_min_in.n_samples() != 1 ||
61  mu_max_in.n_samples() != 1,
62  "Error: Invalid mu_min/mu_max in initialize_parameters(), only 1 sample supported.");
63 
64  // Ensure all the values are valid for min and max.
65  auto pr_min = mu_min_in.begin_serialized();
66  auto pr_max = mu_max_in.begin_serialized();
67  for (; pr_min != mu_min_in.end_serialized(); ++pr_min, ++pr_max)
68  libmesh_error_msg_if((*pr_min).second > (*pr_max).second,
69  "Error: Invalid mu_min/mu_max in RBParameters constructor.");
70 
71  parameters_min = mu_min_in;
72  parameters_max = mu_max_in;
73 
74  // Add in min/max values due to the discrete parameters
75  for (const auto & [name, vals] : discrete_parameter_values)
76  {
77  libmesh_error_msg_if(vals.empty(), "Error: List of discrete parameters for " << name << " is empty.");
78 
79  Real min_val = *std::min_element(vals.begin(), vals.end());
80  Real max_val = *std::max_element(vals.begin(), vals.end());
81 
82  libmesh_assert_less_equal(min_val, max_val);
83 
84  parameters_min.set_value(name, min_val);
85  parameters_max.set_value(name, max_val);
86  }
87 
88  _discrete_parameter_values = discrete_parameter_values;
89 
91 
92  // Initialize the current parameters to parameters_min
94 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
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.
std::map< std::string, std::vector< Real > > _discrete_parameter_values
Map that defines the allowable values of any discrete parameters.
bool set_parameters(const RBParameters &params)
Set the current parameters to params The parameters are checked for validity; an error is thrown if t...
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.

◆ initialize_parameters() [2/2]

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

Initialize the parameter ranges and set current_parameters.

Definition at line 96 of file rb_parametrized.C.

References libMesh::RBParametrized::get_discrete_parameter_values(), libMesh::RBParametrized::get_parameters_max(), libMesh::RBParametrized::get_parameters_min(), and libMesh::RBParametrized::initialize_parameters().

97 {
98  initialize_parameters(rb_parametrized.get_parameters_min(),
99  rb_parametrized.get_parameters_max(),
100  rb_parametrized.get_discrete_parameter_values());
101 }
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.

◆ initialize_training_parameters()

template<class Base >
void libMesh::RBConstructionBase< Base >::initialize_training_parameters ( const RBParameters mu_min,
const RBParameters mu_max,
const unsigned int  n_global_training_samples,
const std::map< std::string, bool > &  log_param_scale,
const bool  deterministic = true 
)
virtual

Initialize the parameter ranges and indicate whether deterministic or random training parameters should be used and whether or not we want the parameters to be scaled logarithmically.

n_global_training_samples is the total number of samples to generate, which will be distributed across all the processors.

Definition at line 292 of file rb_construction_base.C.

297 {
298  if (!is_quiet())
299  {
300  // Print out some info about the training set initialization
301  libMesh::out << "Initializing training parameters with "
302  << (deterministic ? "deterministic " : "random " )
303  << "training set..." << std::endl;
304 
305  for (const auto & pr : log_param_scale)
306  libMesh::out << "Parameter "
307  << pr.first
308  << ": log scaling = "
309  << pr.second
310  << std::endl;
311 
312  libMesh::out << std::endl;
313  }
314 
315  if (deterministic)
316  {
317  const auto [first_local_index, last_local_index] =
319  log_param_scale,
321  n_global_training_samples,
322  mu_min,
323  mu_max,
325  _first_local_index = first_local_index;
326  _n_local_training_samples = last_local_index-first_local_index;
327  }
328  else
329  {
330  // Generate random training samples for all parameters
331  const auto [first_local_index, last_local_index] =
333  log_param_scale,
335  n_global_training_samples,
336  mu_min,
337  mu_max,
340  _first_local_index = first_local_index;
341  _n_local_training_samples = last_local_index-first_local_index;
342  }
344 
345  if (!serial_training_set)
346  this->comm().sum(_n_global_training_samples);
347 
348  // For each parameter that only allows discrete values, we "snap" to the nearest
349  // allowable discrete value
350  if (get_n_discrete_params() > 0)
351  {
352  for (auto & [param_name, sample_vector] : _training_parameters)
353  {
354  if (is_discrete_parameter(param_name))
355  {
356  const std::vector<Real> & discrete_values =
357  libmesh_map_find(get_discrete_parameter_values(), param_name);
358 
359  for (const auto sample_idx : index_range(sample_vector))
360  {
361  // Round all values to the closest discrete value.
362  std::vector<Real> discretized_vector(sample_vector[sample_idx].size());
363  std::transform(sample_vector[sample_idx].cbegin(),
364  sample_vector[sample_idx].cend(),
365  discretized_vector.begin(),
366  [&discrete_values](const Real & val) {
367  return get_closest_value(val, discrete_values);
368  });
369  sample_vector[sample_idx] = discretized_vector;
370  }
371  }
372  }
373  }
374 
376 }
static std::pair< std::size_t, std::size_t > generate_training_parameters_random(const Parallel::Communicator &communicator, const std::map< std::string, bool > &log_param_scale, std::map< std::string, std::vector< RBParameter >> &local_training_parameters_in, const unsigned int n_global_training_samples_in, const RBParameters &min_parameters, const RBParameters &max_parameters, const int training_parameters_random_seed=-1, const bool serial_training_set=false)
Static helper function for generating a randomized set of parameters.
static std::pair< std::size_t, std::size_t > generate_training_parameters_deterministic(const Parallel::Communicator &communicator, const std::map< std::string, bool > &log_param_scale, std::map< std::string, std::vector< RBParameter >> &local_training_parameters_in, const unsigned int n_global_training_samples_in, const RBParameters &min_parameters, const RBParameters &max_parameters, const bool serial_training_set=false)
Static helper function for generating a deterministic set of parameters.
bool is_quiet() const
Is the system in quiet mode?
static Real get_closest_value(Real value, const std::vector< Real > &list_of_values)
unsigned int get_n_discrete_params() const
Get the number of discrete parameters.
numeric_index_type _first_local_index
The first sample-vector index from the global vector which is stored in the _training_parameters on t...
numeric_index_type _n_local_training_samples
const std::map< std::string, std::vector< Real > > & get_discrete_parameter_values() const
Get a const reference to the discrete parameter values.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
OStreamProxy out
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors...
int _training_parameters_random_seed
If < 0, use std::time() * processor_id() to seed the random number generator for the training paramet...
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.
numeric_index_type _n_global_training_samples
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:117
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.
bool is_discrete_parameter(const std::string &mu_name) const
Is parameter mu_name discrete?

◆ is_discrete_parameter()

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

Is parameter mu_name discrete?

Definition at line 365 of file rb_parametrized.C.

References libMesh::RBParametrized::_discrete_parameter_values, and libMesh::RBParametrized::parameters_initialized.

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

366 {
367  libmesh_error_msg_if(!parameters_initialized,
368  "Error: parameters not initialized in RBParametrized::is_discrete_parameter");
369 
370  return _discrete_parameter_values.count(mu_name);
371 }
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.

◆ is_quiet()

template<class Base>
bool libMesh::RBConstructionBase< Base >::is_quiet ( ) const
inline

Is the system in quiet mode?

Definition at line 106 of file rb_construction_base.h.

107  { return this->quiet_mode; }
bool quiet_mode
Flag to indicate whether we print out extra information during the Offline stage. ...

◆ load_training_set()

template<class Base >
void libMesh::RBConstructionBase< Base >::load_training_set ( const std::map< std::string, std::vector< RBParameter >> &  new_training_set)
virtual

Overwrite the training parameters with new_training_set.

This training set is assumed to contain only the samples local to this processor.

Definition at line 379 of file rb_construction_base.C.

380 {
381  // Make sure we're running this on all processors at the same time
382  libmesh_parallel_only(this->comm());
383 
384  // First, make sure that an initial training set has already been generated
385  libmesh_error_msg_if(!_training_parameters_initialized,
386  "Error: load_training_set cannot be used to initialize parameters");
387 
388  // Make sure that the training set has the correct number of parameters
389  const unsigned int n_params = get_n_params();
390  libmesh_error_msg_if(new_training_set.size() > n_params,
391  "Error: new_training_set should not have more than get_n_params() parameters.");
392 
393  // Check that (new_training_set.size() == get_n_params()) is the same on all processes so that
394  // we go into the same branch of the "if" statement below on all processes.
395  const bool size_matches = (new_training_set.size() == n_params);
396  libmesh_assert(this->comm().verify(size_matches));
397 
398  if (size_matches)
399  {
400  // If new_training_set stores values for all parameters, then we overwrite
401  // _training_parameters with new_training_set.
402 
403  // Get the number of local and global training parameters
404  _first_local_index = 0;
406  cast_int<numeric_index_type>(new_training_set.begin()->second.size());
408 
409  if (!serial_training_set)
410  {
411  this->comm().sum(_n_global_training_samples);
412 
413  // Set the first/last indices.
414  std::vector<numeric_index_type> local_sizes (this->n_processors(), 0);
415  local_sizes[this->processor_id()] = _n_local_training_samples;
416  this->comm().sum(local_sizes);
417 
418  // first_local_index is the sum of local_sizes
419  // for all processor ids less than ours
420  for (auto p : make_range(this->processor_id()))
421  _first_local_index += local_sizes[p];
422  }
423 
424  // Ensure that the parameters are the same.
425  for (const auto & pr : _training_parameters)
426  libmesh_error_msg_if(!new_training_set.count(pr.first),
427  "Parameters must be identical in order to overwrite dataset.");
428 
429  // Copy the values from the new_training_set to the internal training_parameters.
430  _training_parameters = new_training_set;
431  }
432  else
433  {
434  // If new_training_set stores values for a subset of the parameters, then we keep the
435  // length of training_parameters unchanged and overwrite the entries of the specified
436  // parameters from new_training_set. Note that we repeatedly loop over new_training_set
437  // to fill up the entire length of the sample_vector.
438  for (auto & [param_name, sample_vector]: _training_parameters)
439  {
440  if (new_training_set.count(param_name))
441  {
442  for (const auto i : make_range(get_local_n_training_samples()))
443  {
444  const unsigned int num_new_samples = libmesh_map_find(new_training_set,param_name).size();
445  libmesh_error_msg_if (num_new_samples==0, "new_training_set set should not be empty");
446 
447  const unsigned int new_training_set_index = i % num_new_samples;
448  sample_vector[i] = libmesh_map_find(new_training_set,param_name)[new_training_set_index];
449  }
450  }
451  }
452  }
453 }
numeric_index_type _first_local_index
The first sample-vector index from the global vector which is stored in the _training_parameters on t...
numeric_index_type _n_local_training_samples
numeric_index_type get_local_n_training_samples() const
Get the total number of training samples local to this processor.
libmesh_assert(ctx)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors...
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.
unsigned int get_n_params() const
Get the number of parameters.
numeric_index_type _n_global_training_samples
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.

◆ n_objects()

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

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

Definition at line 85 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

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

86  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ operator=() [1/2]

template<class Base>
RBConstructionBase& libMesh::RBConstructionBase< Base >::operator= ( RBConstructionBase< Base > &&  )
delete

◆ operator=() [2/2]

template<class Base>
RBConstructionBase& libMesh::RBConstructionBase< Base >::operator= ( const RBConstructionBase< Base > &  )
delete

◆ print_discrete_parameter_values()

void libMesh::RBParametrized::print_discrete_parameter_values ( ) const
inherited

Print out all the discrete parameter values.

Definition at line 380 of file rb_parametrized.C.

References libMesh::RBParametrized::get_discrete_parameter_values(), libMesh::Quality::name(), libMesh::out, and value.

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

381 {
382  for (const auto & [name, values] : get_discrete_parameter_values())
383  {
384  libMesh::out << "Discrete parameter " << name << ", values: ";
385 
386  for (const auto & value : values)
387  libMesh::out << value << " ";
388  libMesh::out << std::endl;
389  }
390 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
const std::map< std::string, std::vector< Real > > & get_discrete_parameter_values() const
Get a const reference to the discrete parameter values.
OStreamProxy out
static const bool value
Definition: xdr_io.C:54

◆ print_info()

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

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

Definition at line 81 of file reference_counter.C.

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

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

82 {
84  out_stream << ReferenceCounter::get_info();
85 }
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...

◆ print_parameters()

void libMesh::RBParametrized::print_parameters ( ) const
inherited

Print the current parameters.

Definition at line 192 of file rb_parametrized.C.

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

Referenced by libMesh::RBEIMConstruction::train_eim_approximation_with_greedy(), and libMesh::RBConstruction::train_reduced_basis_with_greedy().

193 {
194  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::print_current_parameters");
195 
196  get_parameters().print();
197 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
void print(unsigned precision=6, int max_values=5) const
Print the parameters.
const RBParameters & get_parameters() const
Get the current parameters.

◆ 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 
)
inherited

Read in the parameter ranges from files.

Definition at line 276 of file rb_parametrized.C.

References libMesh::RBParametrized::initialize_parameters(), libMesh::RBParametrized::read_discrete_parameter_values_from_file(), and libMesh::RBParametrized::read_parameter_ranges_from_file().

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

279 {
280  RBParameters param_min;
281  RBParameters param_max;
282  read_parameter_ranges_from_file(continuous_param_file_name,
283  read_binary_data,
284  param_min,
285  param_max);
286 
287  std::map<std::string, std::vector<Real>> discrete_parameter_values_in;
288  read_discrete_parameter_values_from_file(discrete_param_file_name,
289  read_binary_data,
290  discrete_parameter_values_in);
291 
292  initialize_parameters(param_min, param_max, discrete_parameter_values_in);
293 }
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.

◆ set_deterministic_training_parameter_name()

template<class Base>
void libMesh::RBConstructionBase< Base >::set_deterministic_training_parameter_name ( const std::string &  name)

In some cases we only want to allow discrete parameter values, instead of parameters that may take any value in a specified interval.

Here we provide a method to set the d Set the discrete values for parameter mu that are allowed in the training set. This must be called before the training set is generated. Set the name of the parameter that we will generate deterministic training parameters for. Defaults to "NONE".

◆ set_normalize_solution_snapshots()

template<class Base >
void libMesh::RBConstructionBase< Base >::set_normalize_solution_snapshots ( bool  value)

Set the boolean option that indicates if we normalization solution snapshots or not.

Definition at line 147 of file rb_construction_base.C.

148 {
150 }
bool _normalize_solution_snapshots
Set this boolean to true if we want to normalize solution snapshots used in training to have norm of ...
static const bool value
Definition: xdr_io.C:54

◆ set_parameters()

bool libMesh::RBParametrized::set_parameters ( const RBParameters params)
inherited

Set the current parameters to params The parameters are checked for validity; an error is thrown if the number of parameters or samples is different than expected.

We

Returns
a boolean true if the new parameters are within the min/max range, and false otherwise (but the parameters are set regardless). Enabling the "verbose_mode" flag will also print more details.

Definition at line 143 of file rb_parametrized.C.

References libMesh::RBParametrized::check_if_valid_params(), libMesh::RBParametrized::parameters, and libMesh::RBParametrized::parameters_initialized.

Referenced by libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_interiors(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_nodes(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_sides(), libMesh::RBConstruction::get_RB_error_bound(), SimpleRBEvaluation::get_stability_lower_bound(), libMesh::RBParametrized::initialize_parameters(), libMesh::RBSCMEvaluation::reload_current_parameters(), libMesh::RBSCMEvaluation::set_current_parameters_from_C_J(), and RBParametersTest::testRBParametrized().

144 {
145  libmesh_error_msg_if(!parameters_initialized, "Error: parameters not initialized in RBParametrized::set_parameters");
146 
147  // Terminate if params has the wrong number of parameters or samples.
148  // If the parameters are outside the min/max range, return false.
149  const bool valid_params = check_if_valid_params(params);
150 
151  // Make a copy of params (default assignment operator just does memberwise copy, which is sufficient here)
152  this->parameters = params;
153 
154  return valid_params;
155 }
bool parameters_initialized
Flag indicating whether the parameters have been initialized.
bool check_if_valid_params(const RBParameters &params) const
Helper function to check that params is valid:
RBParameters parameters
Vector storing the current parameters.

◆ set_params_from_training_set()

template<class Base >
void libMesh::RBConstructionBase< Base >::set_params_from_training_set ( unsigned int  global_index)
protected

Set parameters to the RBParameters stored in index global_index of the global training set.

Definition at line 225 of file rb_construction_base.C.

226 {
228 }
bool set_parameters(const RBParameters &params)
Set the current parameters to params The parameters are checked for validity; an error is thrown if t...
RBParameters get_params_from_training_set(unsigned int global_index)
Return the RBParameters in index global_index of the global training set.

◆ set_params_from_training_set_and_broadcast()

template<class Base >
void libMesh::RBConstructionBase< Base >::set_params_from_training_set_and_broadcast ( unsigned int  global_index)
protectedvirtual

Load the specified training parameter and then broadcast to all processors.

Definition at line 270 of file rb_construction_base.C.

271 {
272  libmesh_error_msg_if(!_training_parameters_initialized,
273  "Error: training parameters must first be initialized.");
274 
275  processor_id_type root_id = 0;
276  if ((this->get_first_local_training_index() <= global_index) &&
277  (global_index < this->get_last_local_training_index()))
278  {
279  // Set parameters on only one processor
280  set_params_from_training_set(global_index);
281 
282  // set root_id, only non-zero on one processor
283  root_id = this->processor_id();
284  }
285 
286  // broadcast
287  this->comm().max(root_id);
288  broadcast_parameters(root_id);
289 }
numeric_index_type get_first_local_training_index() const
Get the first local index of the training parameters.
void broadcast_parameters(const unsigned int proc_id)
Broadcasts parameters from processor proc_id to all processors.
uint8_t processor_id_type
numeric_index_type get_last_local_training_index() const
Get the last local index of the training parameters.
void set_params_from_training_set(unsigned int global_index)
Set parameters to the RBParameters stored in index global_index of the global training set...
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.

◆ set_quiet_mode()

template<class Base>
void libMesh::RBConstructionBase< Base >::set_quiet_mode ( bool  quiet_mode_in)
inline

Set the quiet_mode flag.

If quiet == false then we print out a lot of extra information during the Offline stage.

Definition at line 100 of file rb_construction_base.h.

101  { this->quiet_mode = quiet_mode_in; }
bool quiet_mode
Flag to indicate whether we print out extra information during the Offline stage. ...

◆ set_training_parameter_values()

template<class Base >
void libMesh::RBConstructionBase< Base >::set_training_parameter_values ( const std::string &  param_name,
const std::vector< RBParameter > &  values 
)

Overwrite the local training samples for param_name using values.

This assumes that values.size() matches get_local_n_training_samples().

Definition at line 456 of file rb_construction_base.C.

458 {
459  libmesh_error_msg_if(!_training_parameters_initialized,
460  "Training parameters must be initialized before calling set_training_parameter_values");
461  libmesh_error_msg_if(values.size() != get_local_n_training_samples(),
462  "Inconsistent sizes");
463 
464  // Copy the new data, overwriting the old data.
465  auto & training_vector = libmesh_map_find(_training_parameters, param_name);
466  training_vector = values;
467 }
numeric_index_type get_local_n_training_samples() const
Get the total number of training samples local to this processor.
std::map< std::string, std::vector< RBParameter > > _training_parameters
The training samples for each parameter.
bool _training_parameters_initialized
Boolean flag to indicate whether or not the parameter ranges have been initialized.

◆ set_training_random_seed()

template<class Base >
void libMesh::RBConstructionBase< Base >::set_training_random_seed ( int  seed)

Set the seed that is used to randomly generate training parameters.

Definition at line 780 of file rb_construction_base.C.

781 {
783 }
int _training_parameters_random_seed
If < 0, use std::time() * processor_id() to seed the random number generator for the training paramet...

◆ system()

template<class Base>
sys_type& libMesh::RBConstructionBase< Base >::system ( )
inline
Returns
A reference to *this.

Definition at line 87 of file rb_construction_base.h.

87 { return *this; }

◆ 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 
)
inherited

Write out the parameter ranges to files.

Definition at line 199 of file rb_parametrized.C.

References libMesh::RBParametrized::write_discrete_parameter_values_to_file(), and libMesh::RBParametrized::write_parameter_ranges_to_file().

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

202 {
203  write_parameter_ranges_to_file(continuous_param_file_name, write_binary_data);
204  write_discrete_parameter_values_to_file(discrete_param_file_name, write_binary_data);
205 }
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.

Member Data Documentation

◆ _counts

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

Actually holds the data.

Definition at line 124 of file reference_counter.h.

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

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

◆ _first_local_index

template<class Base>
numeric_index_type libMesh::RBConstructionBase< Base >::_first_local_index
private

The first sample-vector index from the global vector which is stored in the _training_parameters on this processor.

_n_local_training_samples is equivalent to the .size() of any vector in _training_parameters.

Definition at line 313 of file rb_construction_base.h.

◆ _mutex

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.

◆ _n_global_training_samples

template<class Base>
numeric_index_type libMesh::RBConstructionBase< Base >::_n_global_training_samples
private

Definition at line 315 of file rb_construction_base.h.

◆ _n_local_training_samples

template<class Base>
numeric_index_type libMesh::RBConstructionBase< Base >::_n_local_training_samples
private

Definition at line 314 of file rb_construction_base.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 132 of file reference_counter.h.

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

◆ _normalize_solution_snapshots

template<class Base>
bool libMesh::RBConstructionBase< Base >::_normalize_solution_snapshots
protected

Set this boolean to true if we want to normalize solution snapshots used in training to have norm of 1.

This is relevant if snapshots have differing magnitudes and we want to approximate them all with equal accuracy.

Definition at line 281 of file rb_construction_base.h.

◆ _training_parameters

template<class Base>
std::map<std::string, std::vector<RBParameter> > libMesh::RBConstructionBase< Base >::_training_parameters
private

The training samples for each parameter.

When serial_training_set is true, the map contains all samples of all parameters. Otherwise, the sample vectors will only contain the values for the local samples as defined by _first_local_index and _n_local_training_samples. Mapped from parameter_name -> sample_vector -> value_vector.

Definition at line 306 of file rb_construction_base.h.

◆ _training_parameters_initialized

template<class Base>
bool libMesh::RBConstructionBase< Base >::_training_parameters_initialized
private

Boolean flag to indicate whether or not the parameter ranges have been initialized.

Definition at line 297 of file rb_construction_base.h.

◆ _training_parameters_random_seed

template<class Base>
int libMesh::RBConstructionBase< Base >::_training_parameters_random_seed
private

If < 0, use std::time() * processor_id() to seed the random number generator for the training parameters (default).

If >= 0, use the provided value * processor_id() as the random number generator seed.

Definition at line 323 of file rb_construction_base.h.

◆ inner_product_storage_vector

template<class Base>
std::unique_ptr<NumericVector<Number> > libMesh::RBConstructionBase< Base >::inner_product_storage_vector
protected

We keep an extra temporary vector that is useful for performing inner products (avoids unnecessary memory allocation/deallocation).

Definition at line 288 of file rb_construction_base.h.

◆ quiet_mode

template<class Base>
bool libMesh::RBConstructionBase< Base >::quiet_mode
protected

Flag to indicate whether we print out extra information during the Offline stage.

Definition at line 265 of file rb_construction_base.h.

Referenced by libMesh::RBConstructionBase< CondensedEigenSystem >::is_quiet(), and libMesh::RBConstructionBase< CondensedEigenSystem >::set_quiet_mode().

◆ serial_training_set

template<class Base>
bool libMesh::RBConstructionBase< Base >::serial_training_set
protected

This boolean flag indicates whether or not the training set should be the same on all processors.

By default it is false, but in the case of the Empirical Interpolation Method (RBEIMConstruction), for example, we need the training set to be identical on all processors.

Definition at line 273 of file rb_construction_base.h.

◆ verbose_mode

bool libMesh::RBParametrized::verbose_mode
inherited

Public boolean to toggle verbose mode.

Definition at line 193 of file rb_parametrized.h.

Referenced by libMesh::RBParametrized::check_if_valid_params().


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