libMesh
Functions
miscellaneous_ex1.C File Reference

Go to the source code of this file.

Functions

void assemble_wave (EquationSystems &es, const std::string &system_name)
 
int main (int argc, char **argv)
 
void assemble_wave (EquationSystems &es, const std::string &libmesh_dbg_var(system_name))
 

Function Documentation

◆ assemble_wave() [1/2]

void assemble_wave ( EquationSystems es,
const std::string &  libmesh_dbg_varsystem_name 
)

Definition at line 224 of file miscellaneous_ex1.C.

226 {
227  // It is a good idea to make sure we are assembling
228  // the proper system.
229  libmesh_assert_equal_to (system_name, "Wave");
230 
231  // Avoid unused variable warnings when compiling without infinite
232  // elements enabled.
233  libmesh_ignore(es);
234 
235 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
236 
237  // Get a constant reference to the mesh object.
238  const MeshBase & mesh = es.get_mesh();
239 
240  // Get a reference to the system we are solving.
242 
243  // A reference to the DofMap object for this system. The DofMap
244  // object handles the index translation from node and element numbers
245  // to degree of freedom numbers.
246  const DofMap & dof_map = system.get_dof_map();
247 
248  // The dimension that we are running.
249  const unsigned int dim = mesh.mesh_dimension();
250 
251  // Copy the speed of sound to a local variable.
252  const Real speed = es.parameters.get<Real>("speed");
253 
254  // Get a constant reference to the Finite Element type
255  // for the first (and only) variable in the system.
256  const FEType & fe_type = dof_map.variable_type(0);
257 
258  // Build a Finite Element object of the specified type. Since the
259  // FEBase::build() member dynamically creates memory we will
260  // store the object as a std::unique_ptr<FEBase>.
261  std::unique_ptr<FEBase> fe (FEBase::build(dim, fe_type));
262 
263  // Do the same for an infinite element.
264  std::unique_ptr<FEBase> inf_fe (FEBase::build_InfFE(dim, fe_type));
265 
266  // A 2nd order Gauss quadrature rule for numerical integration.
267  QGauss qrule (dim, SECOND);
268 
269  // Tell the finite element object to use our quadrature rule.
270  fe->attach_quadrature_rule (&qrule);
271 
272  // Due to its internal structure, the infinite element handles
273  // quadrature rules differently. It takes the quadrature
274  // rule which has been initialized for the FE object, but
275  // creates suitable quadrature rules by @e itself. The user
276  // need not worry about this.
277  inf_fe->attach_quadrature_rule (&qrule);
278 
279  // Define data structures to contain the element matrix
280  // and right-hand-side vector contribution. Following
281  // basic finite element terminology we will denote these
282  // "Ke", "Ce", "Me", and "Fe" for the stiffness, damping
283  // and mass matrices, and the load vector. Note that in
284  // Acoustics, these descriptors though do @e not match the
285  // true physical meaning of the projectors. The final
286  // overall system, however, resembles the conventional
287  // notation again.
292 
293  // This vector will hold the degree of freedom indices for
294  // the element. These define where in the global system
295  // the element degrees of freedom get mapped.
296  std::vector<dof_id_type> dof_indices;
297 
298  // Now we will loop over all the elements in the mesh.
299  // We will compute the element matrix and right-hand-side
300  // contribution.
301  for (const auto & elem : mesh.active_local_element_ptr_range())
302  {
303  // Get the degree of freedom indices for the
304  // current element. These define where in the global
305  // matrix and right-hand-side this element will
306  // contribute to.
307  dof_map.dof_indices (elem, dof_indices);
308 
309  const unsigned int n_dofs =
310  cast_int<unsigned int>(dof_indices.size());
311 
312  // The mesh contains both finite and infinite elements. These
313  // elements are handled through different classes, namely
314  // FE and InfFE, respectively. However, since both
315  // are derived from FEBase, they share the same interface,
316  // and overall burden of coding is @e greatly reduced through
317  // using a pointer, which is adjusted appropriately to the
318  // current element type.
319  FEBase * cfe = nullptr;
320 
321  // This here is almost the only place where we need to
322  // distinguish between finite and infinite elements.
323  // For faster computation, however, different approaches
324  // may be feasible.
325  //
326  // Up to now, we do not know what kind of element we
327  // have. Aske the element of what type it is:
328  if (elem->infinite())
329  {
330  // We have an infinite element. Let cfe point
331  // to our InfFE object. This is handled through
332  // a std::unique_ptr. Through the std::unique_ptr::get() we "borrow"
333  // the pointer, while the std::unique_ptr inf_fe is
334  // still in charge of memory management.
335  cfe = inf_fe.get();
336  }
337  else
338  {
339  // This is a conventional finite element. Let fe handle it.
340  cfe = fe.get();
341 
342  // Boundary conditions.
343  // Here we just zero the rhs-vector. For natural boundary
344  // conditions check e.g. previous examples.
345  {
346  // Zero the RHS for this element.
347  Fe.resize (n_dofs);
348 
349  system.rhs->add_vector (Fe, dof_indices);
350  } // end boundary condition section
351  } // else if (elem->infinite())
352 
353  // This is slightly different from the Poisson solver:
354  // Since the finite element object may change, we have to
355  // initialize the constant references to the data fields
356  // each time again, when a new element is processed.
357  //
358  // The element Jacobian * quadrature weight at each integration point.
359  const std::vector<Real> & JxW = cfe->get_JxW();
360 
361  // The element shape functions evaluated at the quadrature points.
362  const std::vector<std::vector<Real>> & phi = cfe->get_phi();
363 
364  // The element shape function gradients evaluated at the quadrature
365  // points.
366  const std::vector<std::vector<RealGradient>> & dphi = cfe->get_dphi();
367 
368  // The infinite elements need more data fields than conventional FE.
369  // These are the gradients of the phase term dphase, an additional
370  // radial weight for the test functions Sobolev_weight, and its
371  // gradient.
372  //
373  // Note that these data fields are also initialized appropriately by
374  // the FE method, so that the weak form (below) is valid for @e both
375  // finite and infinite elements.
376  const std::vector<RealGradient> & dphase = cfe->get_dphase();
377  const std::vector<Real> & weight = cfe->get_Sobolev_weight();
378  const std::vector<RealGradient> & dweight = cfe->get_Sobolev_dweight();
379 
380  // Now this is all independent of whether we use an FE
381  // or an InfFE. Nice, hm? ;-)
382  //
383  // Compute the element-specific data, as described
384  // in previous examples.
385  cfe->reinit (elem);
386 
387  // Zero the element matrices. Boundary conditions were already
388  // processed in the FE-only section, see above.
389  Ke.resize (n_dofs, n_dofs);
390  Ce.resize (n_dofs, n_dofs);
391  Me.resize (n_dofs, n_dofs);
392 
393  // The total number of quadrature points for infinite elements
394  // @e has to be determined in a different way, compared to
395  // conventional finite elements. This type of access is also
396  // valid for finite elements, so this can safely be used
397  // anytime, instead of asking the quadrature rule, as
398  // seen in previous examples.
399  unsigned int max_qp = cfe->n_quadrature_points();
400 
401  // Loop over the quadrature points.
402  for (unsigned int qp=0; qp<max_qp; qp++)
403  {
404  // Similar to the modified access to the number of quadrature
405  // points, the number of shape functions may also be obtained
406  // in a different manner. This offers the great advantage
407  // of being valid for both finite and infinite elements.
408  const unsigned int n_sf = cfe->n_shape_functions();
409 
410  // Now we will build the element matrices. Since the infinite
411  // elements are based on a Petrov-Galerkin scheme, the
412  // resulting system matrices are non-symmetric. The additional
413  // weight, described before, is part of the trial space.
414  //
415  // For the finite elements, though, these matrices are symmetric
416  // just as we know them, since the additional fields dphase,
417  // weight, and dweight are initialized appropriately.
418  //
419  // test functions: weight[qp]*phi[i][qp]
420  // trial functions: phi[j][qp]
421  // phase term: phase[qp]
422  //
423  // derivatives are similar, but note that these are of type
424  // Point, not of type Real.
425  for (unsigned int i=0; i<n_sf; i++)
426  for (unsigned int j=0; j<n_sf; j++)
427  {
428  // (ndt*Ht + nHt*d) * nH
429  Ke(i,j) +=
430  (
431  (dweight[qp] * phi[i][qp] // Point * Real = Point
432  + // +
433  dphi[i][qp] * weight[qp] // Point * Real = Point
434  ) * dphi[j][qp]
435  ) * JxW[qp];
436 
437  // (d*Ht*nmut*nH - ndt*nmu*Ht*H - d*nHt*nmu*H)
438  Ce(i,j) +=
439  (
440  (dphase[qp] * dphi[j][qp]) // (Point * Point) = Real
441  * weight[qp] * phi[i][qp] // * Real * Real = Real
442  - // -
443  (dweight[qp] * dphase[qp]) // (Point * Point) = Real
444  * phi[i][qp] * phi[j][qp] // * Real * Real = Real
445  - // -
446  (dphi[i][qp] * dphase[qp]) // (Point * Point) = Real
447  * weight[qp] * phi[j][qp] // * Real * Real = Real
448  ) * JxW[qp];
449 
450  // (d*Ht*H * (1 - nmut*nmu))
451  Me(i,j) +=
452  (
453  (1. - (dphase[qp] * dphase[qp])) // (Real - (Point * Point)) = Real
454  * phi[i][qp] * phi[j][qp] * weight[qp] // * Real * Real * Real = Real
455  ) * JxW[qp];
456 
457  } // end of the matrix summation loop
458  } // end of quadrature point loop
459 
460  // The element matrices are now built for this element.
461  // Collect them in Ke, and then add them to the global matrix.
462  // The SparseMatrix::add_matrix() member does this for us.
463  Ke.add(1./speed , Ce);
464  Ke.add(1./(speed*speed), Me);
465 
466  // If this assembly program were to be used on an adaptive mesh,
467  // we would have to apply any hanging node constraint equations
468  dof_map.constrain_element_matrix(Ke, dof_indices);
469 
470  system.matrix->add_matrix (Ke, dof_indices);
471  } // end of element loop
472 
473  // Note that we have not applied any boundary conditions so far.
474  // Here we apply a unit load at the node located at (0,0,0).
475  for (const auto & node : mesh.local_node_ptr_range())
476  if (std::abs((*node)(0)) < TOLERANCE &&
477  std::abs((*node)(1)) < TOLERANCE &&
478  std::abs((*node)(2)) < TOLERANCE)
479  {
480  // The global number of the respective degree of freedom.
481  unsigned int dn = node->dof_number(0,0,0);
482 
483  system.rhs->add (dn, 1.);
484  }
485 
486 #else
487 
488  // dummy assert
489  libmesh_assert_not_equal_to (es.get_mesh().mesh_dimension(), 1);
490 
491 #endif //ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
492 }

References std::abs(), libMesh::MeshBase::active_local_element_ptr_range(), libMesh::DenseMatrix< T >::add(), libMesh::NumericVector< T >::add(), libMesh::SparseMatrix< T >::add_matrix(), libMesh::NumericVector< T >::add_vector(), libMesh::FEGenericBase< OutputType >::build(), libMesh::FEGenericBase< OutputType >::build_InfFE(), dim, libMesh::Parameters::get(), libMesh::System::get_dof_map(), libMesh::EquationSystems::get_mesh(), libMesh::EquationSystems::get_system(), libMesh::libmesh_ignore(), libMesh::MeshBase::local_node_ptr_range(), libMesh::ImplicitSystem::matrix, mesh, libMesh::MeshBase::mesh_dimension(), libMesh::EquationSystems::parameters, libMesh::Real, libMesh::DenseVector< T >::resize(), libMesh::DenseMatrix< T >::resize(), libMesh::ExplicitSystem::rhs, libMesh::SECOND, libMesh::TOLERANCE, and libMesh::MeshTools::weight().

◆ assemble_wave() [2/2]

void assemble_wave ( EquationSystems es,
const std::string &  system_name 
)

Definition at line 323 of file transient_ex2.C.

325 {
326  // It is a good idea to make sure we are assembling
327  // the proper system.
328  libmesh_assert_equal_to (system_name, "Wave");
329 
330  // Get a constant reference to the mesh object.
331  const MeshBase & mesh = es.get_mesh();
332 
333  // The dimension that we are running.
334  const unsigned int dim = mesh.mesh_dimension();
335 
336  // Copy the speed of sound and fluid density
337  // to a local variable.
338  const Real speed = es.parameters.get<Real>("speed");
339  const Real rho = es.parameters.get<Real>("fluid density");
340 
341  // Get a reference to our system, as before.
342  NewmarkSystem & t_system = es.get_system<NewmarkSystem> (system_name);
343 
344  // Get a constant reference to the Finite Element type
345  // for the first (and only) variable in the system.
346  FEType fe_type = t_system.get_dof_map().variable_type(0);
347 
348  // In here, we will add the element matrices to the
349  // @e additional matrices "stiffness_mass" and "damping"
350  // and the additional vector "force", not to the members
351  // "matrix" and "rhs". Therefore, get writable
352  // references to them.
353  SparseMatrix<Number> & stiffness = t_system.get_matrix("stiffness");
354  SparseMatrix<Number> & damping = t_system.get_matrix("damping");
355  SparseMatrix<Number> & mass = t_system.get_matrix("mass");
356  NumericVector<Number> & force = t_system.get_vector("force");
357 
358  // Some solver packages (PETSc) are especially picky about
359  // allocating sparsity structure and truly assigning values
360  // to this structure. Namely, matrix additions, as performed
361  // later, exhibit acceptable performance only for identical
362  // sparsity structures. Therefore, explicitly zero the
363  // values in the collective matrix, so that matrix additions
364  // encounter identical sparsity structures.
365  SparseMatrix<Number> & matrix = *t_system.matrix;
366  DenseMatrix<Number> zero_matrix;
367 
368  // Build a Finite Element object of the specified type. Since the
369  // FEBase::build() member dynamically creates memory we will
370  // store the object as a std::unique_ptr<FEBase>. This can be thought
371  // of as a pointer that will clean up after itself.
372  std::unique_ptr<FEBase> fe (FEBase::build(dim, fe_type));
373 
374  // A 2nd order Gauss quadrature rule for numerical integration.
375  QGauss qrule (dim, SECOND);
376 
377  // Tell the finite element object to use our quadrature rule.
378  fe->attach_quadrature_rule (&qrule);
379 
380  // The element Jacobian * quadrature weight at each integration point.
381  const std::vector<Real> & JxW = fe->get_JxW();
382 
383  // The element shape functions evaluated at the quadrature points.
384  const std::vector<std::vector<Real>> & phi = fe->get_phi();
385 
386  // The element shape function gradients evaluated at the quadrature
387  // points.
388  const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
389 
390  // A reference to the DofMap object for this system. The DofMap
391  // object handles the index translation from node and element numbers
392  // to degree of freedom numbers.
393  const DofMap & dof_map = t_system.get_dof_map();
394 
395  // The element mass, damping and stiffness matrices
396  // and the element contribution to the rhs.
397  DenseMatrix<Number> Ke, Ce, Me;
399 
400  // This vector will hold the degree of freedom indices for
401  // the element. These define where in the global system
402  // the element degrees of freedom get mapped.
403  std::vector<dof_id_type> dof_indices;
404 
405  // Now we will loop over all the elements in the mesh.
406  // We will compute the element matrix and right-hand-side
407  // contribution.
408  for (const auto & elem : mesh.active_local_element_ptr_range())
409  {
410  // Get the degree of freedom indices for the
411  // current element. These define where in the global
412  // matrix and right-hand-side this element will
413  // contribute to.
414  dof_map.dof_indices (elem, dof_indices);
415 
416  // Compute the element-specific data for the current
417  // element. This involves computing the location of the
418  // quadrature points (q_point) and the shape functions
419  // (phi, dphi) for the current element.
420  fe->reinit (elem);
421 
422  // Zero the element matrices and rhs before
423  // summing them. We use the resize member here because
424  // the number of degrees of freedom might have changed from
425  // the last element. Note that this will be the case if the
426  // element type is different (i.e. the last element was HEX8
427  // and now have a PRISM6).
428  {
429  const unsigned int n_dof_indices = dof_indices.size();
430 
431  Ke.resize (n_dof_indices, n_dof_indices);
432  Ce.resize (n_dof_indices, n_dof_indices);
433  Me.resize (n_dof_indices, n_dof_indices);
434  zero_matrix.resize (n_dof_indices, n_dof_indices);
435  Fe.resize (n_dof_indices);
436  }
437 
438  // Now loop over the quadrature points. This handles
439  // the numeric integration.
440  for (unsigned int qp=0; qp<qrule.n_points(); qp++)
441  {
442  // Now we will build the element matrix. This involves
443  // a double loop to integrate the test functions (i) against
444  // the trial functions (j).
445  for (std::size_t i=0; i<phi.size(); i++)
446  for (std::size_t j=0; j<phi.size(); j++)
447  {
448  Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
449  Me(i,j) += JxW[qp]*phi[i][qp]*phi[j][qp]
450  *1./(speed*speed);
451  } // end of the matrix summation loop
452  } // end of quadrature point loop
453 
454  // Now compute the contribution to the element matrix and the
455  // right-hand-side vector if the current element lies on the
456  // boundary.
457  {
458  // In this example no natural boundary conditions will
459  // be considered. The code is left here so it can easily
460  // be extended.
461  //
462  // don't do this for any side
463  for (auto side : elem->side_index_range())
464  if (!true)
465  // if (elem->neighbor_ptr(side) == nullptr)
466  {
467  // Declare a special finite element object for
468  // boundary integration.
469  std::unique_ptr<FEBase> fe_face (FEBase::build(dim, fe_type));
470 
471  // Boundary integration requires one quadrature rule,
472  // with dimensionality one less than the dimensionality
473  // of the element.
474  QGauss qface(dim-1, SECOND);
475 
476  // Tell the finite element object to use our
477  // quadrature rule.
478  fe_face->attach_quadrature_rule (&qface);
479 
480  // The value of the shape functions at the quadrature
481  // points.
482  const std::vector<std::vector<Real>> & phi_face = fe_face->get_phi();
483 
484  // The Jacobian * Quadrature Weight at the quadrature
485  // points on the face.
486  const std::vector<Real> & JxW_face = fe_face->get_JxW();
487 
488  // Compute the shape function values on the element
489  // face.
490  fe_face->reinit(elem, side);
491 
492  // Here we consider a normal acceleration acc_n=1 applied to
493  // the whole boundary of our mesh.
494  const Real acc_n_value = 1.0;
495 
496  // Loop over the face quadrature points for integration.
497  for (unsigned int qp=0; qp<qface.n_points(); qp++)
498  {
499  // Right-hand-side contribution due to prescribed
500  // normal acceleration.
501  for (std::size_t i=0; i<phi_face.size(); i++)
502  {
503  Fe(i) += acc_n_value*rho
504  *phi_face[i][qp]*JxW_face[qp];
505  }
506  } // end face quadrature point loop
507  } // end if (elem->neighbor_ptr(side) == nullptr)
508 
509  // In this example the Dirichlet boundary conditions will be
510  // imposed via penalty method after the
511  // system is assembled.
512 
513  } // end boundary condition section
514 
515  // If this assembly program were to be used on an adaptive mesh,
516  // we would have to apply any hanging node constraint equations
517  // by uncommenting the following lines:
518  // std::vector<unsigned int> dof_indicesC = dof_indices;
519  // std::vector<unsigned int> dof_indicesM = dof_indices;
520  // dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
521  // dof_map.constrain_element_matrix (Ce, dof_indicesC);
522  // dof_map.constrain_element_matrix (Me, dof_indicesM);
523 
524  // Finally, simply add the contributions to the additional
525  // matrices and vector.
526  stiffness.add_matrix (Ke, dof_indices);
527  damping.add_matrix (Ce, dof_indices);
528  mass.add_matrix (Me, dof_indices);
529 
530  force.add_vector (Fe, dof_indices);
531 
532  // For the overall matrix, explicitly zero the entries where
533  // we added values in the other ones, so that we have
534  // identical sparsity footprints.
535  matrix.add_matrix(zero_matrix, dof_indices);
536 
537  } // end of element loop
538 }

