libMesh
Functions
reduced_basis_ex6.C File Reference

Go to the source code of this file.

Functions

void transform_mesh_and_plot (EquationSystems &es, Real curvature, const std::string &filename)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 111 of file reduced_basis_ex6.C.

112 {
113  // Initialize libMesh.
114  LibMeshInit init (argc, argv);
115 
116  // This example requires a linear solver package.
117  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
118  "--enable-petsc, --enable-trilinos, or --enable-eigen");
119 
120 #if !defined(LIBMESH_HAVE_XDR)
121  // We need XDR support to write out reduced bases
122  libmesh_example_requires(false, "--enable-xdr");
123 #elif defined(LIBMESH_DEFAULT_SINGLE_PRECISION)
124  // XDR binary support requires double precision
125  libmesh_example_requires(false, "--disable-singleprecision");
126 #elif defined(LIBMESH_DEFAULT_TRIPLE_PRECISION)
127  // I have no idea why long double isn't working here... [RHS]
128  libmesh_example_requires(false, "double precision");
129 #elif defined(LIBMESH_ENABLE_BLOCKED_STORAGE)
130  // This example dies with "New nonzero at (0,2) caused a malloc"
131  // when blocked storage is enabled.
132  libmesh_example_requires(false, "--disable-blocked-storage");
133 #endif
134 
135  // This is a 3D example
136  libmesh_example_requires(3 == LIBMESH_DIM, "3D support");
137 
138 #ifndef LIBMESH_ENABLE_DIRICHLET
139  libmesh_example_requires(false, "--enable-dirichlet");
140 #else
141 
142  // Parse the input file using GetPot
143  std::string eim_parameters = "eim.in";
144  std::string rb_parameters = "rb.in";
145  std::string main_parameters = "reduced_basis_ex6.in";
146  GetPot infile(main_parameters);
147 
148  unsigned int n_elem_xy = infile("n_elem_xy", 1);
149  unsigned int n_elem_z = infile("n_elem_z", 1);
150 
151  // Do we write the RB basis functions to disk?
152  bool store_basis_functions = infile("store_basis_functions", true);
153 
154  // Read the "online_mode" flag from the command line
155  GetPot command_line (argc, argv);
156  int online_mode = 0;
157  if (command_line.search(1, "-online_mode"))
158  online_mode = command_line.next(online_mode);
159 
160  // Create a mesh, with dimension to be overridden by build_cube, on
161  // the default MPI communicator. We currently have to create a
162  // ReplicatedMesh here due to a reduced_basis regression with
163  // DistributedMesh
164  ReplicatedMesh mesh(init.comm());
165 
167  n_elem_xy, n_elem_xy, n_elem_z,
168  -0.2, 0.2,
169  -0.2, 0.2,
170  0., 3.,
171  HEX8);
172 
173  // Create an equation systems object.
174  EquationSystems equation_systems (mesh);
175 
176  SimpleEIMConstruction & eim_construction =
177  equation_systems.add_system<SimpleEIMConstruction> ("EIM");
178  SimpleRBConstruction & rb_construction =
179  equation_systems.add_system<SimpleRBConstruction> ("RB");
180 
181  // Initialize the data structures for the equation system.
182  equation_systems.init ();
183 
184  // Print out some information about the "truth" discretization
185  equation_systems.print_info();
186  mesh.print_info();
187 
188  // Initialize the standard RBEvaluation object
189  SimpleRBEvaluation rb_eval(mesh.comm());
190 
191  // Initialize the EIM RBEvaluation object
192  SimpleEIMEvaluation eim_rb_eval(mesh.comm());
193 
194  // Set the rb_eval objects for the RBConstructions
195  eim_construction.set_rb_evaluation(eim_rb_eval);
196  rb_construction.set_rb_evaluation(rb_eval);
197 
198  if (!online_mode) // Perform the Offline stage of the RB method
199  {
200  // Read data from input file and print state
201  eim_construction.process_parameters_file(eim_parameters);
202  eim_construction.print_info();
203 
204  // Perform the EIM Greedy and write out the data
205  eim_construction.initialize_rb_construction();
206 
207  eim_construction.train_reduced_basis();
208 
209 #if defined(LIBMESH_HAVE_CAPNPROTO)
210  RBDataSerialization::RBEIMEvaluationSerialization rb_eim_eval_writer(eim_rb_eval);
211  rb_eim_eval_writer.write_to_file("rb_eim_eval.bin");
212 #else
213  eim_construction.get_rb_evaluation().legacy_write_offline_data_to_files("eim_data");
214 #endif
215 
216  // Read data from input file and print state
217  rb_construction.process_parameters_file(rb_parameters);
218 
219  // attach the EIM theta objects to the RBEvaluation
220  eim_rb_eval.initialize_eim_theta_objects();
221  rb_eval.get_rb_theta_expansion().attach_multiple_A_theta(eim_rb_eval.get_eim_theta_objects());
222 
223  // attach the EIM assembly objects to the RBConstruction
224  eim_construction.initialize_eim_assembly_objects();
225  rb_construction.get_rb_assembly_expansion().attach_multiple_A_assembly(eim_construction.get_eim_assembly_objects());
226 
227  // Print out the state of rb_construction now that the EIM objects have been attached
228  rb_construction.print_info();
229 
230  // Need to initialize _after_ EIM greedy so that
231  // the system knows how many affine terms there are
232  rb_construction.initialize_rb_construction();
233  rb_construction.train_reduced_basis();
234 
235 #if defined(LIBMESH_HAVE_CAPNPROTO)
236  RBDataSerialization::RBEvaluationSerialization rb_eval_writer(rb_construction.get_rb_evaluation());
237  rb_eval_writer.write_to_file("rb_eval.bin");
238 #else
239  rb_construction.get_rb_evaluation().legacy_write_offline_data_to_files("rb_data");
240 #endif
241 
242  // Write out the basis functions, if requested
243  if (store_basis_functions)
244  {
245  // Write out the basis functions
246  eim_construction.get_rb_evaluation().write_out_basis_functions(eim_construction.get_explicit_system(),
247  "eim_data");
248  rb_construction.get_rb_evaluation().write_out_basis_functions(rb_construction,
249  "rb_data");
250  }
251  }
252  else // Perform the Online stage of the RB method
253  {
254 #if defined(LIBMESH_HAVE_CAPNPROTO)
255  RBDataDeserialization::RBEIMEvaluationDeserialization rb_eim_eval_reader(eim_rb_eval);
256  rb_eim_eval_reader.read_from_file("rb_eim_eval.bin");
257 #else
258  eim_rb_eval.legacy_read_offline_data_from_files("eim_data");
259 #endif
260 
261  // attach the EIM theta objects to rb_eval objects
262  eim_rb_eval.initialize_eim_theta_objects();
263  rb_eval.get_rb_theta_expansion().attach_multiple_A_theta(eim_rb_eval.get_eim_theta_objects());
264 
265  // Read in the offline data for rb_eval
266 #if defined(LIBMESH_HAVE_CAPNPROTO)
268  rb_eval_reader.read_from_file("rb_eval.bin", /*read_error_bound_data*/ true);
269 #else
270  rb_eval.legacy_read_offline_data_from_files("rb_data");
271 #endif
272 
273  // Get the parameters at which we will do a reduced basis solve
274  Real online_curvature = infile("online_curvature", 0.);
275  Real online_Bi = infile("online_Bi", 0.);
276  Real online_kappa = infile("online_kappa", 0.);
277  RBParameters online_mu;
278  online_mu.set_value("curvature", online_curvature);
279  online_mu.set_value("Bi", online_Bi);
280  online_mu.set_value("kappa", online_kappa);
281  rb_eval.set_parameters(online_mu);
282  rb_eval.print_parameters();
283  rb_eval.rb_solve(rb_eval.get_n_basis_functions());
284 
285  // plot the solution, if requested
286  if (store_basis_functions)
287  {
288  // read in the data from files
289  eim_rb_eval.read_in_basis_functions(
290  eim_construction.get_explicit_system(), "eim_data");
291  rb_eval.read_in_basis_functions(rb_construction, "rb_data");
292 
293  eim_construction.load_rb_solution();
294  rb_construction.load_rb_solution();
295 
296  transform_mesh_and_plot(equation_systems, online_curvature, "RB_sol.e");
297  }
298  }
299 
300 #endif // LIBMESH_ENABLE_DIRICHLET
301 
302  return 0;
303 }

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_cube(), libMesh::ParallelObject::comm(), libMesh::default_solver_package(), libMesh::HEX8, libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), libMesh::INVALID_SOLVER_PACKAGE, mesh, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::RBDataDeserialization::RBEvaluationDeserialization::read_from_file(), libMesh::RBDataDeserialization::RBEIMEvaluationDeserialization::read_from_file(), libMesh::Real, libMesh::RBParameters::set_value(), transform_mesh_and_plot(), libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file(), and libMesh::RBDataSerialization::RBEIMEvaluationSerialization::write_to_file().

◆ transform_mesh_and_plot()

void transform_mesh_and_plot ( EquationSystems es,
Real  curvature,
const std::string &  filename 
)

Definition at line 307 of file reduced_basis_ex6.C.

310 {
311  // Loop over the mesh nodes and move them!
312  MeshBase & mesh = es.get_mesh();
313 
314  for (auto & node : mesh.node_ptr_range())
315  {
316  Real x = (*node)(0);
317  Real z = (*node)(2);
318 
319  (*node)(0) = -1./curvature + (1./curvature + x)*cos(curvature*z);
320  (*node)(2) = (1./curvature + x)*sin(curvature*z);
321  }
322 
323 #ifdef LIBMESH_HAVE_EXODUS_API
324  ExodusII_IO(mesh).write_equation_systems(filename, es);
325 #endif
326 }

References libMesh::EquationSystems::get_mesh(), mesh, libMesh::MeshBase::node_ptr_range(), libMesh::Real, and libMesh::MeshOutput< MT >::write_equation_systems().

Referenced by main().

SimpleRBConstruction
Definition: rb_classes.h:73
libMesh::EquationSystems::get_mesh
const MeshBase & get_mesh() const
Definition: equation_systems.h:637
libMesh::HEX8
Definition: enum_elem_type.h:47
SimpleEIMConstruction
Definition: eim_classes.h:40
libMesh::System::init
void init()
Initializes degrees of freedom on the current mesh.
Definition: system.C:237
libMesh::MeshTools::Generation::build_cube
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
Definition: mesh_generation.C:298
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
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::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
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::MeshBase::node_ptr_range
virtual SimpleRange< node_iterator > node_ptr_range()=0
libMesh::INVALID_SOLVER_PACKAGE
Definition: enum_solver_package.h:43
transform_mesh_and_plot
void transform_mesh_and_plot(EquationSystems &es, Real curvature, const std::string &filename)
Definition: reduced_basis_ex6.C:307
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