Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
fe_enriched.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2016 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_fe_enriched_h
17 #define dealii_fe_enriched_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/function.h>
22 #include <deal.II/base/quadrature.h>
24 
25 #include <deal.II/fe/fe.h>
26 #include <deal.II/fe/fe_nothing.h>
27 #include <deal.II/fe/fe_q.h>
28 #include <deal.II/fe/fe_system.h>
29 #include <deal.II/fe/fe_update_flags.h>
30 
31 #include <deal.II/hp/dof_handler.h>
32 #include <deal.II/hp/fe_collection.h>
33 
34 #include <map>
35 #include <numeric>
36 #include <utility>
37 #include <vector>
38 
39 DEAL_II_NAMESPACE_OPEN
40 
215 template <int dim, int spacedim = dim>
216 class FE_Enriched : public FiniteElement<dim, spacedim>
217 {
218 public:
227  const FiniteElement<dim, spacedim> &fe_enriched,
228  const Function<spacedim> * enrichment_function);
229 
241 
289  FE_Enriched(
290  const FiniteElement<dim, spacedim> * fe_base,
291  const std::vector<const FiniteElement<dim, spacedim> *> &fe_enriched,
292  const std::vector<std::vector<std::function<const Function<spacedim> *(
294  &functions);
295 
296 private:
303  FE_Enriched(
304  const std::vector<const FiniteElement<dim, spacedim> *> &fes,
305  const std::vector<unsigned int> & multiplicities,
306  const std::vector<std::vector<std::function<const Function<spacedim> *(
308  &functions);
309 
310 public:
311  virtual std::unique_ptr<FiniteElement<dim, spacedim>>
312  clone() const override;
313 
314  virtual UpdateFlags
315  requires_update_flags(const UpdateFlags update_flags) const override;
316 
320  virtual std::string
321  get_name() const override;
322 
329  virtual const FiniteElement<dim, spacedim> &
330  base_element(const unsigned int index) const override;
331 
340  virtual double
341  shape_value(const unsigned int i, const Point<dim> &p) const override;
342 
354  virtual const FullMatrix<double> &
356  const unsigned int child,
357  const RefinementCase<dim> &refinement_case =
359 
366  virtual const FullMatrix<double> &
368  const unsigned int child,
369  const RefinementCase<dim> &refinement_case =
371 
373 
385  virtual bool
386  hp_constraints_are_implemented() const override;
387 
400  virtual void
402  FullMatrix<double> &matrix) const override;
403 
416  virtual void
418  const unsigned int subface,
419  FullMatrix<double> &matrix) const override;
420 
436  virtual std::vector<std::pair<unsigned int, unsigned int>>
438  const FiniteElement<dim, spacedim> &fe_other) const override;
439 
444  virtual std::vector<std::pair<unsigned int, unsigned int>>
446  const FiniteElement<dim, spacedim> &fe_other) const override;
447 
452  virtual std::vector<std::pair<unsigned int, unsigned int>>
454  const FiniteElement<dim, spacedim> &fe_other) const override;
455 
461  const unsigned int codim = 0) const override final;
462 
464 
465 
469  const std::vector<std::vector<std::function<const Function<spacedim> *(
471  get_enrichments() const;
472 
477  get_fe_system() const;
478 
479 protected:
484  class InternalData : public FiniteElement<dim, spacedim>::InternalDataBase
485  {
486  public:
493  {
494  std::vector<double> values;
495  std::vector<Tensor<1, spacedim>> gradients;
496  std::vector<SymmetricTensor<2, spacedim>> hessians;
497  };
498 
509  InternalData(std::unique_ptr<typename FESystem<dim, spacedim>::InternalData>
510  fesystem_data);
511 
517  get_fe_data(const unsigned int base_no) const;
518 
525  get_fe_output_object(const unsigned int base_no) const;
526 
531  std::unique_ptr<typename FESystem<dim, spacedim>::InternalData>
533 
549  mutable std::vector<std::vector<EnrichmentValues>> enrichment;
550  };
551 
558  std::vector<std::vector<std::vector<unsigned int>>>
560 
568  const std::vector<std::vector<std::function<const Function<spacedim> *(
571 
581  const bool is_enriched;
582 
593  template <int dim_1>
594  std::unique_ptr<typename FiniteElement<dim, spacedim>::InternalDataBase>
595  setup_data(
596  std::unique_ptr<typename FESystem<dim, spacedim>::InternalData> fes_data,
597  const UpdateFlags flags,
598  const Quadrature<dim_1> &quadrature) const;
599 
606  virtual std::unique_ptr<
608  get_data(
609  const UpdateFlags flags,
610  const Mapping<dim, spacedim> &mapping,
611  const Quadrature<dim> & quadrature,
613  spacedim>
614  &output_data) const override;
615 
616  virtual std::unique_ptr<
619  const UpdateFlags update_flags,
620  const Mapping<dim, spacedim> &mapping,
621  const Quadrature<dim - 1> & quadrature,
623  spacedim>
624  &output_data) const override;
625 
626  virtual std::unique_ptr<
629  const UpdateFlags update_flags,
630  const Mapping<dim, spacedim> &mapping,
631  const Quadrature<dim - 1> & quadrature,
633  spacedim>
634  &output_data) const override;
635 
636  virtual void
637  fill_fe_values(
638  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
639  const CellSimilarity::Similarity cell_similarity,
640  const Quadrature<dim> & quadrature,
641  const Mapping<dim, spacedim> & mapping,
642  const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
643  const ::internal::FEValuesImplementation::MappingRelatedData<dim,
644  spacedim>
645  & mapping_data,
646  const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
648  spacedim>
649  &output_data) const override;
650 
651  virtual void
652  fill_fe_face_values(
653  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
654  const unsigned int face_no,
655  const Quadrature<dim - 1> & quadrature,
656  const Mapping<dim, spacedim> & mapping,
657  const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
658  const ::internal::FEValuesImplementation::MappingRelatedData<dim,
659  spacedim>
660  & mapping_data,
661  const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
663  spacedim>
664  &output_data) const override;
665 
666  virtual void
667  fill_fe_subface_values(
668  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
669  const unsigned int face_no,
670  const unsigned int sub_no,
671  const Quadrature<dim - 1> & quadrature,
672  const Mapping<dim, spacedim> & mapping,
673  const typename Mapping<dim, spacedim>::InternalDataBase &mapping_internal,
674  const ::internal::FEValuesImplementation::MappingRelatedData<dim,
675  spacedim>
676  & mapping_data,
677  const typename FiniteElement<dim, spacedim>::InternalDataBase &fe_internal,
679  spacedim>
680  &output_data) const override;
681 
682 private:
687  void
688  initialize(const std::vector<const FiniteElement<dim, spacedim> *> &fes,
689  const std::vector<unsigned int> &multiplicities);
690 
694  const std::unique_ptr<const FESystem<dim, spacedim>> fe_system;
695 
701  template <int dim_1>
702  void
704  const Quadrature<dim_1> &quadrature,
705  const InternalData & fe_data,
707  & mapping_data,
708  const typename Triangulation<dim, spacedim>::cell_iterator &cell,
710  &output_data) const;
711 };
712 
713 
714 
725 namespace ColorEnriched
726 {
734  template <int dim, int spacedim = dim>
735  using predicate_function = std::function<bool(
737 
738  namespace internal
739  {
786  template <int dim, int spacedim>
787  bool
788  find_connection_between_subdomains(
789  const hp::DoFHandler<dim, spacedim> & dof_handler,
790  const predicate_function<dim, spacedim> &predicate_1,
791  const predicate_function<dim, spacedim> &predicate_2);
792 
805  template <int dim, int spacedim>
806  unsigned int
807  color_predicates(
808  const hp::DoFHandler<dim, spacedim> & dof_handler,
809  const std::vector<predicate_function<dim, spacedim>> &predicates,
810  std::vector<unsigned int> & predicate_colors);
811 
852  template <int dim, int spacedim>
853  void
854  set_cellwise_color_set_and_fe_index(
855  hp::DoFHandler<dim, spacedim> & dof_handler,
856  const std::vector<predicate_function<dim, spacedim>> &predicates,
857  const std::vector<unsigned int> & predicate_colors,
858  std::map<unsigned int, std::map<unsigned int, unsigned int>>
859  & cellwise_color_predicate_map,
860  std::vector<std::set<unsigned int>> &fe_sets);
861 
885  template <int dim, int spacedim>
886  void
887  make_colorwise_enrichment_functions(
888  const unsigned int n_colors,
889  const std::vector<std::shared_ptr<Function<spacedim>>> &enrichments,
890  const std::map<unsigned int, std::map<unsigned int, unsigned int>>
891  &cellwise_color_predicate_map,
892  std::vector<std::function<const Function<spacedim> *(
894  &color_enrichments);
895 
896 
911  template <int dim, int spacedim>
912  void
913  make_fe_collection_from_colored_enrichments(
914  const unsigned int n_colors,
915  const std::vector<std::set<unsigned int>>
916  &fe_sets, // total list of color sets possible
917  const std::vector<std::function<const Function<spacedim> *(
919  &color_enrichments, // color wise enrichment functions
920  const FiniteElement<dim, spacedim> &fe_base, // basic FE element
922  &fe_enriched, // FE multiplied by enrichment function
923  const FE_Nothing<dim, spacedim> &fe_nothing,
924  hp::FECollection<dim, spacedim> &fe_collection);
925  } // namespace internal
926 
927 
928 
1097  template <int dim, int spacedim = dim>
1098  struct Helper
1099  {
1112  const std::vector<predicate_function<dim, spacedim>> & predicates,
1113  const std::vector<std::shared_ptr<Function<spacedim>>> &enrichments);
1114 
1126 
1127  private:
1133 
1139 
1145 
1152 
1158  const std::vector<predicate_function<dim, spacedim>> predicates;
1159 
1165  const std::vector<std::shared_ptr<Function<spacedim>>> enrichments;
1166 
1176  using cell_iterator_function = std::function<const Function<spacedim> *(
1178 
1188  std::vector<cell_iterator_function> color_enrichments;
1189 
1195  std::vector<unsigned int> predicate_colors;
1196 
1200  unsigned int n_colors;
1201 
1207  std::map<unsigned int, std::map<unsigned int, unsigned int>>
1209 
1214  std::vector<std::set<unsigned int>> fe_sets;
1215  };
1216 } // namespace ColorEnriched
1217 
1218 DEAL_II_NAMESPACE_CLOSE
1219 
1220 #endif // dealii_fe_enriched_h
virtual FiniteElementDomination::Domination compare_for_domination(const FiniteElement< dim, spacedim > &fe_other, const unsigned int codim=0) const override final
Definition: fe_enriched.cc:981
virtual const FiniteElement< dim, spacedim > & base_element(const unsigned int index) const override
Definition: fe_enriched.cc:507
const std::vector< std::vector< std::function< const Function< spacedim > *(const typename Triangulation< dim, spacedim >::cell_iterator &)> > > get_enrichments() const
Definition: fe_enriched.cc:263
virtual std::vector< std::pair< unsigned int, unsigned int > > hp_line_dof_identities(const FiniteElement< dim, spacedim > &fe_other) const override
Definition: fe_enriched.cc:945
virtual void get_face_interpolation_matrix(const FiniteElement< dim, spacedim > &source, FullMatrix< double > &matrix) const override
Definition: fe_enriched.cc:881
virtual const FullMatrix< double > & get_restriction_matrix(const unsigned int child, const RefinementCase< dim > &refinement_case=RefinementCase< dim >::isotropic_refinement) const override
InternalData(std::unique_ptr< typename FESystem< dim, spacedim >::InternalData > fesystem_data)
FE_Enriched(const FiniteElement< dim, spacedim > &fe_base, const FiniteElement< dim, spacedim > &fe_enriched, const Function< spacedim > *enrichment_function)
Definition: fe_enriched.cc:146
void initialize(const std::vector< const FiniteElement< dim, spacedim > *> &fes, const std::vector< unsigned int > &multiplicities)
Definition: fe_enriched.cc:425
const FiniteElement< dim, spacedim > & fe_enriched
Definition: fe_enriched.h:1144
internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > & get_fe_output_object(const unsigned int base_no) const
const hp::FECollection< dim, spacedim > & build_fe_collection(hp::DoFHandler< dim, spacedim > &dof_handler)
std::vector< std::vector< EnrichmentValues > > enrichment
Definition: fe_enriched.h:549
unsigned int n_colors
Definition: fe_enriched.h:1200
std::function< bool(const typename Triangulation< dim, spacedim >::cell_iterator &)> predicate_function
Definition: fe_enriched.h:736
hp::FECollection< dim, spacedim > fe_collection
Definition: fe_enriched.h:1132
void multiply_by_enrichment(const Quadrature< dim_1 > &quadrature, const InternalData &fe_data, const internal::FEValuesImplementation::MappingRelatedData< dim, spacedim > &mapping_data, const typename Triangulation< dim, spacedim >::cell_iterator &cell, internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const
Definition: fe_enriched.cc:623
const bool is_enriched
Definition: fe_enriched.h:581
virtual std::vector< std::pair< unsigned int, unsigned int > > hp_vertex_dof_identities(const FiniteElement< dim, spacedim > &fe_other) const override
Definition: fe_enriched.cc:927
virtual std::string get_name() const override
Definition: fe_enriched.cc:486
const std::vector< std::vector< std::function< const Function< spacedim > *(const typename Triangulation< dim, spacedim >::cell_iterator &)> > > enrichments
Definition: fe_enriched.h:570
const FESystem< dim, spacedim > & get_fe_system() const
Definition: fe_enriched.cc:865
std::unique_ptr< typename FESystem< dim, spacedim >::InternalData > fesystem_data
Definition: fe_enriched.h:532
const std::unique_ptr< const FESystem< dim, spacedim > > fe_system
Definition: fe_enriched.h:694
UpdateFlags
FiniteElement< dim, spacedim >::InternalDataBase & get_fe_data(const unsigned int base_no) const
Abstract base class for mapping classes.
Definition: dof_tools.h:57
Definition: fe.h:44
Helper(const FiniteElement< dim, spacedim > &fe_base, const FiniteElement< dim, spacedim > &fe_enriched, const std::vector< predicate_function< dim, spacedim >> &predicates, const std::vector< std::shared_ptr< Function< spacedim >>> &enrichments)
std::vector< std::set< unsigned int > > fe_sets
Definition: fe_enriched.h:1214
std::vector< unsigned int > predicate_colors
Definition: fe_enriched.h:1195
virtual std::unique_ptr< typename FiniteElement< dim, spacedim >::InternalDataBase > get_subface_data(const UpdateFlags update_flags, const Mapping< dim, spacedim > &mapping, const Quadrature< dim - 1 > &quadrature, ::internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const override
Definition: fe_enriched.cc:387
virtual double shape_value(const unsigned int i, const Point< dim > &p) const override
Definition: fe_enriched.cc:271
virtual UpdateFlags requires_update_flags(const UpdateFlags update_flags) const override
Definition: fe_enriched.cc:302
const FiniteElement< dim, spacedim > & fe_base
Definition: fe_enriched.h:1138
const std::vector< predicate_function< dim, spacedim > > predicates
Definition: fe_enriched.h:1158
virtual const FullMatrix< double > & get_prolongation_matrix(const unsigned int child, const RefinementCase< dim > &refinement_case=RefinementCase< dim >::isotropic_refinement) const override
virtual void get_subface_interpolation_matrix(const FiniteElement< dim, spacedim > &source, const unsigned int subface, FullMatrix< double > &matrix) const override
Definition: fe_enriched.cc:903
virtual std::unique_ptr< typename FiniteElement< dim, spacedim >::InternalDataBase > get_data(const UpdateFlags flags, const Mapping< dim, spacedim > &mapping, const Quadrature< dim > &quadrature, ::internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const override
Definition: fe_enriched.cc:407
std::vector< std::vector< std::vector< unsigned int > > > base_no_mult_local_enriched_dofs
Definition: fe_enriched.h:559
std::vector< cell_iterator_function > color_enrichments
Definition: fe_enriched.h:1188
std::function< const Function< spacedim > *(const typename Triangulation< dim, spacedim >::cell_iterator &)> cell_iterator_function
Definition: fe_enriched.h:1177
std::unique_ptr< typename FiniteElement< dim, spacedim >::InternalDataBase > setup_data(std::unique_ptr< typename FESystem< dim, spacedim >::InternalData > fes_data, const UpdateFlags flags, const Quadrature< dim_1 > &quadrature) const
Definition: fe_enriched.cc:326
virtual std::unique_ptr< FiniteElement< dim, spacedim > > clone() const override
Definition: fe_enriched.cc:284
std::map< unsigned int, std::map< unsigned int, unsigned int > > cellwise_color_predicate_map
Definition: fe_enriched.h:1208
virtual std::vector< std::pair< unsigned int, unsigned int > > hp_quad_dof_identities(const FiniteElement< dim, spacedim > &fe_other) const override
Definition: fe_enriched.cc:963
const std::vector< std::shared_ptr< Function< spacedim > > > enrichments
Definition: fe_enriched.h:1165
const FE_Nothing< dim, spacedim > fe_nothing
Definition: fe_enriched.h:1151
virtual bool hp_constraints_are_implemented() const override
Definition: fe_enriched.cc:873
virtual std::unique_ptr< typename FiniteElement< dim, spacedim >::InternalDataBase > get_face_data(const UpdateFlags update_flags, const Mapping< dim, spacedim > &mapping, const Quadrature< dim - 1 > &quadrature, ::internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const override
Definition: fe_enriched.cc:368