libMesh
Functions
reduced_basis_ex4.C File Reference

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 58 of file reduced_basis_ex4.C.

59 {
60  // Initialize libMesh.
61  LibMeshInit init (argc, argv);
62 
63  // This example requires a linear solver package.
64  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
65  "--enable-petsc, --enable-trilinos, or --enable-eigen");
66 
67 #if !defined(LIBMESH_HAVE_XDR)
68  // We need XDR support to write out reduced bases
69  libmesh_example_requires(false, "--enable-xdr");
70 #elif defined(LIBMESH_DEFAULT_SINGLE_PRECISION)
71  // XDR binary support requires double precision
72  libmesh_example_requires(false, "double precision");
73 #elif defined(LIBMESH_DEFAULT_TRIPLE_PRECISION)
74  // I have no idea why long double isn't working here... [RHS]
75  libmesh_example_requires(false, "double precision");
76 #endif
77 
78  // Skip this 2D example if libMesh was compiled as 1D-only.
79  libmesh_example_requires(2 <= LIBMESH_DIM, "2D support");
80 
81 #ifndef LIBMESH_ENABLE_DIRICHLET
82  libmesh_example_requires(false, "--enable-dirichlet");
83 #else
84 
85  // Define the names of the input files we will read the problem properties from
86  std::string eim_parameters = "eim.in";
87  std::string rb_parameters = "rb.in";
88  std::string main_parameters = "reduced_basis_ex4.in";
89  GetPot infile(main_parameters);
90 
91  unsigned int n_elem = infile("n_elem", 1); // Determines the number of elements in the "truth" mesh
92  const unsigned int dim = 2; // The number of spatial dimensions
93  bool store_basis_functions = infile("store_basis_functions", false); // Do we write out basis functions?
94 
95  // Read the "online_mode" flag from the command line
96  GetPot command_line (argc, argv);
97  int online_mode = 0;
98  if (command_line.search(1, "-online_mode"))
99  online_mode = command_line.next(online_mode);
100 
101  // Create a mesh (just a simple square) on the default MPI
102  // communicator. We currently have to create a ReplicatedMesh here
103  // due to a reduced_basis regression with DistributedMesh
104  ReplicatedMesh mesh (init.comm(), dim);
106  n_elem, n_elem,
107  -1., 1.,
108  -1., 1.,
109  QUAD4);
110 
111  // Initialize the EquationSystems object for this mesh and attach
112  // the EIM and RB Construction objects
113  EquationSystems equation_systems (mesh);
114 
115  SimpleEIMConstruction & eim_construction =
116  equation_systems.add_system<SimpleEIMConstruction> ("EIM");
117  SimpleRBConstruction & rb_construction =
118  equation_systems.add_system<SimpleRBConstruction> ("RB");
119 
120  // Initialize the data structures for the equation system.
121  equation_systems.init ();
122 
123  // Print out some information about the "truth" discretization
124  mesh.print_info();
125  equation_systems.print_info();
126 
127  // Initialize the standard RBEvaluation object
128  SimpleRBEvaluation rb_eval(mesh.comm());
129 
130  // Initialize the EIM RBEvaluation object
131  SimpleEIMEvaluation eim_rb_eval(mesh.comm());
132 
133  // Set the rb_eval objects for the RBConstructions
134  eim_construction.set_rb_evaluation(eim_rb_eval);
135  rb_construction.set_rb_evaluation(rb_eval);
136 
137  if (!online_mode)
138  {
139  // Read data from input file and print state
140  eim_construction.process_parameters_file(eim_parameters);
141  eim_construction.print_info();
142 
143  // Perform the EIM Greedy and write out the data
144  eim_construction.initialize_rb_construction();
145  eim_construction.train_reduced_basis();
146 
147 #if defined(LIBMESH_HAVE_CAPNPROTO)
148  RBDataSerialization::RBEIMEvaluationSerialization rb_eim_eval_writer(eim_rb_eval);
149  rb_eim_eval_writer.write_to_file("rb_eim_eval.bin");
150 #else
151  eim_construction.get_rb_evaluation().legacy_write_offline_data_to_files("eim_data");
152 #endif
153 
154  // Read data from input file and print state
155  rb_construction.process_parameters_file(rb_parameters);
156 
157  // attach the EIM theta objects to the RBConstruction and RBEvaluation objects
158  eim_rb_eval.initialize_eim_theta_objects();
159  rb_eval.get_rb_theta_expansion().attach_multiple_F_theta(eim_rb_eval.get_eim_theta_objects());
160 
161  // attach the EIM assembly objects to the RBConstruction object
162  eim_construction.initialize_eim_assembly_objects();
163  rb_construction.get_rb_assembly_expansion().attach_multiple_F_assembly(eim_construction.get_eim_assembly_objects());
164 
165  // Print out the state of rb_construction now that the EIM objects have been attached
166  rb_construction.print_info();
167 
168  // Need to initialize _after_ EIM greedy so that
169  // the system knows how many affine terms there are
170  rb_construction.initialize_rb_construction();
171  rb_construction.train_reduced_basis();
172 
173 #if defined(LIBMESH_HAVE_CAPNPROTO)
174  RBDataSerialization::RBEvaluationSerialization rb_eval_writer(rb_construction.get_rb_evaluation());
175  rb_eval_writer.write_to_file("rb_eval.bin");
176 #else
177  rb_construction.get_rb_evaluation().legacy_write_offline_data_to_files("rb_data");
178 #endif
179 
180  // Write out the basis functions, if requested
181  if (store_basis_functions)
182  {
183  // Write out the basis functions
184  eim_construction.get_rb_evaluation().write_out_basis_functions(eim_construction.get_explicit_system(),
185  "eim_data");
186 
187  rb_construction.get_rb_evaluation().write_out_basis_functions(rb_construction,
188  "rb_data");
189  }
190  }
191  else
192  {
193 #if defined(LIBMESH_HAVE_CAPNPROTO)
194  RBDataDeserialization::RBEIMEvaluationDeserialization rb_eim_eval_reader(eim_rb_eval);
195  rb_eim_eval_reader.read_from_file("rb_eim_eval.bin");
196 #else
197  eim_rb_eval.legacy_read_offline_data_from_files("eim_data");
198 #endif
199 
200  // attach the EIM theta objects to rb_eval objects
201  eim_rb_eval.initialize_eim_theta_objects();
202  rb_eval.get_rb_theta_expansion().attach_multiple_F_theta(eim_rb_eval.get_eim_theta_objects());
203 
204  // Read in the offline data for rb_eval
205 #if defined(LIBMESH_HAVE_CAPNPROTO)
207  rb_eval_reader.read_from_file("rb_eval.bin", /*read_error_bound_data*/ true);
208 #else
209  rb_eval.legacy_read_offline_data_from_files("rb_data");
210 #endif
211 
212  // Get the parameters at which we will do a reduced basis solve
213  Real online_center_x = infile("online_center_x", 0.);
214  Real online_center_y = infile("online_center_y", 0.);
215  RBParameters online_mu;
216  online_mu.set_value("center_x", online_center_x);
217  online_mu.set_value("center_y", online_center_y);
218  rb_eval.set_parameters(online_mu);
219  rb_eval.print_parameters();
220  rb_eval.rb_solve(rb_eval.get_n_basis_functions());
221 
222  // plot the solution, if requested
223  if (store_basis_functions)
224  {
225  // read in the data from files
226  eim_rb_eval.read_in_basis_functions(eim_construction.get_explicit_system(), "eim_data");
227  rb_eval.read_in_basis_functions(rb_construction, "rb_data");
228 
229  eim_construction.load_rb_solution();
230  rb_construction.load_rb_solution();
231 #ifdef LIBMESH_HAVE_EXODUS_API
232  ExodusII_IO(mesh).write_equation_systems("RB_sol.e", equation_systems);
233 #endif
234  }
235  }
236 
237 #endif // LIBMESH_ENABLE_DIRICHLET
238 }

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_square(), libMesh::ParallelObject::comm(), libMesh::default_solver_package(), dim, libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), libMesh::INVALID_SOLVER_PACKAGE, mesh, libMesh::MeshTools::n_elem(), libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::QUAD4, libMesh::RBDataDeserialization::RBEvaluationDeserialization::read_from_file(), libMesh::RBDataDeserialization::RBEIMEvaluationDeserialization::read_from_file(), libMesh::Real, libMesh::RBParameters::set_value(), libMesh::MeshOutput< MT >::write_equation_systems(), libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file(), and libMesh::RBDataSerialization::RBEIMEvaluationSerialization::write_to_file().

SimpleRBConstruction
Definition: rb_classes.h:73
libMesh::MeshTools::n_elem
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:705
SimpleEIMConstruction
Definition: eim_classes.h:40
libMesh::System::init
void init()
Initializes degrees of freedom on the current mesh.
Definition: system.C:237
SimpleEIMEvaluation
Definition: eim_classes.h:23
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::RBParameters
This class is part of the rbOOmit framework.
Definition: rb_parameters.h:42
libMesh::RBDataSerialization::RBEvaluationSerialization
This class serializes an RBEvaluation object using the Cap'n Proto library.
Definition: rb_data_serialization.h:58
libMesh::default_solver_package
SolverPackage default_solver_package()
Definition: libmesh.C:993
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::ExodusII_IO
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:51
dim
unsigned int dim
Definition: adaptivity_ex3.C:113
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::MeshTools::Generation::build_square
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
Definition: mesh_generation.C:1501
libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file
void write_to_file(const std::string &path)
Write the Cap'n'Proto buffer to disk.
Definition: rb_data_serialization.C:82
libMesh::INVALID_SOLVER_PACKAGE
Definition: enum_solver_package.h:43
libMesh::QUAD4
Definition: enum_elem_type.h:41
libMesh::RBParameters::set_value
void set_value(const std::string &param_name, Real value)
Set the value of the specified parameter.
Definition: rb_parameters.C:47
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
libMesh::RBDataSerialization::RBEIMEvaluationSerialization
This class serializes an RBEIMEvaluation object using the Cap'n Proto library.
Definition: rb_data_serialization.h:124
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::MeshOutput::write_equation_systems
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 ...
Definition: mesh_output.C:31
SimpleRBEvaluation
Definition: rb_classes.h:45
libMesh::MeshBase::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
Definition: mesh_base.C:585
libMesh::RBDataDeserialization::RBEvaluationDeserialization
This class de-serializes an RBEvaluation object using the Cap'n Proto library.
Definition: rb_data_deserialization.h:60
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::RBDataDeserialization::RBEIMEvaluationDeserialization
This class de-serializes a RBEIMEvaluation object using the Cap'n Proto library.
Definition: rb_data_deserialization.h:126