deal.II version GIT relicensing-1721-g8100761196 2024-08-31 12:30:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
step-61.h
Go to the documentation of this file.
1,
732 *   const unsigned int /*component*/) const
733 *   {
734 *   return 0;
735 *   }
736 *  
737 *  
738 *  
739 *   template <int dim>
740 *   class RightHandSide : public Function<dim>
741 *   {
742 *   public:
743 *   virtual double value(const Point<dim> &p,
744 *   const unsigned int component = 0) const override;
745 *   };
746 *  
747 *  
748 *  
749 *   template <int dim>
750 *   double RightHandSide<dim>::value(const Point<dim> &p,
751 *   const unsigned int /*component*/) const
752 *   {
753 *   return (2 * numbers::PI * numbers::PI * std::sin(numbers::PI * p[0]) *
754 *   std::sin(numbers::PI * p[1]));
755 *   }
756 *  
757 *  
758 *  
759 * @endcode
760 *
761 * The class that implements the exact pressure solution has an
762 * oddity in that we implement it as a vector-valued one with two
763 * components. (We say that it has two components in the constructor
764 * where we call the constructor of the base Function class.) In the
765 * `value()` function, we do not test for the value of the
766 * `component` argument, which implies that we return the same value
767 * for both components of the vector-valued function. We do this
768 * because we describe the finite element in use in this program as
769 * a vector-valued system that contains the interior and the
770 * interface pressures, and when we compute errors, we will want to
771 * use the same pressure solution to test both of these components.
772 *
773 * @code
774 *   template <int dim>
775 *   class ExactPressure : public Function<dim>
776 *   {
777 *   public:
778 *   ExactPressure()
779 *   : Function<dim>(2)
780 *   {}
781 *  
782 *   virtual double value(const Point<dim> &p,
783 *   const unsigned int component) const override;
784 *   };
785 *  
786 *  
787 *  
788 *   template <int dim>
789 *   double ExactPressure<dim>::value(const Point<dim> &p,
790 *   const unsigned int /*component*/) const
791 *   {
792 *   return std::sin(numbers::PI * p[0]) * std::sin(numbers::PI * p[1]);
793 *   }
794 *  
795 *  
796 *  
797 *   template <int dim>
798 *   class ExactVelocity : public TensorFunction<1, dim>
799 *   {
800 *   public:
801 *   ExactVelocity()
803 *   {}
804 *  
805 *   virtual Tensor<1, dim> value(const Point<dim> &p) const override;
806 *   };
807 *  
808 *  
809 *  
810 *   template <int dim>
811 *   Tensor<1, dim> ExactVelocity<dim>::value(const Point<dim> &p) const
812 *   {
813 *   Tensor<1, dim> return_value;
814 *   return_value[0] = -numbers::PI * std::cos(numbers::PI * p[0]) *
815 *   std::sin(numbers::PI * p[1]);
816 *   return_value[1] = -numbers::PI * std::sin(numbers::PI * p[0]) *
817 *   std::cos(numbers::PI * p[1]);
818 *   return return_value;
819 *   }
820 *  
821 *  
822 *  
823 * @endcode
824 *
825 *
826 * <a name="step_61-WGDarcyEquationclassimplementation"></a>
827 * <h3>WGDarcyEquation class implementation</h3>
828 *
829
830 *
831 *
832 * <a name="step_61-WGDarcyEquationWGDarcyEquation"></a>
833 * <h4>WGDarcyEquation::WGDarcyEquation</h4>
834 *
835
836 *
837 * In this constructor, we create a finite element space for vector valued
838 * functions, which will here include the ones used for the interior and
839 * interface pressures, @f$p^\circ@f$ and @f$p^\partial@f$.
840 *
841 * @code
842 *   template <int dim>
843 *   WGDarcyEquation<dim>::WGDarcyEquation(const unsigned int degree)
844 *   : fe(FE_DGQ<dim>(degree), FE_FaceQ<dim>(degree))
845 *   , dof_handler(triangulation)
846 *   , fe_dgrt(degree)
847 *   , dof_handler_dgrt(triangulation)
848 *   {}
849 *  
850 *  
851 *  
852 * @endcode
853 *
854 *
855 * <a name="step_61-WGDarcyEquationmake_grid"></a>
856 * <h4>WGDarcyEquation::make_grid</h4>
857 *
858
859 *
860 * We generate a mesh on the unit square domain and refine it.
861 *
862 * @code
863 *   template <int dim>
864 *   void WGDarcyEquation<dim>::make_grid()
865 *   {
867 *   triangulation.refine_global(5);
868 *  
869 *   std::cout << " Number of active cells: " << triangulation.n_active_cells()
870 *   << std::endl
871 *   << " Total number of cells: " << triangulation.n_cells()
872 *   << std::endl;
873 *   }
874 *  
875 *  
876 *  
877 * @endcode
878 *
879 *
880 * <a name="step_61-WGDarcyEquationsetup_system"></a>
881 * <h4>WGDarcyEquation::setup_system</h4>
882 *
883
884 *
885 * After we have created the mesh above, we distribute degrees of
886 * freedom and resize matrices and vectors. The only piece of
887 * interest in this function is how we interpolate the boundary
888 * values for the pressure. Since the pressure consists of interior
889 * and interface components, we need to make sure that we only
890 * interpolate onto that component of the vector-valued solution
891 * space that corresponds to the interface pressures (as these are
892 * the only ones that are defined on the boundary of the domain). We
893 * do this via a component mask object for only the interface
894 * pressures.
895 *
896 * @code
897 *   template <int dim>
898 *   void WGDarcyEquation<dim>::setup_system()
899 *   {
900 *   dof_handler.distribute_dofs(fe);
901 *   dof_handler_dgrt.distribute_dofs(fe_dgrt);
902 *  
903 *   std::cout << " Number of pressure degrees of freedom: "
904 *   << dof_handler.n_dofs() << std::endl;
905 *  
906 *   solution.reinit(dof_handler.n_dofs());
907 *   system_rhs.reinit(dof_handler.n_dofs());
908 *  
909 *  
910 *   {
911 *   constraints.clear();
912 *   const FEValuesExtractors::Scalar interface_pressure(1);
913 *   const ComponentMask interface_pressure_mask =
914 *   fe.component_mask(interface_pressure);
916 *   0,
917 *   BoundaryValues<dim>(),
918 *   constraints,
919 *   interface_pressure_mask);
920 *   constraints.close();
921 *   }
922 *  
923 *  
924 * @endcode
925 *
926 * In the bilinear form, there is no integration term over faces
927 * between two neighboring cells, so we can just use
928 * <code>DoFTools::make_sparsity_pattern</code> to calculate the sparse
929 * matrix.
930 *
931 * @code
932 *   DynamicSparsityPattern dsp(dof_handler.n_dofs());
933 *   DoFTools::make_sparsity_pattern(dof_handler, dsp, constraints);
934 *   sparsity_pattern.copy_from(dsp);
935 *  
936 *   system_matrix.reinit(sparsity_pattern);
937 *   }
938 *  
939 *  
940 *  
941 * @endcode
942 *
943 *
944 * <a name="step_61-WGDarcyEquationassemble_system"></a>
945 * <h4>WGDarcyEquation::assemble_system</h4>
946 *
947
948 *
949 * This function is more interesting. As detailed in the
950 * introduction, the assembly of the linear system requires us to
951 * evaluate the weak gradient of the shape functions, which is an
952 * element in the Raviart-Thomas space. As a consequence, we need to
953 * define a Raviart-Thomas finite element object, and have FEValues
954 * objects that evaluate it at quadrature points. We then need to
955 * compute the matrix @f$C^K@f$ on every cell @f$K@f$, for which we need the
956 * matrices @f$M^K@f$ and @f$G^K@f$ mentioned in the introduction.
957 *
958
959 *
960 * A point that may not be obvious is that in all previous tutorial
961 * programs, we have always called FEValues::reinit() with a cell
962 * iterator from a DoFHandler. This is so that one can call
963 * functions such as FEValuesBase::get_function_values() that
964 * extract the values of a finite element function (represented by a
965 * vector of DoF values) on the quadrature points of a cell. For
966 * this operation to work, one needs to know which vector elements
967 * correspond to the degrees of freedom on a given cell -- i.e.,
968 * exactly the kind of information and operation provided by the
969 * DoFHandler class.
970 *
971
972 *
973 * We could create a DoFHandler object for the "broken" Raviart-Thomas space
974 * (using the FE_DGRaviartThomas class), but we really don't want to here: At
975 * least in the current function, we have no need for any globally defined
976 * degrees of freedom associated with this broken space, but really only
977 * need to reference the shape functions of such a space on the current
978 * cell. As a consequence, we use the fact that one can call
979 * FEValues::reinit() also with cell iterators into Triangulation
980 * objects (rather than DoFHandler objects). In this case, FEValues
981 * can of course only provide us with information that only
982 * references information about cells, rather than degrees of freedom
983 * enumerated on these cells. So we can't use
984 * FEValuesBase::get_function_values(), but we can use
985 * FEValues::shape_value() to obtain the values of shape functions
986 * at quadrature points on the current cell. It is this kind of
987 * functionality we will make use of below. The variable that will
988 * give us this information about the Raviart-Thomas functions below
989 * is then the `fe_values_rt` (and corresponding `fe_face_values_rt`)
990 * object.
991 *
992
993 *
994 * Given this introduction, the following declarations should be
995 * pretty obvious:
996 *
997 * @code
998 *   template <int dim>
999 *   void WGDarcyEquation<dim>::assemble_system()
1000 *   {
1001 *   const QGauss<dim> quadrature_formula(fe_dgrt.degree + 1);
1002 *   const QGauss<dim - 1> face_quadrature_formula(fe_dgrt.degree + 1);
1003 *  
1004 *   FEValues<dim> fe_values(fe,
1005 *   quadrature_formula,
1007 *   update_JxW_values);
1008 *   FEFaceValues<dim> fe_face_values(fe,
1009 *   face_quadrature_formula,
1012 *   update_JxW_values);
1013 *  
1014 *   FEValues<dim> fe_values_dgrt(fe_dgrt,
1015 *   quadrature_formula,
1018 *   update_JxW_values);
1019 *   FEFaceValues<dim> fe_face_values_dgrt(fe_dgrt,
1020 *   face_quadrature_formula,
1021 *   update_values |
1024 *   update_JxW_values);
1025 *  
1026 *   const unsigned int dofs_per_cell = fe.n_dofs_per_cell();
1027 *   const unsigned int dofs_per_cell_dgrt = fe_dgrt.n_dofs_per_cell();
1028 *  
1029 *   const unsigned int n_q_points = fe_values.get_quadrature().size();
1030 *   const unsigned int n_q_points_dgrt = fe_values_dgrt.get_quadrature().size();
1031 *  
1032 *   const unsigned int n_face_q_points = fe_face_values.get_quadrature().size();
1033 *  
1034 *   RightHandSide<dim> right_hand_side;
1035 *   std::vector<double> right_hand_side_values(n_q_points);
1036 *  
1037 *   const Coefficient<dim> coefficient;
1038 *   std::vector<Tensor<2, dim>> coefficient_values(n_q_points);
1039 *  
1040 *   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
1041 *  
1042 *  
1043 * @endcode
1044 *
1045 * Next, let us declare the various cell matrices discussed in the
1046 * introduction:
1047 *
1048 * @code
1049 *   FullMatrix<double> cell_matrix_M(dofs_per_cell_dgrt, dofs_per_cell_dgrt);
1050 *   FullMatrix<double> cell_matrix_G(dofs_per_cell_dgrt, dofs_per_cell);
1051 *   FullMatrix<double> cell_matrix_C(dofs_per_cell, dofs_per_cell_dgrt);
1053 *   Vector<double> cell_rhs(dofs_per_cell);
1054 *   Vector<double> cell_solution(dofs_per_cell);
1055 *  
1056 * @endcode
1057 *
1058 * We need <code>FEValuesExtractors</code> to access the @p interior and
1059 * @p face component of the shape functions.
1060 *
1061 * @code
1062 *   const FEValuesExtractors::Vector velocities(0);
1063 *   const FEValuesExtractors::Scalar pressure_interior(0);
1064 *   const FEValuesExtractors::Scalar pressure_face(1);
1065 *  
1066 * @endcode
1067 *
1068 * This finally gets us in position to loop over all cells. On
1069 * each cell, we will first calculate the various cell matrices
1070 * used to construct the local matrix -- as they depend on the
1071 * cell in question, they need to be re-computed on each cell. We
1072 * need shape functions for the Raviart-Thomas space as well, for
1073 * which we need to create first an iterator to the cell of the
1074 * triangulation, which we can obtain by assignment from the cell
1075 * pointing into the DoFHandler.
1076 *
1077 * @code
1078 *   for (const auto &cell : dof_handler.active_cell_iterators())
1079 *   {
1080 *   fe_values.reinit(cell);
1081 *  
1082 *   const typename Triangulation<dim>::active_cell_iterator cell_dgrt =
1083 *   cell;
1084 *   fe_values_dgrt.reinit(cell_dgrt);
1085 *  
1086 *   right_hand_side.value_list(fe_values.get_quadrature_points(),
1087 *   right_hand_side_values);
1088 *   coefficient.value_list(fe_values.get_quadrature_points(),
1089 *   coefficient_values);
1090 *  
1091 * @endcode
1092 *
1093 * The first cell matrix we will compute is the @ref GlossMassMatrix "mass matrix"
1094 * for the Raviart-Thomas space. Hence, we need to loop over
1095 * all the quadrature points for the velocity FEValues object.
1096 *
1097 * @code
1098 *   cell_matrix_M = 0;
1099 *   for (unsigned int q = 0; q < n_q_points_dgrt; ++q)
1100 *   for (unsigned int i = 0; i < dofs_per_cell_dgrt; ++i)
1101 *   {
1102 *   const Tensor<1, dim> v_i = fe_values_dgrt[velocities].value(i, q);
1103 *   for (unsigned int k = 0; k < dofs_per_cell_dgrt; ++k)
1104 *   {
1105 *   const Tensor<1, dim> v_k =
1106 *   fe_values_dgrt[velocities].value(k, q);
1107 *   cell_matrix_M(i, k) += (v_i * v_k * fe_values_dgrt.JxW(q));
1108 *   }
1109 *   }
1110 * @endcode
1111 *
1112 * Next we take the inverse of this matrix by using
1113 * FullMatrix::gauss_jordan(). It will be used to calculate
1114 * the coefficient matrix @f$C^K@f$ later. It is worth recalling
1115 * later that `cell_matrix_M` actually contains the *inverse*
1116 * of @f$M^K@f$ after this call.
1117 *
1118 * @code
1119 *   cell_matrix_M.gauss_jordan();
1120 *  
1121 * @endcode
1122 *
1123 * From the introduction, we know that the right hand side
1124 * @f$G^K@f$ of the equation that defines @f$C^K@f$ is the difference
1125 * between a face integral and a cell integral. Here, we
1126 * approximate the negative of the contribution in the
1127 * interior. Each component of this matrix is the integral of
1128 * a product between a basis function of the polynomial space
1129 * and the divergence of a basis function of the
1130 * Raviart-Thomas space. These basis functions are defined in
1131 * the interior.
1132 *
1133 * @code
1134 *   cell_matrix_G = 0;
1135 *   for (unsigned int q = 0; q < n_q_points; ++q)
1136 *   for (unsigned int i = 0; i < dofs_per_cell_dgrt; ++i)
1137 *   {
1138 *   const double div_v_i =
1139 *   fe_values_dgrt[velocities].divergence(i, q);
1140 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
1141 *   {
1142 *   const double phi_j_interior =
1143 *   fe_values[pressure_interior].value(j, q);
1144 *  
1145 *   cell_matrix_G(i, j) -=
1146 *   (div_v_i * phi_j_interior * fe_values.JxW(q));
1147 *   }
1148 *   }
1149 *  
1150 *  
1151 * @endcode
1152 *
1153 * Next, we approximate the integral on faces by quadrature.
1154 * Each component is the integral of a product between a basis function
1155 * of the polynomial space and the dot product of a basis function of
1156 * the Raviart-Thomas space and the normal vector. So we loop over all
1157 * the faces of the element and obtain the normal vector.
1158 *
1159 * @code
1160 *   for (const auto &face : cell->face_iterators())
1161 *   {
1162 *   fe_face_values.reinit(cell, face);
1163 *   fe_face_values_dgrt.reinit(cell_dgrt, face);
1164 *  
1165 *   for (unsigned int q = 0; q < n_face_q_points; ++q)
1166 *   {
1167 *   const Tensor<1, dim> &normal = fe_face_values.normal_vector(q);
1168 *  
1169 *   for (unsigned int i = 0; i < dofs_per_cell_dgrt; ++i)
1170 *   {
1171 *   const Tensor<1, dim> v_i =
1172 *   fe_face_values_dgrt[velocities].value(i, q);
1173 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
1174 *   {
1175 *   const double phi_j_face =
1176 *   fe_face_values[pressure_face].value(j, q);
1177 *  
1178 *   cell_matrix_G(i, j) +=
1179 *   ((v_i * normal) * phi_j_face * fe_face_values.JxW(q));
1180 *   }
1181 *   }
1182 *   }
1183 *   }
1184 *  
1185 * @endcode
1186 *
1187 * @p cell_matrix_C is then the matrix product between the
1188 * transpose of @f$G^K@f$ and the inverse of the mass matrix
1189 * (where this inverse is stored in @p cell_matrix_M):
1190 *
1191 * @code
1192 *   cell_matrix_G.Tmmult(cell_matrix_C, cell_matrix_M);
1193 *  
1194 * @endcode
1195 *
1196 * Finally we can compute the local matrix @f$A^K@f$. Element
1197 * @f$A^K_{ij}@f$ is given by @f$\int_{E} \sum_{k,l} C_{ik} C_{jl}
1198 * (\mathbf{K} \mathbf{v}_k) \cdot \mathbf{v}_l
1199 * \mathrm{d}x@f$. We have calculated the coefficients @f$C@f$ in
1200 * the previous step, and so obtain the following after
1201 * suitably re-arranging the loops:
1202 *
1203 * @code
1204 *   local_matrix = 0;
1205 *   for (unsigned int q = 0; q < n_q_points_dgrt; ++q)
1206 *   {
1207 *   for (unsigned int k = 0; k < dofs_per_cell_dgrt; ++k)
1208 *   {
1209 *   const Tensor<1, dim> v_k =
1210 *   fe_values_dgrt[velocities].value(k, q);
1211 *   for (unsigned int l = 0; l < dofs_per_cell_dgrt; ++l)
1212 *   {
1213 *   const Tensor<1, dim> v_l =
1214 *   fe_values_dgrt[velocities].value(l, q);
1215 *  
1216 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
1217 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
1218 *   local_matrix(i, j) +=
1219 *   (coefficient_values[q] * cell_matrix_C[i][k] * v_k) *
1220 *   cell_matrix_C[j][l] * v_l * fe_values_dgrt.JxW(q);
1221 *   }
1222 *   }
1223 *   }
1224 *  
1225 * @endcode
1226 *
1227 * Next, we calculate the right hand side, @f$\int_{K} f q \mathrm{d}x@f$:
1228 *
1229 * @code
1230 *   cell_rhs = 0;
1231 *   for (unsigned int q = 0; q < n_q_points; ++q)
1232 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
1233 *   {
1234 *   cell_rhs(i) += (fe_values[pressure_interior].value(i, q) *
1235 *   right_hand_side_values[q] * fe_values.JxW(q));
1236 *   }
1237 *  
1238 * @endcode
1239 *
1240 * The last step is to distribute components of the local
1241 * matrix into the system matrix and transfer components of
1242 * the cell right hand side into the system right hand side:
1243 *
1244 * @code
1245 *   cell->get_dof_indices(local_dof_indices);
1246 *   constraints.distribute_local_to_global(
1247 *   local_matrix, cell_rhs, local_dof_indices, system_matrix, system_rhs);
1248 *   }
1249 *   }
1250 *  
1251 *  
1252 *  
1253 * @endcode
1254 *
1255 *
1256 * <a name="step_61-WGDarcyEquationdimsolve"></a>
1257 * <h4>WGDarcyEquation<dim>::solve</h4>
1258 *
1259
1260 *
1261 * This step is rather trivial and the same as in many previous
1262 * tutorial programs:
1263 *
1264 * @code
1265 *   template <int dim>
1266 *   void WGDarcyEquation<dim>::solve()
1267 *   {
1268 *   SolverControl solver_control(1000, 1e-8 * system_rhs.l2_norm());
1269 *   SolverCG<Vector<double>> solver(solver_control);
1270 *   solver.solve(system_matrix, solution, system_rhs, PreconditionIdentity());
1271 *   constraints.distribute(solution);
1272 *   }
1273 *  
1274 *  
1275 * @endcode
1276 *
1277 *
1278 * <a name="step_61-WGDarcyEquationdimcompute_postprocessed_velocity"></a>
1279 * <h4>WGDarcyEquation<dim>::compute_postprocessed_velocity</h4>
1280 *
1281
1282 *
1283 * In this function, compute the velocity field from the pressure
1284 * solution previously computed. The
1285 * velocity is defined as @f$\mathbf{u}_h = \mathbf{Q}_h \left(
1286 * -\mathbf{K}\nabla_{w,d}p_h \right)@f$, which requires us to compute
1287 * many of the same terms as in the assembly of the system matrix.
1288 * There are also the matrices @f$E^K,D^K@f$ we need to assemble (see
1289 * the introduction) but they really just follow the same kind of
1290 * pattern.
1291 *
1292
1293 *
1294 * Computing the same matrices here as we have already done in the
1295 * `assemble_system()` function is of course wasteful in terms of
1296 * CPU time. Likewise, we copy some of the code from there to this
1297 * function, and this is also generally a poor idea. A better
1298 * implementation might provide for a function that encapsulates
1299 * this duplicated code. One could also think of using the classic
1300 * trade-off between computing efficiency and memory efficiency to
1301 * only compute the @f$C^K@f$ matrices once per cell during the
1302 * assembly, storing them somewhere on the side, and re-using them
1303 * here. (This is what @ref step_51 "step-51" does, for example, where the
1304 * `assemble_system()` function takes an argument that determines
1305 * whether the local matrices are recomputed, and a similar approach
1306 * -- maybe with storing local matrices elsewhere -- could be
1307 * adapted for the current program.)
1308 *
1309 * @code
1310 *   template <int dim>
1311 *   void WGDarcyEquation<dim>::compute_postprocessed_velocity()
1312 *   {
1313 *   darcy_velocity.reinit(dof_handler_dgrt.n_dofs());
1314 *  
1315 *   const QGauss<dim> quadrature_formula(fe_dgrt.degree + 1);
1316 *   const QGauss<dim - 1> face_quadrature_formula(fe_dgrt.degree + 1);
1317 *  
1318 *   FEValues<dim> fe_values(fe,
1319 *   quadrature_formula,
1321 *   update_JxW_values);
1322 *  
1323 *   FEFaceValues<dim> fe_face_values(fe,
1324 *   face_quadrature_formula,
1327 *   update_JxW_values);
1328 *  
1329 *   FEValues<dim> fe_values_dgrt(fe_dgrt,
1330 *   quadrature_formula,
1333 *   update_JxW_values);
1334 *  
1335 *   FEFaceValues<dim> fe_face_values_dgrt(fe_dgrt,
1336 *   face_quadrature_formula,
1337 *   update_values |
1340 *   update_JxW_values);
1341 *  
1342 *   const unsigned int dofs_per_cell = fe.n_dofs_per_cell();
1343 *   const unsigned int dofs_per_cell_dgrt = fe_dgrt.n_dofs_per_cell();
1344 *  
1345 *   const unsigned int n_q_points = fe_values.get_quadrature().size();
1346 *   const unsigned int n_q_points_dgrt = fe_values_dgrt.get_quadrature().size();
1347 *  
1348 *   const unsigned int n_face_q_points = fe_face_values.get_quadrature().size();
1349 *  
1350 *  
1351 *   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
1352 *   std::vector<types::global_dof_index> local_dof_indices_dgrt(
1353 *   dofs_per_cell_dgrt);
1354 *  
1355 *   FullMatrix<double> cell_matrix_M(dofs_per_cell_dgrt, dofs_per_cell_dgrt);
1356 *   FullMatrix<double> cell_matrix_G(dofs_per_cell_dgrt, dofs_per_cell);
1357 *   FullMatrix<double> cell_matrix_C(dofs_per_cell, dofs_per_cell_dgrt);
1358 *   FullMatrix<double> cell_matrix_D(dofs_per_cell_dgrt, dofs_per_cell_dgrt);
1359 *   FullMatrix<double> cell_matrix_E(dofs_per_cell_dgrt, dofs_per_cell_dgrt);
1360 *  
1361 *   Vector<double> cell_solution(dofs_per_cell);
1362 *   Vector<double> cell_velocity(dofs_per_cell_dgrt);
1363 *  
1364 *   const Coefficient<dim> coefficient;
1365 *   std::vector<Tensor<2, dim>> coefficient_values(n_q_points_dgrt);
1366 *  
1367 *   const FEValuesExtractors::Vector velocities(0);
1368 *   const FEValuesExtractors::Scalar pressure_interior(0);
1369 *   const FEValuesExtractors::Scalar pressure_face(1);
1370 *  
1371 * @endcode
1372 *
1373 * In the introduction, we explained how to calculate the numerical velocity
1374 * on the cell. We need the pressure solution values on each cell,
1375 * coefficients of the Gram matrix and coefficients of the @f$L_2@f$ projection.
1376 * We have already calculated the global solution, so we will extract the
1377 * cell solution from the global solution. The coefficients of the Gram
1378 * matrix have been calculated when we assembled the system matrix for the
1379 * pressures. We will do the same way here. For the coefficients of the
1380 * projection, we do matrix multiplication, i.e., the inverse of the Gram
1381 * matrix times the matrix with @f$(\mathbf{K} \mathbf{w}, \mathbf{w})@f$ as
1382 * components. Then, we multiply all these coefficients and call them beta.
1383 * The numerical velocity is the product of beta and the basis functions of
1384 * the Raviart-Thomas space.
1385 *
1386 * @code
1388 *   cell = dof_handler.begin_active(),
1389 *   endc = dof_handler.end(), cell_dgrt = dof_handler_dgrt.begin_active();
1390 *   for (; cell != endc; ++cell, ++cell_dgrt)
1391 *   {
1392 *   fe_values.reinit(cell);
1393 *   fe_values_dgrt.reinit(cell_dgrt);
1394 *  
1395 *   coefficient.value_list(fe_values_dgrt.get_quadrature_points(),
1396 *   coefficient_values);
1397 *  
1398 * @endcode
1399 *
1400 * The component of this <code>cell_matrix_E</code> is the integral of
1401 * @f$(\mathbf{K} \mathbf{w}, \mathbf{w})@f$. <code>cell_matrix_M</code> is
1402 * the Gram matrix.
1403 *
1404 * @code
1405 *   cell_matrix_M = 0;
1406 *   cell_matrix_E = 0;
1407 *   for (unsigned int q = 0; q < n_q_points_dgrt; ++q)
1408 *   for (unsigned int i = 0; i < dofs_per_cell_dgrt; ++i)
1409 *   {
1410 *   const Tensor<1, dim> v_i = fe_values_dgrt[velocities].value(i, q);
1411 *   for (unsigned int k = 0; k < dofs_per_cell_dgrt; ++k)
1412 *   {
1413 *   const Tensor<1, dim> v_k =
1414 *   fe_values_dgrt[velocities].value(k, q);
1415 *  
1416 *   cell_matrix_E(i, k) +=
1417 *   (coefficient_values[q] * v_i * v_k * fe_values_dgrt.JxW(q));
1418 *  
1419 *   cell_matrix_M(i, k) += (v_i * v_k * fe_values_dgrt.JxW(q));
1420 *   }
1421 *   }
1422 *  
1423 * @endcode
1424 *
1425 * To compute the matrix @f$D@f$ mentioned in the introduction, we
1426 * then need to evaluate @f$D=M^{-1}E@f$ as explained in the
1427 * introduction:
1428 *
1429 * @code
1430 *   cell_matrix_M.gauss_jordan();
1431 *   cell_matrix_M.mmult(cell_matrix_D, cell_matrix_E);
1432 *  
1433 * @endcode
1434 *
1435 * Then we also need, again, to compute the matrix @f$C@f$ that is
1436 * used to evaluate the weak discrete gradient. This is the
1437 * exact same code as used in the assembly of the system
1438 * matrix, so we just copy it from there:
1439 *
1440 * @code
1441 *   cell_matrix_G = 0;
1442 *   for (unsigned int q = 0; q < n_q_points; ++q)
1443 *   for (unsigned int i = 0; i < dofs_per_cell_dgrt; ++i)
1444 *   {
1445 *   const double div_v_i =
1446 *   fe_values_dgrt[velocities].divergence(i, q);
1447 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
1448 *   {
1449 *   const double phi_j_interior =
1450 *   fe_values[pressure_interior].value(j, q);
1451 *  
1452 *   cell_matrix_G(i, j) -=
1453 *   (div_v_i * phi_j_interior * fe_values.JxW(q));
1454 *   }
1455 *   }
1456 *  
1457 *   for (const auto &face : cell->face_iterators())
1458 *   {
1459 *   fe_face_values.reinit(cell, face);
1460 *   fe_face_values_dgrt.reinit(cell_dgrt, face);
1461 *  
1462 *   for (unsigned int q = 0; q < n_face_q_points; ++q)
1463 *   {
1464 *   const Tensor<1, dim> &normal = fe_face_values.normal_vector(q);
1465 *  
1466 *   for (unsigned int i = 0; i < dofs_per_cell_dgrt; ++i)
1467 *   {
1468 *   const Tensor<1, dim> v_i =
1469 *   fe_face_values_dgrt[velocities].value(i, q);
1470 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
1471 *   {
1472 *   const double phi_j_face =
1473 *   fe_face_values[pressure_face].value(j, q);
1474 *  
1475 *   cell_matrix_G(i, j) +=
1476 *   ((v_i * normal) * phi_j_face * fe_face_values.JxW(q));
1477 *   }
1478 *   }
1479 *   }
1480 *   }
1481 *   cell_matrix_G.Tmmult(cell_matrix_C, cell_matrix_M);
1482 *  
1483 * @endcode
1484 *
1485 * Finally, we need to extract the pressure unknowns that
1486 * correspond to the current cell:
1487 *
1488 * @code
1489 *   cell->get_dof_values(solution, cell_solution);
1490 *  
1491 * @endcode
1492 *
1493 * We are now in a position to compute the local velocity
1494 * unknowns (with respect to the Raviart-Thomas space we are
1495 * projecting the term @f$-\mathbf K \nabla_{w,d} p_h@f$ into):
1496 *
1497 * @code
1498 *   cell_velocity = 0;
1499 *   for (unsigned int k = 0; k < dofs_per_cell_dgrt; ++k)
1500 *   for (unsigned int j = 0; j < dofs_per_cell_dgrt; ++j)
1501 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
1502 *   cell_velocity(k) +=
1503 *   -(cell_solution(i) * cell_matrix_C(i, j) * cell_matrix_D(k, j));
1504 *  
1505 * @endcode
1506 *
1507 * We compute Darcy velocity.
1508 * This is same as cell_velocity but used to graph Darcy velocity.
1509 *
1510 * @code
1511 *   cell_dgrt->get_dof_indices(local_dof_indices_dgrt);
1512 *   for (unsigned int k = 0; k < dofs_per_cell_dgrt; ++k)
1513 *   for (unsigned int j = 0; j < dofs_per_cell_dgrt; ++j)
1514 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
1515 *   darcy_velocity(local_dof_indices_dgrt[k]) +=
1516 *   -(cell_solution(i) * cell_matrix_C(i, j) * cell_matrix_D(k, j));
1517 *   }
1518 *   }
1519 *  
1520 *  
1521 *  
1522 * @endcode
1523 *
1524 *
1525 * <a name="step_61-WGDarcyEquationdimcompute_pressure_error"></a>
1526 * <h4>WGDarcyEquation<dim>::compute_pressure_error</h4>
1527 *
1528
1529 *
1530 * This part is to calculate the @f$L_2@f$ error of the pressure. We
1531 * define a vector that holds the norm of the error on each cell.
1532 * Next, we use VectorTool::integrate_difference() to compute the
1533 * error in the @f$L_2@f$ norm on each cell. However, we really only
1534 * care about the error in the interior component of the solution
1535 * vector (we can't even evaluate the interface pressures at the
1536 * quadrature points because these are all located in the interior
1537 * of cells) and consequently have to use a weight function that
1538 * ensures that the interface component of the solution variable is
1539 * ignored. This is done by using the ComponentSelectFunction whose
1540 * arguments indicate which component we want to select (component
1541 * zero, i.e., the interior pressures) and how many components there
1542 * are in total (two).
1543 *
1544 * @code
1545 *   template <int dim>
1546 *   void WGDarcyEquation<dim>::compute_pressure_error()
1547 *   {
1548 *   Vector<float> difference_per_cell(triangulation.n_active_cells());
1549 *   const ComponentSelectFunction<dim> select_interior_pressure(0, 2);
1550 *   VectorTools::integrate_difference(dof_handler,
1551 *   solution,
1552 *   ExactPressure<dim>(),
1553 *   difference_per_cell,
1554 *   QGauss<dim>(fe.degree + 2),
1556 *   &select_interior_pressure);
1557 *  
1558 *   const double L2_error = difference_per_cell.l2_norm();
1559 *   std::cout << "L2_error_pressure " << L2_error << std::endl;
1560 *   }
1561 *  
1562 *  
1563 *  
1564 * @endcode
1565 *
1566 *
1567 * <a name="step_61-WGDarcyEquationdimcompute_velocity_error"></a>
1568 * <h4>WGDarcyEquation<dim>::compute_velocity_error</h4>
1569 *
1570
1571 *
1572 * In this function, we evaluate @f$L_2@f$ errors for the velocity on
1573 * each cell, and @f$L_2@f$ errors for the flux on faces. The function
1574 * relies on the `compute_postprocessed_velocity()` function having
1575 * previous computed, which computes the velocity field based on the
1576 * pressure solution that has previously been computed.
1577 *
1578
1579 *
1580 * We are going to evaluate velocities on each cell and calculate
1581 * the difference between numerical and exact velocities.
1582 *
1583 * @code
1584 *   template <int dim>
1585 *   void WGDarcyEquation<dim>::compute_velocity_errors()
1586 *   {
1587 *   const QGauss<dim> quadrature_formula(fe_dgrt.degree + 1);
1588 *   const QGauss<dim - 1> face_quadrature_formula(fe_dgrt.degree + 1);
1589 *  
1590 *   FEValues<dim> fe_values_dgrt(fe_dgrt,
1591 *   quadrature_formula,
1594 *   update_JxW_values);
1595 *  
1596 *   FEFaceValues<dim> fe_face_values_dgrt(fe_dgrt,
1597 *   face_quadrature_formula,
1598 *   update_values |
1601 *   update_JxW_values);
1602 *  
1603 *   const unsigned int n_q_points_dgrt = fe_values_dgrt.get_quadrature().size();
1604 *   const unsigned int n_face_q_points_dgrt =
1605 *   fe_face_values_dgrt.get_quadrature().size();
1606 *  
1607 *   std::vector<Tensor<1, dim>> velocity_values(n_q_points_dgrt);
1608 *   std::vector<Tensor<1, dim>> velocity_face_values(n_face_q_points_dgrt);
1609 *  
1610 *   const FEValuesExtractors::Vector velocities(0);
1611 *  
1612 *   const ExactVelocity<dim> exact_velocity;
1613 *  
1614 *   double L2_err_velocity_cell_sqr_global = 0;
1615 *   double L2_err_flux_sqr = 0;
1616 *  
1617 * @endcode
1618 *
1619 * Having previously computed the postprocessed velocity, we here
1620 * only have to extract the corresponding values on each cell and
1621 * face and compare it to the exact values.
1622 *
1623 * @code
1624 *   for (const auto &cell_dgrt : dof_handler_dgrt.active_cell_iterators())
1625 *   {
1626 *   fe_values_dgrt.reinit(cell_dgrt);
1627 *  
1628 * @endcode
1629 *
1630 * First compute the @f$L_2@f$ error between the postprocessed velocity
1631 * field and the exact one:
1632 *
1633 * @code
1634 *   fe_values_dgrt[velocities].get_function_values(darcy_velocity,
1635 *   velocity_values);
1636 *   double L2_err_velocity_cell_sqr_local = 0;
1637 *   for (unsigned int q = 0; q < n_q_points_dgrt; ++q)
1638 *   {
1639 *   const Tensor<1, dim> velocity = velocity_values[q];
1640 *   const Tensor<1, dim> true_velocity =
1641 *   exact_velocity.value(fe_values_dgrt.quadrature_point(q));
1642 *  
1643 *   L2_err_velocity_cell_sqr_local +=
1644 *   ((velocity - true_velocity) * (velocity - true_velocity) *
1645 *   fe_values_dgrt.JxW(q));
1646 *   }
1647 *   L2_err_velocity_cell_sqr_global += L2_err_velocity_cell_sqr_local;
1648 *  
1649 * @endcode
1650 *
1651 * For reconstructing the flux we need the size of cells and
1652 * faces. Since fluxes are calculated on faces, we have the
1653 * loop over all four faces of each cell. To calculate the
1654 * face velocity, we extract values at the quadrature points from the
1655 * `darcy_velocity` which we have computed previously. Then, we
1656 * calculate the squared velocity error in normal direction. Finally, we
1657 * calculate the @f$L_2@f$ flux error on the cell by appropriately scaling
1658 * with face and cell areas and add it to the global error.
1659 *
1660 * @code
1661 *   const double cell_area = cell_dgrt->measure();
1662 *   for (const auto &face_dgrt : cell_dgrt->face_iterators())
1663 *   {
1664 *   const double face_length = face_dgrt->measure();
1665 *   fe_face_values_dgrt.reinit(cell_dgrt, face_dgrt);
1666 *   fe_face_values_dgrt[velocities].get_function_values(
1667 *   darcy_velocity, velocity_face_values);
1668 *  
1669 *   double L2_err_flux_face_sqr_local = 0;
1670 *   for (unsigned int q = 0; q < n_face_q_points_dgrt; ++q)
1671 *   {
1672 *   const Tensor<1, dim> velocity = velocity_face_values[q];
1673 *   const Tensor<1, dim> true_velocity =
1674 *   exact_velocity.value(fe_face_values_dgrt.quadrature_point(q));
1675 *  
1676 *   const Tensor<1, dim> &normal =
1677 *   fe_face_values_dgrt.normal_vector(q);
1678 *  
1679 *   L2_err_flux_face_sqr_local +=
1680 *   ((velocity * normal - true_velocity * normal) *
1681 *   (velocity * normal - true_velocity * normal) *
1682 *   fe_face_values_dgrt.JxW(q));
1683 *   }
1684 *   const double err_flux_each_face =
1685 *   L2_err_flux_face_sqr_local / face_length * cell_area;
1686 *   L2_err_flux_sqr += err_flux_each_face;
1687 *   }
1688 *   }
1689 *  
1690 * @endcode
1691 *
1692 * After adding up errors over all cells and faces, we take the
1693 * square root and get the @f$L_2@f$ errors of velocity and
1694 * flux. These we output to screen.
1695 *
1696 * @code
1697 *   const double L2_err_velocity_cell =
1698 *   std::sqrt(L2_err_velocity_cell_sqr_global);
1699 *   const double L2_err_flux_face = std::sqrt(L2_err_flux_sqr);
1700 *  
1701 *   std::cout << "L2_error_vel: " << L2_err_velocity_cell << std::endl
1702 *   << "L2_error_flux: " << L2_err_flux_face << std::endl;
1703 *   }
1704 *  
1705 *  
1706 * @endcode
1707 *
1708 *
1709 * <a name="step_61-WGDarcyEquationoutput_results"></a>
1710 * <h4>WGDarcyEquation::output_results</h4>
1711 *
1712
1713 *
1714 * We have two sets of results to output: the interior solution and
1715 * the skeleton solution. We use <code>DataOut</code> to visualize
1716 * interior results. The graphical output for the skeleton results
1717 * is done by using the DataOutFaces class.
1718 *
1719
1720 *
1721 * In both of the output files, both the interior and the face
1722 * variables are stored. For the interface output, the output file
1723 * simply contains the interpolation of the interior pressures onto
1724 * the faces, but because it is undefined which of the two interior
1725 * pressure variables you get from the two adjacent cells, it is
1726 * best to ignore the interior pressure in the interface output
1727 * file. Conversely, for the cell interior output file, it is of
1728 * course impossible to show any interface pressures @f$p^\partial@f$,
1729 * because these are only available on interfaces and not cell
1730 * interiors. Consequently, you will see them shown as an invalid
1731 * value (such as an infinity).
1732 *
1733
1734 *
1735 * For the cell interior output, we also want to output the velocity
1736 * variables. This is a bit tricky since it lives on the same mesh
1737 * but uses a different DoFHandler object (the pressure variables live
1738 * on the `dof_handler` object, the Darcy velocity on the `dof_handler_dgrt`
1739 * object). Fortunately, there are variations of the
1740 * DataOut::add_data_vector() function that allow specifying which
1741 * DoFHandler a vector corresponds to, and consequently we can visualize
1742 * the data from both DoFHandler objects within the same file.
1743 *
1744 * @code
1745 *   template <int dim>
1746 *   void WGDarcyEquation<dim>::output_results() const
1747 *   {
1748 *   {
1749 *   DataOut<dim> data_out;
1750 *  
1751 * @endcode
1752 *
1753 * First attach the pressure solution to the DataOut object:
1754 *
1755 * @code
1756 *   const std::vector<std::string> solution_names = {"interior_pressure",
1757 *   "interface_pressure"};
1758 *   data_out.add_data_vector(dof_handler, solution, solution_names);
1759 *  
1760 * @endcode
1761 *
1762 * Then do the same with the Darcy velocity field, and continue
1763 * with writing everything out into a file.
1764 *
1765 * @code
1766 *   const std::vector<std::string> velocity_names(dim, "velocity");
1767 *   const std::vector<
1769 *   velocity_component_interpretation(
1771 *   data_out.add_data_vector(dof_handler_dgrt,
1772 *   darcy_velocity,
1773 *   velocity_names,
1774 *   velocity_component_interpretation);
1775 *  
1776 *   data_out.build_patches(fe.degree);
1777 *   std::ofstream output("solution_interior.vtu");
1778 *   data_out.write_vtu(output);
1779 *   }
1780 *  
1781 *   {
1782 *   DataOutFaces<dim> data_out_faces(false);
1783 *   data_out_faces.attach_dof_handler(dof_handler);
1784 *   data_out_faces.add_data_vector(solution, "Pressure_Face");
1785 *   data_out_faces.build_patches(fe.degree);
1786 *   std::ofstream face_output("solution_interface.vtu");
1787 *   data_out_faces.write_vtu(face_output);
1788 *   }
1789 *   }
1790 *  
1791 *  
1792 * @endcode
1793 *
1794 *
1795 * <a name="step_61-WGDarcyEquationrun"></a>
1796 * <h4>WGDarcyEquation::run</h4>
1797 *
1798
1799 *
1800 * This is the final function of the main class. It calls the other functions
1801 * of our class.
1802 *
1803 * @code
1804 *   template <int dim>
1805 *   void WGDarcyEquation<dim>::run()
1806 *   {
1807 *   std::cout << "Solving problem in " << dim << " space dimensions."
1808 *   << std::endl;
1809 *   make_grid();
1810 *   setup_system();
1811 *   assemble_system();
1812 *   solve();
1813 *   compute_postprocessed_velocity();
1814 *   compute_pressure_error();
1815 *   compute_velocity_errors();
1816 *   output_results();
1817 *   }
1818 *  
1819 *   } // namespace Step61
1820 *  
1821 *  
1822 * @endcode
1823 *
1824 *
1825 * <a name="step_61-Thecodemaincodefunction"></a>
1826 * <h3>The <code>main</code> function</h3>
1827 *
1828
1829 *
1830 * This is the main function. We can change the dimension here to run in 3d.
1831 *
1832 * @code
1833 *   int main()
1834 *   {
1835 *   try
1836 *   {
1837 *   Step61::WGDarcyEquation<2> wg_darcy(0);
1838 *   wg_darcy.run();
1839 *   }
1840 *   catch (std::exception &exc)
1841 *   {
1842 *   std::cerr << std::endl
1843 *   << std::endl
1844 *   << "----------------------------------------------------"
1845 *   << std::endl;
1846 *   std::cerr << "Exception on processing: " << std::endl
1847 *   << exc.what() << std::endl
1848 *   << "Aborting!" << std::endl
1849 *   << "----------------------------------------------------"
1850 *   << std::endl;
1851 *   return 1;
1852 *   }
1853 *   catch (...)
1854 *   {
1855 *   std::cerr << std::endl
1856 *   << std::endl
1857 *   << "----------------------------------------------------"
1858 *   << std::endl;
1859 *   std::cerr << "Unknown exception!" << std::endl
1860 *   << "Aborting!" << std::endl
1861 *   << "----------------------------------------------------"
1862 *   << std::endl;
1863 *   return 1;
1864 *   }
1865 *  
1866 *   return 0;
1867 *   }
1868 * @endcode
1869<a name="step_61-Results"></a><h1>Results</h1>
1870
1871
1872We run the program with a right hand side that will produce the
1873solution @f$p = \sin(\pi x) \sin(\pi y)@f$ and with homogeneous Dirichlet
1874boundary conditions in the domain @f$\Omega = (0,1)^2@f$. In addition, we
1875choose the coefficient matrix in the differential operator
1876@f$\mathbf{K}@f$ as the identity matrix. We test this setup using
1877@f$\mbox{WG}(Q_0,Q_0;RT_{[0]})@f$, @f$\mbox{WG}(Q_1,Q_1;RT_{[1]})@f$ and
1878@f$\mbox{WG}(Q_2,Q_2;RT_{[2]})@f$ element combinations, which one can
1879select by using the appropriate constructor argument for the
1880`WGDarcyEquation` object in `main()`. We will then visualize pressure
1881values in interiors of cells and on faces. We want to see that the
1882pressure maximum is around 1 and the minimum is around 0. With mesh
1883refinement, the convergence rates of pressure, velocity and flux
1884should then be around 1 for @f$\mbox{WG}(Q_0,Q_0;RT_{[0]})@f$ , 2 for
1885@f$\mbox{WG}(Q_1,Q_1;RT_{[1]})@f$, and 3 for
1886@f$\mbox{WG}(Q_2,Q_2;RT_{[2]})@f$.
1887
1888
1889<a name="step_61-TestresultsoniWGQsub0subQsub0subRTsub0subi"></a><h3>Test results on <i>WG(Q<sub>0</sub>,Q<sub>0</sub>;RT<sub>[0]</sub>)</i></h3>
1890
1891
1892The following figures show interior pressures and face pressures using the
1893@f$\mbox{WG}(Q_0,Q_0;RT_{[0]})@f$ element. The mesh is refined 2 times (top)
1894and 4 times (bottom), respectively. (This number can be adjusted in the
1895`make_grid()` function.) When the mesh is coarse, one can see
1896the face pressures @f$p^\partial@f$ neatly between the values of the interior
1897pressures @f$p^\circ@f$ on the two adjacent cells.
1898
1899<table align="center">
1900 <tr>
1901 <td><img src="https://www.dealii.org/images/steps/developer/step-61.wg000_2d_2.png" alt=""></td>
1902 <td><img src="https://www.dealii.org/images/steps/developer/step-61.wg000_3d_2.png" alt=""></td>
1903 </tr>
1904 <tr>
1905 <td><img src="https://www.dealii.org/images/steps/developer/step-61.wg000_2d_4.png" alt=""></td>
1906 <td><img src="https://www.dealii.org/images/steps/developer/step-61.wg000_3d_4.png" alt=""></td>
1907 </tr>
1908</table>
1909
1910From the figures, we can see that with the mesh refinement, the maximum and
1911minimum pressure values are approaching the values we expect.
1912Since the mesh is a rectangular mesh and numbers of cells in each direction is even, we
1913have symmetric solutions. From the 3d figures on the right,
1914we can see that on @f$\mbox{WG}(Q_0,Q_0;RT_{[0]})@f$, the pressure is a constant
1915in the interior of the cell, as expected.
1916
1917<a name="step_61-Convergencetableforik0i"></a><h4>Convergence table for <i>k=0</i></h4>
1918
1919
1920We run the code with differently refined meshes (chosen in the `make_grid()` function)
1921and get the following convergence rates of pressure,
1922velocity, and flux (as defined in the introduction).
1923
1924<table align="center" class="doxtable">
1925 <tr>
1926 <th>number of refinements </th><th> @f$\|p-p_h^\circ\|@f$ </th><th> @f$\|\mathbf{u}-\mathbf{u}_h\|@f$ </th><th> @f$\|(\mathbf{u}-\mathbf{u}_h) \cdot \mathbf{n}\|@f$ </th>
1927 </tr>
1928 <tr>
1929 <td> 2 </td><td> 1.587e-01 </td><td> 5.113e-01 </td><td> 7.062e-01 </td>
1930 </tr>
1931 <tr>
1932 <td> 3 </td><td> 8.000e-02 </td><td> 2.529e-01 </td><td> 3.554e-01 </td>
1933 </tr>
1934 <tr>
1935 <td> 4 </td><td> 4.006e-02 </td><td> 1.260e-01 </td><td> 1.780e-01 </td>
1936 </tr>
1937 <tr>
1938 <td> 5 </td><td> 2.004e-02 </td><td> 6.297e-02 </td><td> 8.902e-02 </td>
1939 </tr>
1940 <tr>
1941 <th>Conv.rate </th><th> 1.00 </th><th> 1.00 </th><th> 1.00 </th>
1942 </tr>
1943</table>
1944
1945We can see that the convergence rates of @f$\mbox{WG}(Q_0,Q_0;RT_{[0]})@f$ are around 1.
1946This, of course, matches our theoretical expectations.
1947
1948
1949<a name="step_61-TestresultsoniWGQsub1subQsub1subRTsub1subi"></a><h3>Test results on <i>WG(Q<sub>1</sub>,Q<sub>1</sub>;RT<sub>[1]</sub>)</i></h3>
1950
1951
1952We can repeat the experiment from above using the next higher polynomial
1953degree:
1954The following figures are interior pressures and face pressures implemented using
1955@f$\mbox{WG}(Q_1,Q_1;RT_{[1]})@f$. The mesh is refined 4 times. Compared to the
1956previous figures using
1957@f$\mbox{WG}(Q_0,Q_0;RT_{[0]})@f$, on each cell, the solution is no longer constant
1958on each cell, as we now use bilinear polynomials to do the approximation.
1959Consequently, there are 4 pressure values in one interior, 2 pressure values on
1960each face.
1961
1962<table align="center">
1963 <tr>
1964 <td><img src="https://www.dealii.org/images/steps/developer/step-61.wg111_2d_4.png" alt=""></td>
1965 <td><img src="https://www.dealii.org/images/steps/developer/step-61.wg111_3d_4.png" alt=""></td>
1966 </tr>
1967</table>
1968
1969Compared to the corresponding image for the @f$\mbox{WG}(Q_0,Q_0;RT_{[0]})@f$
1970combination, the solution is now substantially more accurate and, in
1971particular so close to being continuous at the interfaces that we can
1972no longer distinguish the interface pressures @f$p^\partial@f$ from the
1973interior pressures @f$p^\circ@f$ on the adjacent cells.
1974
1975<a name="step_61-Convergencetableforik1i"></a><h4>Convergence table for <i>k=1</i></h4>
1976
1977
1978The following are the convergence rates of pressure, velocity, and flux
1979we obtain from using the @f$\mbox{WG}(Q_1,Q_1;RT_{[1]})@f$ element combination:
1980
1981<table align="center" class="doxtable">
1982 <tr>
1983 <th>number of refinements </th><th> @f$\|p-p_h^\circ\|@f$ </th><th> @f$\|\mathbf{u}-\mathbf{u}_h\|@f$ </th><th> @f$\|(\mathbf{u}-\mathbf{u}_h) \cdot \mathbf{n}\|@f$ </th>
1984 </tr>
1985 <tr>
1986 <td> 2 </td><td> 1.613e-02 </td><td> 5.093e-02 </td><td> 7.167e-02 </td>
1987 </tr>
1988 <tr>
1989 <td> 3 </td><td> 4.056e-03 </td><td> 1.276e-02 </td><td> 1.802e-02 </td>
1990 </tr>
1991 <tr>
1992 <td> 4 </td><td> 1.015e-03 </td><td> 3.191e-03 </td><td> 4.512e-03 </td>
1993 </tr>
1994 <tr>
1995 <td> 5 </td><td> 2.540e-04 </td><td> 7.979e-04 </td><td> 1.128e-03 </td>
1996 </tr>
1997 <tr>
1998 <th>Conv.rate </th><th> 2.00 </th><th> 2.00 </th><th> 2.00 </th>
1999 </tr>
2000</table>
2001
2002The convergence rates of @f$WG(Q_1,Q_1;RT_{[1]})@f$ are around 2, as expected.
2003
2004
2005
2006<a name="step_61-TestresultsoniWGQsub2subQsub2subRTsub2subi"></a><h3>Test results on <i>WG(Q<sub>2</sub>,Q<sub>2</sub>;RT<sub>[2]</sub>)</i></h3>
2007
2008
2009Let us go one polynomial degree higher.
2010The following are interior pressures and face pressures implemented using
2011@f$WG(Q_2,Q_2;RT_{[2]})@f$, with mesh size @f$h = 1/32@f$ (i.e., 5 global mesh
2012refinement steps). In the program, we use
2013`data_out_face.build_patches(fe.degree)` when generating graphical output
2014(see the documentation of DataOut::build_patches()), which here implies that
2015we divide each 2d cell interior into 4 subcells in order to provide a better
2016visualization of the quadratic polynomials.
2017<table align="center">
2018 <tr>
2019 <td><img src="https://www.dealii.org/images/steps/developer/step-61.wg222_2d_5.png" alt=""></td>
2020 <td><img src="https://www.dealii.org/images/steps/developer/step-61.wg222_3d_5.png" alt=""></td>
2021 </tr>
2022</table>
2023
2024
2025<a name="step_61-Convergencetableforik2i"></a><h4>Convergence table for <i>k=2</i></h4>
2026
2027
2028As before, we can generate convergence data for the
2029@f$L_2@f$ errors of pressure, velocity, and flux
2030using the @f$\mbox{WG}(Q_2,Q_2;RT_{[2]})@f$ combination:
2031
2032<table align="center" class="doxtable">
2033 <tr>
2034 <th>number of refinements </th><th> @f$\|p-p_h^\circ\|@f$ </th><th> @f$\|\mathbf{u}-\mathbf{u}_h\|@f$ </th><th> @f$\|(\mathbf{u}-\mathbf{u}_h) \cdot \mathbf{n}\|@f$ </th>
2035 </tr>
2036 <tr>
2037 <td> 2 </td><td> 1.072e-03 </td><td> 3.375e-03 </td><td> 4.762e-03 </td>
2038 </tr>
2039 <tr>
2040 <td> 3 </td><td> 1.347e-04 </td><td> 4.233e-04 </td><td> 5.982e-04 </td>
2041 </tr>
2042 <tr>
2043 <td> 4 </td><td> 1.685e-05 </td><td> 5.295e-05 </td><td> 7.487e-05 </td>
2044 </tr>
2045 <tr>
2046 <td> 5 </td><td> 2.107e-06 </td><td> 6.620e-06 </td><td> 9.362e-06 </td>
2047 </tr>
2048 <tr>
2049 <th>Conv.rate </th><th> 3.00 </th><th> 3.00 </th><th> 3.00 </th>
2050 </tr>
2051</table>
2052
2053Once more, the convergence rates of @f$\mbox{WG}(Q_2,Q_2;RT_{[2]})@f$ is
2054as expected, with values around 3.
2055 *
2056 *
2057<a name="step_61-PlainProg"></a>
2058<h1> The plain program</h1>
2059@include "step-61.cc"
2060*/
std::vector< bool > component_mask
void add_data_vector(const VectorType &data, const std::vector< std::string > &names, const DataVectorType type=type_automatic, const std::vector< DataComponentInterpretation::DataComponentInterpretation > &data_component_interpretation={})
virtual void build_patches(const unsigned int n_subdivisions=0)
Definition data_out.cc:1062
const unsigned int dofs_per_cell
const SmartPointer< const FiniteElement< dim, spacedim >, FEValuesBase< dim, spacedim > > fe
const Quadrature< dim > quadrature
Definition fe_values.h:172
void reinit(const TriaIterator< DoFCellAccessor< dim, spacedim, level_dof_access > > &cell)
void gauss_jordan()
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
Definition point.h:111
virtual value_type value(const Point< dim > &p) const
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
Point< 2 > first
Definition grid_out.cc:4623
typename ActiveSelector::active_cell_iterator active_cell_iterator
void loop(IteratorType begin, std_cxx20::type_identity_t< IteratorType > end, DOFINFO &dinfo, INFOBOX &info, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(std_cxx20::type_identity_t< DOFINFO > &, std_cxx20::type_identity_t< DOFINFO > &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, AssemblerType &assembler, const LoopControl &lctrl=LoopControl())
Definition loop.h:564
void make_sparsity_pattern(const DoFHandler< dim, spacedim > &dof_handler, SparsityPatternBase &sparsity_pattern, const AffineConstraints< number > &constraints={}, const bool keep_constrained_dofs=true, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id)
@ 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.
CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt K
void approximate(const SynchronousIterators< std::tuple< typename DoFHandler< dim, spacedim >::active_cell_iterator, Vector< float >::iterator > > &cell, const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof_handler, const InputVector &solution, const unsigned int component)
void interpolate(const DoFHandler< dim, spacedim > &dof1, const InVector &u1, const DoFHandler< dim, spacedim > &dof2, OutVector &u2)
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
void refine(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold, const unsigned int max_to_mark=numbers::invalid_unsigned_int)
@ matrix
Contents is actually a matrix.
@ symmetric
Matrix is symmetric.
double norm(const FEValuesBase< dim > &fe, const ArrayView< const std::vector< Tensor< 1, dim > > > &Du)
Definition divergence.h:471
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:191
SymmetricTensor< 2, dim, Number > E(const Tensor< 2, dim, Number > &F)
Tensor< 2, dim, Number > w(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
constexpr ReturnType< rank, T >::value_type & extract(T &t, const ArrayType &indices)
void interpolate_boundary_values(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const std::map< types::boundary_id, const Function< spacedim, number > * > &function_map, std::map< types::global_dof_index, number > &boundary_values, const ComponentMask &component_mask={})
void integrate_difference(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const ReadVector< Number > &fe_function, const Function< spacedim, Number > &exact_solution, OutVector &difference, const Quadrature< dim > &q, const NormType &norm, const Function< spacedim, double > *weight=nullptr, const double exponent=2.)
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)
void copy(const T *begin, const T *end, U *dest)
int(&) functions(const void *v1, const void *v2)
void assemble(const MeshWorker::DoFInfoBox< dim, DOFINFO > &dinfo, A *assembler)
Definition loop.h:70
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
static constexpr double PI
Definition numbers.h:254
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation