Go to the source code of this file.
◆ add_M_C_K_helmholtz()
void add_M_C_K_helmholtz |
( |
EquationSystems & |
es, |
|
|
const std::string & |
system_name |
|
) |
| |
Definition at line 502 of file miscellaneous_ex2.C.
505 START_LOG(
"init phase",
"add_M_C_K_helmholtz");
508 libmesh_assert_equal_to (system_name,
"Helmholtz");
521 const Number k = omega / speed;
540 const Number scale_stiffness (1., 0.);
541 const Number scale_damping=unit_i*omega;
542 const Number scale_mass=-k*k;
543 const Number scale_rhs=-unit_i*rho*omega;
559 STOP_LOG(
"init phase",
"add_M_C_K_helmholtz");
561 START_LOG(
"global matrix & vector additions",
"add_M_C_K_helmholtz");
572 matrix.
add (scale_stiffness, stiffness);
573 matrix.
add (scale_mass, mass);
574 matrix.
add (scale_damping, damping);
575 rhs.
add (scale_rhs, freq_indep_rhs);
577 STOP_LOG(
"global matrix & vector additions",
"add_M_C_K_helmholtz");
References libMesh::SparseMatrix< T >::add(), libMesh::NumericVector< T >::add(), libMesh::SparseMatrix< T >::close(), libMesh::NumericVector< T >::close(), libMesh::Parameters::get(), libMesh::ImplicitSystem::get_matrix(), libMesh::EquationSystems::get_system(), libMesh::System::get_vector(), libMesh::ImplicitSystem::matrix, libMesh::EquationSystems::parameters, libMesh::pi, libMesh::Real, libMesh::ExplicitSystem::rhs, libMesh::SparseMatrix< T >::zero(), and libMesh::NumericVector< T >::zero().
Referenced by main().
◆ assemble_helmholtz()
void assemble_helmholtz |
( |
EquationSystems & |
es, |
|
|
const std::string & |
system_name |
|
) |
| |
Definition at line 293 of file miscellaneous_ex2.C.
299 libmesh_assert_equal_to (system_name,
"Helmholtz");
318 const FEType & fe_type = dof_map.variable_type(0);
335 std::unique_ptr<FEBase> fe (FEBase::build(
dim, fe_type));
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 START_LOG(
"elem init",
"assemble_helmholtz");
381 dof_map.dof_indices (elem, dof_indices);
393 const unsigned int n_dof_indices = dof_indices.size();
395 Ke.
resize (n_dof_indices, n_dof_indices);
396 Ce.
resize (n_dof_indices, n_dof_indices);
397 Me.
resize (n_dof_indices, n_dof_indices);
398 zero_matrix.
resize (n_dof_indices, n_dof_indices);
399 Fe.
resize (n_dof_indices);
403 STOP_LOG(
"elem init",
"assemble_helmholtz");
407 START_LOG(
"stiffness & mass",
"assemble_helmholtz");
409 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
414 for (std::size_t i=0; i<phi.size(); i++)
415 for (std::size_t j=0; j<phi.size(); j++)
417 Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
418 Me(i,j) += JxW[qp]*(phi[i][qp]*phi[j][qp]);
422 STOP_LOG(
"stiffness & mass",
"assemble_helmholtz");
431 for (
auto side : elem->side_index_range())
432 if (elem->neighbor_ptr(side) ==
nullptr)
434 LOG_SCOPE(
"damping",
"assemble_helmholtz");
438 std::unique_ptr<FEBase> fe_face (FEBase::build(
dim, fe_type));
447 fe_face->attach_quadrature_rule (&qface);
451 const std::vector<std::vector<Real>> & phi_face =
456 const std::vector<Real> & JxW_face = fe_face->get_JxW();
460 fe_face->reinit(elem, side);
464 const Real an_value = 1.;
467 for (
unsigned int qp=0; qp<qface.n_points(); qp++)
471 for (std::size_t i=0; i<phi_face.size(); i++)
472 for (std::size_t j=0; j<phi_face.size(); j++)
473 Ce(i,j) += rho * an_value * JxW_face[qp] * phi_face[i][qp] * phi_face[j][qp];
488 stiffness.add_matrix (Ke, dof_indices);
References libMesh::MeshBase::active_local_element_ptr_range(), libMesh::SparseMatrix< T >::add_matrix(), libMesh::FEGenericBase< OutputType >::build(), dim, libMesh::FIFTH, libMesh::Parameters::get(), libMesh::System::get_dof_map(), libMesh::ImplicitSystem::get_matrix(), libMesh::EquationSystems::get_mesh(), libMesh::EquationSystems::get_system(), libMesh::ImplicitSystem::matrix, mesh, libMesh::MeshBase::mesh_dimension(), libMesh::QBase::n_points(), libMesh::EquationSystems::parameters, libMesh::Real, libMesh::DenseVector< T >::resize(), libMesh::DenseMatrix< T >::resize(), and libMesh::SECOND.
Referenced by main().
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 103 of file miscellaneous_ex2.C.
110 #ifndef LIBMESH_USE_COMPLEX_NUMBERS
111 libmesh_example_requires(
false,
"--enable-complex");
115 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
119 libmesh_error_msg(
"Usage: " << argv[0] <<
" -f [real_frequency imag_frequency]");
121 if (
init.comm().size() > 1)
123 if (
init.comm().rank() == 0)
125 libMesh::err <<
"TODO: This example should be able to run in parallel."
136 for (
int i=1; i<argc; i++)
145 const Number frequency_in (atof(argv[2]), atof(argv[3]));
150 const unsigned int n_frequencies = 3;
159 unvio.read(
"lshape.unv");
172 unvio.read_dataset(
"lshape_data.unv");
218 equation_systems.parameters.set<
Real> (
"wave speed") = 1.;
219 equation_systems.parameters.set<
Real> (
"rho") = 1.;
222 equation_systems.init ();
234 const std::vector<Number> * nodal_data = unvio.get_data(node);
239 unsigned int dn = node->dof_number(0,
242 freq_indep_rhs.
set(dn, (*nodal_data)[0]);
248 equation_systems.print_info ();
250 for (
unsigned int n=0; n < n_frequencies; n++)
258 f_system.
solve (n, n);
262 #ifdef LIBMESH_HAVE_EXODUS_API
263 std::ostringstream file_name;
280 equation_systems.write (
"eqn_sys.dat",
WRITE);
References add_M_C_K_helmholtz(), libMesh::ImplicitSystem::add_matrix(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::System::add_vector(), assemble_helmholtz(), libMesh::System::attach_assemble_function(), libMesh::FrequencySystem::attach_solve_function(), libMesh::err, libMesh::System::get_vector(), libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), mesh, libMesh::MeshBase::node_ptr_range(), libMesh::out, libMesh::EquationSystems::parameters, libMesh::MeshBase::prepare_for_use(), libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::Real, libMesh::SECOND, libMesh::Parameters::set(), libMesh::NumericVector< T >::set(), libMesh::FrequencySystem::set_frequencies_by_steps(), libMesh::FrequencySystem::solve(), libMesh::WRITE, libMesh::EquationSystems::write(), and libMesh::MeshOutput< MT >::write_equation_systems().
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
virtual void zero()=0
Set all entries to zero.
virtual void add(const numeric_index_type i, const T value)=0
Adds value to each entry of the vector.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
const MeshBase & get_mesh() const
NumericVector< Number > * rhs
The system matrix.
This class implements specific orders of Gauss quadrature.
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 SimpleRange< element_iterator > active_local_element_ptr_range()=0
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
SparseMatrix< Number > & add_matrix(const std::string &mat_name)
Adds the additional matrix mat_name to this system.
const T_sys & get_system(const std::string &name) const
unsigned int mesh_dimension() const
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
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.
This is the MeshBase class.
The UNVIO class implements the Ideas UNV universal file format.
virtual SimpleRange< node_iterator > node_ptr_range()=0
unsigned int add_variable(const std::string &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.
SparseMatrix< Number > * matrix
The system matrix.
FrequencySystem provides a specific system class for frequency-dependent (linear) systems.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
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 is the EquationSystems class.
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 resize(const unsigned int n)
Resize the vector.
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.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
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.
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
This class handles the numbering of degrees of freedom on a mesh.
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
void assemble_helmholtz(EquationSystems &es, const std::string &system_name)
virtual void solve() override
Solves the system for all frequencies.
void add_M_C_K_helmholtz(EquationSystems &es, const std::string &system_name)
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
const DofMap & get_dof_map() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly ecreated (or read) mesh for use.
const T & get(const std::string &) const
const SparseMatrix< Number > & get_matrix(const std::string &mat_name) const
const NumericVector< Number > & get_vector(const std::string &vec_name) const
virtual void zero()=0
Set all entries to 0.
Parameters parameters
Data structure holding arbitrary parameters.