13#ifndef dealii_quadrature_point_data_h
14#define dealii_quadrature_point_data_h
60template <
typename CellIteratorType,
typename DataType>
99 template <
typename T = DataType>
102 const unsigned int number_of_data_points_per_cell);
109 template <
typename T = DataType>
112 const CellIteratorType &cell_start,
114 const unsigned int number_of_data_points_per_cell);
126 erase(
const CellIteratorType &cell);
148 template <
typename T = DataType>
149 std::vector<std::shared_ptr<T>>
166 template <
typename T = DataType>
167 std::vector<std::shared_ptr<const T>>
186 template <
typename T = DataType>
187 std::optional<std::vector<std::shared_ptr<T>>>
206 template <
typename T = DataType>
207 std::optional<std::vector<std::shared_ptr<const T>>>
215 CellIteratorType::AccessorType::dimension;
221 CellIteratorType::AccessorType::space_dimension;
237 std::map<CellId, std::vector<std::shared_ptr<DataType>>>
map;
244 "Cell data is being retrieved with a type which is different than the type used to initialize it");
251 "The provided cell iterator does not belong to the triangulation that corresponds to the CellDataStorage object.");
322#ifdef DEAL_II_WITH_P4EST
325 namespace distributed
436 template <
int dim,
typename DataType>
441 std::is_base_of_v<TransferableQuadraturePointData, DataType>,
442 "User's DataType class should be derived from TransferableQuadraturePointData");
514 const boost::iterator_range<std::vector<char>::const_iterator>
598template <
typename CellIteratorType,
typename DataType>
602 const CellIteratorType &cell,
603 const unsigned int n_q_points)
605 static_assert(std::is_base_of_v<DataType, T>,
606 "User's T class should be derived from user's DataType class");
610 tria = &cell->get_triangulation();
611 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
613 const auto key = cell->id();
614 if (map.find(key) == map.end())
616 map[key] = std::vector<std::shared_ptr<DataType>>(n_q_points);
620 const auto it = map.find(key);
621 for (
unsigned int q = 0; q < n_q_points; ++q)
622 it->second[q] = std::make_shared<T>();
628template <
typename CellIteratorType,
typename DataType>
632 const CellIteratorType &cell_start,
634 const unsigned int number)
636 for (CellIteratorType it = cell_start; it != cell_end; ++it)
637 if (it->is_locally_owned())
638 initialize<T>(it, number);
643template <
typename CellIteratorType,
typename DataType>
647 const auto key = cell->id();
648 const auto it = map.find(key);
651 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
652 for (
unsigned int i = 0; i < it->second.size(); ++i)
655 it->second[i].use_count() == 1,
657 "Can not erase the cell data multiple objects reference its data."));
660 return (map.erase(key) == 1);
665template <
typename CellIteratorType,
typename DataType>
672 auto it = map.begin();
673 while (it != map.end())
676 for (
unsigned int i = 0; i < it->second.size(); ++i)
679 it->second[i].use_count() == 1,
681 "Can not erase the cell data, multiple objects reference it."));
689template <
typename CellIteratorType,
typename DataType>
691inline std::vector<std::shared_ptr<T>>
693 const CellIteratorType &cell)
695 static_assert(std::is_base_of_v<DataType, T>,
696 "User's T class should be derived from user's DataType class");
697 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
699 const auto it = map.find(cell->id());
707 std::vector<std::shared_ptr<T>> res(it->second.size());
708 for (
unsigned int q = 0; q < res.size(); ++q)
710 res[q] = std::dynamic_pointer_cast<T>(it->second[q]);
711 Assert(res[q], ExcCellDataTypeMismatch());
718template <
typename CellIteratorType,
typename DataType>
720inline std::vector<std::shared_ptr<const T>>
722 const CellIteratorType &cell)
const
724 static_assert(std::is_base_of_v<DataType, T>,
725 "User's T class should be derived from user's DataType class");
726 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
728 const auto it = map.find(cell->id());
734 std::vector<std::shared_ptr<const T>> res(it->second.size());
735 for (
unsigned int q = 0; q < res.size(); ++q)
737 res[q] = std::dynamic_pointer_cast<const T>(it->second[q]);
738 Assert(res[q], ExcCellDataTypeMismatch());
743template <
typename CellIteratorType,
typename DataType>
745inline std::optional<std::vector<std::shared_ptr<T>>>
747 const CellIteratorType &cell)
749 static_assert(std::is_base_of_v<DataType, T>,
750 "User's T class should be derived from user's DataType class");
751 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
753 const auto it = map.find(cell->id());
760 std::vector<std::shared_ptr<T>> result(it->second.size());
761 for (
unsigned int q = 0; q < result.size(); ++q)
763 result[q] = std::dynamic_pointer_cast<T>(it->second[q]);
764 Assert(result[q], ExcCellDataTypeMismatch());
774template <
typename CellIteratorType,
typename DataType>
776inline std::optional<std::vector<std::shared_ptr<const T>>>
778 const CellIteratorType &cell)
const
780 static_assert(std::is_base_of_v<DataType, T>,
781 "User's T class should be derived from user's DataType class");
782 Assert(&cell->get_triangulation() == tria, ExcTriangulationMismatch());
784 const auto it = map.find(cell->id());
791 std::vector<std::shared_ptr<const T>> result(it->second.size());
792 for (
unsigned int q = 0; q < result.size(); ++q)
794 result[q] = std::dynamic_pointer_cast<const T>(it->second[q]);
795 Assert(result[q], ExcCellDataTypeMismatch());
817template <
typename CellIteratorType,
typename DataType>
819pack_cell_data(
const CellIteratorType &cell,
823 static_assert(std::is_base_of_v<TransferableQuadraturePointData, DataType>,
824 "User's DataType class should be derived from QPData");
828 const unsigned int m = qpd->size();
830 const unsigned int n = (*qpd)[0]->number_of_values();
831 matrix_data.reinit(m, n);
833 std::vector<double> single_qp_data(n);
834 for (
unsigned int q = 0; q < m; ++q)
836 (*qpd)[q]->pack_values(single_qp_data);
839 for (
unsigned int i = 0; i < n; ++i)
840 matrix_data(q, i) = single_qp_data[i];
845 matrix_data.reinit({0, 0});
854template <
typename CellIteratorType,
typename DataType>
856unpack_to_cell_data(
const CellIteratorType &cell,
860 static_assert(std::is_base_of_v<TransferableQuadraturePointData, DataType>,
861 "User's DataType class should be derived from QPData");
865 const unsigned int n = values_at_qp.
n();
868 std::vector<double> single_qp_data(n);
871 for (
unsigned int q = 0; q < qpd->size(); ++q)
873 for (
unsigned int i = 0; i < n; ++i)
874 single_qp_data[i] = values_at_qp(q, i);
875 (*qpd)[q]->unpack_values(single_qp_data);
881# ifdef DEAL_II_WITH_P4EST
885 namespace distributed
887 template <
int dim,
typename DataType>
894 , data_size_in_bytes(0)
895 , n_q_points(rhs_quadrature.
size())
896 , project_to_fe_matrix(projection_fe->n_dofs_per_cell(), n_q_points)
897 , project_to_qp_matrix(n_q_points, projection_fe->n_dofs_per_cell())
899 , data_storage(nullptr)
900 , triangulation(nullptr)
905 "ContinuousQuadratureDataTransfer requires scalar FiniteElement"));
919 template <
int dim,
typename DataType>
926 Assert(data_storage ==
nullptr,
927 ExcMessage(
"This function can be called only once"));
928 triangulation = &tr_;
929 data_storage = &data_storage_;
931 handle = triangulation->register_data_attach(
933 dim>::cell_iterator &cell,
935 return this->pack_function(cell, status);
942 template <
int dim,
typename DataType>
946 triangulation->notify_ready_to_unpack(
949 dim>::cell_iterator &cell,
951 const boost::iterator_range<std::vector<char>::const_iterator>
953 this->unpack_function(cell, status, data_range);
957 data_storage =
nullptr;
958 triangulation =
nullptr;
963 template <
int dim,
typename DataType>
964 inline std::vector<char>
970 pack_cell_data(cell, data_storage, matrix_quadrature);
973 const unsigned int number_of_values = matrix_quadrature.n();
974 matrix_dofs.reinit(project_to_fe_matrix.m(), number_of_values);
975 if (number_of_values > 0)
976 project_to_fe_matrix.mmult(matrix_dofs, matrix_quadrature);
983 template <
int dim,
typename DataType>
989 const boost::iterator_range<std::vector<char>::const_iterator>
997 Utilities::unpack<FullMatrix<double>>(data_range.begin(),
1000 const unsigned int number_of_values = matrix_dofs.n();
1001 if (number_of_values == 0)
1004 matrix_quadrature.reinit(n_q_points, number_of_values);
1006 if (cell->has_children())
1010 matrix_dofs_child.reinit(projection_fe->n_dofs_per_cell(),
1012 for (
unsigned int child = 0; child < cell->n_children(); ++child)
1013 if (cell->child(child)->is_locally_owned())
1016 ->get_prolongation_matrix(child, cell->refinement_case())
1017 .mmult(matrix_dofs_child, matrix_dofs);
1021 project_to_qp_matrix.mmult(matrix_quadrature,
1025 unpack_to_cell_data(cell->child(child),
1034 project_to_qp_matrix.mmult(matrix_quadrature, matrix_dofs);
1037 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
* * * * std::vector< Number > ThermoPlasticMaterial< dim, ViscoplasticYieldLaw, Number >::get_state_parameters const
std::size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
constexpr unsigned int invalid_unsigned_int