libMesh
Loading...
Searching...
No Matches
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 // This example requires libmesh to be configured with both
139 // DirichletBoundary and Cap'n Proto support.
140#if !defined(LIBMESH_ENABLE_DIRICHLET) || !defined(LIBMESH_HAVE_CAPNPROTO)
141 libmesh_example_requires(false, "--enable-dirichlet --enable-capnp");
142#else
143
144 // Parse the input file using GetPot
145 std::string eim_parameters = "eim.in";
146 std::string rb_parameters = "rb.in";
147 std::string main_parameters = "reduced_basis_ex6.in";
148 GetPot infile(main_parameters);
149
150 unsigned int n_elem_xy = infile("n_elem_xy", 1);
151 unsigned int n_elem_z = infile("n_elem_z", 1);
152
153 // Read the "online_mode" flag from the command line
154 const int online_mode =
155 libMesh::command_line_next("-online_mode", 0);
156
157 // Create a mesh, with dimension to be overridden by build_cube, on
158 // the default MPI communicator. We currently have to create a
159 // ReplicatedMesh here due to a reduced_basis regression with
160 // DistributedMesh
161 ReplicatedMesh mesh(init.comm());
162
164 n_elem_xy, n_elem_xy, n_elem_z,
165 -0.2, 0.2,
166 -0.2, 0.2,
167 0., 3.,
168 HEX8);
169
170 if (!online_mode)
171 {
172 // First run the Offline stage for the EIM approximation.
173 {
174 libMesh::out << "Perform EIM training" << std::endl << std::endl;
175
176 // Initialize the EquationSystems object for this mesh and attach
177 // the EIM and RB Construction objects
178 EquationSystems equation_systems (mesh);
179
180 SimpleEIMConstruction & eim_construction =
181 equation_systems.add_system<SimpleEIMConstruction> ("EIM");
182
183 // Initialize the data structures for the equation system.
184 equation_systems.init ();
185
186 // Print out some information about the "truth" discretization
188 equation_systems.print_info();
189
190 // Initialize the EIM RBEvaluation object
191 SimpleEIMEvaluation eim_rb_eval(mesh.comm());
192
193 // Set the rb_eval objects for the RBConstructions
194 eim_construction.set_rb_eim_evaluation(eim_rb_eval);
195
196 // Read data from input file and print state
197 eim_construction.process_parameters_file(eim_parameters);
198 eim_construction.print_info();
199
200 // Perform the EIM Greedy and write out the data
201 eim_construction.initialize_eim_construction();
202 eim_construction.train_eim_approximation();
203
204 RBDataSerialization::RBEIMEvaluationSerialization rb_eim_eval_writer(eim_rb_eval);
205 rb_eim_eval_writer.write_to_file("rb_eim_eval.bin");
206
207 // Write out the EIM basis functions
208 eim_rb_eval.write_out_basis_functions("eim_data", /*binary=*/false);
209 }
210
211 {
212 libMesh::out << std::endl << "Perform RB training" << std::endl << std::endl;
213
214 // Create an equation systems object.
215 EquationSystems equation_systems (mesh);
216
217 SimpleEIMConstruction & eim_construction =
218 equation_systems.add_system<SimpleEIMConstruction> ("EIM");
219 SimpleRBConstruction & rb_construction =
220 equation_systems.add_system<SimpleRBConstruction> ("RB");
221
222 // Initialize the data structures for the equation system.
223 equation_systems.init ();
224
225 // Print out some information about the "truth" discretization
226 equation_systems.print_info();
228
229 // Initialize the standard RBEvaluation object
230 SimpleRBEvaluation rb_eval(mesh.comm());
231
232 // Initialize the EIM RBEvaluation object
233 SimpleEIMEvaluation eim_rb_eval(mesh.comm());
234
235 // Set the rb_eval objects for the RBConstructions
236 eim_construction.set_rb_eim_evaluation(eim_rb_eval);
237 rb_construction.set_rb_evaluation(rb_eval);
238
239 RBDataDeserialization::RBEIMEvaluationDeserialization rb_eim_eval_reader(eim_rb_eval);
240 rb_eim_eval_reader.read_from_file("rb_eim_eval.bin");
241 eim_rb_eval.read_in_basis_functions(rb_construction, "eim_data", /*binary=*/false);
242
243 // Read data from input file and print state
244 rb_construction.process_parameters_file(rb_parameters);
245
246 // attach the EIM theta objects to the RBEvaluation
247 eim_rb_eval.initialize_eim_theta_objects();
248 rb_eval.get_rb_theta_expansion().attach_multiple_A_theta(eim_rb_eval.get_eim_theta_objects());
249
250 // attach the EIM assembly objects to the RBConstruction
251 eim_construction.initialize_eim_assembly_objects();
252 rb_construction.get_rb_assembly_expansion().attach_multiple_A_assembly(eim_construction.get_eim_assembly_objects());
253
254 // Print out the state of rb_construction now that the EIM objects have been attached
255 rb_construction.print_info();
256
257 // Need to initialize _after_ EIM greedy so that
258 // the system knows how many affine terms there are
259 rb_construction.initialize_rb_construction();
260 rb_construction.train_reduced_basis();
261
262 RBDataSerialization::RBEvaluationSerialization rb_eval_writer(rb_construction.get_rb_evaluation());
263 rb_eval_writer.write_to_file("rb_eval.bin");
264
265 // Write out the basis functions
266 rb_construction.get_rb_evaluation().write_out_basis_functions(rb_construction,
267 "rb_data");
268 }
269 }
270 else
271 {
272 SimpleEIMEvaluation eim_rb_eval(mesh.comm());
273 SimpleRBEvaluation rb_eval(mesh.comm());
274
275 RBDataDeserialization::RBEIMEvaluationDeserialization rb_eim_eval_reader(eim_rb_eval);
276 rb_eim_eval_reader.read_from_file("rb_eim_eval.bin");
277
278 // attach the EIM theta objects to rb_eval objects
279 eim_rb_eval.initialize_eim_theta_objects();
280 rb_eval.get_rb_theta_expansion().attach_multiple_A_theta(eim_rb_eval.get_eim_theta_objects());
281
283 rb_eval_reader.read_from_file("rb_eval.bin", /*read_error_bound_data*/ true);
284
285 // Get the parameters at which we will do a reduced basis solve
286 Real online_curvature = infile("online_curvature", 0.);
287 Real online_Bi = infile("online_Bi", 0.);
288 Real online_kappa = infile("online_kappa", 0.);
289 RBParameters online_mu;
290 online_mu.set_value("curvature", online_curvature);
291 online_mu.set_value("Bi", online_Bi);
292 online_mu.set_value("kappa", online_kappa);
293 rb_eval.set_parameters(online_mu);
294 rb_eval.print_parameters();
295 rb_eval.rb_solve(rb_eval.get_n_basis_functions());
296
297 EquationSystems equation_systems (mesh);
298
299 SimpleRBConstruction & rb_construction =
300 equation_systems.add_system<SimpleRBConstruction> ("RB");
301
302 equation_systems.init ();
303
304 rb_construction.set_rb_evaluation(rb_eval);
305
306 // read in the data from files
307 rb_eval.read_in_basis_functions(rb_construction, "rb_data");
308 rb_construction.load_rb_solution();
309
310 transform_mesh_and_plot(equation_systems, online_curvature, "RB_sol.e");
311 }
312
313#endif // LIBMESH_ENABLE_DIRICHLET
314
315 return 0;
316}
This is the EquationSystems class.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
Definition mesh_base.C:1755
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.
This class de-serializes an RBEvaluation object using the Cap'n Proto library.
This class serializes an RBEIMEvaluation object using the Cap'n Proto library.
This class serializes an RBEvaluation object using the Cap'n Proto library.
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 &parameters_filename)
Read parameters in from file and set up this system accordingly.
This class is part of the rbOOmit framework.
void set_value(const std::string &param_name, Real value)
Set the value of the specified parameter.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
void init()
Initializes degrees of freedom on the current mesh.
Definition system.C:196
MeshBase & mesh
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.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
SolverPackage default_solver_package()
Definition libmesh.C:1064
OStreamProxy out
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
Definition libmesh.C:1025
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void transform_mesh_and_plot(EquationSystems &es, Real curvature, const std::string &filename)

