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>
424 JxW(offset + q_point) :
440 MemorySpace::Default::kokkos_space::execution_space>::member_type;
450 const Kokkos::Array<PrecomputedData, n_max_dof_handlers>
460 const unsigned int q_point)
const
464 "The cell index is smaller than the first cell of the "
489 const unsigned int q_point)
const
493 "The cell index is smaller than the first cell of the "
514 template <
typename Functor>
519 [&](
const int &q) { func(q); });
539 template <
typename IteratorFiltersType>
545 const IteratorFiltersType &iterator_filter,
571 template <
typename IteratorFiltersType>
577 const IteratorFiltersType &iterator_filter,
595 const unsigned int dof_handler_index = 0)
const;
621 template <
typename Functor,
typename VectorType>
624 const VectorType &src,
625 VectorType &dst)
const;
644 template <
typename Functor>
654 template <
typename VectorType>
658 const unsigned int dof_handler_index = 0)
const;
682 template <
typename VectorType>
686 const unsigned int dof_handler_index = 0)
const;
696 template <
typename MemorySpaceType>
700 const unsigned int dof_handler_index = 0)
const;
708 template <
typename MemorySpaceType>
720 const std::vector<std::vector<CellFilter>> &
729 const std::vector<std::vector<LevelCellFilter>> &
742 const std::shared_ptr<const Utilities::MPI::Partitioner> &
768 const unsigned int index,
769 const unsigned int dof_handler_index = 0)
const;
795 template <
typename IteratorFiltersType>
802 const IteratorFiltersType &iterator_filter,
803 const std::shared_ptr<const MPI_Comm> &
comm,
810 template <
typename Functor,
typename VectorType>
813 const VectorType &src,
814 VectorType &dst)
const;
820 template <
typename Functor>
832 template <
typename Functor>
884 Kokkos::View<point_type **, MemorySpace::Default::kokkos_space>>
892 Kokkos::View<Number *[dim][dim], MemorySpace::Default::kokkos_space>>
899 std::vector<Kokkos::View<Number *, MemorySpace::Default::kokkos_space>>
917 Kokkos::View<unsigned int *, MemorySpace::Default::kokkos_space>>
923 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
q_weights;
1010 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
1016 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
1022 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
1070 std::vector<std::vector<CellFilter>>
graph;
1078 friend class internal::ReinitHelper<dim, Number>;
1083 template <
int dim,
typename Number>
1087 MemorySpace::Default::kokkos_space::execution_space>::member_type;
1091 MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space,
1092 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1095 MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space,
1096 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1099 MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space,
1100 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1108 const unsigned int n_q_points,
1144 template <
int dim,
typename Number>
1150 typename Kokkos::View<Point<dim, Number> **,
1166 typename Kokkos::View<Number *[dim][dim],
1174 typename Kokkos::View<Number *,
1182 typename Kokkos::View<
1190 typename Kokkos::View<
unsigned int *,
1197 typename Kokkos::View<Number *,
1218 typename Kokkos::View<
1235 const unsigned int n_q_points,
1236 const unsigned int q_point)
const
1238 return cell * n_q_points + q_point;
1248 const unsigned int q_point)
const
1259 const unsigned int q_point)
const
1272 JxW_value(
const unsigned int cell,
const unsigned int q_point)
const
1277 JxW(offset + q_point) :
1290 template <
int dim,
typename Number>
1291 DataHost<dim, Number>
1293 const typename ::Portable::MatrixFree<dim, Number>::PrecomputedData
1303 const auto create_mirror_without_initializing = [](
const auto &view) {
1304#if DEAL_II_KOKKOS_VERSION_GTE(3, 6, 0)
1305 return Kokkos::create_mirror(Kokkos::WithoutInitializing, view);
1307 return Kokkos::create_mirror(view);
1311 MemorySpace::Default::kokkos_space::execution_space exec;
1315 data_host.
q_points = create_mirror_without_initializing(
data.q_points);
1316 Kokkos::deep_copy(exec, data_host.
q_points,
data.q_points);
1320 create_mirror_without_initializing(
data.local_to_global);
1326 create_mirror_without_initializing(
data.inv_jacobian);
1332 data_host.
JxW = create_mirror_without_initializing(
data.JxW);
1333 Kokkos::deep_copy(exec, data_host.
JxW,
data.JxW);
1336 data_host.
cell_type = create_mirror_without_initializing(
data.cell_type);
1337 Kokkos::deep_copy(exec, data_host.
cell_type,
data.cell_type);
1340 create_mirror_without_initializing(
data.data_index_offsets);
1341 Kokkos::deep_copy(exec,
1343 data.data_index_offsets);
1345 data_host.
q_weights = create_mirror_without_initializing(
data.q_weights);
1346 Kokkos::deep_copy(exec, data_host.
q_weights,
data.q_weights);
1349 create_mirror_without_initializing(
data.constraint_mask);
1362 template <
int dim,
typename Number>
1363 inline const std::vector<std::vector<
1370 "The MatrixFree object has been initialized for a specific "
1371 "multigrid level. This function is only available when working "
1372 "on active cells."));
1378 template <
int dim,
typename Number>
1379 inline const std::vector<std::vector<
1385 ExcMessage(
"The MatrixFree object has been initialized for active cells. "
1386 "This function is only available when working on a specific "
1387 "multigrid level."));
1393 template <
int dim,
typename Number>
1394 inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
1396 const unsigned int dof_handler_index)
const
1400 return dof_handler_data[dof_handler_index].partitioner;
1405 template <
int dim,
typename Number>
1414 template <
int dim,
typename Number>
1417 const unsigned int dof_handler_index)
const
1422 return *dof_handler_data[dof_handler_index].dof_handler;
1426 template <
int dim,
typename Number>
1429 const unsigned int color,
1430 const unsigned int index,
1431 const unsigned int dof_handler_index)
const
1438 const unsigned int cell_level =
1439 get_colored_graph()[color][
index]->level();
1442 get_colored_graph()[color][
index]->index();
1445 &(get_dof_handler(dof_handler_index).get_triangulation()),
1448 &get_dof_handler(dof_handler_index));
1455 const unsigned int cell_level =
1456 get_colored_level_graph()[color][
index]->level();
1459 get_colored_level_graph()[color][
index]->index();
1462 &(get_dof_handler(dof_handler_index).get_triangulation()),
1465 &get_dof_handler(dof_handler_index));
1471 template <
int dim,
typename Number>
1481 template <
int dim,
typename Number>
1485 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())
DoFHandler< dim >::cell_iterator get_cell_iterator(const unsigned int color, const unsigned int index, const unsigned int dof_handler_index=0) 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::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
std::vector< unsigned int > first_cell
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
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
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