Go to the documentation of this file.
44 #include "libmesh/libmesh.h"
45 #include "libmesh/mesh.h"
46 #include "libmesh/mesh_generation.h"
47 #include "libmesh/exodusII_io.h"
48 #include "libmesh/equation_systems.h"
49 #include "libmesh/dof_map.h"
50 #include "libmesh/getpot.h"
51 #include "libmesh/elem.h"
52 #include "libmesh/rb_data_serialization.h"
53 #include "libmesh/rb_data_deserialization.h"
54 #include "libmesh/enum_solver_package.h"
57 #include "rb_classes.h"
64 int main (
int argc,
char** argv)
69 #ifndef LIBMESH_USE_COMPLEX_NUMBERS
70 libmesh_example_requires(
false,
"--enable-complex");
73 #if !defined(LIBMESH_HAVE_XDR)
75 libmesh_example_requires(
false,
"--enable-xdr");
76 #elif defined(LIBMESH_DEFAULT_SINGLE_PRECISION)
78 libmesh_example_requires(
false,
"--disable-singleprecision");
79 #elif defined(LIBMESH_DEFAULT_TRIPLE_PRECISION)
82 libmesh_example_requires(
false,
"double precision");
87 #if LIBMESH_HAVE_PETSC
90 GetPot input(argc, argv);
93 #if PETSC_VERSION_LESS_THAN(3,9,0)
94 if (input.search(
"-pc_factor_mat_solver_type"))
96 libMesh::out <<
"LibMesh was configured with PETSc < 3.9, but command-line options "
97 <<
"use syntax understood by later versions only. Skipping this example."
102 if (input.search(
"-pc_factor_mat_solver_package"))
104 libMesh::out <<
"LibMesh was configured with PETSc >= 3.9, but command-line options "
105 <<
"use deprecated syntax. Skipping now."
113 solver = input.next(solver);
114 if (solver ==
"mumps")
116 #ifndef LIBMESH_PETSC_HAVE_MUMPS
117 libmesh_example_requires(
false,
"PETSc compiled with MUMPS support");
120 else if (solver ==
"superlu")
122 #ifndef LIBMESH_PETSC_HAVE_SUPERLU_DIST
123 libmesh_example_requires(
false,
"PETSc compiled with SuperLU support");
128 libMesh::err <<
"Error: Solver " << solver <<
" is unknown."
133 #endif //LIBMESH_HAVE_PETSC
136 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
139 std::string parameters_filename =
"reduced_basis_ex7.in";
140 GetPot infile(parameters_filename);
142 const unsigned int dim = 2;
144 bool store_basis_functions = infile(
"store_basis_functions",
true);
147 GetPot command_line (argc, argv);
149 if (command_line.search(1,
"-online_mode"))
150 online_mode = command_line.next(online_mode);
165 equation_systems.
init ();
203 <<
"********************************************************************************\n"
204 <<
"Training reduced basis failed, this example requires a direct solver.\n"
205 <<
"Try running with -ksp_type preonly -pc_type lu instead.\n"
206 <<
"********************************************************************************"
212 #if defined(LIBMESH_HAVE_CAPNPROTO)
220 if (store_basis_functions)
233 #if defined(LIBMESH_HAVE_CAPNPROTO)
237 rb_eval.legacy_read_offline_data_from_files();
241 Real online_frequency = infile(
"online_frequency", 0.);
243 online_mu.
set_value(
"frequency", online_frequency);
244 rb_eval.set_parameters(online_mu);
245 rb_eval.print_parameters();
248 rb_eval.rb_solve(rb_eval.get_n_basis_functions());
250 if (store_basis_functions)
253 rb_eval.read_in_basis_functions(rb_con);
263 std::ofstream reflection_coeffs_out(
"reflection_coefficients.dat");
265 Real n_frequencies = infile(
"n_frequencies", 0.);
266 Real delta_f = (rb_eval.get_parameter_max(
"frequency") - rb_eval.get_parameter_min(
"frequency")) / (n_frequencies-1);
267 for (
unsigned int freq_i=0; freq_i<n_frequencies; freq_i++)
269 Real frequency = rb_eval.get_parameter_min(
"frequency") + freq_i * delta_f;
270 online_mu.
set_value(
"frequency", frequency);
271 rb_eval.set_parameters(online_mu);
272 rb_eval.rb_solve(rb_eval.get_n_basis_functions());
274 Number complex_one(1., 0.);
275 reflection_coeffs_out << frequency <<
" " <<
std::abs(rb_eval.RB_outputs[0] - complex_one) << std::endl;
277 reflection_coeffs_out.close();
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
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 read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
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 write_out_basis_functions(System &sys, const std::string &directory_name="offline_data", const bool write_binary_basis_functions=true)
Write out all the basis functions to file.
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.
The libMesh namespace provides an interface to certain functionality in the library.
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
const Parallel::Communicator & comm() const
int main(int argc, char **argv)
This class is part of the rbOOmit framework.
This class serializes an RBEvaluation object using the Cap'n Proto library.
SolverPackage default_solver_package()
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
void print_basis_function_orthogonality()
Print out a matrix that shows the orthogonality of the RB basis functions.
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
void write_to_file(const std::string &path)
Write the Cap'n'Proto buffer to disk.
virtual void init()
Initialize all the systems.
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.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
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 void legacy_write_offline_data_to_files(const std::string &directory_name="offline_data", const bool write_binary_data=true)
Write out all the data to text files in order to segregate the Offline stage from the Online stage.
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
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 an RBEvaluation object using the Cap'n Proto library.
void read_from_file(const std::string &path, bool read_error_bound_data)
Write the Cap'n'Proto buffer to disk.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
Train the reduced basis.