deal.II version GIT relicensing-2173-gae8fc9d14b 2024-11-24 06:40: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-14.h
Go to the documentation of this file.
1) const
746 *   {
747 *   std::ofstream out(output_name_base + "-" +
748 *   std::to_string(this->refinement_cycle) + ".svg");
749 *   GridOut().write_svg(dof_handler.get_triangulation(), out);
750 *   }
751 *   } // namespace Evaluation
752 *  
753 *  
754 * @endcode
755 *
756 *
757 * <a name="step_14-TheLaplacesolverclasses"></a>
758 * <h3>The Laplace solver classes</h3>
759 *
760
761 *
762 * Next are the actual solver classes. Again, we discuss only the
763 * differences to the previous program.
764 *
765 * @code
766 *   namespace LaplaceSolver
767 *   {
768 * @endcode
769 *
770 *
771 * <a name="step_14-TheLaplacesolverbaseclass"></a>
772 * <h4>The Laplace solver base class</h4>
773 *
774
775 *
776 * This class is almost unchanged, with the exception that it declares two
777 * more functions: <code>output_solution</code> will be used to generate
778 * output files from the actual solutions computed by derived classes, and
779 * the <code>set_refinement_cycle</code> function by which the testing
780 * framework sets the number of the refinement cycle to a local variable
781 * in this class; this number is later used to generate filenames for the
782 * solution output.
783 *
784 * @code
785 *   template <int dim>
786 *   class Base
787 *   {
788 *   public:
789 *   Base(Triangulation<dim> &coarse_grid);
790 *   virtual ~Base() = default;
791 *  
792 *   virtual void solve_problem() = 0;
793 *   virtual void postprocess(
794 *   const Evaluation::EvaluationBase<dim> &postprocessor) const = 0;
795 *   virtual void refine_grid() = 0;
796 *   virtual unsigned int n_dofs() const = 0;
797 *  
798 *   virtual void set_refinement_cycle(const unsigned int cycle);
799 *  
800 *   virtual void output_solution() const = 0;
801 *  
802 *   protected:
804 *  
805 *   unsigned int refinement_cycle;
806 *   };
807 *  
808 *  
809 *   template <int dim>
810 *   Base<dim>::Base(Triangulation<dim> &coarse_grid)
811 *   : triangulation(&coarse_grid)
812 *   , refinement_cycle(numbers::invalid_unsigned_int)
813 *   {}
814 *  
815 *  
816 *  
817 *   template <int dim>
818 *   void Base<dim>::set_refinement_cycle(const unsigned int cycle)
819 *   {
820 *   refinement_cycle = cycle;
821 *   }
822 *  
823 *  
824 * @endcode
825 *
826 *
827 * <a name="step_14-TheLaplaceSolverclass"></a>
828 * <h4>The Laplace Solver class</h4>
829 *
830
831 *
832 * Likewise, the <code>Solver</code> class is entirely unchanged and will
833 * thus not be discussed.
834 *
835 * @code
836 *   template <int dim>
837 *   class Solver : public virtual Base<dim>
838 *   {
839 *   public:
841 *   const FiniteElement<dim> &fe,
842 *   const Quadrature<dim> &quadrature,
843 *   const Quadrature<dim - 1> &face_quadrature,
844 *   const Function<dim> &boundary_values);
845 *   virtual ~Solver() override;
846 *  
847 *   virtual void solve_problem() override;
848 *  
849 *   virtual void postprocess(
850 *   const Evaluation::EvaluationBase<dim> &postprocessor) const override;
851 *  
852 *   virtual unsigned int n_dofs() const override;
853 *  
854 *   protected:
856 *   const ObserverPointer<const Quadrature<dim>> quadrature;
857 *   const ObserverPointer<const Quadrature<dim - 1>> face_quadrature;
858 *   DoFHandler<dim> dof_handler;
859 *   Vector<double> solution;
860 *   const ObserverPointer<const Function<dim>> boundary_values;
861 *  
862 *   virtual void assemble_rhs(Vector<double> &rhs) const = 0;
863 *  
864 *   private:
865 *   struct LinearSystem
866 *   {
867 *   LinearSystem(const DoFHandler<dim> &dof_handler);
868 *  
869 *   void solve(Vector<double> &solution) const;
870 *  
871 *   AffineConstraints<double> hanging_node_constraints;
872 *   SparsityPattern sparsity_pattern;
874 *   Vector<double> rhs;
875 *   };
876 *  
877 *  
878 * @endcode
879 *
880 * The remainder of the class is essentially a copy of @ref step_13 "step-13"
881 * as well, including the data structures and functions
882 * necessary to compute the linear system in parallel using the
883 * WorkStream framework:
884 *
885 * @code
886 *   struct AssemblyScratchData
887 *   {
888 *   AssemblyScratchData(const FiniteElement<dim> &fe,
889 *   const Quadrature<dim> &quadrature);
890 *   AssemblyScratchData(const AssemblyScratchData &scratch_data);
891 *  
892 *   FEValues<dim> fe_values;
893 *   };
894 *  
895 *   struct AssemblyCopyData
896 *   {
898 *   std::vector<types::global_dof_index> local_dof_indices;
899 *   };
900 *  
901 *  
902 *   void assemble_linear_system(LinearSystem &linear_system);
903 *  
904 *   void local_assemble_matrix(
905 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
906 *   AssemblyScratchData &scratch_data,
907 *   AssemblyCopyData &copy_data) const;
908 *  
909 *  
910 *   void copy_local_to_global(const AssemblyCopyData &copy_data,
911 *   LinearSystem &linear_system) const;
912 *   };
913 *  
914 *  
915 *  
916 *   template <int dim>
917 *   Solver<dim>::Solver(Triangulation<dim> &triangulation,
918 *   const FiniteElement<dim> &fe,
919 *   const Quadrature<dim> &quadrature,
920 *   const Quadrature<dim - 1> &face_quadrature,
921 *   const Function<dim> &boundary_values)
922 *   : Base<dim>(triangulation)
923 *   , fe(&fe)
924 *   , quadrature(&quadrature)
925 *   , face_quadrature(&face_quadrature)
926 *   , dof_handler(triangulation)
927 *   , boundary_values(&boundary_values)
928 *   {}
929 *  
930 *  
931 *   template <int dim>
932 *   Solver<dim>::~Solver()
933 *   {
934 *   dof_handler.clear();
935 *   }
936 *  
937 *  
938 *   template <int dim>
939 *   void Solver<dim>::solve_problem()
940 *   {
941 *   dof_handler.distribute_dofs(*fe);
942 *   solution.reinit(dof_handler.n_dofs());
943 *  
944 *   LinearSystem linear_system(dof_handler);
945 *   assemble_linear_system(linear_system);
946 *   linear_system.solve(solution);
947 *   }
948 *  
949 *  
950 *   template <int dim>
951 *   void Solver<dim>::postprocess(
952 *   const Evaluation::EvaluationBase<dim> &postprocessor) const
953 *   {
954 *   postprocessor(dof_handler, solution);
955 *   }
956 *  
957 *  
958 *   template <int dim>
959 *   unsigned int Solver<dim>::n_dofs() const
960 *   {
961 *   return dof_handler.n_dofs();
962 *   }
963 *  
964 *  
965 * @endcode
966 *
967 * The following few functions and constructors are verbatim
968 * copies taken from @ref step_13 "step-13":
969 *
970 * @code
971 *   template <int dim>
972 *   void Solver<dim>::assemble_linear_system(LinearSystem &linear_system)
973 *   {
974 *   Threads::Task<void> rhs_task =
975 *   Threads::new_task(&Solver<dim>::assemble_rhs, *this, linear_system.rhs);
976 *  
977 *   auto worker =
978 *   [this](const typename DoFHandler<dim>::active_cell_iterator &cell,
979 *   AssemblyScratchData &scratch_data,
980 *   AssemblyCopyData &copy_data) {
981 *   this->local_assemble_matrix(cell, scratch_data, copy_data);
982 *   };
983 *  
984 *   auto copier = [this, &linear_system](const AssemblyCopyData &copy_data) {
985 *   this->copy_local_to_global(copy_data, linear_system);
986 *   };
987 *  
988 *   WorkStream::run(dof_handler.begin_active(),
989 *   dof_handler.end(),
990 *   worker,
991 *   copier,
992 *   AssemblyScratchData(*fe, *quadrature),
993 *   AssemblyCopyData());
994 *   linear_system.hanging_node_constraints.condense(linear_system.matrix);
995 *  
996 *   std::map<types::global_dof_index, double> boundary_value_map;
998 *   0,
999 *   *boundary_values,
1000 *   boundary_value_map);
1001 *  
1002 *   rhs_task.join();
1003 *   linear_system.hanging_node_constraints.condense(linear_system.rhs);
1004 *  
1005 *   MatrixTools::apply_boundary_values(boundary_value_map,
1006 *   linear_system.matrix,
1007 *   solution,
1008 *   linear_system.rhs);
1009 *   }
1010 *  
1011 *  
1012 *   template <int dim>
1013 *   Solver<dim>::AssemblyScratchData::AssemblyScratchData(
1014 *   const FiniteElement<dim> &fe,
1015 *   const Quadrature<dim> &quadrature)
1016 *   : fe_values(fe, quadrature, update_gradients | update_JxW_values)
1017 *   {}
1018 *  
1019 *  
1020 *   template <int dim>
1021 *   Solver<dim>::AssemblyScratchData::AssemblyScratchData(
1022 *   const AssemblyScratchData &scratch_data)
1023 *   : fe_values(scratch_data.fe_values.get_fe(),
1024 *   scratch_data.fe_values.get_quadrature(),
1026 *   {}
1027 *  
1028 *  
1029 *   template <int dim>
1030 *   void Solver<dim>::local_assemble_matrix(
1031 *   const typename DoFHandler<dim>::active_cell_iterator &cell,
1032 *   AssemblyScratchData &scratch_data,
1033 *   AssemblyCopyData &copy_data) const
1034 *   {
1035 *   const unsigned int dofs_per_cell = fe->n_dofs_per_cell();
1036 *   const unsigned int n_q_points = quadrature->size();
1037 *  
1038 *   copy_data.cell_matrix.reinit(dofs_per_cell, dofs_per_cell);
1039 *  
1040 *   copy_data.local_dof_indices.resize(dofs_per_cell);
1041 *  
1042 *   scratch_data.fe_values.reinit(cell);
1043 *  
1044 *   for (unsigned int q_point = 0; q_point < n_q_points; ++q_point)
1045 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
1046 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
1047 *   copy_data.cell_matrix(i, j) +=
1048 *   (scratch_data.fe_values.shape_grad(i, q_point) *
1049 *   scratch_data.fe_values.shape_grad(j, q_point) *
1050 *   scratch_data.fe_values.JxW(q_point));
1051 *  
1052 *   cell->get_dof_indices(copy_data.local_dof_indices);
1053 *   }
1054 *  
1055 *  
1056 *  
1057 *   template <int dim>
1058 *   void Solver<dim>::copy_local_to_global(const AssemblyCopyData &copy_data,
1059 *   LinearSystem &linear_system) const
1060 *   {
1061 *   for (unsigned int i = 0; i < copy_data.local_dof_indices.size(); ++i)
1062 *   for (unsigned int j = 0; j < copy_data.local_dof_indices.size(); ++j)
1063 *   linear_system.matrix.add(copy_data.local_dof_indices[i],
1064 *   copy_data.local_dof_indices[j],
1065 *   copy_data.cell_matrix(i, j));
1066 *   }
1067 *  
1068 *  
1069 * @endcode
1070 *
1071 * Now for the functions that implement actions in the linear
1072 * system class. First, the constructor initializes all data
1073 * elements to their correct sizes, and sets up a number of
1074 * additional data structures, such as constraints due to hanging
1075 * nodes. Since setting up the hanging nodes and finding out about
1076 * the nonzero elements of the matrix is independent, we do that
1077 * in parallel (if the library was configured to use concurrency,
1078 * at least; otherwise, the actions are performed
1079 * sequentially). Note that we start only one thread, and do the
1080 * second action in the main thread. Since only one thread is
1081 * generated, we don't use the <code>Threads::TaskGroup</code>
1082 * class here, but rather use the one created task object
1083 * directly to wait for this particular task's exit. The
1084 * approach is generally the same as the one we have used in
1085 * <code>Solver::assemble_linear_system()</code> above.
1086 *
1087
1088 *
1089 * Note that taking the address of the
1090 * <code>DoFTools::make_hanging_node_constraints</code> function
1091 * is a little tricky, since there are actually three functions of
1092 * this name, one for each supported space dimension. Taking
1093 * addresses of overloaded functions is somewhat complicated in
1094 * C++, since the address-of operator <code>&</code> in that case
1095 * returns a set of values (the addresses of all
1096 * functions with that name), and selecting the right one is then
1097 * the next step. If the context dictates which one to take (for
1098 * example by assigning to a function pointer of known type), then
1099 * the compiler can do that by itself, but if this set of pointers
1100 * shall be given as the argument to a function that takes a
1101 * template, the compiler could choose all without having a
1102 * preference for one. We therefore have to make it clear to the
1103 * compiler which one we would like to have; for this, we could
1104 * use a cast, but for more clarity, we assign it to a temporary
1105 * <code>mhnc_p</code> (short for <code>pointer to
1106 * make_hanging_node_constraints</code>) with the right type, and
1107 * using this pointer instead.
1108 *
1109 * @code
1110 *   template <int dim>
1111 *   Solver<dim>::LinearSystem::LinearSystem(const DoFHandler<dim> &dof_handler)
1112 *   {
1113 *   hanging_node_constraints.clear();
1114 *  
1115 *   void (*mhnc_p)(const DoFHandler<dim> &, AffineConstraints<double> &) =
1117 *  
1118 * @endcode
1119 *
1120 * Start a side task then continue on the main thread
1121 *
1122 * @code
1123 *   Threads::Task<void> side_task =
1124 *   Threads::new_task(mhnc_p, dof_handler, hanging_node_constraints);
1125 *  
1126 *   DynamicSparsityPattern dsp(dof_handler.n_dofs(), dof_handler.n_dofs());
1127 *   DoFTools::make_sparsity_pattern(dof_handler, dsp);
1128 *  
1129 *  
1130 *  
1131 * @endcode
1132 *
1133 * Wait for the side task to be done before going further
1134 *
1135 * @code
1136 *   side_task.join();
1137 *  
1138 *   hanging_node_constraints.close();
1139 *   hanging_node_constraints.condense(dsp);
1140 *   sparsity_pattern.copy_from(dsp);
1141 *  
1142 *   matrix.reinit(sparsity_pattern);
1143 *   rhs.reinit(dof_handler.n_dofs());
1144 *   }
1145 *  
1146 *  
1147 *  
1148 *   template <int dim>
1149 *   void Solver<dim>::LinearSystem::solve(Vector<double> &solution) const
1150 *   {
1151 *   SolverControl solver_control(5000, 1e-12);
1152 *   SolverCG<Vector<double>> cg(solver_control);
1153 *  
1154 *   PreconditionSSOR<SparseMatrix<double>> preconditioner;
1155 *   preconditioner.initialize(matrix, 1.2);
1156 *  
1157 *   cg.solve(matrix, solution, rhs, preconditioner);
1158 *  
1159 *   hanging_node_constraints.distribute(solution);
1160 *   }
1161 *  
1162 *  
1163 *  
1164 * @endcode
1165 *
1166 *
1167 * <a name="step_14-ThePrimalSolverclass"></a>
1168 * <h4>The PrimalSolver class</h4>
1169 *
1170
1171 *
1172 * The <code>PrimalSolver</code> class is also mostly unchanged except for
1173 * implementing the <code>output_solution</code> function. We keep the
1174 * <code>GlobalRefinement</code> and <code>RefinementKelly</code> classes
1175 * in this program, and they can then rely on the default implementation
1176 * of this function which simply outputs the primal solution. The class
1177 * implementing dual weighted error estimators will overload this function
1178 * itself, to also output the dual solution.
1179 *
1180 * @code
1181 *   template <int dim>
1182 *   class PrimalSolver : public Solver<dim>
1183 *   {
1184 *   public:
1185 *   PrimalSolver(Triangulation<dim> &triangulation,
1186 *   const FiniteElement<dim> &fe,
1187 *   const Quadrature<dim> &quadrature,
1188 *   const Quadrature<dim - 1> &face_quadrature,
1189 *   const Function<dim> &rhs_function,
1190 *   const Function<dim> &boundary_values);
1191 *  
1192 *   virtual void output_solution() const override;
1193 *  
1194 *   protected:
1195 *   const ObserverPointer<const Function<dim>> rhs_function;
1196 *   virtual void assemble_rhs(Vector<double> &rhs) const override;
1197 *   };
1198 *  
1199 *  
1200 *   template <int dim>
1201 *   PrimalSolver<dim>::PrimalSolver(Triangulation<dim> &triangulation,
1202 *   const FiniteElement<dim> &fe,
1203 *   const Quadrature<dim> &quadrature,
1204 *   const Quadrature<dim - 1> &face_quadrature,
1205 *   const Function<dim> &rhs_function,
1206 *   const Function<dim> &boundary_values)
1207 *   : Base<dim>(triangulation)
1208 *   , Solver<dim>(triangulation,
1209 *   fe,
1210 *   quadrature,
1211 *   face_quadrature,
1212 *   boundary_values)
1213 *   , rhs_function(&rhs_function)
1214 *   {}
1215 *  
1216 *  
1217 *  
1218 *   template <int dim>
1219 *   void PrimalSolver<dim>::output_solution() const
1220 *   {
1221 *   DataOut<dim> data_out;
1222 *   data_out.attach_dof_handler(this->dof_handler);
1223 *   data_out.add_data_vector(this->solution, "solution");
1224 *   data_out.build_patches();
1225 *  
1226 *   std::ofstream out("solution-" + std::to_string(this->refinement_cycle) +
1227 *   ".vtu");
1228 *   data_out.write(out, DataOutBase::vtu);
1229 *   }
1230 *  
1231 *  
1232 *  
1233 *   template <int dim>
1234 *   void PrimalSolver<dim>::assemble_rhs(Vector<double> &rhs) const
1235 *   {
1236 *   FEValues<dim> fe_values(*this->fe,
1237 *   *this->quadrature,
1239 *   update_JxW_values);
1240 *  
1241 *   const unsigned int dofs_per_cell = this->fe->n_dofs_per_cell();
1242 *   const unsigned int n_q_points = this->quadrature->size();
1243 *  
1244 *   Vector<double> cell_rhs(dofs_per_cell);
1245 *   std::vector<double> rhs_values(n_q_points);
1246 *   std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
1247 *  
1248 *   for (const auto &cell : this->dof_handler.active_cell_iterators())
1249 *   {
1250 *   cell_rhs = 0;
1251 *  
1252 *   fe_values.reinit(cell);
1253 *  
1254 *   rhs_function->value_list(fe_values.get_quadrature_points(),
1255 *   rhs_values);
1256 *  
1257 *   for (unsigned int q_point = 0; q_point < n_q_points; ++q_point)
1258 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
1259 *   cell_rhs(i) += (fe_values.shape_value(i, q_point) * // phi_i(x_q)
1260 *   rhs_values[q_point] * // f((x_q)
1261 *   fe_values.JxW(q_point)); // dx
1262 *  
1263 *   cell->get_dof_indices(local_dof_indices);
1264 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
1265 *   rhs(local_dof_indices[i]) += cell_rhs(i);
1266 *   }
1267 *   }
1268 *  
1269 *  
1270 * @endcode
1271 *
1272 *
1273 * <a name="step_14-TheRefinementGlobalandRefinementKellyclasses"></a>
1274 * <h4>The RefinementGlobal and RefinementKelly classes</h4>
1275 *
1276
1277 *
1278 * For the following two classes, the same applies as for most of the
1279 * above: the class is taken from the previous example as-is:
1280 *
1281 * @code
1282 *   template <int dim>
1283 *   class RefinementGlobal : public PrimalSolver<dim>
1284 *   {
1285 *   public:
1286 *   RefinementGlobal(Triangulation<dim> &coarse_grid,
1287 *   const FiniteElement<dim> &fe,
1288 *   const Quadrature<dim> &quadrature,
1289 *   const Quadrature<dim - 1> &face_quadrature,
1290 *   const Function<dim> &rhs_function,
1291 *   const Function<dim> &boundary_values);
1292 *  
1293 *   virtual void refine_grid() override;
1294 *   };
1295 *  
1296 *  
1297 *  
1298 *   template <int dim>
1299 *   RefinementGlobal<dim>::RefinementGlobal(
1300 *   Triangulation<dim> &coarse_grid,
1301 *   const FiniteElement<dim> &fe,
1302 *   const Quadrature<dim> &quadrature,
1303 *   const Quadrature<dim - 1> &face_quadrature,
1304 *   const Function<dim> &rhs_function,
1305 *   const Function<dim> &boundary_values)
1306 *   : Base<dim>(coarse_grid)
1307 *   , PrimalSolver<dim>(coarse_grid,
1308 *   fe,
1309 *   quadrature,
1310 *   face_quadrature,
1311 *   rhs_function,
1312 *   boundary_values)
1313 *   {}
1314 *  
1315 *  
1316 *  
1317 *   template <int dim>
1318 *   void RefinementGlobal<dim>::refine_grid()
1319 *   {
1320 *   this->triangulation->refine_global(1);
1321 *   }
1322 *  
1323 *  
1324 *  
1325 *   template <int dim>
1326 *   class RefinementKelly : public PrimalSolver<dim>
1327 *   {
1328 *   public:
1329 *   RefinementKelly(Triangulation<dim> &coarse_grid,
1330 *   const FiniteElement<dim> &fe,
1331 *   const Quadrature<dim> &quadrature,
1332 *   const Quadrature<dim - 1> &face_quadrature,
1333 *   const Function<dim> &rhs_function,
1334 *   const Function<dim> &boundary_values);
1335 *  
1336 *   virtual void refine_grid() override;
1337 *   };
1338 *  
1339 *  
1340 *  
1341 *   template <int dim>
1342 *   RefinementKelly<dim>::RefinementKelly(
1343 *   Triangulation<dim> &coarse_grid,
1344 *   const FiniteElement<dim> &fe,
1345 *   const Quadrature<dim> &quadrature,
1346 *   const Quadrature<dim - 1> &face_quadrature,
1347 *   const Function<dim> &rhs_function,
1348 *   const Function<dim> &boundary_values)
1349 *   : Base<dim>(coarse_grid)
1350 *   , PrimalSolver<dim>(coarse_grid,
1351 *   fe,
1352 *   quadrature,
1353 *   face_quadrature,
1354 *   rhs_function,
1355 *   boundary_values)
1356 *   {}
1357 *  
1358 *  
1359 *  
1360 *   template <int dim>
1361 *   void RefinementKelly<dim>::refine_grid()
1362 *   {
1363 *   Vector<float> estimated_error_per_cell(
1364 *   this->triangulation->n_active_cells());
1366 *   this->dof_handler,
1367 *   QGauss<dim - 1>(this->fe->degree + 1),
1368 *   std::map<types::boundary_id, const Function<dim> *>(),
1369 *   this->solution,
1370 *   estimated_error_per_cell);
1372 *   estimated_error_per_cell,
1373 *   0.3,
1374 *   0.03);
1375 *   this->triangulation->execute_coarsening_and_refinement();
1376 *   }
1377 *  
1378 *  
1379 *  
1380 * @endcode
1381 *
1382 *
1383 * <a name="step_14-TheRefinementWeightedKellyclass"></a>
1384 * <h4>The RefinementWeightedKelly class</h4>
1385 *
1386
1387 *
1388 * This class is a variant of the previous one, in that it allows to
1389 * weight the refinement indicators we get from the library's Kelly
1390 * indicator by some function. We include this class since the goal of
1391 * this example program is to demonstrate automatic refinement criteria
1392 * even for complex output quantities such as point values or stresses. If
1393 * we did not solve a dual problem and compute the weights thereof, we
1394 * would probably be tempted to give a hand-crafted weighting to the
1395 * indicators to account for the fact that we are going to evaluate these
1396 * quantities. This class accepts such a weighting function as argument to
1397 * its constructor:
1398 *
1399 * @code
1400 *   template <int dim>
1401 *   class RefinementWeightedKelly : public PrimalSolver<dim>
1402 *   {
1403 *   public:
1404 *   RefinementWeightedKelly(Triangulation<dim> &coarse_grid,
1405 *   const FiniteElement<dim> &fe,
1406 *   const Quadrature<dim> &quadrature,
1407 *   const Quadrature<dim - 1> &face_quadrature,
1408 *   const Function<dim> &rhs_function,
1409 *   const Function<dim> &boundary_values,
1410 *   const Function<dim> &weighting_function);
1411 *  
1412 *   virtual void refine_grid() override;
1413 *  
1414 *   private:
1415 *   const ObserverPointer<const Function<dim>> weighting_function;
1416 *   };
1417 *  
1418 *  
1419 *  
1420 *   template <int dim>
1421 *   RefinementWeightedKelly<dim>::RefinementWeightedKelly(
1422 *   Triangulation<dim> &coarse_grid,
1423 *   const FiniteElement<dim> &fe,
1424 *   const Quadrature<dim> &quadrature,
1425 *   const Quadrature<dim - 1> &face_quadrature,
1426 *   const Function<dim> &rhs_function,
1427 *   const Function<dim> &boundary_values,
1428 *   const Function<dim> &weighting_function)
1429 *   : Base<dim>(coarse_grid)
1430 *   , PrimalSolver<dim>(coarse_grid,
1431 *   fe,
1432 *   quadrature,
1433 *   face_quadrature,
1434 *   rhs_function,
1435 *   boundary_values)
1436 *   , weighting_function(&weighting_function)
1437 *   {}
1438 *  
1439 *  
1440 *  
1441 * @endcode
1442 *
1443 * Now, here comes the main function, including the weighting:
1444 *
1445 * @code
1446 *   template <int dim>
1447 *   void RefinementWeightedKelly<dim>::refine_grid()
1448 *   {
1449 * @endcode
1450 *
1451 * First compute some residual based error indicators for all cells by a
1452 * method already implemented in the library. What exactly we compute
1453 * here is described in more detail in the documentation of that class.
1454 *
1455 * @code
1456 *   Vector<float> estimated_error_per_cell(
1457 *   this->triangulation->n_active_cells());
1458 *   std::map<types::boundary_id, const Function<dim> *> dummy_function_map;
1459 *   KellyErrorEstimator<dim>::estimate(this->dof_handler,
1460 *   *this->face_quadrature,
1461 *   dummy_function_map,
1462 *   this->solution,
1463 *   estimated_error_per_cell);
1464 *  
1465 * @endcode
1466 *
1467 * Next weigh each entry in the vector of indicators by the value of the
1468 * function given to the constructor, evaluated at the cell center. We
1469 * need to write the result into the vector entry that corresponds to the
1470 * current cell, which we can obtain by asking the cell what its index
1471 * among all active cells is using CellAccessor::active_cell_index(). (In
1472 * reality, this index is zero for the first cell we handle in the loop,
1473 * one for the second cell, etc., and we could as well just keep track of
1474 * this index using an integer counter; but using
1475 * CellAccessor::active_cell_index() makes this more explicit.)
1476 *
1477 * @code
1478 *   for (const auto &cell : this->dof_handler.active_cell_iterators())
1479 *   estimated_error_per_cell(cell->active_cell_index()) *=
1480 *   weighting_function->value(cell->center());
1481 *  
1482 *   GridRefinement::refine_and_coarsen_fixed_number(*this->triangulation,
1483 *   estimated_error_per_cell,
1484 *   0.3,
1485 *   0.03);
1486 *   this->triangulation->execute_coarsening_and_refinement();
1487 *   }
1488 *  
1489 *   } // namespace LaplaceSolver
1490 *  
1491 *  
1492 * @endcode
1493 *
1494 *
1495 * <a name="step_14-Equationdata"></a>
1496 * <h3>Equation data</h3>
1497 *
1498
1499 *
1500 * In this example program, we work with the same data sets as in the
1501 * previous one, but as it may so happen that someone wants to run the
1502 * program with different boundary values and right hand side functions, or
1503 * on a different grid, we show a simple technique to do exactly that. For
1504 * more clarity, we furthermore pack everything that has to do with equation
1505 * data into a namespace of its own.
1506 *
1507
1508 *
1509 * The underlying assumption is that this is a research program, and that
1510 * there we often have a number of test cases that consist of a domain, a
1511 * right hand side, boundary values, possibly a specified coefficient, and a
1512 * number of other parameters. They often vary all at the same time when
1513 * shifting from one example to another. To make handling such sets of
1514 * problem description parameters simple is the goal of the following.
1515 *
1516
1517 *
1518 * Basically, the idea is this: let us have a structure for each set of
1519 * data, in which we pack everything that describes a test case: here, these
1520 * are two subclasses, one called <code>BoundaryValues</code> for the
1521 * boundary values of the exact solution, and one called
1522 * <code>RightHandSide</code>, and then a way to generate the coarse
1523 * grid. Since the solution of the previous example program looked like
1524 * curved ridges, we use this name here for the enclosing class. Note that
1525 * the names of the two inner classes have to be the same for all enclosing
1526 * test case classes, and also that we have attached the dimension template
1527 * argument to the enclosing class rather than to the inner ones, to make
1528 * further processing simpler. (From a language viewpoint, a namespace
1529 * would be better to encapsulate these inner classes, rather than a
1530 * structure. However, namespaces cannot be given as template arguments, so
1531 * we use a structure to allow a second object to select from within its
1532 * given argument. The enclosing structure, of course, has no member
1533 * variables apart from the classes it declares, and a static function to
1534 * generate the coarse mesh; it will in general never be instantiated.)
1535 *
1536
1537 *
1538 * The idea is then the following (this is the right time to also take a
1539 * brief look at the code below): we can generate objects for boundary
1540 * values and right hand side by simply giving the name of the outer class
1541 * as a template argument to a class which we call here
1542 * <code>Data::SetUp</code>, and it then creates objects for the inner
1543 * classes. In this case, to get all that characterizes the curved ridge
1544 * solution, we would simply generate an instance of
1545 * <code>Data::SetUp@<Data::CurvedRidge@></code>, and everything we need to
1546 * know about the solution would be static member variables and functions of
1547 * that object.
1548 *
1549
1550 *
1551 * This approach might seem like overkill in this case, but will become very
1552 * handy once a certain set up is not only characterized by Dirichlet
1553 * boundary values and a right hand side function, but in addition by
1554 * material properties, Neumann values, different boundary descriptors,
1555 * etc. In that case, the <code>SetUp</code> class might consist of a dozen
1556 * or more objects, and each descriptor class (like the
1557 * <code>CurvedRidges</code> class below) would have to provide them. Then,
1558 * you will be happy to be able to change from one set of data to another by
1559 * only changing the template argument to the <code>SetUp</code> class at
1560 * one place, rather than at many.
1561 *
1562
1563 *
1564 * With this framework for different test cases, we are almost finished, but
1565 * one thing remains: by now we can select statically, by changing one
1566 * template argument, which data set to choose. In order to be able to do
1567 * that dynamically, i.e. at run time, we need a base class. This we provide
1568 * in the obvious way, see below, with virtual abstract functions. It forces
1569 * us to introduce a second template parameter <code>dim</code> which we
1570 * need for the base class (which could be avoided using some template
1571 * magic, but we omit that), but that's all.
1572 *
1573
1574 *
1575 * Adding new testcases is now simple, you don't have to touch the framework
1576 * classes, only a structure like the <code>CurvedRidges</code> one is
1577 * needed.
1578 *
1579 * @code
1580 *   namespace Data
1581 *   {
1582 * @endcode
1583 *
1584 *
1585 * <a name="step_14-TheSetUpBaseandSetUpclasses"></a>
1586 * <h4>The SetUpBase and SetUp classes</h4>
1587 *
1588
1589 *
1590 * Based on the above description, the <code>SetUpBase</code> class then
1591 * looks as follows. To allow using the <code>ObserverPointer</code> class
1592 * with this class, we derived from the
1593 * <code>EnableObserverPointer</code> class.
1594 *
1595 * @code
1596 *   template <int dim>
1597 *   struct SetUpBase : public EnableObserverPointer
1598 *   {
1599 *   virtual const Function<dim> &get_boundary_values() const = 0;
1600 *  
1601 *   virtual const Function<dim> &get_right_hand_side() const = 0;
1602 *  
1603 *   virtual void
1604 *   create_coarse_grid(Triangulation<dim> &coarse_grid) const = 0;
1605 *   };
1606 *  
1607 *  
1608 * @endcode
1609 *
1610 * And now for the derived class that takes the template argument as
1611 * explained above.
1612 *
1613
1614 *
1615 * Here we pack the data elements into private variables, and allow access
1616 * to them through the methods of the base class.
1617 *
1618 * @code
1619 *   template <class Traits, int dim>
1620 *   struct SetUp : public SetUpBase<dim>
1621 *   {
1622 *   virtual const Function<dim> &get_boundary_values() const override;
1623 *  
1624 *   virtual const Function<dim> &get_right_hand_side() const override;
1625 *  
1626 *  
1627 *   virtual void
1628 *   create_coarse_grid(Triangulation<dim> &coarse_grid) const override;
1629 *  
1630 *   private:
1631 *   static const typename Traits::BoundaryValues boundary_values;
1632 *   static const typename Traits::RightHandSide right_hand_side;
1633 *   };
1634 *  
1635 * @endcode
1636 *
1637 * We have to provide definitions for the static member variables of the
1638 * above class:
1639 *
1640 * @code
1641 *   template <class Traits, int dim>
1642 *   const typename Traits::BoundaryValues SetUp<Traits, dim>::boundary_values;
1643 *   template <class Traits, int dim>
1644 *   const typename Traits::RightHandSide SetUp<Traits, dim>::right_hand_side;
1645 *  
1646 * @endcode
1647 *
1648 * And definitions of the member functions:
1649 *
1650 * @code
1651 *   template <class Traits, int dim>
1652 *   const Function<dim> &SetUp<Traits, dim>::get_boundary_values() const
1653 *   {
1654 *   return boundary_values;
1655 *   }
1656 *  
1657 *  
1658 *   template <class Traits, int dim>
1659 *   const Function<dim> &SetUp<Traits, dim>::get_right_hand_side() const
1660 *   {
1661 *   return right_hand_side;
1662 *   }
1663 *  
1664 *  
1665 *   template <class Traits, int dim>
1666 *   void SetUp<Traits, dim>::create_coarse_grid(
1667 *   Triangulation<dim> &coarse_grid) const
1668 *   {
1669 *   Traits::create_coarse_grid(coarse_grid);
1670 *   }
1671 *  
1672 *  
1673 * @endcode
1674 *
1675 *
1676 * <a name="step_14-TheCurvedRidgesclass"></a>
1677 * <h4>The CurvedRidges class</h4>
1678 *
1679
1680 *
1681 * The class that is used to describe the boundary values and right hand
1682 * side of the <code>curved ridge</code> problem already used in the
1683 * @ref step_13 "step-13" example program is then like so:
1684 *
1685 * @code
1686 *   template <int dim>
1687 *   struct CurvedRidges
1688 *   {
1689 *   class BoundaryValues : public Function<dim>
1690 *   {
1691 *   public:
1692 *   virtual double value(const Point<dim> &p,
1693 *   const unsigned int component) const;
1694 *   };
1695 *  
1696 *  
1697 *   class RightHandSide : public Function<dim>
1698 *   {
1699 *   public:
1700 *   virtual double value(const Point<dim> &p,
1701 *   const unsigned int component) const;
1702 *   };
1703 *  
1704 *   static void create_coarse_grid(Triangulation<dim> &coarse_grid);
1705 *   };
1706 *  
1707 *  
1708 *   template <int dim>
1709 *   double CurvedRidges<dim>::BoundaryValues::value(
1710 *   const Point<dim> &p,
1711 *   const unsigned int /*component*/) const
1712 *   {
1713 *   double q = p(0);
1714 *   for (unsigned int i = 1; i < dim; ++i)
1715 *   q += std::sin(10 * p(i) + 5 * p(0) * p(0));
1716 *   const double exponential = std::exp(q);
1717 *   return exponential;
1718 *   }
1719 *  
1720 *  
1721 *  
1722 *   template <int dim>
1723 *   double CurvedRidges<dim>::RightHandSide::value(
1724 *   const Point<dim> &p,
1725 *   const unsigned int /*component*/) const
1726 *   {
1727 *   double q = p(0);
1728 *   for (unsigned int i = 1; i < dim; ++i)
1729 *   q += std::sin(10 * p(i) + 5 * p(0) * p(0));
1730 *   const double u = std::exp(q);
1731 *   double t1 = 1, t2 = 0, t3 = 0;
1732 *   for (unsigned int i = 1; i < dim; ++i)
1733 *   {
1734 *   t1 += std::cos(10 * p(i) + 5 * p(0) * p(0)) * 10 * p(0);
1735 *   t2 += 10 * std::cos(10 * p(i) + 5 * p(0) * p(0)) -
1736 *   100 * std::sin(10 * p(i) + 5 * p(0) * p(0)) * p(0) * p(0);
1737 *   t3 += 100 * std::cos(10 * p(i) + 5 * p(0) * p(0)) *
1738 *   std::cos(10 * p(i) + 5 * p(0) * p(0)) -
1739 *   100 * std::sin(10 * p(i) + 5 * p(0) * p(0));
1740 *   }
1741 *   t1 = t1 * t1;
1742 *  
1743 *   return -u * (t1 + t2 + t3);
1744 *   }
1745 *  
1746 *  
1747 *   template <int dim>
1748 *   void CurvedRidges<dim>::create_coarse_grid(Triangulation<dim> &coarse_grid)
1749 *   {
1750 *   GridGenerator::hyper_cube(coarse_grid, -1, 1);
1751 *   coarse_grid.refine_global(2);
1752 *   }
1753 *  
1754 *  
1755 * @endcode
1756 *
1757 *
1758 * <a name="step_14-TheExercise_2_3class"></a>
1759 * <h4>The Exercise_2_3 class</h4>
1760 *
1761
1762 *
1763 * This example program was written while giving practical courses for a
1764 * lecture on adaptive finite element methods and duality based error
1765 * estimates. For these courses, we had one exercise, which required to
1766 * solve the Laplace equation with constant right hand side on a square
1767 * domain with a square hole in the center, and zero boundary
1768 * values. Since the implementation of the properties of this problem is
1769 * so particularly simple here, lets do it. As the number of the exercise
1770 * was 2.3, we take the liberty to retain this name for the class as well.
1771 *
1772 * @code
1773 *   template <int dim>
1774 *   struct Exercise_2_3
1775 *   {
1776 * @endcode
1777 *
1778 * We need a class to denote the boundary values of the problem. In this
1779 * case, this is simple: it's the zero function, so don't even declare a
1780 * class, just an alias:
1781 *
1782 * @code
1783 *   using BoundaryValues = Functions::ZeroFunction<dim>;
1784 *  
1785 * @endcode
1786 *
1787 * Second, a class that denotes the right hand side. Since they are
1788 * constant, just subclass the corresponding class of the library and be
1789 * done:
1790 *
1791 * @code
1792 *   class RightHandSide : public Functions::ConstantFunction<dim>
1793 *   {
1794 *   public:
1795 *   RightHandSide()
1796 *   : Functions::ConstantFunction<dim>(1.)
1797 *   {}
1798 *   };
1799 *  
1800 * @endcode
1801 *
1802 * Finally a function to generate the coarse grid. This is somewhat more
1803 * complicated here, see immediately below.
1804 *
1805 * @code
1806 *   static void create_coarse_grid(Triangulation<dim> &coarse_grid);
1807 *   };
1808 *  
1809 *  
1810 * @endcode
1811 *
1812 * As stated above, the grid for this example is the square [-1,1]^2 with
1813 * the square [-1/2,1/2]^2 as hole in it. We create the coarse grid as 4
1814 * times 4 cells with the middle four ones missing. To understand how
1815 * exactly the mesh is going to look, it may be simplest to just look
1816 * at the "Results" section of this tutorial program first. In general,
1817 * if you'd like to understand more about creating meshes either from
1818 * scratch by hand, as we do here, or using other techniques, you
1819 * should take a look at @ref step_49 "step-49".
1820 *
1821
1822 *
1823 * Of course, the example has an extension to 3d, but since this function
1824 * cannot be written in a dimension independent way we choose not to
1825 * implement this here, but rather only specialize the template for
1826 * dim=2. If you compile the program for 3d, you'll get a message from the
1827 * linker that this function is not implemented for 3d, and needs to be
1828 * provided.
1829 *
1830
1831 *
1832 * For the creation of this geometry, the library has no predefined
1833 * method. In this case, the geometry is still simple enough to do the
1834 * creation by hand, rather than using a mesh generator.
1835 *
1836 * @code
1837 *   template <>
1838 *   void Exercise_2_3<2>::create_coarse_grid(Triangulation<2> &coarse_grid)
1839 *   {
1840 * @endcode
1841 *
1842 * We first define the space dimension, to allow those parts of the
1843 * function that are actually dimension independent to use this
1844 * variable. That makes it simpler if you later take this as a starting
1845 * point to implement a 3d version of this mesh. The next step is then
1846 * to have a list of vertices. Here, they are 24 (5 times 5, with the
1847 * middle one omitted). It is probably best to draw a sketch here.
1848 *
1849 * @code
1850 *   const unsigned int dim = 2;
1851 *  
1852 *   const std::vector<Point<2>> vertices = {
1853 *   {-1.0, -1.0}, {-0.5, -1.0}, {+0.0, -1.0}, {+0.5, -1.0}, {+1.0, -1.0},
1854 *   {-1.0, -0.5}, {-0.5, -0.5}, {+0.0, -0.5}, {+0.5, -0.5}, {+1.0, -0.5},
1855 *   {-1.0, +0.0}, {-0.5, +0.0}, {+0.5, +0.0}, {+1.0, +0.0},
1856 *   {-1.0, +0.5}, {-0.5, +0.5}, {+0.0, +0.5}, {+0.5, +0.5}, {+1.0, +0.5},
1857 *   {-1.0, +1.0}, {-0.5, +1.0}, {+0.0, +1.0}, {+0.5, +1.0}, {+1.0, +1.0}};
1858 *  
1859 * @endcode
1860 *
1861 * Next, we have to define the cells and the vertices they contain.
1862 *
1863 * @code
1864 *   const std::vector<std::array<int, GeometryInfo<dim>::vertices_per_cell>>
1865 *   cell_vertices = {{{0, 1, 5, 6}},
1866 *   {{1, 2, 6, 7}},
1867 *   {{2, 3, 7, 8}},
1868 *   {{3, 4, 8, 9}},
1869 *   {{5, 6, 10, 11}},
1870 *   {{8, 9, 12, 13}},
1871 *   {{10, 11, 14, 15}},
1872 *   {{12, 13, 17, 18}},
1873 *   {{14, 15, 19, 20}},
1874 *   {{15, 16, 20, 21}},
1875 *   {{16, 17, 21, 22}},
1876 *   {{17, 18, 22, 23}}};
1877 *  
1878 *   const unsigned int n_cells = cell_vertices.size();
1879 *  
1880 * @endcode
1881 *
1882 * Again, we generate a C++ vector type from this, but this time by
1883 * looping over the cells (yes, this is boring). Additionally, we set
1884 * the material indicator to zero for all the cells:
1885 *
1886 * @code
1887 *   std::vector<CellData<dim>> cells(n_cells, CellData<dim>());
1888 *   for (unsigned int i = 0; i < n_cells; ++i)
1889 *   {
1890 *   for (unsigned int j = 0; j < cell_vertices[i].size(); ++j)
1891 *   cells[i].vertices[j] = cell_vertices[i][j];
1892 *   cells[i].material_id = 0;
1893 *   }
1894 *  
1895 * @endcode
1896 *
1897 * Finally pass all this information to the library to generate a
1898 * triangulation. The right call for this is
1899 * Triangulation::create_triangulation(), but that function wants
1900 * its input in a format in which cells are consistently oriented
1901 * in some way. It turns out that the mesh we describe with the
1902 * `vertices` and `cells` objects above already is consistently
1903 * oriented, but if you modify the code in some way it may not
1904 * be any more, and so it is good practice to call a function
1905 * that ensures it is -- GridTools::consistently_order_cells()
1906 * does this.
1907 *
1908
1909 *
1910 * The last parameter of the call to Triangulation::create_triangulation()
1911 * below describes what we want to do about boundary and manifold
1912 * indicators on boundary faces. Here, we don't want to do anything
1913 * specific (in particular, we are fine with labeling all boundaries
1914 * with boundary indicator zero, and so we call the function with
1915 * an empty object as the last argument:
1916 *
1917 * @code
1919 *   coarse_grid.create_triangulation(vertices, cells, SubCellData());
1920 *  
1921 * @endcode
1922 *
1923 * And since we want that the evaluation point (3/4,3/4) in this example
1924 * is a grid point, we refine once globally:
1925 *
1926 * @code
1927 *   coarse_grid.refine_global(1);
1928 *   }
1929 *   } // namespace Data
1930 *  
1931 * @endcode
1932 *
1933 *
1934 * <a name="step_14-Discussion"></a>
1935 * <h4>Discussion</h4>
1936 *
1937
1938 *
1939 * As you have now read through this framework, you may be wondering why we
1940 * have not chosen to implement the classes implementing a certain setup
1941 * (like the <code>CurvedRidges</code> class) directly as classes derived
1942 * from <code>Data::SetUpBase</code>. Indeed, we could have done very well
1943 * so. The only reason is that then we would have to have member variables
1944 * for the solution and right hand side classes in the
1945 * <code>CurvedRidges</code> class, as well as member functions overloading
1946 * the abstract functions of the base class giving access to these member
1947 * variables. The <code>SetUp</code> class has the sole reason to relieve us
1948 * from the need to reiterate these member variables and functions that
1949 * would be necessary in all such classes. In some way, the template
1950 * mechanism here only provides a way to have default implementations for a
1951 * number of functions that depend on external quantities and can thus not
1952 * be provided using normal virtual functions, at least not without the help
1953 * of templates.
1954 *
1955
1956 *
1957 * However, there might be good reasons to actually implement classes
1958 * derived from <code>Data::SetUpBase</code>, for example if the solution or
1959 * right hand side classes require constructors that take arguments, which
1960 * the <code>Data::SetUpBase</code> class cannot provide. In that case,
1961 * subclassing is a worthwhile strategy. Other possibilities for special
1962 * cases are to derive from <code>Data::SetUp@<SomeSetUp@></code> where
1963 * <code>SomeSetUp</code> denotes a class, or even to explicitly specialize
1964 * <code>Data::SetUp@<SomeSetUp@></code>. The latter allows to transparently
1965 * use the way the <code>SetUp</code> class is used for other set-ups, but
1966 * with special actions taken for special arguments.
1967 *
1968
1969 *
1970 * A final observation favoring the approach taken here is the following: we
1971 * have found numerous times that when starting a project, the number of
1972 * parameters (usually boundary values, right hand side, coarse grid, just
1973 * as here) was small, and the number of test cases was small as well. One
1974 * then starts out by handcoding them into a number of <code>switch</code>
1975 * statements. Over time, projects grow, and so does the number of test
1976 * cases. The number of <code>switch</code> statements grows with that, and
1977 * their length as well, and one starts to find ways to consider impossible
1978 * examples where domains, boundary values, and right hand sides do not fit
1979 * together any more, and starts losing the overview over the whole
1980 * structure. Encapsulating everything belonging to a certain test case into
1981 * a structure of its own has proven worthwhile for this, as it keeps
1982 * everything that belongs to one test case in one place. Furthermore, it
1983 * allows to put these things all in one or more files that are only devoted
1984 * to test cases and their data, without having to bring their actual
1985 * implementation into contact with the rest of the program.
1986 *
1987
1988 *
1989 *
1990
1991 *
1992 *
1993 * <a name="step_14-Dualfunctionals"></a>
1994 * <h3>Dual functionals</h3>
1995 *
1996
1997 *
1998 * As with the other components of the program, we put everything we need to
1999 * describe dual functionals into a namespace of its own, and define an
2000 * abstract base class that provides the interface the class solving the
2001 * dual problem needs for its work.
2002 *
2003
2004 *
2005 * We will then implement two such classes, for the evaluation of a point
2006 * value and of the derivative of the solution at that point. For these
2007 * functionals we already have the corresponding evaluation objects, so they
2008 * are complementary.
2009 *
2010 * @code
2011 *   namespace DualFunctional
2012 *   {
2013 * @endcode
2014 *
2015 *
2016 * <a name="step_14-TheDualFunctionalBaseclass"></a>
2017 * <h4>The DualFunctionalBase class</h4>
2018 *
2019
2020 *
2021 * First start with the base class for dual functionals. Since for linear
2022 * problems the characteristics of the dual problem play a role only in
2023 * the right hand side, we only need to provide for a function that
2024 * assembles the right hand side for a given discretization:
2025 *
2026 * @code
2027 *   template <int dim>
2028 *   class DualFunctionalBase : public EnableObserverPointer
2029 *   {
2030 *   public:
2031 *   virtual void assemble_rhs(const DoFHandler<dim> &dof_handler,
2032 *   Vector<double> &rhs) const = 0;
2033 *   };
2034 *  
2035 *  
2036 * @endcode
2037 *
2038 *
2039 * <a name="step_14-ThedualfunctionalPointValueEvaluationclass"></a>
2040 * <h4>The dual functional PointValueEvaluation class</h4>
2041 *
2042
2043 *
2044 * As a first application, we consider the functional corresponding to the
2045 * evaluation of the solution's value at a given point which again we
2046 * assume to be a vertex. Apart from the constructor that takes and stores
2047 * the evaluation point, this class consists only of the function that
2048 * implements assembling the right hand side.
2049 *
2050 * @code
2051 *   template <int dim>
2052 *   class PointValueEvaluation : public DualFunctionalBase<dim>
2053 *   {
2054 *   public:
2055 *   PointValueEvaluation(const Point<dim> &evaluation_point);
2056 *  
2057 *   virtual void assemble_rhs(const DoFHandler<dim> &dof_handler,
2058 *   Vector<double> &rhs) const override;
2059 *  
2060 *   DeclException1(
2061 *   ExcEvaluationPointNotFound,
2062 *   Point<dim>,
2063 *   << "The evaluation point " << arg1
2064 *   << " was not found among the vertices of the present grid.");
2065 *  
2066 *   protected:
2067 *   const Point<dim> evaluation_point;
2068 *   };
2069 *  
2070 *  
2071 *   template <int dim>
2072 *   PointValueEvaluation<dim>::PointValueEvaluation(
2073 *   const Point<dim> &evaluation_point)
2074 *   : evaluation_point(evaluation_point)
2075 *   {}
2076 *  
2077 *  
2078 * @endcode
2079 *
2080 * As for doing the main purpose of the class, assembling the right hand
2081 * side, let us first consider what is necessary: The right hand side of
2082 * the dual problem is a vector of values J(phi_i), where J is the error
2083 * functional, and phi_i is the i-th shape function. Here, J is the
2084 * evaluation at the point x0, i.e. J(phi_i)=phi_i(x0).
2085 *
2086
2087 *
2088 * Now, we have assumed that the evaluation point is a vertex. Thus, for
2089 * the usual finite elements we might be using in this program, we can
2090 * take for granted that at such a point exactly one shape function is
2091 * nonzero, and in particular has the value one. Thus, we set the right
2092 * hand side vector to all-zeros, then seek for the shape function
2093 * associated with that point and set the corresponding value of the right
2094 * hand side vector to one:
2095 *
2096 * @code
2097 *   template <int dim>
2098 *   void
2099 *   PointValueEvaluation<dim>::assemble_rhs(const DoFHandler<dim> &dof_handler,
2100 *   Vector<double> &rhs) const
2101 *   {
2102 * @endcode
2103 *
2104 * So, first set everything to zeros...
2105 *
2106 * @code
2107 *   rhs.reinit(dof_handler.n_dofs());
2108 *  
2109 * @endcode
2110 *
2111 * ...then loop over cells and find the evaluation point among the
2112 * vertices (or very close to a vertex, which may happen due to floating
2113 * point round-off):
2114 *
2115 * @code
2116 *   for (const auto &cell : dof_handler.active_cell_iterators())
2117 *   for (const auto vertex : cell->vertex_indices())
2118 *   if (cell->vertex(vertex).distance(evaluation_point) <
2119 *   cell->diameter() * 1e-8)
2120 *   {
2121 * @endcode
2122 *
2123 * Ok, found, so set corresponding entry, and leave function
2124 * since we are finished:
2125 *
2126 * @code
2127 *   rhs(cell->vertex_dof_index(vertex, 0)) = 1;
2128 *   return;
2129 *   }
2130 *  
2131 * @endcode
2132 *
2133 * Finally, a sanity check: if we somehow got here, then we must have
2134 * missed the evaluation point, so raise an exception unconditionally:
2135 *
2136 * @code
2137 *   AssertThrow(false, ExcEvaluationPointNotFound(evaluation_point));
2138 *   }
2139 *  
2140 *  
2141 * @endcode
2142 *
2143 *
2144 * <a name="step_14-ThedualfunctionalPointXDerivativeEvaluationclass"></a>
2145 * <h4>The dual functional PointXDerivativeEvaluation class</h4>
2146 *
2147
2148 *
2149 * As second application, we again consider the evaluation of the
2150 * x-derivative of the solution at one point. Again, the declaration of
2151 * the class, and the implementation of its constructor is not too
2152 * interesting:
2153 *
2154 * @code
2155 *   template <int dim>
2156 *   class PointXDerivativeEvaluation : public DualFunctionalBase<dim>
2157 *   {
2158 *   public:
2159 *   PointXDerivativeEvaluation(const Point<dim> &evaluation_point);
2160 *  
2161 *   virtual void assemble_rhs(const DoFHandler<dim> &dof_handler,
2162 *   Vector<double> &rhs) const;
2163 *  
2164 *   DeclException1(
2165 *   ExcEvaluationPointNotFound,
2166 *   Point<dim>,
2167 *   << "The evaluation point " << arg1
2168 *   << " was not found among the vertices of the present grid.");
2169 *  
2170 *   protected:
2171 *   const Point<dim> evaluation_point;
2172 *   };
2173 *  
2174 *  
2175 *   template <int dim>
2176 *   PointXDerivativeEvaluation<dim>::PointXDerivativeEvaluation(
2177 *   const Point<dim> &evaluation_point)
2178 *   : evaluation_point(evaluation_point)
2179 *   {}
2180 *  
2181 *  
2182 * @endcode
2183 *
2184 * What is interesting is the implementation of this functional: here,
2185 * J(phi_i)=d/dx phi_i(x0).
2186 *
2187
2188 *
2189 * We could, as in the implementation of the respective evaluation object
2190 * take the average of the gradients of each shape function phi_i at this
2191 * evaluation point. However, we take a slightly different approach: we
2192 * simply take the average over all cells that surround this point. The
2193 * question which cells <code>surrounds</code> the evaluation point is
2194 * made dependent on the mesh width by including those cells for which the
2195 * distance of the cell's midpoint to the evaluation point is less than
2196 * the cell's diameter.
2197 *
2198
2199 *
2200 * Taking the average of the gradient over the area/volume of these cells
2201 * leads to a dual solution which is very close to the one which would
2202 * result from the point evaluation of the gradient. It is simple to
2203 * justify theoretically that this does not change the method
2204 * significantly.
2205 *
2206 * @code
2207 *   template <int dim>
2208 *   void PointXDerivativeEvaluation<dim>::assemble_rhs(
2209 *   const DoFHandler<dim> &dof_handler,
2210 *   Vector<double> &rhs) const
2211 *   {
2212 * @endcode
2213 *
2214 * Again, first set all entries to zero:
2215 *
2216 * @code
2217 *   rhs.reinit(dof_handler.n_dofs());
2218 *  
2219 * @endcode
2220 *
2221 * Initialize a <code>FEValues</code> object with a quadrature formula,
2222 * have abbreviations for the number of quadrature points and shape
2223 * functions...
2224 *
2225 * @code
2226 *   const QGauss<dim> quadrature(dof_handler.get_fe().degree + 1);
2227 *   FEValues<dim> fe_values(dof_handler.get_fe(),
2228 *   quadrature,
2229 *   update_gradients | update_quadrature_points |
2230 *   update_JxW_values);
2231 *   const unsigned int n_q_points = fe_values.n_quadrature_points;
2232 *   const unsigned int dofs_per_cell = dof_handler.get_fe().dofs_per_cell;
2233 *  
2234 * @endcode
2235 *
2236 * ...and have two objects that are used to store the global indices of
2237 * the degrees of freedom on a cell, and the values of the gradients of
2238 * the shape functions at the quadrature points:
2239 *
2240 * @code
2241 *   Vector<double> cell_rhs(dofs_per_cell);
2242 *   std::vector<unsigned int> local_dof_indices(dofs_per_cell);
2243 *  
2244 * @endcode
2245 *
2246 * Finally have a variable in which we will sum up the area/volume of
2247 * the cells over which we integrate, by integrating the unit functions
2248 * on these cells:
2249 *
2250 * @code
2251 *   double total_volume = 0;
2252 *  
2253 * @endcode
2254 *
2255 * Then start the loop over all cells, and select those cells which are
2256 * close enough to the evaluation point:
2257 *
2258 * @code
2259 *   for (const auto &cell : dof_handler.active_cell_iterators())
2260 *   if (cell->center().distance(evaluation_point) <= cell->diameter())
2261 *   {
2262 * @endcode
2263 *
2264 * If we have found such a cell, then initialize the
2265 * <code>FEValues</code> object and integrate the x-component of
2266 * the gradient of each shape function, as well as the unit
2267 * function for the total area/volume.
2268 *
2269 * @code
2270 *   fe_values.reinit(cell);
2271 *   cell_rhs = 0;
2272 *  
2273 *   for (unsigned int q = 0; q < n_q_points; ++q)
2274 *   {
2275 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
2276 *   cell_rhs(i) +=
2277 *   fe_values.shape_grad(i, q)[0] // (d/dx phi_i(x_q))
2278 *   * fe_values.JxW(q); // * dx
2279 *   total_volume += fe_values.JxW(q);
2280 *   }
2281 *  
2282 * @endcode
2283 *
2284 * If we have the local contributions, distribute them to the
2285 * global vector:
2286 *
2287 * @code
2288 *   cell->get_dof_indices(local_dof_indices);
2289 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
2290 *   rhs(local_dof_indices[i]) += cell_rhs(i);
2291 *   }
2292 *  
2293 * @endcode
2294 *
2295 * After we have looped over all cells, check whether we have found any
2296 * at all, by making sure that their volume is non-zero. If not, then
2297 * the results will be botched, as the right hand side should then still
2298 * be zero, so throw an exception:
2299 *
2300 * @code
2301 *   AssertThrow(total_volume > 0,
2302 *   ExcEvaluationPointNotFound(evaluation_point));
2303 *  
2304 * @endcode
2305 *
2306 * Finally, we have by now only integrated the gradients of the shape
2307 * functions, not taking their mean value. We fix this by dividing by
2308 * the measure of the volume over which we have integrated:
2309 *
2310 * @code
2311 *   rhs /= total_volume;
2312 *   }
2313 *  
2314 *  
2315 *   } // namespace DualFunctional
2316 *  
2317 *  
2318 * @endcode
2319 *
2320 *
2321 * <a name="step_14-ExtendingtheLaplaceSolvernamespace"></a>
2322 * <h3>Extending the LaplaceSolver namespace</h3>
2323 *
2324 * @code
2325 *   namespace LaplaceSolver
2326 *   {
2327 * @endcode
2328 *
2329 *
2330 * <a name="step_14-TheDualSolverclass"></a>
2331 * <h4>The DualSolver class</h4>
2332 *
2333
2334 *
2335 * In the same way as the <code>PrimalSolver</code> class above, we now
2336 * implement a <code>DualSolver</code>. It has all the same features, the
2337 * only difference is that it does not take a function object denoting a
2338 * right hand side object, but now takes a <code>DualFunctionalBase</code>
2339 * object that will assemble the right hand side vector of the dual
2340 * problem. The rest of the class is rather trivial.
2341 *
2342
2343 *
2344 * Since both primal and dual solver will use the same triangulation, but
2345 * different discretizations, it now becomes clear why we have made the
2346 * <code>Base</code> class a virtual one: since the final class will be
2347 * derived from both <code>PrimalSolver</code> as well as
2348 * <code>DualSolver</code>, it would have two <code>Base</code> instances,
2349 * would we not have marked the inheritance as virtual. Since in many
2350 * applications the base class would store much more information than just
2351 * the triangulation which needs to be shared between primal and dual
2352 * solvers, we do not usually want to use two such base classes.
2353 *
2354 * @code
2355 *   template <int dim>
2356 *   class DualSolver : public Solver<dim>
2357 *   {
2358 *   public:
2359 *   DualSolver(
2360 *   Triangulation<dim> &triangulation,
2361 *   const FiniteElement<dim> &fe,
2362 *   const Quadrature<dim> &quadrature,
2363 *   const Quadrature<dim - 1> &face_quadrature,
2364 *   const DualFunctional::DualFunctionalBase<dim> &dual_functional);
2365 *  
2366 *   protected:
2367 *   const ObserverPointer<const DualFunctional::DualFunctionalBase<dim>>
2368 *   dual_functional;
2369 *   virtual void assemble_rhs(Vector<double> &rhs) const override;
2370 *  
2371 *   static const Functions::ZeroFunction<dim> boundary_values;
2372 *   };
2373 *  
2374 *   template <int dim>
2375 *   const Functions::ZeroFunction<dim> DualSolver<dim>::boundary_values;
2376 *  
2377 *   template <int dim>
2378 *   DualSolver<dim>::DualSolver(
2379 *   Triangulation<dim> &triangulation,
2380 *   const FiniteElement<dim> &fe,
2381 *   const Quadrature<dim> &quadrature,
2382 *   const Quadrature<dim - 1> &face_quadrature,
2383 *   const DualFunctional::DualFunctionalBase<dim> &dual_functional)
2384 *   : Base<dim>(triangulation)
2385 *   , Solver<dim>(triangulation,
2386 *   fe,
2387 *   quadrature,
2388 *   face_quadrature,
2389 *   boundary_values)
2390 *   , dual_functional(&dual_functional)
2391 *   {}
2392 *  
2393 *  
2394 *  
2395 *   template <int dim>
2396 *   void DualSolver<dim>::assemble_rhs(Vector<double> &rhs) const
2397 *   {
2398 *   dual_functional->assemble_rhs(this->dof_handler, rhs);
2399 *   }
2400 *  
2401 *  
2402 * @endcode
2403 *
2404 *
2405 * <a name="step_14-TheWeightedResidualclass"></a>
2406 * <h4>The WeightedResidual class</h4>
2407 *
2408
2409 *
2410 * Here finally comes the main class of this program, the one that
2411 * implements the dual weighted residual error estimator. It joins the
2412 * primal and dual solver classes to use them for the computation of
2413 * primal and dual solutions, and implements the error representation
2414 * formula for use as error estimate and mesh refinement.
2415 *
2416
2417 *
2418 * The first few of the functions of this class are mostly overriders of
2419 * the respective functions of the base class:
2420 *
2421 * @code
2422 *   template <int dim>
2423 *   class WeightedResidual : public PrimalSolver<dim>, public DualSolver<dim>
2424 *   {
2425 *   public:
2426 *   WeightedResidual(
2427 *   Triangulation<dim> &coarse_grid,
2428 *   const FiniteElement<dim> &primal_fe,
2429 *   const FiniteElement<dim> &dual_fe,
2430 *   const Quadrature<dim> &quadrature,
2431 *   const Quadrature<dim - 1> &face_quadrature,
2432 *   const Function<dim> &rhs_function,
2433 *   const Function<dim> &boundary_values,
2434 *   const DualFunctional::DualFunctionalBase<dim> &dual_functional);
2435 *  
2436 *   virtual void solve_problem() override;
2437 *  
2438 *   virtual void postprocess(
2439 *   const Evaluation::EvaluationBase<dim> &postprocessor) const override;
2440 *  
2441 *   virtual unsigned int n_dofs() const override;
2442 *  
2443 *   virtual void refine_grid() override;
2444 *  
2445 *   virtual void output_solution() const override;
2446 *  
2447 *   private:
2448 * @endcode
2449 *
2450 * In the private section, we have two functions that are used to call
2451 * the <code>solve_problem</code> functions of the primal and dual base
2452 * classes. These two functions will be called in parallel by the
2453 * <code>solve_problem</code> function of this class.
2454 *
2455 * @code
2456 *   void solve_primal_problem();
2457 *   void solve_dual_problem();
2458 * @endcode
2459 *
2460 * Then declare abbreviations for active cell iterators, to avoid that
2461 * we have to write this lengthy name over and over again:
2462 *
2463
2464 *
2465 *
2466 * @code
2467 *   using active_cell_iterator =
2468 *   typename DoFHandler<dim>::active_cell_iterator;
2469 *  
2470 * @endcode
2471 *
2472 * Next, declare a data type that we will us to store the contribution
2473 * of faces to the error estimator. The idea is that we can compute the
2474 * face terms from each of the two cells to this face, as they are the
2475 * same when viewed from both sides. What we will do is to compute them
2476 * only once, based on some rules explained below which of the two
2477 * adjacent cells will be in charge to do so. We then store the
2478 * contribution of each face in a map mapping faces to their values, and
2479 * only collect the contributions for each cell by looping over the
2480 * cells a second time and grabbing the values from the map.
2481 *
2482
2483 *
2484 * The data type of this map is declared here:
2485 *
2486 * @code
2487 *   using FaceIntegrals =
2488 *   typename std::map<typename DoFHandler<dim>::face_iterator, double>;
2489 *  
2490 * @endcode
2491 *
2492 * In the computation of the error estimates on cells and faces, we need
2493 * a number of helper objects, such as <code>FEValues</code> and
2494 * <code>FEFaceValues</code> functions, but also temporary objects
2495 * storing the values and gradients of primal and dual solutions, for
2496 * example. These fields are needed in the three functions that do the
2497 * integration on cells, and regular and irregular faces, respectively.
2498 *
2499
2500 *
2501 * There are three reasonable ways to provide these fields: first, as
2502 * local variables in the function that needs them; second, as member
2503 * variables of this class; third, as arguments passed to that function.
2504 *
2505
2506 *
2507 * These three alternatives all have drawbacks: the third that their
2508 * number is not negligible and would make calling these functions a
2509 * lengthy enterprise. The second has the drawback that it disallows
2510 * parallelization, since the threads that will compute the error
2511 * estimate have to have their own copies of these variables each, so
2512 * member variables of the enclosing class will not work. The first
2513 * approach, although straightforward, has a subtle but important
2514 * drawback: we will call these functions over and over again, many
2515 * thousands of times maybe; it now turns out that allocating
2516 * vectors and other objects that need memory from the heap is an
2517 * expensive business in terms of run-time, since memory allocation is
2518 * expensive when several threads are involved. It is thus
2519 * significantly better to allocate the memory only once, and recycle
2520 * the objects as often as possible.
2521 *
2522
2523 *
2524 * What to do? Our answer is to use a variant of the third strategy.
2525 * In fact, this is exactly what the WorkStream concept is supposed to
2526 * do (we have already introduced it above, but see also @ref threads).
2527 * To avoid that we have to give these functions a dozen or so
2528 * arguments, we pack all these variables into two structures, one which
2529 * is used for the computations on cells, the other doing them on the
2530 * faces. Both are then joined into the WeightedResidualScratchData class
2531 * that will serve as the "scratch data" class of the WorkStream concept:
2532 *
2533 * @code
2534 *   struct CellData
2535 *   {
2536 *   FEValues<dim> fe_values;
2537 *   const ObserverPointer<const Function<dim>> right_hand_side;
2538 *  
2539 *   std::vector<double> cell_residual;
2540 *   std::vector<double> rhs_values;
2541 *   std::vector<double> dual_weights;
2542 *   std::vector<double> cell_laplacians;
2543 *   CellData(const FiniteElement<dim> &fe,
2544 *   const Quadrature<dim> &quadrature,
2545 *   const Function<dim> &right_hand_side);
2546 *   CellData(const CellData &cell_data);
2547 *   };
2548 *  
2549 *   struct FaceData
2550 *   {
2551 *   FEFaceValues<dim> fe_face_values_cell;
2552 *   FEFaceValues<dim> fe_face_values_neighbor;
2553 *   FESubfaceValues<dim> fe_subface_values_cell;
2554 *  
2555 *   std::vector<double> jump_residual;
2556 *   std::vector<double> dual_weights;
2557 *   typename std::vector<Tensor<1, dim>> cell_grads;
2558 *   typename std::vector<Tensor<1, dim>> neighbor_grads;
2559 *   FaceData(const FiniteElement<dim> &fe,
2560 *   const Quadrature<dim - 1> &face_quadrature);
2561 *   FaceData(const FaceData &face_data);
2562 *   };
2563 *  
2564 *   struct WeightedResidualScratchData
2565 *   {
2566 *   WeightedResidualScratchData(
2567 *   const FiniteElement<dim> &primal_fe,
2568 *   const Quadrature<dim> &primal_quadrature,
2569 *   const Quadrature<dim - 1> &primal_face_quadrature,
2570 *   const Function<dim> &rhs_function,
2571 *   const Vector<double> &primal_solution,
2572 *   const Vector<double> &dual_weights);
2573 *  
2574 *   WeightedResidualScratchData(
2575 *   const WeightedResidualScratchData &scratch_data);
2576 *  
2577 *   CellData cell_data;
2578 *   FaceData face_data;
2579 *   Vector<double> primal_solution;
2580 *   Vector<double> dual_weights;
2581 *   };
2582 *  
2583 *  
2584 * @endcode
2585 *
2586 * WorkStream::run generally wants both a scratch object and a copy
2587 * object. Here, for reasons similar to what we had in @ref step_9 "step-9" when
2588 * discussing the computation of an approximation of the gradient, we
2589 * don't actually need a "copy data" structure. Since WorkStream insists
2590 * on having one of these, we just declare an empty structure that does
2591 * nothing other than being there.
2592 *
2593 * @code
2594 *   struct WeightedResidualCopyData
2595 *   {};
2596 *  
2597 *  
2598 *  
2599 * @endcode
2600 *
2601 * Regarding the evaluation of the error estimator, we have one driver
2602 * function that uses WorkStream::run() to call the second function on
2603 * every cell:
2604 *
2605 * @code
2606 *   void estimate_error(Vector<float> &error_indicators) const;
2607 *  
2608 *   void estimate_on_one_cell(const active_cell_iterator &cell,
2609 *   WeightedResidualScratchData &scratch_data,
2610 *   WeightedResidualCopyData &copy_data,
2611 *   Vector<float> &error_indicators,
2612 *   FaceIntegrals &face_integrals) const;
2613 *  
2614 * @endcode
2615 *
2616 * Then we have functions that do the actual integration of the error
2617 * representation formula. They will treat the terms on the cell
2618 * interiors, on those faces that have no hanging nodes, and on those
2619 * faces with hanging nodes, respectively:
2620 *
2621 * @code
2622 *   void integrate_over_cell(const active_cell_iterator &cell,
2623 *   const Vector<double> &primal_solution,
2624 *   const Vector<double> &dual_weights,
2625 *   CellData &cell_data,
2626 *   Vector<float> &error_indicators) const;
2627 *  
2628 *   void integrate_over_regular_face(const active_cell_iterator &cell,
2629 *   const unsigned int face_no,
2630 *   const Vector<double> &primal_solution,
2631 *   const Vector<double> &dual_weights,
2632 *   FaceData &face_data,
2633 *   FaceIntegrals &face_integrals) const;
2634 *   void integrate_over_irregular_face(const active_cell_iterator &cell,
2635 *   const unsigned int face_no,
2636 *   const Vector<double> &primal_solution,
2637 *   const Vector<double> &dual_weights,
2638 *   FaceData &face_data,
2639 *   FaceIntegrals &face_integrals) const;
2640 *   };
2641 *  
2642 *  
2643 *  
2644 * @endcode
2645 *
2646 * In the implementation of this class, we first have the constructors of
2647 * the <code>CellData</code> and <code>FaceData</code> member classes, and
2648 * the <code>WeightedResidual</code> constructor. They only initialize
2649 * fields to their correct lengths, so we do not have to discuss them in
2650 * too much detail:
2651 *
2652 * @code
2653 *   template <int dim>
2654 *   WeightedResidual<dim>::CellData::CellData(
2655 *   const FiniteElement<dim> &fe,
2656 *   const Quadrature<dim> &quadrature,
2657 *   const Function<dim> &right_hand_side)
2658 *   : fe_values(fe,
2659 *   quadrature,
2661 *   update_JxW_values)
2662 *   , right_hand_side(&right_hand_side)
2663 *   , cell_residual(quadrature.size())
2664 *   , rhs_values(quadrature.size())
2665 *   , dual_weights(quadrature.size())
2666 *   , cell_laplacians(quadrature.size())
2667 *   {}
2668 *  
2669 *  
2670 *  
2671 *   template <int dim>
2672 *   WeightedResidual<dim>::CellData::CellData(const CellData &cell_data)
2673 *   : fe_values(cell_data.fe_values.get_fe(),
2674 *   cell_data.fe_values.get_quadrature(),
2676 *   update_JxW_values)
2677 *   , right_hand_side(cell_data.right_hand_side)
2678 *   , cell_residual(cell_data.cell_residual)
2679 *   , rhs_values(cell_data.rhs_values)
2680 *   , dual_weights(cell_data.dual_weights)
2681 *   , cell_laplacians(cell_data.cell_laplacians)
2682 *   {}
2683 *  
2684 *  
2685 *  
2686 *   template <int dim>
2687 *   WeightedResidual<dim>::FaceData::FaceData(
2688 *   const FiniteElement<dim> &fe,
2689 *   const Quadrature<dim - 1> &face_quadrature)
2690 *   : fe_face_values_cell(fe,
2691 *   face_quadrature,
2694 *   , fe_face_values_neighbor(fe,
2695 *   face_quadrature,
2698 *   , fe_subface_values_cell(fe, face_quadrature, update_gradients)
2699 *   {
2700 *   const unsigned int n_face_q_points = face_quadrature.size();
2701 *  
2702 *   jump_residual.resize(n_face_q_points);
2703 *   dual_weights.resize(n_face_q_points);
2704 *   cell_grads.resize(n_face_q_points);
2705 *   neighbor_grads.resize(n_face_q_points);
2706 *   }
2707 *  
2708 *  
2709 *  
2710 *   template <int dim>
2711 *   WeightedResidual<dim>::FaceData::FaceData(const FaceData &face_data)
2712 *   : fe_face_values_cell(face_data.fe_face_values_cell.get_fe(),
2713 *   face_data.fe_face_values_cell.get_quadrature(),
2716 *   , fe_face_values_neighbor(
2717 *   face_data.fe_face_values_neighbor.get_fe(),
2718 *   face_data.fe_face_values_neighbor.get_quadrature(),
2721 *   , fe_subface_values_cell(
2722 *   face_data.fe_subface_values_cell.get_fe(),
2723 *   face_data.fe_subface_values_cell.get_quadrature(),
2724 *   update_gradients)
2725 *   , jump_residual(face_data.jump_residual)
2726 *   , dual_weights(face_data.dual_weights)
2727 *   , cell_grads(face_data.cell_grads)
2728 *   , neighbor_grads(face_data.neighbor_grads)
2729 *   {}
2730 *  
2731 *  
2732 *  
2733 *   template <int dim>
2734 *   WeightedResidual<dim>::WeightedResidualScratchData::
2735 *   WeightedResidualScratchData(
2736 *   const FiniteElement<dim> &primal_fe,
2737 *   const Quadrature<dim> &primal_quadrature,
2738 *   const Quadrature<dim - 1> &primal_face_quadrature,
2739 *   const Function<dim> &rhs_function,
2740 *   const Vector<double> &primal_solution,
2741 *   const Vector<double> &dual_weights)
2742 *   : cell_data(primal_fe, primal_quadrature, rhs_function)
2743 *   , face_data(primal_fe, primal_face_quadrature)
2744 *   , primal_solution(primal_solution)
2745 *   , dual_weights(dual_weights)
2746 *   {}
2747 *  
2748 *   template <int dim>
2749 *   WeightedResidual<dim>::WeightedResidualScratchData::
2750 *   WeightedResidualScratchData(
2751 *   const WeightedResidualScratchData &scratch_data)
2752 *   : cell_data(scratch_data.cell_data)
2753 *   , face_data(scratch_data.face_data)
2754 *   , primal_solution(scratch_data.primal_solution)
2755 *   , dual_weights(scratch_data.dual_weights)
2756 *   {}
2757 *  
2758 *  
2759 *  
2760 *   template <int dim>
2761 *   WeightedResidual<dim>::WeightedResidual(
2762 *   Triangulation<dim> &coarse_grid,
2763 *   const FiniteElement<dim> &primal_fe,
2764 *   const FiniteElement<dim> &dual_fe,
2765 *   const Quadrature<dim> &quadrature,
2766 *   const Quadrature<dim - 1> &face_quadrature,
2767 *   const Function<dim> &rhs_function,
2768 *   const Function<dim> &bv,
2769 *   const DualFunctional::DualFunctionalBase<dim> &dual_functional)
2770 *   : Base<dim>(coarse_grid)
2771 *   , PrimalSolver<dim>(coarse_grid,
2772 *   primal_fe,
2773 *   quadrature,
2774 *   face_quadrature,
2775 *   rhs_function,
2776 *   bv)
2777 *   , DualSolver<dim>(coarse_grid,
2778 *   dual_fe,
2779 *   quadrature,
2780 *   face_quadrature,
2781 *   dual_functional)
2782 *   {}
2783 *  
2784 *  
2785 * @endcode
2786 *
2787 * The next five functions are boring, as they simply relay their work to
2788 * the base classes. The first calls the primal and dual solvers in
2789 * parallel, while postprocessing the solution and retrieving the number
2790 * of degrees of freedom is done by the primal class.
2791 *
2792 * @code
2793 *   template <int dim>
2794 *   void WeightedResidual<dim>::solve_problem()
2795 *   {
2796 *   Threads::TaskGroup<void> tasks;
2797 *   tasks +=
2798 *   Threads::new_task(&WeightedResidual<dim>::solve_primal_problem, *this);
2799 *   tasks +=
2800 *   Threads::new_task(&WeightedResidual<dim>::solve_dual_problem, *this);
2801 *   tasks.join_all();
2802 *   }
2803 *  
2804 *  
2805 *   template <int dim>
2806 *   void WeightedResidual<dim>::solve_primal_problem()
2807 *   {
2808 *   PrimalSolver<dim>::solve_problem();
2809 *   }
2810 *  
2811 *   template <int dim>
2812 *   void WeightedResidual<dim>::solve_dual_problem()
2813 *   {
2814 *   DualSolver<dim>::solve_problem();
2815 *   }
2816 *  
2817 *  
2818 *   template <int dim>
2819 *   void WeightedResidual<dim>::postprocess(
2820 *   const Evaluation::EvaluationBase<dim> &postprocessor) const
2821 *   {
2822 *   PrimalSolver<dim>::postprocess(postprocessor);
2823 *   }
2824 *  
2825 *  
2826 *   template <int dim>
2827 *   unsigned int WeightedResidual<dim>::n_dofs() const
2828 *   {
2829 *   return PrimalSolver<dim>::n_dofs();
2830 *   }
2831 *  
2832 *  
2833 *  
2834 * @endcode
2835 *
2836 * Now, it is becoming more interesting: the <code>refine_grid()</code>
2837 * function asks the error estimator to compute the cell-wise error
2838 * indicators, then uses their absolute values for mesh refinement.
2839 *
2840 * @code
2841 *   template <int dim>
2842 *   void WeightedResidual<dim>::refine_grid()
2843 *   {
2844 * @endcode
2845 *
2846 * First call the function that computes the cell-wise and global error:
2847 *
2848 * @code
2849 *   Vector<float> error_indicators(this->triangulation->n_active_cells());
2850 *   estimate_error(error_indicators);
2851 *  
2852 * @endcode
2853 *
2854 * Then note that marking cells for refinement or coarsening only works
2855 * if all indicators are positive, to allow their comparison. Thus, drop
2856 * the signs on all these indicators:
2857 *
2858 * @code
2859 *   for (float &error_indicator : error_indicators)
2860 *   error_indicator = std::fabs(error_indicator);
2861 *  
2862 * @endcode
2863 *
2864 * Finally, we can select between different strategies for
2865 * refinement. The default here is to refine those cells with the
2866 * largest error indicators that make up for a total of 80 per cent of
2867 * the error, while we coarsen those with the smallest indicators that
2868 * make up for the bottom 2 per cent of the error.
2869 *
2870 * @code
2872 *   error_indicators,
2873 *   0.8,
2874 *   0.02);
2875 *   this->triangulation->execute_coarsening_and_refinement();
2876 *   }
2877 *  
2878 *  
2879 * @endcode
2880 *
2881 * Since we want to output both the primal and the dual solution, we
2882 * overload the <code>output_solution</code> function. The only
2883 * interesting feature of this function is that the primal and dual
2884 * solutions are defined on different finite element spaces, which is not
2885 * the format the <code>DataOut</code> class expects. Thus, we have to
2886 * transfer them to a common finite element space. Since we want the
2887 * solutions only to see them qualitatively, we contend ourselves with
2888 * interpolating the dual solution to the (smaller) primal space. For the
2889 * interpolation, there is a library function, that takes a
2890 * AffineConstraints object including the hanging node
2891 * constraints. The rest is standard.
2892 *
2893 * @code
2894 *   template <int dim>
2895 *   void WeightedResidual<dim>::output_solution() const
2896 *   {
2897 *   AffineConstraints<double> primal_hanging_node_constraints;
2898 *   DoFTools::make_hanging_node_constraints(PrimalSolver<dim>::dof_handler,
2899 *   primal_hanging_node_constraints);
2900 *   primal_hanging_node_constraints.close();
2901 *   Vector<double> dual_solution(PrimalSolver<dim>::dof_handler.n_dofs());
2902 *   FETools::interpolate(DualSolver<dim>::dof_handler,
2903 *   DualSolver<dim>::solution,
2904 *   PrimalSolver<dim>::dof_handler,
2905 *   primal_hanging_node_constraints,
2906 *   dual_solution);
2907 *  
2908 *   DataOut<dim> data_out;
2909 *   data_out.attach_dof_handler(PrimalSolver<dim>::dof_handler);
2910 *  
2911 * @endcode
2912 *
2913 * Add the data vectors for which we want output. Add them both, the
2914 * <code>DataOut</code> functions can handle as many data vectors as you
2915 * wish to write to output:
2916 *
2917 * @code
2918 *   data_out.add_data_vector(PrimalSolver<dim>::solution, "primal_solution");
2919 *   data_out.add_data_vector(dual_solution, "dual_solution");
2920 *  
2921 *   data_out.build_patches();
2922 *  
2923 *   std::ofstream out("solution-" + std::to_string(this->refinement_cycle) +
2924 *   ".vtu");
2925 *   data_out.write(out, DataOutBase::vtu);
2926 *   }
2927 *  
2928 *  
2929 * @endcode
2930 *
2931 *
2932 * <a name="step_14-Estimatingerrors"></a>
2933 * <h3>Estimating errors</h3>
2934 *
2935
2936 *
2937 *
2938 * <a name="step_14-Errorestimationdriverfunctions"></a>
2939 * <h4>Error estimation driver functions</h4>
2940 *
2941
2942 *
2943 * As for the actual computation of error estimates, let's start with the
2944 * function that drives all this, i.e. calls those functions that actually
2945 * do the work, and finally collects the results.
2946 *
2947 * @code
2948 *   template <int dim>
2949 *   void
2950 *   WeightedResidual<dim>::estimate_error(Vector<float> &error_indicators) const
2951 *   {
2952 * @endcode
2953 *
2954 * The first task in computing the error is to set up vectors that
2955 * denote the primal solution, and the weights (z-z_h)=(z-I_hz), both in
2956 * the finite element space for which we have computed the dual
2957 * solution. For this, we have to interpolate the primal solution to the
2958 * dual finite element space, and to subtract the interpolation of the
2959 * computed dual solution to the primal finite element
2960 * space. Fortunately, the library provides functions for the
2961 * interpolation into larger or smaller finite element spaces, so this
2962 * is mostly obvious.
2963 *
2964
2965 *
2966 * First, let's do that for the primal solution: it is cell-wise
2967 * interpolated into the finite element space in which we have solved
2968 * the dual problem: But, again as in the
2969 * <code>WeightedResidual::output_solution</code> function we first need
2970 * to create an AffineConstraints object including the hanging node
2971 * constraints, but this time of the dual finite element space.
2972 *
2973 * @code
2974 *   AffineConstraints<double> dual_hanging_node_constraints;
2975 *   DoFTools::make_hanging_node_constraints(DualSolver<dim>::dof_handler,
2976 *   dual_hanging_node_constraints);
2977 *   dual_hanging_node_constraints.close();
2978 *   Vector<double> primal_solution(DualSolver<dim>::dof_handler.n_dofs());
2979 *   FETools::interpolate(PrimalSolver<dim>::dof_handler,
2980 *   PrimalSolver<dim>::solution,
2981 *   DualSolver<dim>::dof_handler,
2982 *   dual_hanging_node_constraints,
2983 *   primal_solution);
2984 *  
2985 * @endcode
2986 *
2987 * Then for computing the interpolation of the numerically approximated
2988 * dual solution z into the finite element space of the primal solution
2989 * and subtracting it from z: use the
2990 * <code>interpolate_difference</code> function, that gives (z-I_hz) in
2991 * the element space of the dual solution.
2992 *
2993 * @code
2994 *   AffineConstraints<double> primal_hanging_node_constraints;
2995 *   DoFTools::make_hanging_node_constraints(PrimalSolver<dim>::dof_handler,
2996 *   primal_hanging_node_constraints);
2997 *   primal_hanging_node_constraints.close();
2998 *   Vector<double> dual_weights(DualSolver<dim>::dof_handler.n_dofs());
2999 *   FETools::interpolation_difference(DualSolver<dim>::dof_handler,
3000 *   dual_hanging_node_constraints,
3001 *   DualSolver<dim>::solution,
3002 *   PrimalSolver<dim>::dof_handler,
3003 *   primal_hanging_node_constraints,
3004 *   dual_weights);
3005 *  
3006 * @endcode
3007 *
3008 * Note that this could probably have been more efficient since those
3009 * constraints have been used previously when assembling matrix and
3010 * right hand side for the primal problem and writing out the dual
3011 * solution. We leave the optimization of the program in this respect as
3012 * an exercise.
3013 *
3014
3015 *
3016 * Having computed the dual weights we now proceed with computing the
3017 * cell and face residuals of the primal solution. First we set up a map
3018 * between face iterators and their jump term contributions of faces to
3019 * the error estimator. The reason is that we compute the jump terms
3020 * only once, from one side of the face, and want to collect them only
3021 * afterwards when looping over all cells a second time.
3022 *
3023
3024 *
3025 * We initialize this map already with a value of -1e20 for all faces,
3026 * since this value will stand out in the results if something should go
3027 * wrong and we fail to compute the value for a face for some
3028 * reason. Secondly, this initialization already makes the std::map
3029 * object allocate all objects it may possibly need. This is important
3030 * since we will write into this structure from parallel threads,
3031 * and doing so would not be thread-safe if the map needed to allocate
3032 * memory and thereby reshape its data structures. In other words, the
3033 * initial initialization relieves us from the necessity to synchronize
3034 * the threads through a mutex each time they write to (and modify the
3035 * structure of) this map.
3036 *
3037 * @code
3038 *   FaceIntegrals face_integrals;
3039 *   for (const auto &cell :
3040 *   DualSolver<dim>::dof_handler.active_cell_iterators())
3041 *   for (const auto &face : cell->face_iterators())
3042 *   face_integrals[face] = -1e20;
3043 *  
3044 *   auto worker = [this,
3045 *   &error_indicators,
3046 *   &face_integrals](const active_cell_iterator &cell,
3047 *   WeightedResidualScratchData &scratch_data,
3048 *   WeightedResidualCopyData &copy_data) {
3049 *   this->estimate_on_one_cell(
3050 *   cell, scratch_data, copy_data, error_indicators, face_integrals);
3051 *   };
3052 *  
3053 *   auto do_nothing_copier =
3054 *   std::function<void(const WeightedResidualCopyData &)>();
3055 *  
3056 * @endcode
3057 *
3058 * Then hand it all off to WorkStream::run() to compute the
3059 * estimators for all cells in parallel:
3060 *
3061 * @code
3062 *   WorkStream::run(
3063 *   DualSolver<dim>::dof_handler.begin_active(),
3064 *   DualSolver<dim>::dof_handler.end(),
3065 *   worker,
3066 *   do_nothing_copier,
3067 *   WeightedResidualScratchData(*DualSolver<dim>::fe,
3068 *   *DualSolver<dim>::quadrature,
3069 *   *DualSolver<dim>::face_quadrature,
3070 *   *this->rhs_function,
3071 *   primal_solution,
3072 *   dual_weights),
3073 *   WeightedResidualCopyData());
3074 *  
3075 * @endcode
3076 *
3077 * Once the error contributions are computed, sum them up. For this,
3078 * note that the cell terms are already set, and that only the edge
3079 * terms need to be collected. Thus, loop over all cells and their
3080 * faces, make sure that the contributions of each of the faces are
3081 * there, and add them up. Only take minus one half of the jump term,
3082 * since the other half will be taken by the neighboring cell.
3083 *
3084 * @code
3085 *   unsigned int present_cell = 0;
3086 *   for (const auto &cell :
3087 *   DualSolver<dim>::dof_handler.active_cell_iterators())
3088 *   {
3089 *   for (const auto &face : cell->face_iterators())
3090 *   {
3091 *   Assert(face_integrals.find(face) != face_integrals.end(),
3092 *   ExcInternalError());
3093 *   error_indicators(present_cell) -= 0.5 * face_integrals[face];
3094 *   }
3095 *   ++present_cell;
3096 *   }
3097 *   std::cout << " Estimated error: "
3098 *   << std::accumulate(error_indicators.begin(),
3099 *   error_indicators.end(),
3100 *   0.)
3101 *   << std::endl;
3102 *   }
3103 *  
3104 *  
3105 * @endcode
3106 *
3107 *
3108 * <a name="step_14-Estimatingonasinglecell"></a>
3109 * <h4>Estimating on a single cell</h4>
3110 *
3111
3112 *
3113 * Next we have the function that is called to estimate the error on a
3114 * single cell. The function may be called multiple times if the library was
3115 * configured to use multithreading. Here it goes:
3116 *
3117 * @code
3118 *   template <int dim>
3119 *   void WeightedResidual<dim>::estimate_on_one_cell(
3120 *   const active_cell_iterator &cell,
3121 *   WeightedResidualScratchData &scratch_data,
3122 *   WeightedResidualCopyData &copy_data,
3123 *   Vector<float> &error_indicators,
3124 *   FaceIntegrals &face_integrals) const
3125 *   {
3126 * @endcode
3127 *
3128 * Because of WorkStream, estimate_on_one_cell requires a CopyData object
3129 * even if it is no used. The next line silences a warning about this
3130 * unused variable.
3131 *
3132 * @code
3133 *   (void)copy_data;
3134 *  
3135 * @endcode
3136 *
3137 * First task on each cell is to compute the cell residual
3138 * contributions of this cell, and put them into the
3139 * <code>error_indicators</code> variable:
3140 *
3141 * @code
3142 *   integrate_over_cell(cell,
3143 *   scratch_data.primal_solution,
3144 *   scratch_data.dual_weights,
3145 *   scratch_data.cell_data,
3146 *   error_indicators);
3147 *  
3148 * @endcode
3149 *
3150 * After computing the cell terms, turn to the face terms. For this,
3151 * loop over all faces of the present cell, and see whether
3152 * something needs to be computed on it:
3153 *
3154 * @code
3155 *   for (const auto face_no : cell->face_indices())
3156 *   {
3157 * @endcode
3158 *
3159 * First, if this face is part of the boundary, then there is
3160 * nothing to do. However, to make things easier when summing up
3161 * the contributions of the faces of cells, we enter this face
3162 * into the list of faces with a zero contribution to the error.
3163 *
3164 * @code
3165 *   if (cell->face(face_no)->at_boundary())
3166 *   {
3167 *   face_integrals[cell->face(face_no)] = 0;
3168 *   continue;
3169 *   }
3170 *  
3171 * @endcode
3172 *
3173 * Next, note that since we want to compute the jump terms on
3174 * each face only once although we access it twice (if it is not
3175 * at the boundary), we have to define some rules who is
3176 * responsible for computing on a face:
3177 *
3178
3179 *
3180 * First, if the neighboring cell is on the same level as this
3181 * one, i.e. neither further refined not coarser, then the one
3182 * with the lower index within this level does the work. In
3183 * other words: if the other one has a lower index, then skip
3184 * work on this face:
3185 *
3186 * @code
3187 *   if ((cell->neighbor(face_no)->has_children() == false) &&
3188 *   (cell->neighbor(face_no)->level() == cell->level()) &&
3189 *   (cell->neighbor(face_no)->index() < cell->index()))
3190 *   continue;
3191 *  
3192 * @endcode
3193 *
3194 * Likewise, we always work from the coarser cell if this and
3195 * its neighbor differ in refinement. Thus, if the neighboring
3196 * cell is less refined than the present one, then do nothing
3197 * since we integrate over the subfaces when we visit the coarse
3198 * cell.
3199 *
3200 * @code
3201 *   if (cell->at_boundary(face_no) == false)
3202 *   if (cell->neighbor(face_no)->level() < cell->level())
3203 *   continue;
3204 *  
3205 *  
3206 * @endcode
3207 *
3208 * Now we know that we are in charge here, so actually compute
3209 * the face jump terms. If the face is a regular one, i.e. the
3210 * other side's cell is neither coarser not finer than this
3211 * cell, then call one function, and if the cell on the other
3212 * side is further refined, then use another function. Note that
3213 * the case that the cell on the other side is coarser cannot
3214 * happen since we have decided above that we handle this case
3215 * when we pass over that other cell.
3216 *
3217 * @code
3218 *   if (cell->face(face_no)->has_children() == false)
3219 *   integrate_over_regular_face(cell,
3220 *   face_no,
3221 *   scratch_data.primal_solution,
3222 *   scratch_data.dual_weights,
3223 *   scratch_data.face_data,
3224 *   face_integrals);
3225 *   else
3226 *   integrate_over_irregular_face(cell,
3227 *   face_no,
3228 *   scratch_data.primal_solution,
3229 *   scratch_data.dual_weights,
3230 *   scratch_data.face_data,
3231 *   face_integrals);
3232 *   }
3233 *   }
3234 *  
3235 *  
3236 * @endcode
3237 *
3238 *
3239 * <a name="step_14-Computingcelltermerrorcontributions"></a>
3240 * <h4>Computing cell term error contributions</h4>
3241 *
3242
3243 *
3244 * As for the actual computation of the error contributions, first turn to
3245 * the cell terms:
3246 *
3247 * @code
3248 *   template <int dim>
3249 *   void WeightedResidual<dim>::integrate_over_cell(
3250 *   const active_cell_iterator &cell,
3251 *   const Vector<double> &primal_solution,
3252 *   const Vector<double> &dual_weights,
3253 *   CellData &cell_data,
3254 *   Vector<float> &error_indicators) const
3255 *   {
3256 * @endcode
3257 *
3258 * The tasks to be done are what appears natural from looking at the
3259 * error estimation formula: first get the right hand side and Laplacian
3260 * of the numerical solution at the quadrature points for the cell
3261 * residual,
3262 *
3263 * @code
3264 *   cell_data.fe_values.reinit(cell);
3265 *   cell_data.right_hand_side->value_list(
3266 *   cell_data.fe_values.get_quadrature_points(), cell_data.rhs_values);
3267 *   cell_data.fe_values.get_function_laplacians(primal_solution,
3268 *   cell_data.cell_laplacians);
3269 *  
3270 * @endcode
3271 *
3272 * ...then get the dual weights...
3273 *
3274 * @code
3275 *   cell_data.fe_values.get_function_values(dual_weights,
3276 *   cell_data.dual_weights);
3277 *  
3278 * @endcode
3279 *
3280 * ...and finally build the sum over all quadrature points and store it
3281 * with the present cell:
3282 *
3283 * @code
3284 *   double sum = 0;
3285 *   for (unsigned int p = 0; p < cell_data.fe_values.n_quadrature_points; ++p)
3286 *   sum += ((cell_data.rhs_values[p] + cell_data.cell_laplacians[p]) *
3287 *   cell_data.dual_weights[p] * cell_data.fe_values.JxW(p));
3288 *   error_indicators(cell->active_cell_index()) += sum;
3289 *   }
3290 *  
3291 *  
3292 * @endcode
3293 *
3294 *
3295 * <a name="step_14-Computingedgetermerrorcontributions1"></a>
3296 * <h4>Computing edge term error contributions -- 1</h4>
3297 *
3298
3299 *
3300 * On the other hand, computation of the edge terms for the error estimate
3301 * is not so simple. First, we have to distinguish between faces with and
3302 * without hanging nodes. Because it is the simple case, we first consider
3303 * the case without hanging nodes on a face (let's call this the `regular'
3304 * case):
3305 *
3306 * @code
3307 *   template <int dim>
3308 *   void WeightedResidual<dim>::integrate_over_regular_face(
3309 *   const active_cell_iterator &cell,
3310 *   const unsigned int face_no,
3311 *   const Vector<double> &primal_solution,
3312 *   const Vector<double> &dual_weights,
3313 *   FaceData &face_data,
3314 *   FaceIntegrals &face_integrals) const
3315 *   {
3316 *   const unsigned int n_q_points =
3317 *   face_data.fe_face_values_cell.n_quadrature_points;
3318 *  
3319 * @endcode
3320 *
3321 * The first step is to get the values of the gradients at the
3322 * quadrature points of the finite element field on the present
3323 * cell. For this, initialize the <code>FEFaceValues</code> object
3324 * corresponding to this side of the face, and extract the gradients
3325 * using that object.
3326 *
3327 * @code
3328 *   face_data.fe_face_values_cell.reinit(cell, face_no);
3329 *   face_data.fe_face_values_cell.get_function_gradients(
3330 *   primal_solution, face_data.cell_grads);
3331 *  
3332 * @endcode
3333 *
3334 * The second step is then to extract the gradients of the finite
3335 * element solution at the quadrature points on the other side of the
3336 * face, i.e. from the neighboring cell.
3337 *
3338
3339 *
3340 * For this, do a sanity check before: make sure that the neighbor
3341 * actually exists (yes, we should not have come here if the neighbor
3342 * did not exist, but in complicated software there are bugs, so better
3343 * check this), and if this is not the case throw an error.
3344 *
3345 * @code
3346 *   Assert(cell->neighbor(face_no).state() == IteratorState::valid,
3347 *   ExcInternalError());
3348 * @endcode
3349 *
3350 * If we have that, then we need to find out with which face of the
3351 * neighboring cell we have to work, i.e. the <code>how-many'th</code> the
3352 * neighbor the present cell is of the cell behind the present face. For
3353 * this, there is a function, and we put the result into a variable with
3354 * the name <code>neighbor_neighbor</code>:
3355 *
3356 * @code
3357 *   const unsigned int neighbor_neighbor =
3358 *   cell->neighbor_of_neighbor(face_no);
3359 * @endcode
3360 *
3361 * Then define an abbreviation for the neighbor cell, initialize the
3362 * <code>FEFaceValues</code> object on that cell, and extract the
3363 * gradients on that cell:
3364 *
3365 * @code
3366 *   const active_cell_iterator neighbor = cell->neighbor(face_no);
3367 *   face_data.fe_face_values_neighbor.reinit(neighbor, neighbor_neighbor);
3368 *   face_data.fe_face_values_neighbor.get_function_gradients(
3369 *   primal_solution, face_data.neighbor_grads);
3370 *  
3371 * @endcode
3372 *
3373 * Now that we have the gradients on this and the neighboring cell,
3374 * compute the jump residual by multiplying the jump in the gradient
3375 * with the normal vector:
3376 *
3377 * @code
3378 *   for (unsigned int p = 0; p < n_q_points; ++p)
3379 *   face_data.jump_residual[p] =
3380 *   ((face_data.cell_grads[p] - face_data.neighbor_grads[p]) *
3381 *   face_data.fe_face_values_cell.normal_vector(p));
3382 *  
3383 * @endcode
3384 *
3385 * Next get the dual weights for this face:
3386 *
3387 * @code
3388 *   face_data.fe_face_values_cell.get_function_values(dual_weights,
3389 *   face_data.dual_weights);
3390 *  
3391 * @endcode
3392 *
3393 * Finally, we have to compute the sum over jump residuals, dual
3394 * weights, and quadrature weights, to get the result for this face:
3395 *
3396 * @code
3397 *   double face_integral = 0;
3398 *   for (unsigned int p = 0; p < n_q_points; ++p)
3399 *   face_integral +=
3400 *   (face_data.jump_residual[p] * face_data.dual_weights[p] *
3401 *   face_data.fe_face_values_cell.JxW(p));
3402 *  
3403 * @endcode
3404 *
3405 * Double check that the element already exists and that it was not
3406 * already written to...
3407 *
3408 * @code
3409 *   Assert(face_integrals.find(cell->face(face_no)) != face_integrals.end(),
3410 *   ExcInternalError());
3411 *   Assert(face_integrals[cell->face(face_no)] == -1e20, ExcInternalError());
3412 *  
3413 * @endcode
3414 *
3415 * ...then store computed value at assigned location. Note that the
3416 * stored value does not contain the factor 1/2 that appears in the
3417 * error representation. The reason is that the term actually does not
3418 * have this factor if we loop over all faces in the triangulation, but
3419 * only appears if we write it as a sum over all cells and all faces of
3420 * each cell; we thus visit the same face twice. We take account of this
3421 * by using this factor -1/2 later, when we sum up the contributions for
3422 * each cell individually.
3423 *
3424 * @code
3425 *   face_integrals[cell->face(face_no)] = face_integral;
3426 *   }
3427 *  
3428 *  
3429 * @endcode
3430 *
3431 *
3432 * <a name="step_14-Computingedgetermerrorcontributions2"></a>
3433 * <h4>Computing edge term error contributions -- 2</h4>
3434 *
3435
3436 *
3437 * We are still missing the case of faces with hanging nodes. This is what
3438 * is covered in this function:
3439 *
3440 * @code
3441 *   template <int dim>
3442 *   void WeightedResidual<dim>::integrate_over_irregular_face(
3443 *   const active_cell_iterator &cell,
3444 *   const unsigned int face_no,
3445 *   const Vector<double> &primal_solution,
3446 *   const Vector<double> &dual_weights,
3447 *   FaceData &face_data,
3448 *   FaceIntegrals &face_integrals) const
3449 *   {
3450 * @endcode
3451 *
3452 * First again two abbreviations, and some consistency checks whether
3453 * the function is called only on faces for which it is supposed to be
3454 * called:
3455 *
3456 * @code
3457 *   const unsigned int n_q_points =
3458 *   face_data.fe_face_values_cell.n_quadrature_points;
3459 *  
3460 *   const typename DoFHandler<dim>::face_iterator face = cell->face(face_no);
3461 *   const typename DoFHandler<dim>::cell_iterator neighbor =
3462 *   cell->neighbor(face_no);
3463 *   Assert(neighbor.state() == IteratorState::valid, ExcInternalError());
3464 *   Assert(neighbor->has_children(), ExcInternalError());
3465 *   (void)neighbor;
3466 *  
3467 * @endcode
3468 *
3469 * Then find out which neighbor the present cell is of the adjacent
3470 * cell. Note that we will operate on the children of this adjacent
3471 * cell, but that their orientation is the same as that of their mother,
3472 * i.e. the neighbor direction is the same.
3473 *
3474 * @code
3475 *   const unsigned int neighbor_neighbor =
3476 *   cell->neighbor_of_neighbor(face_no);
3477 *  
3478 * @endcode
3479 *
3480 * Then simply do everything we did in the previous function for one
3481 * face for all the sub-faces now:
3482 *
3483 * @code
3484 *   for (unsigned int subface_no = 0; subface_no < face->n_children();
3485 *   ++subface_no)
3486 *   {
3487 * @endcode
3488 *
3489 * Start with some checks again: get an iterator pointing to the
3490 * cell behind the present subface and check whether its face is a
3491 * subface of the one we are considering. If that were not the case,
3492 * then there would be either a bug in the
3493 * <code>neighbor_neighbor</code> function called above, or -- worse
3494 * -- some function in the library did not keep to some underlying
3495 * assumptions about cells, their children, and their faces. In any
3496 * case, even though this assertion should not be triggered, it does
3497 * not harm to be cautious, and in optimized mode computations the
3498 * assertion will be removed anyway.
3499 *
3500 * @code
3501 *   const active_cell_iterator neighbor_child =
3502 *   cell->neighbor_child_on_subface(face_no, subface_no);
3503 *   Assert(neighbor_child->face(neighbor_neighbor) ==
3504 *   cell->face(face_no)->child(subface_no),
3505 *   ExcInternalError());
3506 *  
3507 * @endcode
3508 *
3509 * Now start the work by again getting the gradient of the solution
3510 * first at this side of the interface,
3511 *
3512 * @code
3513 *   face_data.fe_subface_values_cell.reinit(cell, face_no, subface_no);
3514 *   face_data.fe_subface_values_cell.get_function_gradients(
3515 *   primal_solution, face_data.cell_grads);
3516 * @endcode
3517 *
3518 * then at the other side,
3519 *
3520 * @code
3521 *   face_data.fe_face_values_neighbor.reinit(neighbor_child,
3522 *   neighbor_neighbor);
3523 *   face_data.fe_face_values_neighbor.get_function_gradients(
3524 *   primal_solution, face_data.neighbor_grads);
3525 *  
3526 * @endcode
3527 *
3528 * and finally building the jump residuals. Since we take the normal
3529 * vector from the other cell this time, revert the sign of the
3530 * first term compared to the other function:
3531 *
3532 * @code
3533 *   for (unsigned int p = 0; p < n_q_points; ++p)
3534 *   face_data.jump_residual[p] =
3535 *   ((face_data.neighbor_grads[p] - face_data.cell_grads[p]) *
3536 *   face_data.fe_face_values_neighbor.normal_vector(p));
3537 *  
3538 * @endcode
3539 *
3540 * Then get dual weights:
3541 *
3542 * @code
3543 *   face_data.fe_face_values_neighbor.get_function_values(
3544 *   dual_weights, face_data.dual_weights);
3545 *  
3546 * @endcode
3547 *
3548 * At last, sum up the contribution of this sub-face, and set it in
3549 * the global map:
3550 *
3551 * @code
3552 *   double face_integral = 0;
3553 *   for (unsigned int p = 0; p < n_q_points; ++p)
3554 *   face_integral +=
3555 *   (face_data.jump_residual[p] * face_data.dual_weights[p] *
3556 *   face_data.fe_face_values_neighbor.JxW(p));
3557 *   face_integrals[neighbor_child->face(neighbor_neighbor)] =
3558 *   face_integral;
3559 *   }
3560 *  
3561 * @endcode
3562 *
3563 * Once the contributions of all sub-faces are computed, loop over all
3564 * sub-faces to collect and store them with the mother face for simple
3565 * use when later collecting the error terms of cells. Again make safety
3566 * checks that the entries for the sub-faces have been computed and do
3567 * not carry an invalid value.
3568 *
3569 * @code
3570 *   double sum = 0;
3571 *   for (unsigned int subface_no = 0; subface_no < face->n_children();
3572 *   ++subface_no)
3573 *   {
3574 *   Assert(face_integrals.find(face->child(subface_no)) !=
3575 *   face_integrals.end(),
3576 *   ExcInternalError());
3577 *   Assert(face_integrals[face->child(subface_no)] != -1e20,
3578 *   ExcInternalError());
3579 *  
3580 *   sum += face_integrals[face->child(subface_no)];
3581 *   }
3582 * @endcode
3583 *
3584 * Finally store the value with the parent face.
3585 *
3586 * @code
3587 *   face_integrals[face] = sum;
3588 *   }
3589 *  
3590 *   } // namespace LaplaceSolver
3591 *  
3592 *  
3593 * @endcode
3594 *
3595 *
3596 * <a name="step_14-Asimulationframework"></a>
3597 * <h3>A simulation framework</h3>
3598 *
3599
3600 *
3601 * In the previous example program, we have had two functions that were used
3602 * to drive the process of solving on subsequently finer grids. We extend
3603 * this here to allow for a number of parameters to be passed to these
3604 * functions, and put all of that into framework class.
3605 *
3606
3607 *
3608 * You will have noted that this program is built up of a number of small
3609 * parts (evaluation functions, solver classes implementing various
3610 * refinement methods, different dual functionals, different problem and
3611 * data descriptions), which makes the program relatively simple to extend,
3612 * but also allows to solve a large number of different problems by
3613 * replacing one part by another. We reflect this flexibility by declaring a
3614 * structure in the following framework class that holds a number of
3615 * parameters that may be set to test various combinations of the parts of
3616 * this program, and which can be used to test it at various problems and
3617 * discretizations in a simple way.
3618 *
3619 * @code
3620 *   template <int dim>
3621 *   struct Framework
3622 *   {
3623 *   public:
3624 * @endcode
3625 *
3626 * First, we declare two abbreviations for simple use of the respective
3627 * data types:
3628 *
3629 * @code
3630 *   using Evaluator = Evaluation::EvaluationBase<dim>;
3631 *   using EvaluatorList = std::list<Evaluator *>;
3632 *  
3633 *  
3634 * @endcode
3635 *
3636 * Then we have the structure which declares all the parameters that may
3637 * be set. In the default constructor of the structure, these values are
3638 * all set to default values, for simple use.
3639 *
3640 * @code
3641 *   struct ProblemDescription
3642 *   {
3643 * @endcode
3644 *
3645 * First allow for the degrees of the piecewise polynomials by which the
3646 * primal and dual problems will be discretized. They default to (bi-,
3647 * tri-)linear ansatz functions for the primal, and (bi-, tri-)quadratic
3648 * ones for the dual problem. If a refinement criterion is chosen that
3649 * does not need the solution of a dual problem, the value of the dual
3650 * finite element degree is of course ignored.
3651 *
3652 * @code
3653 *   unsigned int primal_fe_degree;
3654 *   unsigned int dual_fe_degree;
3655 *  
3656 * @endcode
3657 *
3658 * Then have an object that describes the problem type, i.e. right hand
3659 * side, domain, boundary values, etc. The pointer needed here defaults
3660 * to the Null pointer, i.e. you will have to set it in actual instances
3661 * of this object to make it useful.
3662 *
3663 * @code
3664 *   std::unique_ptr<const Data::SetUpBase<dim>> data;
3665 *  
3666 * @endcode
3667 *
3668 * Since we allow to use different refinement criteria (global
3669 * refinement, refinement by the Kelly error indicator, possibly with a
3670 * weight, and using the dual estimator), define a number of enumeration
3671 * values, and subsequently a variable of that type. It will default to
3672 * <code>dual_weighted_error_estimator</code>.
3673 *
3674 * @code
3675 *   enum RefinementCriterion
3676 *   {
3677 *   dual_weighted_error_estimator,
3678 *   global_refinement,
3679 *   kelly_indicator,
3680 *   weighted_kelly_indicator
3681 *   };
3682 *  
3683 *   RefinementCriterion refinement_criterion;
3684 *  
3685 * @endcode
3686 *
3687 * Next, an object that describes the dual functional. It is only needed
3688 * if the dual weighted residual refinement is chosen, and also defaults
3689 * to a Null pointer.
3690 *
3691 * @code
3692 *   std::unique_ptr<const DualFunctional::DualFunctionalBase<dim>>
3693 *   dual_functional;
3694 *  
3695 * @endcode
3696 *
3697 * Then a list of evaluation objects. Its default value is empty,
3698 * i.e. no evaluation objects.
3699 *
3700 * @code
3701 *   EvaluatorList evaluator_list;
3702 *  
3703 * @endcode
3704 *
3705 * Next to last, a function that is used as a weight to the
3706 * <code>RefinementWeightedKelly</code> class. The default value of this
3707 * pointer is zero, but you have to set it to some other value if you
3708 * want to use the <code>weighted_kelly_indicator</code> refinement
3709 * criterion.
3710 *
3711 * @code
3712 *   std::unique_ptr<const Function<dim>> kelly_weight;
3713 *  
3714 * @endcode
3715 *
3716 * Finally, we have a variable that denotes the maximum number of
3717 * degrees of freedom we allow for the (primal) discretization. If it is
3718 * exceeded, we stop the process of solving and intermittent mesh
3719 * refinement. Its default value is 20,000.
3720 *
3721 * @code
3722 *   unsigned int max_degrees_of_freedom;
3723 *  
3724 * @endcode
3725 *
3726 * Finally the default constructor of this class:
3727 *
3728 * @code
3729 *   ProblemDescription();
3730 *   };
3731 *  
3732 * @endcode
3733 *
3734 * The driver framework class only has one method which calls solver and
3735 * mesh refinement intermittently, and does some other small tasks in
3736 * between. Since it does not need data besides the parameters given to
3737 * it, we make it static:
3738 *
3739 * @code
3740 *   static void run(const ProblemDescription &descriptor);
3741 *   };
3742 *  
3743 *  
3744 * @endcode
3745 *
3746 * As for the implementation, first the constructor of the parameter object,
3747 * setting all values to their defaults:
3748 *
3749 * @code
3750 *   template <int dim>
3751 *   Framework<dim>::ProblemDescription::ProblemDescription()
3752 *   : primal_fe_degree(1)
3753 *   , dual_fe_degree(2)
3754 *   , refinement_criterion(dual_weighted_error_estimator)
3755 *   , max_degrees_of_freedom(20000)
3756 *   {}
3757 *  
3758 *  
3759 *  
3760 * @endcode
3761 *
3762 * Then the function which drives the whole process:
3763 *
3764 * @code
3765 *   template <int dim>
3766 *   void Framework<dim>::run(const ProblemDescription &descriptor)
3767 *   {
3768 * @endcode
3769 *
3770 * First create a triangulation from the given data object,
3771 *
3772 * @code
3775 *   descriptor.data->create_coarse_grid(triangulation);
3776 *  
3777 * @endcode
3778 *
3779 * then a set of finite elements and appropriate quadrature formula:
3780 *
3781 * @code
3782 *   const FE_Q<dim> primal_fe(descriptor.primal_fe_degree);
3783 *   const FE_Q<dim> dual_fe(descriptor.dual_fe_degree);
3784 *   const QGauss<dim> quadrature(descriptor.dual_fe_degree + 1);
3785 *   const QGauss<dim - 1> face_quadrature(descriptor.dual_fe_degree + 1);
3786 *  
3787 * @endcode
3788 *
3789 * Next, select one of the classes implementing different refinement
3790 * criteria.
3791 *
3792 * @code
3793 *   std::unique_ptr<LaplaceSolver::Base<dim>> solver;
3794 *   switch (descriptor.refinement_criterion)
3795 *   {
3796 *   case ProblemDescription::dual_weighted_error_estimator:
3797 *   {
3798 *   solver = std::make_unique<LaplaceSolver::WeightedResidual<dim>>(
3799 *   triangulation,
3800 *   primal_fe,
3801 *   dual_fe,
3802 *   quadrature,
3803 *   face_quadrature,
3804 *   descriptor.data->get_right_hand_side(),
3805 *   descriptor.data->get_boundary_values(),
3806 *   *descriptor.dual_functional);
3807 *   break;
3808 *   }
3809 *  
3810 *   case ProblemDescription::global_refinement:
3811 *   {
3812 *   solver = std::make_unique<LaplaceSolver::RefinementGlobal<dim>>(
3813 *   triangulation,
3814 *   primal_fe,
3815 *   quadrature,
3816 *   face_quadrature,
3817 *   descriptor.data->get_right_hand_side(),
3818 *   descriptor.data->get_boundary_values());
3819 *   break;
3820 *   }
3821 *  
3822 *   case ProblemDescription::kelly_indicator:
3823 *   {
3824 *   solver = std::make_unique<LaplaceSolver::RefinementKelly<dim>>(
3825 *   triangulation,
3826 *   primal_fe,
3827 *   quadrature,
3828 *   face_quadrature,
3829 *   descriptor.data->get_right_hand_side(),
3830 *   descriptor.data->get_boundary_values());
3831 *   break;
3832 *   }
3833 *  
3834 *   case ProblemDescription::weighted_kelly_indicator:
3835 *   {
3836 *   solver =
3837 *   std::make_unique<LaplaceSolver::RefinementWeightedKelly<dim>>(
3838 *   triangulation,
3839 *   primal_fe,
3840 *   quadrature,
3841 *   face_quadrature,
3842 *   descriptor.data->get_right_hand_side(),
3843 *   descriptor.data->get_boundary_values(),
3844 *   *descriptor.kelly_weight);
3845 *   break;
3846 *   }
3847 *  
3848 *   default:
3849 *   AssertThrow(false, ExcInternalError());
3850 *   }
3851 *  
3852 * @endcode
3853 *
3854 * Now that all objects are in place, run the main loop. The stopping
3855 * criterion is implemented at the bottom of the loop.
3856 *
3857
3858 *
3859 * In the loop, first set the new cycle number, then solve the problem,
3860 * output its solution(s), apply the evaluation objects to it, then decide
3861 * whether we want to refine the mesh further and solve again on this
3862 * mesh, or jump out of the loop.
3863 *
3864 * @code
3865 *   for (unsigned int step = 0; true; ++step)
3866 *   {
3867 *   std::cout << "Refinement cycle: " << step << std::endl;
3868 *  
3869 *   solver->set_refinement_cycle(step);
3870 *   solver->solve_problem();
3871 *   solver->output_solution();
3872 *  
3873 *   std::cout << " Number of degrees of freedom: " << solver->n_dofs()
3874 *   << std::endl;
3875 *  
3876 *   for (const auto &evaluator : descriptor.evaluator_list)
3877 *   {
3878 *   evaluator->set_refinement_cycle(step);
3879 *   solver->postprocess(*evaluator);
3880 *   }
3881 *  
3882 *  
3883 *   if (solver->n_dofs() < descriptor.max_degrees_of_freedom)
3884 *   solver->refine_grid();
3885 *   else
3886 *   break;
3887 *   }
3888 *  
3889 * @endcode
3890 *
3891 * Clean up the screen after the loop has run:
3892 *
3893 * @code
3894 *   std::cout << std::endl;
3895 *   }
3896 *  
3897 *   } // namespace Step14
3898 *  
3899 *  
3900 *  
3901 * @endcode
3902 *
3903 *
3904 * <a name="step_14-Themainfunction"></a>
3905 * <h3>The main function</h3>
3906 *
3907
3908 *
3909 * Here finally comes the main function. It drives the whole process by
3910 * specifying a set of parameters to be used for the simulation (polynomial
3911 * degrees, evaluation and dual functionals, etc), and passes them packed into
3912 * a structure to the frame work class above.
3913 *
3914 * @code
3915 *   int main()
3916 *   {
3917 *   try
3918 *   {
3919 *   using namespace Step14;
3920 *  
3921 * @endcode
3922 *
3923 * Describe the problem we want to solve here by passing a descriptor
3924 * object to the function doing the rest of the work:
3925 *
3926 * @code
3927 *   const unsigned int dim = 2;
3928 *   Framework<dim>::ProblemDescription descriptor;
3929 *  
3930 * @endcode
3931 *
3932 * First set the refinement criterion we wish to use:
3933 *
3934 * @code
3935 *   descriptor.refinement_criterion =
3936 *   Framework<dim>::ProblemDescription::dual_weighted_error_estimator;
3937 * @endcode
3938 *
3939 * Here, we could as well have used <code>global_refinement</code> or
3940 * <code>weighted_kelly_indicator</code>. Note that the information
3941 * given about dual finite elements, dual functional, etc is only
3942 * important for the given choice of refinement criterion, and is
3943 * ignored otherwise.
3944 *
3945
3946 *
3947 * Then set the polynomial degrees of primal and dual problem. We choose
3948 * here bi-linear and bi-quadratic ones:
3949 *
3950 * @code
3951 *   descriptor.primal_fe_degree = 1;
3952 *   descriptor.dual_fe_degree = 2;
3953 *  
3954 * @endcode
3955 *
3956 * Then set the description of the test case, i.e. domain, boundary
3957 * values, and right hand side. These are prepackaged in classes. We
3958 * take here the description of <code>Exercise_2_3</code>, but you can
3959 * also use <code>CurvedRidges@<dim@></code>:
3960 *
3961 * @code
3962 *   descriptor.data =
3963 *   std::make_unique<Data::SetUp<Data::Exercise_2_3<dim>, dim>>();
3964 *  
3965 * @endcode
3966 *
3967 * Next set first a dual functional, then a list of evaluation
3968 * objects. We choose as default the evaluation of the value at an
3969 * evaluation point, represented by the classes
3970 * <code>PointValueEvaluation</code> in the namespaces of evaluation and
3971 * dual functional classes. You can also set the
3972 * <code>PointXDerivativeEvaluation</code> classes for the x-derivative
3973 * instead of the value at the evaluation point.
3974 *
3975
3976 *
3977 * Note that dual functional and evaluation objects should
3978 * match. However, you can give as many evaluation functionals as you
3979 * want, so you can have both point value and derivative evaluated after
3980 * each step. One such additional evaluation is to output the grid in
3981 * each step.
3982 *
3983 * @code
3984 *   const Point<dim> evaluation_point(0.75, 0.75);
3985 *   descriptor.dual_functional =
3986 *   std::make_unique<DualFunctional::PointValueEvaluation<dim>>(
3987 *   evaluation_point);
3988 *  
3989 *   Evaluation::PointValueEvaluation<dim> postprocessor1(evaluation_point);
3990 *   Evaluation::GridOutput<dim> postprocessor2("grid");
3991 *  
3992 *   descriptor.evaluator_list.push_back(&postprocessor1);
3993 *   descriptor.evaluator_list.push_back(&postprocessor2);
3994 *  
3995 * @endcode
3996 *
3997 * Set the maximal number of degrees of freedom after which we want the
3998 * program to stop refining the mesh further:
3999 *
4000 * @code
4001 *   descriptor.max_degrees_of_freedom = 20000;
4002 *  
4003 * @endcode
4004 *
4005 * Finally pass the descriptor object to a function that runs the entire
4006 * solution with it:
4007 *
4008 * @code
4009 *   Framework<dim>::run(descriptor);
4010 *   }
4011 *  
4012 * @endcode
4013 *
4014 * Catch exceptions to give information about things that failed:
4015 *
4016 * @code
4017 *   catch (std::exception &exc)
4018 *   {
4019 *   std::cerr << std::endl
4020 *   << std::endl
4021 *   << "----------------------------------------------------"
4022 *   << std::endl;
4023 *   std::cerr << "Exception on processing: " << std::endl
4024 *   << exc.what() << std::endl
4025 *   << "Aborting!" << std::endl
4026 *   << "----------------------------------------------------"
4027 *   << std::endl;
4028 *   return 1;
4029 *   }
4030 *   catch (...)
4031 *   {
4032 *   std::cerr << std::endl
4033 *   << std::endl
4034 *   << "----------------------------------------------------"
4035 *   << std::endl;
4036 *   std::cerr << "Unknown exception!" << std::endl
4037 *   << "Aborting!" << std::endl
4038 *   << "----------------------------------------------------"
4039 *   << std::endl;
4040 *   return 1;
4041 *   }
4042 *  
4043 *   return 0;
4044 *   }
4045 * @endcode
4046<a name="step_14-Results"></a><h1>Results</h1>
4047
4048
4049<a name="step_14-Pointvalues"></a><h3>Point values</h3>
4050
4051
4052
4053This program offers a lot of possibilities to play around. We can thus
4054only show a small part of all possible results that can be obtained
4055with the help of this program. However, you are encouraged to just try
4056it out, by changing the settings in the main program. Here, we start
4057by simply letting it run, unmodified:
4058@code
4059Refinement cycle: 0
4060 Number of degrees of freedom: 72
4061 Point value: 0.03243
4062 Estimated error: 0.000702385
4063Refinement cycle: 1
4064 Number of degrees of freedom: 67
4065 Point value: 0.0324827
4066 Estimated error: 0.000888953
4067Refinement cycle: 2
4068 Number of degrees of freedom: 130
4069 Point value: 0.0329619
4070 Estimated error: 0.000454606
4071Refinement cycle: 3
4072 Number of degrees of freedom: 307
4073 Point value: 0.0331934
4074 Estimated error: 0.000241254
4075Refinement cycle: 4
4076 Number of degrees of freedom: 718
4077 Point value: 0.0333675
4078 Estimated error: 7.4912e-05
4079Refinement cycle: 5
4080 Number of degrees of freedom: 1665
4081 Point value: 0.0334083
4082 Estimated error: 3.69111e-05
4083Refinement cycle: 6
4084 Number of degrees of freedom: 3975
4085 Point value: 0.033431
4086 Estimated error: 1.54218e-05
4087Refinement cycle: 7
4088 Number of degrees of freedom: 8934
4089 Point value: 0.0334406
4090 Estimated error: 6.28359e-06
4091Refinement cycle: 8
4092 Number of degrees of freedom: 21799
4093 Point value: 0.0334444
4094@endcode
4095
4096
4097First let's look what the program actually computed. On the seventh
4098grid, primal and dual numerical solutions look like this (using a
4099color scheme intended to evoke the snow-capped mountains of
4100Colorado that the original author of this program now calls
4101home):
4102<table align="center">
4103 <tr>
4104 <td width="50%">
4105 <img src="https://www.dealii.org/images/steps/developer/step-14.point-value.solution-7.9.2.png" alt="">
4106 </td>
4107 <td width="50%">
4108 <img src="https://www.dealii.org/images/steps/developer/step-14.point-value.solution-7-dual.9.2.png" alt="">
4109 </td>
4110 </tr>
4111</table>
4112Apparently, the region at the bottom left is so unimportant for the
4113point value evaluation at the top right that the grid is left entirely
4114unrefined there, even though the solution has singularities at the inner
4115corner of that cell! Due
4116to the symmetry in right hand side and domain, the solution should
4117actually look like at the top right in all four corners, but the mesh
4118refinement criterion involving the dual solution chose to refine them
4119differently -- because we said that we really only care about a single
4120function value somewhere at the top right.
4121
4122
4123
4124Here are some of the meshes that are produced in refinement cycles 0,
41252, 4 (top row), and 5, 7, and 8 (bottom row):
4126
4127<table width="80%" align="center">
4128 <tr>
4129 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-value.grid-0.9.2.png" alt="" width="100%"></td>
4130 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-value.grid-2.9.2.png" alt="" width="100%"></td>
4131 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-value.grid-4.9.2.png" alt="" width="100%"></td>
4132 </tr>
4133 <tr>
4134 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-value.grid-5.9.2.png" alt="" width="100%"></td>
4135 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-value.grid-7.9.2.png" alt="" width="100%"></td>
4136 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-value.grid-8.9.2.png" alt="" width="100%"></td>
4137 </tr>
4138</table>
4139
4140Note the subtle interplay between resolving the corner singularities,
4141and resolving around the point of evaluation. It will be rather
4142difficult to generate such a mesh by hand, as this would involve to
4143judge quantitatively how much which of the four corner singularities
4144should be resolved, and to set the weight compared to the vicinity of
4145the evaluation point.
4146
4147
4148
4149The program prints the point value and the estimated error in this
4150quantity. From extrapolating it, we can guess that the exact value is
4151somewhere close to 0.0334473, plus or minus 0.0000001 (note that we get
4152almost 6 valid digits from only 22,000 (primal) degrees of
4153freedom. This number cannot be obtained from the value of the
4154functional alone, but I have used the assumption that the error
4155estimator is mostly exact, and extrapolated the computed value plus
4156the estimated error, to get an approximation of the true
4157value. Computing with more degrees of freedom shows that this
4158assumption is indeed valid.
4159
4160
4161
4162From the computed results, we can generate two graphs: one that shows
4163the convergence of the error @f$J(u)-J(u_h)@f$ (taking the
4164extrapolated value as correct) in the point value, and the value that
4165we get by adding up computed value @f$J(u_h)@f$ and estimated
4166error eta (if the error estimator @f$eta@f$ were exact, then the value
4167@f$J(u_h)+\eta@f$ would equal the exact point value, and the error
4168in this quantity would always be zero; however, since the error
4169estimator is only a - good - approximation to the true error, we can
4170by this only reduce the size of the error). In this graph, we also
4171indicate the complexity @f${\cal O}(1/N)@f$ to show that mesh refinement
4172acts optimal in this case. The second chart compares
4173true and estimated error, and shows that the two are actually very
4174close to each other, even for such a complicated quantity as the point
4175value:
4176
4177
4178<table width="80%" align="center">
4179 <tr>
4180 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-value.error.png" alt="" width="100%"></td>
4181 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-value.error-estimation.png" alt="" width="100%"></td>
4182 </tr>
4183</table>
4184
4185
4186<a name="step_14-Comparingrefinementcriteria"></a><h3>Comparing refinement criteria</h3>
4187
4188
4189
4190Since we have accepted quite some effort when using the mesh
4191refinement driven by the dual weighted error estimator (for solving
4192the dual problem, and for evaluating the error representation), it is
4193worth while asking whether that effort was successful. To this end, we
4194first compare the achieved error levels for different mesh refinement
4195criteria. To generate this data, simply change the value of the mesh
4196refinement criterion variable in the main program. The results are
4197thus (for the weight in the Kelly indicator, we have chosen the
4198function @f$1/(r^2+0.1^2)@f$, where @f$r@f$
4199is the distance to the evaluation point; it can be shown that this is
4200the optimal weight if we neglect the effects of boundaries):
4201
4202<img src="https://www.dealii.org/images/steps/developer/step-14.point-value.error-comparison.png" alt="">
4203
4204
4205
4206Checking these numbers, we see that for global refinement, the error
4207is proportional to @f$O(1/(sqrt(N) log(N)))@f$, and for the dual
4208estimator @f$O(1/N)@f$. Generally speaking, we see that the dual
4209weighted error estimator is better than the other refinement
4210indicators, at least when compared with those that have a similarly
4211regular behavior. The Kelly indicator produces smaller errors, but
4212jumps about the picture rather irregularly, with the error also
4213changing signs sometimes. Therefore, its behavior does not allow to
4214extrapolate the results to larger values of N. Furthermore, if we
4215trust the error estimates of the dual weighted error estimator, the
4216results can be improved by adding the estimated error to the computed
4217values. In terms of reliability, the weighted estimator is thus better
4218than the Kelly indicator, although the latter sometimes produces
4219smaller errors.
4220
4221
4222
4223<a name="step_14-Evaluationofpointstresses"></a><h3>Evaluation of point stresses</h3>
4224
4225
4226
4227Besides evaluating the values of the solution at a certain point, the
4228program also offers the possibility to evaluate the x-derivatives at a
4229certain point, and also to tailor mesh refinement for this. To let the
4230program compute these quantities, simply replace the two occurrences of
4231<code>PointValueEvaluation</code> in the main function by
4232<code>PointXDerivativeEvaluation</code>, and let the program run:
4233@code
4234Refinement cycle: 0
4235 Number of degrees of freedom: 72
4236 Point x-derivative: -0.0719397
4237 Estimated error: -0.0126173
4238Refinement cycle: 1
4239 Number of degrees of freedom: 61
4240 Point x-derivative: -0.0707956
4241 Estimated error: -0.00774316
4242Refinement cycle: 2
4243 Number of degrees of freedom: 131
4244 Point x-derivative: -0.0568671
4245 Estimated error: -0.00313426
4246Refinement cycle: 3
4247 Number of degrees of freedom: 247
4248 Point x-derivative: -0.053033
4249 Estimated error: -0.00136114
4250Refinement cycle: 4
4251 Number of degrees of freedom: 532
4252 Point x-derivative: -0.0526429
4253 Estimated error: -0.000558868
4254Refinement cycle: 5
4255 Number of degrees of freedom: 1267
4256 Point x-derivative: -0.0526955
4257 Estimated error: -0.000220116
4258Refinement cycle: 6
4259 Number of degrees of freedom: 2864
4260 Point x-derivative: -0.0527495
4261 Estimated error: -9.46731e-05
4262Refinement cycle: 7
4263 Number of degrees of freedom: 6409
4264 Point x-derivative: -0.052785
4265 Estimated error: -4.21543e-05
4266Refinement cycle: 8
4267 Number of degrees of freedom: 14183
4268 Point x-derivative: -0.0528028
4269 Estimated error: -2.04241e-05
4270Refinement cycle: 9
4271 Number of degrees of freedom: 29902
4272 Point x-derivative: -0.052814
4273@endcode
4274
4275
4276
4277The solution looks roughly the same as before (the exact solution of
4278course <em>is</em> the same, only the grid changed a little), but the
4279dual solution is now different. A close-up around the point of
4280evaluation shows this:
4281<table align="center">
4282 <tr>
4283 <td width="50%">
4284 <img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.solution-7-dual.png" alt="">
4285 </td>
4286 <td width="50%">
4287 <img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.solution-7-dual-close-up.png" alt="">
4288 </td>
4289</table>
4290This time, the grids in refinement cycles 0, 5, 6, 7, 8, and 9 look
4291like this:
4292
4293<table align="center" width="80%">
4294 <tr>
4295 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.grid-0.9.2.png" alt="" width="100%"></td>
4296 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.grid-5.9.2.png" alt="" width="100%"></td>
4297 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.grid-6.9.2.png" alt="" width="100%"></td>
4298 </tr>
4299 <tr>
4300 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.grid-7.9.2.png" alt="" width="100%"></td>
4301 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.grid-8.9.2.png" alt="" width="100%"></td>
4302 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.grid-9.9.2.png" alt="" width="100%"></td>
4303 </tr>
4304</table>
4305
4306Note the asymmetry of the grids compared with those we obtained for
4307the point evaluation. This is due to the fact that the domain and the primal
4308solution may be symmetric about the diagonal, but the @f$x@f$-derivative is
4309not, and the latter enters the refinement criterion.
4310
4311
4312
4313Then, it is interesting to compare actually computed values of the
4314quantity of interest (i.e. the x-derivative of the solution at one
4315point) with a reference value of -0.0528223... plus or minus
43160.0000005. We get this reference value by computing on finer grid after
4317some more mesh refinements, with approximately 130,000 cells.
4318Recall that if the error is @f$O(1/N)@f$ in the optimal case, then
4319taking a mesh with ten times more cells gives us one additional digit
4320in the result.
4321
4322
4323
4324In the left part of the following chart, you again see the convergence
4325of the error towards this extrapolated value, while on the right you
4326see a comparison of true and estimated error:
4327
4328<table width="80%" align="center">
4329 <tr>
4330 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.error.png" alt="" width="100%"></td>
4331 <td><img src="https://www.dealii.org/images/steps/developer/step-14.point-derivative.error-estimation.png" alt="" width="100%"></td>
4332 </tr>
4333</table>
4334
4335After an initial phase where the true error changes its sign, the
4336estimated error matches it quite well, again. Also note the dramatic
4337improvement in the error when using the estimated error to correct the
4338computed value of @f$J(u_h)@f$.
4339
4340
4341
4342<a name="step_14-step13revisited"></a><h3>step-13 revisited</h3>
4343
4344
4345
4346If instead of the <code>Exercise_2_3</code> data set, we choose
4347<code>CurvedRidges</code> in the main function, and choose @f$(0.5,0.5)@f$
4348as the evaluation point, then we can redo the
4349computations of the previous example program, to compare whether the
4350results obtained with the help of the dual weighted error estimator
4351are better than those we had previously.
4352
4353
4354
4355First, the meshes after 9 adaptive refinement cycles obtained with
4356the point evaluation and derivative evaluation refinement
4357criteria, respectively, look like this:
4358
4359<table width="80%" align="center">
4360 <tr>
4361 <td><img src="https://www.dealii.org/images/steps/developer/step-14.step-13.point-value.png" alt="" width="100%"></td>
4362 <td><img src="https://www.dealii.org/images/steps/developer/step-14.step-13.point-derivative.png" alt="" width="100%"></td>
4363 </tr>
4364</table>
4365
4366The features of the solution can still be seen in the mesh, but since the
4367solution is smooth, the singularities of the dual solution entirely
4368dominate the mesh refinement criterion, and lead to strongly
4369concentrated meshes. The solution after the seventh refinement step looks
4370like the following:
4371
4372<table width="40%" align="center">
4373 <tr>
4374 <td><img src="https://www.dealii.org/images/steps/developer/step-14.step-13.solution-7.9.2.png" alt="" width="100%"></td>
4375 </tr>
4376</table>
4377
4378Obviously, the solution is worse at some places, but the mesh
4379refinement process should have taken care that these places are not
4380important for computing the point value.
4381
4382
4383
4384
4385The next point is to compare the new (duality based) mesh refinement
4386criterion with the old ones. These are the results:
4387
4388<img src="https://www.dealii.org/images/steps/developer/step-14.step-13.error-comparison.png" alt="">
4389
4390
4391
4392The results are, well, somewhat mixed. First, the Kelly indicator
4393disqualifies itself by its unsteady behavior, changing the sign of the
4394error several times, and with increasing errors under mesh
4395refinement. The dual weighted error estimator has a monotone decrease
4396in the error, and is better than the weighted Kelly and global
4397refinement, but the margin is not as large as expected. This is, here,
4398due to the fact the global refinement can exploit the regular
4399structure of the meshes around the point of evaluation, which leads to
4400a better order of convergence for the point error. However, if we had
4401a mesh that is not locally rectangular, for example because we had to
4402approximate curved boundaries, or if the coefficients were not
4403constant, then this advantage of globally refinement meshes would
4404vanish, while the good performance of the duality based estimator
4405would remain.
4406
4407
4408
4409
4410<a name="step_14-Conclusionsandoutlook"></a><h3>Conclusions and outlook</h3>
4411
4412
4413
4414The results here are not too clearly indicating the superiority of the
4415dual weighted error estimation approach for mesh refinement over other
4416mesh refinement criteria, such as the Kelly indicator. This is due to
4417the relative simplicity of the shown applications. If you are not
4418convinced yet that this approach is indeed superior, you are invited
4419to browse through the literature indicated in the introduction, where
4420plenty of examples are provided where the dual weighted approach can
4421reduce the necessary numerical work by orders of magnitude, making
4422this the only way to compute certain quantities to reasonable
4423accuracies at all.
4424
4425
4426
4427Besides the objections you may raise against its use as a mesh
4428refinement criterion, consider that accurate knowledge of the error in
4429the quantity one might want to compute is of great use, since we can
4430stop computations when we are satisfied with the accuracy. Using more
4431traditional approaches, it is very difficult to get accurate estimates
4432for arbitrary quantities, except for, maybe, the error in the energy
4433norm, and we will then have no guarantee that the result we computed
4434satisfies any requirements on its accuracy. Also, as was shown for the
4435evaluation of point values and derivatives, the error estimate can be
4436used to extrapolate the results, yielding much higher accuracy in the
4437quantity we want to know.
4438
4439
4440
4441Leaving these mathematical considerations, we tried to write the
4442program in a modular way, such that implementing another test case, or
4443another evaluation and dual functional is simple. You are encouraged
4444to take the program as a basis for your own experiments, and to play a
4445little.
4446 *
4447 *
4448<a name="step_14-PlainProg"></a>
4449<h1> The plain program</h1>
4450@include "step-14.cc"
4451*/
void attach_dof_handler(const DoFHandler< dim, spacedim > &)
types::global_dof_index n_dofs() const
Definition fe_q.h:554
void write_svg(const Triangulation< 2, 2 > &tria, std::ostream &out) const
Definition grid_out.cc:1702
static void estimate(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< dim - 1 > &quadrature, const std::map< types::boundary_id, const Function< spacedim, Number > * > &neumann_bc, const ReadVector< Number > &solution, Vector< float > &error, const ComponentMask &component_mask={}, const Function< spacedim > *coefficients=nullptr, const unsigned int n_threads=numbers::invalid_unsigned_int, const types::subdomain_id subdomain_id=numbers::invalid_subdomain_id, const types::material_id material_id=numbers::invalid_material_id, const Strategy strategy=cell_diameter_over_24)
Definition point.h:111
void initialize(const MatrixType &A, const AdditionalData &parameters=AdditionalData())
Point< 2 > second
Definition grid_out.cc:4624
Point< 2 > first
Definition grid_out.cc:4623
unsigned int level
Definition grid_out.cc:4626
#define Assert(cond, exc)
#define AssertThrow(cond, exc)
typename ActiveSelector::cell_iterator cell_iterator
typename ActiveSelector::face_iterator face_iterator
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_hanging_node_constraints(const DoFHandler< dim, spacedim > &dof_handler, AffineConstraints< number > &constraints)
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_hessians
Second derivatives of shape functions.
@ 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.
void consistently_order_cells(std::vector< CellData< dim > > &cells)
Task< RT > new_task(const std::function< RT()> &function)
std::vector< index_type > data
Definition mpi.cc:735
std::size_t size
Definition mpi.cc:734
const Event initial
Definition event.cc:64
Expression fabs(const Expression &x)
Expression sign(const Expression &x)
void interpolation_difference(const DoFHandler< dim, spacedim > &dof1, const InVector &z1, const FiniteElement< dim, spacedim > &fe2, OutVector &z1_difference)
void interpolate(const DoFHandler< dim, spacedim > &dof1, const InVector &u1, const DoFHandler< dim, spacedim > &dof2, OutVector &u2)
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())
void coarsen(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double threshold)
void refine_and_coarsen_fixed_fraction(Triangulation< dim, spacedim > &tria, const Vector< Number > &criteria, const double top_fraction, const double bottom_fraction, const unsigned int max_n_cells=std::numeric_limits< unsigned int >::max(), const VectorTools::NormType norm_type=VectorTools::L1_norm)
@ valid
Iterator points to a valid object.
@ matrix
Contents is actually a matrix.
void cell_matrix(FullMatrix< double > &M, const FEValuesBase< dim > &fe, const FEValuesBase< dim > &fetest, const ArrayView< const std::vector< double > > &velocity, const double factor=1.)
Definition advection.h:74
void cell_residual(Vector< double > &result, const FEValuesBase< dim > &fe, const std::vector< Tensor< 1, dim > > &input, const ArrayView< const std::vector< double > > &velocity, double factor=1.)
Definition advection.h:130
void apply_boundary_values(const std::map< types::global_dof_index, number > &boundary_values, SparseMatrix< number > &matrix, Vector< number > &solution, Vector< number > &right_hand_side, const bool eliminate_columns=true)
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:191
SymmetricTensor< 2, dim, Number > C(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 apply(const Kokkos::TeamPolicy< MemorySpace::Default::kokkos_space::execution_space >::member_type &team_member, const Kokkos::View< Number *, MemorySpace::Default::kokkos_space > shape_data, const ViewTypeIn in, ViewTypeOut out)
constexpr ReturnType< rank, T >::value_type & extract(T &t, const ArrayType &indices)
VectorType::value_type * end(VectorType &V)
T sum(const T &t, const MPI_Comm mpi_communicator)
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 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 run(const std::vector< std::vector< Iterator > > &colored_iterators, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)
bool check(const ConstraintKinds kind_in, const unsigned int dim)
void copy(const T *begin, const T *end, U *dest)
int(&) functions(const void *v1, const void *v2)
static const unsigned int invalid_unsigned_int
Definition types.h:220
STL namespace.
Definition types.h:32
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation