libMesh
miscellaneous_ex11.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // <h1>Miscellaneous Example 11 - Using Loop Subdivision Shell Elements</h1>
21 // \author Roman Vetter
22 // \author Norbert Stoop
23 // \date 2014
24 //
25 // This example demonstrates how subdivision surface shell elements
26 // are used, and how boundary conditions can be applied to them. To
27 // keep it simple, we solve the static deflection of a clamped, square,
28 // linearly elastic Kirchhoff-Love plate subject to a uniform
29 // load distribution. Refer to Cirak et al., Int. J. Numer. Meth.
30 // Engng. 2000; 47: 2039-2072, for a detailed description of what's
31 // implemented. In fact, this example follows that paper very closely.
32 
33 
34 // C++ include files that we need
35 #include <iostream>
36 
37 // LibMesh includes
38 #include "libmesh/libmesh.h"
39 #include "libmesh/replicated_mesh.h"
40 #include "libmesh/mesh_refinement.h"
41 #include "libmesh/mesh_modification.h"
42 #include "libmesh/mesh_tools.h"
43 #include "libmesh/linear_implicit_system.h"
44 #include "libmesh/equation_systems.h"
45 #include "libmesh/fe.h"
46 #include "libmesh/quadrature.h"
47 #include "libmesh/node.h"
48 #include "libmesh/elem.h"
49 #include "libmesh/dof_map.h"
50 #include "libmesh/vector_value.h"
51 #include "libmesh/tensor_value.h"
52 #include "libmesh/dense_matrix.h"
53 #include "libmesh/dense_submatrix.h"
54 #include "libmesh/dense_vector.h"
55 #include "libmesh/dense_subvector.h"
56 #include "libmesh/sparse_matrix.h"
57 #include "libmesh/numeric_vector.h"
58 #include "libmesh/vtk_io.h"
59 #include "libmesh/exodusII_io.h"
60 #include "libmesh/enum_solver_package.h"
61 #include "libmesh/parallel.h"
62 
63 // These are the include files typically needed for subdivision elements.
64 #include "libmesh/face_tri3_subdivision.h"
65 #include "libmesh/mesh_subdivision_support.h"
66 
67 // Bring in everything from the libMesh namespace
68 using namespace libMesh;
69 
70 #if defined(LIBMESH_ENABLE_SECOND_DERIVATIVES) && LIBMESH_DIM > 2
71 // Function prototype. This is the function that will assemble
72 // the stiffness matrix and the right-hand-side vector ready
73 // for solution.
75  const std::string & system_name);
76 #endif
77 
78 // Begin the main program.
79 int main (int argc, char ** argv)
80 {
81  // Initialize libMesh.
82  LibMeshInit init (argc, argv);
83 
84  // This example requires a linear solver package.
85  libmesh_example_requires(libMesh::default_solver_package() != INVALID_SOLVER_PACKAGE,
86  "--enable-petsc, --enable-trilinos, or --enable-eigen");
87 
88  // Skip this 3D example if libMesh was compiled as 1D/2D-only.
89  libmesh_example_requires (3 == LIBMESH_DIM, "3D support");
90 
91  // Skip this example without --enable-node-valence
92 #ifndef LIBMESH_ENABLE_NODE_VALENCE
93  libmesh_example_requires (false, "--enable-node-valence");
94 #endif
95 
96  // Skip this example without --enable-amr; requires MeshRefinement
97 #ifndef LIBMESH_ENABLE_AMR
98  libmesh_example_requires(false, "--enable-amr");
99 #else
100 
101  // Skip this example without --enable-second; requires d2phi
102 #ifndef LIBMESH_ENABLE_SECOND_DERIVATIVES
103  libmesh_example_requires(false, "--enable-second");
104 #elif LIBMESH_DIM > 2
105 
106  // Create a 2D mesh distributed across the default MPI communicator.
107  // Subdivision surfaces do not appear to work with DistributedMesh yet.
108  ReplicatedMesh mesh (init.comm(), 2);
109 
110  // Read the coarse square mesh.
111  mesh.read ("square_mesh.off");
112 
113  // Resize the square plate to edge length L.
114  const Real L = 100.;
116 
117  // Quadrisect the mesh triangles a few times to obtain a
118  // finer mesh. Subdivision surface elements require the
119  // refinement data to be removed afterward.
120  MeshRefinement mesh_refinement (mesh);
121  mesh_refinement.uniformly_refine (3);
123 
124  // Write the mesh before the ghost elements are added.
125 #if defined(LIBMESH_HAVE_VTK)
126  VTKIO(mesh).write ("without_ghosts.pvtu");
127 #endif
128 #if defined(LIBMESH_HAVE_EXODUS_API)
129  ExodusII_IO(mesh).write ("without_ghosts.e");
130 #endif
131 
132  // Print information about the triangulated mesh to the screen.
133  mesh.print_info();
134 
135  // Turn the triangulated mesh into a subdivision mesh
136  // and add an additional row of "ghost" elements around
137  // it in order to complete the extended local support of
138  // the triangles at the boundaries. If the second
139  // argument is set to true, the outermost existing
140  // elements are converted into ghost elements, and the
141  // actual physical mesh is thus getting smaller.
143 
144  // Print information about the subdivision mesh to the screen.
145  mesh.print_info();
146 
147  // Write the mesh with the ghost elements added.
148  // Compare this to the original mesh to see the difference.
149 #if defined(LIBMESH_HAVE_VTK)
150  VTKIO(mesh).write ("with_ghosts.pvtu");
151 #endif
152 #if defined(LIBMESH_HAVE_EXODUS_API)
153  ExodusII_IO(mesh).write ("with_ghosts.e");
154 #endif
155 
156  // Create an equation systems object.
157  EquationSystems equation_systems (mesh);
158 
159  // Declare the system and its variables.
160  // Create a linear implicit system named "Shell".
161  LinearImplicitSystem & system = equation_systems.add_system<LinearImplicitSystem> ("Shell");
162 
163  // Add the three translational deformation variables
164  // "u", "v", "w" to "Shell". Since subdivision shell
165  // elements meet the C1-continuity requirement, no
166  // rotational or other auxiliary variables are needed.
167  // Loop Subdivision Elements are always interpolated
168  // by quartic box splines, hence the order must always
169  // be FOURTH.
170  system.add_variable ("u", FOURTH, SUBDIVISION);
171  system.add_variable ("v", FOURTH, SUBDIVISION);
172  system.add_variable ("w", FOURTH, SUBDIVISION);
173 
174  // Give the system a pointer to the matrix and rhs assembly
175  // function.
177 
178  // Use the parameters of the equation systems object to
179  // tell the shell system about the material properties, the
180  // shell thickness, and the external load.
181  const Real h = 1.;
182  const Real E = 1.e7;
183  const Real nu = 0.;
184  const Real q = 1.;
185  equation_systems.parameters.set<Real> ("thickness") = h;
186  equation_systems.parameters.set<Real> ("young's modulus") = E;
187  equation_systems.parameters.set<Real> ("poisson ratio") = nu;
188  equation_systems.parameters.set<Real> ("uniform load") = q;
189 
190  // Initialize the data structures for the equation system.
191  equation_systems.init();
192 
193  // Print information about the system to the screen.
194  equation_systems.print_info();
195 
196  // Solve the linear system.
197  system.solve();
198 
199  // After solving the system, write the solution to a VTK
200  // or ExodusII output file ready for import in, e.g.,
201  // Paraview.
202 #if defined(LIBMESH_HAVE_VTK)
203  VTKIO(mesh).write_equation_systems ("out.pvtu", equation_systems);
204 #endif
205 #if defined(LIBMESH_HAVE_EXODUS_API)
206  ExodusII_IO(mesh).write_equation_systems ("out.e", equation_systems);
207 #endif
208 
209  // Find the center node to measure the maximum deformation of the plate.
210  Node * center_node = 0;
211  Real nearest_dist_sq = mesh.point(0).norm_sq();
212  for (unsigned int nid=1; nid<mesh.n_nodes(); ++nid)
213  {
214  const Real dist_sq = mesh.point(nid).norm_sq();
215  if (dist_sq < nearest_dist_sq)
216  {
217  nearest_dist_sq = dist_sq;
218  center_node = mesh.node_ptr(nid);
219  }
220  }
221 
222  // Finally, we evaluate the z-displacement "w" at the center node.
223  const unsigned int w_var = system.variable_number ("w");
224  dof_id_type w_dof = center_node->dof_number (system.number(), w_var, 0);
225  Number w = 0;
226  if (w_dof >= system.get_dof_map().first_dof() &&
227  w_dof < system.get_dof_map().end_dof())
228  w = system.current_solution(w_dof);
229  system.comm().sum(w);
230 
231 
232  // The analytic solution for the maximum displacement of
233  // a clamped square plate in pure bending, from Taylor,
234  // Govindjee, Commun. Numer. Meth. Eng. 20, 757-765, 2004.
235  const Real D = E * h*h*h / (12*(1-nu*nu));
236  const Real w_analytic = 0.001265319 * L*L*L*L * q / D;
237 
238  // Print the finite element solution and the analytic
239  // prediction of the maximum displacement of the clamped
240  // square plate to the screen.
241  libMesh::out << "z-displacement of the center point: " << w << std::endl;
242  libMesh::out << "Analytic solution for pure bending: " << w_analytic << std::endl;
243 
244 #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES, LIBMESH_DIM > 2
245 
246 #endif // #ifdef LIBMESH_ENABLE_AMR
247 
248  // All done.
249  return 0;
250 }
251 
252 #if defined(LIBMESH_ENABLE_SECOND_DERIVATIVES) && LIBMESH_DIM > 2
253 
254 // We now define the matrix and rhs vector assembly function
255 // for the shell system. This function implements the
256 // linear Kirchhoff-Love theory for thin shells. At the
257 // end we also take into account the boundary conditions
258 // here, using the penalty method.
260  const std::string & libmesh_dbg_var(system_name))
261 {
262  // It is a good idea to make sure we are assembling
263  // the proper system.
264  libmesh_assert_equal_to (system_name, "Shell");
265 
266  // Get a constant reference to the mesh object.
267  const MeshBase & mesh = es.get_mesh();
268 
269  // Get a reference to the shell system object.
270  LinearImplicitSystem & system = es.get_system<LinearImplicitSystem> ("Shell");
271 
272  // Get the shell parameters that we need during assembly.
273  const Real h = es.parameters.get<Real> ("thickness");
274  const Real E = es.parameters.get<Real> ("young's modulus");
275  const Real nu = es.parameters.get<Real> ("poisson ratio");
276  const Real q = es.parameters.get<Real> ("uniform load");
277 
278  // Compute the membrane stiffness K and the bending
279  // rigidity D from these parameters.
280  const Real K = E * h / (1-nu*nu);
281  const Real D = E * h*h*h / (12*(1-nu*nu));
282 
283  // Numeric ids corresponding to each variable in the system.
284  const unsigned int u_var = system.variable_number ("u");
285  const unsigned int v_var = system.variable_number ("v");
286  const unsigned int w_var = system.variable_number ("w");
287 
288  // Get the Finite Element type for "u". Note this will be
289  // the same as the type for "v" and "w".
290  FEType fe_type = system.variable_type (u_var);
291 
292  // Build a Finite Element object of the specified type.
293  std::unique_ptr<FEBase> fe (FEBase::build(2, fe_type));
294 
295  // A Gauss quadrature rule for numerical integration.
296  // For subdivision shell elements, a single Gauss point per
297  // element is sufficient, hence we use extraorder = 0.
298  const int extraorder = 0;
299  std::unique_ptr<QBase> qrule (fe_type.default_quadrature_rule (2, extraorder));
300 
301  // Tell the finite element object to use our quadrature rule.
302  fe->attach_quadrature_rule (qrule.get());
303 
304  // The element Jacobian * quadrature weight at each integration point.
305  const std::vector<Real> & JxW = fe->get_JxW();
306 
307  // The surface tangents in both directions at the quadrature points.
308  const std::vector<RealGradient> & dxyzdxi = fe->get_dxyzdxi();
309  const std::vector<RealGradient> & dxyzdeta = fe->get_dxyzdeta();
310 
311  // The second partial derivatives at the quadrature points.
312  const std::vector<RealGradient> & d2xyzdxi2 = fe->get_d2xyzdxi2();
313  const std::vector<RealGradient> & d2xyzdeta2 = fe->get_d2xyzdeta2();
314  const std::vector<RealGradient> & d2xyzdxideta = fe->get_d2xyzdxideta();
315 
316  // The element shape function and its derivatives evaluated at the
317  // quadrature points.
318  const std::vector<std::vector<Real>> & phi = fe->get_phi();
319  const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
320  const std::vector<std::vector<RealTensor>> & d2phi = fe->get_d2phi();
321 
322  // A reference to the DofMap object for this system. The DofMap
323  // object handles the index translation from node and element numbers
324  // to degree of freedom numbers.
325  const DofMap & dof_map = system.get_dof_map();
326 
327  // Define data structures to contain the element stiffness matrix
328  // and right-hand-side vector contribution. Following
329  // basic finite element terminology we will denote these
330  // "Ke" and "Fe".
333 
335  Kuu(Ke), Kuv(Ke), Kuw(Ke),
336  Kvu(Ke), Kvv(Ke), Kvw(Ke),
337  Kwu(Ke), Kwv(Ke), Kww(Ke);
338 
340  Fu(Fe),
341  Fv(Fe),
342  Fw(Fe);
343 
344  // This vector will hold the degree of freedom indices for
345  // the element. These define where in the global system
346  // the element degrees of freedom get mapped.
347  std::vector<dof_id_type> dof_indices;
348  std::vector<dof_id_type> dof_indices_u;
349  std::vector<dof_id_type> dof_indices_v;
350  std::vector<dof_id_type> dof_indices_w;
351 
352  // Now we will loop over all the elements in the mesh. We will
353  // compute the element matrix and right-hand-side contribution.
354  for (const auto & elem : mesh.active_local_element_ptr_range())
355  {
356  // The ghost elements at the boundaries need to be excluded
357  // here, as they don't belong to the physical shell,
358  // but serve for a proper boundary treatment only.
359  libmesh_assert_equal_to (elem->type(), TRI3SUBDIVISION);
360  const Tri3Subdivision * sd_elem = static_cast<const Tri3Subdivision *> (elem);
361  if (sd_elem->is_ghost())
362  continue;
363 
364  // Get the degree of freedom indices for the
365  // current element. These define where in the global
366  // matrix and right-hand-side this element will
367  // contribute to.
368  dof_map.dof_indices (elem, dof_indices);
369  dof_map.dof_indices (elem, dof_indices_u, u_var);
370  dof_map.dof_indices (elem, dof_indices_v, v_var);
371  dof_map.dof_indices (elem, dof_indices_w, w_var);
372 
373  const std::size_t n_dofs = dof_indices.size();
374  const std::size_t n_u_dofs = dof_indices_u.size();
375  const std::size_t n_v_dofs = dof_indices_v.size();
376  const std::size_t n_w_dofs = dof_indices_w.size();
377 
378  // Compute the element-specific data for the current
379  // element. This involves computing the location of the
380  // quadrature points and the shape functions
381  // (phi, dphi, d2phi) for the current element.
382  fe->reinit (elem);
383 
384  // Zero the element matrix and right-hand side before
385  // summing them. We use the resize member here because
386  // the number of degrees of freedom might have changed from
387  // the last element.
388  Ke.resize (n_dofs, n_dofs);
389  Fe.resize (n_dofs);
390 
391  // Reposition the submatrices... The idea is this:
392  //
393  // - - - -
394  // | Kuu Kuv Kuw | | Fu |
395  // Ke = | Kvu Kvv Kvw |; Fe = | Fv |
396  // | Kwu Kwv Kww | | Fw |
397  // - - - -
398  //
399  // The DenseSubMatrix.reposition () member takes the
400  // (row_offset, column_offset, row_size, column_size).
401  //
402  // Similarly, the DenseSubVector.reposition () member
403  // takes the (row_offset, row_size)
404  Kuu.reposition (u_var*n_u_dofs, u_var*n_u_dofs, n_u_dofs, n_u_dofs);
405  Kuv.reposition (u_var*n_u_dofs, v_var*n_u_dofs, n_u_dofs, n_v_dofs);
406  Kuw.reposition (u_var*n_u_dofs, w_var*n_u_dofs, n_u_dofs, n_w_dofs);
407 
408  Kvu.reposition (v_var*n_v_dofs, u_var*n_v_dofs, n_v_dofs, n_u_dofs);
409  Kvv.reposition (v_var*n_v_dofs, v_var*n_v_dofs, n_v_dofs, n_v_dofs);
410  Kvw.reposition (v_var*n_v_dofs, w_var*n_v_dofs, n_v_dofs, n_w_dofs);
411 
412  Kwu.reposition (w_var*n_w_dofs, u_var*n_w_dofs, n_w_dofs, n_u_dofs);
413  Kwv.reposition (w_var*n_w_dofs, v_var*n_w_dofs, n_w_dofs, n_v_dofs);
414  Kww.reposition (w_var*n_w_dofs, w_var*n_w_dofs, n_w_dofs, n_w_dofs);
415 
416  Fu.reposition (u_var*n_u_dofs, n_u_dofs);
417  Fv.reposition (v_var*n_u_dofs, n_v_dofs);
418  Fw.reposition (w_var*n_u_dofs, n_w_dofs);
419 
420  // Now we will build the element matrix and right-hand-side.
421  for (unsigned int qp=0; qp<qrule->n_points(); ++qp)
422  {
423  // First, we compute the external force resulting
424  // from a load q distributed uniformly across the plate.
425  // Since the load is supposed to be transverse to the plate,
426  // it affects the z-direction, i.e. the "w" variable.
427  for (unsigned int i=0; i<n_u_dofs; ++i)
428  Fw(i) += JxW[qp] * phi[i][qp] * q;
429 
430  // Next, we assemble the stiffness matrix. This is only valid
431  // for the linear theory, i.e., for small deformations, where
432  // reference and deformed surface metrics are indistinguishable.
433 
434  // Get the three surface basis vectors.
435  const RealVectorValue & a1 = dxyzdxi[qp];
436  const RealVectorValue & a2 = dxyzdeta[qp];
437  RealVectorValue a3 = a1.cross(a2);
438  const Real jac = a3.norm(); // the surface Jacobian
439  libmesh_assert_greater (jac, 0);
440  a3 /= jac; // the shell director a3 is normalized to unit length
441 
442  // Get the derivatives of the surface tangents.
443  const RealVectorValue & a11 = d2xyzdxi2[qp];
444  const RealVectorValue & a22 = d2xyzdeta2[qp];
445  const RealVectorValue & a12 = d2xyzdxideta[qp];
446 
447  // Compute the three covariant components of the first
448  // fundamental form of the surface.
449  const RealVectorValue a(a1*a1, a2*a2, a1*a2);
450 
451  // The elastic H matrix in Voigt's notation, computed from the
452  // covariant components of the first fundamental form rather
453  // than the contravariant components, exploiting that the
454  // contravariant first fundamental form is the inverse of the
455  // covariant first fundamental form (hence the determinant etc.).
456  RealTensorValue H;
457  H(0,0) = a(1) * a(1);
458  H(0,1) = H(1,0) = nu * a(1) * a(0) + (1-nu) * a(2) * a(2);
459  H(0,2) = H(2,0) = -a(1) * a(2);
460  H(1,1) = a(0) * a(0);
461  H(1,2) = H(2,1) = -a(0) * a(2);
462  H(2,2) = 0.5 * ((1-nu) * a(1) * a(0) + (1+nu) * a(2) * a(2));
463  const Real det = a(0) * a(1) - a(2) * a(2);
464  libmesh_assert_not_equal_to (det * det, 0);
465  H /= det * det;
466 
467  // Precompute come cross products for the bending part below.
468  const RealVectorValue a11xa2 = a11.cross(a2);
469  const RealVectorValue a22xa2 = a22.cross(a2);
470  const RealVectorValue a12xa2 = a12.cross(a2);
471  const RealVectorValue a1xa11 = a1.cross(a11);
472  const RealVectorValue a1xa22 = a1.cross(a22);
473  const RealVectorValue a1xa12 = a1.cross(a12);
474  const RealVectorValue a2xa3 = a2.cross(a3);
475  const RealVectorValue a3xa1 = a3.cross(a1);
476 
477  // Loop over all pairs of nodes I,J.
478  for (unsigned int i=0; i<n_u_dofs; ++i)
479  {
480  for (unsigned int j=0; j<n_u_dofs; ++j)
481  {
482  // The membrane strain matrices in Voigt's notation.
483  RealTensorValue MI, MJ;
484  for (unsigned int k=0; k<3; ++k)
485  {
486  MI(0,k) = dphi[i][qp](0) * a1(k);
487  MI(1,k) = dphi[i][qp](1) * a2(k);
488  MI(2,k) = dphi[i][qp](1) * a1(k)
489  + dphi[i][qp](0) * a2(k);
490 
491  MJ(0,k) = dphi[j][qp](0) * a1(k);
492  MJ(1,k) = dphi[j][qp](1) * a2(k);
493  MJ(2,k) = dphi[j][qp](1) * a1(k)
494  + dphi[j][qp](0) * a2(k);
495  }
496 
497  // The bending strain matrices in Voigt's notation.
498  RealTensorValue BI, BJ;
499  for (unsigned int k=0; k<3; ++k)
500  {
501  const Real term_ik = dphi[i][qp](0) * a2xa3(k)
502  + dphi[i][qp](1) * a3xa1(k);
503  BI(0,k) = -d2phi[i][qp](0,0) * a3(k)
504  +(dphi[i][qp](0) * a11xa2(k)
505  + dphi[i][qp](1) * a1xa11(k)
506  + (a3*a11) * term_ik) / jac;
507  BI(1,k) = -d2phi[i][qp](1,1) * a3(k)
508  +(dphi[i][qp](0) * a22xa2(k)
509  + dphi[i][qp](1) * a1xa22(k)
510  + (a3*a22) * term_ik) / jac;
511  BI(2,k) = 2 * (-d2phi[i][qp](0,1) * a3(k)
512  +(dphi[i][qp](0) * a12xa2(k)
513  + dphi[i][qp](1) * a1xa12(k)
514  + (a3*a12) * term_ik) / jac);
515 
516  const Real term_jk = dphi[j][qp](0) * a2xa3(k)
517  + dphi[j][qp](1) * a3xa1(k);
518  BJ(0,k) = -d2phi[j][qp](0,0) * a3(k)
519  +(dphi[j][qp](0) * a11xa2(k)
520  + dphi[j][qp](1) * a1xa11(k)
521  + (a3*a11) * term_jk) / jac;
522  BJ(1,k) = -d2phi[j][qp](1,1) * a3(k)
523  +(dphi[j][qp](0) * a22xa2(k)
524  + dphi[j][qp](1) * a1xa22(k)
525  + (a3*a22) * term_jk) / jac;
526  BJ(2,k) = 2 * (-d2phi[j][qp](0,1) * a3(k)
527  +(dphi[j][qp](0) * a12xa2(k)
528  + dphi[j][qp](1) * a1xa12(k)
529  + (a3*a12) * term_jk) / jac);
530  }
531 
532  // The total stiffness matrix coupling the nodes
533  // I and J is a sum of membrane and bending
534  // contributions according to the following formula.
535  const RealTensorValue KIJ = JxW[qp] * K * MI.transpose() * H * MJ
536  + JxW[qp] * D * BI.transpose() * H * BJ;
537 
538  // Insert the components of the coupling stiffness
539  // matrix KIJ into the corresponding directional
540  // submatrices.
541  Kuu(i,j) += KIJ(0,0);
542  Kuv(i,j) += KIJ(0,1);
543  Kuw(i,j) += KIJ(0,2);
544 
545  Kvu(i,j) += KIJ(1,0);
546  Kvv(i,j) += KIJ(1,1);
547  Kvw(i,j) += KIJ(1,2);
548 
549  Kwu(i,j) += KIJ(2,0);
550  Kwv(i,j) += KIJ(2,1);
551  Kww(i,j) += KIJ(2,2);
552  }
553  }
554 
555  } // end of the quadrature point qp-loop
556 
557  // The element matrix and right-hand-side are now built
558  // for this element. Add them to the global matrix and
559  // right-hand-side vector. The NumericMatrix::add_matrix()
560  // and NumericVector::add_vector() members do this for us.
561  system.matrix->add_matrix (Ke, dof_indices);
562  system.rhs->add_vector (Fe, dof_indices);
563  } // end of non-ghost element loop
564 
565  // Next, we apply the boundary conditions. In this case,
566  // all boundaries are clamped by the penalty method, using
567  // the special "ghost" nodes along the boundaries. Note
568  // that there are better ways to implement boundary conditions
569  // for subdivision shells. We use the simplest way here,
570  // which is known to be overly restrictive and will lead to
571  // a slightly too small deformation of the plate.
572  for (const auto & elem : mesh.active_local_element_ptr_range())
573  {
574  // For the boundary conditions, we only need to loop over
575  // the ghost elements.
576  libmesh_assert_equal_to (elem->type(), TRI3SUBDIVISION);
577  const Tri3Subdivision * gh_elem = static_cast<const Tri3Subdivision *> (elem);
578  if (!gh_elem->is_ghost())
579  continue;
580 
581  // Find the side which is part of the physical plate boundary,
582  // that is, the boundary of the original mesh without ghosts.
583  for (auto s : elem->side_index_range())
584  {
585  const Tri3Subdivision * nb_elem = static_cast<const Tri3Subdivision *> (elem->neighbor_ptr(s));
586  if (nb_elem == nullptr || nb_elem->is_ghost())
587  continue;
588 
589  /*
590  * Determine the four nodes involved in the boundary
591  * condition treatment of this side. The MeshTools::Subdiv
592  * namespace provides lookup tables next and prev
593  * for an efficient determination of the next and previous
594  * nodes of an element, respectively.
595  *
596  * n4
597  * / \
598  * / gh \
599  * n2 ---- n3
600  * \ nb /
601  * \ /
602  * n1
603  */
604  const Node * nodes [4]; // n1, n2, n3, n4
605  nodes[1] = gh_elem->node_ptr(s); // n2
606  nodes[2] = gh_elem->node_ptr(MeshTools::Subdivision::next[s]); // n3
607  nodes[3] = gh_elem->node_ptr(MeshTools::Subdivision::prev[s]); // n4
608 
609  // The node in the interior of the domain, n1, is the
610  // hardest to find. Walk along the edges of element nb until
611  // we have identified it.
612  unsigned int n_int = 0;
613  nodes[0] = nb_elem->node_ptr(0);
614  while (nodes[0]->id() == nodes[1]->id() || nodes[0]->id() == nodes[2]->id())
615  nodes[0] = nb_elem->node_ptr(++n_int);
616 
617  // The penalty value. \f$ \frac{1}{\epsilon} \f$
618  const Real penalty = 1.e10;
619 
620  // With this simple method, clamped boundary conditions are
621  // obtained by penalizing the displacements of all four nodes.
622  // This ensures that the displacement field vanishes on the
623  // boundary side s.
624  for (unsigned int n=0; n<4; ++n)
625  {
626  const dof_id_type u_dof = nodes[n]->dof_number (system.number(), u_var, 0);
627  const dof_id_type v_dof = nodes[n]->dof_number (system.number(), v_var, 0);
628  const dof_id_type w_dof = nodes[n]->dof_number (system.number(), w_var, 0);
629  system.matrix->add (u_dof, u_dof, penalty);
630  system.matrix->add (v_dof, v_dof, penalty);
631  system.matrix->add (w_dof, w_dof, penalty);
632  }
633  }
634  } // end of ghost element loop
635 }
636 
637 #endif // defined(LIBMESH_ENABLE_SECOND_DERIVATIVES) && LIBMESH_DIM > 2
libMesh::TypeTensor::transpose
TypeTensor< T > transpose() const
Definition: type_tensor.h:1068
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::MeshTools::Subdivision::next
static const unsigned int next[3]
A lookup table for the increment modulo 3 operation, for iterating through the three nodes per elemen...
Definition: mesh_subdivision_support.h:102
libMesh::EquationSystems::add_system
virtual System & add_system(const std::string &system_type, const std::string &name)
Add the system of type system_type named name to the systems array.
Definition: equation_systems.C:345
libMesh::EquationSystems::get_mesh
const MeshBase & get_mesh() const
Definition: equation_systems.h:637
libMesh::MeshBase::read
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.
libMesh::ExplicitSystem::rhs
NumericVector< Number > * rhs
The system matrix.
Definition: explicit_system.h:114
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::MeshBase::point
virtual const Point & point(const dof_id_type i) const =0
libMesh::MeshBase::active_local_element_ptr_range
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
libMesh::DenseSubMatrix
Defines a dense submatrix for use in Finite Element-type computations.
Definition: dense_submatrix.h:45
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::EquationSystems::get_system
const T_sys & get_system(const std::string &name) const
Definition: equation_systems.h:757
assemble_shell
void assemble_shell(EquationSystems &es, const std::string &system_name)
Definition: miscellaneous_ex12.C:348
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::DenseMatrix< Number >
libMesh::LinearImplicitSystem::solve
virtual void solve() override
Assembles & solves the linear system A*x=b.
Definition: linear_implicit_system.C:108
libMesh::default_solver_package
SolverPackage default_solver_package()
Definition: libmesh.C:993
libMesh::System::number
unsigned int number() const
Definition: system.h:2075
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase::node_ptr
virtual const Node * node_ptr(const dof_id_type i) const =0
libMesh::DofMap::first_dof
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:650
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::VTKIO
This class implements reading and writing meshes in the VTK format.
Definition: vtk_io.h:60
libMesh::DenseMatrix::resize
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
Definition: dense_matrix.h:822
libMesh::VectorValue< Real >
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
libMesh::System::current_solution
Number current_solution(const dof_id_type global_dof_number) const
Definition: system.C:194
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::MeshRefinement
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Definition: mesh_refinement.h:61
libMesh::DofObject::dof_number
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
Definition: dof_object.h:956
libMesh::System::attach_assemble_function
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.
Definition: system.C:1755
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
libMesh::TypeVector::norm_sq
auto norm_sq() const -> decltype(std::norm(T()))
Definition: type_vector.h:986
libMesh::Tri3Subdivision::is_ghost
bool is_ghost() const
Definition: face_tri3_subdivision.h:116
libMesh::INVALID_SOLVER_PACKAGE
Definition: enum_solver_package.h:43
libMesh::FEGenericBase::build
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
libMesh::System::add_variable
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.
Definition: system.C:1069
libMesh::TensorValue
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
Definition: exact_solution.h:53
libMesh::EquationSystems::init
virtual void init()
Initialize all the systems.
Definition: equation_systems.C:96
libMesh::ImplicitSystem::matrix
SparseMatrix< Number > * matrix
The system matrix.
Definition: implicit_system.h:393
libMesh::Node
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::FEType::default_quadrature_rule
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
Definition: fe_type.C:31
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
libMesh::SparseMatrix::add
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
Add value to the element (i,j).
libMesh::EquationSystems::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
Definition: equation_systems.C:1314
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::Parameters::set
T & set(const std::string &)
Definition: parameters.h:460
libMesh::DenseSubVector< Number >
libMesh::MeshOutput::write_equation_systems
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 ...
Definition: mesh_output.C:31
libMesh::FOURTH
Definition: enum_order.h:45
libMesh::System::variable_type
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2233
libMesh::MeshBase::n_nodes
virtual dof_id_type n_nodes() const =0
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::MeshTools::Subdivision::prepare_subdivision_mesh
void prepare_subdivision_mesh(MeshBase &mesh, bool ghosted=false)
Prepares the mesh for use with subdivision elements.
Definition: mesh_subdivision_support.C:160
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::MeshTools::Modification::flatten
void flatten(MeshBase &mesh)
Removes all the refinement tree structure of Mesh, leaving only the highest-level (most-refined) elem...
Definition: mesh_modification.C:1265
libMesh::System::variable_number
unsigned short int variable_number(const std::string &var) const
Definition: system.C:1232
libMesh::DenseSubVector::reposition
void reposition(const unsigned int ioff, const unsigned int n)
Changes the location of the subvector in the parent vector.
Definition: dense_subvector.h:174
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::MeshTools::Subdivision::prev
static const unsigned int prev[3]
A lookup table for the decrement modulo 3 operation, for iterating through the three nodes per elemen...
Definition: mesh_subdivision_support.h:108
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::SUBDIVISION
Definition: enum_fe_family.h:55
libMesh::TypeVector::cross
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const
Definition: type_vector.h:920
libMesh::VTKIO::write
virtual void write(const std::string &) override
Output the mesh without solutions to a .pvtu file.
libMesh::TRI3SUBDIVISION
Definition: enum_elem_type.h:69
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
main
int main(int argc, char **argv)
Definition: miscellaneous_ex11.C:79
libMesh::MeshTools::Modification::scale
void scale(MeshBase &mesh, const Real xs, const Real ys=0., const Real zs=0.)
Scales the mesh.
Definition: mesh_modification.C:243
libMesh::TypeVector::norm
auto norm() const -> decltype(std::norm(T()))
Definition: type_vector.h:955
libMesh::Tri3Subdivision
The Tri3Subdivision element is a three-noded subdivision surface shell element used in mechanics calc...
Definition: face_tri3_subdivision.h:40
libMesh::Parameters::get
const T & get(const std::string &) const
Definition: parameters.h:421
libMesh::out
OStreamProxy out
libMesh::Elem::node_ptr
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:2009
libMesh::MeshRefinement::uniformly_refine
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
Definition: mesh_refinement.C:1678
libMesh::DenseVector< Number >
libMesh::DenseSubMatrix::reposition
void reposition(const unsigned int ioff, const unsigned int joff, const unsigned int new_m, const unsigned int new_n)
Changes the location of the submatrix in the parent matrix.
Definition: dense_submatrix.h:173
libMesh::DofMap::end_dof
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:692
libMesh::EquationSystems::parameters
Parameters parameters
Data structure holding arbitrary parameters.
Definition: equation_systems.h:557