14#ifndef dealii_portable_matrix_free_h
15#define dealii_portable_matrix_free_h
40#include <Kokkos_Array.hpp>
41#include <Kokkos_Core.hpp>
50 namespace MatrixFreeFunctions
62 template <
int dim,
typename Number>
65 template <
int dim,
typename Number>
84 template <
typename Number>
86 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>;
94 template <
typename Number>
123 template <
typename MemorySpace>
129 ExcMessage(
"Portable::MatrixFree is configured with " +
131 " but you are passing a BlockVector with " +
134 for (
int b = 0; b < src.
n_blocks(); ++b)
136 src.
block(b).locally_owned_size());
196 template <
int dim,
typename Number =
double>
281 Kokkos::View<point_type **, MemorySpace::Default::kokkos_space>
q_points;
298 Kokkos::View<Number *[dim][dim], MemorySpace::Default::kokkos_space>
311 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
JxW;
324 Kokkos::View<unsigned int *, MemorySpace::Default::kokkos_space>
331 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
q_weights;
343 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
shape_values;
348 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
354 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
360 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
425 JxW(offset + q_point) :
441 MemorySpace::Default::kokkos_space::execution_space>::member_type;
451 const Kokkos::Array<PrecomputedData, n_max_dof_handlers>
461 const unsigned int q_point)
const
487 const unsigned int q_point)
const
507 template <
typename Functor>
512 [&](
const int &q) { func(q); });
538 template <
typename IteratorFiltersType>
544 const IteratorFiltersType &iterator_filter,
570 template <
typename IteratorFiltersType>
576 const IteratorFiltersType &iterator_filter,
594 const unsigned int dof_handler_index = 0)
const;
620 template <
typename Functor,
typename VectorType>
623 const VectorType &src,
624 VectorType &dst)
const;
643 template <
typename Functor>
653 template <
typename VectorType>
657 const unsigned int dof_handler_index = 0)
const;
681 template <
typename VectorType>
685 const unsigned int dof_handler_index = 0)
const;
695 template <
typename MemorySpaceType>
699 const unsigned int dof_handler_index = 0)
const;
707 template <
typename MemorySpaceType>
719 const std::vector<std::vector<CellFilter>> &
728 const std::vector<std::vector<LevelCellFilter>> &
741 const std::shared_ptr<const Utilities::MPI::Partitioner> &
767 const unsigned int index,
768 const unsigned int dof_handler_index = 0)
const;
794 template <
typename IteratorFiltersType>
801 const IteratorFiltersType &iterator_filter,
802 const std::shared_ptr<const MPI_Comm> &
comm,
809 template <
typename Functor,
typename VectorType>
812 const VectorType &src,
813 VectorType &dst)
const;
819 template <
typename Functor>
831 template <
typename Functor>
883 Kokkos::View<point_type **, MemorySpace::Default::kokkos_space>>
891 Kokkos::View<Number *[dim][dim], MemorySpace::Default::kokkos_space>>
898 std::vector<Kokkos::View<Number *, MemorySpace::Default::kokkos_space>>
916 Kokkos::View<unsigned int *, MemorySpace::Default::kokkos_space>>
922 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
q_weights;
1009 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
1015 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
1021 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
1072 std::vector<std::vector<CellFilter>>
graph;
1080 friend class internal::ReinitHelper<dim, Number>;
1085 template <
int dim,
typename Number>
1089 MemorySpace::Default::kokkos_space::execution_space>::member_type;
1093 MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space,
1094 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1097 MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space,
1098 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1101 MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space,
1102 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1110 const unsigned int n_q_points,
1146 template <
int dim,
typename Number>
1152 typename Kokkos::View<Point<dim, Number> **,
1168 typename Kokkos::View<Number *[dim][dim],
1176 typename Kokkos::View<Number *,
1184 typename Kokkos::View<
1192 typename Kokkos::View<
unsigned int *,
1199 typename Kokkos::View<Number *,
1221 typename Kokkos::View<
1238 const unsigned int n_q_points,
1239 const unsigned int q_point)
const
1251 const unsigned int q_point)
const
1262 const unsigned int q_point)
const
1275 JxW_value(
const unsigned int cell,
const unsigned int q_point)
const
1280 JxW(offset + q_point) :
1293 template <
int dim,
typename Number>
1294 DataHost<dim, Number>
1296 const typename ::Portable::MatrixFree<dim, Number>::PrecomputedData
1307 const auto create_mirror_without_initializing = [](
const auto &view) {
1308#if DEAL_II_KOKKOS_VERSION_GTE(3, 6, 0)
1309 return Kokkos::create_mirror(Kokkos::WithoutInitializing, view);
1311 return Kokkos::create_mirror(view);
1315 MemorySpace::Default::kokkos_space::execution_space exec;
1319 data_host.
q_points = create_mirror_without_initializing(
data.q_points);
1320 Kokkos::deep_copy(exec, data_host.
q_points,
data.q_points);
1324 create_mirror_without_initializing(
data.local_to_global);
1330 create_mirror_without_initializing(
data.inv_jacobian);
1336 data_host.
JxW = create_mirror_without_initializing(
data.JxW);
1337 Kokkos::deep_copy(exec, data_host.
JxW,
data.JxW);
1340 data_host.
cell_type = create_mirror_without_initializing(
data.cell_type);
1341 Kokkos::deep_copy(exec, data_host.
cell_type,
data.cell_type);
1344 create_mirror_without_initializing(
data.data_index_offsets);
1345 Kokkos::deep_copy(exec,
1347 data.data_index_offsets);
1349 data_host.
q_weights = create_mirror_without_initializing(
data.q_weights);
1350 Kokkos::deep_copy(exec, data_host.
q_weights,
data.q_weights);
1353 create_mirror_without_initializing(
data.constraint_mask);
1366 template <
int dim,
typename Number>
1367 inline const std::vector<std::vector<
1374 "The MatrixFree object has been initialized for a specific "
1375 "multigrid level. This function is only available when working "
1376 "on active cells."));
1382 template <
int dim,
typename Number>
1383 inline const std::vector<std::vector<
1389 ExcMessage(
"The MatrixFree object has been initialized for active cells. "
1390 "This function is only available when working on a specific "
1391 "multigrid level."));
1397 template <
int dim,
typename Number>
1398 inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
1400 const unsigned int dof_handler_index)
const
1404 return dof_handler_data[dof_handler_index].partitioner;
1409 template <
int dim,
typename Number>
1418 template <
int dim,
typename Number>
1421 const unsigned int dof_handler_index)
const
1426 return *dof_handler_data[dof_handler_index].dof_handler;
1430 template <
int dim,
typename Number>
1433 const unsigned int color,
1434 const unsigned int index,
1435 const unsigned int dof_handler_index)
const
1442 const unsigned int cell_level =
1443 get_colored_graph()[color][
index]->level();
1446 get_colored_graph()[color][
index]->index();
1449 &(get_dof_handler(dof_handler_index).get_triangulation()),
1452 &get_dof_handler(dof_handler_index));
1459 const unsigned int cell_level =
1460 get_colored_level_graph()[color][
index]->level();
1463 get_colored_level_graph()[color][
index]->index();
1466 &(get_dof_handler(dof_handler_index).get_triangulation()),
1469 &get_dof_handler(dof_handler_index));
1475 template <
int dim,
typename Number>
1485 template <
int dim,
typename Number>
1489 return overlap_communication_computation;
unsigned int n_blocks() const
BlockType & block(const unsigned int i)
Abstract base class for mapping classes.
DeviceBlockVector(const DeviceBlockVector &other)=default
Kokkos::Array< DeviceVector< Number >, n_max_dof_handlers > blocks
const DeviceVector< Number > & block(unsigned int index) const
DeviceBlockVector(const DeviceVector< Number > &src)
DeviceVector< Number > & block(unsigned int index)
DeviceBlockVector(const LinearAlgebra::distributed::BlockVector< Number, MemorySpace > &src)
void copy_constrained_values(const VectorType &src, VectorType &dst, const unsigned int dof_handler_index=0) const
const std::vector< std::vector< CellFilter > > & get_colored_graph() const
unsigned int get_mg_level() const
void copy_constrained_values(const LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > &src, LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > &dst) const
std::vector< std::vector< CellFilter > > graph
void reinit(const DoFHandler< dim > &dof_handler, const AffineConstraints< Number > &constraints, const Quadrature< 1 > &quad, const AdditionalData &additional_data=AdditionalData())
void reinit(const Mapping< dim > &mapping, const std::vector< const DoFHandler< dim > * > &dof_handler, const std::vector< const AffineConstraints< Number > * > &constraints, const Quadrature< 1 > &quad, const IteratorFiltersType &iterator_filter, const AdditionalData &additional_data=AdditionalData())
unsigned int padding_length
DoFHandler< dim >::cell_iterator get_cell_iterator(const unsigned int color, const unsigned int index, const unsigned int dof_handler_index=0) const
unsigned int get_padding_length() const
void reinit(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< Number > &constraints, const Quadrature< 1 > &quad, const IteratorFiltersType &iterator_filter, const AdditionalData &additional_data=AdditionalData())
std::vector< std::vector< LevelCellFilter > > level_graph
bool use_overlap_communication_computation() const
unsigned int q_points_per_cell
PrecomputedData get_data(const unsigned int color, const unsigned int dof_handler_index=0) const
void distributed_cell_loop(const Functor &func, const LinearAlgebra::distributed::Vector< Number, MemorySpace::Default > &src, LinearAlgebra::distributed::Vector< Number, MemorySpace::Default > &dst) const
std::vector< unsigned int > row_start
std::size_t memory_consumption() const
void initialize_dof_vector(LinearAlgebra::distributed::Vector< Number, MemorySpaceType > &vec, const unsigned int dof_handler_index=0) const
void distributed_cell_loop(const Functor &func, const LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > &src, LinearAlgebra::distributed::BlockVector< Number, MemorySpace::Default > &dst) const
bool overlap_communication_computation
void serial_cell_loop(const Functor &func, const VectorType &src, VectorType &dst) const
void initialize_dof_vector(LinearAlgebra::distributed::BlockVector< Number, MemorySpaceType > &vec) const
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_vector_partitioner(const unsigned int dof_handler_index=0) const
void evaluate_coefficients(Functor func) const
std::vector< DoFInfo > dof_handler_data
DataHost< dim, Number > copy_mf_data_to_host(const typename::Portable::MatrixFree< dim, Number >::PrecomputedData &data, const UpdateFlags &update_flags)
const DoFHandler< dim > & get_dof_handler(const unsigned int dof_handler_index=0) const
void reinit(const Mapping< dim > &mapping, const std::vector< const DoFHandler< dim > * > &dof_handler, const std::vector< const AffineConstraints< Number > * > &constraints, const Quadrature< 1 > &quad, const AdditionalData &additional_data=AdditionalData())
void internal_reinit(const Mapping< dim > &mapping, const std::vector< const DoFHandler< dim > * > &dof_handler, const std::vector< const AffineConstraints< Number > * > &constraints, const Quadrature< 1 > &quad, const IteratorFiltersType &iterator_filter, const std::shared_ptr< const MPI_Comm > &comm, const AdditionalData additional_data)
void set_constrained_values(const Number value, VectorType &dst, const unsigned int dof_handler_index=0) const
std::vector< MappingInfo > mapping_info
void reinit(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< Number > &constraints, const Quadrature< 1 > &quad, const AdditionalData &additional_data=AdditionalData())
unsigned int n_cells_per_color(const unsigned int color) const
std::vector< unsigned int > n_cells
const std::vector< std::vector< LevelCellFilter > > & get_colored_level_graph() const
void cell_loop(const Functor &func, const VectorType &src, VectorType &dst) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_HOST_DEVICE
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
typename ActiveSelector::cell_iterator cell_iterator
@ update_JxW_values
Transformed quadrature weights.
@ update_gradients
Shape function gradients.
@ update_quadrature_points
Transformed quadrature points.
std::vector< index_type > data
constexpr unsigned int n_max_dof_handlers
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > DeviceVector
std::string to_string(const number value, const unsigned int digits=numbers::invalid_unsigned_int)
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
constexpr unsigned int invalid_unsigned_int
::Kokkos::DefaultExecutionSpace::memory_space kokkos_space
Kokkos::View<::internal::MatrixFreeFunctions::ConstraintKinds *, MemorySpace::Default::kokkos_space >::host_mirror_type constraint_mask
Kokkos::View< Number *, MemorySpace::Default::kokkos_space >::host_mirror_type q_weights
Kokkos::View< types::global_dof_index **, MemorySpace::Default::kokkos_space >::host_mirror_type local_to_global
Kokkos::View< unsignedint *, MemorySpace::Default::kokkos_space >::host_mirror_type data_index_offsets
Kokkos::View< Number *, MemorySpace::Default::kokkos_space >::host_mirror_type JxW
Point< dim, Number > get_quadrature_point(const unsigned int cell, const unsigned int q_point) const
Kokkos::View<::internal::MatrixFreeFunctions::GeometryType *, MemorySpace::Default::kokkos_space >::host_mirror_type cell_type
unsigned int padding_length
Kokkos::View< Point< dim, Number > **, MemorySpace::Default::kokkos_space >::host_mirror_type q_points
Kokkos::View< Number *[dim][dim], MemorySpace::Default::kokkos_space >::host_mirror_type inv_jacobian
unsigned int inv_jacobian_index(const unsigned int cell, const unsigned int q_point) const
Number JxW_value(const unsigned int cell, const unsigned int q_point) const
unsigned int local_q_point_id(const unsigned int cell, const unsigned int n_q_points, const unsigned int q_point) const
bool overlap_communication_computation
AdditionalData(const UpdateFlags mapping_update_flags=update_gradients|update_JxW_values|update_quadrature_points, const bool use_coloring=false, const bool overlap_communication_computation=false, const unsigned int mg_level=numbers::invalid_unsigned_int, const unsigned int team_size=numbers::invalid_unsigned_int)
UpdateFlags mapping_update_flags
const unsigned int n_dof_handler
unsigned int local_q_point_id(const unsigned int cell, const unsigned int q_point) const
Kokkos::Array< SharedData< dim, Number >, n_max_dof_handlers > & shared_data
void for_each_quad_point(const Functor &func) const
Kokkos::TeamPolicy< MemorySpace::Default::kokkos_space::execution_space >::member_type TeamHandle
const Kokkos::Array< PrecomputedData, n_max_dof_handlers > & precomputed_data
Portable::MatrixFree< dim, Number >::point_type & get_quadrature_point(const unsigned int cell, const unsigned int q_point) const
const unsigned int n_q_points
unsigned int scalar_dofs_per_cell
unsigned int scratch_pad_size
unsigned int n_constrained_dofs
::internal::MatrixFreeFunctions::ElementType element_type
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner
std::vector< Kokkos::View<::internal::MatrixFreeFunctions::ConstraintKinds *, MemorySpace::Default::kokkos_space > > constraint_mask
types::global_dof_index n_dofs
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > shape_gradients
unsigned int dofs_per_cell
std::vector< Kokkos::View< types::global_dof_index **, MemorySpace::Default::kokkos_space > > local_to_global
const DoFHandler< dim > * dof_handler
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > constraint_weights
unsigned int n_components
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > co_shape_gradients
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > shape_values
Kokkos::View< types::global_dof_index *, MemorySpace::Default::kokkos_space > constrained_dofs
std::vector< Kokkos::View<::internal::MatrixFreeFunctions::GeometryType *, MemorySpace::Default::kokkos_space > > cell_type
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > q_weights
std::vector< Kokkos::View< Number *[dim][dim], MemorySpace::Default::kokkos_space > > inv_jacobian
std::vector< Kokkos::View< unsigned int *, MemorySpace::Default::kokkos_space > > data_index_offsets
std::vector< Kokkos::View< Number *, MemorySpace::Default::kokkos_space > > JxW
std::vector< Kokkos::View< point_type **, MemorySpace::Default::kokkos_space > > q_points
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > shape_gradients
Kokkos::View< point_type **, MemorySpace::Default::kokkos_space > q_points
Number JxW_value(const int cell, const int q_point) const
unsigned int n_components
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > shape_values
unsigned int padding_length
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > JxW
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > constraint_weights
Kokkos::View<::internal::MatrixFreeFunctions::GeometryType *, MemorySpace::Default::kokkos_space > cell_type
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > co_shape_gradients
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > q_weights
::internal::MatrixFreeFunctions::ElementType element_type
unsigned int inv_jacobian_index(const int cell, const int q_point) const
Kokkos::View<::internal::MatrixFreeFunctions::ConstraintKinds *, MemorySpace::Default::kokkos_space > constraint_mask
Kokkos::View< Number *[dim][dim], MemorySpace::Default::kokkos_space > inv_jacobian
Kokkos::View< unsigned int *, MemorySpace::Default::kokkos_space > data_index_offsets
Kokkos::View< types::global_dof_index **, MemorySpace::Default::kokkos_space > local_to_global
unsigned int scratch_pad_size
Kokkos::View< Number ***, MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > SharedViewGradients
SharedViewScratchPad scratch_pad
Kokkos::View< Number *, MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > SharedViewScratchPad
void reinit(const TeamHandle &team_handle, const unsigned int n_q_points, const typename MatrixFree< dim, Number >::PrecomputedData &gpu_data)
Kokkos::TeamPolicy< MemorySpace::Default::kokkos_space::execution_space >::member_type TeamHandle
Kokkos::View< Number **, MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > SharedViewValues
SharedViewGradients gradients