Go to the documentation of this file.
   25 #include "libmesh/sparse_matrix.h" 
   26 #include "libmesh/numeric_vector.h" 
   27 #include "libmesh/dense_matrix.h" 
   28 #include "libmesh/dense_vector.h" 
   29 #include "libmesh/dof_map.h" 
   30 #include "libmesh/libmesh_logging.h" 
   31 #include "libmesh/equation_systems.h" 
   32 #include "libmesh/parallel.h" 
   33 #include "libmesh/parallel_algebra.h" 
   34 #include "libmesh/fe.h" 
   35 #include "libmesh/quadrature.h" 
   36 #include "libmesh/utility.h" 
   37 #include "libmesh/fe_interface.h" 
   38 #include "libmesh/fe_compute_data.h" 
   39 #include "libmesh/getpot.h" 
   40 #include "libmesh/exodusII_io.h" 
   41 #include "libmesh/fem_context.h" 
   42 #include "libmesh/elem.h" 
   43 #include "libmesh/int_range.h" 
   44 #include "libmesh/auto_ptr.h" 
   47 #include "libmesh/rb_eim_construction.h" 
   48 #include "libmesh/rb_eim_evaluation.h" 
   54                                       const std::string & name_in,
 
   55                                       const unsigned int number_in)
 
   56   : 
Parent(es, name_in, number_in),
 
   57     best_fit_type_flag(PROJECTION_BEST_FIT),
 
   58     _parametrized_functions_in_training_set_initialized(false),
 
  116   GetPot infile(parameters_filename);
 
  118   std::string best_fit_type_string = infile(
"best_fit_type",
"projection");
 
  124   if (best_fit_type_string == 
"projection")
 
  129     if (best_fit_type_string == 
"eim")
 
  134       libmesh_error_msg(
"Error: invalid best_fit_type in input file");
 
  142   libMesh::out << std::endl << 
"RBEIMConstruction parameters:" << std::endl;
 
  145       libMesh::out << 
"best fit type: projection" << std::endl;
 
  167                                                    bool skip_vector_assembly)
 
  179   std::vector<unsigned int> vars;
 
  223   unsigned int root_id=0;
 
  224   unsigned int check_for_valid_value = 0;
 
  225   if (values.
size() != 0)
 
  228       value = values(var_number);
 
  229       check_for_valid_value = 1;
 
  234   this->
comm().sum(check_for_valid_value);
 
  235   if (check_for_valid_value == 0)
 
  237       libmesh_error_msg(
"MeshFunction evaluation failed on all processors");
 
  242   this->
comm().max(root_id);
 
  245   this->
comm().broadcast(value, root_id);
 
  274   LOG_SCOPE(
"load_basis_function()", 
"RBEIMConstruction");
 
  285   LOG_SCOPE(
"load_rb_solution()", 
"RBEIMConstruction");
 
  292                       << 
" RB_solution in RBConstruction::load_rb_solution is too long!");
 
  309   LOG_SCOPE(
"enrich_RB_space()", 
"RBEIMConstruction");
 
  327       for (
unsigned int i=0; i<RB_size; i++)
 
  351   Number optimal_value = 0.;
 
  352   unsigned int optimal_var = 0;
 
  356   Real largest_abs_value = -1.;
 
  361   std::unique_ptr<DGFEMContext> explicit_c = libmesh_make_unique<DGFEMContext>(
get_explicit_system());
 
  362   DGFEMContext & explicit_context = cast_ref<DGFEMContext &>(*explicit_c);
 
  365   for (
const auto & elem : 
mesh.active_local_element_ptr_range())
 
  374           for (
unsigned int qp=0; qp<n_qpoints; qp++)
 
  379               if (abs_value > largest_abs_value)
 
  381                   optimal_value = 
value;
 
  382                   largest_abs_value = abs_value;
 
  384                   optimal_elem_id = elem->id();
 
  386                   FEBase * elem_fe = 
nullptr;
 
  388                   optimal_point = elem_fe->
get_xyz()[qp];
 
  396   unsigned int proc_ID_index;
 
  397   this->
comm().maxloc(largest_abs_value, proc_ID_index);
 
  400   this->
comm().broadcast(optimal_point, proc_ID_index);
 
  403   this->
comm().broadcast(optimal_var, proc_ID_index);
 
  404   this->
comm().broadcast(optimal_value, proc_ID_index);
 
  405   this->
