Reference documentation for deal.II version 9.6.0
\(\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-89.h
Go to the documentation of this file.
1
347{},
348 /* interior_face_operation= */ face_function,
349 /* boundary_face_operation= */{},
350 dst, src);
351@endcode
352
353The code to do the same with FERemoteEvaluation is shown below.
354For brevity, we assume all boundary faces are somehow connected via
355non-conforming interfaces for FERemoteEvaluation.
356
357@code
358// Initialize FERemoteEvaluation: Note, that FERemoteEvaluation internally manages
359// the memory to store precomputed values. Therefore, FERemoteEvaluation
360// should be initialized only once to avoid frequent memory
361// allocation/deallocation. At this point, remote_communicator is assumed
362// to be initialized.
363FERemoteEvaluation<dim,Number> u_p_evaluator(remote_communicator);
364
365// Precompute the interpolated values of the finite element solution at all
366// the quadrature points outside the loop, invoking the vector entries and
367// respective basis function at possibly remote MPI processes before communication.
368u_p_evaluator.gather_evaluate(src, EvaluationFlags::values);
369
370const auto boundary_function =
371 [&](const MatrixFree &data, VectorType &dst, const VectorType &src,
372 const std::pair<unsigned int, unsigned int> face_range) {
373
374 FEFaceEvaluation phi_m(data, true);
375 // To access the values in a thread safe way each thread has
376 // to create a own accessor object. A small helper function
377 // provides the accessor.
378 internal::PrecomputedEvaluationDataAccessor u_p = u_p_evaluator.get_data_accessor();
379
380 for (unsigned int f = face_range.first; f < face_range.second; ++f)
381 {
382 phi_m.reinit(f);
383 u_p.reinit(f);
384
385 for (unsigned int q = 0; q < phi_m.n_q_points; ++q)
386 phi_m.submit_value(u_p.get_value(q), q); // access values with phi_p
387
388 phi_m.integrate_scatter(EvaluationFlags::values, dst);
389 }
390 };
391
392matrix_free.template loop<VectorType, VectorType>({}, {}, boundary_function, dst, src);
393@endcode
394The object @c remote_communicator is of type `FERemoteEvaluationCommunicator`
395and assumed to be correctly initialized prior to the above code snippet.
396`FERemoteEvaluationCommunicator` internally manages the update of ghost values
397over non-matching interfaces and keeps track of the mapping between quadrature
398point index and corresponding values/gradients. As mentioned above, the update
399of the values/gradients happens <i>before</i> the actual matrix-free loop.
401differently for the given template parameter @c value_type. If we want to access
402values at arbitrary points (e.g. in combination with @c FEPointEvaluation), then
403we need to choose @c value_type=Number. If the values are defined at quadrature
404points of a @c FEEvaluation object it is possible to get the values at the
405quadrature points of <i>batches</i> and we need to choose
406@c value_type=VectorizedArray<Number>.
407
408
409<a name="step_89-Overviewofthetestcase"></a><h3>Overview of the test case</h3>
410
411
412In this program, we implemented both the point-to-point interpolation and
413Nitsche-type mortaring mentioned in the introduction.
414
415At first we are considering the test case of a vibrating membrane, see e.g.
416@cite nguyen2011high. Standing waves of length @f$\lambda=2/M@f$ are oscillating
417with a time period of @f$T=2 / (M \sqrt{d} c)@f$ where @f$d@f$ is the dimension of the
418space in which our domain is located and @f$M@f$ is the number of modes per meter,
419i.e. the number of half-waves per meter. The corresponding analytical solution
420reads as
421
422@f{align*}{
423 p &=\cos(M \sqrt{d} \pi c t)\prod_{i=1}^{d} \sin(M \pi x_i),\\
424 u_i&=-\frac{\sin(M \sqrt{d} \pi c t)}{\sqrt{d}\rho c}
425 \cos(M \pi x_i)\prod_{j=1,j\neq i}^{d} \sin(M \pi x_j),
426@f}
427
428For simplicity, we are using homogeneous pressure Dirichlet boundary conditions
429within this tutorial. To be able to do so we have to tailor the domain size as
430well as the number of modes to conform with the homogeneous pressure Dirichlet
431boundary conditions. Within this tutorial we are using @f$M=10@f$ and a domain
432@f$\Omega=(0,1)^2@f$. The domain will be meshed so that the left and right parts of
433the domain consist of separate meshes that do not match at the interface.
434
435As will become clear from the results, the point-to-point interpolation will
436result in aliasing, which can be resolved using Nitsche-type mortaring.
437
438In a more realistic second example, we apply this implementation to a test case
439in which a wave is propagating from one fluid into another fluid. The speed of
440sound in the left part of the domain is @f$c=1@f$ and in the right part it is @f$c=3@f$.
441Since the wavelength is directly proportional to the speed of sound, three times
442larger elements can be used in the right part of the domain to resolve waves up
443to the same frequency. A test case like this has been simulated with a different
444domain and different initial conditions, e.g., in @cite bangerth2010adaptive.
445 *
446 *
447 * <a name="step_89-CommProg"></a>
448 * <h1> The commented program</h1>
449 *
450 *
451 * <a name="step_89-Includefiles"></a>
452 * <h3>Include files</h3>
453 *
454
455 *
456 * The program starts with including all the relevant header files.
457 *
458 * @code
459 *   #include <deal.II/base/conditional_ostream.h>
460 *   #include <deal.II/base/mpi.h>
461 *  
462 *   #include <deal.II/distributed/tria.h>
463 *  
464 *   #include <deal.II/fe/fe_dgq.h>
465 *   #include <deal.II/fe/fe_system.h>
466 *   #include <deal.II/fe/fe_values.h>
467 *   #include <deal.II/fe/mapping_q1.h>
468 *  
469 *   #include <deal.II/grid/grid_generator.h>
470 *   #include <deal.II/grid/grid_tools.h>
471 *   #include <deal.II/grid/grid_tools_cache.h>
472 *  
473 *   #include <deal.II/matrix_free/fe_evaluation.h>
474 *   #include <deal.II/matrix_free/matrix_free.h>
475 *   #include <deal.II/matrix_free/operators.h>
476 *  
477 *   #include <deal.II/non_matching/mapping_info.h>
478 *  
479 *   #include <deal.II/numerics/data_out.h>
480 *   #include <deal.II/numerics/vector_tools.h>
481 * @endcode
482 *
483 * The following header file provides the class FERemoteEvaluation, which allows
484 * to access values and/or gradients at remote triangulations similar to
485 * FEEvaluation.
486 *
487 * @code
488 *   #include <deal.II/matrix_free/fe_remote_evaluation.h>
489 *  
490 * @endcode
491 *
492 * We pack everything that is specific for this program into a namespace
493 * of its own.
494 *
495 * @code
496 *   namespace Step89
497 *   {
498 *   using namespace dealii;
499 *  
500 * @endcode
501 *
502 *
503 * <a name="step_89-Initialconditionsforvibratingmembrane"></a>
504 * <h3>Initial conditions for vibrating membrane</h3>
505 *
506
507 *
508 * In the following, let us first define a function that provides
509 * the initial condition for the vibrating membrane test case. It
510 * implements both the initial pressure (component 0) and velocity
511 * (components 1 to 1 + dim).
512 *
513
514 *
515 * There is also a function that computes the duration of one
516 * oscillation.
517 *
518 * @code
519 *   template <int dim>
520 *   class InitialConditionVibratingMembrane : public Function<dim>
521 *   {
522 *   public:
523 *   InitialConditionVibratingMembrane(const double modes);
524 *  
525 *   double value(const Point<dim> &p, const unsigned int comp) const final;
526 *  
527 *   double get_period_duration(const double speed_of_sound) const;
528 *  
529 *   private:
530 *   const double M;
531 *   };
532 *  
533 *   template <int dim>
534 *   InitialConditionVibratingMembrane<dim>::InitialConditionVibratingMembrane(
535 *   const double modes)
536 *   : Function<dim>(dim + 1, 0.0)
537 *   , M(modes)
538 *   {
539 *   static_assert(dim == 2, "Only implemented for dim==2");
540 *   }
541 *  
542 *   template <int dim>
543 *   double
544 *   InitialConditionVibratingMembrane<dim>::value(const Point<dim> &p,
545 *   const unsigned int comp) const
546 *   {
547 *   if (comp == 0)
548 *   return std::sin(M * numbers::PI * p[0]) *
549 *   std::sin(M * numbers::PI * p[1]);
550 *  
551 *   return 0.0;
552 *   }
553 *  
554 *   template <int dim>
555 *   double InitialConditionVibratingMembrane<dim>::get_period_duration(
556 *   const double speed_of_sound) const
557 *   {
558 *   return 2.0 / (M * std::sqrt(dim) * speed_of_sound);
559 *   }
560 *  
561 * @endcode
562 *
563 *
564 * <a name="step_89-Gausspulse"></a>
565 * <h3>Gauss pulse</h3>
566 *
567
568 *
569 * Next up is a function that provides the values of a pressure
570 * Gauss pulse. As with the previous function, it implements both
571 * the initial pressure (component 0) and velocity (components 1 to
572 * 1 + dim).
573 *
574 * @code
575 *   template <int dim>
576 *   class GaussPulse : public Function<dim>
577 *   {
578 *   public:
579 *   GaussPulse(const double shift_x, const double shift_y);
580 *  
581 *   double value(const Point<dim> &p, const unsigned int comp) const final;
582 *  
583 *   private:
584 *   const double shift_x;
585 *   const double shift_y;
586 *   };
587 *  
588 *   template <int dim>
589 *   GaussPulse<dim>::GaussPulse(const double shift_x, const double shift_y)
590 *   : Function<dim>(dim + 1, 0.0)
591 *   , shift_x(shift_x)
592 *   , shift_y(shift_y)
593 *   {
594 *   static_assert(dim == 2, "Only implemented for dim==2");
595 *   }
596 *  
597 *   template <int dim>
598 *   double GaussPulse<dim>::value(const Point<dim> &p,
599 *   const unsigned int comp) const
600 *   {
601 *   if (comp == 0)
602 *   return std::exp(-1000.0 * ((std::pow(p[0] - shift_x, 2)) +
603 *   (std::pow(p[1] - shift_y, 2))));
604 *  
605 *   return 0.0;
606 *   }
607 *  
608 * @endcode
609 *
610 *
611 * <a name="step_89-Helperfunctions"></a>
612 * <h3>Helper functions</h3>
613 *
614
615 *
616 * The following namespace contains free helper functions that are used in the
617 * tutorial.
618 *
619 * @code
620 *   namespace HelperFunctions
621 *   {
622 * @endcode
623 *
624 * Helper function to check if a boundary ID is related to a non-matching
625 * face. A @c std::set that contains all non-matching boundary IDs is
626 * handed over in addition to the face ID under question.
627 *
628 * @code
629 *   bool is_non_matching_face(
630 *   const std::set<types::boundary_id> &non_matching_face_ids,
631 *   const types::boundary_id face_id)
632 *   {
633 *   return non_matching_face_ids.find(face_id) != non_matching_face_ids.end();
634 *   }
635 *  
636 * @endcode
637 *
638 * Helper function to set the initial conditions for the vibrating membrane
639 * test case.
640 *
641 * @code
642 *   template <int dim, typename Number, typename VectorType>
643 *   void set_initial_condition(MatrixFree<dim, Number> matrix_free,
644 *   const Function<dim> &initial_solution,
645 *   VectorType &dst)
646 *   {
647 *   VectorTools::interpolate(*matrix_free.get_mapping_info().mapping,
648 *   matrix_free.get_dof_handler(),
649 *   initial_solution,
650 *   dst);
651 *   }
652 *  
653 * @endcode
654 *
655 * Helper function to compute the time step size according to the CFL
656 * condition.
657 *
658 * @code
659 *   double
660 *   compute_dt_cfl(const double hmin, const unsigned int degree, const double c)
661 *   {
662 *   return hmin / (std::pow(degree, 1.5) * c);
663 *   }
664 *  
665 * @endcode
666 *
667 * Helper function that writes vtu output.
668 *
669 * @code
670 *   template <typename VectorType, int dim>
671 *   void write_vtu(const VectorType &solution,
672 *   const DoFHandler<dim> &dof_handler,
673 *   const Mapping<dim> &mapping,
674 *   const unsigned int degree,
675 *   const std::string &name_prefix)
676 *   {
677 *   DataOut<dim> data_out;
678 *   DataOutBase::VtkFlags flags;
679 *   flags.write_higher_order_cells = true;
680 *   data_out.set_flags(flags);
681 *  
682 *   std::vector<DataComponentInterpretation::DataComponentInterpretation>
683 *   interpretation(
685 *   std::vector<std::string> names(dim + 1, "U");
686 *  
688 *   names[0] = "P";
689 *  
690 *   data_out.add_data_vector(dof_handler, solution, names, interpretation);
691 *  
692 *   data_out.build_patches(mapping, degree, DataOut<dim>::curved_inner_cells);
693 *   data_out.write_vtu_in_parallel(name_prefix + ".vtu",
694 *   dof_handler.get_communicator());
695 *   }
696 *   } // namespace HelperFunctions
697 *  
698 * @endcode
699 *
700 *
701 * <a name="step_89-Materialparameterdescription"></a>
702 * <h3>Material parameter description</h3>
703 *
704
705 *
706 * The following class stores the information if the fluid is
707 * homogeneous as well as the material properties at every cell.
708 * This class helps access the correct values without accessing a
709 * large vector of materials in the homogeneous case.
710 *
711
712 *
713 * The class is provided a map from material ids to material
714 * properties (given as a pair of values for the speed of sound and
715 * the density). If the map has only one entry, the material is
716 * homogeneous -- using the same values everywhere -- and we can
717 * remember that fact in the `homogeneous` member variable and use it
718 * to optimize some code paths below. If the material is not
719 * homogeneous, we will fill a vector with the correct materials for
720 * each batch of cells; this information can then be access via
722 *
723
724 *
725 * As is usual when working with the MatrixFree framework, we will
726 * not only access material parameters at a single site, but for
727 * whole "batches" of cells. As a consequence, the functions below
728 * returned VectorizedArray objects for a batch at a time.
729 *
730 * @code
731 *   template <typename Number>
732 *   class CellwiseMaterialData
733 *   {
734 *   public:
735 *   template <int dim>
736 *   CellwiseMaterialData(
737 *   const MatrixFree<dim, Number, VectorizedArray<Number>> &matrix_free,
738 *   const std::map<types::material_id, std::pair<double, double>>
739 *   &material_id_map)
740 *   : homogeneous(material_id_map.size() == 1)
741 *   {
742 *   Assert(material_id_map.size() > 0,
743 *   ExcMessage("No materials given to CellwiseMaterialData."));
744 *  
745 *   if (homogeneous)
746 *   {
747 *   speed_of_sound_homogeneous = material_id_map.begin()->second.first;
748 *   density_homogeneous = material_id_map.begin()->second.second;
749 *   }
750 *   else
751 *   {
752 *   const auto n_cell_batches =
753 *   matrix_free.n_cell_batches() + matrix_free.n_ghost_cell_batches();
754 *  
755 *   speed_of_sound.resize(n_cell_batches);
756 *   density.resize(n_cell_batches);
757 *  
758 *   for (unsigned int cell = 0; cell < n_cell_batches; ++cell)
759 *   {
760 *   speed_of_sound[cell] = 1.;
761 *   density[cell] = 1.;
762 *   for (unsigned int v = 0;
763 *   v < matrix_free.n_active_entries_per_cell_batch(cell);
764 *   ++v)
765 *   {
766 *   const auto material_id =
767 *   matrix_free.get_cell_iterator(cell, v)->material_id();
768 *  
769 *   speed_of_sound[cell][v] =
770 *   material_id_map.at(material_id).first;
771 *   density[cell][v] = material_id_map.at(material_id).second;
772 *   }
773 *   }
774 *   }
775 *   }
776 *  
777 *   bool is_homogeneous() const
778 *   {
779 *   return homogeneous;
780 *   }
781 *  
782 *   const AlignedVector<VectorizedArray<Number>> &get_speed_of_sound() const
783 *   {
784 *   Assert(!homogeneous, ExcMessage("Use get_homogeneous_speed_of_sound()."));
785 *   return speed_of_sound;
786 *   }
787 *  
788 *   const AlignedVector<VectorizedArray<Number>> &get_density() const
789 *   {
790 *   Assert(!homogeneous, ExcMessage("Use get_homogeneous_density()."));
791 *   return density;
792 *   }
793 *  
794 *   VectorizedArray<Number> get_homogeneous_speed_of_sound() const
795 *   {
796 *   Assert(homogeneous, ExcMessage("Use get_speed_of_sound()."));
797 *   return speed_of_sound_homogeneous;
798 *   }
799 *  
800 *   VectorizedArray<Number> get_homogeneous_density() const
801 *   {
802 *   Assert(homogeneous, ExcMessage("Use get_density()."));
803 *   return density_homogeneous;
804 *   }
805 *  
806 *   private:
807 *   const bool homogeneous;
808 *  
809 *   /* Materials in the inhomogeneous case. */
810 *   AlignedVector<VectorizedArray<Number>> speed_of_sound;
812 *  
813 *   /* Materials in the homogeneous case. */
814 *   VectorizedArray<Number> speed_of_sound_homogeneous;
815 *   VectorizedArray<Number> density_homogeneous;
816 *   };
817 *  
818 * @endcode
819 *
820 * To be able to access the material data in every cell in a thread
821 * safe way, the following class @c MaterialEvaluation is
822 * used. Similar to @c FEEvaluation, functions below will create
823 * their own instances of this class; thus, there can be no race
824 * conditions even if these functions run multiple times in
825 * parallel. For inhomogeneous materials, a @c reinit_cell() or @c
826 * reinit_face() function is used to set the correct material at the
827 * current cell batch. In the homogeneous case the @c _reinit()
828 * functions don't have to reset the materials.
829 *
830 * @code
831 *   template <int dim, typename Number>
832 *   class MaterialEvaluation
833 *   {
834 *   public:
835 *   MaterialEvaluation(
836 *   const MatrixFree<dim, Number, VectorizedArray<Number>> &matrix_free,
837 *   const CellwiseMaterialData<Number> &material_data)
838 *   : phi(matrix_free)
839 *   , phi_face(matrix_free, true)
840 *   , material_data(material_data)
841 *   {
842 *   if (material_data.is_homogeneous())
843 *   {
844 *   speed_of_sound = material_data.get_homogeneous_speed_of_sound();
845 *   density = material_data.get_homogeneous_density();
846 *   }
847 *   }
848 *  
849 *   bool is_homogeneous() const
850 *   {
851 *   return material_data.is_homogeneous();
852 *   }
853 *  
854 * @endcode
855 *
856 * The following two functions update the data for the current
857 * cell or face, given a cell batch index. If the material is
858 * homogeneous, there is nothing to do. Otherwise, we reinit the
859 * FEEvaluation object and store the data for the current object.
860 *
861 * @code
862 *   void reinit_cell(const unsigned int cell)
863 *   {
864 *   if (!material_data.is_homogeneous())
865 *   {
866 *   phi.reinit(cell);
867 *   speed_of_sound =
868 *   phi.read_cell_data(material_data.get_speed_of_sound());
869 *   density = phi.read_cell_data(material_data.get_density());
870 *   }
871 *   }
872 *  
873 *   void reinit_face(const unsigned int face)
874 *   {
875 *   if (!material_data.is_homogeneous())
876 *   {
877 *   phi_face.reinit(face);
878 *   speed_of_sound =
879 *   phi_face.read_cell_data(material_data.get_speed_of_sound());
880 *   density = phi_face.read_cell_data(material_data.get_density());
881 *   }
882 *   }
883 *  
884 * @endcode
885 *
886 * The following functions then return the speed of sound and
887 * density for the current cell batch.
888 *
889 * @code
890 *   VectorizedArray<Number> get_speed_of_sound() const
891 *   {
892 *   return speed_of_sound;
893 *   }
894 *  
895 *   VectorizedArray<Number> get_density() const
896 *   {
897 *   return density;
898 *   }
899 *  
900 *   private:
901 *   /* Members needed for the inhomogeneous case. */
902 *   FEEvaluation<dim, -1, 0, 1, Number> phi;
903 *   FEFaceEvaluation<dim, -1, 0, 1, Number> phi_face;
904 *  
905 *   /* Material defined at every cell. */
906 *   const CellwiseMaterialData<Number> &material_data;
907 *  
908 *   /* Materials at current cell. */
909 *   VectorizedArray<Number> speed_of_sound;
910 *   VectorizedArray<Number> density;
911 *   };
912 *  
913 *  
914 * @endcode
915 *
916 *
917 * <a name="step_89-Boundaryconditions"></a>
918 * <h3>Boundary conditions</h3>
919 *
920
921 *
922 * To be able to use the same kernel, for all face integrals we define
923 * a class that returns the needed values at boundaries. In this tutorial
924 * homogeneous pressure Dirichlet boundary conditions are applied via
925 * the mirror principle, i.e. @f$p_h^+=-p_h^- + 2g@f$ with @f$g=0@f$.
926 *
927 * @code
928 *   template <int dim, typename Number>
929 *   class BCEvaluationP
930 *   {
931 *   public:
932 *   BCEvaluationP(const FEFaceEvaluation<dim, -1, 0, 1, Number> &pressure_m)
933 *   : pressure_m(pressure_m)
934 *   {}
935 *  
936 *   typename FEFaceEvaluation<dim, -1, 0, 1, Number>::value_type
937 *   get_value(const unsigned int q) const
938 *   {
939 *   return -pressure_m.get_value(q);
940 *   }
941 *  
942 *   private:
943 *   const FEFaceEvaluation<dim, -1, 0, 1, Number> &pressure_m;
944 *   };
945 *  
946 * @endcode
947 *
948 * We don't have to apply boundary conditions for the velocity, i.e.
949 * @f$\mathbf{u}_h^+=\mathbf{u}_h^-@f$.
950 *
951 * @code
952 *   template <int dim, typename Number>
953 *   class BCEvaluationU
954 *   {
955 *   public:
956 *   BCEvaluationU(const FEFaceEvaluation<dim, -1, 0, dim, Number> &velocity_m)
957 *   : velocity_m(velocity_m)
958 *   {}
959 *  
960 *   typename FEFaceEvaluation<dim, -1, 0, dim, Number>::value_type
961 *   get_value(const unsigned int q) const
962 *   {
963 *   return velocity_m.get_value(q);
964 *   }
965 *  
966 *   private:
967 *   const FEFaceEvaluation<dim, -1, 0, dim, Number> &velocity_m;
968 *   };
969 *  
970 * @endcode
971 *
972 *
973 * <a name="step_89-Acousticoperator"></a>
974 * <h3>Acoustic operator</h3>
975 *
976
977 *
978 * The following class then defines the acoustic operator. The class is
979 * heavily based on matrix-free methods. For a better understanding in
980 * matrix-free methods please refer to @ref step_67 "step-67".
981 *
982
983 *
984 * At the top we define a flag that decides whether we want to use
985 * mortaring. If the remote evaluators are set up with a
986 * VectorizedArray we are using point-to-point interpolation;
987 * otherwise we make use of Nitsche-type mortaring. The decision is
988 * made using `std::is_floating_point_v`, which is a variable that
989 * is true if the template argument is a floating point type (such
990 * as `float` or `double`) and false otherwise (in particular if the
991 * template argument is a vectorized array type).
992 *
993 * @code
994 *   template <int dim, typename Number, typename remote_value_type>
995 *   class AcousticOperator
996 *   {
997 *   static constexpr bool use_mortaring =
998 *   std::is_floating_point_v<remote_value_type>;
999 *  
1000 *   public:
1001 * @endcode
1002 *
1003 * In case of Nitsche-type mortaring, `NonMatching::MappingInfo` has to
1004 * be provided in the constructor.
1005 *
1006 * @code
1007 *   AcousticOperator(
1008 *   const MatrixFree<dim, Number> &matrix_free,
1009 *   std::shared_ptr<CellwiseMaterialData<Number>> material_data,
1010 *   const std::set<types::boundary_id> &remote_face_ids,
1011 *   std::shared_ptr<FERemoteEvaluation<dim, 1, remote_value_type>>
1012 *   pressure_r_eval,
1013 *   std::shared_ptr<FERemoteEvaluation<dim, dim, remote_value_type>>
1014 *   velocity_r_eval,
1015 *   std::shared_ptr<FERemoteEvaluation<dim, 1, remote_value_type>> c_r_eval,
1016 *   std::shared_ptr<FERemoteEvaluation<dim, 1, remote_value_type>> rho_r_eval,
1017 *   std::shared_ptr<NonMatching::MappingInfo<dim, dim, Number>> nm_info =
1018 *   nullptr)
1019 *   : matrix_free(matrix_free)
1020 *   , material_data(material_data)
1021 *   , remote_face_ids(remote_face_ids)
1022 *   , pressure_r_eval(pressure_r_eval)
1023 *   , velocity_r_eval(velocity_r_eval)
1024 *   , c_r_eval(c_r_eval)
1025 *   , rho_r_eval(rho_r_eval)
1026 *   , nm_mapping_info(nm_info)
1027 *   {
1028 *   if (use_mortaring)
1029 *   Assert(nm_info,
1030 *   ExcMessage(
1031 *   "In case of Nitsche-type mortaring NonMatching::MappingInfo \
1032 *   has to be provided."));
1033 *   }
1034 *  
1035 * @endcode
1036 *
1037 * The following function then evaluates the acoustic operator.
1038 * It first updates the precomputed values in corresponding the
1039 * FERemoteEvaluation objects. The material parameters do not change and
1040 * thus, we do not have to update precomputed values in @c c_r_eval and @c
1041 * rho_r_eval.
1042 *
1043
1044 *
1045 * It then either performs a matrix-free loop with Nitsche-type
1046 * mortaring at non-matching faces (if `use_mortaring` is true) or
1047 * with point-to-point interpolation at non-matching faces (in the
1048 * `else` branch). The difference is only in the third argument to
1049 * the loop function, denoting the function object that is
1050 * executed at boundary faces.
1051 *
1052 * @code
1053 *   template <typename VectorType>
1054 *   void evaluate(VectorType &dst, const VectorType &src) const
1055 *   {
1056 *   pressure_r_eval->gather_evaluate(src, EvaluationFlags::values);
1057 *   velocity_r_eval->gather_evaluate(src, EvaluationFlags::values);
1058 *  
1059 *   if constexpr (use_mortaring)
1060 *   {
1061 *   matrix_free.loop(
1062 *   &AcousticOperator::local_apply_cell<VectorType>,
1063 *   &AcousticOperator::local_apply_face<VectorType>,
1064 *   &AcousticOperator::local_apply_boundary_face_mortaring<VectorType>,
1065 *   this,
1066 *   dst,
1067 *   src,
1068 *   true,
1069 *   MatrixFree<dim, Number>::DataAccessOnFaces::values,
1070 *   MatrixFree<dim, Number>::DataAccessOnFaces::values);
1071 *   }
1072 *   else
1073 *   {
1074 *   matrix_free.loop(
1075 *   &AcousticOperator::local_apply_cell<VectorType>,
1076 *   &AcousticOperator::local_apply_face<VectorType>,
1077 *   &AcousticOperator::local_apply_boundary_face_point_to_point<
1078 *   VectorType>,
1079 *   this,
1080 *   dst,
1081 *   src,
1082 *   true,
1083 *   MatrixFree<dim, Number>::DataAccessOnFaces::values,
1084 *   MatrixFree<dim, Number>::DataAccessOnFaces::values);
1085 *   }
1086 *   }
1087 *  
1088 * @endcode
1089 *
1090 * In the `private` section of the class, we then define the
1091 * functions that evaluate volume, interior face, and boundary
1092 * face integrals. The concrete terms these functions evaluate are
1093 * stated in the documentation at the top of this tutorial
1094 * program. Each of these functions has its own object of type
1095 * `MaterialEvaluation` that provides access to the material at
1096 * each cell or face.
1097 *
1098 * @code
1099 *   private:
1100 *   template <typename VectorType>
1101 *   void local_apply_cell(
1102 *   const MatrixFree<dim, Number> &matrix_free,
1103 *   VectorType &dst,
1104 *   const VectorType &src,
1105 *   const std::pair<unsigned int, unsigned int> &cell_range) const
1106 *   {
1107 *   FEEvaluation<dim, -1, 0, 1, Number> pressure(matrix_free, 0, 0, 0);
1108 *   FEEvaluation<dim, -1, 0, dim, Number> velocity(matrix_free, 0, 0, 1);
1109 *  
1110 *   MaterialEvaluation material(matrix_free, *material_data);
1111 *  
1112 *   for (unsigned int cell = cell_range.first; cell < cell_range.second;
1113 *   ++cell)
1114 *   {
1115 *   velocity.reinit(cell);
1116 *   pressure.reinit(cell);
1117 *  
1118 *   pressure.gather_evaluate(src, EvaluationFlags::gradients);
1119 *   velocity.gather_evaluate(src, EvaluationFlags::gradients);
1120 *  
1121 * @endcode
1122 *
1123 * Get the materials on the corresponding cell. Since we
1124 * introduced @c MaterialEvaluation we can write the code
1125 * independent of whether the material is homogeneous or
1126 * inhomogeneous.
1127 *
1128 * @code
1129 *   material.reinit_cell(cell);
1130 *   const auto c = material.get_speed_of_sound();
1131 *   const auto rho = material.get_density();
1132 *  
1133 *   for (const unsigned int q : pressure.quadrature_point_indices())
1134 *   {
1135 *   pressure.submit_value(rho * c * c * velocity.get_divergence(q),
1136 *   q);
1137 *   velocity.submit_value(1.0 / rho * pressure.get_gradient(q), q);
1138 *   }
1139 *  
1140 *   pressure.integrate_scatter(EvaluationFlags::values, dst);
1141 *   velocity.integrate_scatter(EvaluationFlags::values, dst);
1142 *   }
1143 *   }
1144 *  
1145 * @endcode
1146 *
1147 * This next function evaluates the fluxes at faces between cells with the
1148 * same material. If boundary faces are under consideration fluxes into
1149 * neighboring faces do not have to be considered which is enforced via
1150 * `weight_neighbor=false`. For non-matching faces the fluxes into
1151 * neighboring faces are not considered as well. This is because we iterate
1152 * over each side of the non-matching face separately (similar to a cell
1153 * centric loop).
1154 *
1155
1156 *
1157 * In this and following functions, we also introduce the factors
1158 * @f$\tau@f$ and @f$\gamma@f$ that are computed from @f$\rho@f$ and @f$c@f$ along
1159 * interfaces and that appear in the bilinear forms. Their
1160 * definitions are provided in the introduction.
1161 *
1162 * @code
1163 *   template <bool weight_neighbor,
1164 *   typename InternalFaceIntegratorPressure,
1165 *   typename InternalFaceIntegratorVelocity,
1166 *   typename ExternalFaceIntegratorPressure,
1167 *   typename ExternalFaceIntegratorVelocity>
1168 *   inline DEAL_II_ALWAYS_INLINE void evaluate_face_kernel(
1169 *   InternalFaceIntegratorPressure &pressure_m,
1170 *   InternalFaceIntegratorVelocity &velocity_m,
1171 *   ExternalFaceIntegratorPressure &pressure_p,
1172 *   ExternalFaceIntegratorVelocity &velocity_p,
1173 *   const typename InternalFaceIntegratorPressure::value_type c,
1174 *   const typename InternalFaceIntegratorPressure::value_type rho) const
1175 *   {
1176 *   const auto tau = 0.5 * rho * c;
1177 *   const auto gamma = 0.5 / (rho * c);
1178 *  
1179 *   for (const unsigned int q : pressure_m.quadrature_point_indices())
1180 *   {
1181 *   const auto n = pressure_m.normal_vector(q);
1182 *   const auto pm = pressure_m.get_value(q);
1183 *   const auto um = velocity_m.get_value(q);
1184 *  
1185 *   const auto pp = pressure_p.get_value(q);
1186 *   const auto up = velocity_p.get_value(q);
1187 *  
1188 * @endcode
1189 *
1190 * Compute homogeneous local Lax-Friedrichs fluxes and submit the
1191 * corresponding values to the integrators.
1192 *
1193 * @code
1194 *   const auto momentum_flux =
1195 *   0.5 * (pm + pp) + 0.5 * tau * (um - up) * n;
1196 *   velocity_m.submit_value(1.0 / rho * (momentum_flux - pm) * n, q);
1197 *   if constexpr (weight_neighbor)
1198 *   velocity_p.submit_value(1.0 / rho * (momentum_flux - pp) * (-n), q);
1199 *  
1200 *   const auto mass_flux = 0.5 * (um + up) + 0.5 * gamma * (pm - pp) * n;
1201 *   pressure_m.submit_value(rho * c * c * (mass_flux - um) * n, q);
1202 *   if constexpr (weight_neighbor)
1203 *   pressure_p.submit_value(rho * c * c * (mass_flux - up) * (-n), q);
1204 *   }
1205 *   }
1206 *  
1207 * @endcode
1208 *
1209 * This function evaluates the fluxes at faces between cells with different
1210 * materials. This can only happen over non-matching interfaces. Therefore,
1211 * it is implicitly known that `weight_neighbor=false` and we can omit the
1212 * parameter.
1213 *
1214 * @code
1215 *   template <typename InternalFaceIntegratorPressure,
1216 *   typename InternalFaceIntegratorVelocity,
1217 *   typename ExternalFaceIntegratorPressure,
1218 *   typename ExternalFaceIntegratorVelocity,
1219 *   typename MaterialIntegrator>
1220 *   void evaluate_face_kernel_inhomogeneous(
1221 *   InternalFaceIntegratorPressure &pressure_m,
1222 *   InternalFaceIntegratorVelocity &velocity_m,
1223 *   const ExternalFaceIntegratorPressure &pressure_p,
1224 *   const ExternalFaceIntegratorVelocity &velocity_p,
1225 *   const typename InternalFaceIntegratorPressure::value_type c,
1226 *   const typename InternalFaceIntegratorPressure::value_type rho,
1227 *   const MaterialIntegrator &c_r,
1228 *   const MaterialIntegrator &rho_r) const
1229 *   {
1230 *   const auto tau_m = 0.5 * rho * c;
1231 *   const auto gamma_m = 0.5 / (rho * c);
1232 *  
1233 *   for (const unsigned int q : pressure_m.quadrature_point_indices())
1234 *   {
1235 *   const auto c_p = c_r.get_value(q);
1236 *   const auto rho_p = rho_r.get_value(q);
1237 *   const auto tau_p = 0.5 * rho_p * c_p;
1238 *   const auto gamma_p = 0.5 / (rho_p * c_p);
1239 *   const auto tau_sum_inv = 1.0 / (tau_m + tau_p);
1240 *   const auto gamma_sum_inv = 1.0 / (gamma_m + gamma_p);
1241 *  
1242 *   const auto n = pressure_m.normal_vector(q);
1243 *   const auto pm = pressure_m.get_value(q);
1244 *   const auto um = velocity_m.get_value(q);
1245 *  
1246 *   const auto pp = pressure_p.get_value(q);
1247 *   const auto up = velocity_p.get_value(q);
1248 *  
1249 *  
1250 * @endcode
1251 *
1252 * Compute inhomogeneous fluxes and submit the corresponding values
1253 * to the integrators.
1254 *
1255 * @code
1256 *   const auto momentum_flux =
1257 *   pm - tau_m * tau_sum_inv * (pm - pp) +
1258 *   tau_m * tau_p * tau_sum_inv * (um - up) * n;
1259 *   velocity_m.submit_value(1.0 / rho * (momentum_flux - pm) * n, q);
1260 *  
1261 *  
1262 *   const auto mass_flux =
1263 *   um - gamma_m * gamma_sum_inv * (um - up) +
1264 *   gamma_m * gamma_p * gamma_sum_inv * (pm - pp) * n;
1265 *  
1266 *   pressure_m.submit_value(rho * c * c * (mass_flux - um) * n, q);
1267 *   }
1268 *   }
1269 *  
1270 * @endcode
1271 *
1272 * This function evaluates the inner face integrals.
1273 *
1274 * @code
1275 *   template <typename VectorType>
1276 *   void local_apply_face(
1277 *   const MatrixFree<dim, Number> &matrix_free,
1278 *   VectorType &dst,
1279 *   const VectorType &src,
1280 *   const std::pair<unsigned int, unsigned int> &face_range) const
1281 *   {
1282 *   FEFaceEvaluation<dim, -1, 0, 1, Number> pressure_m(
1283 *   matrix_free, true, 0, 0, 0);
1284 *   FEFaceEvaluation<dim, -1, 0, 1, Number> pressure_p(
1285 *   matrix_free, false, 0, 0, 0);
1286 *   FEFaceEvaluation<dim, -1, 0, dim, Number> velocity_m(
1287 *   matrix_free, true, 0, 0, 1);
1288 *   FEFaceEvaluation<dim, -1, 0, dim, Number> velocity_p(
1289 *   matrix_free, false, 0, 0, 1);
1290 *  
1291 *   MaterialEvaluation material(matrix_free, *material_data);
1292 *  
1293 *   for (unsigned int face = face_range.first; face < face_range.second;
1294 *   ++face)
1295 *   {
1296 *   velocity_m.reinit(face);
1297 *   velocity_p.reinit(face);
1298 *  
1299 *   pressure_m.reinit(face);
1300 *   pressure_p.reinit(face);
1301 *  
1302 *   pressure_m.gather_evaluate(src, EvaluationFlags::values);
1303 *   pressure_p.gather_evaluate(src, EvaluationFlags::values);
1304 *  
1305 *   velocity_m.gather_evaluate(src, EvaluationFlags::values);
1306 *   velocity_p.gather_evaluate(src, EvaluationFlags::values);
1307 *  
1308 *   material.reinit_face(face);
1309 *   evaluate_face_kernel<true>(pressure_m,
1310 *   velocity_m,
1311 *   pressure_p,
1312 *   velocity_p,
1313 *   material.get_speed_of_sound(),
1314 *   material.get_density());
1315 *  
1316 *   pressure_m.integrate_scatter(EvaluationFlags::values, dst);
1317 *   pressure_p.integrate_scatter(EvaluationFlags::values, dst);
1318 *   velocity_m.integrate_scatter(EvaluationFlags::values, dst);
1319 *   velocity_p.integrate_scatter(EvaluationFlags::values, dst);
1320 *   }
1321 *   }
1322 *  
1323 *  
1324 * @endcode
1325 *
1326 *
1327 * <a name="step_89-Matrixfreeboundaryfunctionforpointtopointinterpolation"></a>
1328 * <h4>Matrix-free boundary function for point-to-point interpolation</h4>
1329 *
1330
1331 *
1332 * The following function then evaluates the boundary face integrals and the
1333 * non-matching face integrals using point-to-point interpolation.
1334 *
1335 * @code
1336 *   template <typename VectorType>
1337 *   void local_apply_boundary_face_point_to_point(
1338 *   const MatrixFree<dim, Number> &matrix_free,
1339 *   VectorType &dst,
1340 *   const VectorType &src,
1341 *   const std::pair<unsigned int, unsigned int> &face_range) const
1342 *   {
1343 *   FEFaceEvaluation<dim, -1, 0, 1, Number> pressure_m(
1344 *   matrix_free, true, 0, 0, 0);
1345 *   FEFaceEvaluation<dim, -1, 0, dim, Number> velocity_m(
1346 *   matrix_free, true, 0, 0, 1);
1347 *  
1348 *   BCEvaluationP pressure_bc(pressure_m);
1349 *   BCEvaluationU velocity_bc(velocity_m);
1350 *  
1351 *   MaterialEvaluation material(matrix_free, *material_data);
1352 *  
1353 * @endcode
1354 *
1355 * Remote evaluators.
1356 *
1357 * @code
1358 *   auto pressure_r = pressure_r_eval->get_data_accessor();
1359 *   auto velocity_r = velocity_r_eval->get_data_accessor();
1360 *   auto c_r = c_r_eval->get_data_accessor();
1361 *   auto rho_r = rho_r_eval->get_data_accessor();
1362 *  
1363 *   for (unsigned int face = face_range.first; face < face_range.second;
1364 *   ++face)
1365 *   {
1366 *   velocity_m.reinit(face);
1367 *   pressure_m.reinit(face);
1368 *  
1369 *   pressure_m.gather_evaluate(src, EvaluationFlags::values);
1370 *   velocity_m.gather_evaluate(src, EvaluationFlags::values);
1371 *  
1372 *   if (HelperFunctions::is_non_matching_face(
1373 *   remote_face_ids, matrix_free.get_boundary_id(face)))
1374 *   {
1375 * @endcode
1376 *
1377 * If @c face is non-matching we have to query values via the
1378 * FERemoteEvaluaton objects. This is done by passing the
1379 * corresponding FERemoteEvaluaton objects to the function that
1380 * evaluates the kernel. As mentioned above, each side of the
1381 * non-matching interface is traversed separately and we do not
1382 * have to consider the neighbor in the kernel. Note, that the
1383 * values in the FERemoteEvaluaton objects are already updated at
1384 * this point.
1385 *
1386
1387 *
1388 * For point-to-point interpolation we simply use the
1389 * corresponding FERemoteEvaluaton objects in combination with the
1390 * standard FEFaceEvaluation objects.
1391 *
1392 * @code
1393 *   velocity_r.reinit(face);
1394 *   pressure_r.reinit(face);
1395 *  
1396 *   material.reinit_face(face);
1397 *  
1398 * @endcode
1399 *
1400 * If we are considering a homogeneous material, do not use the
1401 * inhomogeneous fluxes. While it would be possible
1402 * to use the inhomogeneous fluxes they are more expensive to
1403 * compute.
1404 *
1405 * @code
1406 *   if (material.is_homogeneous())
1407 *   {
1408 *   evaluate_face_kernel<false>(pressure_m,
1409 *   velocity_m,
1410 *   pressure_r,
1411 *   velocity_r,
1412 *   material.get_speed_of_sound(),
1413 *   material.get_density());
1414 *   }
1415 *   else
1416 *   {
1417 *   c_r.reinit(face);
1418 *   rho_r.reinit(face);
1419 *   evaluate_face_kernel_inhomogeneous(
1420 *   pressure_m,
1421 *   velocity_m,
1422 *   pressure_r,
1423 *   velocity_r,
1424 *   material.get_speed_of_sound(),
1425 *   material.get_density(),
1426 *   c_r,
1427 *   rho_r);
1428 *   }
1429 *   }
1430 *   else
1431 *   {
1432 * @endcode
1433 *
1434 * If @c face is a standard boundary face, evaluate the integral
1435 * as usual in the matrix free context. To be able to use the same
1436 * kernel as for inner faces we pass the boundary condition
1437 * objects to the function that evaluates the kernel. As detailed
1438 * above `weight_neighbor=false`.
1439 *
1440 * @code
1441 *   material.reinit_face(face);
1442 *   evaluate_face_kernel<false>(pressure_m,
1443 *   velocity_m,
1444 *   pressure_bc,
1445 *   velocity_bc,
1446 *   material.get_speed_of_sound(),
1447 *   material.get_density());
1448 *   }
1449 *  
1450 *   pressure_m.integrate_scatter(EvaluationFlags::values, dst);
1451 *   velocity_m.integrate_scatter(EvaluationFlags::values, dst);
1452 *   }
1453 *   }
1454 *  
1455 * @endcode
1456 *
1457 *
1458 * <a name="step_89-MatrixfreeboundaryfunctionforNitschetypemortaring"></a>
1459 * <h4>Matrix-free boundary function for Nitsche-type mortaring</h4>
1460 *
1461
1462 *
1463 * This function evaluates the boundary face integrals and the
1464 * non-matching face integrals using Nitsche-type mortaring.
1465 *
1466 * @code
1467 *   template <typename VectorType>
1468 *   void local_apply_boundary_face_mortaring(
1469 *   const MatrixFree<dim, Number> &matrix_free,
1470 *   VectorType &dst,
1471 *   const VectorType &src,
1472 *   const std::pair<unsigned int, unsigned int> &face_range) const
1473 *   {
1474 *   FEFaceEvaluation<dim, -1, 0, 1, Number> pressure_m(
1475 *   matrix_free, true, 0, 0, 0);
1476 *   FEFaceEvaluation<dim, -1, 0, dim, Number> velocity_m(
1477 *   matrix_free, true, 0, 0, 1);
1478 *  
1479 * @endcode
1480 *
1481 * For Nitsche-type mortaring we are evaluating the integrals over
1482 * intersections. This is why, quadrature points are arbitrarily
1483 * distributed on every face. Thus, we can not make use of face batches
1484 * and FEFaceEvaluation but have to consider each face individually and
1485 * make use of @c FEFacePointEvaluation to evaluate the integrals in the
1486 * arbitrarily distributed quadrature points.
1487 * Since the setup of FEFacePointEvaluation is more expensive than that of
1488 * FEEvaluation we do the setup only once. For this we are using the
1489 * helper function @c get_thread_safe_fe_face_point_evaluation_object().
1490 *
1491 * @code
1492 *   FEFacePointEvaluation<1, dim, dim, Number> &pressure_m_mortar =
1493 *   get_thread_safe_fe_face_point_evaluation_object<1>(
1494 *   thread_local_pressure_m_mortar, 0);
1495 *   FEFacePointEvaluation<dim, dim, dim, Number> &velocity_m_mortar =
1496 *   get_thread_safe_fe_face_point_evaluation_object<dim>(
1497 *   thread_local_velocity_m_mortar, 1);
1498 *  
1499 *   BCEvaluationP pressure_bc(pressure_m);
1500 *   BCEvaluationU velocity_bc(velocity_m);
1501 *  
1502 *   MaterialEvaluation material(matrix_free, *material_data);
1503 *  
1504 *   auto pressure_r_mortar = pressure_r_eval->get_data_accessor();
1505 *   auto velocity_r_mortar = velocity_r_eval->get_data_accessor();
1506 *   auto c_r = c_r_eval->get_data_accessor();
1507 *   auto rho_r = rho_r_eval->get_data_accessor();
1508 *  
1509 *   for (unsigned int face = face_range.first; face < face_range.second;
1510 *   ++face)
1511 *   {
1512 *   if (HelperFunctions::is_non_matching_face(
1513 *   remote_face_ids, matrix_free.get_boundary_id(face)))
1514 *   {
1515 *   material.reinit_face(face);
1516 *  
1517 * @endcode
1518 *
1519 * First fetch the DoF values with standard FEFaceEvaluation
1520 * objects.
1521 *
1522 * @code
1523 *   pressure_m.reinit(face);
1524 *   velocity_m.reinit(face);
1525 *  
1526 *   pressure_m.read_dof_values(src);
1527 *   velocity_m.read_dof_values(src);
1528 *  
1529 * @endcode
1530 *
1531 * Project the internally stored values into the face DoFs
1532 * of the current face.
1533 *
1534 * @code
1535 *   pressure_m.project_to_face(EvaluationFlags::values);
1536 *   velocity_m.project_to_face(EvaluationFlags::values);
1537 *  
1538 * @endcode
1539 *
1540 * For mortaring, we have to consider every face from the face
1541 * batches separately and have to use the FEFacePointEvaluation
1542 * objects to be able to evaluate the integrals with the
1543 * arbitrarily distributed quadrature points.
1544 *
1545 * @code
1546 *   for (unsigned int v = 0;
1547 *   v < matrix_free.n_active_entries_per_face_batch(face);
1548 *   ++v)
1549 *   {
1550 *   constexpr unsigned int n_lanes =
1551 *   VectorizedArray<Number>::size();
1552 *   velocity_m_mortar.reinit(face * n_lanes + v);
1553 *   pressure_m_mortar.reinit(face * n_lanes + v);
1554 *  
1555 * @endcode
1556 *
1557 * Evaluate using FEFacePointEvaluation. As buffer,
1558 * simply use the internal buffers from the
1559 * FEFaceEvaluation objects.
1560 *
1561 * @code
1562 *   velocity_m_mortar.evaluate_in_face(
1563 *   &velocity_m.get_scratch_data().begin()[0][v],
1564 *   EvaluationFlags::values);
1565 *  
1566 *   pressure_m_mortar.evaluate_in_face(
1567 *   &pressure_m.get_scratch_data().begin()[0][v],
1568 *   EvaluationFlags::values);
1569 *  
1570 *   velocity_r_mortar.reinit(face * n_lanes + v);
1571 *   pressure_r_mortar.reinit(face * n_lanes + v);
1572 *  
1573 * @endcode
1574 *
1575 * As above, if we are considering a homogeneous
1576 * material, do not use the inhomogeneous
1577 * fluxes. Since we are operating on face @c v we
1578 * call @c material.get_density()[v].
1579 *
1580 * @code
1581 *   if (material.is_homogeneous())
1582 *   {
1583 *   evaluate_face_kernel<false>(
1584 *   pressure_m_mortar,
1585 *   velocity_m_mortar,
1586 *   pressure_r_mortar,
1587 *   velocity_r_mortar,
1588 *   material.get_speed_of_sound()[v],
1589 *   material.get_density()[v]);
1590 *   }
1591 *   else
1592 *   {
1593 *   c_r.reinit(face * n_lanes + v);
1594 *   rho_r.reinit(face * n_lanes + v);
1595 *  
1596 *   evaluate_face_kernel_inhomogeneous(
1597 *   pressure_m_mortar,
1598 *   velocity_m_mortar,
1599 *   pressure_r_mortar,
1600 *   velocity_r_mortar,
1601 *   material.get_speed_of_sound()[v],
1602 *   material.get_density()[v],
1603 *   c_r,
1604 *   rho_r);
1605 *   }
1606 *  
1607 * @endcode
1608 *
1609 * Integrate using FEFacePointEvaluation. As buffer,
1610 * simply use the internal buffers from the
1611 * FEFaceEvaluation objects.
1612 *
1613 * @code
1614 *   velocity_m_mortar.integrate_in_face(
1615 *   &velocity_m.get_scratch_data().begin()[0][v],
1616 *   EvaluationFlags::values);
1617 *  
1618 *   pressure_m_mortar.integrate_in_face(
1619 *   &pressure_m.get_scratch_data().begin()[0][v],
1620 *   EvaluationFlags::values);
1621 *   }
1622 *  
1623 * @endcode
1624 *
1625 * Collect the contributions from the face DoFs to
1626 * the internal cell DoFs to be able to use the
1627 * member function @c distribute_local_to_global().
1628 *
1629 * @code
1630 *   pressure_m.collect_from_face(EvaluationFlags::values);
1631 *   velocity_m.collect_from_face(EvaluationFlags::values);
1632 *  
1633 *   pressure_m.distribute_local_to_global(dst);
1634 *   velocity_m.distribute_local_to_global(dst);
1635 *   }
1636 *   else
1637 *   {
1638 *   velocity_m.reinit(face);
1639 *   pressure_m.reinit(face);
1640 *  
1641 *   pressure_m.gather_evaluate(src, EvaluationFlags::values);
1642 *   velocity_m.gather_evaluate(src, EvaluationFlags::values);
1643 *  
1644 *   material.reinit_face(face);
1645 *   evaluate_face_kernel<false>(pressure_m,
1646 *   velocity_m,
1647 *   pressure_bc,
1648 *   velocity_bc,
1649 *   material.get_speed_of_sound(),
1650 *   material.get_density());
1651 *  
1652 *   pressure_m.integrate_scatter(EvaluationFlags::values, dst);
1653 *   velocity_m.integrate_scatter(EvaluationFlags::values, dst);
1654 *   }
1655 *   }
1656 *   }
1657 *  
1658 *   const MatrixFree<dim, Number> &matrix_free;
1659 *  
1660 *   const std::shared_ptr<CellwiseMaterialData<Number>> material_data;
1661 *  
1662 *   const std::set<types::boundary_id> remote_face_ids;
1663 *  
1664 * @endcode
1665 *
1666 * FERemoteEvaluation objects are stored as shared pointers. This way,
1667 * they can also be used for other operators without precomputing the values
1668 * multiple times.
1669 *
1670 * @code
1671 *   const std::shared_ptr<FERemoteEvaluation<dim, 1, remote_value_type>>
1672 *   pressure_r_eval;
1673 *   const std::shared_ptr<FERemoteEvaluation<dim, dim, remote_value_type>>
1674 *   velocity_r_eval;
1675 *  
1676 *   const std::shared_ptr<FERemoteEvaluation<dim, 1, remote_value_type>>
1677 *   c_r_eval;
1678 *   const std::shared_ptr<FERemoteEvaluation<dim, 1, remote_value_type>>
1679 *   rho_r_eval;
1680 *  
1681 *   const std::shared_ptr<NonMatching::MappingInfo<dim, dim, Number>>
1682 *   nm_mapping_info;
1683 *  
1684 * @endcode
1685 *
1686 * We store FEFacePointEvaluation objects as members in a thread local
1687 * way, since its creation is more expensive compared to FEEvaluation
1688 * objects.
1689 *
1690 * @code
1691 *   mutable Threads::ThreadLocalStorage<
1692 *   std::unique_ptr<FEFacePointEvaluation<1, dim, dim, Number>>>
1693 *   thread_local_pressure_m_mortar;
1694 *  
1695 *   mutable Threads::ThreadLocalStorage<
1696 *   std::unique_ptr<FEFacePointEvaluation<dim, dim, dim, Number>>>
1697 *   thread_local_velocity_m_mortar;
1698 *  
1699 * @endcode
1700 *
1701 * Helper function to create and get FEFacePointEvaluation objects in a
1702 * thread safe way. On each thread, FEFacePointEvaluation is created if it
1703 * has not been created by now. After that, simply return the object
1704 * corresponding to the thread under consideration.
1705 *
1706 * @code
1707 *   template <int n_components>
1708 *   FEFacePointEvaluation<n_components, dim, dim, Number> &
1709 *   get_thread_safe_fe_face_point_evaluation_object(
1710 *   Threads::ThreadLocalStorage<
1711 *   std::unique_ptr<FEFacePointEvaluation<n_components, dim, dim, Number>>>
1712 *   &fe_face_point_eval_thread_local,
1713 *   unsigned int fist_selected_comp) const
1714 *   {
1715 *   if (fe_face_point_eval_thread_local.get() == nullptr)
1716 *   {
1717 *   fe_face_point_eval_thread_local = std::make_unique<
1718 *   FEFacePointEvaluation<n_components, dim, dim, Number>>(
1719 *   *nm_mapping_info,
1720 *   matrix_free.get_dof_handler().get_fe(),
1721 *   true,
1722 *   fist_selected_comp);
1723 *   }
1724 *   return *fe_face_point_eval_thread_local.get();
1725 *   }
1726 *   };
1727 *  
1728 * @endcode
1729 *
1730 *
1731 * <a name="step_89-Inversemassoperator"></a>
1732 * <h3>Inverse mass operator</h3>
1733 *
1734
1735 *
1736 * For the time stepping methods below, we need the inverse mass
1737 * operator. We apply it via a loop over all (batches of) cells as
1738 * always, where the contribution of each cell is computed in a
1739 * matrix-free way:
1740 *
1741 * @code
1742 *   template <int dim, typename Number>
1743 *   class InverseMassOperator
1744 *   {
1745 *   public:
1746 *   InverseMassOperator(const MatrixFree<dim, Number> &matrix_free)
1747 *   : matrix_free(matrix_free)
1748 *   {}
1749 *  
1750 *   template <typename VectorType>
1751 *   void apply(VectorType &dst, const VectorType &src) const
1752 *   {
1753 *   dst.zero_out_ghost_values();
1754 *   matrix_free.cell_loop(&InverseMassOperator::local_apply_cell<VectorType>,
1755 *   this,
1756 *   dst,
1757 *   src);
1758 *   }
1759 *  
1760 *   private:
1761 *   template <typename VectorType>
1762 *   void local_apply_cell(
1763 *   const MatrixFree<dim, Number> &mf,
1764 *   VectorType &dst,
1765 *   const VectorType &src,
1766 *   const std::pair<unsigned int, unsigned int> &cell_range) const
1767 *   {
1768 *   FEEvaluation<dim, -1, 0, dim + 1, Number> phi(mf);
1769 *   MatrixFreeOperators::CellwiseInverseMassMatrix<dim, -1, dim + 1, Number>
1770 *   minv(phi);
1771 *  
1772 *   for (unsigned int cell = cell_range.first; cell < cell_range.second;
1773 *   ++cell)
1774 *   {
1775 *   phi.reinit(cell);
1776 *   phi.read_dof_values(src);
1777 *   minv.apply(phi.begin_dof_values(), phi.begin_dof_values());
1778 *   phi.set_dof_values(dst);
1779 *   }
1780 *   }
1781 *  
1782 *   const MatrixFree<dim, Number> &matrix_free;
1783 *   };
1784 *  
1785 * @endcode
1786 *
1787 *
1788 * <a name="step_89-RungeKuttatimestepping"></a>
1789 * <h3>Runge-Kutta time-stepping</h3>
1790 *
1791
1792 *
1793 * This class implements a Runge-Kutta scheme of order 2.
1794 *
1795 * @code
1796 *   template <int dim, typename Number, typename remote_value_type>
1797 *   class RungeKutta2
1798 *   {
1799 *   using VectorType = LinearAlgebra::distributed::Vector<Number>;
1800 *  
1801 *   public:
1802 *   RungeKutta2(
1803 *   const std::shared_ptr<InverseMassOperator<dim, Number>>
1804 *   inverse_mass_operator,
1805 *   const std::shared_ptr<AcousticOperator<dim, Number, remote_value_type>>
1806 *   acoustic_operator)
1807 *   : inverse_mass_operator(inverse_mass_operator)
1808 *   , acoustic_operator(acoustic_operator)
1809 *   {}
1810 *  
1811 * @endcode
1812 *
1813 * The `run()` function of this class contains the time loop. It
1814 * starts by initializing some member variables (such as
1815 * short-cuts to objects that describe the finite element, its
1816 * properties, and the mapping; an by initializing vectors). It
1817 * then computes the time step size via minimum element edge
1818 * length. Assuming non-distorted elements, we can compute the
1819 * edge length as the distance between two vertices. From this,
1820 * we can then obtain the time step size via the CFL condition.
1821 *
1822 * @code
1823 *   void run(const MatrixFree<dim, Number> &matrix_free,
1824 *   const double cr,
1825 *   const double end_time,
1826 *   const double speed_of_sound,
1827 *   const Function<dim> &initial_condition,
1828 *   const std::string &vtk_prefix)
1829 *   {
1830 *   const auto &dof_handler = matrix_free.get_dof_handler();
1831 *   const auto &mapping = *matrix_free.get_mapping_info().mapping;
1832 *   const auto degree = dof_handler.get_fe().degree;
1833 *  
1834 *   VectorType solution;
1835 *   matrix_free.initialize_dof_vector(solution);
1836 *   VectorType solution_temp;
1837 *   matrix_free.initialize_dof_vector(solution_temp);
1838 *  
1839 *   HelperFunctions::set_initial_condition(matrix_free,
1840 *   initial_condition,
1841 *   solution);
1842 *  
1843 *   double h_local_min = std::numeric_limits<double>::max();
1844 *   for (const auto &cell : dof_handler.active_cell_iterators())
1845 *   h_local_min =
1846 *   std::min(h_local_min,
1847 *   (cell->vertex(1) - cell->vertex(0)).norm_square());
1848 *   h_local_min = std::sqrt(h_local_min);
1849 *   const double h_min =
1850 *   Utilities::MPI::min(h_local_min, dof_handler.get_communicator());
1851 *  
1852 *   const double dt =
1853 *   cr * HelperFunctions::compute_dt_cfl(h_min, degree, speed_of_sound);
1854 *  
1855 * @endcode
1856 *
1857 * We can then perform the time integration loop:
1858 *
1859 * @code
1860 *   double time = 0.0;
1861 *   unsigned int timestep = 0;
1862 *   while (time < end_time)
1863 *   {
1864 *   HelperFunctions::write_vtu(solution,
1865 *   matrix_free.get_dof_handler(),
1866 *   mapping,
1867 *   degree,
1868 *   "step_89-" + vtk_prefix +
1869 *   std::to_string(timestep));
1870 *  
1871 *   std::swap(solution, solution_temp);
1872 *   time += dt;
1873 *   ++timestep;
1874 *   perform_time_step(dt, solution, solution_temp);
1875 *   }
1876 *   }
1877 *  
1878 * @endcode
1879 *
1880 * The main work of this class is done by a `private` member
1881 * function that performs one Runge-Kutta 2 time step. Recall that
1882 * this method requires two sub-steps ("stages") computing
1883 * intermediate values `k1` and `k2`, after which the intermediate
1884 * values are summed with weights to obtain the new solution at
1885 * the end of the time step. The RK2 method allows for the
1886 * elimination of the intermediate vector `k2` by utilizing the
1887 * `dst` vector as temporary storage.
1888 *
1889 * @code
1890 *   private:
1891 *   void
1892 *   perform_time_step(const double dt, VectorType &dst, const VectorType &src)
1893 *   {
1894 *   VectorType k1 = src;
1895 *  
1896 *   /* First stage. */
1897 *   evaluate_stage(k1, src);
1898 *  
1899 *   /* Second stage. */
1900 *   k1.sadd(0.5 * dt, 1.0, src);
1901 *   evaluate_stage(dst, k1);
1902 *  
1903 *   /* Summing things into the output vector. */
1904 *   dst.sadd(dt, 1.0, src);
1905 *   }
1906 *  
1907 * @endcode
1908 *
1909 * Evaluating a single Runge-Kutta stage is a straightforward step
1910 * that really only requires applying the operator once, and then
1911 * applying the inverse of the mass matrix.
1912 *
1913 * @code
1914 *   void evaluate_stage(VectorType &dst, const VectorType &src)
1915 *   {
1916 *   acoustic_operator->evaluate(dst, src);
1917 *   dst *= -1.0;
1918 *   inverse_mass_operator->apply(dst, dst);
1919 *   }
1920 *  
1921 *   const std::shared_ptr<InverseMassOperator<dim, Number>>
1922 *   inverse_mass_operator;
1923 *   const std::shared_ptr<AcousticOperator<dim, Number, remote_value_type>>
1924 *   acoustic_operator;
1925 *   };
1926 *  
1927 *  
1928 * @endcode
1929 *
1930 *
1931 * <a name="step_89-Constructionofnonmatchingtriangulations"></a>
1932 * <h3>Construction of non-matching triangulations</h3>
1933 *
1934
1935 *
1936 * Let us now make our way to the higher-level functions of this program.
1937 *
1938
1939 *
1940 * The first of these functions creates a two dimensional square
1941 * triangulation that spans from @f$(0,0)@f$ to @f$(1,1)@f$. It consists of
1942 * two sub-domains. The left sub-domain spans from @f$(0,0)@f$ to
1943 * @f$(0.525,1)@f$. The right sub-domain spans from @f$(0.525,0)@f$ to
1944 * @f$(1,1)@f$. The left sub-domain has elements that are three times
1945 * smaller compared to the ones for the right sub-domain.
1946 *
1947
1948 *
1949 * At non-matching interfaces, we need to provide different boundary
1950 * IDs for the cells that make up the two parts (because, while they
1951 * may be physically adjacent, they are not logically neighbors
1952 * given that the faces of cells on both sides do not match, and the
1953 * Triangulation class will therefore treat the interface between
1954 * the two parts as a "boundary"). These boundary IDs have to differ
1955 * because later on RemotePointEvaluation has to search for remote
1956 * points for each face, that are defined in the same mesh (since we
1957 * merge the mesh) but not on the same side of the non-matching
1958 * interface. As a consequence, we declare at the top symbolic names
1959 * for these boundary indicators, and ensure that we return a set
1960 * with these values to the caller for later use.
1961 *
1962
1963 *
1964 * The actual mesh is then constructed by first constructing the
1965 * left and right parts separately (setting material ids to zero and
1966 * one, respectively), and using the appropriate boundary ids for
1967 * all parts of the mesh. We then use
1968 * GridGenerator::merge_triangulations() to combine them into one
1969 * (non-matching) mesh. We have to pay attention that should the two
1970 * sub-triangulations have vertices at the same locations, that they
1971 * are not merged (connecting the two triangulations logically)
1972 * since we want the interface to be an actual boundary. We achieve
1973 * this by providing a tolerance of zero for the merge, see the
1974 * documentation of the function
1975 * GridGenerator::merge_triangulations().
1976 *
1977 * @code
1978 *   template <int dim>
1979 *   void build_non_matching_triangulation(
1980 *   Triangulation<dim> &tria,
1981 *   std::set<types::boundary_id> &non_matching_faces,
1982 *   const unsigned int refinements)
1983 *   {
1984 *   const double length = 1.0;
1985 *  
1986 *   const types::boundary_id non_matching_id_left = 98;
1987 *   const types::boundary_id non_matching_id_right = 99;
1988 *  
1989 *   non_matching_faces = {non_matching_id_left, non_matching_id_right};
1990 *  
1991 *   /* Construct left part of mesh. */
1992 *   Triangulation<dim> tria_left;
1993 *   const unsigned int subdiv_left = 11;
1994 *   GridGenerator::subdivided_hyper_rectangle(tria_left,
1995 *   {subdiv_left, 2 * subdiv_left},
1996 *   {0.0, 0.0},
1997 *   {0.525 * length, length});
1998 *  
1999 *   for (const auto &cell : tria_left.active_cell_iterators())
2000 *   cell->set_material_id(0);
2001 *   for (const auto &face : tria_left.active_face_iterators())
2002 *   if (face->at_boundary())
2003 *   {
2004 *   face->set_boundary_id(0);
2005 *   if (face->center()[0] > 0.525 * length - 1e-6)
2006 *   face->set_boundary_id(non_matching_id_left);
2007 *   }
2008 *  
2009 *   /* Construct right part of mesh. */
2010 *   Triangulation<dim> tria_right;
2011 *   const unsigned int subdiv_right = 4;
2012 *   GridGenerator::subdivided_hyper_rectangle(tria_right,
2013 *   {subdiv_right, 2 * subdiv_right},
2014 *   {0.525 * length, 0.0},
2015 *   {length, length});
2016 *  
2017 *   for (const auto &cell : tria_right.active_cell_iterators())
2018 *   cell->set_material_id(1);
2019 *   for (const auto &face : tria_right.active_face_iterators())
2020 *   if (face->at_boundary())
2021 *   {
2022 *   face->set_boundary_id(0);
2023 *   if (face->center()[0] < 0.525 * length + 1e-6)
2024 *   face->set_boundary_id(non_matching_id_right);
2025 *   }
2026 *  
2027 *   /* Merge triangulations. */
2028 *   GridGenerator::merge_triangulations(tria_left,
2029 *   tria_right,
2030 *   tria,
2031 *   /*tolerance*/ 0.,
2032 *   /*copy_manifold_ids*/ false,
2033 *   /*copy_boundary_ids*/ true);
2034 *  
2035 *   /* Refine the result. */
2036 *   tria.refine_global(refinements);
2037 *   }
2038 *  
2039 * @endcode
2040 *
2041 *
2042 * <a name="step_89-Setupandrunningofthetwoschemes"></a>
2043 * <h3>Set up and running of the two schemes</h3>
2044 *
2045
2046 *
2047 *
2048 * <a name="step_89-Setupandrunningofthepointtopointinterpolationscheme"></a>
2049 * <h4>Setup and running of the point-to-point interpolation scheme</h4>
2050 *
2051
2052 *
2053 * We are now at the two functions that run the overall schemes (the
2054 * point-to-point and the mortaring schemes). The first of these
2055 * functions fills a FERemoteEvaluationCommunicator object that is
2056 * needed for point-to-point interpolation. Additionally, the
2057 * corresponding remote evaluators are set up using this remote
2058 * communicator. Eventually, the operators are handed to the time
2059 * integrator that runs the simulation.
2060 *
2061 * @code
2062 *   template <int dim, typename Number>
2063 *   void run_with_point_to_point_interpolation(
2064 *   const MatrixFree<dim, Number> &matrix_free,
2065 *   const std::set<types::boundary_id> &non_matching_faces,
2066 *   const std::map<types::material_id, std::pair<double, double>> &materials,
2067 *   const double end_time,
2068 *   const Function<dim> &initial_condition,
2069 *   const std::string &vtk_prefix)
2070 *   {
2071 *   const auto &dof_handler = matrix_free.get_dof_handler();
2072 *   const auto &tria = dof_handler.get_triangulation();
2073 *  
2074 * @endcode
2075 *
2076 * Communication objects know about the communication pattern. That is,
2077 * they know about the cells and quadrature points that have to be
2078 * evaluated at remote faces. This information is given via
2079 * RemotePointEvaluation. Additionally, the communication objects
2080 * have to be able to match the quadrature points of the remote
2081 * points (that provide exterior information) to the quadrature points
2082 * defined at the interior cell. In case of point-to-point interpolation
2083 * a vector of pairs with face batch Ids and the number of faces in the
2084 * batch is needed. @c FERemoteCommunicationObjectEntityBatches
2085 * is a container to store this information.
2086 *
2087
2088 *
2089 * The information is filled outside of the actual class since in some cases
2090 * the information is available from some heuristic and
2091 * it is possible to skip some expensive operations. This is for example
2092 * the case for sliding rotating interfaces with equally spaced elements on
2093 * both sides of the non-matching interface @cite duerrwaechter2021an.
2094 *
2095
2096 *
2097 * For the standard case of point to point-to-point interpolation without
2098 * any heuristic we make use of the utility function
2099 * Utilities::compute_remote_communicator_faces_point_to_point_interpolation().
2100 * Please refer to the documentation of this function to see how to manually
2101 * set up the remote communicator from outside.
2102 *
2103
2104 *
2105 * Among the inputs for the remote communicator we need a list of
2106 * boundary ids for the non-matching faces, along with a function
2107 * object for each boundary id that returns a vector of true/false
2108 * flags in which exactly the vertices of cells of the
2109 * triangulation are marked that have a face at the boundary id in
2110 * question.
2111 *
2112 * @code
2113 *   std::vector<
2114 *   std::pair<types::boundary_id, std::function<std::vector<bool>()>>>
2115 *   non_matching_faces_marked_vertices;
2116 *   for (const auto &nm_face : non_matching_faces)
2117 *   {
2118 *   auto marked_vertices = [&nm_face, &tria]() -> std::vector<bool> {
2119 *   std::vector<bool> mask(tria.n_vertices(), true);
2120 *  
2121 *   for (const auto &cell : tria.active_cell_iterators())
2122 *   for (auto const &f : cell->face_indices())
2123 *   if (cell->face(f)->at_boundary() &&
2124 *   cell->face(f)->boundary_id() == nm_face)
2125 *   for (const auto v : cell->vertex_indices())
2126 *   mask[cell->vertex_index(v)] = false;
2127 *  
2128 *   return mask;
2129 *   };
2130 *  
2131 *   non_matching_faces_marked_vertices.emplace_back(
2132 *   std::make_pair(nm_face, marked_vertices));
2133 *   }
2134 *  
2135 *   auto remote_communicator =
2136 *   Utilities::compute_remote_communicator_faces_point_to_point_interpolation(
2137 *   matrix_free, non_matching_faces_marked_vertices);
2138 *  
2139 * @endcode
2140 *
2141 * We are using point-to-point interpolation and can therefore
2142 * easily access the corresponding data at face batches. This
2143 * is why we use a @c VectorizedArray as @c remote_value_type:
2144 *
2145 * @code
2146 *   using remote_value_type = VectorizedArray<Number>;
2147 *  
2148 * @endcode
2149 *
2150 * We then set up FERemoteEvaluation objects that access the
2151 * pressure and velocity at remote faces, along with an object to
2152 * describe cell-wise material data.
2153 *
2154 * @code
2155 *   const auto pressure_r =
2156 *   std::make_shared<FERemoteEvaluation<dim, 1, remote_value_type>>(
2157 *   remote_communicator, dof_handler, /*first_selected_component*/ 0);
2158 *  
2159 *   const auto velocity_r =
2160 *   std::make_shared<FERemoteEvaluation<dim, dim, remote_value_type>>(
2161 *   remote_communicator, dof_handler, /*first_selected_component*/ 1);
2162 *  
2163 *   const auto material_data =
2164 *   std::make_shared<CellwiseMaterialData<Number>>(matrix_free, materials);
2165 *  
2166 * @endcode
2167 *
2168 * If we have an inhomogeneous problem, we have to set up the
2169 * material handler that accesses the materials at remote faces.
2170 *
2171 * @code
2172 *   const auto c_r =
2173 *   std::make_shared<FERemoteEvaluation<dim, 1, remote_value_type>>(
2174 *   remote_communicator,
2175 *   matrix_free.get_dof_handler().get_triangulation(),
2176 *   /*first_selected_component*/ 0);
2177 *   const auto rho_r =
2178 *   std::make_shared<FERemoteEvaluation<dim, 1, remote_value_type>>(
2179 *   remote_communicator,
2180 *   matrix_free.get_dof_handler().get_triangulation(),
2181 *   /*first_selected_component*/ 0);
2182 *  
2183 * @endcode
2184 *
2185 * If the domain is not homogeneous, i.e., if material parameters
2186 * change from cell to cell, we initialize and fill DoF vectors
2187 * that contain the material properties. Materials do not change
2188 * during the simulation, therefore there is no need to ever
2189 * compute the values after the first @c gather_evaluate() (at the
2190 * end of the following block) again.
2191 *
2192 * @code
2193 *   if (!material_data->is_homogeneous())
2194 *   {
2195 *   Vector<Number> c(
2196 *   matrix_free.get_dof_handler().get_triangulation().n_active_cells());
2197 *   Vector<Number> rho(
2198 *   matrix_free.get_dof_handler().get_triangulation().n_active_cells());
2199 *  
2200 *   for (const auto &cell : matrix_free.get_dof_handler()
2201 *   .get_triangulation()
2202 *   .active_cell_iterators())
2203 *   {
2204 *   c[cell->active_cell_index()] =
2205 *   materials.at(cell->material_id()).first;
2206 *   rho[cell->active_cell_index()] =
2207 *   materials.at(cell->material_id()).second;
2208 *   }
2209 *  
2210 *   c_r->gather_evaluate(c, EvaluationFlags::values);
2211 *   rho_r->gather_evaluate(rho, EvaluationFlags::values);
2212 *   }
2213 *  
2214 *  
2215 * @endcode
2216 *
2217 * Next, we set up the inverse mass operator and the acoustic
2218 * operator. Using `remote_value_type=VectorizedArray<Number>`
2219 * makes the operator use point-to-point interpolation. These two
2220 * objects are then used to create a `RungeKutta2` object to
2221 * perform the time integration.
2222 *
2223
2224 *
2225 * We also compute the maximum speed of sound, needed for the
2226 * computation of the time-step size, and then run the time integrator.
2227 * For the examples considered here, we found a limiting Courant number of
2228 * @f$\mathrm{Cr}\approx 0.36@f$ to maintain stability. To ensure, the
2229 * error of the temporal discretization is small, we use a considerably
2230 * smaller Courant number of @f$0.2@f$.
2231 *
2232 * @code
2233 *   const auto inverse_mass_operator =
2234 *   std::make_shared<InverseMassOperator<dim, Number>>(matrix_free);
2235 *  
2236 *   const auto acoustic_operator =
2237 *   std::make_shared<AcousticOperator<dim, Number, remote_value_type>>(
2238 *   matrix_free,
2239 *   material_data,
2240 *   non_matching_faces,
2241 *   pressure_r,
2242 *   velocity_r,
2243 *   c_r,
2244 *   rho_r);
2245 *  
2246 *   RungeKutta2<dim, Number, remote_value_type> time_integrator(
2247 *   inverse_mass_operator, acoustic_operator);
2248 *  
2249 *   double speed_of_sound_max = 0.0;
2250 *   for (const auto &mat : materials)
2251 *   speed_of_sound_max = std::max(speed_of_sound_max, mat.second.first);
2252 *  
2253 *  
2254 *   time_integrator.run(matrix_free,
2255 *   /*Cr*/ 0.2,
2256 *   end_time,
2257 *   speed_of_sound_max,
2258 *   initial_condition,
2259 *   vtk_prefix);
2260 *   }
2261 *  
2262 * @endcode
2263 *
2264 *
2265 * <a name="step_89-SetupandrunningoftheNitschetypemortaringscheme"></a>
2266 * <h4>Setup and running of the Nitsche-type mortaring scheme</h4>
2267 *
2268
2269 *
2270 * The alternative to the previous function is to use the mortaring
2271 * scheme -- implemented in the following function. This function
2272 * can only be run when deal.II is configured using CGAL (but the
2273 * previous function can still be used without CGAL), and so errors
2274 * out if CGAL is not available.
2275 *
2276 * @code
2277 *   template <int dim, typename Number>
2278 *   void run_with_nitsche_type_mortaring(
2279 *   const MatrixFree<dim, Number> &matrix_free,
2280 *   const std::set<types::boundary_id> &non_matching_faces,
2281 *   const std::map<types::material_id, std::pair<double, double>> &materials,
2282 *   const double end_time,
2283 *   const Function<dim> &initial_condition,
2284 *   const std::string &vtk_prefix)
2285 *   {
2286 *   #ifndef DEAL_II_WITH_CGAL
2287 *   (void)matrix_free;
2288 *   (void)non_matching_faces;
2289 *   (void)materials;
2290 *   (void)end_time;
2291 *   (void)initial_condition;
2292 *   (void)vtk_prefix;
2293 *  
2294 *   ConditionalOStream pcout(
2295 *   std::cout, (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0));
2296 *  
2297 *   pcout << "In this function, mortars are computed using CGAL. "
2298 *   "Configure deal.II with DEAL_II_WITH_CGAL to run this function.\n";
2299 *  
2300 *   return;
2301 *   #else
2302 *  
2303 *   const auto &dof_handler = matrix_free.get_dof_handler();
2304 *   const auto &tria = dof_handler.get_triangulation();
2305 *   const auto &mapping = *matrix_free.get_mapping_info().mapping;
2306 *   const auto n_quadrature_pnts = matrix_free.get_quadrature().size();
2307 *  
2308 *   std::vector<
2309 *   std::pair<types::boundary_id, std::function<std::vector<bool>()>>>
2310 *   non_matching_faces_marked_vertices;
2311 *  
2312 *   for (const auto &nm_face : non_matching_faces)
2313 *   {
2314 *   auto marked_vertices = [&]() {
2315 *   std::vector<bool> mask(tria.n_vertices(), true);
2316 *  
2317 *   for (const auto &cell : tria.active_cell_iterators())
2318 *   for (auto const &f : cell->face_indices())
2319 *   if (cell->face(f)->at_boundary() &&
2320 *   cell->face(f)->boundary_id() == nm_face)
2321 *   for (const auto v : cell->vertex_indices())
2322 *   mask[cell->vertex_index(v)] = false;
2323 *  
2324 *   return mask;
2325 *   };
2326 *  
2327 *   non_matching_faces_marked_vertices.emplace_back(
2328 *   std::make_pair(nm_face, marked_vertices));
2329 *   }
2330 *  
2331 * @endcode
2332 *
2333 * The only parts in this function that are functionally different
2334 * from the previous one follow here.
2335 *
2336
2337 *
2338 * First, quadrature points are arbitrarily distributed on each non-matching
2339 * face. Therefore, we have to make use of FEFacePointEvaluation.
2340 * FEFacePointEvaluation needs NonMatching::MappingInfo to work at the
2341 * correct quadrature points that are in sync with used FERemoteEvaluation
2342 * object. Using
2343 * `compute_remote_communicator_faces_nitsche_type_mortaring()` to reinit
2344 * NonMatching::MappingInfo ensures this. In the case of mortaring, we have
2345 * to use the weights provided by the quadrature rules that are used to set
2346 * up NonMatching::MappingInfo. Therefore we set the flag @c
2347 * use_global_weights.
2348 *
2349 * @code
2350 *   typename NonMatching::MappingInfo<dim, dim, Number>::AdditionalData
2351 *   additional_data;
2352 *   additional_data.use_global_weights = true;
2353 *  
2354 * @endcode
2355 *
2356 * Set up NonMatching::MappingInfo with needed update flags and
2357 * @c additional_data.
2358 *
2359 * @code
2360 *   auto nm_mapping_info =
2361 *   std::make_shared<NonMatching::MappingInfo<dim, dim, Number>>(
2362 *   mapping,
2363 *   update_values | update_JxW_values | update_normal_vectors |
2364 *   update_quadrature_points,
2365 *   additional_data);
2366 *  
2367 *   auto remote_communicator =
2368 *   Utilities::compute_remote_communicator_faces_nitsche_type_mortaring(
2369 *   matrix_free,
2370 *   non_matching_faces_marked_vertices,
2371 *   n_quadrature_pnts,
2372 *   0,
2373 *   nm_mapping_info.get());
2374 *  
2375 * @endcode
2376 *
2377 * Second, since quadrature points are arbitrarily distributed we
2378 * have to consider each face in a batch separately and can not
2379 * make use of @c VecorizedArray.
2380 *
2381 * @code
2382 *   using remote_value_type = Number;
2383 *  
2384 * @endcode
2385 *
2386 * The rest of the code is then identical to what we had in the
2387 * previous function (though it functions differently because of
2388 * the difference in `remote_value_type`).
2389 *
2390 * @code
2391 *   const auto pressure_r =
2392 *   std::make_shared<FERemoteEvaluation<dim, 1, remote_value_type>>(
2393 *   remote_communicator, dof_handler, /*first_selected_component*/ 0);
2394 *  
2395 *   const auto velocity_r =
2396 *   std::make_shared<FERemoteEvaluation<dim, dim, remote_value_type>>(
2397 *   remote_communicator, dof_handler, /*first_selected_component*/ 1);
2398 *  
2399 *   const auto material_data =
2400 *   std::make_shared<CellwiseMaterialData<Number>>(matrix_free, materials);
2401 *  
2402 *   const auto c_r =
2403 *   std::make_shared<FERemoteEvaluation<dim, 1, remote_value_type>>(
2404 *   remote_communicator,
2405 *   matrix_free.get_dof_handler().get_triangulation(),
2406 *   /*first_selected_component*/ 0);
2407 *   const auto rho_r =
2408 *   std::make_shared<FERemoteEvaluation<dim, 1, remote_value_type>>(
2409 *   remote_communicator,
2410 *   matrix_free.get_dof_handler().get_triangulation(),
2411 *   /*first_selected_component*/ 0);
2412 *  
2413 *   if (!material_data->is_homogeneous())
2414 *   {
2415 *   Vector<Number> c(
2416 *   matrix_free.get_dof_handler().get_triangulation().n_active_cells());
2417 *   Vector<Number> rho(
2418 *   matrix_free.get_dof_handler().get_triangulation().n_active_cells());
2419 *  
2420 *   for (const auto &cell : matrix_free.get_dof_handler()
2421 *   .get_triangulation()
2422 *   .active_cell_iterators())
2423 *   {
2424 *   c[cell->active_cell_index()] =
2425 *   materials.at(cell->material_id()).first;
2426 *   rho[cell->active_cell_index()] =
2427 *   materials.at(cell->material_id()).second;
2428 *   }
2429 *  
2430 *   c_r->gather_evaluate(c, EvaluationFlags::values);
2431 *   rho_r->gather_evaluate(rho, EvaluationFlags::values);
2432 *   }
2433 *  
2434 *   const auto inverse_mass_operator =
2435 *   std::make_shared<InverseMassOperator<dim, Number>>(matrix_free);
2436 *  
2437 *   const auto acoustic_operator =
2438 *   std::make_shared<AcousticOperator<dim, Number, remote_value_type>>(
2439 *   matrix_free,
2440 *   material_data,
2441 *   non_matching_faces,
2442 *   pressure_r,
2443 *   velocity_r,
2444 *   c_r,
2445 *   rho_r,
2446 *   nm_mapping_info);
2447 *  
2448 *   RungeKutta2<dim, Number, remote_value_type> time_integrator(
2449 *   inverse_mass_operator, acoustic_operator);
2450 *  
2451 *   double speed_of_sound_max = 0.0;
2452 *   for (const auto &mat : materials)
2453 *   speed_of_sound_max = std::max(speed_of_sound_max, mat.second.first);
2454 *  
2455 *   time_integrator.run(matrix_free,
2456 *   /*Cr*/ 0.2,
2457 *   end_time,
2458 *   speed_of_sound_max,
2459 *   initial_condition,
2460 *   vtk_prefix);
2461 *   #endif
2462 *   }
2463 *   } // namespace Step89
2464 *  
2465 *  
2466 * @endcode
2467 *
2468 *
2469 * <a name="step_89-main"></a>
2470 * <h3>main()</h3>
2471 *
2472
2473 *
2474 * Finally, the `main()` function executes the different versions of handling
2475 * non-matching interfaces.
2476 *
2477
2478 *
2479 * Similar to @ref step_87 "step-87", the minimum requirement of this tutorial is MPI.
2480 * The parallel::distributed::Triangulation class is used if deal.II is
2481 * configured with p4est. Otherwise parallel::shared::Triangulation is used.
2482 *
2483 * @code
2484 *   int main(int argc, char *argv[])
2485 *   {
2486 *   using namespace dealii;
2487 *   constexpr int dim = 2;
2488 *   using Number = double;
2489 *  
2490 *   Utilities::MPI::MPI_InitFinalize mpi(argc, argv);
2491 *   std::cout.precision(5);
2492 *   ConditionalOStream pcout(std::cout,
2493 *   (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) ==
2494 *   0));
2495 *  
2496 *   const unsigned int refinements = 1;
2497 *   const unsigned int degree = 3;
2498 *  
2499 *   #ifdef DEAL_II_WITH_P4EST
2500 *   parallel::distributed::Triangulation<dim> tria(MPI_COMM_WORLD);
2501 *   #else
2502 *   parallel::shared::Triangulation<dim> tria(MPI_COMM_WORLD);
2503 *   #endif
2504 *  
2505 *   pcout << "Create non-matching grid..." << std::endl;
2506 *  
2507 *   std::set<types::boundary_id> non_matching_faces;
2508 *   Step89::build_non_matching_triangulation(tria,
2509 *   non_matching_faces,
2510 *   refinements);
2511 *  
2512 *   pcout << " - Refinement level: " << refinements << std::endl;
2513 *   pcout << " - Number of cells: " << tria.n_cells() << std::endl;
2514 *  
2515 *   pcout << "Create DoFHandler..." << std::endl;
2516 *   DoFHandler<dim> dof_handler(tria);
2517 *   dof_handler.distribute_dofs(FESystem<dim>(FE_DGQ<dim>(degree) ^ (dim + 1)));
2518 *   pcout << " - Number of DoFs: " << dof_handler.n_dofs() << std::endl;
2519 *  
2520 *   AffineConstraints<Number> constraints;
2521 *   constraints.close();
2522 *  
2523 *   pcout << "Set up MatrixFree..." << std::endl;
2524 *   typename MatrixFree<dim, Number>::AdditionalData data;
2525 *   data.mapping_update_flags = update_gradients | update_values;
2526 *   data.mapping_update_flags_inner_faces = update_values;
2527 *   data.mapping_update_flags_boundary_faces =
2528 *   update_quadrature_points | update_values;
2529 *  
2530 *   MatrixFree<dim, Number> matrix_free;
2531 *   matrix_free.reinit(
2532 *   MappingQ1<dim>(), dof_handler, constraints, QGauss<dim>(degree + 1), data);
2533 *  
2534 *  
2535 * @endcode
2536 *
2537 *
2538 * <a name="step_89-RunvibratingmembranetestcaseHomogeneouspressure"></a>
2539 * <h4>Run vibrating membrane test case} Homogeneous pressure</h4>
2540 * Dirichlet boundary conditions are applied for
2541 * simplicity. Therefore, modes can not be chosen arbitrarily.
2542 *
2543 * @code
2544 *   pcout << "Run vibrating membrane test case..." << std::endl;
2545 *   const double modes = 10.0;
2546 *   std::map<types::material_id, std::pair<double, double>> homogeneous_material;
2547 *   homogeneous_material[numbers::invalid_material_id] = std::make_pair(1.0, 1.0);
2548 *   const auto initial_solution_membrane =
2549 *   Step89::InitialConditionVibratingMembrane<dim>(modes);
2550 *  
2551 *   /* Run vibrating membrane test case using point-to-point interpolation: */
2552 *   pcout << " - Point-to-point interpolation: " << std::endl;
2553 *   Step89::run_with_point_to_point_interpolation(
2554 *   matrix_free,
2555 *   non_matching_faces,
2556 *   homogeneous_material,
2557 *   8.0 * initial_solution_membrane.get_period_duration(
2558 *   homogeneous_material.begin()->second.first),
2559 *   initial_solution_membrane,
2560 *   "vm-p2p");
2561 *  
2562 *   /* Run vibrating membrane test case using Nitsche-type mortaring: */
2563 *   pcout << " - Nitsche-type mortaring: " << std::endl;
2564 *   Step89::run_with_nitsche_type_mortaring(
2565 *   matrix_free,
2566 *   non_matching_faces,
2567 *   homogeneous_material,
2568 *   8.0 * initial_solution_membrane.get_period_duration(
2569 *   homogeneous_material.begin()->second.first),
2570 *   initial_solution_membrane,
2571 *   "vm-nitsche");
2572 *  
2573 * @endcode
2574 *
2575 *
2576 * <a name="step_89-Runtestcasewithinhomogeneousmaterial"></a>
2577 * <h4>Run test case with inhomogeneous material</h4>
2578 * Run simple test case with inhomogeneous material and Nitsche-type
2579 * mortaring:
2580 *
2581 * @code
2582 *   pcout << "Run test case with inhomogeneous material..." << std::endl;
2583 *   std::map<types::material_id, std::pair<double, double>>
2584 *   inhomogeneous_material;
2585 *   inhomogeneous_material[0] = std::make_pair(1.0, 1.0);
2586 *   inhomogeneous_material[1] = std::make_pair(3.0, 1.0);
2587 *   Step89::run_with_nitsche_type_mortaring(matrix_free,
2588 *   non_matching_faces,
2589 *   inhomogeneous_material,
2590 *   /*runtime*/ 0.3,
2591 *   Step89::GaussPulse<dim>(0.3, 0.5),
2592 *   "inhomogeneous");
2593 *  
2594 *  
2595 *   return 0;
2596 *   }
2597 * @endcode
2598<a name="step_89-Results"></a><h1>Results</h1>
2599
2600
2601<a name="step_89-VibratingmembranePointtopointinterpolationvsNitschetypemortaring"></a><h3>Vibrating membrane: Point-to-point interpolation vs. Nitsche-type mortaring</h3>
2602
2603
2604We compare the results of the simulations after the last time step, i.e. at @f$t=8T@f$.
2605The @f$y@f$-component of the velocity field using Nitsche-type mortaring is depicted on the left.
2606The same field using point-to-point interpolation is depicted on the right.
2607
2608<table align="center" class="doxtable">
2609 <tr>
2610 <td>
2611 @image html https://www.dealii.org/images/steps/developer/step_89_membrane_test_case_mortaring_velocity_Y.png "" width=60%
2612 </td>
2613 <td>
2614 @image html https://www.dealii.org/images/steps/developer/step_89_membrane_test_case_point_to_point_velocity_Y.png "" width=60%
2615 </td>
2616 </tr>
2617</table>
2618
2619Besides this, the results for the pressure and the velocity in @f$y@f$ direction
2620are plotted along the horizontal line that spans from (0,0.69) to (1,0.69).
2621
2622<table align="center" class="doxtable">
2623 <tr>
2624 <td>
2625 @image html https://www.dealii.org/images/steps/developer/step_89_membrane_test_case_mortaring_vs_point_to_point_pressure.svg "" width=150%
2626 </td>
2627 <td>
2628 @image html https://www.dealii.org/images/steps/developer/step_89_membrane_test_case_mortaring_vs_point_to_point_velocity_Y.svg "" width=150%
2629 </td>
2630 </tr>
2631</table>
2632
2633While the results of the pressure are similar, @f$u_y@f$ clearly differs. At certain
2634positions we can see aliasing errors for the point-to-point interpolation.
2635For different mesh configurations and/or longer run times, the aliasing effects
2636of the point-to-point simulation accumulate and the simulation becomes instable.
2637To keep the tutorial short we have chosen one mesh that can be used for all
2638examples. For a configuration that yields instable results for a wide range of
2639polynomial degrees, see @cite heinz2022high.
2640
2641<a name="step_89-Wavepropagationthroughinhomogeneousfluid"></a><h3>Wave propagation through in-homogeneous fluid</h3>
2642
2643
2644The example that follows is just one example in which non-matching discretizations can be efficiently
2645used to reduce the number of DoFs. The example is nice, since results for a similar
2646test case are shown in multiple publications. As before, we slightly adapted the
2647test case to be able to use the same mesh for all simulations. The pressure field
2648at @f$t=0.3@f$ is depicted below.
2649
2650@image html https://www.dealii.org/images/steps/developer/step_89_inhomogenous_test_case_pressure.png "" width=30%
2651
2652As expected, we can easily see that the wave length in the right domain is roughly
2653three times times the wave length in the left domain. Hence, the wave can be
2654resolved with a coarser discretization.
2655
2656Using the same element size in the whole domain, we can compute a reference result.
2657The displayed reference result is obtained by choosing the same subdivision level
2658for both sub-domains, i.e. @c subdiv_right = 11. In this particular example the
2659reference result uses @f$92,928@f$ DoFs, while the non-matching result uses @f$52,608@f$ DoFs.
2660The pressure result is plotted along the horizontal line that spans from (0,0.5) to (1,0.5).
2661
2662@image html https://www.dealii.org/images/steps/developer/step_89_inhomogenous_test_case_conforming_vs_nonmatching.svg "" width=60%
2663
2664The results computed using the non-matching discretization are clearly in good agreement with
2665the reference result.
2666
2667<a name="step_89-Possibilitiesforextensions"></a><h3>Possibilities for extensions</h3>
2668
2669
2670All the implementations are done with overlapping triangulations in mind. In particular the
2671intersections in the mortaring case are constructed such that they are computed correctly
2672for overlapping triangulations. For this the intersection requests are of dimension @f$dim-1@f$.
2673The cells which are intersected with the intersection requests are of dimension @f$dim@f$. For the
2674simple case of non-conforming interfaces it would be sufficient to compute the intersections
2675between @f$dim-1@f$ and @f$dim-1@f$ entities. Furthermore, the lambda could be adapted, such that cells are
2676only marked if they are connected to a certain boundary ID (in this case, e.g., 99) instead of
2677marking every cell that is <i>not</i> connected to the opposite boundary ID (in this case, e.g., 98).
2678Marking fewer cells can reduce the setup costs significantly.
2679
2680Note that the use of inhomogeneous materials in this procedure is questionable, since it is not clear which
2681material is present in the overlapping part of the mesh.
2682 *
2683 *
2684<a name="step_89-PlainProg"></a>
2685<h1> The plain program</h1>
2686@include "step-89.cc"
2687*/
value_type get_value(const unsigned int q_point) const
T read_cell_data(const AlignedVector< T > &array) const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
Abstract base class for mapping classes.
Definition mapping.h:318
void reinit(const MappingType &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< number2 > &constraint, const QuadratureType &quad, const AdditionalData &additional_data=AdditionalData())
Definition point.h:111
const value_type get_value(const unsigned int q) const
Point< 2 > second
Definition grid_out.cc:4624
Point< 2 > first
Definition grid_out.cc:4623
__global__ void set(Number *val, const Number s, const size_type N)
#define Assert(cond, exc)
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
const Event initial
Definition event.cc:64
void write_vtu(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const VtkFlags &flags, std::ostream &out)
@ matrix
Contents is actually a matrix.
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:191
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
void free(T *&pointer)
Definition cuda.h:96
void interpolate(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Function< spacedim, typename VectorType::value_type > &function, VectorType &vec, 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)
bool check(const ConstraintKinds kind_in, const unsigned int dim)
int(& functions)(const void *v1, const void *v2)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
static constexpr double PI
Definition numbers.h:259
::VectorizedArray< Number, width > exp(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
unsigned int material_id
Definition types.h:167