References libMesh::MeshBase::active_local_element_ptr_range(), libMesh::SparseMatrix< T >::add_matrix(), libMesh::NumericVector< T >::add_vector(), libMesh::FEGenericBase< OutputType >::build(), dim, libMesh::DofMap::dof_indices(), libMesh::Parameters::get(), libMesh::EquationSystems::get_mesh(), libMesh::EquationSystems::get_system(), 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 84 of file miscellaneous_ex1.C.

85 {
86  // Initialize libMesh, like in example 2.
87  LibMeshInit init (argc, argv);
88 
89  // This example requires Infinite Elements
90 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
91  libmesh_example_requires(false, "--enable-ifem");
92 #else
93 
94  // Skip this 3D example if libMesh was compiled as 1D/2D-only.
95  libmesh_example_requires(3 <= LIBMESH_DIM, "3D support");
96 
97  // Tell the user what we are doing.
98  libMesh::out << "Running ex6 with dim = 3" << std::endl << std::endl;
99 
100  // Create a serialized mesh, distributed across the default MPI
101  // communicator.
102  Mesh mesh(init.comm());
103 
104  // Use the internal mesh generator to create elements
105  // on the square [-1,1]^3, of type Hex8.
107  4, 4, 4,
108  -1., 1.,
109  -1., 1.,
110  -1., 1.,
111  HEX8);
112 
113  // Print information about the mesh to the screen.
114  mesh.print_info();
115 
116  // Write the mesh before the infinite elements are added
117 #ifdef LIBMESH_HAVE_EXODUS_API
118  ExodusII_IO(mesh).write ("orig_mesh.e");
119 #endif
120 
121  // Normally, when a mesh is imported or created in
122  // libMesh, only conventional elements exist. The infinite
123  // elements used here, however, require prescribed
124  // nodal locations (with specified distances from an imaginary
125  // origin) and configurations that a conventional mesh creator
126  // in general does not offer. Therefore, an efficient method
127  // for building infinite elements is offered. It can account
128  // for symmetry planes and creates infinite elements in a fully
129  // automatic way.
130  //
131  // Right now, the simplified interface is used, automatically
132  // determining the origin. Check MeshBase for a generalized
133  // method that can even return the element faces of interior
134  // vibrating surfaces. The bool determines whether to be
135  // verbose.
136  InfElemBuilder builder(mesh);
137  builder.build_inf_elem(true);
138 
139  // Reassign subdomain_id() of all infinite elements.
140  // Otherwise, the exodus-api will fail on the mesh.
141  for (auto & elem : mesh.element_ptr_range())
142  if (elem->infinite())
143  elem->subdomain_id() = 1;
144 
145  // Print information about the mesh to the screen.
146  mesh.print_info();
147 
148  // Write the mesh with the infinite elements added.
149  // Compare this to the original mesh.
150 #ifdef LIBMESH_HAVE_EXODUS_API
151  ExodusII_IO(mesh).write ("ifems_added.e");
152 #endif
153 
154  // After building infinite elements, we have to let
155  // the elements find their neighbors again.
157 
158  // Create an equation systems object, where ThinSystem
159  // offers only the crucial functionality for solving a
160  // system. Use ThinSystem when you want the sleekest
161  // system possible.
162  EquationSystems equation_systems (mesh);
163 
164  // Declare the system and its variables.
165  // Create a system named "Wave". This can
166  // be a simple, steady system
167  equation_systems.add_system<LinearImplicitSystem> ("Wave");
168 
169  // Create an FEType describing the approximation
170  // characteristics of the InfFE object. Note that
171  // the constructor automatically defaults to some
172  // sensible values. But use FIRST order
173  // approximation.
174  FEType fe_type(FIRST);
175 
176  // Add the variable "p" to "Wave". Note that there exist
177  // various approaches in adding variables. In example 3,
178  // add_variable took the order of approximation and used
179  // default values for the FEFamily, while here the FEType
180  // is used.
181  equation_systems.get_system("Wave").add_variable("p", fe_type);
182 
183  // Give the system a pointer to the matrix assembly
184  // function.
185  equation_systems.get_system("Wave").attach_assemble_function (assemble_wave);
186 
187  // Set the speed of sound and fluid density
188  // as EquationSystems parameter,
189  // so that assemble_wave() can access it.
190  equation_systems.parameters.set<Real>("speed") = 1.;
191  equation_systems.parameters.set<Real>("fluid density") = 1.;
192 
193  // Initialize the data structures for the equation system.
194  equation_systems.init();
195 
196  // Prints information about the system to the screen.
197  equation_systems.print_info();
198 
199  // Solve the system "Wave".
200  equation_systems.get_system("Wave").solve();
201 
202  libMesh::out << "Wave system solved" << std::endl;
203 
204  // Write the whole EquationSystems object to file.
205  // For infinite elements, the concept of nodal_soln()
206  // is not applicable. Therefore, writing the mesh in
207  // some format @e always gives all-zero results at
208  // the nodes of the infinite elements. Instead,
209  // use the FEInterface::compute_data() methods to
210  // determine physically correct results within an
211  // infinite element.
212  equation_systems.write ("eqn_sys.dat", WRITE);
213 
214  libMesh::out << "eqn_sys.dat written" << std::endl;
215 
216  // All done.
217  return 0;
218 
219 #endif // else part of ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS
220 }