comm().broadcast(optimal_elem_id, proc_ID_index);
 
  416   Elem * elem_ptr = 
mesh.elem_ptr(optimal_elem_id);
 
  431       std::unique_ptr<NumericVector<Number>> implicit_sys_temp1 = this->
solution->zero_clone();
 
  432       std::unique_ptr<NumericVector<Number>> implicit_sys_temp2 = this->
solution->zero_clone();
 
  436       std::unique_ptr<NumericVector<Number>> localized_new_bf =
 
  451                                      *implicit_sys_temp2);
 
  461     libmesh_error_msg(
"Error: We must have serial_training_set==true in " \
 
  462                       << 
"RBEIMConstruction::initialize_parametrized_functions_in_training_set");
 
  464   libMesh::out << 
"Initializing parametrized functions in training set..." << std::endl;
 
  481   libMesh::out << 
"Parametrized functions in training set initialized" << std::endl << std::endl;
 
  493 #ifdef LIBMESH_HAVE_EXODUS_API 
  496       std::stringstream pathname_i;
 
  497       pathname_i << pathname << 
"_" << i << 
".exo";
 
  499       std::set<std::string> system_names;
 
  504       libMesh::out << 
"Plotted parameterized function " << i << std::endl;
 
  513   LOG_SCOPE(
"compute_best_fit_error()", 
"RBEIMConstruction");
 
  528         for (
unsigned int i=0; i<RB_size; i++)
 
  553       libmesh_error_msg(
"Should not reach here");
 
  563   return best_fit_error;
 
  568   LOG_SCOPE(
"truth_solve()", 
"RBEIMConstruction");
 
  570   int training_parameters_found_index = -1;
 
  580               training_parameters_found_index = i;
 
  587   if (training_parameters_found_index >= 0)
 
  598           libmesh_error_msg(
"The system that we use to perform EIM L2 solves should have one variable");
 
  607       std::unique_ptr<DGFEMContext> c = libmesh_make_unique<DGFEMContext>(*
this);
 
  612       std::vector<std::vector<std::vector<Number>>> parametrized_fn_vals(
mesh.n_elem());
 
  613       std::vector<std::vector<Real>> JxW_values(
mesh.n_elem());
 
  614       std::vector<std::vector<std::vector<Real>>> phi_values(
mesh.n_elem());
 
  616       for (
const auto & elem : 
mesh.active_local_element_ptr_range())
 
  623           FEBase * elem_fe = 
nullptr;
 
  626           const std::vector<Real> & JxW = elem_fe->
get_JxW();
 
  627           const std::vector<std::vector<Real>> & phi = elem_fe->
get_phi();
 
  628           const std::vector<Point> & xyz = elem_fe->
get_xyz();
 
  632           parametrized_fn_vals[elem_id].resize(n_qpoints);
 
  633           JxW_values[elem_id].resize(n_qpoints);
 
  634           phi_values[elem_id].resize(n_qpoints);
 
  635           for (
unsigned int qp=0; qp<n_qpoints; qp++)
 
  637               JxW_values[elem_id][qp] = JxW[qp];
 
  639               unsigned int n_var_dofs = cast_int<unsigned int>(context.
get_dof_indices().size());
 
  640               phi_values[elem_id][qp].resize(n_var_dofs);
 
  641               for (
unsigned int i=0; i != n_var_dofs; i++)
 
  643                   phi_values[elem_id][qp][i] = phi[i][qp];
 
  650                   parametrized_fn_vals[elem_id][qp][var] = eval_result;
 
  660           for (
const auto & elem : 
mesh.active_local_element_ptr_range())
 
  671                   const unsigned int n_var_dofs =
 
  672                     cast_int<unsigned int>(phi_values[elem_id][qp].size());
 
  674                   Number eval_result = parametrized_fn_vals[elem_id][qp][var];
 
  675                   for (
unsigned int i=0; i != n_var_dofs; i++)
 
  678                         JxW_values[elem_id][qp] * eval_result * phi_values[elem_id][qp][i];
 
  702   if (plot_solution > 0)
 
  704 #ifdef LIBMESH_HAVE_EXODUS_API 
  717   for (
unsigned int var=0; var<sys.
n_vars(); var++)
 
  719       FEBase * elem_fe = 
nullptr;
 
  729   LOG_SCOPE(
"update_RB_system_matrices()", 
"RBEIMConstruction");
 
  735     std::unique_ptr<NumericVector<Number>> explicit_sys_temp =
 
  738     std::unique_ptr<NumericVector<Number>> temp1 = this->
