43 #include "libmesh/libmesh.h" 44 #include "libmesh/replicated_mesh.h" 45 #include "libmesh/gmv_io.h" 46 #include "libmesh/vtk_io.h" 47 #include "libmesh/newmark_system.h" 48 #include "libmesh/equation_systems.h" 49 #include "libmesh/enum_solver_package.h" 52 #include "libmesh/fe.h" 55 #include "libmesh/quadrature_gauss.h" 58 #include "libmesh/dense_matrix.h" 59 #include "libmesh/dense_vector.h" 65 #include "libmesh/sparse_matrix.h" 66 #include "libmesh/numeric_vector.h" 70 #include "libmesh/dof_map.h" 73 #include "libmesh/node.h" 76 #include "libmesh/elem.h" 85 const std::string & system_name);
91 const std::string & system_name);
97 const std::string & system_name);
100 int main (
int argc,
char** argv)
107 "--enable-petsc, --enable-trilinos, or --enable-eigen");
110 libmesh_error_msg_if(argc < 2,
"Usage: " << argv[0] <<
" [meshfile]");
115 for (
int i=1; i<argc; i++)
127 std::string mesh_file = argv[1];
128 libMesh::out <<
"Mesh file is: " << mesh_file << std::endl;
131 libmesh_example_requires(3 <= LIBMESH_DIM,
"3D support");
148 const unsigned int result_node = 274;
157 const Real delta_t = .0000625;
160 unsigned int n_time_steps = 300;
187 t_system.set_newmark_parameters(delta_t);
199 equation_systems.
init();
205 std::ofstream res_out(
"pressure_node.res");
209 const unsigned int res_node_no = result_node;
211 unsigned int dof_no = res_node.
dof_number(0, 0, 0);
225 res_out <<
"# pressure at node " << res_node_no <<
"\n" 226 <<
"# time\tpressure\n" 227 << t_system.time <<
"\t" << 0 << std::endl;
230 for (
unsigned int time_step=0; time_step<n_time_steps; time_step++)
234 t_system.time += delta_t;
237 t_system.update_rhs();
252 equation_systems.
parameters.
set<
bool>(
"Newmark set BC for Matrix") =
true;
257 equation_systems.
parameters.
set<
bool>(
"Newmark set BC for Matrix") =
false;
268 if (time_step == 30 || time_step == 60 ||
269 time_step == 90 || time_step == 120)
271 std::ostringstream file_name;
273 #ifdef LIBMESH_HAVE_VTK 296 t_system.update_u_v_a();
301 std::vector<Number> global_displacement(displacement.
size());
302 displacement.
localize(global_displacement);
307 res_out << t_system.time <<
"\t" 308 << global_displacement[dof_no]
319 const std::string & system_name)
323 libmesh_assert_equal_to (system_name,
"Wave");
342 FEType fe_type = t_system.get_dof_map().variable_type(0);
374 fe->attach_quadrature_rule (&qrule);
377 const std::vector<Real> & JxW = fe->get_JxW();
380 const std::vector<std::vector<Real>> & phi = fe->get_phi();
384 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
389 const DofMap & dof_map = t_system.get_dof_map();
399 std::vector<dof_id_type> dof_indices;
404 for (
const auto & elem :
mesh.active_local_element_ptr_range())
425 const unsigned int n_dof_indices = dof_indices.size();
427 Ke.
resize (n_dof_indices, n_dof_indices);
428 Ce.
resize (n_dof_indices, n_dof_indices);
429 Me.
resize (n_dof_indices, n_dof_indices);
430 zero_matrix.
resize (n_dof_indices, n_dof_indices);
431 Fe.
resize (n_dof_indices);
436 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
441 for (std::size_t i=0; i<phi.size(); i++)
442 for (std::size_t j=0; j<phi.size(); j++)
444 Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
445 Me(i,j) += JxW[qp]*phi[i][qp]*phi[j][qp]
460 for (
auto side : elem->side_index_range())
461 if (elem->neighbor_ptr(side) ==
nullptr)
474 fe_face->attach_quadrature_rule (&qface);
478 const std::vector<std::vector<Real>> & phi_face = fe_face->get_phi();
482 const std::vector<Real> & JxW_face = fe_face->get_JxW();
486 fe_face->reinit(elem, side);
490 const Real acc_n_value = 1.0;
493 for (
unsigned int qp=0; qp<qface.
n_points(); qp++)
497 for (std::size_t i=0; i<phi_face.size(); i++)
499 Fe(i) += acc_n_value*rho
500 *phi_face[i][qp]*JxW_face[qp];
539 const std::string & system_name)
560 const std::string & system_name)
564 libmesh_assert_equal_to (system_name,
"Wave");
581 const bool do_for_matrix =
587 for (
unsigned int n_cnt=0; n_cnt<
n_nodes; n_cnt++)
597 const Real z_coo = 4.;
599 if (std::abs(curr_node(2)-z_coo) <
TOLERANCE)
602 unsigned int dn = curr_node.
dof_number(0, 0, 0);
605 const Real penalty = 1.e10;
610 if (t_system.
time < .002)
611 p_value = sin(2*
pi*t_system.
time/.002);
616 rhs.
add(dn, p_value*penalty);
621 matrix.add(dn, dn, penalty);
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
This is the EquationSystems class.
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.
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
A Node is like a Point, but with more information.
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 ...
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
static constexpr Real TOLERANCE
virtual numeric_index_type size() const =0
void resize(const unsigned int n)
Resize the vector.
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i]...
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
NumericVector< Number > * rhs
The system matrix.
void apply_initial(EquationSystems &es, const std::string &system_name)
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
This class implements writing meshes in the GMV format.
This class implements reading and writing meshes in the VTK format.
const T_sys & get_system(std::string_view name) const
This is the MeshBase class.
virtual void zero()=0
Set all entries to zero.
SolverPackage default_solver_package()
This class handles the numbering of degrees of freedom on a mesh.
const dof_id_type n_nodes
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
const T & get(std::string_view) const
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
int main(int argc, char **argv)
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.
void fill_dirichlet_bc(EquationSystems &es, const std::string &system_name)
unsigned int n_points() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
T & set(const std::string &)
SparseMatrix< Number > * matrix
The system matrix.
const MeshBase & get_mesh() const
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
This class contains a specific system class.
This class implements specific orders of Gauss quadrature.
unsigned int mesh_dimension() const
Parameters parameters
Data structure holding arbitrary parameters.
virtual const Node & node_ref(const dof_id_type i) const
virtual void init()
Initialize all the systems.
virtual void add(const numeric_index_type i, const T value)=0
Adds value to the vector entry specified by i.
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.
void assemble_wave(EquationSystems &es, const std::string &system_name)
virtual dof_id_type n_nodes() const =0
const NumericVector< Number > & get_vector(std::string_view vec_name) const
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.