References libMesh::EquationSystems::add_system(), assemble_wave(), libMesh::MeshTools::Generation::build_cube(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::MeshBase::element_ptr_range(), libMesh::MeshBase::find_neighbors(), libMesh::FIRST, libMesh::EquationSystems::get_system(), libMesh::HEX8, libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), mesh, libMesh::out, libMesh::EquationSystems::parameters, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::Real, libMesh::Parameters::set(), libMesh::WRITE, libMesh::ExodusII_IO::write(), and libMesh::EquationSystems::write().

libMesh::NumericVector::add
virtual void add(const numeric_index_type i, const T value)=0
Adds value to each entry of the vector.
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::EquationSystems::get_mesh
const MeshBase & get_mesh() const
Definition: equation_systems.h:637
libMesh::ExplicitSystem::rhs
NumericVector< Number > * rhs
The system matrix.
Definition: explicit_system.h:114
libMesh::QGauss
This class implements specific orders of Gauss quadrature.
Definition: quadrature_gauss.h:39
libMesh::DofMap::dof_indices
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1967
libMesh::HEX8
Definition: enum_elem_type.h:47
libMesh::MeshBase::active_local_element_ptr_range
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
libMesh::NewmarkSystem
This class contains a specific system class.
Definition: newmark_system.h:51
libMesh::DenseMatrix::add
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrix< T3 > &mat)
Adds factor times mat to this matrix.
Definition: dense_matrix.h:945
libMesh::FEGenericBase
This class forms the foundation from which generic finite elements may be derived.
Definition: exact_error_estimator.h:39
libMesh::EquationSystems::get_system
const T_sys & get_system(const std::string &name) const
Definition: equation_systems.h:757
libMesh::MeshTools::Generation::build_cube
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.
Definition: mesh_generation.C:298
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::DenseMatrix< Number >
assemble_wave
void assemble_wave(EquationSystems &es, const std::string &system_name)
Definition: transient_ex2.C:323
libMesh::WRITE
Definition: enum_xdr_mode.h:40
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase::mesh_dimension
unsigned int mesh_dimension() const
Definition: mesh_base.C:135
libMesh::ExodusII_IO
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
Definition: exodusII_io.h:51
libMesh::SECOND
Definition: enum_order.h:43
libMesh::SparseMatrix< Number >
dim
unsigned int dim
Definition: adaptivity_ex3.C:113
libMesh::DenseMatrix::resize
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
Definition: dense_matrix.h:822
libMesh::NumericVector< Number >
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::MeshBase::element_ptr_range
virtual SimpleRange< element_iterator > element_ptr_range()=0
libMesh::NumericVector::add_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].
Definition: numeric_vector.C:363
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::libmesh_ignore
void libmesh_ignore(const Args &...)
Definition: libmesh_common.h:526
libMesh::MeshBase::local_node_ptr_range
virtual SimpleRange< node_iterator > local_node_ptr_range()=0
libMesh::InfElemBuilder
This class is used to build infinite elements on top of an existing mesh.
Definition: inf_elem_builder.h:53
libMesh::ImplicitSystem::matrix
SparseMatrix< Number > * matrix
The system matrix.
Definition: implicit_system.h:393
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::DenseVector::resize
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:355
libMesh::SparseMatrix::add_matrix
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.
libMesh::FEType
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:178
libMesh::DofMap
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:176
libMesh::MeshBase::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
Definition: mesh_base.C:585
libMesh::ExodusII_IO::write
virtual void write(const std::string &fname) override
This method implements writing a mesh to a specified file.
Definition: exodusII_io.C:1338
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::LinearImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
Definition: linear_implicit_system.h:55
libMesh::MeshTools::weight
dof_id_type weight(const MeshBase &mesh, const processor_id_type pid)
Definition: mesh_tools.C:236
libMesh::Parameters::get
const T & get(const std::string &) const
Definition: parameters.h:421
libMesh::out
OStreamProxy out
libMesh::MeshBase::find_neighbors
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true)=0
Locate element face (edge in 2D) neighbors.
libMesh::FIRST
Definition: enum_order.h:42
libMesh::DenseVector< Number >
libMesh::EquationSystems::parameters
Parameters parameters
Data structure holding arbitrary parameters.
Definition: equation_systems.h:557