16 #ifndef dealii_quadrature_point_data_h 17 #define dealii_quadrature_point_data_h 19 #include <deal.II/base/config.h> 21 #include <deal.II/base/quadrature.h> 22 #include <deal.II/base/subscriptor.h> 24 #include <deal.II/distributed/tria.h> 26 #include <deal.II/fe/fe.h> 27 #include <deal.II/fe/fe_tools.h> 29 #include <deal.II/grid/tria.h> 30 #include <deal.II/grid/tria_accessor.h> 32 #include <deal.II/lac/vector.h> 35 #include <type_traits> 38 DEAL_II_NAMESPACE_OPEN
58 template <
typename CellIteratorType,
typename DataType>
93 template <
typename T = DataType>
96 const unsigned int number_of_data_points_per_cell);
103 template <
typename T = DataType>
105 initialize(
const CellIteratorType &cell_start,
106 const CellIteratorType &cell_end,
107 const unsigned int number_of_data_points_per_cell);
119 erase(
const CellIteratorType &cell);
138 template <
typename T = DataType>
139 std::vector<std::shared_ptr<T>>
140 get_data(
const CellIteratorType &cell);
153 template <
typename T = DataType>
154 std::vector<std::shared_ptr<const T>>
155 get_data(
const CellIteratorType &cell)
const;
161 std::map<CellIteratorType, std::vector<std::shared_ptr<DataType>>>
map;
202 number_of_values()
const = 0;
215 pack_values(std::vector<double> &values)
const = 0;
226 unpack_values(
const std::vector<double> &values) = 0;
230 #ifdef DEAL_II_WITH_P4EST 233 namespace distributed
346 template <
int dim,
typename DataType>
351 std::is_base_of<TransferableQuadraturePointData, DataType>::value,
352 "User's DataType class should be derived from TransferableQuadraturePointData");
390 prepare_for_coarsening_and_refinement(
417 const typename parallel::distributed::Triangulation<dim>::CellStatus
429 const typename parallel::distributed::Triangulation<dim>::CellStatus
431 const boost::iterator_range<std::vector<char>::const_iterator>
515 template <
typename CellIteratorType,
typename DataType>
516 template <
typename T>
520 const unsigned int n_q_points)
522 static_assert(std::is_base_of<DataType, T>::value,
523 "User's T class should be derived from user's DataType class");
525 if (
map.find(cell) ==
map.end())
527 map[cell] = std::vector<std::shared_ptr<DataType>>(n_q_points);
531 auto it =
map.find(cell);
532 for (
unsigned int q = 0; q < n_q_points; q++)
533 it->second[q] = std::make_shared<T>();
539 template <
typename CellIteratorType,
typename DataType>
540 template <
typename T>
545 const unsigned int number)
548 if (it->is_locally_owned())
549 initialize<T>(it, number);
554 template <
typename CellIteratorType,
typename DataType>
558 const auto it =
map.find(cell);
559 for (
unsigned int i = 0; i < it->second.size(); i++)
562 it->second[i].unique(),
564 "Can not erase the cell data multiple objects reference its data."));
567 return (
map.erase(cell) == 1);
572 template <
typename CellIteratorType,
typename DataType>
579 auto it =
map.begin();
580 while (it !=
map.end())
583 for (
unsigned int i = 0; i < it->second.size(); i++)
586 it->second[i].unique(),
588 "Can not erase the cell data, multiple objects reference it."));
596 template <
typename CellIteratorType,
typename DataType>
597 template <
typename T>
598 std::vector<std::shared_ptr<T>>
602 static_assert(std::is_base_of<DataType, T>::value,
603 "User's T class should be derived from user's DataType class");
605 auto it =
map.find(cell);
613 std::vector<std::shared_ptr<T>> res(it->second.size());
614 for (
unsigned int q = 0; q < res.size(); q++)
615 res[q] = std::dynamic_pointer_cast<T>(it->second[q]);
621 template <
typename CellIteratorType,
typename DataType>
622 template <
typename T>
623 std::vector<std::shared_ptr<const T>>
627 static_assert(std::is_base_of<DataType, T>::value,
628 "User's T class should be derived from user's DataType class");
630 auto it =
map.find(cell);
636 std::vector<std::shared_ptr<const T>> res(it->second.size());
637 for (
unsigned int q = 0; q < res.size(); q++)
638 res[q] = std::dynamic_pointer_cast<const T>(it->second[q]);
654 template <
typename CellIteratorType,
typename DataType>
661 std::is_base_of<TransferableQuadraturePointData, DataType>::value,
662 "User's DataType class should be derived from QPData");
664 const std::vector<std::shared_ptr<const DataType>> qpd =
667 const unsigned int n = matrix_data.
n();
669 std::vector<double> single_qp_data(n);
670 Assert(qpd.size() == matrix_data.
m(),
672 for (
unsigned int q = 0; q < qpd.size(); q++)
674 qpd[q]->pack_values(single_qp_data);
675 Assert(single_qp_data.size() == n,
678 for (
unsigned int i = 0; i < n; i++)
679 matrix_data(q, i) = single_qp_data[i];
688 template <
typename CellIteratorType,
typename DataType>
695 std::is_base_of<TransferableQuadraturePointData, DataType>::value,
696 "User's DataType class should be derived from QPData");
698 std::vector<std::shared_ptr<DataType>> qpd = data_storage->
get_data(cell);
700 const unsigned int n = values_at_qp.
n();
702 std::vector<double> single_qp_data(n);
703 Assert(qpd.size() == values_at_qp.
m(),
706 for (
unsigned int q = 0; q < qpd.size(); q++)
708 for (
unsigned int i = 0; i < n; i++)
709 single_qp_data[i] = values_at_qp(q, i);
710 qpd[q]->unpack_values(single_qp_data);
715 # ifdef DEAL_II_WITH_P4EST 719 namespace distributed
721 template <
int dim,
typename DataType>
728 , data_size_in_bytes(0)
729 , n_q_points(rhs_quadrature.
size())
730 , project_to_fe_matrix(projection_fe->dofs_per_cell, n_q_points)
731 , project_to_qp_matrix(n_q_points, projection_fe->dofs_per_cell)
733 , data_storage(
nullptr)
734 , triangulation(
nullptr)
737 projection_fe->n_components() == 1,
739 "ContinuousQuadratureDataTransfer requires scalar FiniteElement"));
742 *projection_fe.get(),
745 project_to_fe_matrix);
748 *projection_fe.get(), rhs_quadrature, project_to_qp_matrix);
753 template <
int dim,
typename DataType>
760 template <
int dim,
typename DataType>
767 Assert(data_storage ==
nullptr,
768 ExcMessage(
"This function can be called only once"));
769 triangulation = &tr_;
770 data_storage = &data_storage_;
772 unsigned int number_of_values = 0;
777 dim>::active_cell_iterator it = triangulation->begin_active();
778 it != triangulation->end();
780 if (it->is_locally_owned())
782 std::vector<std::shared_ptr<DataType>> qpd =
784 number_of_values = qpd[0]->number_of_values();
790 triangulation->get_communicator());
792 const unsigned int dofs_per_cell = projection_fe->dofs_per_cell;
793 matrix_dofs.reinit(dofs_per_cell, number_of_values);
794 matrix_dofs_child.reinit(dofs_per_cell, number_of_values);
795 matrix_quadrature.reinit(n_q_points, number_of_values);
797 handle = triangulation->register_data_attach(
801 std::placeholders::_1,
802 std::placeholders::_2),
808 template <
int dim,
typename DataType>
812 triangulation->notify_ready_to_unpack(
817 std::placeholders::_1,
818 std::placeholders::_2,
819 std::placeholders::_3));
822 data_storage =
nullptr;
823 triangulation =
nullptr;
828 template <
int dim,
typename DataType>
836 pack_cell_data(cell, data_storage, matrix_quadrature);
839 project_to_fe_matrix.mmult(matrix_dofs, matrix_quadrature);
848 template <
int dim,
typename DataType>
853 const typename parallel::distributed::Triangulation<dim>::CellStatus
855 const boost::iterator_range<std::vector<char>::const_iterator>
864 Utilities::unpack<FullMatrix<double>>(data_range.begin(),
868 if (cell->has_children())
872 for (
unsigned int child = 0; child < cell->n_children(); ++child)
873 if (cell->child(child)->is_locally_owned())
876 ->get_prolongation_matrix(child, cell->refinement_case())
877 .mmult(matrix_dofs_child, matrix_dofs);
881 project_to_qp_matrix.mmult(matrix_quadrature,
885 unpack_to_cell_data(cell->child(child),
894 project_to_qp_matrix.mmult(matrix_quadrature, matrix_dofs);
897 unpack_to_cell_data(cell, matrix_quadrature, data_storage);
905 # endif // DEAL_II_WITH_P4EST 908 DEAL_II_NAMESPACE_CLOSE
~CellDataStorage() override=default
static const unsigned int invalid_unsigned_int
CellDataStorage()=default
virtual std::unique_ptr< FiniteElement< dim, spacedim > > clone() const =0
std::map< CellIteratorType, std::vector< std::shared_ptr< DataType > > > map
std::vector< std::shared_ptr< T > > get_data(const CellIteratorType &cell)
bool erase(const CellIteratorType &cell)
CellDataStorage< CellIteratorType, DataType > * data_storage
unsigned int size() const
static::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
static::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
const std::unique_ptr< const FiniteElement< dim > > projection_fe
size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
std::size_t data_size_in_bytes
FullMatrix< double > project_to_qp_matrix
parallel::distributed::Triangulation< dim > * triangulation
static::ExceptionBase & ExcNotImplemented()
FullMatrix< double > matrix_quadrature
typename parallel::distributed::Triangulation< dim >::cell_iterator CellIteratorType
FullMatrix< double > matrix_dofs_child
typename::Triangulation< dim, spacedim >::cell_iterator cell_iterator
FullMatrix< double > project_to_fe_matrix
FullMatrix< double > matrix_dofs
T max(const T &t, const MPI_Comm &mpi_communicator)
void initialize(const CellIteratorType &cell, const unsigned int number_of_data_points_per_cell)
const unsigned int n_q_points
static::ExceptionBase & ExcInternalError()