612 *
class BoundaryValues :
public Function<dim>
616 * std::vector<double> &
values,
617 *
const unsigned int = 0) const override
622 *
for (
unsigned int i = 0; i <
values.size(); ++i)
624 *
if (points[i](0) < 0.5)
639 * The flow field is chosen to be a quarter circle with counterclockwise
640 * flow direction and with the origin as midpoint
for the right half of the
641 * domain with positive @f$x@f$
values, whereas the flow simply goes to the left
642 * in the left part of the domain at a velocity that matches the
one coming
643 * in from the right. In the circular part the magnitude of the flow
644 * velocity is proportional to the distance from the origin. This is a
645 * difference to @ref step_12
"step-12", where the magnitude was 1 everywhere. the
new
646 * definition leads to a linear variation of @f$\beta@f$ along each given face
647 * of a cell. On the other hand, the solution @f$u(x,y)@f$ is exactly the same
651 *
void value_list(
const std::vector<
Point<dim>> &points,
657 *
for (
unsigned int i = 0; i < points.size(); ++i)
659 *
if (points[i](0) > 0)
661 *
values[i](0) = -points[i](1);
662 *
values[i](1) = points[i](0);
667 *
values[i](0) = -points[i](1);
678 * <a name=
"ClassDGTransportEquation"></a>
679 * <h3>Class: DGTransportEquation</h3>
683 * This declaration of
this class is utterly unaffected by our current
688 *
class DGTransportEquation
691 * DGTransportEquation();
709 *
const Beta<dim> beta_function;
710 *
const RHS<dim> rhs_function;
711 *
const BoundaryValues<dim> boundary_function;
718 * Likewise, the constructor of the
class as well as the
functions
719 * assembling the terms corresponding to cell interiors and boundary faces
720 * are unchanged from before. The function that assembles face terms between
721 * cells also did not change because all it does is operate on two objects
723 * and
FESubfaceValues). Where these objects come from, i.e. how they are
724 * initialized, is of no concern to
this function: it simply assumes that
725 * the quadrature points on faces or subfaces represented by the two objects
726 * correspond to the same points in physical space.
730 * DGTransportEquation<dim>::DGTransportEquation()
733 * , boundary_function()
739 *
void DGTransportEquation<dim>::assemble_cell_term(
746 * std::vector<Point<dim>> beta(fe_v.n_quadrature_points);
747 * std::vector<double> rhs(fe_v.n_quadrature_points);
749 * beta_function.value_list(fe_v.get_quadrature_points(), beta);
750 * rhs_function.value_list(fe_v.get_quadrature_points(), rhs);
752 *
for (
unsigned int point = 0;
point < fe_v.n_quadrature_points; ++
point)
753 *
for (
unsigned int i = 0; i < fe_v.dofs_per_cell; ++i)
755 *
for (
unsigned int j = 0; j < fe_v.dofs_per_cell; ++j)
756 * ui_vi_matrix(i, j) -= beta[
point] * fe_v.shape_grad(i,
point) *
766 *
void DGTransportEquation<dim>::assemble_boundary_term(
771 *
const std::vector<double> & JxW = fe_v.get_JxW_values();
772 *
const std::vector<Tensor<1, dim>> &normals = fe_v.get_normal_vectors();
774 * std::vector<Point<dim>> beta(fe_v.n_quadrature_points);
775 * std::vector<double> g(fe_v.n_quadrature_points);
777 * beta_function.value_list(fe_v.get_quadrature_points(), beta);
778 * boundary_function.value_list(fe_v.get_quadrature_points(), g);
780 *
for (
unsigned int point = 0;
point < fe_v.n_quadrature_points; ++
point)
782 *
const double beta_n = beta[
point] * normals[
point];
784 *
for (
unsigned int i = 0; i < fe_v.dofs_per_cell; ++i)
785 *
for (
unsigned int j = 0; j < fe_v.dofs_per_cell; ++j)
786 * ui_vi_matrix(i, j) += beta_n * fe_v.shape_value(j,
point) *
789 *
for (
unsigned int i = 0; i < fe_v.dofs_per_cell; ++i)
797 *
void DGTransportEquation<dim>::assemble_face_term(
805 *
const std::vector<double> & JxW = fe_v.get_JxW_values();
806 *
const std::vector<Tensor<1, dim>> &normals = fe_v.get_normal_vectors();
808 * std::vector<Point<dim>> beta(fe_v.n_quadrature_points);
810 * beta_function.value_list(fe_v.get_quadrature_points(), beta);
812 *
for (
unsigned int point = 0;
point < fe_v.n_quadrature_points; ++
point)
814 *
const double beta_n = beta[
point] * normals[
point];
817 *
for (
unsigned int i = 0; i < fe_v.dofs_per_cell; ++i)
818 *
for (
unsigned int j = 0; j < fe_v.dofs_per_cell; ++j)
819 * ui_vi_matrix(i, j) += beta_n * fe_v.shape_value(j,
point) *
822 *
for (
unsigned int k = 0; k < fe_v_neighbor.dofs_per_cell; ++k)
823 *
for (
unsigned int j = 0; j < fe_v.dofs_per_cell; ++j)
824 * ui_ve_matrix(k, j) -= beta_n * fe_v.shape_value(j,
point) *
825 * fe_v_neighbor.shape_value(k,
point) *
830 *
for (
unsigned int i = 0; i < fe_v.dofs_per_cell; ++i)
831 *
for (
unsigned int l = 0;
l < fe_v_neighbor.dofs_per_cell; ++
l)
832 * ue_vi_matrix(i,
l) += beta_n *
833 * fe_v_neighbor.shape_value(
l,
point) *
836 *
for (
unsigned int k = 0; k < fe_v_neighbor.dofs_per_cell; ++k)
837 *
for (
unsigned int l = 0;
l < fe_v_neighbor.dofs_per_cell; ++
l)
838 * ue_ve_matrix(k,
l) -=
839 * beta_n * fe_v_neighbor.shape_value(
l,
point) *
840 * fe_v_neighbor.shape_value(k,
point) * JxW[
point];
849 * <a name=
"ClassDGMethod"></a>
850 * <h3>Class: DGMethod</h3>
854 * This declaration is much like that of @ref step_12
"step-12". However, we introduce a
855 *
new routine (set_anisotropic_flags) and modify another
one (refine_grid).
862 * DGMethod(
const bool anisotropic);
867 *
void setup_system();
868 *
void assemble_system();
870 *
void refine_grid();
871 *
void set_anisotropic_flags();
872 *
void output_results(
const unsigned int cycle)
const;
878 * Again we want to use DG elements of degree 1 (but
this is only
879 * specified in the constructor). If you want to use a DG method of a
880 * different degree replace 1 in the constructor by the
new degree.
883 *
const unsigned int degree;
891 * This is
new, the threshold value used in the evaluation of the
892 * anisotropic jump indicator explained in the introduction. Its value is
893 *
set to 3.0 in the constructor, but it can easily be changed to a
894 * different value greater than 1.
897 *
const double anisotropic_threshold_ratio;
900 * This is a
bool flag indicating whether anisotropic refinement shall be
901 * used or not. It is
set by the constructor, which takes an argument of
905 *
const bool anisotropic;
913 *
const DGTransportEquation<dim> dg;
918 * DGMethod<dim>::DGMethod(
const bool anisotropic)
923 * Change here
for DG methods of different degrees.
929 * , anisotropic_threshold_ratio(3.)
930 * , anisotropic(anisotropic)
934 * As beta is a linear function, we can choose the degree of the
935 * quadrature
for which the resulting integration is correct. Thus, we
936 * choose to use <code>degree+1</code> Gauss points, which enables us to
937 * integrate exactly polynomials of degree <code>2*degree+1</code>, enough
938 *
for all the integrals we will perform in
this program.
941 * quadrature(degree + 1)
942 * , face_quadrature(degree + 1)
949 *
void DGMethod<dim>::setup_system()
951 * dof_handler.distribute_dofs(fe);
952 * sparsity_pattern.
reinit(dof_handler.n_dofs(),
953 * dof_handler.n_dofs(),
957 * fe.n_dofs_per_cell());
961 * sparsity_pattern.compress();
963 * system_matrix.reinit(sparsity_pattern);
965 * solution2.reinit(dof_handler.n_dofs());
966 * right_hand_side.reinit(dof_handler.n_dofs());
973 * <a name=
"Functionassemble_system"></a>
974 * <h4>
Function: assemble_system</h4>
978 * We proceed with the <code>assemble_system</code> function that implements
979 * the DG discretization. This function does the same thing as the
980 * <code>assemble_system</code> function from @ref step_12
"step-12" (but without
981 *
MeshWorker). The four cases considered
for the neighbor-relations of a
982 * cell are the same as the isotropic
case, namely a) cell is at the
983 * boundary,
b) there are finer neighboring cells, c) the neighbor is
984 * neither coarser nor finer and
d) the neighbor is coarser. However, the
985 * way in which we decide upon which
case we have are modified in the way
986 * described in the introduction.
990 *
void DGMethod<dim>::assemble_system()
992 *
const unsigned int dofs_per_cell = dof_handler.get_fe().n_dofs_per_cell();
993 * std::vector<types::global_dof_index> dofs(dofs_per_cell);
994 * std::vector<types::global_dof_index> dofs_neighbor(dofs_per_cell);
1006 *
FEValues<dim> fe_v(mapping, fe, quadrature, update_flags);
1010 * face_update_flags);
1014 * face_update_flags);
1018 * neighbor_face_update_flags);
1029 *
for (
const auto &cell : dof_handler.active_cell_iterators())
1034 * fe_v.reinit(cell);
1036 * dg.assemble_cell_term(fe_v, ui_vi_matrix, cell_vector);
1038 * cell->get_dof_indices(dofs);
1040 *
for (
const auto face_no : cell->face_indices())
1042 *
const auto face = cell->face(face_no);
1046 * Case (a): The face is at the boundary.
1049 * if (face->at_boundary())
1051 * fe_v_face.reinit(cell, face_no);
1053 * dg.assemble_boundary_term(fe_v_face, ui_vi_matrix, cell_vector);
1059 *
const auto neighbor = cell->neighbor(face_no);
1063 * Case (
b): This is an
internal face and the neighbor
1064 * is refined (which we can test by asking whether the
1065 * face of the current cell has children). In this
1066 * case, we will need to integrate over the
1067 *
"sub-faces", i.
e., the children of the face of the
1072 * (There is a slightly confusing corner case: If we
1073 * are in 1
d -- where admittedly the current program
1074 * and its demonstration of anisotropic refinement is
1075 * not particularly relevant -- then the faces between
1076 * cells are
always the same: they are just
1077 *
vertices. In other words, in 1
d, we do not want to
1078 * treat faces between cells of different
level
1079 * differently. The condition `face->has_children()`
1080 * we check here ensures this: in 1
d, this function
1081 *
always returns `false`, and consequently in 1
d we
1082 * will not ever go into this `if` branch. But we will
1083 * have to come back to this corner case below in case
1087 * if (face->has_children())
1091 * We need to know, which of the neighbors faces points in
1092 * the direction of our cell. Using the @p
1093 * neighbor_face_no function we get
this information
for
1094 * both coarser and non-coarser neighbors.
1097 *
const unsigned int neighbor2 =
1098 * cell->neighbor_face_no(face_no);
1102 * Now we
loop over all subfaces, i.e. the children and
1103 * possibly grandchildren of the current face.
1106 *
for (
unsigned int subface_no = 0;
1107 * subface_no < face->n_active_descendants();
1112 * To get the cell behind the current subface we can
1113 * use the @p neighbor_child_on_subface function. it
1114 * takes care of all the complicated situations of
1115 * anisotropic refinement and non-standard faces.
1118 *
const auto neighbor_child =
1119 * cell->neighbor_child_on_subface(face_no, subface_no);
1120 *
Assert(!neighbor_child->has_children(),
1125 * The remaining part of
this case is unchanged.
1132 * fe_v_subface.reinit(cell, face_no, subface_no);
1133 * fe_v_face_neighbor.reinit(neighbor_child, neighbor2);
1135 * dg.assemble_face_term(fe_v_subface,
1136 * fe_v_face_neighbor,
1142 * neighbor_child->get_dof_indices(dofs_neighbor);
1144 *
for (
unsigned int i = 0; i < dofs_per_cell; ++i)
1145 *
for (
unsigned int j = 0; j < dofs_per_cell; ++j)
1147 * system_matrix.add(dofs[i],
1149 * ue_vi_matrix(i, j));
1150 * system_matrix.add(dofs_neighbor[i],
1152 * ui_ve_matrix(i, j));
1153 * system_matrix.add(dofs_neighbor[i],
1155 * ue_ve_matrix(i, j));
1163 * Case (c). We get here
if this is an
internal
1164 * face and
if the neighbor is not further refined
1165 * (or, as mentioned above, we are in 1
d in which
1166 *
case we get here
for every
internal face). We
1167 * then need to decide whether we want to
1168 * integrate over the current face. If the
1169 * neighbor is in fact coarser, then we ignore the
1170 * face and instead handle it when we visit the
1171 * neighboring cell and look at the current face
1172 * (except in 1
d, where as mentioned above
this is
1176 *
if (dim > 1 && cell->neighbor_is_coarser(face_no))
1181 * On the other hand,
if the neighbor is more
1182 * refined, then we have already handled the face
1183 * in
case (
b) above (except in 1
d). So
for 2
d and
1184 * 3
d, we just have to decide whether we want to
1185 * handle a face between cells at the same
level
1186 * from the current side or from the neighboring
1187 * side. We
do this by introducing a tie-breaker:
1188 * We
'll just take the cell with the smaller index
1189 * (within the current refinement level). In 1d,
1190 * we take either the coarser cell, or if they are
1191 * on the same level, the one with the smaller
1192 * index within that level. This leads to a
1193 * complicated condition that, hopefully, makes
1194 * sense given the description above:
1197 * if (((dim > 1) && (cell->index() < neighbor->index())) ||
1198 * ((dim == 1) && ((cell->level() < neighbor->level()) ||
1199 * ((cell->level() == neighbor->level()) &&
1200 * (cell->index() < neighbor->index())))))
1204 * Here we know, that the neighbor is not coarser so we
1205 * can use the usual @p neighbor_of_neighbor
1206 * function. However, we could also use the more
1207 * general @p neighbor_face_no function.
1210 * const unsigned int neighbor2 =
1211 * cell->neighbor_of_neighbor(face_no);
1217 * fe_v_face.reinit(cell, face_no);
1218 * fe_v_face_neighbor.reinit(neighbor, neighbor2);
1220 * dg.assemble_face_term(fe_v_face,
1221 * fe_v_face_neighbor,
1227 * neighbor->get_dof_indices(dofs_neighbor);
1229 * for (unsigned int i = 0; i < dofs_per_cell; ++i)
1230 * for (unsigned int j = 0; j < dofs_per_cell; ++j)
1232 * system_matrix.add(dofs[i],
1234 * ue_vi_matrix(i, j));
1235 * system_matrix.add(dofs_neighbor[i],
1237 * ui_ve_matrix(i, j));
1238 * system_matrix.add(dofs_neighbor[i],
1240 * ue_ve_matrix(i, j));
1246 * We do not need to consider a case (d), as those
1247 * faces are treated 'from the other side within
1255 *
for (
unsigned int i = 0; i < dofs_per_cell; ++i)
1256 *
for (
unsigned int j = 0; j < dofs_per_cell; ++j)
1257 * system_matrix.add(dofs[i], dofs[j], ui_vi_matrix(i, j));
1259 *
for (
unsigned int i = 0; i < dofs_per_cell; ++i)
1260 * right_hand_side(dofs[i]) += cell_vector(i);
1268 * <a name=
"Solver"></a>
1273 * For
this simple problem we use the simple Richardson iteration again. The
1274 * solver is completely unaffected by our anisotropic changes.
1277 *
template <
int dim>
1285 * preconditioner.
initialize(system_matrix, fe.n_dofs_per_cell());
1287 * solver.solve(system_matrix, solution, right_hand_side, preconditioner);
1294 * <a name=
"Refinement"></a>
1295 * <h3>Refinement</h3>
1299 * We
refine the grid according to the same simple refinement criterion used
1300 * in @ref step_12
"step-12", namely an approximation to the
gradient of the solution.
1303 *
template <
int dim>
1304 *
void DGMethod<dim>::refine_grid()
1316 * gradient_indicator);
1320 * and
scale it to obtain an error indicator.
1323 *
for (
const auto &cell :
triangulation.active_cell_iterators())
1324 * gradient_indicator[cell->active_cell_index()] *=
1325 *
std::pow(cell->diameter(), 1 + 1.0 * dim / 2);
1328 * Then we use
this indicator to flag the 30 percent of the cells with
1329 * highest error indicator to be refined.
1333 * gradient_indicator,
1338 * Now the refinement flags are
set for those cells with a large error
1339 * indicator. If
nothing is done to change
this, those cells will be
1340 * refined isotropically. If the @p anisotropic flag given to
this
1341 * function is
set, we now
call the set_anisotropic_flags() function,
1342 * which uses the jump indicator to reset some of the refinement flags to
1343 * anisotropic refinement.
1347 * set_anisotropic_flags();
1350 * Now execute the refinement considering anisotropic as well as isotropic
1359 * Once an error indicator has been evaluated and the cells with largest
1360 * error are flagged for refinement we want to
loop over the flagged cells
1361 * again to decide whether they need isotropic refinement or whether
1362 * anisotropic refinement is more appropriate. This is the anisotropic jump
1363 * indicator explained in the introduction.
1366 * template <
int dim>
1367 *
void DGMethod<dim>::set_anisotropic_flags()
1371 * We want to evaluate the jump over faces of the flagged cells, so we
1372 * need some objects to evaluate
values of the solution on faces.
1381 * face_update_flags);
1385 * face_update_flags);
1393 * Now we need to
loop over all active cells.
1396 *
for (
const auto &cell : dof_handler.active_cell_iterators())
1399 * We only need to consider cells which are flagged
for refinement.
1402 *
if (cell->refine_flag_set())
1407 *
for (
const auto face_no : cell->face_indices())
1409 *
const auto face = cell->face(face_no);
1411 *
if (!face->at_boundary())
1413 *
Assert(cell->neighbor(face_no).state() ==
1416 *
const auto neighbor = cell->neighbor(face_no);
1418 * std::vector<double> u(fe_v_face.n_quadrature_points);
1419 * std::vector<double> u_neighbor(fe_v_face.n_quadrature_points);
1423 * The four cases of different neighbor relations seen in
1424 * the assembly routines are repeated much in the same way
1428 *
if (face->has_children())
1432 * The neighbor is refined. First we store the
1433 * information, which of the neighbor
's faces points in
1434 * the direction of our current cell. This property is
1435 * inherited to the children.
1438 * unsigned int neighbor2 = cell->neighbor_face_no(face_no);
1441 * Now we loop over all subfaces,
1444 * for (unsigned int subface_no = 0;
1445 * subface_no < face->n_active_descendants();
1450 * get an iterator pointing to the cell behind the
1451 * present subface...
1454 * const auto neighbor_child =
1455 * cell->neighbor_child_on_subface(face_no,
1457 * Assert(!neighbor_child->has_children(),
1458 * ExcInternalError());
1461 * ... and reinit the respective FEFaceValues and
1462 * FESubFaceValues objects.
1465 * fe_v_subface.reinit(cell, face_no, subface_no);
1466 * fe_v_face_neighbor.reinit(neighbor_child, neighbor2);
1469 * We obtain the function values
1472 * fe_v_subface.get_function_values(solution2, u);
1473 * fe_v_face_neighbor.get_function_values(solution2,
1477 * as well as the quadrature weights, multiplied by
1478 * the Jacobian determinant.
1481 * const std::vector<double> &JxW =
1482 * fe_v_subface.get_JxW_values();
1485 * Now we loop over all quadrature points
1488 * for (unsigned int x = 0;
1489 * x < fe_v_subface.n_quadrature_points;
1494 * and integrate the absolute value of the jump
1495 * of the solution, i.e. the absolute value of
1496 * the difference between the function value
1497 * seen from the current cell and the
1498 * neighboring cell, respectively. We know, that
1499 * the first two faces are orthogonal to the
1500 * first coordinate direction on the unit cell,
1501 * the second two faces are orthogonal to the
1502 * second coordinate direction and so on, so we
1503 * accumulate these values into vectors with
1504 * <code>dim</code> components.
1507 * jump[face_no / 2] +=
1508 * std::abs(u[x] - u_neighbor[x]) * JxW[x];
1511 * We also sum up the scaled weights to obtain
1512 * the measure of the face.
1515 * area[face_no / 2] += JxW[x];
1521 * if (!cell->neighbor_is_coarser(face_no))
1525 * Our current cell and the neighbor have the same
1526 * refinement along the face under
1527 * consideration. Apart from that, we do much the
1528 * same as with one of the subcells in the above
1532 * unsigned int neighbor2 =
1533 * cell->neighbor_of_neighbor(face_no);
1535 * fe_v_face.reinit(cell, face_no);
1536 * fe_v_face_neighbor.reinit(neighbor, neighbor2);
1538 * fe_v_face.get_function_values(solution2, u);
1539 * fe_v_face_neighbor.get_function_values(solution2,
1542 * const std::vector<double> &JxW =
1543 * fe_v_face.get_JxW_values();
1545 * for (unsigned int x = 0;
1546 * x < fe_v_face.n_quadrature_points;
1549 * jump[face_no / 2] +=
1550 * std::abs(u[x] - u_neighbor[x]) * JxW[x];
1551 * area[face_no / 2] += JxW[x];
1554 * else // i.e. neighbor is coarser than cell
1558 * Now the neighbor is actually coarser. This case
1559 * is new, in that it did not occur in the assembly
1560 * routine. Here, we have to consider it, but this
1561 * is not overly complicated. We simply use the @p
1562 * neighbor_of_coarser_neighbor function, which
1563 * again takes care of anisotropic refinement and
1564 * non-standard face orientation by itself.
1567 * std::pair<unsigned int, unsigned int>
1568 * neighbor_face_subface =
1569 * cell->neighbor_of_coarser_neighbor(face_no);
1570 * Assert(neighbor_face_subface.first < cell->n_faces(),
1571 * ExcInternalError());
1572 * Assert(neighbor_face_subface.second <
1573 * neighbor->face(neighbor_face_subface.first)
1574 * ->n_active_descendants(),
1575 * ExcInternalError());
1576 * Assert(neighbor->neighbor_child_on_subface(
1577 * neighbor_face_subface.first,
1578 * neighbor_face_subface.second) == cell,
1579 * ExcInternalError());
1581 * fe_v_face.reinit(cell, face_no);
1582 * fe_v_subface.reinit(neighbor,
1583 * neighbor_face_subface.first,
1584 * neighbor_face_subface.second);
1586 * fe_v_face.get_function_values(solution2, u);
1587 * fe_v_subface.get_function_values(solution2,
1590 * const std::vector<double> &JxW =
1591 * fe_v_face.get_JxW_values();
1593 * for (unsigned int x = 0;
1594 * x < fe_v_face.n_quadrature_points;
1597 * jump[face_no / 2] +=
1598 * std::abs(u[x] - u_neighbor[x]) * JxW[x];
1599 * area[face_no / 2] += JxW[x];
1607 * Now we analyze the size of the mean jumps, which we get dividing
1608 * the jumps by the measure of the respective faces.
1611 * std::array<double, dim> average_jumps;
1612 * double sum_of_average_jumps = 0.;
1613 * for (unsigned int i = 0; i < dim; ++i)
1615 * average_jumps[i] = jump(i) / area(i);
1616 * sum_of_average_jumps += average_jumps[i];
1621 * Now we loop over the <code>dim</code> coordinate directions of
1622 * the unit cell and compare the average jump over the faces
1623 * orthogonal to that direction with the average jumps over faces
1624 * orthogonal to the remaining direction(s). If the first is larger
1625 * than the latter by a given factor, we refine only along hat
1626 * axis. Otherwise we leave the refinement flag unchanged, resulting
1627 * in isotropic refinement.
1630 * for (unsigned int i = 0; i < dim; ++i)
1631 * if (average_jumps[i] > anisotropic_threshold_ratio *
1632 * (sum_of_average_jumps - average_jumps[i]))
1633 * cell->set_refine_flag(RefinementCase<dim>::cut_axis(i));
1640 * <a name="TheRest"></a>
1645 * The remaining part of the program very much follows the scheme of
1646 * previous tutorial programs. We output the mesh in VTU format (just
1647 * as we did in @ref step_1 "step-1", for example), and the visualization output
1648 * in VTU format as we almost always do.
1651 * template <int dim>
1652 * void DGMethod<dim>::output_results(const unsigned int cycle) const
1654 * std::string refine_type;
1656 * refine_type = ".aniso";
1658 * refine_type = ".iso";
1661 * const std::string filename =
1662 * "grid-" + std::to_string(cycle) + refine_type + ".svg";
1663 * std::cout << " Writing grid to <" << filename << ">..." << std::endl;
1664 * std::ofstream svg_output(filename);
1667 * grid_out.write_svg(triangulation, svg_output);
1671 * const std::string filename =
1672 * "sol-" + std::to_string(cycle) + refine_type + ".vtu";
1673 * std::cout << " Writing solution to <" << filename << ">..."
1675 * std::ofstream gnuplot_output(filename);
1677 * DataOut<dim> data_out;
1678 * data_out.attach_dof_handler(dof_handler);
1679 * data_out.add_data_vector(solution2, "u");
1681 * data_out.build_patches(degree);
1683 * data_out.write_vtu(gnuplot_output);
1689 * template <int dim>
1690 * void DGMethod<dim>::run()
1692 * for (unsigned int cycle = 0; cycle < 6; ++cycle)
1694 * std::cout << "Cycle " << cycle << ':
' << std::endl;
1700 * Create the rectangular domain.
1703 * Point<dim> p1, p2;
1706 * for (unsigned int i = 0; i < dim; ++i)
1710 * Adjust the number of cells in different directions to obtain
1711 * completely isotropic cells for the original mesh.
1714 * std::vector<unsigned int> repetitions(dim, 1);
1715 * repetitions[0] = 2;
1716 * GridGenerator::subdivided_hyper_rectangle(triangulation,
1721 * triangulation.refine_global(5 - dim);
1727 * std::cout << " Number of active cells: "
1728 * << triangulation.n_active_cells() << std::endl;
1732 * std::cout << " Number of degrees of freedom: " << dof_handler.n_dofs()
1735 * Timer assemble_timer;
1736 * assemble_system();
1737 * std::cout << " Time of assemble_system: " << assemble_timer.cpu_time()
1741 * output_results(cycle);
1743 * std::cout << std::endl;
1746 * } // namespace Step30
1754 * using namespace Step30;
1758 * If you want to run the program in 3D, simply change the following
1759 * line to <code>const unsigned int dim = 3;</code>.
1762 * const unsigned int dim = 2;
1767 * First, we perform a run with isotropic refinement.
1770 * std::cout << "Performing a " << dim
1771 * << "D run with isotropic refinement..." << std::endl
1772 * << "------------------------------------------------"
1774 * DGMethod<dim> dgmethod_iso(false);
1775 * dgmethod_iso.run();
1781 * Now we do a second run, this time with anisotropic refinement.
1784 * std::cout << std::endl
1785 * << "Performing a " << dim
1786 * << "D run with anisotropic refinement..." << std::endl
1787 * << "--------------------------------------------------"
1789 * DGMethod<dim> dgmethod_aniso(true);
1790 * dgmethod_aniso.run();
1793 * catch (std::exception &exc)
1795 * std::cerr << std::endl
1797 * << "----------------------------------------------------"
1799 * std::cerr << "Exception on processing: " << std::endl
1800 * << exc.what() << std::endl
1801 * << "Aborting!" << std::endl
1802 * << "----------------------------------------------------"
1808 * std::cerr << std::endl
1810 * << "----------------------------------------------------"
1812 * std::cerr << "Unknown exception!" << std::endl
1813 * << "Aborting!" << std::endl
1814 * << "----------------------------------------------------"
1822<a name="Results"></a><h1>Results</h1>
1826The output of this program consist of the console output, the SVG
1827files containing the grids, and the solutions given in VTU format.
1829Performing a 2D run with isotropic refinement...
1830------------------------------------------------
1832 Number of active cells: 128
1833 Number of degrees of freedom: 512
1834 Time of assemble_system: 0.092049
1835 Writing grid to <grid-0.iso.svg>...
1836 Writing solution to <sol-0.iso.vtu>...
1839 Number of active cells: 239
1840 Number of degrees of freedom: 956
1841 Time of assemble_system: 0.109519
1842 Writing grid to <grid-1.iso.svg>...
1843 Writing solution to <sol-1.iso.vtu>...
1846 Number of active cells: 491
1847 Number of degrees of freedom: 1964
1848 Time of assemble_system: 0.08303
1849 Writing grid to <grid-2.iso.svg>...
1850 Writing solution to <sol-2.iso.vtu>...
1853 Number of active cells: 1031
1854 Number of degrees of freedom: 4124
1855 Time of assemble_system: 0.278987
1856 Writing grid to <grid-3.iso.svg>...
1857 Writing solution to <sol-3.iso.vtu>...
1860 Number of active cells: 2027
1861 Number of degrees of freedom: 8108
1862 Time of assemble_system: 0.305869
1863 Writing grid to <grid-4.iso.svg>...
1864 Writing solution to <sol-4.iso.vtu>...
1867 Number of active cells: 4019
1868 Number of degrees of freedom: 16076
1869 Time of assemble_system: 0.47616
1870 Writing grid to <grid-5.iso.svg>...
1871 Writing solution to <sol-5.iso.vtu>...
1874Performing a 2D run with anisotropic refinement...
1875--------------------------------------------------
1877 Number of active cells: 128
1878 Number of degrees of freedom: 512
1879 Time of assemble_system: 0.052866
1880 Writing grid to <grid-0.aniso.svg>...
1881 Writing solution to <sol-0.aniso.vtu>...
1884 Number of active cells: 171
1885 Number of degrees of freedom: 684
1886 Time of assemble_system: 0.050917
1887 Writing grid to <grid-1.aniso.svg>...
1888 Writing solution to <sol-1.aniso.vtu>...
1891 Number of active cells: 255
1892 Number of degrees of freedom: 1020
1893 Time of assemble_system: 0.064132
1894 Writing grid to <grid-2.aniso.svg>...
1895 Writing solution to <sol-2.aniso.vtu>...
1898 Number of active cells: 394
1899 Number of degrees of freedom: 1576
1900 Time of assemble_system: 0.119849
1901 Writing grid to <grid-3.aniso.svg>...
1902 Writing solution to <sol-3.aniso.vtu>...
1905 Number of active cells: 648
1906 Number of degrees of freedom: 2592
1907 Time of assemble_system: 0.218244
1908 Writing grid to <grid-4.aniso.svg>...
1909 Writing solution to <sol-4.aniso.vtu>...
1912 Number of active cells: 1030
1913 Number of degrees of freedom: 4120
1914 Time of assemble_system: 0.128121
1915 Writing grid to <grid-5.aniso.svg>...
1916 Writing solution to <sol-5.aniso.vtu>...
1919This text output shows the reduction in the number of cells which results from
1920the successive application of anisotropic refinement. After the last refinement
1921step the savings have accumulated so much that almost four times as many cells
1922and thus degrees of freedom are needed in the isotropic case. The time needed for assembly
1923scales with a similar factor.
1925The first interesting part is of course to see how the meshes look like.
1926On the left are the isotropically refined ones, on the right the
1927anisotropic ones (colors indicate the refinement level of cells):
1929<table width="80%" align="center">
1932 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-0.iso.9.2.png" alt="">
1935 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-0.aniso.9.2.png" alt="">
1940 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-1.iso.9.2.png" alt="">
1943 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-1.aniso.9.2.png" alt="">
1948 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-2.iso.9.2.png" alt="">
1951 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-2.aniso.9.2.png" alt="">
1956 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-3.iso.9.2.png" alt="">
1959 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-3.aniso.9.2.png" alt="">
1964 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-4.iso.9.2.png" alt="">
1967 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-4.aniso.9.2.png" alt="">
1972 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-5.iso.9.2.png" alt="">
1975 <img src="https://www.dealii.org/images/steps/developer/step-30.grid-5.aniso.9.2.png" alt="">
1981The other interesting thing is, of course, to see the solution on these
1982two sequences of meshes. Here they are, on the refinement cycles 1 and 4,
1983clearly showing that the solution is indeed composed of <i>discontinuous</i> piecewise
1986<table width="60%" align="center">
1989 <img src="https://www.dealii.org/images/steps/developer/step-30.sol-1.iso.9.2.png" alt="">
1992 <img src="https://www.dealii.org/images/steps/developer/step-30.sol-1.aniso.9.2.png" alt="">
1997 <img src="https://www.dealii.org/images/steps/developer/step-30.sol-4.iso.9.2.png" alt="">
2000 <img src="https://www.dealii.org/images/steps/developer/step-30.sol-4.aniso.9.2.png" alt="">
2005We see, that the solution on the anisotropically refined mesh is very similar to
2006the solution obtained on the isotropically refined mesh. Thus the anisotropic
2007indicator seems to effectively select the appropriate cells for anisotropic
2010The pictures also explain why the mesh is refined as it is.
2011In the whole left part of the domain refinement is only performed along the
2012@f$y@f$-axis of cells. In the right part of the domain the refinement is dominated by
2013isotropic refinement, as the anisotropic feature of the solution - the jump from
2014one to zero - is not well aligned with the mesh where the advection direction
2015takes a turn. However, at the bottom and closest (to the observer) parts of the
2016quarter circle this jumps again becomes more and more aligned
2017with the mesh and the refinement algorithm reacts by creating anisotropic cells
2018of increasing aspect ratio.
2020It might seem that the necessary alignment of anisotropic features and the
2021coarse mesh can decrease performance significantly for real world
2022problems. That is not wrong in general: If one were, for example, to apply
2023anisotropic refinement to problems in which shocks appear (e.g., the
2024equations solved in @ref step_69 "step-69"), then it many cases the shock is not aligned
2025with the mesh and anisotropic refinement will help little unless one also
2026introduces techniques to move the mesh in alignment with the shocks.
2027On the other hand, many steep features of solutions are due to boundary layers.
2028In those cases, the mesh is already aligned with the anisotropic features
2029because it is of course aligned with the boundary itself, and anisotropic
2030refinement will almost always increase the efficiency of computations on
2031adapted grids for these cases.
2034<a name="PlainProg"></a>
2035<h1> The plain program</h1>
2036@include "step-30.cc"
const std::vector< double > & get_JxW_values() const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
@ update_values
Shape function values.
@ update_normal_vectors
Normal vectors.
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
__global__ void set(Number *val, const Number s, const size_type N)
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void loop(ITERATOR begin, typename identity< ITERATOR >::type end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(DOFINFO &, DOFINFO &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, ASSEMBLER &assembler, const LoopControl &lctrl=LoopControl())
void initialize(const MatrixType &A, const AdditionalData parameters)
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
void make_flux_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternType &sparsity_pattern)
void approximate(SynchronousIterators< std::tuple< typename DoFHandler< dim, spacedim >::active_cell_iterator, Vector< float >::iterator > > const &cell, const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof_handler, const InputVector &solution, const unsigned int component)
void approximate_gradient(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const InputVector &solution, Vector< float > &derivative_norm, const unsigned int component=0)
void refine(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold, const unsigned int max_to_mark=numbers::invalid_unsigned_int)
void refine_and_coarsen_fixed_number(Triangulation< dim, spacedim > &triangulation, const Vector< Number > &criteria, const double top_fraction_of_cells, const double bottom_fraction_of_cells, const unsigned int max_n_cells=std::numeric_limits< unsigned int >::max())
@ valid
Iterator points to a valid object.
static const types::blas_int one
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
void call(const std::function< RT()> &function, internal::return_value< RT > &ret_val)
void run(const Iterator &begin, const typename identity< Iterator >::type &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 > pow(const ::VectorizedArray< Number, width > &, const Number p)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation