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;
299 Kokkos::View<Number *[dim][dim], MemorySpace::Default::kokkos_space>
312 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
JxW;
325 Kokkos::View<unsigned int *, MemorySpace::Default::kokkos_space>
332 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
q_weights;
344 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
shape_values;
349 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
355 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
361 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
465 "The cell index is smaller than the first cell of the "
490 const unsigned int q_point)
const
494 "The cell index is smaller than the first cell of the "
515 template <
typename Functor>
520 [&](
const int &q) { func(q); });
540 template <
typename IteratorFiltersType>
546 const IteratorFiltersType &iterator_filter,
572 template <
typename IteratorFiltersType>
578 const IteratorFiltersType &iterator_filter,
596 const unsigned int dof_handler_index = 0)
const;
622 template <
typename Functor,
typename VectorType>
625 const VectorType &src,
626 VectorType &dst)
const;
645 template <
typename Functor>
655 template <
typename VectorType>
659 const unsigned int dof_handler_index = 0)
const;
683 template <
typename VectorType>
687 const unsigned int dof_handler_index = 0)
const;
697 template <
typename MemorySpaceType>
701 const unsigned int dof_handler_index = 0)
const;
709 template <
typename MemorySpaceType>
721 const std::vector<std::vector<CellFilter>> &
730 const std::vector<std::vector<LevelCellFilter>> &
743 const std::shared_ptr<const Utilities::MPI::Partitioner> &
769 const unsigned int index,
770 const unsigned int dof_handler_index = 0)
const;
796 template <
typename IteratorFiltersType>
803 const IteratorFiltersType &iterator_filter,
804 const std::shared_ptr<const MPI_Comm> &
comm,
811 template <
typename Functor,
typename VectorType>
814 const VectorType &src,
815 VectorType &dst)
const;
821 template <
typename Functor>
833 template <
typename Functor>
885 Kokkos::View<point_type **, MemorySpace::Default::kokkos_space>>
893 Kokkos::View<Number *[dim][dim], MemorySpace::Default::kokkos_space>>
900 std::vector<Kokkos::View<Number *, MemorySpace::Default::kokkos_space>>
918 Kokkos::View<unsigned int *, MemorySpace::Default::kokkos_space>>
924 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
q_weights;
1011 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
1017 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
1023 Kokkos::View<Number *, MemorySpace::Default::kokkos_space>
1071 std::vector<std::vector<CellFilter>>
graph;
1079 friend class internal::ReinitHelper<dim, Number>;
1084 template <
int dim,
typename Number>
1088 MemorySpace::Default::kokkos_space::execution_space>::member_type;
1092 MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space,
1093 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1096 MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space,
1097 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1100 MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space,
1101 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
1109 const unsigned int n_q_points,
1145 template <
int dim,
typename Number>
1151 typename Kokkos::View<Point<dim, Number> **,
1167 typename Kokkos::View<Number *[dim][dim],
1175 typename Kokkos::View<Number *,
1183 typename Kokkos::View<
1191 typename Kokkos::View<
unsigned int *,
1198 typename Kokkos::View<Number *,
1219 typename Kokkos::View<
1236 const unsigned int n_q_points,
1237 const unsigned int q_point)
const
1239 return cell * n_q_points + q_point;
1249 const unsigned int q_point)
const
1260 const unsigned int q_point)
const
1273 JxW_value(
const unsigned int cell,
const unsigned int q_point)
const
1278 JxW(offset + q_point) :
1291 template <
int dim,
typename Number>
1292 DataHost<dim, Number>
1294 const typename ::Portable::MatrixFree<dim, Number>::PrecomputedData
1304 const auto create_mirror_without_initializing = [](
const auto &view) {
1305#if DEAL_II_KOKKOS_VERSION_GTE(3, 6, 0)
1306 return Kokkos::create_mirror(Kokkos::WithoutInitializing, view);
1308 return Kokkos::create_mirror(view);
1312 MemorySpace::Default::kokkos_space::execution_space exec;
1316 data_host.
q_points = create_mirror_without_initializing(
data.q_points);
1317 Kokkos::deep_copy(exec, data_host.
q_points,
data.q_points);
1321 create_mirror_without_initializing(
data.local_to_global);
1327 create_mirror_without_initializing(
data.inv_jacobian);
1333 data_host.
JxW = create_mirror_without_initializing(
data.JxW);
1334 Kokkos::deep_copy(exec, data_host.
JxW,
data.JxW);
1337 data_host.
cell_type = create_mirror_without_initializing(
data.cell_type);
1338 Kokkos::deep_copy(exec, data_host.
cell_type,
data.cell_type);
1341 create_mirror_without_initializing(
data.data_index_offsets);
1342 Kokkos::deep_copy(exec,
1344 data.data_index_offsets);
1346 data_host.
q_weights = create_mirror_without_initializing(
data.q_weights);
1347 Kokkos::deep_copy(exec, data_host.
q_weights,
data.q_weights);
1350 create_mirror_without_initializing(
data.constraint_mask);
1363 template <
int dim,
typename Number>
1364 inline const std::vector<std::vector<
1371 "The MatrixFree object has been initialized for a specific "
1372 "multigrid level. This function is only available when working "
1373 "on active cells."));
1379 template <
int dim,
typename Number>
1380 inline const std::vector<std::vector<
1386 ExcMessage(
"The MatrixFree object has been initialized for active cells. "
1387 "This function is only available when working on a specific "
1388 "multigrid level."));
1394 template <
int dim,
typename Number>
1395 inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
1397 const unsigned int dof_handler_index)
const
1401 return dof_handler_data[dof_handler_index].partitioner;
1406 template <
int dim,
typename Number>
1415 template <
int dim,
typename Number>
1418 const unsigned int dof_handler_index)
const
1423 return *dof_handler_data[dof_handler_index].dof_handler;
1427 template <
int dim,
typename Number>
1430 const unsigned int color,
1431 const unsigned int index,
1432 const unsigned int dof_handler_index)
const
1439 const unsigned int cell_level =
1440 get_colored_graph()[color][
index]->level();
1443 get_colored_graph()[color][
index]->index();
1446 &(get_dof_handler(dof_handler_index).get_triangulation()),
1449 &get_dof_handler(dof_handler_index));
1456 const unsigned int cell_level =
1457 get_colored_level_graph()[color][
index]->level();
1460 get_colored_level_graph()[color][
index]->index();
1463 &(get_dof_handler(dof_handler_index).get_triangulation()),
1466 &get_dof_handler(dof_handler_index));
1472 template <
int dim,
typename Number>
1482 template <
int dim,
typename Number>
1486 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