solution->zero_clone();
 
  739     std::unique_ptr<NumericVector<Number>> temp2 = this->
solution->zero_clone();
 
  741     for (
unsigned int i=(RB_size-1); i<RB_size; i++)
 
  743         for (
unsigned int j=0; j<RB_size; j++)
 
  747             std::unique_ptr<NumericVector<Number>> localized_basis_function =
 
  777   for (
unsigned int j=0; j<RB_size; j++)
 
  793   return best_fit_error;
 
  806   LOG_SCOPE(
"set_explicit_sys_subvector()", 
"RBEIMConstruction");
 
  810   std::unique_ptr<NumericVector<Number>> localized_source =
 
  822         dest.
set(explicit_sys_dof_index,
 
  823                  (*localized_source)(implicit_sys_dof_index));
 
  833   LOG_SCOPE(
"get_explicit_sys_subvector()", 
"RBEIMConstruction");
 
  842         dest.
set(implicit_sys_dof_index,
 
  843                  localized_source(explicit_sys_dof_index));
 
  851   LOG_SCOPE(
"init_dof_map_between_systems()", 
"RBEIMConstruction");
 
  854   unsigned int n_sys_dofs = this->
n_dofs();
 
  857   for (
unsigned int var=0; var<
n_vars; var++)
 
  862   std::vector<dof_id_type> implicit_sys_dof_indices;
 
  863   std::vector<dof_id_type> explicit_sys_dof_indices;
 
  865   for (
const auto & elem : 
get_mesh().active_element_ptr_range())
 
  869       const std::size_t 
n_dofs = implicit_sys_dof_indices.size();
 
  871       for (
unsigned int var=0; var<
n_vars; var++)
 
  877           for (std::size_t i=0; i<
n_dofs; i++)
 
  879               dof_id_type implicit_sys_dof_index = implicit_sys_dof_indices[i];
 
  880               dof_id_type explicit_sys_dof_index = explicit_sys_dof_indices[i];
 
  883                 explicit_sys_dof_index;
 
  
std::unique_ptr< SparseMatrix< Number > > inner_product_matrix
The inner product matrix.
 
virtual void process_parameters_file(const std::string ¶meters_filename) override
Read parameters in from file and set up this system accordingly.
 
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true) override
Override train_reduced_basis to first initialize _parametrized_functions_in_training_set.
 
Manages consistently variables, degrees of freedom, and coefficient vectors.
 
virtual unsigned int get_n_basis_functions() const
Get the current number of basis functions.
 
virtual void zero()=0
Set all entries to zero.
 
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
 
const QBase & get_element_qrule() const
Accessor for element interior quadrature rule for the dimension of the current _elem.
 
unsigned int n_vars() const
 
virtual void print_info() override
Print out info that describes the current setup of this RBConstruction.
 
virtual void load_rb_solution() override
Load the RB solution from the most recent solve with rb_eval into this system's solution vector.
 
const EquationSystems & get_equation_systems() const
 
const std::vector< Point > & get_xyz() const
 
virtual System & add_system(const std::string &system_type, const std::string &name)
Add the system of type system_type named name to the systems array.
 
virtual void enrich_RB_space() override
Add a new basis function to the RB space.
 
virtual Real rb_solve(unsigned int N) override
Calculate the EIM approximation to parametrized_function using the first N EIM basis functions.
 
virtual void update_system() override
Update the system after enriching the RB space; this calls a series of functions to update the system...
 
NumericVector< Number > * rhs
The system matrix.
 
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
 
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
 
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...
 
void constrain_element_vector(DenseVector< Number > &rhs, std::vector< dof_id_type > &dofs, bool asymmetric_constraint_rows=true) const
Constrains the element vector.
 
virtual void init_explicit_system()=0
Add variables to the ExplicitSystem that is used to store the basis functions.
 
virtual ~RBEIMConstruction()
Destructor.
 
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.
 
RBAssemblyExpansion _empty_rb_assembly_expansion
We initialize RBEIMConstruction so that it has an "empty" RBAssemblyExpansion, because this isn't use...
 
This class extends FEMContext in order to provide extra data required to perform local element residu...
 
unsigned int n_points() const
 
virtual Real rb_solve(unsigned int N)
Perform online solve with the N RB basis functions, for the set of parameters in current_params,...
 
virtual numeric_index_type last_local_index() const =0
 
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
 
