deal.II version GIT relicensing-1721-g8100761196 2024-08-31 12:30:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
step-74.h
Go to the documentation of this file.
1) const
274 *   {
275 *   using numbers::PI;
276 *   for (unsigned int i = 0; i < values.size(); ++i)
277 *   values[i] =
278 *   std::sin(2. * PI * points[i][0]) * std::sin(2. * PI * points[i][1]);
279 *   }
280 *  
281 *  
282 *  
283 *   template <int dim>
284 *   Tensor<1, dim>
285 *   SmoothSolution<dim>::gradient(const Point<dim> &point,
286 *   const unsigned int /*component*/) const
287 *   {
288 *   Tensor<1, dim> return_value;
289 *   using numbers::PI;
290 *   return_value[0] =
291 *   2. * PI * std::cos(2. * PI * point[0]) * std::sin(2. * PI * point[1]);
292 *   return_value[1] =
293 *   2. * PI * std::sin(2. * PI * point[0]) * std::cos(2. * PI * point[1]);
294 *   return return_value;
295 *   }
296 *  
297 *  
298 *  
299 * @endcode
300 *
301 * The corresponding right-hand side of the smooth function:
302 *
303 * @code
304 *   template <int dim>
305 *   class SmoothRightHandSide : public Function<dim>
306 *   {
307 *   public:
308 *   SmoothRightHandSide()
309 *   : Function<dim>()
310 *   {}
311 *  
312 *   virtual void value_list(const std::vector<Point<dim>> &points,
313 *   std::vector<double> &values,
314 *   const unsigned int /*component*/) const override;
315 *   };
316 *  
317 *  
318 *  
319 *   template <int dim>
320 *   void
321 *   SmoothRightHandSide<dim>::value_list(const std::vector<Point<dim>> &points,
322 *   std::vector<double> &values,
323 *   const unsigned int /*component*/) const
324 *   {
325 *   using numbers::PI;
326 *   for (unsigned int i = 0; i < values.size(); ++i)
327 *   values[i] = 8. * PI * PI * std::sin(2. * PI * points[i][0]) *
328 *   std::sin(2. * PI * points[i][1]);
329 *   }
330 *  
331 *  
332 *  
333 * @endcode
334 *
335 * The right-hand side that corresponds to the function
337 * assume that the diffusion coefficient @f$\nu = 1@f$:
338 *
339 * @code
340 *   template <int dim>
341 *   class SingularRightHandSide : public Function<dim>
342 *   {
343 *   public:
344 *   SingularRightHandSide()
345 *   : Function<dim>()
346 *   {}
347 *  
348 *   virtual void value_list(const std::vector<Point<dim>> &points,
349 *   std::vector<double> &values,
350 *   const unsigned int /*component*/) const override;
351 *  
352 *   private:
353 *   const Functions::LSingularityFunction ref;
354 *   };
355 *  
356 *  
357 *  
358 *   template <int dim>
359 *   void
360 *   SingularRightHandSide<dim>::value_list(const std::vector<Point<dim>> &points,
361 *   std::vector<double> &values,
362 *   const unsigned int /*component*/) const
363 *   {
364 *   for (unsigned int i = 0; i < values.size(); ++i)
365 *   values[i] = -ref.laplacian(points[i]);
366 *   }
367 *  
368 *  
369 *  
370 * @endcode
371 *
372 *
373 * <a name="step_74-Auxiliaryfunctions"></a>
374 * <h3>Auxiliary functions</h3>
375 * This function computes the penalty @f$\sigma@f$.
376 *
377 * @code
378 *   double get_penalty_factor(const unsigned int fe_degree,
379 *   const double cell_extent_left,
380 *   const double cell_extent_right)
381 *   {
382 *   const unsigned int degree = std::max(1U, fe_degree);
383 *   return degree * (degree + 1.) * 0.5 *
384 *   (1. / cell_extent_left + 1. / cell_extent_right);
385 *   }
386 *  
387 *  
388 * @endcode
389 *
390 *
391 * <a name="step_74-TheCopyData"></a>
392 * <h3>The CopyData</h3>
393 * In the following, we define "Copy" objects for the MeshWorker::mesh_loop(),
394 * which is essentially the same as @ref step_12 "step-12". Note that the
395 * "Scratch" object is not defined here because we use
396 * MeshWorker::ScratchData<dim> instead. (The use of "Copy" and "Scratch"
397 * objects is extensively explained in the WorkStream namespace documentation.
398 *
399 * @code
400 *   struct CopyDataFace
401 *   {
403 *   std::vector<types::global_dof_index> joint_dof_indices;
404 *   std::array<double, 2> values;
405 *   std::array<unsigned int, 2> cell_indices;
406 *   };
407 *  
408 *  
409 *  
410 *   struct CopyData
411 *   {
413 *   Vector<double> cell_rhs;
414 *   std::vector<types::global_dof_index> local_dof_indices;
415 *   std::vector<CopyDataFace> face_data;
416 *   double value;
417 *   unsigned int cell_index;
418 *  
419 *  
420 *   template <class Iterator>
421 *   void reinit(const Iterator &cell, const unsigned int dofs_per_cell)
422 *   {
423 *   cell_matrix.reinit(dofs_per_cell, dofs_per_cell);
424 *   cell_rhs.reinit(dofs_per_cell);
425 *   local_dof_indices.resize(dofs_per_cell);
426 *   cell->get_dof_indices(local_dof_indices);
427 *   }
428 *   };
429 *  
430 *  
431 *  
432 * @endcode
433 *
434 *
435 * <a name="step_74-TheSIPGLaplaceclass"></a>
436 * <h3>The SIPGLaplace class</h3>
437 * After these preparations, we proceed with the main class of this program,
438 * called `SIPGLaplace`. The overall structure of the class is as in many
439 * of the other tutorial programs. Major differences will only come up in the
440 * implementation of the assemble functions, since we use FEInterfaceValues to
441 * assemble face terms.
442 *
443 * @code
444 *   template <int dim>
445 *   class SIPGLaplace
446 *   {
447 *   public:
448 *   SIPGLaplace(const TestCase &test_case);
449 *   void run();
450 *  
451 *   private:
452 *   void setup_system();
453 *   void assemble_system();
454 *   void solve();
455 *   void refine_grid();
456 *   void output_results(const unsigned int cycle) const;
457 *  
458 *   void compute_errors();
459 *   void compute_error_estimate();
460 *   double compute_energy_norm_error();
461 *  
463 *   const unsigned int degree;
464 *   const QGauss<dim> quadrature;
465 *   const QGauss<dim - 1> face_quadrature;
466 *   const QGauss<dim> quadrature_overintegration;
467 *   const QGauss<dim - 1> face_quadrature_overintegration;
468 *   const MappingQ1<dim> mapping;
469 *  
470 *   using ScratchData = MeshWorker::ScratchData<dim>;
471 *  
472 *   const FE_DGQ<dim> fe;
473 *   DoFHandler<dim> dof_handler;
474 *  
475 *   SparsityPattern sparsity_pattern;
476 *   SparseMatrix<double> system_matrix;
477 *   Vector<double> solution;
478 *   Vector<double> system_rhs;
479 *  
480 * @endcode
481 *
482 * The remainder of the class's members are used for the following:
483 * - Vectors to store error estimator square and energy norm square per
484 * cell.
485 * - Print convergence rate and errors on the screen.
486 * - The fiffusion coefficient @f$\nu@f$ is set to 1.
487 * - Members that store information about the test case to be computed.
488 *
489 * @code
490 *   Vector<double> estimated_error_square_per_cell;
491 *   Vector<double> energy_norm_square_per_cell;
492 *  
493 *   ConvergenceTable convergence_table;
494 *  
495 *   const double diffusion_coefficient = 1.;
496 *  
497 *   const TestCase test_case;
498 *   std::unique_ptr<const Function<dim>> exact_solution;
499 *   std::unique_ptr<const Function<dim>> rhs_function;
500 *   };
501 *  
502 * @endcode
503 *
504 * The constructor here takes the test case as input and then
505 * determines the correct solution and right-hand side classes. The
506 * remaining member variables are initialized in the obvious way.
507 *
508 * @code
509 *   template <int dim>
510 *   SIPGLaplace<dim>::SIPGLaplace(const TestCase &test_case)
511 *   : degree(3)
512 *   , quadrature(degree + 1)
513 *   , face_quadrature(degree + 1)
514 *   , quadrature_overintegration(degree + 2)
515 *   , face_quadrature_overintegration(degree + 2)
516 *   , mapping()
517 *   , fe(degree)
518 *   , dof_handler(triangulation)
519 *   , test_case(test_case)
520 *   {
521 *   if (test_case == TestCase::convergence_rate)
522 *   {
523 *   exact_solution = std::make_unique<const SmoothSolution<dim>>();
524 *   rhs_function = std::make_unique<const SmoothRightHandSide<dim>>();
525 *   }
526 *  
527 *   else if (test_case == TestCase::l_singularity)
528 *   {
529 *   exact_solution =
530 *   std::make_unique<const Functions::LSingularityFunction>();
531 *   rhs_function = std::make_unique<const SingularRightHandSide<dim>>();
532 *   }
533 *   else
534 *   AssertThrow(false, ExcNotImplemented());
535 *   }
536 *  
537 *  
538 *  
539 *   template <int dim>
540 *   void SIPGLaplace<dim>::setup_system()
541 *   {
542 *   dof_handler.distribute_dofs(fe);
543 *   DynamicSparsityPattern dsp(dof_handler.n_dofs());
544 *   DoFTools::make_flux_sparsity_pattern(dof_handler, dsp);
545 *   sparsity_pattern.copy_from(dsp);
546 *  
547 *   system_matrix.reinit(sparsity_pattern);
548 *   solution.reinit(dof_handler.n_dofs());
549 *   system_rhs.reinit(dof_handler.n_dofs());
550 *   }
551 *  
552 *  
553 *  
554 * @endcode
555 *
556 *
557 * <a name="step_74-Theassemble_systemfunction"></a>
558 * <h3>The assemble_system function</h3>
559 * The assemble function here is similar to that in @ref step_12 "step-12" and @ref step_47 "step-47".
560 * Different from assembling by hand, we just need to focus
561 * on assembling on each cell, each boundary face, and each
562 * interior face. The loops over cells and faces are handled
563 * automatically by MeshWorker::mesh_loop().
564 *
565
566 *
567 * The function starts by defining a local (lambda) function that is
568 * used to integrate the cell terms:
569 *
570 * @code
571 *   template <int dim>
572 *   void SIPGLaplace<dim>::assemble_system()
573 *   {
574 *   const auto cell_worker =
575 *   [&](const typename DoFHandler<dim>::active_cell_iterator &cell,
576 *   ScratchData &scratch_data,
577 *   CopyData &copy_data) {
578 *   const FEValues<dim> &fe_v = scratch_data.reinit(cell);
579 *   const unsigned int dofs_per_cell = fe_v.dofs_per_cell;
580 *   copy_data.reinit(cell, dofs_per_cell);
581 *  
582 *   const std::vector<Point<dim>> &q_points =
583 *   scratch_data.get_quadrature_points();
584 *   const unsigned int n_q_points = q_points.size();
585 *   const std::vector<double> &JxW = scratch_data.get_JxW_values();
586 *  
587 *   std::vector<double> rhs(n_q_points);
588 *   rhs_function->value_list(q_points, rhs);
589 *  
590 *   for (unsigned int point = 0; point < n_q_points; ++point)
591 *   for (unsigned int i = 0; i < fe_v.dofs_per_cell; ++i)
592 *   {
593 *   for (unsigned int j = 0; j < fe_v.dofs_per_cell; ++j)
594 *   copy_data.cell_matrix(i, j) +=
595 *   diffusion_coefficient * // nu
596 *   fe_v.shape_grad(i, point) * // grad v_h
597 *   fe_v.shape_grad(j, point) * // grad u_h
598 *   JxW[point]; // dx
599 *  
600 *   copy_data.cell_rhs(i) += fe_v.shape_value(i, point) * // v_h
601 *   rhs[point] * // f
602 *   JxW[point]; // dx
603 *   }
604 *   };
605 *  
606 * @endcode
607 *
608 * Next, we need a function that assembles face integrals on the boundary:
609 *
610 * @code
611 *   const auto boundary_worker =
612 *   [&](const typename DoFHandler<dim>::active_cell_iterator &cell,
613 *   const unsigned int &face_no,
614 *   ScratchData &scratch_data,
615 *   CopyData &copy_data) {
616 *   const FEFaceValuesBase<dim> &fe_fv = scratch_data.reinit(cell, face_no);
617 *  
618 *   const std::vector<Point<dim>> &q_points =
619 *   scratch_data.get_quadrature_points();
620 *   const unsigned int n_q_points = q_points.size();
621 *   const unsigned int dofs_per_cell = fe_fv.dofs_per_cell;
622 *  
623 *   const std::vector<double> &JxW = scratch_data.get_JxW_values();
624 *   const std::vector<Tensor<1, dim>> &normals =
625 *   scratch_data.get_normal_vectors();
626 *  
627 *   std::vector<double> g(n_q_points);
628 *   exact_solution->value_list(q_points, g);
629 *  
630 *   const double extent1 = cell->measure() / cell->face(face_no)->measure();
631 *   const double penalty = get_penalty_factor(degree, extent1, extent1);
632 *  
633 *   for (unsigned int point = 0; point < n_q_points; ++point)
634 *   {
635 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
636 *   for (unsigned int j = 0; j < dofs_per_cell; ++j)
637 *   copy_data.cell_matrix(i, j) +=
638 *   (-diffusion_coefficient * // - nu
639 *   fe_fv.shape_value(i, point) * // v_h
640 *   (fe_fv.shape_grad(j, point) * // (grad u_h .
641 *   normals[point]) // n)
642 *  
643 *   - diffusion_coefficient * // - nu
644 *   (fe_fv.shape_grad(i, point) * // (grad v_h .
645 *   normals[point]) * // n)
646 *   fe_fv.shape_value(j, point) // u_h
647 *  
648 *   + diffusion_coefficient * penalty * // + nu sigma
649 *   fe_fv.shape_value(i, point) * // v_h
650 *   fe_fv.shape_value(j, point) // u_h
651 *  
652 *   ) *
653 *   JxW[point]; // dx
654 *  
655 *   for (unsigned int i = 0; i < dofs_per_cell; ++i)
656 *   copy_data.cell_rhs(i) +=
657 *   (-diffusion_coefficient * // - nu
658 *   (fe_fv.shape_grad(i, point) * // (grad v_h .
659 *   normals[point]) * // n)
660 *   g[point] // g
661 *  
662 *  
663 *   + diffusion_coefficient * penalty * // + nu sigma
664 *   fe_fv.shape_value(i, point) * g[point] // v_h g
665 *  
666 *   ) *
667 *   JxW[point]; // dx
668 *   }
669 *   };
670 *  
671 * @endcode
672 *
673 * Finally, a function that assembles face integrals on interior
674 * faces. To reinitialize FEInterfaceValues, we need to pass
675 * cells, face and subface indices (for adaptive refinement) to
676 * the reinit() function of FEInterfaceValues:
677 *
678 * @code
679 *   const auto face_worker =
680 *   [&](const typename DoFHandler<dim>::cell_iterator &cell,
681 *   const unsigned int &f,
682 *   const unsigned int &sf,
683 *   const typename DoFHandler<dim>::cell_iterator &ncell,
684 *   const unsigned int &nf,
685 *   const unsigned int &nsf,
686 *   ScratchData &scratch_data,
687 *   CopyData &copy_data) {
688 *   const FEInterfaceValues<dim> &fe_iv =
689 *   scratch_data.reinit(cell, f, sf, ncell, nf, nsf);
690 *  
691 *   copy_data.face_data.emplace_back();
692 *   CopyDataFace &copy_data_face = copy_data.face_data.back();
693 *   const unsigned int n_dofs_face = fe_iv.n_current_interface_dofs();
694 *   copy_data_face.joint_dof_indices = fe_iv.get_interface_dof_indices();
695 *   copy_data_face.cell_matrix.reinit(n_dofs_face, n_dofs_face);
696 *  
697 *   const std::vector<double> &JxW = fe_iv.get_JxW_values();
698 *   const std::vector<Tensor<1, dim>> &normals = fe_iv.get_normal_vectors();
699 *  
700 *   const double extent1 = cell->measure() / cell->face(f)->measure();
701 *   const double extent2 = ncell->measure() / ncell->face(nf)->measure();
702 *   const double penalty = get_penalty_factor(degree, extent1, extent2);
703 *  
704 *   for (const unsigned int point : fe_iv.quadrature_point_indices())
705 *   {
706 *   for (const unsigned int i : fe_iv.dof_indices())
707 *   for (const unsigned int j : fe_iv.dof_indices())
708 *   copy_data_face.cell_matrix(i, j) +=
709 *   (-diffusion_coefficient * // - nu
710 *   fe_iv.jump_in_shape_values(i, point) * // [v_h]
711 *   (fe_iv.average_of_shape_gradients(j,
712 *   point) * // ({grad u_h} .
713 *   normals[point]) // n)
714 *  
715 *   - diffusion_coefficient * // - nu
716 *   (fe_iv.average_of_shape_gradients(i,
717 *   point) * // (grad v_h .
718 *   normals[point]) * // n)
719 *   fe_iv.jump_in_shape_values(j, point) // [u_h]
720 *  
721 *   + diffusion_coefficient * penalty * // + nu sigma
722 *   fe_iv.jump_in_shape_values(i, point) * // [v_h]
723 *   fe_iv.jump_in_shape_values(j, point) // [u_h]
724 *  
725 *   ) *
726 *   JxW[point]; // dx
727 *   }
728 *   };
729 *  
730 * @endcode
731 *
732 * The following lambda function will then copy data into the
733 * global matrix and right-hand side. Though there are no hanging
734 * node constraints in DG discretization, we define an empty
735 * AffineConstraints object that allows us to use the
736 * AffineConstraints::distribute_local_to_global() functionality.
737 *
738 * @code
739 *   AffineConstraints<double> constraints;
740 *   constraints.close();
741 *   const auto copier = [&](const CopyData &c) {
742 *   constraints.distribute_local_to_global(c.cell_matrix,
743 *   c.cell_rhs,
744 *   c.local_dof_indices,
745 *   system_matrix,
746 *   system_rhs);
747 *  
748 * @endcode
749 *
750 * Copy data from interior face assembly to the global matrix.
751 *
752 * @code
753 *   for (const CopyDataFace &cdf : c.face_data)
754 *   {
755 *   constraints.distribute_local_to_global(cdf.cell_matrix,
756 *   cdf.joint_dof_indices,
757 *   system_matrix);
758 *   }
759 *   };
760 *  
761 *  
762 * @endcode
763 *
764 * With the assembly functions defined, we can now create
765 * ScratchData and CopyData objects, and pass them together with
766 * the lambda functions above to MeshWorker::mesh_loop(). In
767 * addition, we need to specify that we want to assemble on
768 * interior faces exactly once.
769 *
770 * @code
771 *   const UpdateFlags cell_flags = update_values | update_gradients |
772 *   update_quadrature_points | update_JxW_values;
773 *   const UpdateFlags face_flags = update_values | update_gradients |
774 *   update_quadrature_points |
775 *   update_normal_vectors | update_JxW_values;
776 *  
777 *   ScratchData scratch_data(
778 *   mapping, fe, quadrature, cell_flags, face_quadrature, face_flags);
779 *   CopyData copy_data;
780 *  
781 *   MeshWorker::mesh_loop(dof_handler.begin_active(),
782 *   dof_handler.end(),
783 *   cell_worker,
784 *   copier,
785 *   scratch_data,
786 *   copy_data,
787 *   MeshWorker::assemble_own_cells |
788 *   MeshWorker::assemble_boundary_faces |
789 *   MeshWorker::assemble_own_interior_faces_once,
790 *   boundary_worker,
791 *   face_worker);
792 *   }
793 *  
794 *  
795 *  
796 * @endcode
797 *
798 *
799 * <a name="step_74-Thesolveandoutput_resultsfunction"></a>
800 * <h3>The solve() and output_results() function</h3>
801 * The following two functions are entirely standard and without difficulty.
802 *
803 * @code
804 *   template <int dim>
805 *   void SIPGLaplace<dim>::solve()
806 *   {
807 *   SparseDirectUMFPACK A_direct;
808 *   A_direct.initialize(system_matrix);
809 *   A_direct.vmult(solution, system_rhs);
810 *   }
811 *  
812 *  
813 *  
814 *   template <int dim>
815 *   void SIPGLaplace<dim>::output_results(const unsigned int cycle) const
816 *   {
817 *   const std::string filename = "sol_Q" + Utilities::int_to_string(degree, 1) +
818 *   "-" + Utilities::int_to_string(cycle, 2) +
819 *   ".vtu";
820 *   std::ofstream output(filename);
821 *  
822 *   DataOut<dim> data_out;
823 *   data_out.attach_dof_handler(dof_handler);
824 *   data_out.add_data_vector(solution, "u", DataOut<dim>::type_dof_data);
825 *   data_out.build_patches(mapping);
826 *   data_out.write_vtu(output);
827 *   }
828 *  
829 *  
830 * @endcode
831 *
832 *
833 * <a name="step_74-Thecompute_error_estimatefunction"></a>
834 * <h3>The compute_error_estimate() function</h3>
835 * The assembly of the error estimator here is quite similar to
836 * that of the global matrix and right-had side and can be handled
837 * by the MeshWorker::mesh_loop() framework. To understand what
838 * each of the local (lambda) functions is doing, recall first that
839 * the local cell residual is defined as
840 * @f$h_K^2 \left\| f + \nu \Delta u_h \right\|_K^2@f$:
841 *
842 * @code
843 *   template <int dim>
844 *   void SIPGLaplace<dim>::compute_error_estimate()
845 *   {
846 *   const auto cell_worker =
847 *   [&](const typename DoFHandler<dim>::active_cell_iterator &cell,
848 *   ScratchData &scratch_data,
849 *   CopyData &copy_data) {
850 *   const FEValues<dim> &fe_v = scratch_data.reinit(cell);
851 *  
852 *   copy_data.cell_index = cell->active_cell_index();
853 *  
854 *   const std::vector<Point<dim>> &q_points = fe_v.get_quadrature_points();
855 *   const unsigned int n_q_points = q_points.size();
856 *   const std::vector<double> &JxW = fe_v.get_JxW_values();
857 *  
858 *   std::vector<Tensor<2, dim>> hessians(n_q_points);
859 *   fe_v.get_function_hessians(solution, hessians);
860 *  
861 *   std::vector<double> rhs(n_q_points);
862 *   rhs_function->value_list(q_points, rhs);
863 *  
864 *   const double hk = cell->diameter();
865 *   double residual_norm_square = 0;
866 *  
867 *   for (unsigned int point = 0; point < n_q_points; ++point)
868 *   {
869 *   const double residual =
870 *   rhs[point] + diffusion_coefficient * trace(hessians[point]);
871 *   residual_norm_square += residual * residual * JxW[point];
872 *   }
873 *   copy_data.value = hk * hk * residual_norm_square;
874 *   };
875 *  
876 * @endcode
877 *
878 * Next compute boundary terms @f$\sum_{f\in \partial K \cap \partial \Omega}
879 * \sigma \left\| [ u_h-g_D ] \right\|_f^2 @f$:
880 *
881 * @code
882 *   const auto boundary_worker =
883 *   [&](const typename DoFHandler<dim>::active_cell_iterator &cell,
884 *   const unsigned int &face_no,
885 *   ScratchData &scratch_data,
886 *   CopyData &copy_data) {
887 *   const FEFaceValuesBase<dim> &fe_fv = scratch_data.reinit(cell, face_no);
888 *  
889 *   const std::vector<Point<dim>> &q_points = fe_fv.get_quadrature_points();
890 *   const unsigned n_q_points = q_points.size();
891 *  
892 *   const std::vector<double> &JxW = fe_fv.get_JxW_values();
893 *  
894 *   std::vector<double> g(n_q_points);
895 *   exact_solution->value_list(q_points, g);
896 *  
897 *   std::vector<double> sol_u(n_q_points);
898 *   fe_fv.get_function_values(solution, sol_u);
899 *  
900 *   const double extent1 = cell->measure() / cell->face(face_no)->measure();
901 *   const double penalty = get_penalty_factor(degree, extent1, extent1);
902 *  
903 *   double difference_norm_square = 0.;
904 *   for (unsigned int point = 0; point < q_points.size(); ++point)
905 *   {
906 *   const double diff = (g[point] - sol_u[point]);
907 *   difference_norm_square += diff * diff * JxW[point];
908 *   }
909 *   copy_data.value += penalty * difference_norm_square;
910 *   };
911 *  
912 * @endcode
913 *
914 * And finally interior face terms @f$\sum_{f\in \partial K}\lbrace \sigma
915 * \left\| [u_h] \right\|_f^2 + h_f \left\| [\nu \nabla u_h \cdot
916 * \mathbf n ] \right\|_f^2 \rbrace@f$:
917 *
918 * @code
919 *   const auto face_worker =
920 *   [&](const typename DoFHandler<dim>::cell_iterator &cell,
921 *   const unsigned int &f,
922 *   const unsigned int &sf,
923 *   const typename DoFHandler<dim>::cell_iterator &ncell,
924 *   const unsigned int &nf,
925 *   const unsigned int &nsf,
926 *   ScratchData &scratch_data,
927 *   CopyData &copy_data) {
928 *   const FEInterfaceValues<dim> &fe_iv =
929 *   scratch_data.reinit(cell, f, sf, ncell, nf, nsf);
930 *  
931 *   copy_data.face_data.emplace_back();
932 *   CopyDataFace &copy_data_face = copy_data.face_data.back();
933 *  
934 *   copy_data_face.cell_indices[0] = cell->active_cell_index();
935 *   copy_data_face.cell_indices[1] = ncell->active_cell_index();
936 *  
937 *   const std::vector<double> &JxW = fe_iv.get_JxW_values();
938 *   const std::vector<Tensor<1, dim>> &normals = fe_iv.get_normal_vectors();
939 *  
940 *   const std::vector<Point<dim>> &q_points = fe_iv.get_quadrature_points();
941 *   const unsigned int n_q_points = q_points.size();
942 *  
943 *   std::vector<double> jump(n_q_points);
944 *   fe_iv.get_jump_in_function_values(solution, jump);
945 *  
946 *   std::vector<Tensor<1, dim>> grad_jump(n_q_points);
947 *   fe_iv.get_jump_in_function_gradients(solution, grad_jump);
948 *  
949 *   const double h = cell->face(f)->diameter();
950 *  
951 *   const double extent1 = cell->measure() / cell->face(f)->measure();
952 *   const double extent2 = ncell->measure() / ncell->face(nf)->measure();
953 *   const double penalty = get_penalty_factor(degree, extent1, extent2);
954 *  
955 *   double flux_jump_square = 0;
956 *   double u_jump_square = 0;
957 *   for (unsigned int point = 0; point < n_q_points; ++point)
958 *   {
959 *   u_jump_square += jump[point] * jump[point] * JxW[point];
960 *   const double flux_jump = grad_jump[point] * normals[point];
961 *   flux_jump_square +=
962 *   diffusion_coefficient * flux_jump * flux_jump * JxW[point];
963 *   }
964 *   copy_data_face.values[0] =
965 *   0.5 * h * (flux_jump_square + penalty * u_jump_square);
966 *   copy_data_face.values[1] = copy_data_face.values[0];
967 *   };
968 *  
969 * @endcode
970 *
971 * Having computed local contributions for each cell, we still
972 * need a way to copy these into the global vector that will hold
973 * the error estimators for all cells:
974 *
975 * @code
976 *   const auto copier = [&](const CopyData &copy_data) {
977 *   if (copy_data.cell_index != numbers::invalid_unsigned_int)
978 *   estimated_error_square_per_cell[copy_data.cell_index] +=
979 *   copy_data.value;
980 *   for (const CopyDataFace &cdf : copy_data.face_data)
981 *   for (unsigned int j = 0; j < 2; ++j)
982 *   estimated_error_square_per_cell[cdf.cell_indices[j]] += cdf.values[j];
983 *   };
984 *  
985 * @endcode
986 *
987 * After all of this set-up, let's do the actual work: We resize
988 * the vector into which the results will be written, and then
989 * drive the whole process using the MeshWorker::mesh_loop()
990 * function.
991 *
992 * @code
993 *   estimated_error_square_per_cell.reinit(triangulation.n_active_cells());
994 *  
995 *   const UpdateFlags cell_flags =
997 *   const UpdateFlags face_flags = update_values | update_gradients |
1000 *  
1001 *   ScratchData scratch_data(
1002 *   mapping, fe, quadrature, cell_flags, face_quadrature, face_flags);
1003 *  
1004 *   CopyData copy_data;
1005 *   MeshWorker::mesh_loop(dof_handler.begin_active(),
1006 *   dof_handler.end(),
1007 *   cell_worker,
1008 *   copier,
1009 *   scratch_data,
1010 *   copy_data,
1014 *   boundary_worker,
1015 *   face_worker);
1016 *   }
1017 *  
1018 * @endcode
1019 *
1020 *
1021 * <a name="step_74-Thecompute_energy_norm_errorfunction"></a>
1022 * <h3>The compute_energy_norm_error() function</h3>
1023 * Next, we evaluate the accuracy in terms of the energy norm.
1024 * This function is similar to the assembling of the error estimator above.
1025 * Here we compute the square of the energy norm defined by
1026 * @f[
1027 * \|u \|_{1,h}^2 = \sum_{K \in \Gamma_h} \nu\|\nabla u \|_K^2 +
1028 * \sum_{f \in F_i} \sigma \| [ u ] \|_f^2 +
1029 * \sum_{f \in F_b} \sigma \|u\|_f^2.
1030 * @f]
1031 * Therefore the corresponding error is
1032 * @f[
1033 * \|u -u_h \|_{1,h}^2 = \sum_{K \in \Gamma_h} \nu\|\nabla (u_h - u) \|_K^2
1034 * + \sum_{f \in F_i} \sigma \|[ u_h ] \|_f^2 + \sum_{f \in F_b}\sigma
1035 * \|u_h-g_D\|_f^2.
1036 * @f]
1037 *
1038 * @code
1039 *   template <int dim>
1040 *   double SIPGLaplace<dim>::compute_energy_norm_error()
1041 *   {
1042 *   energy_norm_square_per_cell.reinit(triangulation.n_active_cells());
1043 *  
1044 * @endcode
1045 *
1046 * Assemble @f$\sum_{K \in \Gamma_h} \nu\|\nabla (u_h - u) \|_K^2 @f$.
1047 *
1048 * @code
1049 *   const auto cell_worker =
1050 *   [&](const typename DoFHandler<dim>::active_cell_iterator &cell,
1051 *   ScratchData &scratch_data,
1052 *   CopyData &copy_data) {
1053 *   const FEValues<dim> &fe_v = scratch_data.reinit(cell);
1054 *  
1055 *   copy_data.cell_index = cell->active_cell_index();
1056 *  
1057 *   const std::vector<Point<dim>> &q_points = fe_v.get_quadrature_points();
1058 *   const unsigned int n_q_points = q_points.size();
1059 *   const std::vector<double> &JxW = fe_v.get_JxW_values();
1060 *  
1061 *   std::vector<Tensor<1, dim>> grad_u(n_q_points);
1062 *   fe_v.get_function_gradients(solution, grad_u);
1063 *  
1064 *   std::vector<Tensor<1, dim>> grad_exact(n_q_points);
1065 *   exact_solution->gradient_list(q_points, grad_exact);
1066 *  
1067 *   double norm_square = 0;
1068 *   for (unsigned int point = 0; point < n_q_points; ++point)
1069 *   {
1070 *   norm_square +=
1071 *   (grad_u[point] - grad_exact[point]).norm_square() * JxW[point];
1072 *   }
1073 *   copy_data.value = diffusion_coefficient * norm_square;
1074 *   };
1075 *  
1076 * @endcode
1077 *
1078 * Assemble @f$\sum_{f \in F_b}\sigma \|u_h-g_D\|_f^2@f$.
1079 *
1080 * @code
1081 *   const auto boundary_worker =
1082 *   [&](const typename DoFHandler<dim>::active_cell_iterator &cell,
1083 *   const unsigned int &face_no,
1084 *   ScratchData &scratch_data,
1085 *   CopyData &copy_data) {
1086 *   const FEFaceValuesBase<dim> &fe_fv = scratch_data.reinit(cell, face_no);
1087 *  
1088 *   const std::vector<Point<dim>> &q_points = fe_fv.get_quadrature_points();
1089 *   const unsigned n_q_points = q_points.size();
1090 *  
1091 *   const std::vector<double> &JxW = fe_fv.get_JxW_values();
1092 *  
1093 *   std::vector<double> g(n_q_points);
1094 *   exact_solution->value_list(q_points, g);
1095 *  
1096 *   std::vector<double> sol_u(n_q_points);
1097 *   fe_fv.get_function_values(solution, sol_u);
1098 *  
1099 *   const double extent1 = cell->measure() / cell->face(face_no)->measure();
1100 *   const double penalty = get_penalty_factor(degree, extent1, extent1);
1101 *  
1102 *   double difference_norm_square = 0.;
1103 *   for (unsigned int point = 0; point < q_points.size(); ++point)
1104 *   {
1105 *   const double diff = (g[point] - sol_u[point]);
1106 *   difference_norm_square += diff * diff * JxW[point];
1107 *   }
1108 *   copy_data.value += penalty * difference_norm_square;
1109 *   };
1110 *  
1111 * @endcode
1112 *
1113 * Assemble @f$\sum_{f \in F_i} \sigma \| [ u_h ] \|_f^2@f$.
1114 *
1115 * @code
1116 *   const auto face_worker =
1117 *   [&](const typename DoFHandler<dim>::cell_iterator &cell,
1118 *   const unsigned int &f,
1119 *   const unsigned int &sf,
1120 *   const typename DoFHandler<dim>::cell_iterator &ncell,
1121 *   const unsigned int &nf,
1122 *   const unsigned int &nsf,
1123 *   ScratchData &scratch_data,
1124 *   CopyData &copy_data) {
1125 *   const FEInterfaceValues<dim> &fe_iv =
1126 *   scratch_data.reinit(cell, f, sf, ncell, nf, nsf);
1127 *  
1128 *   copy_data.face_data.emplace_back();
1129 *   CopyDataFace &copy_data_face = copy_data.face_data.back();
1130 *  
1131 *   copy_data_face.cell_indices[0] = cell->active_cell_index();
1132 *   copy_data_face.cell_indices[1] = ncell->active_cell_index();
1133 *  
1134 *   const std::vector<double> &JxW = fe_iv.get_JxW_values();
1135 *  
1136 *   const std::vector<Point<dim>> &q_points = fe_iv.get_quadrature_points();
1137 *   const unsigned int n_q_points = q_points.size();
1138 *  
1139 *   std::vector<double> jump(n_q_points);
1140 *   fe_iv.get_jump_in_function_values(solution, jump);
1141 *  
1142 *   const double extent1 = cell->measure() / cell->face(f)->measure();
1143 *   const double extent2 = ncell->measure() / ncell->face(nf)->measure();
1144 *   const double penalty = get_penalty_factor(degree, extent1, extent2);
1145 *  
1146 *   double u_jump_square = 0;
1147 *   for (unsigned int point = 0; point < n_q_points; ++point)
1148 *   {
1149 *   u_jump_square += jump[point] * jump[point] * JxW[point];
1150 *   }
1151 *   copy_data_face.values[0] = 0.5 * penalty * u_jump_square;
1152 *   copy_data_face.values[1] = copy_data_face.values[0];
1153 *   };
1154 *  
1155 *   const auto copier = [&](const CopyData &copy_data) {
1156 *   if (copy_data.cell_index != numbers::invalid_unsigned_int)
1157 *   energy_norm_square_per_cell[copy_data.cell_index] += copy_data.value;
1158 *   for (const CopyDataFace &cdf : copy_data.face_data)
1159 *   for (unsigned int j = 0; j < 2; ++j)
1160 *   energy_norm_square_per_cell[cdf.cell_indices[j]] += cdf.values[j];
1161 *   };
1162 *  
1163 *   const UpdateFlags cell_flags =
1165 *   UpdateFlags face_flags =
1167 *  
1168 *   const ScratchData scratch_data(mapping,
1169 *   fe,
1170 *   quadrature_overintegration,
1171 *   cell_flags,
1172 *   face_quadrature_overintegration,
1173 *   face_flags);
1174 *  
1175 *   CopyData copy_data;
1176 *   MeshWorker::mesh_loop(dof_handler.begin_active(),
1177 *   dof_handler.end(),
1178 *   cell_worker,
1179 *   copier,
1180 *   scratch_data,
1181 *   copy_data,
1185 *   boundary_worker,
1186 *   face_worker);
1187 *   const double energy_error =
1188 *   std::sqrt(energy_norm_square_per_cell.l1_norm());
1189 *   return energy_error;
1190 *   }
1191 *  
1192 *  
1193 *  
1194 * @endcode
1195 *
1196 *
1197 * <a name="step_74-Therefine_gridfunction"></a>
1198 * <h3>The refine_grid() function</h3>
1199 *
1200 * @code
1201 *   template <int dim>
1202 *   void SIPGLaplace<dim>::refine_grid()
1203 *   {
1204 *   const double refinement_fraction = 0.1;
1205 *  
1207 *   triangulation, estimated_error_square_per_cell, refinement_fraction, 0.);
1208 *  
1209 *   triangulation.execute_coarsening_and_refinement();
1210 *   }
1211 *  
1212 *  
1213 *  
1214 * @endcode
1215 *
1216 *
1217 * <a name="step_74-Thecompute_errorsfunction"></a>
1218 * <h3>The compute_errors() function</h3>
1219 * We compute three errors in the @f$L_2@f$ norm, @f$H_1@f$ seminorm, and
1220 * the energy norm, respectively. These are then printed to screen,
1221 * but also stored in a table that records how these errors decay
1222 * with mesh refinement and which can be output in one step at the
1223 * end of the program.
1224 *
1225 * @code
1226 *   template <int dim>
1227 *   void SIPGLaplace<dim>::compute_errors()
1228 *   {
1229 *   double L2_error, H1_error, energy_error;
1230 *  
1231 *   {
1232 *   Vector<float> difference_per_cell(triangulation.n_active_cells());
1234 *   dof_handler,
1235 *   solution,
1236 *   *(exact_solution.get()),
1237 *   difference_per_cell,
1238 *   quadrature_overintegration,
1240 *  
1242 *   difference_per_cell,
1244 *   convergence_table.add_value("L2", L2_error);
1245 *   }
1246 *  
1247 *   {
1248 *   Vector<float> difference_per_cell(triangulation.n_active_cells());
1250 *   dof_handler,
1251 *   solution,
1252 *   *(exact_solution.get()),
1253 *   difference_per_cell,
1254 *   quadrature_overintegration,
1256 *  
1258 *   difference_per_cell,
1260 *   convergence_table.add_value("H1", H1_error);
1261 *   }
1262 *  
1263 *   {
1264 *   energy_error = compute_energy_norm_error();
1265 *   convergence_table.add_value("Energy", energy_error);
1266 *   }
1267 *  
1268 *   std::cout << " Error in the L2 norm : " << L2_error << std::endl
1269 *   << " Error in the H1 seminorm : " << H1_error << std::endl
1270 *   << " Error in the energy norm : " << energy_error
1271 *   << std::endl;
1272 *   }
1273 *  
1274 *  
1275 *  
1276 * @endcode
1277 *
1278 *
1279 * <a name="step_74-Therunfunction"></a>
1280 * <h3>The run() function</h3>
1281 *
1282 * @code
1283 *   template <int dim>
1284 *   void SIPGLaplace<dim>::run()
1285 *   {
1286 *   const unsigned int max_cycle =
1287 *   (test_case == TestCase::convergence_rate ? 6 : 20);
1288 *   for (unsigned int cycle = 0; cycle < max_cycle; ++cycle)
1289 *   {
1290 *   std::cout << "Cycle " << cycle << std::endl;
1291 *  
1292 *   switch (test_case)
1293 *   {
1294 *   case TestCase::convergence_rate:
1295 *   {
1296 *   if (cycle == 0)
1297 *   {
1299 *  
1300 *   triangulation.refine_global(2);
1301 *   }
1302 *   else
1303 *   {
1304 *   triangulation.refine_global(1);
1305 *   }
1306 *   break;
1307 *   }
1308 *  
1309 *   case TestCase::l_singularity:
1310 *   {
1311 *   if (cycle == 0)
1312 *   {
1314 *   triangulation.refine_global(3);
1315 *   }
1316 *   else
1317 *   {
1318 *   refine_grid();
1319 *   }
1320 *   break;
1321 *   }
1322 *  
1323 *   default:
1324 *   {
1326 *   }
1327 *   }
1328 *  
1329 *   std::cout << " Number of active cells : "
1330 *   << triangulation.n_active_cells() << std::endl;
1331 *   setup_system();
1332 *  
1333 *   std::cout << " Number of degrees of freedom : " << dof_handler.n_dofs()
1334 *   << std::endl;
1335 *  
1336 *   assemble_system();
1337 *   solve();
1338 *   output_results(cycle);
1339 *   {
1340 *   convergence_table.add_value("cycle", cycle);
1341 *   convergence_table.add_value("cells", triangulation.n_active_cells());
1342 *   convergence_table.add_value("dofs", dof_handler.n_dofs());
1343 *   }
1344 *   compute_errors();
1345 *  
1346 *   if (test_case == TestCase::l_singularity)
1347 *   {
1348 *   compute_error_estimate();
1349 *   std::cout << " Estimated error : "
1350 *   << std::sqrt(estimated_error_square_per_cell.l1_norm())
1351 *   << std::endl;
1352 *  
1353 *   convergence_table.add_value(
1354 *   "Estimator",
1355 *   std::sqrt(estimated_error_square_per_cell.l1_norm()));
1356 *   }
1357 *   std::cout << std::endl;
1358 *   }
1359 *  
1360 * @endcode
1361 *
1362 * Having run all of our computations, let us tell the convergence
1363 * table how to format its data and output it to screen:
1364 *
1365 * @code
1366 *   convergence_table.set_precision("L2", 3);
1367 *   convergence_table.set_precision("H1", 3);
1368 *   convergence_table.set_precision("Energy", 3);
1369 *  
1370 *   convergence_table.set_scientific("L2", true);
1371 *   convergence_table.set_scientific("H1", true);
1372 *   convergence_table.set_scientific("Energy", true);
1373 *  
1374 *   if (test_case == TestCase::convergence_rate)
1375 *   {
1376 *   convergence_table.evaluate_convergence_rates(
1378 *   convergence_table.evaluate_convergence_rates(
1380 *   }
1381 *   if (test_case == TestCase::l_singularity)
1382 *   {
1383 *   convergence_table.set_precision("Estimator", 3);
1384 *   convergence_table.set_scientific("Estimator", true);
1385 *   }
1386 *  
1387 *   std::cout << "degree = " << degree << std::endl;
1388 *   convergence_table.write_text(
1390 *   }
1391 *   } // namespace Step74
1392 *  
1393 *  
1394 *  
1395 * @endcode
1396 *
1397 *
1398 * <a name="step_74-Themainfunction"></a>
1399 * <h3>The main() function</h3>
1400 * The following <code>main</code> function is similar to previous examples as
1401 * well, and need not be commented on.
1402 *
1403 * @code
1404 *   int main()
1405 *   {
1406 *   try
1407 *   {
1408 *   using namespace dealii;
1409 *   using namespace Step74;
1410 *  
1411 *   const TestCase test_case = TestCase::l_singularity;
1412 *  
1413 *   SIPGLaplace<2> problem(test_case);
1414 *   problem.run();
1415 *   }
1416 *   catch (std::exception &exc)
1417 *   {
1418 *   std::cerr << std::endl
1419 *   << std::endl
1420 *   << "----------------------------------------------------"
1421 *   << std::endl;
1422 *   std::cerr << "Exception on processing: " << std::endl
1423 *   << exc.what() << std::endl
1424 *   << "Aborting!" << std::endl
1425 *   << "----------------------------------------------------"
1426 *   << std::endl;
1427 *   return 1;
1428 *   }
1429 *   catch (...)
1430 *   {
1431 *   std::cerr << std::endl
1432 *   << std::endl
1433 *   << "----------------------------------------------------"
1434 *   << std::endl;
1435 *   std::cerr << "Unknown exception!" << std::endl
1436 *   << "Aborting!" << std::endl
1437 *   << "----------------------------------------------------"
1438 *   << std::endl;
1439 *   return 1;
1440 *   };
1441 *  
1442 *   return 0;
1443 *   }
1444 * @endcode
1445<a name="step_74-Results"></a><h1>Results</h1>
1446
1447
1448The output of this program consist of the console output and
1449solutions in vtu format.
1450
1451In the first test case, when you run the program, the screen output should look like the following:
1452@code
1453Cycle 0
1454 Number of active cells : 16
1455 Number of degrees of freedom : 256
1456 Error in the L2 norm : 0.00193285
1457 Error in the H1 seminorm : 0.106087
1458 Error in the energy norm : 0.150625
1459
1460Cycle 1
1461 Number of active cells : 64
1462 Number of degrees of freedom : 1024
1463 Error in the L2 norm : 9.60497e-05
1464 Error in the H1 seminorm : 0.0089954
1465 Error in the energy norm : 0.0113265
1466
1467Cycle 2
1468.
1469.
1470.
1471@endcode
1472
1473When using the smooth case with polynomial degree 3, the convergence
1474table will look like this:
1475<table align="center" class="doxtable">
1476 <tr>
1477 <th>cycle</th>
1478 <th>n_cells</th>
1479 <th>n_dofs</th>
1480 <th>L2 </th>
1481 <th>rate</th>
1482 <th>H1</th>
1483 <th>rate</th>
1484 <th>Energy</th>
1485 </tr>
1486 <tr>
1487 <td align="center">0</td>
1488 <td align="right">16</td>
1489 <td align="right">256</td>
1490 <td align="center">1.933e-03</td>
1491 <td>&nbsp;</td>
1492 <td align="center">1.061e-01</td>
1493 <td>&nbsp;</td>
1494 <td align="center">1.506e-01</td>
1495 </tr>
1496 <tr>
1497 <td align="center">1</td>
1498 <td align="right">64</td>
1499 <td align="right">1024</td>
1500 <td align="center">9.605e-05</td>
1501 <td align="center">4.33</td>
1502 <td align="center">8.995e-03</td>
1503 <td align="center">3.56</td>
1504 <td align="center">1.133e-02</td>
1505 </tr>
1506 <tr>
1507 <td align="center">2</td>
1508 <td align="right">256</td>
1509 <td align="right">4096</td>
1510 <td align="center">5.606e-06</td>
1511 <td align="center">4.10</td>
1512 <td align="center">9.018e-04</td>
1513 <td align="center">3.32</td>
1514 <td align="center">9.736e-04</td>
1515 </tr>
1516 <tr>
1517 <td align="center">3</td>
1518 <td align="right">1024</td>
1519 <td align="right">16384</td>
1520 <td align="center">3.484e-07</td>
1521 <td align="center">4.01</td>
1522 <td align="center">1.071e-04</td>
1523 <td align="center">3.07</td>
1524 <td align="center">1.088e-04</td>
1525 </tr>
1526 <tr>
1527 <td align="center">4</td>
1528 <td align="right">4096</td>
1529 <td align="right">65536</td>
1530 <td align="center">2.179e-08</td>
1531 <td align="center">4.00</td>
1532 <td align="center">1.327e-05</td>
1533 <td align="center">3.01</td>
1534 <td align="center">1.331e-05</td>
1535 </tr>
1536 <tr>
1537 <td align="center">5</td>
1538 <td align="right">16384</td>
1539 <td align="right">262144</td>
1540 <td align="center">1.363e-09</td>
1541 <td align="center">4.00</td>
1542 <td align="center">1.656e-06</td>
1543 <td align="center">3.00</td>
1544 <td align="center">1.657e-06</td>
1545 </tr>
1546</table>
1547
1548Theoretically, for polynomial degree @f$p@f$, the order of convergence in @f$L_2@f$
1549norm and @f$H^1@f$ seminorm should be @f$p+1@f$ and @f$p@f$, respectively. Our numerical
1550results are in good agreement with theory.
1551
1552In the second test case, when you run the program, the screen output should look like the following:
1553@code
1554Cycle 0
1555 Number of active cells : 192
1556 Number of degrees of freedom : 3072
1557 Error in the L2 norm : 0.000323585
1558 Error in the H1 seminorm : 0.0296202
1559 Error in the energy norm : 0.0420478
1560 Estimated error : 0.136067
1561
1562Cycle 1
1563 Number of active cells : 249
1564 Number of degrees of freedom : 3984
1565 Error in the L2 norm : 0.000114739
1566 Error in the H1 seminorm : 0.0186571
1567 Error in the energy norm : 0.0264879
1568 Estimated error : 0.0857186
1569
1570Cycle 2
1571.
1572.
1573.
1574@endcode
1575
1576The following figure provides a log-log plot of the errors versus
1577the number of degrees of freedom for this test case on the L-shaped
1578domain. In order to interpret it, let @f$n@f$ be the number of degrees of
1579freedom, then on uniformly refined meshes, @f$h@f$ is of order
1580@f$1/\sqrt{n}@f$ in 2D. Combining the theoretical results in the previous case,
1581we see that if the solution is sufficiently smooth,
1582we can expect the error in the @f$L_2@f$ norm to be of order @f$O(n^{-\frac{p+1}{2}})@f$
1583and in @f$H^1@f$ seminorm to be @f$O(n^{-\frac{p}{2}})@f$. It is not a priori
1584clear that one would get the same kind of behavior as a function of
1585@f$n@f$ on adaptively refined meshes like the ones we use for this second
1586test case, but one can certainly hope. Indeed, from the figure, we see
1587that the SIPG with adaptive mesh refinement produces asymptotically
1588the kinds of hoped-for results:
1589
1590<img width="600px" src="https://www.dealii.org/images/steps/developer/step-74.log-log-plot.png" alt="">
1591
1592In addition, we observe that the error estimator decreases
1593at almost the same rate as the errors in the energy norm and @f$H^1@f$ seminorm,
1594and one order lower than the @f$L_2@f$ error. This suggests
1595its ability to predict regions with large errors.
1596
1597While this tutorial is focused on the implementation, the @ref step_59 "step-59" tutorial program achieves an efficient
1598large-scale solver in terms of computing time with matrix-free solution techniques.
1599Note that the @ref step_59 "step-59" tutorial does not work with meshes containing hanging nodes at this moment,
1600because the multigrid interface matrices are not as easily determined,
1601but that is merely the lack of some interfaces in deal.II, nothing fundamental.
1602 *
1603 *
1604<a name="step_74-PlainProg"></a>
1605<h1> The plain program</h1>
1606@include "step-74.cc"
1607*/
void reinit(const CellIteratorType &cell, const unsigned int face_no, const unsigned int sub_face_no, const CellNeighborIteratorType &cell_neighbor, const unsigned int face_no_neighbor, const unsigned int sub_face_no_neighbor, const unsigned int q_index=numbers::invalid_unsigned_int, const unsigned int mapping_index=numbers::invalid_unsigned_int, const unsigned int fe_index=numbers::invalid_unsigned_int, const unsigned int fe_index_neighbor=numbers::invalid_unsigned_int)
const std::vector< Point< spacedim > > & get_quadrature_points() const
void reinit(const TriaIterator< DoFCellAccessor< dim, spacedim, level_dof_access > > &cell)
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual double laplacian(const Point< 2 > &p, const unsigned int component=0) const override
Definition point.h:111
virtual void reinit(const size_type N, const bool omit_zeroing_entries=false)
Point< 2 > second
Definition grid_out.cc:4624
Point< 2 > first
Definition grid_out.cc:4623
unsigned int cell_index
typename ActiveSelector::cell_iterator cell_iterator
typename ActiveSelector::active_cell_iterator active_cell_iterator
void mesh_loop(const CellIteratorType &begin, const CellIteratorType &end, const CellWorkerFunctionType &cell_worker, const CopierType &copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const AssembleFlags flags=assemble_own_cells, const BoundaryWorkerFunctionType &boundary_worker=BoundaryWorkerFunctionType(), const FaceWorkerFunctionType &face_worker=FaceWorkerFunctionType(), const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)
Definition mesh_loop.h:281
UpdateFlags
@ 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.
#define DEAL_II_NOT_IMPLEMENTED()
void hyper_L(Triangulation< dim > &tria, const double left=-1., const double right=1., const bool colorize=false)
void hyper_cube(Triangulation< dim, spacedim > &tria, const double left=0., const double right=1., const bool colorize=false)
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 scale(const double scaling_factor, Triangulation< dim, spacedim > &triangulation)
@ 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
double norm(const FEValuesBase< dim > &fe, const ArrayView< const std::vector< Tensor< 1, dim > > > &Du)
Definition divergence.h:471
void L2(Vector< number > &result, const FEValuesBase< dim > &fe, const std::vector< double > &input, const double factor=1.)
Definition l2.h:159
@ assemble_boundary_faces
@ assemble_own_interior_faces_once
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:191
double compute_global_error(const Triangulation< dim, spacedim > &tria, const InVector &cellwise_error, const NormType &norm, const double exponent=2.)
void integrate_difference(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const ReadVector< Number > &fe_function, const Function< spacedim, Number > &exact_solution, OutVector &difference, const Quadrature< dim > &q, const NormType &norm, const Function< spacedim, double > *weight=nullptr, const double exponent=2.)
void run(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length, const unsigned int chunk_size)
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
Definition tria.cc:14882
int(&) functions(const void *v1, const void *v2)
void assemble(const MeshWorker::DoFInfoBox< dim, DOFINFO > &dinfo, A *assembler)
Definition loop.h:70
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
static constexpr double PI
Definition numbers.h:254
static const unsigned int invalid_unsigned_int
Definition types.h:220
::VectorizedArray< Number, width > log(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation