45 #include "libmesh/libmesh.h" 46 #include "libmesh/libmesh_logging.h" 47 #include "libmesh/mesh.h" 48 #include "libmesh/mesh_generation.h" 49 #include "libmesh/exodusII_io.h" 50 #include "libmesh/unv_io.h" 51 #include "libmesh/equation_systems.h" 52 #include "libmesh/elem.h" 53 #include "libmesh/enum_xdr_mode.h" 57 #include "libmesh/frequency_system.h" 60 #include "libmesh/fe.h" 63 #include "libmesh/quadrature_gauss.h" 66 #include "libmesh/dense_matrix.h" 67 #include "libmesh/dense_vector.h" 70 #include "libmesh/sparse_matrix.h" 71 #include "libmesh/numeric_vector.h" 74 #include "libmesh/dof_map.h" 81 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 87 const std::string & system_name);
93 const std::string & system_name);
103 int main (
int argc,
char ** argv)
110 #ifndef LIBMESH_USE_COMPLEX_NUMBERS 111 libmesh_example_requires(
false,
"--enable-complex");
115 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
118 libmesh_error_msg_if(argc < 4,
"Usage: " << argv[0] <<
" -f [real_frequency imag_frequency]");
120 if (
init.comm().size() > 1)
122 if (
init.comm().rank() == 0)
124 libMesh::err <<
"TODO: This example should be able to run in parallel." 135 for (
int i=1; i<argc; i++)
144 const Number frequency_in (atof(argv[2]), atof(argv[3]));
149 const unsigned int n_frequencies = 3;
158 unvio.read(
"lshape.unv");
171 unvio.read_dataset(
"lshape_data.unv");
221 equation_systems.
init ();
230 for (
const auto & node :
mesh.node_ptr_range())
233 const std::vector<Number> * nodal_data = unvio.get_data(node);
238 unsigned int dn = node->dof_number(0,
241 freq_indep_rhs.
set(dn, (*nodal_data)[0]);
249 for (
unsigned int n=0; n < n_frequencies; n++)
257 f_system.
solve (n, n);
261 #ifdef LIBMESH_HAVE_EXODUS_API 262 std::ostringstream file_name;
279 equation_systems.
write (
"eqn_sys.dat",
WRITE);
288 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 293 const std::string & system_name)
295 LOG_SCOPE(
"assemble_helmholtz",
"misc_ex2");
299 libmesh_assert_equal_to (system_name,
"Helmholtz");
318 const FEType & fe_type = dof_map.variable_type(0);
341 fe->attach_quadrature_rule (&qrule);
344 const std::vector<Real> & JxW = fe->get_JxW();
347 const std::vector<std::vector<Real>> & phi = fe->get_phi();
351 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
368 std::vector<dof_id_type> dof_indices;
375 for (
const auto & elem :
mesh.active_local_element_ptr_range())
381 dof_map.dof_indices (elem, dof_indices);
392 const unsigned int n_dof_indices = dof_indices.size();
394 Ke.
resize (n_dof_indices, n_dof_indices);
395 Ce.
resize (n_dof_indices, n_dof_indices);
396 Me.
resize (n_dof_indices, n_dof_indices);
397 zero_matrix.
resize (n_dof_indices, n_dof_indices);
398 Fe.
resize (n_dof_indices);
402 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
407 for (std::size_t i=0; i<phi.size(); i++)
408 for (std::size_t j=0; j<phi.size(); j++)
410 Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
411 Me(i,j) += JxW[qp]*(phi[i][qp]*phi[j][qp]);
422 for (
auto side : elem->side_index_range())
423 if (elem->neighbor_ptr(side) ==
nullptr)
436 fe_face->attach_quadrature_rule (&qface);
440 const std::vector<std::vector<Real>> & phi_face =
445 const std::vector<Real> & JxW_face = fe_face->get_JxW();
449 fe_face->reinit(elem, side);
453 const Real an_value = 1.;
456 for (
unsigned int qp=0; qp<qface.
n_points(); qp++)
460 for (std::size_t i=0; i<phi_face.size(); i++)
461 for (std::size_t j=0; j<phi_face.size(); j++)
462 Ce(i,j) += rho * an_value * JxW_face[qp] * phi_face[i][qp] * phi_face[j][qp];
477 stiffness.add_matrix (Ke, dof_indices);
492 const std::string & system_name)
494 LOG_SCOPE(
"add_M_C_K_helmholtz()",
"misc_ex2");
497 libmesh_assert_equal_to (system_name,
"Helmholtz");
510 const Number k = omega / speed;
529 const Number scale_stiffness (1., 0.);
530 const Number scale_damping=unit_i*omega;
531 const Number scale_mass=-k*k;
532 const Number scale_rhs=-unit_i*rho*omega;
557 matrix.
add (scale_stiffness, stiffness);
558 matrix.
add (scale_mass, mass);
559 matrix.
add (scale_damping, damping);
560 rhs.
add (scale_rhs, freq_indep_rhs);
565 #endif // LIBMESH_USE_COMPLEX_NUMBERS class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
void attach_solve_function(void fptr(EquationSystems &es, const std::string &name))
Register a required user function to use in assembling/solving the system.
virtual void solve() override
Solves the system for all frequencies.
This is the EquationSystems class.
void write(std::string_view name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
Write the systems to disk using the XDR data format.
int main(int argc, char **argv)
FrequencySystem provides a specific system class for frequency-dependent (linear) systems...
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
void resize(const unsigned int n)
Resize the vector.
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use.
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.
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
const T_sys & get_system(std::string_view name) const
This is the MeshBase class.
virtual void zero()=0
Set all entries to zero.
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
This class handles the numbering of degrees of freedom on a mesh.
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
virtual void zero()=0
Set all entries to 0.
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.
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.
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.
unsigned int n_points() const
void set_frequencies_by_steps(const Number base_freq, const Number freq_step=0., const unsigned int n_freq=1, const bool allocate_solution_duplicates=true)
Set the frequency range for which the system should be solved.
void attach_assemble_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in assembling the system matrix and RHS.
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
void add_M_C_K_helmholtz(EquationSystems &es, const std::string &system_name)
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
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 implements specific orders of Gauss quadrature.
unsigned int mesh_dimension() const
Parameters parameters
Data structure holding arbitrary parameters.
void assemble_helmholtz(EquationSystems &es, const std::string &system_name)
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
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.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
SparseMatrix< Number > & add_matrix(std::string_view mat_name, ParallelType type=PARALLEL, MatrixBuildType mat_build_type=MatrixBuildType::AUTOMATIC)
Adds the additional matrix mat_name to this system.
const DofMap & get_dof_map() const
const SparseMatrix< Number > & get_matrix(std::string_view mat_name) const
const SparseMatrix< Number > & get_system_matrix() const
The UNVIO class implements the Ideas UNV universal file format.
const NumericVector< Number > & get_vector(std::string_view vec_name) const