The libMesh namespace provides an interface to certain functionality in the library.
 
std::vector< std::unique_ptr< NumericVector< Number > > > _matrix_times_bfs
This vector is used to store inner_product_matrix * basis_function[i] for each i, since we frequently...
 
virtual Real truth_solve(int plot_solution) override
Load the truth representation of the parametrized function at the current parameters into the solutio...
 
virtual void pre_fe_reinit(const System &, const Elem *e)
Reinitializes local data vectors/matrices on the current geometric element.
 
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
 
This class forms the foundation from which generic finite elements may be derived.
 
const T_sys & get_system(const std::string &name) const
 
const std::vector< Real > & get_JxW() const
 
static const Real TOLERANCE
 
const Parallel::Communicator & comm() const
 
bool assert_convergence
A boolean flag to indicate whether to check for proper convergence after each solve.
 
virtual void init_data()
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.
 
void initialize_parametrized_functions_in_training_set()
Loop over the training set and compute the parametrized function for each training index.
 
std::vector< std::vector< dof_id_type > > _dof_map_between_systems
The index map between the explicit system and the implicit system.
 
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
 
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::unique_ptr< MeshFunction > _mesh_function
A mesh function to interpolate on the mesh.
 
void set_parameters(const RBParameters ¶ms)
Set the current parameters to params.
 
void plot_parametrized_functions_in_training_set(const std::string &pathname)
Plot all the parameterized functions that we are storing in _parametrized_functions_in_training_set.
 
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
 
const RBParameters & get_parameters() const
Get the current parameters.
 
bool _parametrized_functions_in_training_set_initialized
Boolean flag to indicate whether or not we have called compute_parametrized_functions_in_training_set...
 
std::vector< unsigned int > interpolation_points_var
The corresponding list of variables indices at which the interpolation points were identified.
 
Number evaluate_mesh_function(unsigned int var_number, Point p)
Evaluate the mesh function at the specified point and for the specified variable.
 
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
 
virtual void load_basis_function(unsigned int i) override
Load the i^th RB function into the RBConstruction solution vector.
 
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i].
 
virtual void init_context_with_sys(FEMContext &c, System &sys)
Initialize c based on sys.
 
This is the MeshBase class.
 
bool evaluate_RB_error_bound
Boolean to indicate whether we evaluate a posteriori error bounds when rb_solve is called.
 
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
 
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...
 
virtual void clear() override
Clear all the data structures associated with the system.
 
void set_explicit_sys_subvector(NumericVector< Number > &dest, unsigned int var, NumericVector< Number > &source)
Load source into the subvector of dest corresponding to var var.
 
std::unique_ptr< NumericVector< Number > > _ghosted_meshfunction_vector
We also need an extra vector in which we can store a ghosted copy of the vector that we wish to use M...
 
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.
 
void set_best_fit_type_flag(const std::string &best_fit_type_string)
Specify which type of "best fit" we use to guide the EIM greedy algorithm.
 
void set_point_locator_tol(Real point_locator_tol)
Set a point locator tolerance to be used in this class's MeshFunction, and other operations that requ...
 
numeric_index_type get_n_training_samples() const
Get the total number of training samples.
 
dof_id_type n_local_dofs() const
 
RBParameters get_params_from_training_set(unsigned int index)
Return the RBParameters in index index of training set.
 
DenseVector< Number > RB_solution
The RB solution vector.
 
void set_implicit_neighbor_dofs(bool implicit_neighbor_dofs)
Allow the implicit_neighbor_dofs flag to be set programmatically.
 
void set_params_from_training_set(unsigned int index)
Set parameters to the RBParameters stored in index index of the training set.
 
const MeshBase & get_mesh() const
 
processor_id_type processor_id() const
 
void libmesh_ignore(const Args &...)
 
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
 
void init_dof_map_between_systems()
Set up the index map between the implicit and explicit systems.
 
A Point defines a location in LIBMESH_DIM dimensional Real space.
 
Real get_point_locator_tol() const
 
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 ...
 
RBEvaluation & get_rb_evaluation()
Get a reference to the RBEvaluation object.
 
void set_rb_assembly_expansion(RBAssemblyExpansion &rb_assembly_expansion_in)
Set the rb_assembly_expansion object.
 
virtual unsigned int size() const override
 
This class is part of the rbOOmit framework.
 
std::vector< std::unique_ptr< ElemAssembly > > & get_eim_assembly_objects()
 
