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/quadrature_gauss.h"
53#include "libmesh/libmesh_logging.h"
54#include "libmesh/nemesis_io.h"
55#include "libmesh/rb_data_serialization.h"
56#include "libmesh/rb_data_deserialization.h"
57#include "libmesh/enum_solver_package.h"
58#include "libmesh/enum_solver_type.h"
59#include "libmesh/elem_side_builder.h"
62#include "rb_classes.h"
66#define BOUNDARY_ID_MIN_Z 0
67#define BOUNDARY_ID_MIN_Y 1
68#define BOUNDARY_ID_MAX_X 2
69#define BOUNDARY_ID_MAX_Y 3
70#define BOUNDARY_ID_MIN_X 4
71#define BOUNDARY_ID_MAX_Z 5
72#define NODE_BOUNDARY_ID 10
80 const std::string & filename);
86int main(
int argc,
char ** argv)
93 "--enable-petsc, --enable-trilinos, or --enable-eigen");
95#if !defined(LIBMESH_HAVE_XDR)
97 libmesh_example_requires(
false,
"--enable-xdr");
98#elif defined(LIBMESH_DEFAULT_SINGLE_PRECISION)
100 libmesh_example_requires(
false,
"--disable-singleprecision");
101#elif defined(LIBMESH_DEFAULT_TRIPLE_PRECISION)
103 libmesh_example_requires(
false,
"double precision");
111 libmesh_example_requires(LIBMESH_DIM == 3,
"3D support");
113#ifndef LIBMESH_ENABLE_DIRICHLET
114 libmesh_example_requires(
false,
"--enable-dirichlet");
117 std::string parameters_filename =
"reduced_basis_ex5.in";
118 GetPot infile(parameters_filename);
121 infile.parse_command_line(argc, argv);
123 unsigned int n_elem_x = infile(
"n_elem_x", 0);
124 unsigned int n_elem_y = infile(
"n_elem_y", 0);
125 unsigned int n_elem_z = infile(
"n_elem_z", 0);
126 Real x_size = infile(
"x_size", 0.);
127 Real y_size = infile(
"y_size", 0.);
128 Real z_size = infile(
"z_size", 0.);
130 bool store_basis_functions = infile(
"store_basis_functions",
true);
138 const std::string mesh_filename = infile(
"mesh_filename",
"NO MESH FILE");
140 if (mesh_filename ==
"NO MESH FILE")
142 (
mesh, n_elem_x, n_elem_y, n_elem_z,
143 0., x_size, 0., y_size, 0., z_size,
HEX27);
153#if !defined(LIBMESH_HAVE_CAPNPROTO) && !defined(LIBMESH_ENABLE_UNIQUE_ID)
154 libmesh_example_requires(
false,
"--enable-unique-id or --enable-capnp");
166 for (
const auto & elem :
mesh.element_ptr_range())
167 for (
auto side : elem->side_index_range())
168 if (!elem->neighbor_ptr(side))
170 const Point side_center = side_builder(*elem, side).vertex_average();
174 if (side_center(2) < 0.1)
176 if (side_center(2) > 11.9)
186 for (
const auto & elem :
mesh.element_ptr_range())
188 unsigned int side_max_x = 0, side_max_y = 0, side_max_z = 0;
189 bool found_side_max_x =
false, found_side_max_y =
false, found_side_max_z =
false;
190 for (
auto side : elem->side_index_range())
195 found_side_max_x =
true;
201 found_side_max_y =
true;
207 found_side_max_z =
true;
214 if (found_side_max_x && found_side_max_y && found_side_max_z)
216 for (
auto n : elem->node_index_range())
218 if (elem->is_node_on_side(n, side_max_x) &&
219 elem->is_node_on_side(n, side_max_y) &&
220 elem->is_node_on_side(n, side_max_z))
240 unsigned int order = infile(
"order", 1);
268 equation_systems.
init ();
303#if defined(LIBMESH_HAVE_CAPNPROTO)
311 if (store_basis_functions)
320#if defined(LIBMESH_HAVE_CAPNPROTO)
328 Real online_x_scaling = infile(
"online_x_scaling", 0.);
329 Real online_load_Fx = infile(
"online_load_Fx", 0.);
330 Real online_load_Fy = infile(
"online_load_Fy", 0.);
331 Real online_load_Fz = infile(
"online_load_Fz", 0.);
332 Real online_point_load_Fx = infile(
"online_point_load_Fx", 0.);
333 Real online_point_load_Fy = infile(
"online_point_load_Fy", 0.);
334 Real online_point_load_Fz = infile(
"online_point_load_Fz", 0.);
336 online_mu.
set_value(
"x_scaling", online_x_scaling);
337 online_mu.
set_value(
"load_Fx", online_load_Fx);
338 online_mu.
set_value(
"load_Fy", online_load_Fy);
339 online_mu.
set_value(
"load_Fz", online_load_Fz);
340 online_mu.
set_value(
"point_load_Fx", online_point_load_Fx);
341 online_mu.
set_value(
"point_load_Fy", online_point_load_Fy);
342 online_mu.
set_value(
"point_load_Fz", online_point_load_Fz);
349 if (store_basis_functions)
367#ifdef LIBMESH_ENABLE_DIRICHLET
371 const std::string & file_basename)
376 for (
auto & node :
mesh.node_ptr_range())
382#ifdef LIBMESH_HAVE_EXODUS_API
384 bool do_exodus_write =
387 es.
comm().
min(do_exodus_write);
390#ifdef LIBMESH_HAVE_NEMESIS_API
400 for (
auto & node :
mesh.node_ptr_range())
406 LOG_SCOPE(
"compute_stresses()",
"main");
411 libmesh_assert_less_equal(
dim, 3);
415 unsigned int displacement_vars[3];
427 fe->attach_quadrature_rule (&qrule);
429 const std::vector<Real> & JxW = fe->get_JxW();
430 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
435 unsigned int sigma_vars[3][3];
453 unsigned int vonMises_var = stress_system.
variable_number (
"vonMises");
456 std::vector<std::vector<dof_id_type>> dof_indices_var(system.
n_vars());
457 std::vector<dof_id_type> stress_dof_indices_var;
462 for (
const auto & elem :
mesh.active_local_element_ptr_range())
466 if (elem->dim() !=
dim)
469 for (
unsigned int var=0; var<
dim; var++)
470 dof_map.
dof_indices (elem, dof_indices_var[var], displacement_vars[var]);
476 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
477 for (
unsigned int C_i=0; C_i<
dim; C_i++)
478 for (
unsigned int C_j=0; C_j<
dim; C_j++)
479 for (
unsigned int C_k=0; C_k<
dim; C_k++)
481 const unsigned int n_var_dofs = dof_indices_var[C_k].size();
485 for (
unsigned int l=0; l<n_var_dofs; l++)
488 for (
unsigned int C_l=0; C_l<
dim; C_l++)
489 elem_sigma(C_i,C_j) += JxW[qp] * (
elasticity_tensor(C_i, C_j, C_k, C_l) * displacement_gradient(C_l));
493 elem_sigma.
scale(1./elem->volume());
496 for (
unsigned int i=0; i<
dim; i++)
497 for (
unsigned int j=0; j<
dim; j++)
499 stress_dof_map.dof_indices (elem, stress_dof_indices_var, sigma_vars[i][j]);
505 if ((stress_system.
solution->first_local_index() <= dof_index) &&
506 (dof_index < stress_system.
solution->last_local_index()))
508 stress_system.
solution->set(dof_index, elem_sigma(i,j));
517 Number sigma00 = elem_sigma(0,0);
518 Number sigma11 = (
dim > 1) ? elem_sigma(1,1) : 0;
519 Number sigma22 = (
dim > 2) ? elem_sigma(2,2) : 0;
520 Number sum_term = pow(sigma00 - sigma11,2);
522 sum_term += pow(sigma11 - sigma22,2) +
523 6.*pow(elem_sigma(0,1),2);
525 sum_term += pow(sigma22 - sigma00,2) +
526 6.*(pow(elem_sigma(1,2),2) + pow(elem_sigma(2,0),2));
527 Number vonMises_value = std::sqrt(0.5*sum_term);
528 stress_dof_map.dof_indices (elem, stress_dof_indices_var, vonMises_var);
530 if ((stress_system.
solution->first_local_index() <= dof_index) &&
531 (dof_index < stress_system.solution->last_local_index()))
533 stress_system.
solution->set(dof_index, vonMises_value);
void min(const T &r, T &o, Request &req) const
bool has_boundary_id(const Node *const node, const boundary_id_type id) const
void add_node(const Node *node, const boundary_id_type id)
Add Node node with boundary id id to the boundary information data structures.
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
Add side side of element number elem with boundary id id to the boundary information data structure.
Defines a dense matrix for use in Finite Element-type computations.
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
void scale(const T factor)
Multiplies every element in the matrix by factor.
This class handles the numbering of degrees of freedom on a mesh.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
const FEType & variable_type(const unsigned int i) const
Helper for building element sides that minimizes the construction of new elements.
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.
const MeshBase & get_mesh() const
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.
const T_sys & get_system(std::string_view name) const
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.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Order default_quadrature_order() const
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
virtual LinearSolver< Number > * get_linear_solver() const override
void set_solver_type(const SolverType st)
Sets the type of solver to use.
This is the MeshBase class.
virtual bool is_serial() const
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
unsigned int mesh_dimension() const
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false)=0
Interfaces for reading/writing a mesh to/from a file.
constraint_rows_type & get_constraint_rows()
Constraint rows accessors.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
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 ...
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
The Nemesis_IO class implements reading parallel meshes in the Nemesis file format from Sandia Nation...
const Parallel::Communicator & comm() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
unsigned int n_points() const
This class implements specific orders of Gauss quadrature.
void set_rb_evaluation(RBEvaluation &rb_eval_in)
Set the RBEvaluation object.
virtual void print_info() const
Print out info that describes the current setup of this RBConstruction.
RBEvaluation & get_rb_evaluation()
Get a reference to the RBEvaluation object.
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.
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
Train the reduced basis.
virtual void load_rb_solution()
Load the RB solution from the most recent solve with rb_eval into this system's solution vector.
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...
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 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.
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.
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.
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 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.
virtual void legacy_read_offline_data_from_files(const std::string &directory_name="offline_data", bool read_error_bound_data=true, const bool read_binary_data=true)
Read in the saved Offline reduced basis data to initialize the system for Online solves.
This class is part of the rbOOmit framework.
Real get_value(const std::string ¶m_name) const
Get the value of the specified parameter, throw an error if it does not exist.
void set_value(const std::string ¶m_name, Real value)
Set the value of the specified parameter.
const RBParameters & get_parameters() const
Get the current 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.
Number current_solution(const dof_id_type global_dof_number) const
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
virtual void update()
Update the local values to reflect the solution on neighboring processors.
unsigned int variable_number(std::string_view var) const
unsigned int n_vars() const
const DofMap & get_dof_map() const
void add_scaled(const TypeVector< T2 > &, const T &)
Add a scaled value to this vector without creating a temporary.
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
void libmesh_ignore(const Args &...)
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
Real elasticity_tensor(unsigned int i, unsigned int j, unsigned int k, unsigned int l)
void scale_mesh_and_plot(EquationSystems &es, const RBParameters &mu, const std::string &filename)
void compute_stresses(EquationSystems &es)