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" 40 #include <sys/types.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);
248 #endif // LIBMESH_ENABLE_CONSTRAINTS 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;
483 #endif // LIBMESH_HAVE_SLEPC && LIBMESH_HAVE_GLPK
std::vector< Real > B_min
B_min, B_max define the bounding box.
Real get_value(const std::string ¶m_name) const
Get the value of the specified parameter, throw an error if it does not exist.
numeric_index_type get_first_local_training_index() const
Get the first local index of the training parameters.
virtual Real get_SCM_UB()
Evaluate single SCM upper bound.
This is the EquationSystems class.
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.
SparseMatrix< Number > * matrix_B
A second system matrix for generalized eigenvalue problems.
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...
const SparseMatrix< Number > & get_matrix_A() const
static constexpr Real TOLERANCE
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...
Real get_parameter_min(const std::string ¶m_name) const
Get minimum allowable value of parameter param_name.
Real get_parameter_max(const std::string ¶m_name) const
Get maximum allowable value of parameter param_name.
Real get_B_min(unsigned int i) const
Get B_min and B_max.
const RBParameters & get_parameters_max() const
Get an RBParameters object that specifies the maximum allowable value for each parameter.
const EquationSystems & get_equation_systems() const
Real get_SCM_training_tolerance() const
Get/set SCM_training_tolerance: tolerance for SCM greedy.
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...
unsigned int get_n_A_terms() const
Get Q_a, the number of terms in the affine expansion for the bilinear form.
const Parallel::Communicator & comm() const
virtual void evaluate_stability_constant()
Compute the stability constant for current_parameters by solving a generalized eigenvalue problem ove...
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.
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...
virtual ~RBSCMConstruction()
The libMesh namespace provides an interface to certain functionality in the library.
virtual T dot(const NumericVector< T > &v) const =0
const T_sys & get_system(std::string_view name) const
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the rb_theta_expansion.
std::vector< Real > B_max
RBSCMEvaluation * rb_scm_eval
The current RBSCMEvaluation object we are using to perform the Evaluation stage of the SCM...
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
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...
virtual void solve() override
Override to solve the condensed eigenproblem with the dofs in local_non_condensed_dofs_vector strippe...
dof_id_type n_dofs() const
std::vector< Real > C_J_stability_vector
Vector storing the (truth) stability values at the parameters in C_J.
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...
Real SCM_training_tolerance
Tolerance which controls when to terminate the SCM Greedy.
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
virtual Real get_SCM_LB()
Evaluate single SCM lower bound.
virtual void print_info()
Print out info that describes the current setup of this RBSCMConstruction.
void set_rb_scm_evaluation(RBSCMEvaluation &rb_scm_eval_in)
Set the RBSCMEvaluation object.
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 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_training_random_seed(int seed)
Set the seed that is used to randomly generate training parameters.
virtual void load_matrix_B()
Copy over the matrix to store in matrix_B, usually this is the mass or inner-product matrix...
virtual void zero()=0
Set all entries to 0.
const RBParameters & get_parameters_min() const
Get an RBParameters object that specifies the minimum allowable value for each parameter.
dof_id_type numeric_index_type
std::string RB_system_name
The name of the associated RB system.
std::vector< RBParameters > C_J
Vector storing the greedily selected parameters during SCM training.
void set_B_min(unsigned int i, Real B_min_val)
Set B_min and B_max.
SparseMatrix< Number > * get_inner_product_matrix()
Get a pointer to inner_product_matrix.
void set_C_J_stability_constraint(unsigned int j, Real stability_constraint_in)
Set stability constraints (i.e.
virtual Real SCM_greedy_error_indicator(Real LB, Real UB)
Helper function which provides an error indicator to be used in the SCM greedy.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
numeric_index_type get_local_n_training_samples() const
Get the total number of training samples local to this processor.
virtual void attach_deflation_space()
Attach the deflation space defined by the specified vector, can be useful in solving constrained eige...
bool is_constrained_dof(const dof_id_type dof) const
SparseMatrix< Number > * matrix_A
The system matrix for standard eigenvalue problems.
virtual void set_eigensolver_properties(int)
This function is called before truth eigensolves in compute_SCM_bounding_box and evaluate_stability_c...
RBSCMConstruction(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
Constructor.
const RBParameters & get_parameters() const
Get the current parameters.
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.
This class is part of the rbOOmit framework.
numeric_index_type get_n_training_samples() const
Get the number of global training samples.
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...
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the RBThetaExpansion object.
virtual std::pair< unsigned int, Real > compute_SCM_bounds_on_training_set()
Compute upper and lower bounds for each SCM training point.
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...
bool set_parameters(const RBParameters ¶ms)
Set the current parameters to params The parameters are checked for validity; an error is thrown if t...
virtual void resize_SCM_vectors()
Clear and resize the SCM data vectors.
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
void set_SCM_training_tolerance(Real SCM_training_tolerance_in)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void perform_SCM_greedy()
Perform the SCM greedy algorithm to develop a lower bound over the training set.
void set_B_max(unsigned int i, Real B_max_val)
Real get_C_J_stability_constraint(unsigned int j) const
Get stability constraints (i.e.
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.
std::unique_ptr< EigenSolver< Number > > eigen_solver
The EigenSolver, defining which interface, i.e solver package to use.
void set_value(const std::string ¶m_name, Real value)
Set the value of the specified parameter.
virtual void compute_SCM_bounding_box()
Compute the SCM bounding box.
virtual std::pair< Real, Real > get_eigenpair(dof_id_type i) override
Override get_eigenpair() to retrieve the eigenpair for the condensed eigensolve.
RBSCMEvaluation & get_rb_scm_evaluation()
Get a reference to the RBSCMEvaluation object.
Real get_B_max(unsigned int i) const
void set_eigenproblem_type(EigenProblemType ept)
Sets the type of the current eigen problem.
This class is part of the rbOOmit framework.
unsigned int get_n_converged() const
const std::string & name() const
bool assemble_before_solve
Flag which tells the system to whether or not to call the user assembly function during each call to ...
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.
const DofMap & get_dof_map() const
unsigned int get_n_params() const
Get the number of parameters.
virtual void set_params_from_training_set_and_broadcast(unsigned int global_index)
Load the specified training parameter and then broadcast to all processors.
virtual void clear()
Clear all the data structures associated with the system.
virtual void clear() override
Clear all the data structures associated with the system.
This class is part of the rbOOmit framework.
void print_discrete_parameter_values() const
Print out all the discrete parameter values.