void check_convergence(LinearSolver< Number > &input_solver)
Check if the linear solver reports convergence.
 
This is the EquationSystems class.
 
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
 
virtual void print_info()
Print out info that describes the current setup of this RBConstruction.
 
virtual Real compute_best_fit_error()
We compute the best fit of parametrized_function into the EIM space and then evaluate the error in th...
 
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
 
void resize(const unsigned int n)
Resize the vector.
 
virtual void elem_fe_reinit(const std::vector< Point > *const pts=nullptr)
Reinitializes interior FE objects on the current geometric element.
 
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.
 
bool compute_RB_inner_product
Boolean flag to indicate whether we compute the RB_inner_product_matrix.
 
Real _point_locator_tol
The point locator tolerance.
 
void get_element_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for interior finite element object for variable var for the largest dimension in the mesh.
 
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
 
std::vector< std::unique_ptr< ElemAssembly > > _rb_eim_assembly_objects
The vector of assembly objects that are created to point to this RBEIMConstruction.
 
std::string _explicit_system_name
We use an ExplicitSystem to store the EIM basis functions.
 
DenseMatrix< Number > RB_inner_product_matrix
The inner product matrix.
 
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
 
const std::string & name() const
 
This class is part of the rbOOmit framework.
 
virtual Real get_RB_error_bound() override
Override to return the best fit error.
 
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors.
 
void get_principal_submatrix(unsigned int sub_m, unsigned int sub_n, DenseMatrix< T > &dest) const
Put the sub_m x sub_n principal submatrix into dest.
 
RBEIMConstruction(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
 
This is the base class from which all geometric element types are derived.
 
ExplicitSystem & get_explicit_system()
Get the ExplicitSystem associated with this system.
 
virtual std::unique_ptr< ElemAssembly > build_eim_assembly(unsigned int bf_index)=0
Build an element assembly object that will access basis function bf_index.
 
BEST_FIT_TYPE best_fit_type_flag
Enum that indicates which type of "best fit" algorithm we should use.
 
virtual void update_RB_system_matrices() override
Compute the reduced basis matrices for the current basis.
 
const DofMap & get_dof_map() const
 
std::vector< Point > interpolation_points
The list of interpolation points, i.e.
 
dof_id_type n_dofs() const
 
std::vector< std::unique_ptr< NumericVector< Number > > > _parametrized_functions_in_training_set
The libMesh vectors storing the finite element coefficients of the RB basis functions.
 
std::vector< Elem * > interpolation_points_elem
The corresponding list of elements at which the interpolation points were identified.
 
void lu_solve(const DenseVector< T > &b, DenseVector< T > &x)
Solve the system Ax=b given the input vector b.
 
const std::vector< std::vector< OutputShape > > & get_phi() const
 
virtual void initialize_eim_assembly_objects()
Build a vector of ElemAssembly objects that accesses the basis functions stored in this RBEIMConstruc...
 
std::vector< std::unique_ptr< NumericVector< Number > > > basis_functions
The libMesh vectors storing the finite element coefficients of the RB basis functions.
 
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
 
virtual void initialize_rb_construction(bool skip_matrix_assembly=false, bool skip_vector_assembly=false) override
Initialize this system so that we can perform the Construction stage of the RB method.
 
void get_all_variable_numbers(std::vector< unsigned int > &all_variable_numbers) const
Fills all_variable_numbers with all the variable numbers for the variables that have been added to th...
 
virtual void clear() override
Clear this object.
 
DenseMatrix< Number > interpolation_matrix
Dense matrix that stores the lower triangular interpolation matrix that can be used.
 
virtual void update()
Update the local values to reflect the solution on neighboring processors.
 
void get_explicit_sys_subvector(NumericVector< Number > &dest, unsigned int var, NumericVector< Number > &localized_source)
Load the subvector of localized_source corresponding to variable var into dest.
 
virtual void init_data() override
Override to initialize the coupling matrix to decouple variables in this system.
 
Number interior_value(unsigned int var, unsigned int qp) const
 
NumericVector< Number > & get_basis_function(unsigned int i)
Get a reference to the i^th basis function.
 
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
Train the reduced basis.
 
Number evaluate_parametrized_function(unsigned int var_index, const Point &p, const Elem &elem)
 
virtual numeric_index_type first_local_index() const =0
 
virtual void init_implicit_system()=0
Add one variable to the ImplicitSystem (i.e.
 
This class provides all data required for a physics package (e.g.