Go to the documentation of this file.
21 #include "libmesh/rb_construction.h"
22 #include "libmesh/rb_assembly_expansion.h"
23 #include "libmesh/rb_evaluation.h"
24 #include "libmesh/elem_assembly.h"
27 #include "libmesh/numeric_vector.h"
28 #include "libmesh/sparse_matrix.h"
29 #include "libmesh/dof_map.h"
30 #include "libmesh/libmesh_logging.h"
31 #include "libmesh/equation_systems.h"
32 #include "libmesh/exodusII_io.h"
33 #include "libmesh/gmv_io.h"
34 #include "libmesh/linear_solver.h"
35 #include "libmesh/getpot.h"
36 #include "libmesh/int_range.h"
37 #include "libmesh/mesh_base.h"
38 #include "libmesh/parallel.h"
39 #include "libmesh/xdr_cxx.h"
40 #include "libmesh/timestamp.h"
41 #include "libmesh/petsc_linear_solver.h"
42 #include "libmesh/dg_fem_context.h"
43 #include "libmesh/dirichlet_boundaries.h"
44 #include "libmesh/zero_function.h"
45 #include "libmesh/coupling_matrix.h"
46 #include "libmesh/face_tri3_subdivision.h"
47 #include "libmesh/quadrature.h"
48 #include "libmesh/utility.h"
49 #include "libmesh/int_range.h"
52 #include <sys/types.h>
63 const std::string & name_in,
64 const unsigned int number_in)
65 :
Parent(es, name_in, number_in),
67 extra_linear_solver(nullptr),
69 skip_residual_in_train_reduced_basis(false),
70 exit_on_repeated_greedy_parameters(true),
71 impose_internal_fluxes(false),
72 skip_degenerate_sides(true),
73 compute_RB_inner_product(false),
74 store_non_dirichlet_operators(false),
75 use_empty_rb_solve_in_greedy(true),
76 Fq_representor_innerprods_computed(false),
79 output_dual_innerprods_computed(false),
80 assert_convergence(true),
82 inner_product_assembly(nullptr),
83 use_energy_inner_product(false),
84 rel_training_tolerance(1.e-4),
85 abs_training_tolerance(1.e-12),
86 normalize_rb_bound_in_greedy(false)
102 LOG_SCOPE(
"clear()",
"RBConstruction");
127 return "RBConstruction";
148 const unsigned int maxits =
149 es.
parameters.
get<
unsigned int>(
"linear solver maximum iterations");
152 std::pair<unsigned int, Real> rval = std::make_pair(0,0.0);
157 rval = input_solver.
solve (input_matrix, *
solution, input_rhs, tol, maxits);
178 libmesh_error_msg(
"Error: RBEvaluation object hasn't been initialized yet");
196 GetPot infile(parameters_filename);
198 const unsigned int n_training_samples = infile(
"n_training_samples",0);
199 const bool deterministic_training = infile(
"deterministic_training",
false);
200 unsigned int training_parameters_random_seed_in =
201 static_cast<unsigned int>(-1);
202 training_parameters_random_seed_in = infile(
"training_parameters_random_seed",
203 training_parameters_random_seed_in);
204 const bool quiet_mode_in = infile(
"quiet_mode",
quiet_mode);
205 const unsigned int Nmax_in = infile(
"Nmax",
Nmax);
206 const Real rel_training_tolerance_in = infile(
"rel_training_tolerance",
208 const Real abs_training_tolerance_in = infile(
"abs_training_tolerance",
212 const bool normalize_rb_bound_in_greedy_in = infile(
"normalize_rb_bound_in_greedy",
216 unsigned int n_continuous_parameters = infile.vector_variable_size(
"parameter_names");
219 for (
unsigned int i=0; i<n_continuous_parameters; i++)
222 std::string param_name = infile(
"parameter_names",
"NONE", i);
225 Real min_val = infile(param_name, 0., 0);
226 mu_min_in.
set_value(param_name, min_val);
230 Real max_val = infile(param_name, 0., 1);
231 mu_max_in.
set_value(param_name, max_val);
235 std::map<std::string, std::vector<Real>> discrete_parameter_values_in;
237 unsigned int n_discrete_parameters = infile.vector_variable_size(
"discrete_parameter_names");
238 for (
unsigned int i=0; i<n_discrete_parameters; i++)
240 std::string param_name = infile(
"discrete_parameter_names",
"NONE", i);
242 unsigned int n_vals_for_param = infile.vector_variable_size(param_name);
243 std::vector<Real> vals_for_param(n_vals_for_param);
245 vals_for_param[j] = infile(param_name, 0., j);
247 discrete_parameter_values_in[param_name] = vals_for_param;
250 std::map<std::string,bool> log_scaling_in;
254 for (
const auto & pr : mu_min_in)
255 log_scaling_in[pr.first] =
false;
259 deterministic_training,
260 training_parameters_random_seed_in,
263 rel_training_tolerance_in,
264 abs_training_tolerance_in,
265 normalize_rb_bound_in_greedy_in,
268 discrete_parameter_values_in,
273 unsigned int n_training_samples_in,
274 bool deterministic_training_in,
275 unsigned int training_parameters_random_seed_in,
277 unsigned int Nmax_in,
278 Real rel_training_tolerance_in,
279 Real abs_training_tolerance_in,
280 bool normalize_rb_bound_in_greedy_in,
283 std::map<std::string, std::vector<Real>> discrete_parameter_values_in,
284 std::map<std::string,bool> log_scaling_in)
307 n_training_samples_in,
309 deterministic_training_in);
315 libMesh::out << std::endl <<
"RBConstruction parameters:" << std::endl;
331 libMesh::out <<
"RBThetaExpansion member is not set yet" << std::endl;
350 std::unique_ptr<NumericVector<Number>> temp =
solution->clone();
374 libmesh_error_msg(
"Error: RBAssemblyExpansion object hasn't been initialized yet");
388 libmesh_error_msg(
"Error: inner_product_assembly not available since we're using energy inner-product");
391 libmesh_error_msg(
"Error: inner_product_assembly hasn't been initialized yet");
404 #ifdef LIBMESH_ENABLE_CONSTRAINTS
420 bool skip_vector_assembly)
422 if (!skip_matrix_assembly && !skip_vector_assembly)
450 bool skip_vector_assembly)
452 if (!skip_matrix_assembly)
459 if (!skip_vector_assembly)
585 return libmesh_make_unique<DGFEMContext>(*
this);
593 bool apply_dof_constraints)
595 LOG_SCOPE(
"add_scaled_matrix_and_vector()",
"RBConstruction");
597 bool assemble_matrix = (input_matrix !=
nullptr);
598 bool assemble_vector = (input_vector !=
nullptr);
600 if (!assemble_matrix && !assemble_vector)
612 for (
const auto & t :
mesh.get_boundary_info().build_node_list())
614 const Node & node =
mesh.node_ref(std::get<0>(t));
621 std::vector<dof_id_type> nodal_dof_indices;
641 if (!nodal_dof_indices.empty())
644 input_vector->
add_vector(nodal_rhs, nodal_dof_indices);
647 input_matrix->
add_matrix(nodal_matrix, nodal_dof_indices);
658 for (
const auto & elem :
mesh.active_local_element_ptr_range())
663 std::unique_ptr<QBase> qrule;
666 const Tri3Subdivision * gh_elem = static_cast<const Tri3Subdivision *> (elem);
672 const int extraorder = 0;
673 FEBase * elem_fe =
nullptr;
687 for (context.
side = 0; context.
side != n_sides; ++context.
side)
723 if (apply_dof_constraints)
728 if (assemble_matrix && symmetrize)
736 if (apply_dof_constraints)
754 if (!coupling_matrix)
764 for (
unsigned int var1=0; var1<
n_vars(); var1++)
767 for (
const auto & var2 : ccr)
772 for (
unsigned int row=0; row<sub_m; row++)
773 for (
unsigned int col=0; col<sub_n; col++)
792 input_matrix->
close();
794 input_vector->
close();
807 LOG_SCOPE(
"truth_assembly()",
"RBConstruction");
842 bool apply_dof_constraints)
844 input_matrix->
zero();
853 apply_dof_constraints);
859 libmesh_error_msg(
"Error: invalid number of entries in energy_inner_product_coeffs.");
871 apply_dof_constraints);
878 bool apply_dof_constraints)
881 libmesh_error_msg(
"Error: We must have q < Q_a in assemble_Aq_matrix.");
883 input_matrix->
zero();
890 apply_dof_constraints);
898 LOG_SCOPE(
"add_scaled_Aq()",
"RBConstruction");
901 libmesh_error_msg(
"Error: We must have q < Q_a in add_scaled_Aq.");
906 input_matrix->
close();
920 libMesh::out <<
"Assembling inner product matrix" << std::endl;
925 libMesh::out <<
"Assembling non-Dirichlet inner product matrix" << std::endl;
934 libMesh::out <<
"Assembling affine operator " << (q_a+1) <<
" of "
943 libMesh::out <<
"Assembling non-Dirichlet affine operator " << (q_a+1) <<
" of "
954 libMesh::out <<
"Assembling affine vector " << (q_f+1) <<
" of "
963 libMesh::out <<
"Assembling non-Dirichlet affine vector " << (q_f+1) <<
" of "
973 bool apply_dof_constraints)
976 libmesh_error_msg(
"Error: We must have q < Q_f in assemble_Fq_vector.");
978 input_vector->
zero();
985 apply_dof_constraints );
993 libMesh::out <<
"Assembling output vector, (" << (n+1) <<
"," << (q_l+1)
1010 libMesh::out <<
"Assembling non-Dirichlet output vector, (" << (n+1) <<
"," << (q_l+1)
1026 LOG_SCOPE(
"train_reduced_basis()",
"RBConstruction");
1036 if (resize_rb_eval_data)
1045 Real training_greedy_error = 0.;
1053 libMesh::out <<
"Maximum number of basis functions reached: Nmax = "
1068 libMesh::out << std::endl <<
"---- Performing Greedy basis enrichment ----" << std::endl;
1069 Real initial_greedy_error = 0.;
1070 bool initial_greedy_error_initialized =
false;
1078 libMesh::out <<
"Performing RB solves on training set" << std::endl;
1081 libMesh::out <<
"Maximum error bound is " << training_greedy_error << std::endl << std::endl;
1084 if (!initial_greedy_error_initialized)
1086 initial_greedy_error = training_greedy_error;
1087 initial_greedy_error_initialized =
true;
1096 libMesh::out <<
"Performing truth solve at parameter:" << std::endl;
1116 libMesh::out <<
"Maximum number of basis functions reached: Nmax = "
1131 return training_greedy_error;
1136 LOG_SCOPE(
"enrich_basis_from_rhs_terms()",
"RBConstruction");
1142 if (resize_rb_eval_data)
1147 libMesh::out << std::endl <<
"---- Enriching basis from rhs terms ----" << std::endl;
1153 libMesh::out << std::endl <<
"Performing truth solve with rhs from rhs term " << q_f << std::endl;
1198 libMesh::out <<
"Absolute error tolerance reached." << std::endl;
1202 Real rel_greedy_error = abs_greedy_error/initial_error;
1205 libMesh::out <<
"Relative error tolerance reached." << std::endl;
1213 libMesh::out <<
"Maximum number of basis functions reached: Nmax = "
1222 libMesh::out <<
"Exiting greedy because the same parameters were selected twice" << std::endl;
1237 libmesh_error_msg(
"Error: Argument in RBConstruction::get_greedy_parameter is too large.");
1244 LOG_SCOPE(
"truth_solve()",
"RBConstruction");
1279 if (plot_solution > 0)
1281 #if defined(LIBMESH_USE_COMPLEX_NUMBERS)
1285 #ifdef LIBMESH_HAVE_EXODUS_API
1302 this->
Nmax = Nmax_in;
1307 LOG_SCOPE(
"load_basis_function()",
"RBConstruction");
1318 LOG_SCOPE(
"enrich_RB_space()",
"RBConstruction");
1337 if (new_bf_norm == 0.)
1343 new_bf->scale(1./new_bf_norm);
1374 error_bound /= error_bound_normalization;
1387 unsigned int saved_delta_N =
delta_N;
1397 LOG_SCOPE(
"compute_max_error_bound()",
"RBConstruction");
1403 if (std::numeric_limits<Real>::has_infinity)
1405 max_val = std::numeric_limits<Real>::infinity();
1409 max_val = std::numeric_limits<Real>::max();
1420 unsigned int max_err_index = 0;
1439 std::pair<numeric_index_type, Real> error_pair(first_index+max_err_index, max_err);
1451 unsigned int root_id=0;
1459 this->
comm().sum(root_id);
1463 return error_pair.second;
1468 LOG_SCOPE(
"update_RB_system_matrices()",
"RBConstruction");
1477 for (
unsigned int i=(RB_size-
delta_N); i<RB_size; i++)
1483 for (
unsigned int i=(RB_size-
delta_N); i<RB_size; i++)
1492 for (
unsigned int j=0; j<RB_size; j++)
1537 LOG_SCOPE(
"update_residual_terms()",
"RBConstruction");
1539 libMesh::out <<
"Updating RB residual terms" << std::endl;
1545 for (
unsigned int i=(RB_size-
delta_N); i<RB_size; i++)
1563 libMesh::out <<
"Starting solve [q_a][i]=[" << q_a <<
"]["<< i <<
"] in RBConstruction::update_residual_terms() at "
1574 libMesh::out <<
"Finished solve [q_a][i]=[" << q_a <<
"]["<< i <<
"] in RBConstruction::update_residual_terms() at "
1586 if (compute_inner_products)
1595 for (
unsigned int i=(RB_size-
delta_N); i<RB_size; i++)
1608 for (
unsigned int i=(RB_size-
delta_N); i<RB_size; i++)
1610 for (
unsigned int j=0; j<RB_size; j++)
1648 LOG_SCOPE(
"compute_output_dual_innerprods()",
"RBConstruction");
1650 libMesh::out <<
"Compute output dual inner products" << std::endl;
1653 unsigned int max_Q_l = 0;
1657 std::vector<std::unique_ptr<NumericVector<Number>>> L_q_representor(max_Q_l);
1658 for (
unsigned int q=0; q<max_Q_l; q++)
1672 libMesh::out <<
"Starting solve n=" << n <<
", q_l=" << q_l
1673 <<
" in RBConstruction::compute_output_dual_innerprods() at "
1690 libMesh::out <<
"Finished solve n=" << n <<
", q_l=" << q_l
1691 <<
" in RBConstruction::compute_output_dual_innerprods() at "
1695 <<
" iterations, final residual "
1737 LOG_SCOPE(
"compute_Fq_representor_innerprods()",
"RBConstruction");
1755 <<
" in RBConstruction::update_residual_terms() at "
1766 <<
" in RBConstruction::update_residual_terms() at "
1770 <<
" iterations, final residual "
1777 if (compute_inner_products)
1802 LOG_SCOPE(
"load_rb_solution()",
"RBConstruction");
1809 <<
" RB_solution in RBConstruction::load_rb_solution is too long!");
1821 LOG_SCOPE(
"compute_residual_dual_norm_slow()",
"RBConstruction");
1833 for (
unsigned int i=0; i<N; i++)
1861 libmesh_error_msg(
"Error: Must have store_non_dirichlet_operators==true to access non_dirichlet_inner_product_matrix.");
1879 libmesh_error_msg(
"Error: We must have q < Q_a in get_Aq.");
1887 libmesh_error_msg(
"Error: Must have store_non_dirichlet_operators==true to access non_dirichlet_Aq.");
1890 libmesh_error_msg(
"Error: We must have q < Q_a in get_Aq.");
1908 libmesh_error_msg(
"Error: We must have q < Q_f in get_Fq.");
1916 libmesh_error_msg(
"Error: Must have store_non_dirichlet_operators==true to access non_dirichlet_Fq.");
1919 libmesh_error_msg(
"Error: We must have q < Q_f in get_Fq.");
1937 libmesh_error_msg(
"Error: We must have n < n_outputs and " \
1938 <<
"q_l < get_rb_theta_expansion().get_n_output_terms(n) in get_output_vector.");
1946 libmesh_error_msg(
"Error: We must have n < n_outputs and " \
1947 <<
"q_l < get_rb_theta_expansion().get_n_output_terms(n) in get_non_dirichlet_output_vector.");
1954 all_matrices.clear();
1965 std::stringstream matrix_name;
1966 matrix_name <<
"A" << q_a;
1967 all_matrices[matrix_name.str()] =
get_Aq(q_a);
1971 matrix_name <<
"_non_dirichlet";
1979 all_vectors.clear();
1985 std::stringstream F_vector_name;
1986 F_vector_name <<
"F" << q_f;
1987 all_vectors[F_vector_name.str()] =
get_Fq(q_f);
1991 F_vector_name <<
"_non_dirichlet";
1999 output_vectors.clear();
2004 std::stringstream output_name;
2005 output_name <<
"output_" << n <<
"_"<< q_l;
2010 output_name <<
"_non_dirichlet";
2016 #ifdef LIBMESH_ENABLE_DIRICHLET
2022 std::set<boundary_id_type> dirichlet_ids;
2023 std::vector<unsigned int> variables;
2026 return libmesh_make_unique<DirichletBoundary>(dirichlet_ids, variables, &zf);
2032 const bool write_binary_residual_representors)
2034 LOG_SCOPE(
"write_riesz_representors_to_files()",
"RBConstruction");
2040 libMesh::out <<
"Writing out the Fq_representors..." << std::endl;
2042 std::ostringstream file_name;
2043 const std::string riesz_representor_suffix = (write_binary_residual_representors ?
".xdr" :
".dat");
2044 struct stat stat_info;
2049 libMesh::out <<
"Skipping creating residual_representors directory: " << strerror(errno) << std::endl;
2056 file_name << riesz_representors_dir <<
"/Fq_representor" << i << riesz_representor_suffix;
2070 int stat_result = stat(file_name.str().c_str(), &stat_info);
2072 if ( (stat_result != 0) ||
2073 (stat_info.st_size == 0))
2081 Xdr fqr_data(file_name.str(),
2082 write_binary_residual_representors ?
ENCODE :
WRITE);
2087 this->
comm().barrier();
2100 libMesh::out <<
"Writing out the Aq_representors..." << std::endl;
2107 for (
unsigned int j=jstart; j<jstop; ++j)
2109 libMesh::out <<
"Writing out Aq_representor[" << i <<
"][" << j <<
"]..." << std::endl;
2113 file_name << riesz_representors_dir
2114 <<
"/Aq_representor" << i <<
"_" << j << riesz_representor_suffix;
2121 Xdr aqr_data(file_name.str(),
2122 write_binary_residual_representors ?
ENCODE :
WRITE);
2127 this->
comm().barrier();
2141 const bool read_binary_residual_representors)
2143 LOG_SCOPE(
"read_riesz_representors_from_files()",
"RBConstruction");
2145 libMesh::out <<
"Reading in the Fq_representors..." << std::endl;
2147 const std::string riesz_representor_suffix = (read_binary_residual_representors ?
".xdr" :
".dat");
2148 std::ostringstream file_name;
2149 struct stat stat_info;
2155 libmesh_error_msg(
"Error, must delete existing Fq_representor before reading in from file.");
2160 file_name << riesz_representors_dir
2161 <<
"/Fq_representor" << i << riesz_representor_suffix;
2166 int stat_result = stat(file_name.str().c_str(), &stat_info);
2168 if (stat_result != 0)
2169 libmesh_error_msg(
"File does not exist: " << file_name.str());
2172 Xdr fqr_data(file_name.str(),
2173 read_binary_residual_representors ?
DECODE :
READ);
2182 Fq_representor[i]->swap(*
solution);
2190 libMesh::out <<
"Reading in the Aq_representors..." << std::endl;
2197 for (
const auto & rep : row)
2199 libmesh_error_msg(
"Error, must delete existing Aq_representor before reading in from file.");
2206 file_name << riesz_representors_dir
2207 <<
"/Aq_representor" << i <<
"_" << j << riesz_representor_suffix;
2212 int stat_result = stat(file_name.str().c_str(), &stat_info);
2214 if (stat_result != 0)
2215 libmesh_error_msg(
"File does not exist: " << file_name.str());
2218 Xdr aqr_data(file_name.str(), read_binary_residual_representors ?
DECODE :
READ);
2239 std::stringstream err_msg;
2240 err_msg <<
"Convergence error. Error id: " << conv_flag;
2241 libmesh_error_msg(err_msg.str());
virtual void reuse_preconditioner(bool)
Set the same_preconditioner flag, which indicates if we reuse the same preconditioner for subsequent ...
std::unique_ptr< SparseMatrix< Number > > inner_product_matrix
The inner product matrix.
Real _final_linear_residual
The final residual for the linear system Ax=b.
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
virtual void enrich_RB_space()
Add a new basis function to the RB space.
virtual void post_process_truth_solution()
Similarly, provide an opportunity to post-process the truth solution after the solve is complete.
virtual unsigned int get_n_basis_functions() const
Get the current number of basis functions.
void print_discrete_parameter_values() const
Print out all the discrete parameter values.
virtual void zero()=0
Set all entries to zero.
const RBParameters & get_parameters_min() const
Get an RBParameters object that specifies the minimum allowable value for each parameter.
virtual void clear()
Clear all the data structures associated with the system.
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
void get_transpose(DenseMatrix< T > &dest) const
Put the tranposed matrix into dest.
unsigned int n_vars() const
std::vector< DenseMatrix< Number > > RB_Aq_vector
Dense matrices for the RB computations.
virtual LinearConvergenceReason get_converged_reason() const =0
unsigned int get_n_output_terms(unsigned int output_index) const
Get the number of affine terms associated with the specified output.
unsigned int get_n_F_terms() const
Get Q_f, the number of terms in the affine expansion for the right-hand side.
unsigned char side
Current side for side_* to examine.
const EquationSystems & get_equation_systems() const
virtual void add(const numeric_index_type i, const T value)=0
Adds value to each entry of the vector.
virtual Real get_RB_error_bound()
NumericVector< Number > * get_non_dirichlet_Fq(unsigned int q)
Get a pointer to non-Dirichlet Fq.
const std::vector< dof_id_type > & get_neighbor_dof_indices() const
Accessor for neighbor dof indices.
SparseMatrix< Number > * get_Aq(unsigned int q)
Get a pointer to Aq.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
NumericVector< Number > * rhs
The system matrix.
numeric_index_type get_first_local_training_index() const
Get the first local index of the training parameters.
unsigned int Nmax
Maximum number of reduced basis functions we are willing to use.
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...
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...
virtual void side_fe_reinit() override
Override side_fe_reinit to set a boolean flag so that by default DG terms are assumed to be inactive.
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0
This function calls the solver _solver_type preconditioned with the _preconditioner_type precondition...
ElemAssembly & get_output_assembly(unsigned int output_index, unsigned int q_l)
Return a reference to the specified output assembly object.
virtual void get_all_vectors(std::map< std::string, NumericVector< Number > * > &all_vectors)
Get a map that stores pointers to all of the vectors.
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 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.
void set_rb_evaluation(RBEvaluation &rb_eval_in)
Set the RBEvaluation object.
This class extends FEMContext in order to provide extra data required to perform local element residu...
Real abs_training_tolerance
virtual Real rb_solve(unsigned int N)
Perform online solve with the N RB basis functions, for the set of parameters in current_params,...
void set_training_random_seed(unsigned int seed)
Set the seed that is used to randomly generate training parameters.
SparseMatrix< Number > * get_non_dirichlet_inner_product_matrix()
Get the non-Dirichlet (or more generally no-constraints) version of the inner-product matrix.
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 rel_training_tolerance
Relative and absolute tolerances for training reduced basis using the Greedy scheme.
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...
unsigned int get_n_params() const
Get the number of parameters.
The libMesh namespace provides an interface to certain functionality in the library.
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
std::vector< Number > Fq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online.
unsigned char get_side() const
Accessor for current side of Elem object.
virtual void pre_fe_reinit(const System &, const Elem *e)
Reinitializes local data vectors/matrices on the current geometric element.
virtual void compute_output_dual_innerprods()
Compute and store the dual norm of each output functional.
ElemAssembly & get_F_assembly(unsigned int q)
Return a reference to the specified F_assembly object.
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
std::vector< std::vector< Number > > output_dual_innerprods
The vector storing the dual norm inner product terms for each output.
This class forms the foundation from which generic finite elements may be derived.
const DenseMatrix< Number > & get_neighbor_elem_jacobian() const
Const accessor for element-neighbor Jacobian.
virtual ~RBConstruction()
Destructor.
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...
const DenseMatrix< Number > & get_elem_elem_jacobian() const
Const accessor for element-element Jacobian.
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
const Elem & get_elem() const
Accessor for current Elem object.
std::vector< std::unique_ptr< NumericVector< Number > > > Fq_representor
Vector storing the residual representors associated with the right-hand side.
const Parallel::Communicator & comm() const
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.
virtual SparseMatrix< Number > & get_matrix_for_output_dual_solves()
Return the matrix for the output residual dual norm solves.
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 get_nodal_values(std::vector< dof_id_type > &, DenseMatrix< Number > &, DenseVector< Number > &, const System &, const Node &)
Get values to add to the matrix or rhs vector based on node.
std::vector< std::unique_ptr< SparseMatrix< Number > > > Aq_vector
Vector storing the Q_a matrices from the affine expansion.
virtual void interior_assembly(FEMContext &)
Perform the element interior assembly.
std::vector< std::unique_ptr< NumericVector< Number > > > non_dirichlet_Fq_vector
virtual void init_context(FEMContext &)
Initialize the FEMContext prior to performing an element loop.
dof_id_type first_dof(const processor_id_type proc) const
virtual Number eval_output_theta(unsigned int output_index, unsigned int q_l, const RBParameters &mu)
Evaluate theta_q_l at the current parameter.
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > outputs_vector
The libMesh vectors that define the output functionals.
RBEvaluation * rb_eval
The current RBEvaluation object we are using to perform the Evaluation stage of the reduced basis met...
This class implements writing meshes in the GMV format.
void set_inner_product_assembly(ElemAssembly &inner_product_assembly_in)
Set the rb_assembly_expansion object.
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 ...
bool is_constrained_dof(const dof_id_type dof) const
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...
void set_parameters(const RBParameters ¶ms)
Set the current parameters to params.
processor_id_type processor_id() const
virtual void init(const char *name=nullptr)=0
Initialize data structures if not done so already.
void zero_constrained_dofs_on_vector(NumericVector< Number > &vector)
It is sometimes useful to be able to zero vector entries that correspond to constrained dofs.
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...
const RBParameters & get_parameters_max() const
Get an RBParameters object that specifies the maximum allowable value for each parameter.
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.
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 void assemble_misc_matrices()
Assemble and store all the inner-product matrix, the constraint matrix (for constrained problems) and...
void update_greedy_param_list()
Update the list of Greedily chosen parameters with current_parameters.
void print_basis_function_orthogonality()
Print out a matrix that shows the orthogonality of the RB basis functions.
bool assemble_before_solve
Flag which tells the system to whether or not to call the user assembly function during each call to ...
This class stores the set of ElemAssembly functor objects that define the "parameter-independent expa...
bool get_convergence_assertion_flag() const
Getter for the flag determining if convergence should be checked after each solve.
SparseMatrix< Number > * get_inner_product_matrix()
Get a pointer to inner_product_matrix.
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
ElemAssembly * inner_product_assembly
Pointer to inner product assembly.
bool skip_degenerate_sides
In some cases meshes are intentionally created with degenerate sides as a way to represent,...
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.
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].
LinearConvergenceReason
Linear solver convergence flags (taken from the PETSc flags).
This is the MeshBase class.
Real get_parameter_max(const std::string ¶m_name) const
Get maximum allowable value of parameter param_name.
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.
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.
void broadcast_parameters(unsigned int proc_id)
Broadcasts parameters on processor proc_id to all processors.
virtual void allocate_data_structures()
Helper function that actually allocates all the data structures required by this class.
numeric_index_type get_n_training_samples() const
Get the total number of training samples.
virtual LinearSolver< Number > * get_linear_solver() const override
dof_id_type n_local_dofs() const
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.
virtual void update_system()
Update the system after enriching the RB space; this calls a series of functions to update the system...
void set_convergence_assertion_flag(bool flag)
Setter for the flag determining if convergence should be checked after each solve.
RBConstruction(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
void set_rel_training_tolerance(Real new_training_tolerance)
Get/set the relative tolerance for the basis training.
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.
DenseVector< Number > RB_solution
The RB solution vector.
bool is_rb_eval_initialized() const
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 get_output_vectors(std::map< std::string, NumericVector< Number > * > &all_vectors)
Get a map that stores pointers to all of the vectors.
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< Number > Fq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online.
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 enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Constrains the numeric vector v, which represents a solution defined on the mesh.
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > non_dirichlet_outputs_vector
NumericVector< Number > * get_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to the n^th output.
virtual Real compute_max_error_bound()
(i) Compute the a posteriori error bound for each set of parameters in the training set,...
std::vector< std::vector< std::vector< Number > > > Fq_Aq_representor_innerprods
Vectors storing the residual representor inner products to be used in computing the residuals online.
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
std::size_t n_nodeset_conds() const
LinearSolver< Number > * extra_linear_solver
Also, we store a pointer to an extra linear solver.
virtual std::unique_ptr< Elem > side_ptr(unsigned int i)=0
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.
void read_serialized_data(Xdr &io, const bool read_additional_data=true)
Reads additional data, namely vectors, for this System.
SparseMatrix< Number > * matrix
The system matrix.
void print_parameters() const
Print the current parameters.
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_value(const std::string ¶m_name, Real value)
Set the value of the specified parameter.
A Node is like a Point, but with more information.
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the RBThetaExpansion object that that belongs to rb_eval.
void enrich_basis_from_rhs_terms(const bool resize_rb_eval_data=true)
This function computes one basis function for each rhs term.
ElemAssembly & get_A_assembly(unsigned int q)
Return a reference to the specified A_assembly object.
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
bool is_quiet() const
Is the system in quiet mode?
unsigned int get_Nmax() const
Get/set Nmax, the maximum number of RB functions we are willing to compute.
void set_rb_assembly_expansion(RBAssemblyExpansion &rb_assembly_expansion_in)
Set the rb_assembly_expansion object.
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 unsigned int size() const override
ConstFunction that simply returns 0.
const DenseMatrix< Number > & get_elem_neighbor_jacobian() const
Const accessor for element-neighbor Jacobian.
FEType get_fe_type() const
const RBParameters & get_greedy_parameter(unsigned int i)
Return the parameters chosen during the i^th step of the Greedy algorithm.
void check_convergence(LinearSolver< Number > &input_solver)
Check if the linear solver reports convergence.
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
std::string get_timestamp()
dof_id_type numeric_index_type
This is the EquationSystems class.
void constrain_element_matrix_and_vector(DenseMatrix< Number > &matrix, DenseVector< Number > &rhs, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true) const
Constrains the element matrix and vector.
unsigned int n_linear_iterations() const
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.
int mkdir(const char *pathname)
Create a directory.
std::vector< std::vector< std::vector< Number > > > Aq_Aq_representor_innerprods
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 ...
unsigned int get_n_outputs() const
Get n_outputs, the number output functionals.
virtual void assemble_affine_expansion(bool skip_matrix_assembly, bool skip_vector_assembly)
Assemble the matrices and vectors for this system.
bool get_normalize_rb_bound_in_greedy()
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.
void write_serialized_data(Xdr &io, const bool write_additional_data=true) const
Writes additional data, namely vectors, for this System.
virtual void update_RB_system_matrices()
Compute the reduced basis matrices for the current basis.
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::vector< std::vector< DenseVector< Number > > > RB_output_vectors
The vectors storing the RB output vectors.
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 elem_fe_reinit(const std::vector< Point > *const pts=nullptr)
Reinitializes interior FE objects on the current geometric element.
std::vector< Number > truth_outputs
Vector storing the truth output values from the most recent truth solve.
Real compute_residual_dual_norm_slow(const unsigned int N)
The slow (but simple, non-error prone) way to compute the residual dual norm.
void attach_matrix(SparseMatrix< Number > &matrix)
Additional matrices may be handled with this DofMap.
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.
numeric_index_type get_last_local_training_index() const
Get the last local index of the training parameters.
bool skip_residual_in_train_reduced_basis
Boolean flag to indicate if we skip residual calculations in train_reduced_basis.
bool compute_RB_inner_product
Boolean flag to indicate whether we compute the RB_inner_product_matrix.
SparseMatrix< Number > * get_non_dirichlet_Aq(unsigned int q)
Get a pointer to non_dirichlet_Aq.
unsigned int delta_N
The number of basis functions that we add at each greedy step.
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.
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
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...
ElemAssembly provides a per-element (interior and boundary) assembly functionality.
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 ...
bool normalize_rb_bound_in_greedy
This boolean indicates if we normalize the RB error in the greedy using RBEvaluation::get_error_bound...
DenseMatrix< Number > RB_inner_product_matrix
The inner product matrix.
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
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...
RBAssemblyExpansion * rb_assembly_expansion
This member holds the (parameter independent) assembly functors that define the "affine expansion" of...
void set_quiet_mode(bool quiet_mode_in)
Set the quiet_mode flag.
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
virtual void load_basis_function(unsigned int i)
Load the i^th RB function into the RBConstruction solution vector.
This class handles the numbering of degrees of freedom on a mesh.
std::vector< std::vector< Number > > output_dual_innerprods
The vector storing the dual norm inner product terms for each output.
const std::string & name() const
bool impose_internal_fluxes
Boolean flag to indicate whether we impose "fluxes" (i.e.
virtual Real get_error_bound_normalization()
bool dg_terms_are_active() const
Are the DG terms active, i.e.
This class is part of the rbOOmit framework.
Real get_abs_training_tolerance()
bool serial_training_set
This boolean flag indicates whether or not the training set should be the same on all processors.
This base class can be inherited from to provide interfaces to linear solvers from different packages...
virtual void load_rb_solution()
Load the RB solution from the most recent solve with rb_eval into this system's solution vector.
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
std::vector< std::vector< std::unique_ptr< NumericVector< Number > > > > Aq_representor
Vector storing the residual representors associated with the left-hand side.
Real get_rel_training_tolerance()
bool use_energy_inner_product
Boolean to indicate whether we're using the energy inner-product.
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.
std::vector< Real > training_error_bounds
Vector storing the values of the error bound for each parameter in the training set — the parameter g...
virtual void truth_assembly()
Assemble the truth matrix and right-hand side for current_parameters.
const DenseMatrix< Number > & get_neighbor_neighbor_jacobian() const
Const accessor for element-neighbor Jacobian.
void set_abs_training_tolerance(Real new_training_tolerance)
Get/set the absolute tolerance for the basis training.
virtual void get_all_matrices(std::map< std::string, SparseMatrix< Number > * > &all_matrices)
Get a map that stores pointers to all of the matrices.
NumericVector< Number > * get_Fq(unsigned int q)
Get a pointer to Fq.
virtual Real l2_norm() const =0
bool output_dual_innerprods_computed
A boolean flag to indicate whether or not the output dual norms have already been computed — used to ...
std::unique_ptr< SparseMatrix< Number > > non_dirichlet_inner_product_matrix
virtual void scale(const T factor)=0
Scale each element of the vector by the given factor.
unsigned int get_n_A_terms() const
Get Q_a, the number of terms in the affine expansion for the bilinear form.
virtual void assemble_all_affine_vectors()
Assemble and store the affine RHS vectors.
bool quiet_mode
Flag to indicate whether we print out extra information during the Offline stage.
bool store_non_dirichlet_operators
Boolean flag to indicate whether we store a second copy of each affine operator and vector which does...
virtual Real truth_solve(int plot_solution)
Perform a "truth" solve, i.e.
Real final_linear_residual() const
NumericVector< Number > * get_non_dirichlet_output_vector(unsigned int n, unsigned int q_l)
Get a pointer to non-Dirichlet output vector.
virtual std::string system_type() const override
const DofMap & get_dof_map() const
dof_id_type n_dofs() const
This proxy class acts like a container of indices from a single coupling row.
CouplingMatrix * _dof_coupling
Degree of freedom coupling.
unsigned int _n_linear_iterations
The number of linear iterations required to solve the linear system Ax=b.
virtual void resize_data_structures(const unsigned int Nmax, bool resize_error_bound_data=true)
Resize and clear the data vectors corresponding to the value of Nmax.
virtual T el(const unsigned int i, const unsigned int j) const override
This class defines a coupling matrix.
const Elem * neighbor_ptr(unsigned int i) const
numeric_index_type get_local_n_training_samples() const
Get the total number of training samples local to this processor.
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the rb_theta_expansion.
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
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.
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 void assemble_all_output_vectors()
Assemble and store the output vectors.
virtual void attach_quadrature_rule(QBase *q)=0
Provides the class with the quadrature rule.
virtual void assemble_all_affine_operators()
Assemble and store all Q_a affine operators as well as the inner-product matrix.
virtual unsigned int n_sides() const =0
std::vector< DenseVector< Number > > RB_Fq_vector
Dense vector for the RHS.
The Tri3Subdivision element is a three-noded subdivision surface shell element used in mechanics calc...
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
const T & get(const std::string &) const
bool Fq_representor_innerprods_computed
A boolean flag to indicate whether or not the Fq representor norms have already been computed — used ...
virtual void set_Nmax(unsigned int Nmax)
ElemAssembly & get_inner_product_assembly()
virtual void update()
Update the local values to reflect the solution on neighboring processors.
virtual void zero()=0
Set all entries to 0.
std::unique_ptr< LinearSolver< Number > > linear_solver
The LinearSolver defines the interface used to solve the linear_implicit system.
virtual void initialize_training_parameters(const RBParameters &mu_min, const RBParameters &mu_max, unsigned int n_training_parameters, std::map< std::string, bool > log_param_scale, bool deterministic=true)
Initialize the parameter ranges and indicate whether deterministic or random training parameters shou...
NumericVector< Number > & get_basis_function(unsigned int i)
Get a reference to the i^th basis function.
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.
bool is_discrete_parameter(const std::string &mu_name) const
Is parameter mu_name discrete?
virtual T dot(const NumericVector< T > &v) const =0
virtual void boundary_assembly(FEMContext &)
Perform the element boundary assembly.
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
Train the reduced basis.
dof_id_type end_dof(const processor_id_type proc) const
RBAssemblyExpansion & get_rb_assembly_expansion()
std::vector< RBParameters > greedy_param_list
The list of parameters selected by the Greedy algorithm in generating the Reduced Basis associated wi...
Real get_parameter_min(const std::string ¶m_name) const
Get minimum allowable value of parameter param_name.
void set_rb_construction_parameters(unsigned int n_training_samples_in, bool deterministic_training_in, unsigned 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, RBParameters mu_min_in, RBParameters mu_max_in, std::map< std::string, std::vector< Real >> discrete_parameter_values_in, std::map< std::string, bool > log_scaling)
Set the state of this RBConstruction object based on the arguments to this function.
Parameters parameters
Data structure holding arbitrary parameters.
virtual std::unique_ptr< DGFEMContext > build_context()
Builds a DGFEMContext object with enough information to do evaluations on each element.