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"
38class RBThetaExpansion;
39class RBAssemblyExpansion;
62 const std::string &
name,
63 const unsigned int number);
136 virtual void clear ()
override;
324 bool skip_vector_assembly=
false);
373 bool skip_vector_assembly);
404 const bool write_binary_residual_representors);
413 const bool write_binary_residual_representors);
436 bool deterministic_training_in,
437 int training_parameters_random_seed_in,
439 unsigned int Nmax_in,
440 Real rel_training_tolerance_in,
441 Real abs_training_tolerance_in,
442 bool normalize_rb_error_bound_in_greedy_in,
443 const std::string & RB_training_type_in,
446 const std::map<std::string, std::vector<Real>> & discrete_parameter_values_in,
447 const std::map<std::string,bool> & log_scaling,
448 std::map<std::string, std::vector<RBParameter>> * training_sample_list=
nullptr);
498#ifdef LIBMESH_ENABLE_DIRICHLET
692 Real initial_greedy_error,
712 bool symmetrize=
false,
713 bool apply_dof_constraints=
true);
829 libmesh_deprecated();
936 std::vector<std::unique_ptr<SparseMatrix<Number>>>
Aq_vector;
942 std::vector<std::unique_ptr<NumericVector<Number>>>
Fq_vector;
This class extends FEMContext in order to provide extra data required to perform local element residu...
ElemAssembly provides a per-element (interior and boundary) assembly functionality.
This is the EquationSystems class.
This class provides all data required for a physics package (e.g.
This base class can be inherited from to provide interfaces to linear solvers from different packages...
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
This class stores the set of ElemAssembly functor objects that define the "parameter-independent expa...
This class is part of the rbOOmit framework.
This class is part of the rbOOmit framework.
virtual bool is_serial_training_type(const std::string &RB_training_type_in)
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 ...
RBConstruction sys_type
The type of system.
SparseMatrix< Number > * get_inner_product_matrix()
Get a pointer to inner_product_matrix.
bool _preevaluate_thetas_completed
Flag to indicate if the preevaluate_thetas function has been called, since this allows us to avoid ca...
RBConstruction & operator=(const RBConstruction &)=delete
ElemAssembly & get_inner_product_assembly()
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.
void enrich_basis_from_rhs_terms(const bool resize_rb_eval_data=true)
This function computes one basis function for each rhs term.
void set_convergence_assertion_flag(bool flag)
Setter for the flag determining if convergence should be checked after each solve.
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.
bool get_convergence_assertion_flag() const
Getter for the flag determining if convergence should be checked after each solve.
virtual void allocate_data_structures()
Helper function that actually allocates all the data structures required by this class.
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.
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the RBThetaExpansion object that that belongs to rb_eval.
std::unique_ptr< SparseMatrix< Number > > inner_product_matrix
The inner product matrix.
virtual void update_RB_system_matrices()
Compute the reduced basis matrices for the current basis.
std::vector< Number > Fq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online.
void print_basis_function_orthogonality() const
Print out a matrix that shows the orthogonality of the RB basis functions.
bool get_preevaluate_thetas_flag() const
Get/set flag to pre-evaluate the theta functions.
RBConstruction(RBConstruction &&)=default
Special functions.
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.
virtual void set_Nmax(unsigned int Nmax)
virtual Real compute_max_error_bound()
(i) Compute the a posteriori error bound for each set of parameters in the training set,...
bool skip_residual_in_train_reduced_basis
Boolean flag to indicate if we skip residual calculations in train_reduced_basis.
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...
virtual void assemble_all_affine_operators()
Assemble and store all Q_a affine operators as well as the inner-product matrix.
void update_greedy_param_list()
Update the list of Greedily chosen parameters with current_parameters.
void set_rb_evaluation(RBEvaluation &rb_eval_in)
Set the RBEvaluation object.
const RBParameters & get_greedy_parameter(unsigned int i)
Return the parameters chosen during the i^th step of the Greedy algorithm.
NumericVector< Number > * get_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to the n^th output.
virtual std::string system_type() const override
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.
virtual Real truth_solve(int plot_solution)
Perform a "truth" solve, i.e.
virtual void print_info() const
Print out info that describes the current setup of this RBConstruction.
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 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.
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_context_solution_vec(NumericVector< Number > &vec)
Set current_local_solution = vec so that we can access vec from FEMContext during assembly.
virtual std::unique_ptr< DGFEMContext > build_context()
Builds a DGFEMContext object with enough information to do evaluations on each element.
virtual void update_system()
Update the system after enriching the RB space; this calls a series of functions to update the system...
bool store_dirichlet_operators
Boolean flag to indicate whether we store affine operator matrices and vectors with constraints enfor...
Real get_rel_training_tolerance() const
virtual void assemble_misc_matrices()
Assemble and store all the inner-product matrix, the constraint matrix (for constrained problems) and...
virtual void assemble_affine_expansion(bool skip_matrix_assembly, bool skip_vector_assembly)
Assemble the matrices and vectors for this system.
NumericVector< Number > * get_non_dirichlet_Fq(unsigned int q)
Get a pointer to non-Dirichlet Fq.
void check_convergence(LinearSolver< Number > &input_solver)
Check if the linear solver reports convergence.
bool use_empty_rb_solve_in_greedy
A boolean flag to indicate whether or not we initialize the Greedy algorithm by performing rb_solves ...
std::vector< std::unique_ptr< NumericVector< Number > > > Fq_vector
Vector storing the Q_f vectors in the affine decomposition of the right-hand side.
std::string RB_training_type
This string indicates the type of training that we will use.
virtual void post_process_truth_solution()
Similarly, provide an opportunity to post-process the truth solution after the solve is complete.
RBEvaluation * rb_eval
The current RBEvaluation object we are using to perform the Evaluation stage of the reduced basis met...
bool compute_RB_inner_product
Boolean flag to indicate whether we compute the RB_inner_product_matrix.
const std::vector< Number > & get_evaluated_thetas(unsigned int training_parameter_index) const
Return the evaluated theta functions at the given training parameter index.
RBEvaluation & get_rb_evaluation()
Get a reference to the RBEvaluation object.
void train_reduced_basis_with_POD()
Train the reduced basis using Proper Orthogonal Decomposition (POD).
virtual void preevaluate_thetas()
virtual ~RBConstruction()
bool normalize_rb_bound_in_greedy
This boolean indicates if we normalize the RB error in the greedy using RBEvaluation::get_error_bound...
virtual Real get_RB_error_bound()
std::vector< Number > energy_inner_product_coeffs
We may optionally want to use the "energy inner-product" rather than the inner-product assembly speci...
std::vector< std::unique_ptr< SparseMatrix< Number > > > Aq_vector
Vector storing the Q_a matrices from the affine expansion.
virtual void init_context(FEMContext &)
Initialize the FEMContext prior to performing an element loop.
virtual void compute_output_dual_innerprods()
Compute and store the dual norm of each output functional.
bool impose_internal_fluxes
Boolean flag to indicate whether we impose "fluxes" (i.e.
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.
Real train_reduced_basis_with_greedy(const bool resize_rb_eval_data)
Train the reduced basis using the "Greedy algorithm.".
SparseMatrix< Number > * get_non_dirichlet_Aq(unsigned int q)
Get a pointer to non_dirichlet_Aq.
Real get_abs_training_tolerance() const
void set_inner_product_assembly(ElemAssembly &inner_product_assembly_in)
Set the rb_assembly_expansion object.
std::vector< std::vector< Number > > output_dual_innerprods
The vector storing the dual norm inner product terms for each output.
bool skip_degenerate_sides
In some cases meshes are intentionally created with degenerate sides as a way to represent,...
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.
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.
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 ...
std::unique_ptr< NumericVector< Number > > _untransformed_solution
We also store a copy of the untransformed solution in order to create _untransformed_basis_functions.
bool output_dual_innerprods_computed
A boolean flag to indicate whether or not the output dual norms have already been computed — used to ...
void set_rb_assembly_expansion(RBAssemblyExpansion &rb_assembly_expansion_in)
Set the rb_assembly_expansion object.
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > outputs_vector
The libMesh vectors that define the output functionals.
void set_current_training_parameter_index(unsigned int index)
NumericVector< Number > * get_Fq(unsigned int q)
Get a pointer to Fq.
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
Train the reduced basis.
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...
virtual void load_basis_function(unsigned int i)
Load the i^th RB function into the RBConstruction solution vector.
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.
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 ...
RBConstructionBase< LinearImplicitSystem > Parent
The type of the parent.
virtual bool check_if_zero_truth_solve() const
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.
RBAssemblyExpansion & get_rb_assembly_expansion()
RBConstruction(const RBConstruction &)=delete
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.
LinearSolver< Number > * extra_linear_solver
Also, we store a pointer to an extra linear solver.
unsigned int get_Nmax() const
Get/set Nmax, the maximum number of RB functions we are willing to compute.
std::vector< Real > training_error_bounds
Vector storing the values of the error bound for each parameter in the training set — the parameter g...
void set_abs_training_tolerance(Real new_training_tolerance)
Get/set the absolute tolerance for the basis training.
void reset_preevaluate_thetas_completed()
Reset the _preevaluate_thetas_completed flag to false.
void set_rel_training_tolerance(Real new_training_tolerance)
Get/set the relative tolerance for the basis training.
std::vector< Number > truth_outputs
Vector storing the truth output values from the most recent truth solve.
std::vector< std::vector< Number > > _evaluated_thetas
Storage of evaluated theta functions at a set of parameters.
virtual void get_output_vectors(std::map< std::string, NumericVector< Number > * > &all_vectors)
Get a map that stores pointers to all of the vectors.
virtual void assemble_all_affine_vectors()
Assemble and store the affine RHS vectors.
Real rel_training_tolerance
Relative and absolute tolerances for training reduced basis using the Greedy scheme.
bool use_energy_inner_product
Boolean to indicate whether we're using the energy inner-product.
virtual SparseMatrix< Number > & get_matrix_for_output_dual_solves()
Return the matrix for the output residual dual norm solves.
virtual void load_rb_solution()
Load the RB solution from the most recent solve with rb_eval into this system's solution vector.
virtual void get_all_vectors(std::map< std::string, NumericVector< Number > * > &all_vectors)
Get a map that stores pointers to all of the vectors.
virtual void enrich_RB_space()
Add a new basis function to the RB space.
const std::string & get_RB_training_type() const
bool store_untransformed_basis
Boolean flag to indicate whether we store a second copy of the basis without constraints or dof trans...
void set_RB_training_type(const std::string &RB_training_type_in)
Get/set the string that determines the training type.
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.
virtual void assemble_all_output_vectors()
Assemble and store the output vectors.
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.
bool Fq_representor_innerprods_computed
A boolean flag to indicate whether or not the Fq representor norms have already been computed — used ...
std::vector< std::unique_ptr< NumericVector< Number > > > Fq_representor
Vector storing the residual representors associated with the right-hand side.
SparseMatrix< Number > * get_non_dirichlet_inner_product_matrix()
Get the non-Dirichlet (or more generally no-constraints) version of the inner-product matrix.
std::unique_ptr< SparseMatrix< Number > > non_dirichlet_inner_product_matrix
std::vector< std::unique_ptr< NumericVector< Number > > > non_dirichlet_Fq_vector
RBAssemblyExpansion * rb_assembly_expansion
This member holds the (parameter independent) assembly functors that define the "affine expansion" of...
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.
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)
Real abs_training_tolerance
virtual void truth_assembly()
Assemble the truth matrix and right-hand side for current_parameters.
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 get_normalize_rb_bound_in_greedy() const
unsigned int Nmax
Maximum number of reduced basis functions we are willing to use.
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > non_dirichlet_outputs_vector
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 store_non_dirichlet_operators
Boolean flag to indicate whether we store a second copy of each affine operator and vector which does...
bool _preevaluate_thetas_flag
Flag to indicate if we preevaluate the theta functions.
virtual void get_all_matrices(std::map< std::string, SparseMatrix< Number > * > &all_matrices)
Get a map that stores pointers to all of the matrices.
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...
bool is_rb_eval_initialized() const
unsigned int _current_training_parameter_index
The current training parameter index during reduced basis training.
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...
SparseMatrix< Number > * get_Aq(unsigned int q)
Get a pointer to Aq.
unsigned int delta_N
The number of basis functions that we add at each greedy step.
NumericVector< Number > * get_non_dirichlet_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to non-Dirichlet output vector.
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...
virtual void clear() override
Clear all the data structures associated with the system.
ElemAssembly * inner_product_assembly
Pointer to inner product assembly.
unsigned int get_current_training_parameter_index() const
Get/set the current training parameter index.
bool assert_convergence
A boolean flag to indicate whether to check for proper convergence after each solve.
This class is part of the rbOOmit framework.
This class is part of the rbOOmit framework.
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
const std::string & name() const
unsigned int number() const
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real