References libMesh::EquationSystems::add_system(), libMesh::RBThetaExpansion::attach_multiple_A_theta(), libMesh::MeshTools::Generation::build_cube(), libMesh::ParallelObject::comm(), libMesh::command_line_next(), libMesh::default_solver_package(), libMesh::RBEIMConstruction::get_eim_assembly_objects(), libMesh::RBEvaluation::get_n_basis_functions(), libMesh::RBEvaluation::get_rb_theta_expansion(), libMesh::HEX8, libMesh::EquationSystems::init(), libMesh::RBEIMConstruction::initialize_eim_assembly_objects(), libMesh::RBEIMConstruction::initialize_eim_construction(), libMesh::INVALID_SOLVER_PACKAGE, libMesh::RBConstruction::load_rb_solution(), main(), mesh, libMesh::out, libMesh::RBEIMConstruction::print_info(), libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::RBParametrized::print_parameters(), libMesh::RBEIMConstruction::process_parameters_file(), libMesh::RBEvaluation::rb_solve(), libMesh::RBDataDeserialization::RBEvaluationDeserialization::read_from_file(), libMesh::RBDataDeserialization::RBEIMEvaluationDeserialization::read_from_file(), libMesh::RBEvaluation::read_in_basis_functions(), libMesh::Real, libMesh::RBParametrized::set_parameters(), libMesh::RBEIMConstruction::set_rb_eim_evaluation(), libMesh::RBConstruction::set_rb_evaluation(), libMesh::RBParameters::set_value(), libMesh::RBEIMConstruction::train_eim_approximation(), 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 320 of file reduced_basis_ex6.C.

323{
324 // Loop over the mesh nodes and move them!
325 MeshBase & mesh = es.get_mesh();
326
327 for (auto & node : mesh.node_ptr_range())
328 {
329 Real x = (*node)(0);
330 Real z = (*node)(2);
331
332 (*node)(0) = -1./curvature + (1./curvature + x)*cos(curvature*z);
333 (*node)(2) = (1./curvature + x)*sin(curvature*z);
334 }
335
336#ifdef LIBMESH_HAVE_EXODUS_API
338#endif
339
340 // Avoid unused variable warnings in the --disable-exodus case
341 libmesh_ignore(filename, es);
342}
const MeshBase & get_mesh() const
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition exodusII_io.h:53
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.
This is the MeshBase class.
Definition mesh_base.h:81
void libmesh_ignore(const Args &...)

References libMesh::EquationSystems::get_mesh(), libMesh::libmesh_ignore(), mesh, libMesh::Real, and libMesh::ExodusII_IO::write_equation_systems().

Referenced by main().