681 *
const unsigned int = 0) const override
690 * hessian_list(
const std::vector<
Point<dim>> &points,
692 *
const unsigned int = 0) const override
694 *
for (
unsigned i = 0; i < points.size(); ++i)
696 *
const double x = points[i][0];
697 *
const double y = points[i][1];
708 *
class RightHandSide :
public Function<dim>
711 *
static_assert(dim == 2,
"Only dim==2 is implemented");
714 *
const unsigned int = 0) const override
717 *
return 4 * Utilities::fixed_power<4>(PI) *
std::sin(PI * p[0]) *
728 * <a name=
"step_47-Themainclass"></a>
729 * <h3>The main
class</h3>
733 * The following is the principal
class of this tutorial program. It has
734 * the structure of many of the other tutorial programs and there should
735 * really be
nothing particularly surprising about its contents or
736 * the constructor that follows it.
740 *
class BiharmonicProblem
743 * BiharmonicProblem(
const unsigned int fe_degree);
749 *
void setup_system();
750 *
void assemble_system();
752 *
void compute_errors();
753 *
void output_results(
const unsigned int iteration)
const;
773 * BiharmonicProblem<dim>::BiharmonicProblem(
const unsigned int fe_degree)
784 * unit square) and set up the constraints, vectors, and matrices on
785 * each mesh. Again, both of these are essentially unchanged from many
786 * previous tutorial programs.
790 *
void BiharmonicProblem<dim>::make_grid()
795 * std::cout <<
"Number of active cells: " <<
triangulation.n_active_cells()
804 *
void BiharmonicProblem<dim>::setup_system()
806 * dof_handler.distribute_dofs(fe);
808 * std::cout <<
" Number of degrees of freedom: " << dof_handler.n_dofs()
811 * constraints.clear();
816 * ExactSolution::Solution<dim>(),
818 * constraints.close();
823 * sparsity_pattern.copy_from(dsp);
824 * system_matrix.reinit(sparsity_pattern);
826 * solution.reinit(dof_handler.n_dofs());
827 * system_rhs.reinit(dof_handler.n_dofs());
835 * <a name=
"step_47-Assemblingthelinearsystem"></a>
836 * <h4>Assembling the linear system</h4>
840 * The following pieces of code are more interesting. They all relate to the
841 * assembly of the linear system. While assembling the cell-interior terms
842 * is not of great difficulty -- that works in essence like the assembly
843 * of the corresponding terms of the Laplace equation, and you have seen
844 * how
this works in @ref step_4
"step-4" or @ref step_6
"step-6",
for example -- the difficulty
845 * is with the penalty terms in the formulation. These require the evaluation
847 * one would therefore need to use two
FEFaceValues objects, but
if one of the
848 * two sides is adaptively refined, then one actually needs an
FEFaceValues
850 * shape
functions live where, and
finally we need to ensure that every
851 * face is visited only once. All of
this is a substantial overhead to the
852 * logic we really want to implement (namely the penalty terms in the
853 * bilinear form). As a consequence, we will make use of the
856 * directly access what we really care about: jumps, averages, etc.
860 * But
this doesn
't yet solve our problem of having to keep track of
861 * which faces we have already visited when we loop over all cells and
862 * all of their faces. To make this process simpler, we use the
863 * MeshWorker::mesh_loop() function that provides a simple interface
864 * for this task: Based on the ideas outlined in the WorkStream
865 * namespace documentation, MeshWorker::mesh_loop() requires three
866 * functions that do work on cells, interior faces, and boundary
867 * faces. These functions work on scratch objects for intermediate
868 * results, and then copy the result of their computations into
869 * copy data objects from where a copier function copies them into
870 * the global matrix and right hand side objects.
874 * The following structures then provide the scratch and copy objects
875 * that are necessary for this approach. You may look up the WorkStream
876 * namespace as well as the
877 * @ref threads "Parallel computing with multiple processors"
878 * topic for more information on how they typically work.
884 * ScratchData(const Mapping<dim> &mapping,
885 * const FiniteElement<dim> &fe,
886 * const unsigned int quadrature_degree,
887 * const UpdateFlags update_flags,
888 * const UpdateFlags interface_update_flags)
889 * : fe_values(mapping, fe, QGauss<dim>(quadrature_degree), update_flags)
890 * , fe_interface_values(mapping,
892 * QGauss<dim - 1>(quadrature_degree),
893 * interface_update_flags)
897 * ScratchData(const ScratchData<dim> &scratch_data)
898 * : fe_values(scratch_data.fe_values.get_mapping(),
899 * scratch_data.fe_values.get_fe(),
900 * scratch_data.fe_values.get_quadrature(),
901 * scratch_data.fe_values.get_update_flags())
902 * , fe_interface_values(scratch_data.fe_values.get_mapping(),
903 * scratch_data.fe_values.get_fe(),
904 * scratch_data.fe_interface_values.get_quadrature(),
905 * scratch_data.fe_interface_values.get_update_flags())
908 * FEValues<dim> fe_values;
909 * FEInterfaceValues<dim> fe_interface_values;
916 * CopyData(const unsigned int dofs_per_cell)
917 * : cell_matrix(dofs_per_cell, dofs_per_cell)
918 * , cell_rhs(dofs_per_cell)
919 * , local_dof_indices(dofs_per_cell)
923 * CopyData(const CopyData &) = default;
926 * CopyData(CopyData &&) = default;
929 * ~CopyData() = default;
932 * CopyData &operator=(const CopyData &) = default;
935 * CopyData &operator=(CopyData &&) = default;
940 * FullMatrix<double> cell_matrix;
941 * std::vector<types::global_dof_index> joint_dof_indices;
944 * FullMatrix<double> cell_matrix;
945 * Vector<double> cell_rhs;
946 * std::vector<types::global_dof_index> local_dof_indices;
947 * std::vector<FaceData> face_data;
954 * The more interesting part is where we actually assemble the linear system.
955 * Fundamentally, this function has five parts:
956 * - The definition of the `cell_worker` lambda function, a small
957 * function that is defined within the `assemble_system()`
958 * function and that will be responsible for computing the local
959 * integrals on an individual cell. It will work on a copy of the
960 * `ScratchData` class and put its results into the corresponding
962 * - The definition of the `face_worker` lambda function that does
963 * the integration of all terms that live on the interfaces between
965 * - The definition of the `boundary_worker` function that does the
966 * same but for cell faces located on the boundary of the domain.
967 * - The definition of the `copier` function that is responsible
968 * for copying all of the data the previous three functions have
969 * put into copy objects for a single cell, into the global matrix
970 * and right hand side.
974 * The fifth part is the one where we bring all of this together.
978 * Let us go through each of these pieces necessary for the assembly
983 * void BiharmonicProblem<dim>::assemble_system()
985 * using Iterator = typename DoFHandler<dim>::active_cell_iterator;
989 * The first piece is the `cell_worker` that does the assembly
990 * on the cell interiors. It is a (lambda) function that takes
991 * a cell (input), a scratch object, and a copy object (output)
992 * as arguments. It looks like the assembly functions of many
993 * other of the tutorial programs, or at least the body of the
994 * loop over all cells.
998 * The terms we integrate here are the cell contribution
1000 * A^K_{ij} = \int_K \nabla^2\varphi_i(x) : \nabla^2\varphi_j(x) dx
1002 * to the global matrix, and
1004 * f^K_i = \int_K \varphi_i(x) f(x) dx
1006 * to the right hand side vector.
1010 * We use the same technique as used in the assembly of @ref step_22 "step-22"
1011 * to accelerate the function: Instead of calling
1012 * `fe_values.shape_hessian(i, qpoint)` in the innermost loop,
1013 * we create a variable `hessian_i` that evaluates this
1014 * value once in the loop over `i` and re-use the so-evaluated
1015 * value in the loop over `j`. For symmetry, we do the same with a
1016 * variable `hessian_j`, although it is indeed only used once and
1017 * we could have left the call to `fe_values.shape_hessian(j,qpoint)`
1018 * in the instruction that computes the scalar product between
1022 * auto cell_worker = [&](const Iterator &cell,
1023 * ScratchData<dim> &scratch_data,
1024 * CopyData ©_data) {
1025 * copy_data.cell_matrix = 0;
1026 * copy_data.cell_rhs = 0;
1028 * FEValues<dim> &fe_values = scratch_data.fe_values;
1029 * fe_values.reinit(cell);
1031 * cell->get_dof_indices(copy_data.local_dof_indices);
1033 * ExactSolution::RightHandSide<dim> right_hand_side;
1035 * const unsigned int dofs_per_cell =
1036 * scratch_data.fe_values.get_fe().n_dofs_per_cell();
1038 * for (unsigned int qpoint = 0; qpoint < fe_values.n_quadrature_points;
1041 * for (unsigned int i = 0; i < dofs_per_cell; ++i)
1043 * const Tensor<2, dim> &hessian_i =
1044 * fe_values.shape_hessian(i, qpoint);
1046 * for (unsigned int j = 0; j < dofs_per_cell; ++j)
1048 * const Tensor<2, dim> &hessian_j =
1049 * fe_values.shape_hessian(j, qpoint);
1051 * copy_data.cell_matrix(i, j) +=
1052 * scalar_product(hessian_i, // nabla^2 phi_i(x)
1053 * hessian_j) * // nabla^2 phi_j(x)
1054 * fe_values.JxW(qpoint); // dx
1057 * copy_data.cell_rhs(i) +=
1058 * fe_values.shape_value(i, qpoint) * // phi_i(x)
1059 * right_hand_side.value(
1060 * fe_values.quadrature_point(qpoint)) * // f(x)
1061 * fe_values.JxW(qpoint); // dx
1069 * The next building block is the one that assembles penalty terms on each
1070 * of the interior faces of the mesh. As described in the documentation of
1071 * MeshWorker::mesh_loop(), this function receives arguments that denote
1072 * a cell and its neighboring cell, as well as (for each of the two
1073 * cells) the face (and potentially sub-face) we have to integrate
1074 * over. Again, we also get a scratch object, and a copy object
1075 * for putting the results in.
1079 * The function has three parts itself. At the top, we initialize
1080 * the FEInterfaceValues object and create a new `CopyData::FaceData`
1081 * object to store our input in. This gets pushed to the end of the
1082 * `copy_data.face_data` variable. We need to do this because
1083 * the number of faces (or subfaces) over which we integrate for a
1084 * given cell differs from cell to cell, and the sizes of these
1085 * matrices also differ, depending on what degrees of freedom
1086 * are adjacent to the face or subface. As discussed in the documentation
1087 * of MeshWorker::mesh_loop(), the copy object is reset every time a new
1088 * cell is visited, so that what we push to the end of
1089 * `copy_data.face_data()` is really all that the later `copier` function
1090 * gets to see when it copies the contributions of each cell to the global
1091 * matrix and right hand side objects.
1094 * auto face_worker = [&](const Iterator &cell,
1095 * const unsigned int &f,
1096 * const unsigned int &sf,
1097 * const Iterator &ncell,
1098 * const unsigned int &nf,
1099 * const unsigned int &nsf,
1100 * ScratchData<dim> &scratch_data,
1101 * CopyData ©_data) {
1102 * FEInterfaceValues<dim> &fe_interface_values =
1103 * scratch_data.fe_interface_values;
1104 * fe_interface_values.reinit(cell, f, sf, ncell, nf, nsf);
1106 * copy_data.face_data.emplace_back();
1107 * CopyData::FaceData ©_data_face = copy_data.face_data.back();
1109 * copy_data_face.joint_dof_indices =
1110 * fe_interface_values.get_interface_dof_indices();
1112 * const unsigned int n_interface_dofs =
1113 * fe_interface_values.n_current_interface_dofs();
1114 * copy_data_face.cell_matrix.reinit(n_interface_dofs, n_interface_dofs);
1118 * The second part deals with determining what the penalty
1119 * parameter should be. By looking at the units of the various
1120 * terms in the bilinear form, it is clear that the penalty has
1121 * to have the form @f$\frac{\gamma}{h_K}@f$ (i.e., one over length
1122 * scale), but it is not a priori obvious how one should choose
1123 * the dimension-less number @f$\gamma@f$. From the discontinuous
1124 * Galerkin theory for the Laplace equation, one might
1125 * conjecture that the right choice is @f$\gamma=p(p+1)@f$ is the
1126 * right choice, where @f$p@f$ is the polynomial degree of the
1127 * finite element used. We will discuss this choice in a bit
1128 * more detail in the results section of this program.
1132 * In the formula above, @f$h_K@f$ is the size of cell @f$K@f$. But this
1133 * is not quite so straightforward either: If one uses highly
1134 * stretched cells, then a more involved theory says that @f$h@f$
1135 * should be replaced by the diameter of cell @f$K@f$ normal to the
1136 * direction of the edge in question. It turns out that there
1137 * is a function in deal.II for that. Secondly, @f$h_K@f$ may be
1138 * different when viewed from the two different sides of a face.
1142 * To stay on the safe side, we take the maximum of the two values.
1143 * We will note that it is possible that this computation has to be
1144 * further adjusted if one were to use hanging nodes resulting from
1145 * adaptive mesh refinement.
1148 * const unsigned int p = fe.degree;
1149 * const double gamma_over_h =
1150 * std::max((1.0 * p * (p + 1) /
1151 * cell->extent_in_direction(
1152 * GeometryInfo<dim>::unit_normal_direction[f])),
1153 * (1.0 * p * (p + 1) /
1154 * ncell->extent_in_direction(
1155 * GeometryInfo<dim>::unit_normal_direction[nf])));
1159 * Finally, and as usual, we loop over the quadrature points and
1160 * indices `i` and `j` to add up the contributions of this face
1161 * or sub-face. These are then stored in the
1162 * `copy_data.face_data` object created above. As for the cell
1163 * worker, we pull the evaluation of averages and jumps out of
1164 * the loops if possible, introducing local variables that store
1165 * these results. The assembly then only needs to use these
1166 * local variables in the innermost loop. Regarding the concrete
1167 * formula this code implements, recall that the interface terms
1168 * of the bilinear form were as follows:
1170 * -\sum_{e \in \mathbb{F}} \int_{e}
1171 * \jump{ \frac{\partial v_h}{\partial \mathbf n}}
1172 * \average{\frac{\partial^2 u_h}{\partial \mathbf n^2}} \ ds
1173 * -\sum_{e \in \mathbb{F}} \int_{e}
1174 * \average{\frac{\partial^2 v_h}{\partial \mathbf n^2}}
1175 * \jump{\frac{\partial u_h}{\partial \mathbf n}} \ ds
1176 * + \sum_{e \in \mathbb{F}}
1177 * \frac{\gamma}{h_e}
1179 * \jump{\frac{\partial v_h}{\partial \mathbf n}}
1180 * \jump{\frac{\partial u_h}{\partial \mathbf n}} \ ds.
1184 * for (unsigned int qpoint = 0;
1185 * qpoint < fe_interface_values.n_quadrature_points;
1188 * const auto &n = fe_interface_values.normal(qpoint);
1190 * for (unsigned int i = 0; i < n_interface_dofs; ++i)
1192 * const double av_hessian_i_dot_n_dot_n =
1193 * (fe_interface_values.average_of_shape_hessians(i, qpoint) * n *
1195 * const double jump_grad_i_dot_n =
1196 * (fe_interface_values.jump_in_shape_gradients(i, qpoint) * n);
1198 * for (unsigned int j = 0; j < n_interface_dofs; ++j)
1200 * const double av_hessian_j_dot_n_dot_n =
1201 * (fe_interface_values.average_of_shape_hessians(j, qpoint) *
1203 * const double jump_grad_j_dot_n =
1204 * (fe_interface_values.jump_in_shape_gradients(j, qpoint) *
1207 * copy_data_face.cell_matrix(i, j) +=
1208 * (-av_hessian_i_dot_n_dot_n // - {grad^2 v n n }
1209 * * jump_grad_j_dot_n // [grad u n]
1210 * - av_hessian_j_dot_n_dot_n // - {grad^2 u n n }
1211 * * jump_grad_i_dot_n // [grad v n]
1213 * gamma_over_h * // gamma/h
1214 * jump_grad_i_dot_n * // [grad v n]
1215 * jump_grad_j_dot_n) * // [grad u n]
1216 * fe_interface_values.JxW(qpoint); // dx
1225 * The third piece is to do the same kind of assembly for faces that
1226 * are at the boundary. The idea is the same as above, of course,
1227 * with only the difference that there are now penalty terms that
1228 * also go into the right hand side.
1232 * As before, the first part of the function simply sets up some
1236 * auto boundary_worker = [&](const Iterator &cell,
1237 * const unsigned int &face_no,
1238 * ScratchData<dim> &scratch_data,
1239 * CopyData ©_data) {
1240 * FEInterfaceValues<dim> &fe_interface_values =
1241 * scratch_data.fe_interface_values;
1242 * fe_interface_values.reinit(cell, face_no);
1243 * const auto &q_points = fe_interface_values.get_quadrature_points();
1245 * copy_data.face_data.emplace_back();
1246 * CopyData::FaceData ©_data_face = copy_data.face_data.back();
1248 * const unsigned int n_dofs =
1249 * fe_interface_values.n_current_interface_dofs();
1250 * copy_data_face.joint_dof_indices =
1251 * fe_interface_values.get_interface_dof_indices();
1253 * copy_data_face.cell_matrix.reinit(n_dofs, n_dofs);
1255 * const std::vector<double> &JxW = fe_interface_values.get_JxW_values();
1256 * const std::vector<Tensor<1, dim>> &normals =
1257 * fe_interface_values.get_normal_vectors();
1260 * ExactSolution::Solution<dim> exact_solution;
1261 * std::vector<Tensor<1, dim>> exact_gradients(q_points.size());
1262 * exact_solution.gradient_list(q_points, exact_gradients);
1267 * Positively, because we now only deal with one cell adjacent to the
1268 * face (as we are on the boundary), the computation of the penalty
1269 * factor @f$\gamma@f$ is substantially simpler:
1272 * const unsigned int p = fe.degree;
1273 * const double gamma_over_h =
1274 * (1.0 * p * (p + 1) /
1275 * cell->extent_in_direction(
1276 * GeometryInfo<dim>::unit_normal_direction[face_no]));
1280 * The third piece is the assembly of terms. This is now
1281 * slightly more involved since these contains both terms for
1282 * the matrix and for the right hand side. The former is exactly
1283 * the same as for the interior faces stated above if one just
1284 * defines the jump and average appropriately (which is what the
1285 * FEInterfaceValues class does). The latter requires us to
1286 * evaluate the boundary conditions @f$j(\mathbf x)@f$, which in the
1287 * current case (where we know the exact solution) we compute
1288 * from @f$j(\mathbf x) = \frac{\partial u(\mathbf x)}{\partial
1289 * {\mathbf n}}@f$. The term to be added to the right hand side
1291 * @f$\frac{\gamma}{h_e}\int_e
1292 * \jump{\frac{\partial v_h}{\partial \mathbf n}} j \ ds@f$.
1295 * for (unsigned int qpoint = 0; qpoint < q_points.size(); ++qpoint)
1297 * const auto &n = normals[qpoint];
1299 * for (unsigned int i = 0; i < n_dofs; ++i)
1301 * const double av_hessian_i_dot_n_dot_n =
1302 * (fe_interface_values.average_of_shape_hessians(i, qpoint) * n *
1304 * const double jump_grad_i_dot_n =
1305 * (fe_interface_values.jump_in_shape_gradients(i, qpoint) * n);
1307 * for (unsigned int j = 0; j < n_dofs; ++j)
1309 * const double av_hessian_j_dot_n_dot_n =
1310 * (fe_interface_values.average_of_shape_hessians(j, qpoint) *
1312 * const double jump_grad_j_dot_n =
1313 * (fe_interface_values.jump_in_shape_gradients(j, qpoint) *
1316 * copy_data_face.cell_matrix(i, j) +=
1317 * (-av_hessian_i_dot_n_dot_n // - {grad^2 v n n}
1318 * * jump_grad_j_dot_n // [grad u n]
1320 * - av_hessian_j_dot_n_dot_n // - {grad^2 u n n}
1321 * * jump_grad_i_dot_n // [grad v n]
1323 * + gamma_over_h // gamma/h
1324 * * jump_grad_i_dot_n // [grad v n]
1325 * * jump_grad_j_dot_n // [grad u n]
1327 * JxW[qpoint]; // dx
1330 * copy_data.cell_rhs(i) +=
1331 * (-av_hessian_i_dot_n_dot_n * // - {grad^2 v n n }
1332 * (exact_gradients[qpoint] * n) // (grad u_exact . n)
1334 * gamma_over_h // gamma/h
1335 * * jump_grad_i_dot_n // [grad v n]
1336 * * (exact_gradients[qpoint] * n) // (grad u_exact . n)
1338 * JxW[qpoint]; // dx
1345 * Part 4 is a small function that copies the data produced by the
1346 * cell, interior, and boundary face assemblers above into the
1347 * global matrix and right hand side vector. There really is not
1348 * very much to do here: We distribute the cell matrix and right
1349 * hand side contributions as we have done in almost all of the
1350 * other tutorial programs using the constraints objects. We then
1351 * also have to do the same for the face matrix contributions
1352 * that have gained content for the faces (interior and boundary)
1353 * and that the `face_worker` and `boundary_worker` have added
1354 * to the `copy_data.face_data` array.
1357 * auto copier = [&](const CopyData ©_data) {
1358 * constraints.distribute_local_to_global(copy_data.cell_matrix,
1359 * copy_data.cell_rhs,
1360 * copy_data.local_dof_indices,
1364 * for (const auto &cdf : copy_data.face_data)
1366 * constraints.distribute_local_to_global(cdf.cell_matrix,
1367 * cdf.joint_dof_indices,
1375 * Having set all of this up, what remains is to just create a scratch
1376 * and copy data object and call the MeshWorker::mesh_loop() function
1377 * that then goes over all cells and faces, calls the respective workers
1378 * on them, and then the copier function that puts things into the
1379 * global matrix and right hand side. As an additional benefit,
1380 * MeshWorker::mesh_loop() does all of this in parallel, using
1381 * as many processor cores as your machine happens to have.
1384 * const unsigned int n_gauss_points = dof_handler.get_fe().degree + 1;
1385 * ScratchData<dim> scratch_data(mapping,
1388 * update_values | update_gradients |
1389 * update_hessians | update_quadrature_points |
1390 * update_JxW_values,
1391 * update_values | update_gradients |
1392 * update_hessians | update_quadrature_points |
1393 * update_JxW_values | update_normal_vectors);
1394 * CopyData copy_data(dof_handler.get_fe().n_dofs_per_cell());
1395 * MeshWorker::mesh_loop(dof_handler.begin_active(),
1396 * dof_handler.end(),
1401 * MeshWorker::assemble_own_cells |
1402 * MeshWorker::assemble_boundary_faces |
1403 * MeshWorker::assemble_own_interior_faces_once,
1413 * <a name="step_47-Solvingthelinearsystemandpostprocessing"></a>
1414 * <h4>Solving the linear system and postprocessing</h4>
1418 * The show is essentially over at this point: The remaining functions are
1419 * not overly interesting or novel. The first one simply uses a direct
1420 * solver to solve the linear system (see also @ref step_29 "step-29"):
1423 * template <int dim>
1424 * void BiharmonicProblem<dim>::solve()
1426 * std::cout << " Solving system..." << std::endl;
1428 * SparseDirectUMFPACK A_direct;
1429 * A_direct.initialize(system_matrix);
1430 * A_direct.vmult(solution, system_rhs);
1432 * constraints.distribute(solution);
1439 * The next function evaluates the error between the computed solution
1440 * and the exact solution (which is known here because we have chosen
1441 * the right hand side and boundary values in a way so that we know
1442 * the corresponding solution). In the first two code blocks below,
1443 * we compute the error in the @f$L_2@f$ norm and the @f$H^1@f$ semi-norm.
1446 * template <int dim>
1447 * void BiharmonicProblem<dim>::compute_errors()
1450 * Vector<float> norm_per_cell(triangulation.n_active_cells());
1451 * VectorTools::integrate_difference(mapping,
1454 * ExactSolution::Solution<dim>(),
1456 * QGauss<dim>(fe.degree + 2),
1457 * VectorTools::L2_norm);
1458 * const double error_norm =
1459 * VectorTools::compute_global_error(triangulation,
1461 * VectorTools::L2_norm);
1462 * std::cout << " Error in the L2 norm : " << error_norm
1467 * Vector<float> norm_per_cell(triangulation.n_active_cells());
1468 * VectorTools::integrate_difference(mapping,
1471 * ExactSolution::Solution<dim>(),
1473 * QGauss<dim>(fe.degree + 2),
1474 * VectorTools::H1_seminorm);
1475 * const double error_norm =
1476 * VectorTools::compute_global_error(triangulation,
1478 * VectorTools::H1_seminorm);
1479 * std::cout << " Error in the H1 seminorm : " << error_norm
1485 * Now also compute an approximation to the @f$H^2@f$ seminorm error. The actual
1486 * @f$H^2@f$ seminorm would require us to integrate second derivatives of the
1487 * solution @f$u_h@f$, but given the Lagrange shape functions we use, @f$u_h@f$ of
1488 * course has kinks at the interfaces between cells, and consequently second
1489 * derivatives are singular at interfaces. As a consequence, we really only
1490 * integrate over the interior of cells and ignore the interface
1491 * contributions. This is *not* an equivalent norm to the energy norm for
1492 * the problem, but still gives us an idea of how fast the error converges.
1496 * We note that one could address this issue by defining a norm that
1497 * is equivalent to the energy norm. This would involve adding up not
1498 * only the integrals over cell interiors as we do below, but also adding
1499 * penalty terms for the jump of the derivative of @f$u_h@f$ across interfaces,
1500 * with an appropriate scaling of the two kinds of terms. We will leave
1501 * this for later work.
1505 * const QGauss<dim> quadrature_formula(fe.degree + 2);
1506 * ExactSolution::Solution<dim> exact_solution;
1507 * Vector<double> error_per_cell(triangulation.n_active_cells());
1509 * FEValues<dim> fe_values(mapping,
1511 * quadrature_formula,
1512 * update_values | update_hessians |
1513 * update_quadrature_points | update_JxW_values);
1515 * const FEValuesExtractors::Scalar scalar(0);
1516 * const unsigned int n_q_points = quadrature_formula.size();
1518 * std::vector<SymmetricTensor<2, dim>> exact_hessians(n_q_points);
1519 * std::vector<Tensor<2, dim>> hessians(n_q_points);
1520 * for (auto &cell : dof_handler.active_cell_iterators())
1522 * fe_values.reinit(cell);
1523 * fe_values[scalar].get_function_hessians(solution, hessians);
1524 * exact_solution.hessian_list(fe_values.get_quadrature_points(),
1527 * double local_error = 0;
1528 * for (unsigned int q_point = 0; q_point < n_q_points; ++q_point)
1531 * ((exact_hessians[q_point] - hessians[q_point]).norm_square() *
1532 * fe_values.JxW(q_point));
1534 * error_per_cell[cell->active_cell_index()] = std::sqrt(local_error);
1537 * const double error_norm =
1538 * VectorTools::compute_global_error(triangulation,
1540 * VectorTools::L2_norm);
1541 * std::cout << " Error in the broken H2 seminorm: " << error_norm
1550 * Equally uninteresting is the function that generates graphical output.
1551 * It looks exactly like the one in @ref step_6 "step-6", for example.
1554 * template <int dim>
1556 * BiharmonicProblem<dim>::output_results(const unsigned int iteration) const
1558 * std::cout << " Writing graphical output..." << std::endl;
1560 * DataOut<dim> data_out;
1562 * data_out.attach_dof_handler(dof_handler);
1563 * data_out.add_data_vector(solution, "solution");
1564 * data_out.build_patches();
1566 * const std::string filename =
1567 * ("output_" + Utilities::int_to_string(iteration, 6) + ".vtu");
1568 * std::ofstream output_vtu(filename);
1569 * data_out.write_vtu(output_vtu);
1576 * The same is true for the `run()` function: Just like in previous
1580 * template <int dim>
1581 * void BiharmonicProblem<dim>::run()
1585 * const unsigned int n_cycles = 4;
1586 * for (unsigned int cycle = 0; cycle < n_cycles; ++cycle)
1588 * std::cout << "Cycle " << cycle << " of " << n_cycles << std::endl;
1590 * triangulation.refine_global(1);
1593 * assemble_system();
1596 * output_results(cycle);
1599 * std::cout << std::endl;
1602 * } // namespace Step47
1609 * <a name="step_47-Themainfunction"></a>
1610 * <h3>The main() function</h3>
1614 * Finally for the `main()` function. There is, again, not very much to see
1615 * here: It looks like the ones in previous tutorial programs. There
1616 * is a variable that allows selecting the polynomial degree of the element
1617 * we want to use for solving the equation. Because the C0IP formulation
1618 * we use requires the element degree to be at least two, we check with
1619 * an assertion that whatever one sets for the polynomial degree actually
1627 * using namespace dealii;
1628 * using namespace Step47;
1630 * const unsigned int fe_degree = 2;
1631 * Assert(fe_degree >= 2,
1632 * ExcMessage("The C0IP formulation for the biharmonic problem "
1633 * "only works if one uses elements of polynomial "
1634 * "degree at least 2."));
1636 * BiharmonicProblem<2> biharmonic_problem(fe_degree);
1637 * biharmonic_problem.run();
1639 * catch (std::exception &exc)
1641 * std::cerr << std::endl
1643 * << "----------------------------------------------------"
1645 * std::cerr << "Exception on processing: " << std::endl
1646 * << exc.what() << std::endl
1647 * << "Aborting!" << std::endl
1648 * << "----------------------------------------------------"
1655 * std::cerr << std::endl
1657 * << "----------------------------------------------------"
1659 * std::cerr << "Unknown exception!" << std::endl
1660 * << "Aborting!" << std::endl
1661 * << "----------------------------------------------------"
1669<a name="step_47-Results"></a><h1>Results</h1>
1672We run the program with right hand side and boundary values as
1673discussed in the introduction. These will produce the
1674solution @f$u = \sin(\pi x) \sin(\pi y)@f$ on the domain @f$\Omega = (0,1)^2@f$.
1675We test this setup using @f$Q_2@f$, @f$Q_3@f$, and @f$Q_4@f$ elements, which one can
1676change via the `fe_degree` variable in the `main()` function. With mesh
1677refinement, the @f$L_2@f$ convergence rates, @f$H^1@f$-seminorm rate,
1678and @f$H^2@f$-seminorm convergence of @f$u@f$
1679should then be around 2, 2, 1 for @f$Q_2@f$ (with the @f$L_2@f$ norm
1680sub-optimal as discussed in the introduction); 4, 3, 2 for
1681@f$Q_3@f$; and 5, 4, 3 for @f$Q_4@f$, respectively.
1683From the literature, it is not immediately clear what
1684the penalty parameter @f$\gamma@f$ should be. For example,
1685@cite Brenner2010 state that it needs to be larger than one, and
1686choose @f$\gamma=5@f$. The FEniCS/Dolphin tutorial chooses it as
1688https://fenicsproject.org/docs/dolfin/1.6.0/python/demo/documented/biharmonic/python/documentation.html
1689. @cite Wells2007 uses a value for @f$\gamma@f$ larger than the
1690number of edges belonging to an element for Kirchhoff plates (see
1691their Section 4.2). This suggests that maybe
1692@f$\gamma = 1@f$, @f$2@f$, are too small; on the other hand, a value
1693@f$p(p+1)@f$ would be reasonable,
1694where @f$p@f$ is the degree of polynomials. The last of these choices is
1695the one one would expect to work by comparing
1696to the discontinuous Galerkin formulations for the Laplace equation
1697(see, for example, the discussions in @ref step_39 "step-39" and @ref step_74 "step-74"),
1698and it will turn out to also work here.
1699But we should check what value of @f$\gamma@f$ is right, and we will do so
1700below; changing @f$\gamma@f$ is easy in the two `face_worker` and
1701`boundary_worker` functions defined in `assemble_system()`.
1704<a name="step_47-TestresultsoniQsub2subiwithigammapp1i"></a><h3>Test results on <i>Q<sub>2</sub></i> with <i>γ = p(p+1)</i> </h3>
1707We run the code with differently refined meshes
1708and get the following convergence rates.
1710<table align="center" class="doxtable">
1712 <th>Number of refinements </th><th> @f$\|u-u_h\|_{L_2}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|_{H^1}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|^\circ_{H^2}@f$ </th><th> Conv. rates </th>
1715 <td> 2 </td><td> 8.780e-03 </td><td> </td><td> 7.095e-02 </td><td> </td><td> 1.645 </td><td> </td>
1718 <td> 3 </td><td> 3.515e-03 </td><td> 1.32 </td><td> 2.174e-02 </td><td> 1.70 </td><td> 8.121e-01 </td><td> 1.018 </td>
1721 <td> 4 </td><td> 1.103e-03 </td><td> 1.67 </td><td> 6.106e-03 </td><td> 1.83 </td><td> 4.015e-01 </td><td> 1.016 </td>
1724 <td> 5 </td><td> 3.084e-04 </td><td> 1.83 </td><td> 1.622e-03 </td><td> 1.91 </td><td> 1.993e-01 </td><td> 1.010 </td>
1727We can see that the @f$L_2@f$ convergence rates are around 2,
1728@f$H^1@f$-seminorm convergence rates are around 2,
1729and @f$H^2@f$-seminorm convergence rates are around 1. The latter two
1730match the theoretically expected rates; for the former, we have no
1731theorem but are not surprised that it is sub-optimal given the remark
1735<a name="step_47-TestresultsoniQsub3subiwithigammapp1i"></a><h3>Test results on <i>Q<sub>3</sub></i> with <i>γ = p(p+1)</i> </h3>
1739<table align="center" class="doxtable">
1741 <th>Number of refinements </th><th> @f$\|u-u_h\|_{L_2}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|_{H^1}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|^\circ_{H^2}@f$ </th><th> Conv. rates </th>
1744 <td> 2 </td><td> 2.045e-04 </td><td> </td><td> 4.402e-03 </td><td> </td><td> 1.641e-01 </td><td> </td>
1747 <td> 3 </td><td> 1.312e-05 </td><td> 3.96 </td><td> 5.537e-04 </td><td> 2.99 </td><td> 4.096e-02 </td><td> 2.00 </td>
1750 <td> 4 </td><td> 8.239e-07 </td><td> 3.99 </td><td> 6.904e-05 </td><td> 3.00 </td><td> 1.023e-02 </td><td> 2.00 </td>
1753 <td> 5 </td><td> 5.158e-08 </td><td> 3.99 </td><td> 8.621e-06 </td><td> 3.00 </td><td> 2.558e-03 </td><td> 2.00 </td>
1756We can see that the @f$L_2@f$ convergence rates are around 4,
1757@f$H^1@f$-seminorm convergence rates are around 3,
1758and @f$H^2@f$-seminorm convergence rates are around 2.
1759This, of course, matches our theoretical expectations.
1762<a name="step_47-TestresultsoniQsub4subiwithigammapp1i"></a><h3>Test results on <i>Q<sub>4</sub></i> with <i>γ = p(p+1)</i> </h3>
1765<table align="center" class="doxtable">
1767 <th>Number of refinements </th><th> @f$\|u-u_h\|_{L_2}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|_{H^1}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|^\circ_{H^2}@f$ </th><th> Conv. rates </th>
1770 <td> 2 </td><td> 6.510e-06 </td><td> </td><td> 2.215e-04 </td><td> </td><td> 1.275e-02 </td><td> </td>
1773 <td> 3 </td><td> 2.679e-07 </td><td> 4.60 </td><td> 1.569e-05 </td><td> 3.81 </td><td> 1.496e-03 </td><td> 3.09 </td>
1776 <td> 4 </td><td> 9.404e-09 </td><td> 4.83 </td><td> 1.040e-06 </td><td> 3.91 </td><td> 1.774e-04 </td><td> 3.07 </td>
1779 <td> 5 </td><td> 7.943e-10 </td><td> 3.56 </td><td> 6.693e-08 </td><td> 3.95 </td><td> 2.150e-05 </td><td> 3.04 </td>
1782We can see that the @f$L_2@f$ norm convergence rates are around 5,
1783@f$H^1@f$-seminorm convergence rates are around 4,
1784and @f$H^2@f$-seminorm convergence rates are around 3.
1785On the finest mesh, the @f$L_2@f$ norm convergence rate
1786is much smaller than our theoretical expectations
1787because the linear solver becomes the limiting factor due
1788to round-off. Of course the @f$L_2@f$ error is also very small already in
1792<a name="step_47-TestresultsoniQsub2subiwithigamma1i"></a><h3>Test results on <i>Q<sub>2</sub></i> with <i>γ = 1</i> </h3>
1795For comparison with the results above, let us now also consider the
1796case where we simply choose @f$\gamma=1@f$:
1798<table align="center" class="doxtable">
1800 <th>Number of refinements </th><th> @f$\|u-u_h\|_{L_2}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|_{H^1}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|^\circ_{H^2}@f$ </th><th> Conv. rates </th>
1803 <td> 2 </td><td> 7.350e-02 </td><td> </td><td> 7.323e-01 </td><td> </td><td> 10.343 </td><td> </td>
1806 <td> 3 </td><td> 6.798e-03 </td><td> 3.43 </td><td> 1.716e-01 </td><td> 2.09 </td><td>4.836 </td><td> 1.09 </td>
1809 <td> 4 </td><td> 9.669e-04 </td><td> 2.81 </td><td> 6.436e-02 </td><td> 1.41 </td><td> 3.590 </td><td> 0.430 </td>
1812 <td> 5 </td><td> 1.755e-04 </td><td> 2.46 </td><td> 2.831e-02 </td><td> 1.18 </td><td>3.144 </td><td> 0.19 </td>
1815Although @f$L_2@f$ norm convergence rates of @f$u@f$ more or less
1816follows the theoretical expectations,
1817the @f$H^1@f$-seminorm and @f$H^2@f$-seminorm do not seem to converge as expected.
1818Comparing results from @f$\gamma = 1@f$ and @f$\gamma = p(p+1)@f$, it is clear that
1819@f$\gamma = p(p+1)@f$ is a better penalty.
1820Given that @f$\gamma=1@f$ is already too small for @f$Q_2@f$ elements, it may not be surprising that if one repeated the
1821experiment with a @f$Q_3@f$ element, the results are even more disappointing: One again only obtains convergence
1822rates of 2, 1, zero -- i.e., no better than for the @f$Q_2@f$ element (although the errors are smaller in magnitude).
1823Maybe surprisingly, however, one obtains more or less the expected convergence orders when using @f$Q_4@f$
1824elements. Regardless, this uncertainty suggests that @f$\gamma=1@f$ is at best a risky choice, and at worst an
1825unreliable one and that we should choose @f$\gamma@f$ larger.
1828<a name="step_47-TestresultsoniQsub2subiwithigamma2i"></a><h3>Test results on <i>Q<sub>2</sub></i> with <i>γ = 2</i> </h3>
1831Since @f$\gamma=1@f$ is clearly too small, one might conjecture that
1832@f$\gamma=2@f$ might actually work better. Here is what one obtains in
1835<table align="center" class="doxtable">
1837 <th>Number of refinements </th><th> @f$\|u-u_h\|_{L_2}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|_{H^1}@f$ </th><th> Conv. rates </th><th> @f$|u-u_h|^\circ_{H^2}@f$ </th><th> Conv. rates </th>
1840 <td> 2 </td><td> 4.133e-02 </td><td> </td><td> 2.517e-01 </td><td> </td><td> 3.056 </td><td> </td>
1843 <td> 3 </td><td> 6.500e-03 </td><td>2.66 </td><td> 5.916e-02 </td><td> 2.08 </td><td>1.444 </td><td> 1.08 </td>
1846 <td> 4 </td><td> 6.780e-04 </td><td> 3.26 </td><td> 1.203e-02 </td><td> 2.296 </td><td> 6.151e-01 </td><td> 1.231 </td>
1849 <td> 5 </td><td> 1.622e-04 </td><td> 2.06 </td><td> 2.448e-03 </td><td> 2.297 </td><td> 2.618e-01 </td><td> 1.232 </td>
1852In this case, the convergence rates more or less follow the
1853theoretical expectations, but, compared to the results from @f$\gamma =
1854p(p+1)@f$, are more variable.
1855Again, we could repeat this kind of experiment for @f$Q_3@f$ and @f$Q_4@f$ elements. In both cases, we will find that we
1856obtain roughly the expected convergence rates. Of more interest may then be to compare the absolute
1857size of the errors. While in the table above, for the @f$Q_2@f$ case, the errors on the finest grid are comparable between
1858the @f$\gamma=p(p+1)@f$ and @f$\gamma=2@f$ case, for @f$Q_3@f$ the errors are substantially larger for @f$\gamma=2@f$ than for
1859@f$\gamma=p(p+1)@f$. The same is true for the @f$Q_4@f$ case.
1862<a name="step_47-Conclusionsforthechoiceofthepenaltyparameter"></a><h3> Conclusions for the choice of the penalty parameter </h3>
1865The conclusions for which of the "reasonable" choices one should use for the penalty parameter
1866is that @f$\gamma=p(p+1)@f$ yields the expected results. It is, consequently, what the code
1867uses as currently written.
1870<a name="step_47-Possibilitiesforextensions"></a><h3> Possibilities for extensions </h3>
1873There are a number of obvious extensions to this program that would
1876- The program uses a square domain and a uniform mesh. Real problems
1877 don't come
this way, and one should verify convergence also on
1878 domains with other shapes and, in particular, curved boundaries. One
1879 may also be interested in resolving areas of less regularity by
1880 using adaptive mesh refinement.
1882- From a more theoretical perspective, the convergence results above
1883 only used the
"broken" @f$H^2@f$ seminorm @f$|\cdot|^\circ_{H^2}@f$ instead
1884 of the
"equivalent" norm @f$|\cdot|_h@f$. This is good enough to
1885 convince ourselves that the program isn
't fundamentally
1886 broken. However, it might be interesting to measure the error in the
1887 actual norm for which we have theoretical results. Implementing this
1888 addition should not be overly difficult using, for example, the
1889 FEInterfaceValues class combined with MeshWorker::mesh_loop() in the
1890 same spirit as we used for the assembly of the linear system.
1893<a name="step_47-Derivationforthesimplysupportedplates"></a> <h4> Derivation for the simply supported plates </h4>
1896 Similar to the "clamped" boundary condition addressed in the implementation,
1897 we will derive the @f$C^0@f$ IP finite element scheme for simply supported plates:
1899 \Delta^2 u(\mathbf x) &= f(\mathbf x)
1900 \qquad \qquad &&\forall \mathbf x \in \Omega,
1901 u(\mathbf x) &= g(\mathbf x) \qquad \qquad
1902 &&\forall \mathbf x \in \partial\Omega, \\
1903 \Delta u(\mathbf x) &= h(\mathbf x) \qquad \qquad
1904 &&\forall \mathbf x \in \partial\Omega.
1906 We multiply the biharmonic equation by the test function @f$v_h@f$ and integrate over @f$ K @f$ and get:
1908 \int_K v_h (\Delta^2 u_h)
1909 &= \int_K (D^2 v_h) : (D^2 u_h)
1910 + \int_{\partial K} v_h \frac{\partial (\Delta u_h)}{\partial \mathbf{n}}
1911 -\int_{\partial K} (\nabla v_h) \cdot (\frac{\partial \nabla u_h}{\partial \mathbf{n}}).
1914 Summing up over all cells @f$K \in \mathbb{T}@f$,since normal directions of @f$\Delta u_h@f$ are pointing at
1915 opposite directions on each interior edge shared by two cells and @f$v_h = 0@f$ on @f$\partial \Omega@f$,
1917 \sum_{K \in \mathbb{T}} \int_{\partial K} v_h \frac{\partial (\Delta u_h)}{\partial \mathbf{n}} = 0,
1919 and by the definition of jump over cell interfaces,
1921 -\sum_{K \in \mathbb{T}} \int_{\partial K} (\nabla v_h) \cdot (\frac{\partial \nabla u_h}{\partial \mathbf{n}}) = -\sum_{e \in \mathbb{F}} \int_{e} \jump{\frac{\partial v_h}{\partial \mathbf{n}}} (\frac{\partial^2 u_h}{\partial \mathbf{n^2}}).
1923 We separate interior faces and boundary faces of the domain,
1925 -\sum_{K \in \mathbb{T}} \int_{\partial K} (\nabla v_h) \cdot (\frac{\partial \nabla u_h}{\partial \mathbf{n}}) = -\sum_{e \in \mathbb{F}^i} \int_{e} \jump{\frac{\partial v_h}{\partial \mathbf{n}}} (\frac{\partial^2 u_h}{\partial \mathbf{n^2}})
1926 - \sum_{e \in \partial \Omega} \int_{e} \jump{\frac{\partial v_h}{\partial \mathbf{n}}} h,
1928 where @f$\mathbb{F}^i@f$ is the set of interior faces.
1931 \sum_{K \in \mathbb{T}} \int_K (D^2 v_h) : (D^2 u_h) \ dx - \sum_{e \in \mathbb{F}^i} \int_{e} \jump{\frac{\partial v_h}{\partial \mathbf{n}}} (\frac{\partial^2 u_h}{\partial \mathbf{n^2}}) \ ds
1932 = \sum_{K \in \mathbb{T}}\int_{K} v_h f \ dx + \sum_{e\subset\partial\Omega} \int_{e} \jump{\frac{\partial v_h}{\partial \mathbf{n}}} h \ ds.
1935 In order to symmetrize and stabilize the discrete problem,
1936 we add symmetrization and stabilization term.
1937 We finally get the @f$C^0@f$ IP finite element scheme for the biharmonic equation:
1938 find @f$u_h@f$ such that @f$u_h =g@f$ on @f$\partial \Omega@f$ and
1940 \mathcal{A}(v_h,u_h)&=\mathcal{F}(v_h) \quad \text{holds for all test functions } v_h,
1944 \mathcal{A}(v_h,u_h):=&\sum_{K \in \mathbb{T}}\int_K D^2v_h:D^2u_h \ dx
1947 -\sum_{e \in \mathbb{F}^i} \int_{e}
1948 \jump{\frac{\partial v_h}{\partial \mathbf n}}
1949 \average{\frac{\partial^2 u_h}{\partial \mathbf n^2}} \ ds
1950 -\sum_{e \in \mathbb{F}^i} \int_{e}
1951 \average{\frac{\partial^2 v_h}{\partial \mathbf n^2}}
1952 \jump{\frac{\partial u_h}{\partial \mathbf n}} \ ds
1954 &+ \sum_{e \in \mathbb{F}^i}
1957 \jump{\frac{\partial v_h}{\partial \mathbf n}}
1958 \jump{\frac{\partial u_h}{\partial \mathbf n}} \ ds,
1962 \mathcal{F}(v_h)&:=\sum_{K \in \mathbb{T}}\int_{K} v_h f \ dx
1964 \sum_{e\subset\partial\Omega}
1965 \int_e \jump{\frac{\partial v_h}{\partial \mathbf n}} h \ ds.
1967 The implementation of this boundary case is similar to the "clamped" version
1968 except that `boundary_worker` is no longer needed for system assembling
1969 and the right hand side is changed according to the formulation.
1972<a name="step_47-PlainProg"></a>
1973<h1> The plain program</h1>
1974@include "step-47.cc"
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
void make_hanging_node_constraints(const DoFHandler< dim, spacedim > &dof_handler, AffineConstraints< number > &constraints)
void make_flux_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern)
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
double norm(const FEValuesBase< dim > &fe, const ArrayView< const std::vector< Tensor< 1, dim > > > &Du)
void run(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length, const unsigned int chunk_size)
int(&) functions(const void *v1, const void *v2)
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation