42#include "libmesh/libmesh.h"
43#include "libmesh/mesh.h"
44#include "libmesh/mesh_generation.h"
45#include "libmesh/equation_systems.h"
46#include "libmesh/exodusII_io.h"
47#include "libmesh/getpot.h"
48#include "libmesh/rb_data_serialization.h"
49#include "libmesh/rb_data_deserialization.h"
50#include "libmesh/enum_solver_package.h"
52#include "eim_classes.h"
53#include "rb_classes.h"
58int main (
int argc,
char ** argv)
65 "--enable-petsc, --enable-trilinos, or --enable-eigen");
67#if !defined(LIBMESH_HAVE_XDR)
69 libmesh_example_requires(
false,
"--enable-xdr");
70#elif defined(LIBMESH_DEFAULT_SINGLE_PRECISION)
72 libmesh_example_requires(
false,
"double precision");
73#elif defined(LIBMESH_DEFAULT_TRIPLE_PRECISION)
75 libmesh_example_requires(
false,
"double precision");
79 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
83#if !defined(LIBMESH_ENABLE_DIRICHLET) || !defined(LIBMESH_HAVE_CAPNPROTO)
84 libmesh_example_requires(
false,
"--enable-dirichlet --enable-capnp");
88 std::string eim_parameters =
"eim.in";
89 std::string rb_parameters =
"rb.in";
90 std::string main_parameters =
"reduced_basis_ex4.in";
91 GetPot infile(main_parameters);
93 unsigned int n_elem = infile(
"n_elem", 1);
94 const unsigned int dim = 2;
97 const int online_mode =
99 eim_training_function_to_plot =
101 eim_basis_function_to_plot =
112 bool eim_binary_io =
true;
118 libMesh::out <<
"Perform EIM training" << std::endl << std::endl;
128 equation_systems.
init ();
152 eim_rb_eval.write_out_basis_functions(
"eim_data", eim_binary_io);
156 libMesh::out << std::endl <<
"Perform RB training" << std::endl << std::endl;
168 equation_systems.
init ();
182 rb_construction.set_rb_evaluation(rb_eval);
186 eim_rb_eval.read_in_basis_functions(rb_construction,
"eim_data", eim_binary_io);
189 rb_construction.process_parameters_file(rb_parameters);
192 eim_rb_eval.initialize_eim_theta_objects();
197 rb_construction.get_rb_assembly_expansion().attach_multiple_F_assembly(eim_construction.
get_eim_assembly_objects());
200 rb_construction.print_info();
204 rb_construction.initialize_rb_construction();
205 rb_construction.train_reduced_basis();
210 rb_construction.get_rb_evaluation().write_out_basis_functions(rb_construction,
223 eim_rb_eval.initialize_eim_theta_objects();
231 Real online_center_x = infile(
"online_center_x", 0.);
232 Real online_center_y = infile(
"online_center_y", 0.);
265 std::vector<RBParameters> mu_vec = {online_mu};
268 std::vector<std::vector<Number>> all_A(rb_theta_expansion.
get_n_A_terms());
269 for (
unsigned int q_a=0; q_a<rb_theta_expansion.
get_n_A_terms(); q_a++)
274 all_A[q_a] = rb_theta_expansion.
eval_A_theta(q_a, mu_vec);
302 std::vector<std::vector<Number>> all_F(rb_theta_expansion.
get_n_F_terms());
303 for (
unsigned int q_f=0; q_f<rb_theta_expansion.
get_n_F_terms(); q_f++)
304 all_F[q_f] = rb_theta_expansion.
eval_F_theta(q_f, mu_vec);
308 const auto & eim_error_indicators =
309 eim_rb_eval.get_rb_eim_error_indicators();
313 libMesh::out <<
"EIM (error indicator, normalization factor) for step "
315 <<
"(" << eim_error_indicators[idx].first
316 <<
", " << eim_error_indicators[idx].second
325 unsigned int output_counter = 0;
326 for (
unsigned int n=0; n<rb_theta_expansion.
get_n_outputs(); n++)
328 all_outputs[output_counter++] =
334 unsigned int n_thetas =
340 std::vector<Number> evaluated_thetas(n_thetas);
348 equation_systems.
init ();
356 for (
unsigned sample_idx=0; sample_idx<online_mu.
n_samples(); ++sample_idx)
358 unsigned int counter = 0;
361 for (
unsigned int q_a=0; q_a<rb_theta_expansion.
get_n_A_terms(); q_a++)
362 evaluated_thetas[counter++] = all_A[q_a][sample_idx];
365 for (
unsigned int q_f=0; q_f<rb_theta_expansion.
get_n_F_terms(); q_f++)
366 evaluated_thetas[counter++] = all_F[q_f][sample_idx];
370 unsigned int output_counter = 0;
371 for (
unsigned int n=0; n<rb_theta_expansion.
get_n_outputs(); n++)
373 evaluated_thetas[counter++] = all_outputs[output_counter++][sample_idx];
377 libMesh::out <<
"Performing solve for step " << sample_idx << std::endl;
388#ifdef LIBMESH_HAVE_EXODUS_API
This is the EquationSystems class.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
const Parallel::Communicator & comm() const
void set_rb_evaluation(RBEvaluation &rb_eval_in)
Set the RBEvaluation object.
virtual void load_rb_solution()
Load the RB solution from the most recent solve with rb_eval into this system's solution vector.
This class de-serializes a RBEIMEvaluation object using the Cap'n Proto library.
void read_from_file(const std::string &path, bool use_packing=false)
Read the Cap'n'Proto buffer from disk.
This class de-serializes an RBEvaluation object using the Cap'n Proto library.
void read_from_file(const std::string &path, bool read_error_bound_data, bool use_packing=false)
Read the Cap'n'Proto buffer from disk.
This class serializes an RBEIMEvaluation object using the Cap'n Proto library.
void write_to_file(const std::string &path, bool use_packing=false)
Write the Cap'n'Proto buffer to disk.
This class serializes an RBEvaluation object using the Cap'n Proto library.
void write_to_file(const std::string &path, bool use_packing=false)
Write the Cap'n'Proto buffer to disk.
void initialize_eim_construction()
Perform initialization of this object to prepare for running train_eim_approximation().
std::vector< std::unique_ptr< ElemAssembly > > & get_eim_assembly_objects()
virtual void initialize_eim_assembly_objects()
Build a vector of ElemAssembly objects that accesses the basis functions stored in this RBEIMConstruc...
void set_rb_eim_evaluation(RBEIMEvaluation &rb_eim_eval_in)
Set the RBEIMEvaluation object.
virtual Real train_eim_approximation()
Generate the EIM approximation for the specified parametrized function using either POD or the Greedy...
virtual void print_info()
Print out info that describes the current setup of this RBConstruction.
virtual void process_parameters_file(const std::string ¶meters_filename)
Read parameters in from file and set up this system accordingly.
std::vector< Real > RB_output_error_bounds
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 unsigned int get_n_basis_functions() const
Get the current number of basis functions.
RBThetaExpansion & get_rb_theta_expansion()
Get a reference to the rb_theta_expansion.
std::vector< Number > RB_outputs
The vectors storing the RB output values and corresponding error bounds.
virtual void read_in_basis_functions(System &sys, const std::string &directory_name="offline_data", const bool read_binary_basis_functions=true)
Read in all the basis functions from file.
This class is part of the rbOOmit framework.
void push_back_value(const std::string ¶m_name, Real value)
Similar to set_value(name, index, value) but instead of specifying a particular index,...
unsigned int n_samples() const
Returns the number of samples stored for all parameters.
bool set_parameters(const RBParameters ¶ms)
Set the current parameters to params The parameters are checked for validity; an error is thrown if t...
void print_parameters() const
Print the current parameters.
This class stores the set of RBTheta functor objects that define the "parameter-dependent expansion" ...
virtual Number eval_F_theta(unsigned int q, const RBParameters &mu) const
Evaluate theta_q_f at the current parameter.
unsigned int get_total_n_output_terms() const
Returns the total number of affine terms associated with all outputs.
unsigned int get_n_F_terms() const
Get Q_f, the number of terms in the affine expansion for the right-hand side.
unsigned int get_n_A_terms() const
Get Q_a, the number of terms in the affine expansion for the bilinear form.
virtual Number eval_A_theta(unsigned int q, const RBParameters &mu) const
Evaluate theta_q_a at the current parameter.
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_outputs() const
Get n_outputs, the number output functionals.
virtual void attach_multiple_F_theta(std::vector< std::unique_ptr< RBTheta > > &theta_q_f)
Attach a vector of pointers to functor objects that each define one of the theta_q_f terms.
virtual Number eval_output_theta(unsigned int output_index, unsigned int q_l, const RBParameters &mu) const
Evaluate theta_q_l at the current parameter.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
SolverPackage default_solver_package()
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real