20 #ifndef LIBMESH_RB_CONSTRUCTION_H 21 #define LIBMESH_RB_CONSTRUCTION_H 24 #include "libmesh/rb_construction_base.h" 27 #include "libmesh/linear_implicit_system.h" 28 #include "libmesh/dense_vector.h" 29 #include "libmesh/dense_matrix.h" 30 #include "libmesh/dg_fem_context.h" 31 #include "libmesh/dirichlet_boundaries.h" 38 class RBThetaExpansion;
39 class RBAssemblyExpansion;
62 const std::string &
name,
63 const unsigned int number);
136 virtual void clear ()
override;
317 bool skip_vector_assembly=
false);
366 bool skip_vector_assembly);
397 const bool write_binary_residual_representors);
406 const bool write_binary_residual_representors);
429 bool deterministic_training_in,
430 int training_parameters_random_seed_in,
432 unsigned int Nmax_in,
433 Real rel_training_tolerance_in,
434 Real abs_training_tolerance_in,
435 bool normalize_rb_error_bound_in_greedy_in,
436 const std::string & RB_training_type_in,
439 const std::map<std::string, std::vector<Real>> & discrete_parameter_values_in,
440 const std::map<std::string,bool> & log_scaling,
441 std::map<std::string, std::vector<RBParameter>> * training_sample_list=
nullptr);
491 #ifdef LIBMESH_ENABLE_DIRICHLET 676 Real initial_greedy_error,
696 bool symmetrize=
false,
697 bool apply_dof_constraints=
true);
813 libmesh_deprecated();
920 std::vector<std::unique_ptr<SparseMatrix<Number>>>
Aq_vector;
926 std::vector<std::unique_ptr<NumericVector<Number>>>
Fq_vector;
1007 #endif // LIBMESH_RB_CONSTRUCTION_H virtual void read_riesz_representors_from_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors)
Read in all the Riesz representor data from files.
Real compute_residual_dual_norm_slow(const unsigned int N)
The slow (but simple, non-error prone) way to compute the residual dual norm.
bool normalize_rb_bound_in_greedy
This boolean indicates if we normalize the RB error in the greedy using RBEvaluation::get_error_bound...
virtual void initialize_rb_construction(bool skip_matrix_assembly=false, bool skip_vector_assembly=false)
Allocate all the data structures necessary for the construction stage of the RB method.
This is the EquationSystems class.
std::vector< Real > training_error_bounds
Vector storing the values of the error bound for each parameter in the training set — the parameter ...
bool get_normalize_rb_bound_in_greedy() const
virtual void truth_assembly()
Assemble the truth matrix and right-hand side for current_parameters.
void set_RB_training_type(const std::string &RB_training_type_in)
Get/set the string that determines the training type.
void zero_constrained_dofs_on_vector(NumericVector< Number > &vector) const
It is sometimes useful to be able to zero vector entries that correspond to constrained dofs...
void set_energy_inner_product(const std::vector< Number > &energy_inner_product_coeffs_in)
Specify the coefficients of the A_q operators to be used in the energy inner-product.
std::vector< std::vector< Number > > _evaluated_thetas
Storage of evaluated theta functions at a set of parameters.
std::vector< std::unique_ptr< NumericVector< Number > > > Fq_representor
Vector storing the residual representors associated with the right-hand side.
virtual void post_process_elem_matrix_and_vector(DGFEMContext &)
This function is called from add_scaled_matrix_and_vector() before each element matrix and vector are...
bool assert_convergence
A boolean flag to indicate whether to check for proper convergence after each solve.
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
Train the reduced basis.
virtual ~RBConstruction()
virtual void get_all_matrices(std::map< std::string, SparseMatrix< Number > *> &all_matrices)
Get a map that stores pointers to all of the matrices.
std::vector< std::unique_ptr< NumericVector< Number > > > _untransformed_basis_functions
In cases where we have dof transformations such as a change of coordinates at some nodes we need to s...
void set_preevaluate_thetas_flag(bool flag)
virtual Real truth_solve(int plot_solution)
Perform a "truth" solve, i.e.
RBConstruction(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
SparseMatrix< Number > * get_Aq(unsigned int q)
Get a pointer to Aq.
bool compute_RB_inner_product
Boolean flag to indicate whether we compute the RB_inner_product_matrix.
virtual void set_context_solution_vec(NumericVector< Number > &vec)
Set current_local_solution = vec so that we can access vec from FEMContext during assembly...
void enrich_basis_from_rhs_terms(const bool resize_rb_eval_data=true)
This function computes one basis function for each rhs term.
std::vector< std::vector< Number > > output_dual_innerprods
The vector storing the dual norm inner product terms for each output.
ElemAssembly & get_inner_product_assembly()
bool get_convergence_assertion_flag() const
Getter for the flag determining if convergence should be checked after each solve.
bool skip_degenerate_sides
In some cases meshes are intentionally created with degenerate sides as a way to represent, say, triangles using a hex-only mesh.
virtual bool greedy_termination_test(Real abs_greedy_error, Real initial_greedy_error, int count)
Function that indicates when to terminate the Greedy basis training.
RBConstructionBase< LinearImplicitSystem > Parent
The type of the parent.
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.
const RBParameters & get_greedy_parameter(unsigned int i)
Return the parameters chosen during the i^th step of the Greedy algorithm.
std::string RB_training_type
This string indicates the type of training that we will use.
SparseMatrix< Number > * get_non_dirichlet_inner_product_matrix()
Get the non-Dirichlet (or more generally no-constraints) version of the inner-product matrix...
NumericVector< Number > * get_non_dirichlet_Fq_if_avail(unsigned int q)
Get a pointer to non_dirichlet_Fq if it's available, otherwise get Fq.
virtual std::unique_ptr< DGFEMContext > build_context()
Builds a DGFEMContext object with enough information to do evaluations on each element.
std::unique_ptr< SparseMatrix< Number > > inner_product_matrix
The inner product matrix.
const std::string & get_RB_training_type() const
The libMesh namespace provides an interface to certain functionality in the library.
NumericVector< Number > * get_Fq(unsigned int q)
Get a pointer to Fq.
std::vector< Number > Fq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online...
unsigned int get_current_training_parameter_index() const
Get/set the current training parameter index.
Real get_rel_training_tolerance() const
void reset_preevaluate_thetas_completed()
Reset the _preevaluate_thetas_completed flag to false.
virtual void print_info() const
Print out info that describes the current setup of this RBConstruction.
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
static std::unique_ptr< DirichletBoundary > build_zero_dirichlet_boundary_object()
It's helpful to be able to generate a DirichletBoundary that stores a ZeroFunction in order to impose...
std::vector< Number > energy_inner_product_coeffs
We may optionally want to use the "energy inner-product" rather than the inner-product assembly speci...
virtual void init_context(FEMContext &)
Initialize the FEMContext prior to performing an element loop.
virtual Real compute_max_error_bound()
(i) Compute the a posteriori error bound for each set of parameters in the training set...
void print_basis_function_orthogonality() const
Print out a matrix that shows the orthogonality of the RB basis functions.
std::vector< std::unique_ptr< NumericVector< Number > > > non_dirichlet_Fq_vector
virtual void get_output_vectors(std::map< std::string, NumericVector< Number > *> &all_vectors)
Get a map that stores pointers to all of the vectors.
void set_rb_construction_parameters(unsigned int n_training_samples_in, bool deterministic_training_in, int training_parameters_random_seed_in, bool quiet_mode_in, unsigned int Nmax_in, Real rel_training_tolerance_in, Real abs_training_tolerance_in, bool normalize_rb_error_bound_in_greedy_in, const std::string &RB_training_type_in, const RBParameters &mu_min_in, const RBParameters &mu_max_in, const std::map< std::string, std::vector< Real >> &discrete_parameter_values_in, const std::map< std::string, bool > &log_scaling, std::map< std::string, std::vector< RBParameter >> *training_sample_list=nullptr)
Set the state of this RBConstruction object based on the arguments to this function.
void assemble_inner_product_matrix(SparseMatrix< Number > *input_matrix, bool apply_dof_constraints=true)
Assemble the inner product matrix and store it in input_matrix.
LinearSolver< Number > * extra_linear_solver
Also, we store a pointer to an extra linear solver.
virtual void recompute_all_residual_terms(const bool compute_inner_products=true)
This function computes all of the residual representors, can be useful when restarting a basis traini...
virtual void load_basis_function(unsigned int i)
Load the i^th RB function into the RBConstruction solution vector.
virtual void solve_for_matrix_and_rhs(LinearSolver< Number > &input_solver, SparseMatrix< Number > &input_matrix, NumericVector< Number > &input_rhs)
Assembles & solves the linear system A*x=b for the specified matrix input_matrix and right-hand side ...
bool impose_internal_fluxes
Boolean flag to indicate whether we impose "fluxes" (i.e.
bool Fq_representor_innerprods_computed
A boolean flag to indicate whether or not the Fq representor norms have already been computed — used...
bool use_empty_rb_solve_in_greedy
A boolean flag to indicate whether or not we initialize the Greedy algorithm by performing rb_solves ...
bool use_energy_inner_product
Boolean to indicate whether we're using the energy inner-product.
unsigned int number() const
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the RBThetaExpansion object that that belongs to rb_eval.
bool get_preevaluate_thetas_flag() const
Get/set flag to pre-evaluate the theta functions.
void set_rb_assembly_expansion(RBAssemblyExpansion &rb_assembly_expansion_in)
Set the rb_assembly_expansion object.
std::unique_ptr< SparseMatrix< Number > > non_dirichlet_inner_product_matrix
void update_greedy_param_list()
Update the list of Greedily chosen parameters with current_parameters.
Real rel_training_tolerance
Relative and absolute tolerances for training reduced basis using the Greedy scheme.
unsigned int _current_training_parameter_index
The current training parameter index during reduced basis training.
unsigned int get_Nmax() const
Get/set Nmax, the maximum number of RB functions we are willing to compute.
RBAssemblyExpansion & get_rb_assembly_expansion()
SparseMatrix< Number > * get_inner_product_matrix()
Get a pointer to inner_product_matrix.
Real abs_training_tolerance
virtual void update_RB_system_matrices()
Compute the reduced basis matrices for the current basis.
virtual void update_residual_terms(bool compute_inner_products=true)
Compute the terms that are combined ‘online’ to determine the dual norm of the residual.
bool store_untransformed_basis
Boolean flag to indicate whether we store a second copy of the basis without constraints or dof trans...
void assemble_Fq_vector(unsigned int q, NumericVector< Number > *input_vector, bool apply_dof_constraints=true)
Assemble the q^th affine vector and store it in input_matrix.
RBConstruction sys_type
The type of system.
const std::vector< Number > & get_evaluated_thetas(unsigned int training_parameter_index) const
Return the evaluated theta functions at the given training parameter index.
virtual void update_system()
Update the system after enriching the RB space; this calls a series of functions to update the system...
Real get_abs_training_tolerance() const
This class extends FEMContext in order to provide extra data required to perform local element residu...
virtual SparseMatrix< Number > & get_matrix_for_output_dual_solves()
Return the matrix for the output residual dual norm solves.
This class provides all data required for a physics package (e.g.
NumericVector< Number > * get_non_dirichlet_Fq(unsigned int q)
Get a pointer to non-Dirichlet Fq.
virtual Real get_RB_error_bound()
unsigned int get_delta_N() const
Get delta_N, the number of basis functions we add to the RB space per iteration of the greedy algorit...
SparseMatrix< Number > * get_non_dirichlet_Aq(unsigned int q)
Get a pointer to non_dirichlet_Aq.
void set_inner_product_assembly(ElemAssembly &inner_product_assembly_in)
Set the rb_assembly_expansion object.
std::vector< std::unique_ptr< SparseMatrix< Number > > > Aq_vector
Vector storing the Q_a matrices from the affine expansion.
void add_scaled_matrix_and_vector(Number scalar, ElemAssembly *elem_assembly, SparseMatrix< Number > *input_matrix, NumericVector< Number > *input_vector, bool symmetrize=false, bool apply_dof_constraints=true)
This function loops over the mesh and applies the specified interior and/or boundary assembly routine...
bool skip_residual_in_train_reduced_basis
Boolean flag to indicate if we skip residual calculations in train_reduced_basis. ...
void set_convergence_assertion_flag(bool flag)
Setter for the flag determining if convergence should be checked after each solve.
This class is part of the rbOOmit framework.
bool is_rb_eval_initialized() const
unsigned int delta_N
The number of basis functions that we add at each greedy step.
Real train_reduced_basis_with_greedy(const bool resize_rb_eval_data)
Train the reduced basis using the "Greedy algorithm.".
RBEvaluation * rb_eval
The current RBEvaluation object we are using to perform the Evaluation stage of the reduced basis met...
std::unique_ptr< NumericVector< Number > > _untransformed_solution
We also store a copy of the untransformed solution in order to create _untransformed_basis_functions...
This class is part of the rbOOmit framework.
virtual void post_process_truth_solution()
Similarly, provide an opportunity to post-process the truth solution after the solve is complete...
void set_current_training_parameter_index(unsigned int index)
void set_abs_training_tolerance(Real new_training_tolerance)
Get/set the absolute tolerance for the basis training.
bool store_non_dirichlet_operators
Boolean flag to indicate whether we store a second copy of each affine operator and vector which does...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void clear() override
Clear all the data structures associated with the system.
ElemAssembly * inner_product_assembly
Pointer to inner product assembly.
virtual std::string system_type() const override
void check_convergence(LinearSolver< Number > &input_solver)
Check if the linear solver reports convergence.
std::unique_ptr< LinearSolver< Number > > inner_product_solver
We store an extra linear solver object which we can optionally use for solving all systems in which t...
void set_normalize_rb_bound_in_greedy(bool normalize_rb_bound_in_greedy_in)
Get/set the boolean to indicate if we normalize the RB error in the greedy.
std::vector< std::unique_ptr< NumericVector< Number > > > Fq_vector
Vector storing the Q_f vectors in the affine decomposition of the right-hand side.
This class stores the set of ElemAssembly functor objects that define the "parameter-independent expa...
ElemAssembly provides a per-element (interior and boundary) assembly functionality.
void preevaluate_thetas()
std::vector< Number > truth_outputs
Vector storing the truth output values from the most recent truth solve.
SparseMatrix< Number > * get_non_dirichlet_inner_product_matrix_if_avail()
Get the non-Dirichlet inner-product matrix if it's available, otherwise get the inner-product matrix ...
virtual void compute_Fq_representor_innerprods(bool compute_inner_products=true)
Compute the terms that are combined ‘online’ to determine the dual norm of the residual.
virtual void set_Nmax(unsigned int Nmax)
std::vector< std::unique_ptr< SparseMatrix< Number > > > non_dirichlet_Aq_vector
We may also need a second set of matrices/vectors that do not have the Dirichlet boundary conditions ...
void set_rel_training_tolerance(Real new_training_tolerance)
Get/set the relative tolerance for the basis training.
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > non_dirichlet_outputs_vector
virtual void write_riesz_representors_to_files(const std::string &riesz_representors_dir, const bool write_binary_residual_representors)
Write out all the Riesz representor data to files.
virtual void assemble_all_output_vectors()
Assemble and store the output vectors.
bool _preevaluate_thetas_flag
Flag to indicate if we preevaluate the theta functions.
void assemble_Aq_matrix(unsigned int q, SparseMatrix< Number > *input_matrix, bool apply_dof_constraints=true)
Assemble the q^th affine matrix and store it in input_matrix.
This class is part of the rbOOmit framework.
virtual void process_parameters_file(const std::string ¶meters_filename)
Read in from the file specified by parameters_filename and set the this system's member variables acc...
RBAssemblyExpansion * rb_assembly_expansion
This member holds the (parameter independent) assembly functors that define the "affine expansion" of...
This class is part of the rbOOmit framework.
NumericVector< Number > * get_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to the n^th output.
RBConstruction & operator=(const RBConstruction &)=delete
virtual bool check_if_zero_truth_solve() const
RBEvaluation & get_rb_evaluation()
Get a reference to the RBEvaluation object.
virtual void assemble_misc_matrices()
Assemble and store all the inner-product matrix, the constraint matrix (for constrained problems) and...
virtual void get_all_vectors(std::map< std::string, NumericVector< Number > *> &all_vectors)
Get a map that stores pointers to all of the vectors.
const std::string & name() const
virtual void load_rb_solution()
Load the RB solution from the most recent solve with rb_eval into this system's solution vector...
void set_rb_evaluation(RBEvaluation &rb_eval_in)
Set the RBEvaluation object.
virtual void compute_output_dual_innerprods()
Compute and store the dual norm of each output functional.
bool exit_on_repeated_greedy_parameters
Boolean flag to indicate whether we exit the greedy if we select the same parameters twice in a row...
bool output_dual_innerprods_computed
A boolean flag to indicate whether or not the output dual norms have already been computed — used to...
void train_reduced_basis_with_POD()
Train the reduced basis using Proper Orthogonal Decomposition (POD).
virtual void enrich_RB_space()
Add a new basis function to the RB space.
virtual void assemble_all_affine_vectors()
Assemble and store the affine RHS vectors.
NumericVector< Number > * get_non_dirichlet_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to non-Dirichlet output vector.
virtual void allocate_data_structures()
Helper function that actually allocates all the data structures required by this class.
bool _preevaluate_thetas_completed
Flag to indicate if the preevaluate_thetas function has been called, since this allows us to avoid ca...
SparseMatrix< Number > * get_non_dirichlet_Aq_if_avail(unsigned int q)
Get a pointer to non_dirichlet_Aq if it's available, otherwise get Aq.
unsigned int Nmax
Maximum number of reduced basis functions we are willing to use.
virtual void assemble_affine_expansion(bool skip_matrix_assembly, bool skip_vector_assembly)
Assemble the matrices and vectors for this system.
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > outputs_vector
The libMesh vectors that define the output functionals.
virtual void assemble_all_affine_operators()
Assemble and store all Q_a affine operators as well as the inner-product matrix.