15#ifndef dealii_quadrature_point_data_h
16#define dealii_quadrature_point_data_h
62template <
typename CellIteratorType,
typename DataType>
101 template <
typename T = DataType>
104 const unsigned int number_of_data_points_per_cell);
111 template <
typename T = DataType>
114 const CellIteratorType &cell_end,
115 const unsigned int number_of_data_points_per_cell);
127 erase(
const CellIteratorType &cell);
149 template <
typename T = DataType>
150 std::vector<std::shared_ptr<T>>
167 template <
typename T = DataType>
168 std::vector<std::shared_ptr<const T>>
187 template <
typename T = DataType>
188 std::optional<std::vector<std::shared_ptr<T>>>
207 template <
typename T = DataType>
208 std::optional<std::vector<std::shared_ptr<const T>>>
216 CellIteratorType::AccessorType::dimension;
222 CellIteratorType::AccessorType::space_dimension;
238 std::map<CellId, std::vector<std::shared_ptr<DataType>>>
map;
245 "Cell data is being retrieved with a type which is different than the type used to initialize it");
252 "The provided cell iterator does not belong to the triangulation that corresponds to the CellDataStorage object.");
323#ifdef DEAL_II_WITH_P4EST
326 namespace distributed
437 template <
int dim,
typename DataType>
442 std::is_base_of_v<TransferableQuadraturePointData, DataType>,
443 "User's DataType class should be derived from TransferableQuadraturePointData");
515 const boost::iterator_range<std::vector<char>::const_iterator>
599template <
typename CellIteratorType,
typename DataType>
603 const CellIteratorType &cell,
604 const unsigned int n_q_points)
606 static_assert(std::is_base_of_v<DataType, T>,
607 "User's T class should be derived from user's DataType class");
612 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
614 const auto key = cell->id();
615 if (map.find(key) == map.end())
617 map[key] = std::vector<std::shared_ptr<DataType>>(n_q_points);
621 const auto it = map.find(key);
622 for (
unsigned int q = 0; q < n_q_points; ++q)
623 it->second[q] = std::make_shared<T>();
629template <
typename CellIteratorType,
typename DataType>
633 const CellIteratorType &cell_start,
634 const CellIteratorType &cell_end,
635 const unsigned int number)
637 for (CellIteratorType it = cell_start;
it != cell_end; ++
it)
638 if (
it->is_locally_owned())
639 initialize<T>(it, number);
644template <
typename CellIteratorType,
typename DataType>
648 const auto key = cell->id();
649 const auto it = map.find(key);
652 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
653 for (
unsigned int i = 0; i <
it->second.size(); ++i)
656 it->second[i].unique(),
658 "Can not erase the cell data multiple objects reference its data."));
661 return (map.erase(key) == 1);
666template <
typename CellIteratorType,
typename DataType>
673 auto it = map.begin();
674 while (it != map.end())
677 for (
unsigned int i = 0; i <
it->second.size(); ++i)
680 it->second[i].unique(),
682 "Can not erase the cell data, multiple objects reference it."));
690template <
typename CellIteratorType,
typename DataType>
692inline std::vector<std::shared_ptr<T>>
694 const CellIteratorType &cell)
696 static_assert(std::is_base_of_v<DataType, T>,
697 "User's T class should be derived from user's DataType class");
698 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
700 const auto it = map.find(cell->id());
708 std::vector<std::shared_ptr<T>> res(
it->second.size());
709 for (
unsigned int q = 0; q < res.size(); ++q)
711 res[q] = std::dynamic_pointer_cast<T>(
it->second[q]);
712 Assert(res[q], ExcCellDataTypeMismatch());
719template <
typename CellIteratorType,
typename DataType>
721inline std::vector<std::shared_ptr<const T>>
723 const CellIteratorType &cell)
const
725 static_assert(std::is_base_of_v<DataType, T>,
726 "User's T class should be derived from user's DataType class");
727 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
729 const auto it = map.find(cell->id());
735 std::vector<std::shared_ptr<const T>> res(
it->second.size());
736 for (
unsigned int q = 0; q < res.size(); ++q)
738 res[q] = std::dynamic_pointer_cast<const T>(
it->second[q]);
739 Assert(res[q], ExcCellDataTypeMismatch());
744template <
typename CellIteratorType,
typename DataType>
746inline std::optional<std::vector<std::shared_ptr<T>>>
748 const CellIteratorType &cell)
750 static_assert(std::is_base_of_v<DataType, T>,
751 "User's T class should be derived from user's DataType class");
752 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
754 const auto it = map.find(cell->id());
761 std::vector<std::shared_ptr<T>> result(
it->second.size());
762 for (
unsigned int q = 0; q < result.size(); ++q)
764 result[q] = std::dynamic_pointer_cast<T>(
it->second[q]);
765 Assert(result[q], ExcCellDataTypeMismatch());
775template <
typename CellIteratorType,
typename DataType>
777inline std::optional<std::vector<std::shared_ptr<const T>>>
779 const CellIteratorType &cell)
const
781 static_assert(std::is_base_of_v<DataType, T>,
782 "User's T class should be derived from user's DataType class");
783 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
785 const auto it = map.find(cell->id());
792 std::vector<std::shared_ptr<const T>> result(
it->second.size());
793 for (
unsigned int q = 0; q < result.size(); ++q)
795 result[q] = std::dynamic_pointer_cast<const T>(
it->second[q]);
796 Assert(result[q], ExcCellDataTypeMismatch());
818template <
typename CellIteratorType,
typename DataType>
820pack_cell_data(
const CellIteratorType &cell,
824 static_assert(std::is_base_of_v<TransferableQuadraturePointData, DataType>,
825 "User's DataType class should be derived from QPData");
829 const unsigned int m = qpd->size();
831 const unsigned int n = (*qpd)[0]->number_of_values();
832 matrix_data.reinit(m, n);
834 std::vector<double> single_qp_data(n);
835 for (
unsigned int q = 0; q < m; ++q)
837 (*qpd)[q]->pack_values(single_qp_data);
840 for (
unsigned int i = 0; i < n; ++i)
841 matrix_data(q, i) = single_qp_data[i];
846 matrix_data.reinit({0, 0});
855template <
typename CellIteratorType,
typename DataType>
857unpack_to_cell_data(
const CellIteratorType &cell,
861 static_assert(std::is_base_of_v<TransferableQuadraturePointData, DataType>,
862 "User's DataType class should be derived from QPData");
866 const unsigned int n = values_at_qp.
n();
869 std::vector<double> single_qp_data(n);
872 for (
unsigned int q = 0; q < qpd->size(); ++q)
874 for (
unsigned int i = 0; i < n; ++i)
875 single_qp_data[i] = values_at_qp(q, i);
876 (*qpd)[q]->unpack_values(single_qp_data);
882# ifdef DEAL_II_WITH_P4EST
886 namespace distributed
888 template <
int dim,
typename DataType>
895 , data_size_in_bytes(0)
896 , n_q_points(rhs_quadrature.size())
897 , project_to_fe_matrix(projection_fe->n_dofs_per_cell(), n_q_points)
898 , project_to_qp_matrix(n_q_points, projection_fe->n_dofs_per_cell())
899 , handle(
numbers::invalid_unsigned_int)
900 , data_storage(nullptr)
906 "ContinuousQuadratureDataTransfer requires scalar FiniteElement"));
920 template <
int dim,
typename DataType>
927 Assert(data_storage ==
nullptr,
928 ExcMessage(
"This function can be called only once"));
930 data_storage = &data_storage_;
934 dim>::cell_iterator &cell,
936 return this->pack_function(cell, status);
943 template <
int dim,
typename DataType>
950 dim>::cell_iterator &cell,
952 const boost::iterator_range<std::vector<char>::const_iterator>
954 this->unpack_function(cell, status, data_range);
958 data_storage =
nullptr;
964 template <
int dim,
typename DataType>
965 inline std::vector<char>
971 pack_cell_data(cell, data_storage, matrix_quadrature);
974 const unsigned int number_of_values = matrix_quadrature.n();
975 matrix_dofs.reinit(project_to_fe_matrix.m(), number_of_values);
976 if (number_of_values > 0)
977 project_to_fe_matrix.mmult(matrix_dofs, matrix_quadrature);
984 template <
int dim,
typename DataType>
990 const boost::iterator_range<std::vector<char>::const_iterator>
998 Utilities::unpack<FullMatrix<double>>(data_range.begin(),
1001 const unsigned int number_of_values = matrix_dofs.n();
1002 if (number_of_values == 0)
1005 matrix_quadrature.reinit(n_q_points, number_of_values);
1007 if (cell->has_children())
1011 matrix_dofs_child.reinit(projection_fe->n_dofs_per_cell(),
1013 for (
unsigned int child = 0; child < cell->n_children(); ++child)
1014 if (cell->child(child)->is_locally_owned())
1017 ->get_prolongation_matrix(child, cell->refinement_case())
1018 .mmult(matrix_dofs_child, matrix_dofs);
1022 project_to_qp_matrix.mmult(matrix_quadrature,
1026 unpack_to_cell_data(cell->child(child),
1035 project_to_qp_matrix.mmult(matrix_quadrature, matrix_dofs);
1038 unpack_to_cell_data(cell, matrix_quadrature, data_storage);
@ children_will_be_coarsened
std::optional< std::vector< std::shared_ptr< const T > > > try_get_data(const CellIteratorType &cell) const
CellDataStorage()=default
void initialize(const CellIteratorType &cell, const unsigned int number_of_data_points_per_cell)
bool erase(const CellIteratorType &cell)
static constexpr unsigned int space_dimension
SmartPointer< const Triangulation< dimension, space_dimension >, CellDataStorage< CellIteratorType, DataType > > tria
std::vector< std::shared_ptr< const T > > get_data(const CellIteratorType &cell) const
void initialize(const CellIteratorType &cell_start, const CellIteratorType &cell_end, const unsigned int number_of_data_points_per_cell)
std::optional< std::vector< std::shared_ptr< T > > > try_get_data(const CellIteratorType &cell)
~CellDataStorage() override=default
std::map< CellId, std::vector< std::shared_ptr< DataType > > > map
std::vector< std::shared_ptr< T > > get_data(const CellIteratorType &cell)
static constexpr unsigned int dimension
virtual ~TransferableQuadraturePointData()=default
virtual unsigned int number_of_values() const =0
virtual void unpack_values(const std::vector< double > &values)=0
TransferableQuadraturePointData()=default
virtual void pack_values(std::vector< double > &values) const =0
Triangulation< dim, spacedim > & get_triangulation()
const std::unique_ptr< const FiniteElement< dim > > projection_fe
ContinuousQuadratureDataTransfer(const FiniteElement< dim > &projection_fe, const Quadrature< dim > &mass_quadrature, const Quadrature< dim > &data_quadrature)
std::size_t data_size_in_bytes
parallel::distributed::Triangulation< dim > * triangulation
typename parallel::distributed::Triangulation< dim >::cell_iterator CellIteratorType
std::vector< char > pack_function(const typename parallel::distributed::Triangulation< dim >::cell_iterator &cell, const CellStatus status)
FullMatrix< double > matrix_quadrature
FullMatrix< double > matrix_dofs
FullMatrix< double > project_to_qp_matrix
void prepare_for_coarsening_and_refinement(parallel::distributed::Triangulation< dim > &tria, CellDataStorage< CellIteratorType, DataType > &data_storage)
void unpack_function(const typename parallel::distributed::Triangulation< dim >::cell_iterator &cell, const CellStatus status, const boost::iterator_range< std::vector< char >::const_iterator > &data_range)
const unsigned int n_q_points
FullMatrix< double > matrix_dofs_child
FullMatrix< double > project_to_fe_matrix
CellDataStorage< CellIteratorType, DataType > * data_storage
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcCellDataTypeMismatch()
#define AssertDimension(dim1, dim2)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcTriangulationMismatch()
static ::ExceptionBase & ExcMessage(std::string arg1)
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator
size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation