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_start,
116 const unsigned int number_of_data_points_per_cell);
128 erase(
const CellIteratorType &cell);
150 template <
typename T = DataType>
151 std::vector<std::shared_ptr<T>>
168 template <
typename T = DataType>
169 std::vector<std::shared_ptr<const T>>
188 template <
typename T = DataType>
189 std::optional<std::vector<std::shared_ptr<T>>>
208 template <
typename T = DataType>
209 std::optional<std::vector<std::shared_ptr<const T>>>
217 CellIteratorType::AccessorType::dimension;
223 CellIteratorType::AccessorType::space_dimension;
239 std::map<CellId, std::vector<std::shared_ptr<DataType>>>
map;
246 "Cell data is being retrieved with a type which is different than the type used to initialize it");
253 "The provided cell iterator does not belong to the triangulation that corresponds to the CellDataStorage object.");
324#ifdef DEAL_II_WITH_P4EST
327 namespace distributed
438 template <
int dim,
typename DataType>
443 std::is_base_of_v<TransferableQuadraturePointData, DataType>,
444 "User's DataType class should be derived from TransferableQuadraturePointData");
516 const boost::iterator_range<std::vector<char>::const_iterator>
600template <
typename CellIteratorType,
typename DataType>
604 const CellIteratorType &cell,
605 const unsigned int n_q_points)
607 static_assert(std::is_base_of_v<DataType, T>,
608 "User's T class should be derived from user's DataType class");
612 tria = &cell->get_triangulation();
613 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
615 const auto key = cell->id();
616 if (map.find(key) == map.end())
618 map[key] = std::vector<std::shared_ptr<DataType>>(n_q_points);
622 const auto it = map.find(key);
623 for (
unsigned int q = 0; q < n_q_points; ++q)
624 it->second[q] = std::make_shared<T>();
630template <
typename CellIteratorType,
typename DataType>
634 const CellIteratorType &cell_start,
636 const unsigned int number)
638 for (CellIteratorType it = cell_start; it != cell_end; ++it)
639 if (it->is_locally_owned())
640 initialize<T>(it, number);
645template <
typename CellIteratorType,
typename DataType>
649 const auto key = cell->id();
650 const auto it = map.find(key);
653 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
654 for (
unsigned int i = 0; i < it->second.size(); ++i)
657 it->second[i].unique(),
659 "Can not erase the cell data multiple objects reference its data."));
662 return (map.erase(key) == 1);
667template <
typename CellIteratorType,
typename DataType>
674 auto it = map.begin();
675 while (it != map.end())
678 for (
unsigned int i = 0; i < it->second.size(); ++i)
681 it->second[i].unique(),
683 "Can not erase the cell data, multiple objects reference it."));
691template <
typename CellIteratorType,
typename DataType>
693inline std::vector<std::shared_ptr<T>>
695 const CellIteratorType &cell)
697 static_assert(std::is_base_of_v<DataType, T>,
698 "User's T class should be derived from user's DataType class");
699 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
701 const auto it = map.find(cell->id());
709 std::vector<std::shared_ptr<T>> res(it->second.size());
710 for (
unsigned int q = 0; q < res.size(); ++q)
712 res[q] = std::dynamic_pointer_cast<T>(it->second[q]);
713 Assert(res[q], ExcCellDataTypeMismatch());
720template <
typename CellIteratorType,
typename DataType>
722inline std::vector<std::shared_ptr<const T>>
724 const CellIteratorType &cell)
const
726 static_assert(std::is_base_of_v<DataType, T>,
727 "User's T class should be derived from user's DataType class");
728 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
730 const auto it = map.find(cell->id());
736 std::vector<std::shared_ptr<const T>> res(it->second.size());
737 for (
unsigned int q = 0; q < res.size(); ++q)
739 res[q] = std::dynamic_pointer_cast<const T>(it->second[q]);
740 Assert(res[q], ExcCellDataTypeMismatch());
745template <
typename CellIteratorType,
typename DataType>
747inline std::optional<std::vector<std::shared_ptr<T>>>
749 const CellIteratorType &cell)
751 static_assert(std::is_base_of_v<DataType, T>,
752 "User's T class should be derived from user's DataType class");
753 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
755 const auto it = map.find(cell->id());
762 std::vector<std::shared_ptr<T>> result(it->second.size());
763 for (
unsigned int q = 0; q < result.size(); ++q)
765 result[q] = std::dynamic_pointer_cast<T>(it->second[q]);
766 Assert(result[q], ExcCellDataTypeMismatch());
776template <
typename CellIteratorType,
typename DataType>
778inline std::optional<std::vector<std::shared_ptr<const T>>>
780 const CellIteratorType &cell)
const
782 static_assert(std::is_base_of_v<DataType, T>,
783 "User's T class should be derived from user's DataType class");
784 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
786 const auto it = map.find(cell->id());
793 std::vector<std::shared_ptr<const T>> result(it->second.size());
794 for (
unsigned int q = 0; q < result.size(); ++q)
796 result[q] = std::dynamic_pointer_cast<const T>(it->second[q]);
797 Assert(result[q], ExcCellDataTypeMismatch());
819template <
typename CellIteratorType,
typename DataType>
821pack_cell_data(
const CellIteratorType &cell,
825 static_assert(std::is_base_of_v<TransferableQuadraturePointData, DataType>,
826 "User's DataType class should be derived from QPData");
830 const unsigned int m = qpd->size();
832 const unsigned int n = (*qpd)[0]->number_of_values();
833 matrix_data.reinit(m, n);
835 std::vector<double> single_qp_data(n);
836 for (
unsigned int q = 0; q < m; ++q)
838 (*qpd)[q]->pack_values(single_qp_data);
841 for (
unsigned int i = 0; i < n; ++i)
842 matrix_data(q, i) = single_qp_data[i];
847 matrix_data.reinit({0, 0});
856template <
typename CellIteratorType,
typename DataType>
858unpack_to_cell_data(
const CellIteratorType &cell,
862 static_assert(std::is_base_of_v<TransferableQuadraturePointData, DataType>,
863 "User's DataType class should be derived from QPData");
867 const unsigned int n = values_at_qp.
n();
870 std::vector<double> single_qp_data(n);
873 for (
unsigned int q = 0; q < qpd->size(); ++q)
875 for (
unsigned int i = 0; i < n; ++i)
876 single_qp_data[i] = values_at_qp(q, i);
877 (*qpd)[q]->unpack_values(single_qp_data);
883# ifdef DEAL_II_WITH_P4EST
887 namespace distributed
889 template <
int dim,
typename DataType>
896 , data_size_in_bytes(0)
897 , n_q_points(rhs_quadrature.
size())
898 , project_to_fe_matrix(projection_fe->n_dofs_per_cell(), n_q_points)
899 , project_to_qp_matrix(n_q_points, projection_fe->n_dofs_per_cell())
900 , handle(
numbers::invalid_unsigned_int)
901 , data_storage(nullptr)
907 "ContinuousQuadratureDataTransfer requires scalar FiniteElement"));
921 template <
int dim,
typename DataType>
928 Assert(data_storage ==
nullptr,
929 ExcMessage(
"This function can be called only once"));
931 data_storage = &data_storage_;
935 dim>::cell_iterator &cell,
937 return this->pack_function(cell, status);
944 template <
int dim,
typename DataType>
951 dim>::cell_iterator &cell,
953 const boost::iterator_range<std::vector<char>::const_iterator>
955 this->unpack_function(cell, status, data_range);
959 data_storage =
nullptr;
965 template <
int dim,
typename DataType>
966 inline std::vector<char>
972 pack_cell_data(cell, data_storage, matrix_quadrature);
975 const unsigned int number_of_values = matrix_quadrature.n();
976 matrix_dofs.reinit(project_to_fe_matrix.m(), number_of_values);
977 if (number_of_values > 0)
978 project_to_fe_matrix.mmult(matrix_dofs, matrix_quadrature);
985 template <
int dim,
typename DataType>
991 const boost::iterator_range<std::vector<char>::const_iterator>
999 Utilities::unpack<FullMatrix<double>>(data_range.begin(),
1002 const unsigned int number_of_values = matrix_dofs.n();
1003 if (number_of_values == 0)
1006 matrix_quadrature.reinit(n_q_points, number_of_values);
1008 if (cell->has_children())
1012 matrix_dofs_child.reinit(projection_fe->n_dofs_per_cell(),
1014 for (
unsigned int child = 0; child < cell->n_children(); ++child)
1015 if (cell->child(child)->is_locally_owned())
1018 ->get_prolongation_matrix(child, cell->refinement_case())
1019 .mmult(matrix_dofs_child, matrix_dofs);
1023 project_to_qp_matrix.mmult(matrix_quadrature,
1027 unpack_to_cell_data(cell->child(child),
1036 project_to_qp_matrix.mmult(matrix_quadrature, matrix_dofs);
1039 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_start, const typename std_cxx20::type_identity< CellIteratorType >::type &cell_end, const unsigned int number_of_data_points_per_cell)
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
std::vector< std::shared_ptr< const T > > get_data(const CellIteratorType &cell) const
ObserverPointer< const Triangulation< dimension, space_dimension >, CellDataStorage< CellIteratorType, DataType > > tria
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
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