21#include "libmesh/libmesh_config.h"
25#if defined(LIBMESH_HAVE_SLEPC) && (LIBMESH_HAVE_GLPK)
27#include "libmesh/rb_scm_construction.h"
28#include "libmesh/rb_construction.h"
29#include "libmesh/rb_scm_evaluation.h"
31#include "libmesh/libmesh_logging.h"
32#include "libmesh/numeric_vector.h"
33#include "libmesh/sparse_matrix.h"
34#include "libmesh/equation_systems.h"
35#include "libmesh/getpot.h"
36#include "libmesh/dof_map.h"
37#include "libmesh/enum_eigen_solver_type.h"
48 const std::string & name_in,
49 const unsigned int number_in)
50 :
Parent(es, name_in, number_in),
51 SCM_training_tolerance(0.5),
79 libmesh_error_msg_if(!
rb_scm_eval,
"Error: RBSCMEvaluation object hasn't been initialized yet");
92 GetPot infile(parameters_filename);
93 const unsigned int n_training_samples = infile(
"n_training_samples",1);
94 const bool deterministic_training = infile(
"deterministic_training",
false);
99 unsigned int training_parameters_random_seed_in =
static_cast<unsigned int>(-1);
100 training_parameters_random_seed_in = infile(
"training_parameters_random_seed",
101 training_parameters_random_seed_in);
109 unsigned int n_continuous_parameters = infile.vector_variable_size(
"parameter_names");
112 for (
unsigned int i=0; i<n_continuous_parameters; i++)
115 std::string param_name = infile(
"parameter_names",
"NONE", i);
118 Real min_val = infile(param_name, 0., 0);
119 mu_min_in.
set_value(param_name, min_val);
123 Real max_val = infile(param_name, 0., 1);
124 mu_max_in.
set_value(param_name, max_val);
128 std::map<std::string, std::vector<Real>> discrete_parameter_values_in;
130 unsigned int n_discrete_parameters = infile.vector_variable_size(
"discrete_parameter_names");
131 for (
unsigned int i=0; i<n_discrete_parameters; i++)
133 std::string param_name = infile(
"discrete_parameter_names",
"NONE", i);
135 unsigned int n_vals_for_param = infile.vector_variable_size(param_name);
136 std::vector<Real> vals_for_param(n_vals_for_param);
137 for (
unsigned int j=0; j != n_vals_for_param; j++)
138 vals_for_param[j] = infile(param_name, 0., j);
140 discrete_parameter_values_in[param_name] = vals_for_param;
145 std::map<std::string,bool> log_scaling;
148 for (
const auto & pr : mu)
150 const std::string & param_name = pr.first;
151 log_scaling[param_name] =
static_cast<bool>(infile(
"log_scaling", 0, i++));
158 deterministic_training);
164 libMesh::out << std::endl <<
"RBSCMConstruction parameters:" << std::endl;
173 libMesh::out <<
"RBThetaExpansion member is not set yet" << std::endl;
178 const std::string & param_name = pr.first;
206 LOG_SCOPE(
"add_scaled_symm_Aq()",
"RBSCMConstruction");
226 LOG_SCOPE(
"perform_SCM_greedy()",
"RBSCMConstruction");
231#ifdef LIBMESH_ENABLE_CONSTRAINTS
233 std::set<dof_id_type> constrained_dofs_set;
241 constrained_dofs_set.insert(i);
259 unsigned int SCM_iter=0;
269 <<
", max_SCM_error = " << SCM_error_pair.second << std::endl;
274 << std::endl << std::endl;
281 libMesh::out << std::endl <<
"-----------------------------------" << std::endl << std::endl;
289 LOG_SCOPE(
"compute_SCM_bounding_box()",
"RBSCMConstruction");
313 libmesh_assert_less (eval.second,
TOLERANCE);
319 libmesh_error_msg(
"Eigen solver for computing B_min did not converge");
334 libmesh_assert_less (eval.second,
TOLERANCE);
340 libmesh_error_msg(
"Eigen solver for computing B_max did not converge");
346 LOG_SCOPE(
"evaluate_stability_constant()",
"RBSCMConstruction");
349 const unsigned int j = cast_int<unsigned int>(
rb_scm_eval->
C_J.size()-1);
374 libmesh_assert_less (eval.second,
TOLERANCE);
378 libMesh::out << std::endl <<
"Stability constant for C_J("<<j<<
") = "
394 libmesh_error_msg(
"Error: Eigensolver did not converge in evaluate_stability_constant");
410 "Error: We must have q < Q_a in Aq_inner_product.");
421 LOG_SCOPE(
"compute_SCM_bounds_on_training_set()",
"RBSCMConstruction");
424 unsigned int new_C_J_index = 0;
425 Real max_SCM_error = 0.;
437 if (error_i > max_SCM_error)
439 max_SCM_error = error_i;
445 std::pair<numeric_index_type,Real> error_pair(global_index, max_SCM_error);
453 LOG_SCOPE(
"enrich_C_J()",
"RBSCMConstruction");
466 const std::string & param_name = pr.first;
virtual void solve() override
Override to solve the condensed eigenproblem with the dofs in local_non_condensed_dofs_vector strippe...
void initialize_condensed_dofs(const std::set< dof_id_type > &global_condensed_dofs_set=std::set< dof_id_type >())
Loop over the dofs on each processor to initialize the list of non-condensed dofs.
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i) override
Override get_eigenpair() to retrieve the eigenpair for the condensed eigensolve.
bool is_constrained_dof(const dof_id_type dof) const
SparseMatrix< Number > * matrix_A
The system matrix for standard eigenvalue problems.
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the current eigen problem.
SparseMatrix< Number > * matrix_B
A second system matrix for generalized eigenvalue problems.
unsigned int get_n_converged() const
const SparseMatrix< Number > & get_matrix_A() const
std::unique_ptr< EigenSolver< Number > > eigen_solver
The EigenSolver, defining which interface, i.e solver package to use.
This is the EquationSystems class.
const T_sys & get_system(std::string_view name) const
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
virtual T dot(const NumericVector< T > &v) const =0
const Parallel::Communicator & comm() const
virtual void set_params_from_training_set_and_broadcast(unsigned int global_index)
Load the specified training parameter and then broadcast to all processors.
void set_training_random_seed(int seed)
Set the seed that is used to randomly generate training parameters.
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...
virtual void clear()
Clear all the data structures associated with the system.
numeric_index_type get_first_local_training_index() const
Get the first local index of the training parameters.
numeric_index_type get_local_n_training_samples() const
Get the total number of training samples local to this processor.
numeric_index_type get_n_training_samples() const
Get the number of global training samples.
virtual void initialize_training_parameters(const RBParameters &mu_min, const RBParameters &mu_max, const unsigned int n_global_training_samples, const std::map< std::string, bool > &log_param_scale, const bool deterministic=true)
Initialize the parameter ranges and indicate whether deterministic or random training parameters shou...
void set_params_from_training_set(unsigned int global_index)
Set parameters to the RBParameters stored in index global_index of the global training set.
static void get_global_max_error_pair(const Parallel::Communicator &communicator, std::pair< numeric_index_type, Real > &error_pair)
Static function to return the error pair (index,error) that is corresponds to the largest error on al...
This class is part of the rbOOmit framework.
SparseMatrix< Number > * get_inner_product_matrix()
Get a pointer to inner_product_matrix.
void add_scaled_Aq(Number scalar, unsigned int q_a, SparseMatrix< Number > *input_matrix, bool symmetrize)
Add the scaled q^th affine matrix to input_matrix.
This class is part of the rbOOmit framework.
Real get_value(const std::string ¶m_name) const
Get the value of the specified parameter, throw an error if it does not exist.
void set_value(const std::string ¶m_name, Real value)
Set the value of the specified parameter.
const RBParameters & get_parameters_max() const
Get an RBParameters object that specifies the maximum allowable value for each parameter.
const RBParameters & get_parameters() const
Get the current parameters.
unsigned int get_n_params() const
Get the number of parameters.
bool set_parameters(const RBParameters ¶ms)
Set the current parameters to params The parameters are checked for validity; an error is thrown if t...
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.
Real get_parameter_max(const std::string ¶m_name) const
Get maximum allowable value of parameter param_name.
void print_discrete_parameter_values() const
Print out all the discrete parameter values.
const RBParameters & get_parameters_min() const
Get an RBParameters object that specifies the minimum allowable value for each parameter.
Real get_parameter_min(const std::string ¶m_name) const
Get minimum allowable value of parameter param_name.
void set_rb_scm_evaluation(RBSCMEvaluation &rb_scm_eval_in)
Set the RBSCMEvaluation object.
virtual ~RBSCMConstruction()
virtual void print_info()
Print out info that describes the current setup of this RBSCMConstruction.
virtual void compute_SCM_bounding_box()
Compute the SCM bounding box.
RBSCMConstruction(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
Constructor.
virtual void load_matrix_B()
Copy over the matrix to store in matrix_B, usually this is the mass or inner-product matrix,...
RBSCMEvaluation * rb_scm_eval
The current RBSCMEvaluation object we are using to perform the Evaluation stage of the SCM.
Real SCM_training_tolerance
Tolerance which controls when to terminate the SCM Greedy.
virtual Real SCM_greedy_error_indicator(Real LB, Real UB)
Helper function which provides an error indicator to be used in the SCM greedy.
virtual void attach_deflation_space()
Attach the deflation space defined by the specified vector, can be useful in solving constrained eige...
virtual void set_eigensolver_properties(int)
This function is called before truth eigensolves in compute_SCM_bounding_box and evaluate_stability_c...
std::string RB_system_name
The name of the associated RB system.
Real get_SCM_training_tolerance() const
Get/set SCM_training_tolerance: tolerance for SCM greedy.
RBSCMEvaluation & get_rb_scm_evaluation()
Get a reference to the RBSCMEvaluation object.
virtual void process_parameters_file(const std::string ¶meters_filename)
Read in the parameters from file specified by parameters_filename and set the this system's member va...
virtual void add_scaled_symm_Aq(unsigned int q_a, Number scalar)
Add the scaled symmetrized affine matrix from the associated RBSystem to matrix_A.
Number Aq_inner_product(unsigned int q, const NumericVector< Number > &v, const NumericVector< Number > &w)
Compute the inner product between two vectors using matrix Aq.
void set_SCM_training_tolerance(Real SCM_training_tolerance_in)
virtual void enrich_C_J(unsigned int new_C_J_index)
Enrich C_J by adding the element of SCM_training_samples that has the largest gap between alpha_LB an...
virtual void perform_SCM_greedy()
Perform the SCM greedy algorithm to develop a lower bound over the training set.
Number B_inner_product(const NumericVector< Number > &v, const NumericVector< Number > &w) const
Compute the inner product between two vectors using the system's matrix_B.
virtual std::pair< unsigned int, Real > compute_SCM_bounds_on_training_set()
Compute upper and lower bounds for each SCM training point.
virtual void evaluate_stability_constant()
Compute the stability constant for current_parameters by solving a generalized eigenvalue problem ove...
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the RBThetaExpansion object.
virtual void clear() override
Clear all the data structures associated with the system.
virtual void resize_SCM_vectors()
Clear and resize the SCM data vectors.
This class is part of the rbOOmit framework.
Real get_B_min(unsigned int i) const
Get B_min and B_max.
Real get_C_J_stability_constraint(unsigned int j) const
Get stability constraints (i.e.
std::vector< Real > B_max
virtual Real get_SCM_LB()
Evaluate single SCM lower bound.
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the rb_theta_expansion.
Real get_B_max(unsigned int i) const
void set_SCM_UB_vector(unsigned int j, unsigned int q, Real y_q)
Set entries of SCM_UB_vector, which stores the vector y, corresponding to the minimizing eigenvectors...
virtual Real get_SCM_UB()
Evaluate single SCM upper bound.
void set_B_max(unsigned int i, Real B_max_val)
std::vector< Real > C_J_stability_vector
Vector storing the (truth) stability values at the parameters in C_J.
std::vector< Real > B_min
B_min, B_max define the bounding box.
void set_C_J_stability_constraint(unsigned int j, Real stability_constraint_in)
Set stability constraints (i.e.
std::vector< std::vector< Real > > SCM_UB_vectors
This matrix stores the infimizing vectors y_1( ),...,y_Q_a( ), for each in C_J, which are used in co...
void set_B_min(unsigned int i, Real B_min_val)
Set B_min and B_max.
std::vector< RBParameters > C_J
Vector storing the greedily selected parameters during SCM training.
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
unsigned int get_n_A_terms() const
Get Q_a, the number of terms in the affine expansion for the bilinear form.
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const
Multiplies the matrix by the NumericVector arg and stores the result in NumericVector dest.
virtual void zero()=0
Set all entries to 0.
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
const std::string & name() const
dof_id_type n_dofs() const
bool assemble_before_solve
Flag which tells the system to whether or not to call the user assembly function during each call to ...
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
const DofMap & get_dof_map() const
const EquationSystems & get_equation_systems() const
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type numeric_index_type
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real