16#ifndef dealii_matrix_free_vector_access_internal_h
17#define dealii_matrix_free_vector_access_internal_h
27#include <boost/algorithm/string/join.hpp>
40 std::enable_if_t<is_serial_vector_or_array<VectorType>::value,
42 inline typename VectorType::value_type
51 template <
typename VectorType,
52 std::enable_if_t<is_serial_vector_or_array<VectorType>::value,
53 VectorType> * =
nullptr>
54 inline typename VectorType::value_type &
67 std::enable_if_t<has_local_element<VectorType>, VectorType> * =
nullptr>
68 inline typename VectorType::value_type &
71 return vec.local_element(entry);
79 std::enable_if_t<has_local_element<VectorType>, VectorType> * =
nullptr>
80 inline typename VectorType::value_type
83 return vec.local_element(entry);
90 std::enable_if_t<has_add_local_element<VectorType>, VectorType> * =
nullptr>
93 const unsigned int entry,
94 const typename VectorType::value_type &val)
96 vec.add_local_element(entry, val);
101 template <
typename VectorType,
102 std::enable_if_t<!has_add_local_element<VectorType>, VectorType> * =
106 const unsigned int entry,
107 const typename VectorType::value_type &val)
116 std::enable_if_t<has_add_local_element<VectorType>, VectorType> * =
nullptr>
120 const typename VectorType::value_type &val)
127 template <
typename VectorType,
128 std::enable_if_t<!has_add_local_element<VectorType>, VectorType> * =
133 const typename VectorType::value_type &val)
142 std::enable_if_t<has_set_local_element<VectorType>, VectorType> * =
nullptr>
145 const unsigned int entry,
146 const typename VectorType::value_type &val)
148 vec.set_local_element(entry, val);
153 template <
typename VectorType,
154 std::enable_if_t<!has_set_local_element<VectorType>, VectorType> * =
158 const unsigned int entry,
159 const typename VectorType::value_type &val)
172 typename VectorizedArrayType,
174 std::enable_if_t<!has_partitioners_are_compatible<VectorType>,
175 VectorType> * =
nullptr>
178 const VectorType &vec,
190 typename VectorizedArrayType,
192 std::enable_if_t<has_partitioners_are_compatible<VectorType>,
193 VectorType> * =
nullptr>
196 const VectorType &vec,
211 for (
unsigned int i = 0; i < matrix_free.
n_components(); ++i)
221 std::vector<std::string> dof_indices_with_compatible_partitioners;
223 for (
unsigned int i = 0; i < matrix_free.
n_components(); ++i)
224 if (vec.partitioners_are_compatible(
226 dof_indices_with_compatible_partitioners.push_back(
229 if (dof_indices_with_compatible_partitioners.empty())
233 "The parallel layout of the given vector is "
234 "compatible neither with the Partitioner of the "
235 "current FEEvaluation with dof_handler_index=" +
236 std::to_string(dof_index) +
237 " nor with any Partitioner in MatrixFree. A "
238 "potential reason is that you did not use "
239 "MatrixFree::initialize_dof_vector() to get a "
240 "compatible vector."));
247 "The parallel layout of the given vector is "
248 "not compatible with the Partitioner of the "
249 "current FEEvaluation with dof_handler_index=" +
250 std::to_string(dof_index) +
251 ". However, the underlying "
252 "MatrixFree contains Partitioner objects that are compatible. "
253 "They have the following dof_handler_index values: " +
254 boost::algorithm::join(
255 dof_indices_with_compatible_partitioners,
", ") +
256 ". Did you want to pass any of these values to the "
257 "constructor of the current FEEvaluation object or "
258 "did you not use MatrixFree::initialize_dof_vector() "
259 "with dof_handler_index=" +
260 std::to_string(dof_index) +
262 "compatible vector?"));
276 template <
typename Number,
typename VectorizedArrayType>
279 template <
typename VectorType>
282 const VectorType &vec,
290 template <
typename VectorNumberType>
299 template <
typename VectorType>
302 const unsigned int dof_index,
304 VectorizedArrayType *dof_values,
305 std::bool_constant<true>)
const
315 std::bool_constant<false>());
319 const Number *vec_ptr = vec.begin() + dof_index;
320 for (
unsigned int i = 0; i < dofs_per_cell;
321 ++i, vec_ptr += VectorizedArrayType::size())
322 dof_values[i].load(vec_ptr);
328 template <
typename VectorType>
331 const unsigned int dof_index,
332 const VectorType &vec,
333 VectorizedArrayType *dof_values,
334 std::bool_constant<false>)
const
336 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
337 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
339 vector_access(vec, dof_index + v + i * VectorizedArrayType::size());
344 template <
typename VectorType>
347 const unsigned int *dof_indices,
349 const unsigned int constant_offset,
350 VectorizedArrayType *dof_values,
351 std::bool_constant<true>)
const
354 vec.begin() + constant_offset,
361 template <
typename VectorType>
364 const unsigned int *dof_indices,
365 const VectorType &vec,
366 const unsigned int constant_offset,
367 VectorizedArrayType *dof_values,
368 std::bool_constant<false>)
const
370 for (
unsigned int d = 0; d < dofs_per_cell; ++d)
371 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
378 template <
typename VectorType>
381 const unsigned int *dof_indices,
383 VectorizedArrayType *dof_values,
384 std::bool_constant<true> type)
const
387 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
392 template <
typename VectorType>
395 const unsigned int *dof_indices,
396 const VectorType &vec,
397 VectorizedArrayType *dof_values,
398 std::bool_constant<false> type)
const
401 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
406 template <
typename Number2>
409 const unsigned int dofs_per_cell,
410 const std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
411 VectorizedArrayType *dof_values,
412 std::bool_constant<true>)
const
421 template <
typename Number2>
425 const std::array<Number2 *, VectorizedArrayType::size()> &,
426 VectorizedArrayType *,
427 std::bool_constant<false>)
const
436 template <
typename VectorType>
440 const unsigned int constant_offset,
441 typename VectorType::value_type *vec_ptr,
442 VectorizedArrayType &res,
443 std::bool_constant<true>)
const
445 (void)constant_offset;
458 std::bool_constant<false>());
462 res.gather(vec_ptr, indices);
470 template <
typename VectorType>
473 const VectorType &vec,
474 const unsigned int constant_offset,
475 typename VectorType::value_type *,
476 VectorizedArrayType &res,
477 std::bool_constant<false>)
const
479 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
485 template <
typename VectorType>
488 const VectorType &vec,
504 template <
typename VectorType>
508 const VectorType &vec,
527 res = VectorizedArrayType();
535 template <
typename Number,
typename VectorizedArrayType>
538 template <
typename VectorType>
546 template <
typename VectorNumberType>
555 template <
typename VectorType>
558 const unsigned int dof_index,
560 VectorizedArrayType *dof_values,
561 std::bool_constant<true>)
const
563 Number *vec_ptr = vec.begin() + dof_index;
564 for (
unsigned int i = 0; i < dofs_per_cell;
565 ++i, vec_ptr += VectorizedArrayType::size())
567 VectorizedArrayType tmp;
569 tmp += dof_values[i];
576 template <
typename VectorType>
579 const unsigned int dof_index,
581 VectorizedArrayType *dof_values,
582 std::bool_constant<false>)
const
584 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
585 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
587 dof_index + v + i * VectorizedArrayType::size(),
593 template <
typename VectorType>
596 const unsigned int *dof_indices,
598 const unsigned int constant_offset,
599 VectorizedArrayType *dof_values,
600 std::bool_constant<true>)
const
606 vec.begin() + constant_offset);
611 template <
typename VectorType>
614 const unsigned int *dof_indices,
616 const unsigned int constant_offset,
617 VectorizedArrayType *dof_values,
618 std::bool_constant<false>)
const
620 for (
unsigned int d = 0; d < dofs_per_cell; ++d)
621 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
623 dof_indices[v] + constant_offset + d,
629 template <
typename VectorType>
632 const unsigned int *dof_indices,
634 VectorizedArrayType *dof_values,
635 std::bool_constant<true> type)
const
638 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
643 template <
typename VectorType>
646 const unsigned int *dof_indices,
648 VectorizedArrayType *dof_values,
649 std::bool_constant<false> type)
const
652 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
657 template <
typename Number2>
660 const unsigned int dofs_per_cell,
661 std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
662 VectorizedArrayType *dof_values,
663 std::bool_constant<true>)
const
673 template <
typename Number2>
677 std::array<Number2 *, VectorizedArrayType::size()> &,
678 VectorizedArrayType *,
679 std::bool_constant<false>)
const
688 template <
typename VectorType>
692 const unsigned int constant_offset,
693 typename VectorType::value_type *vec_ptr,
694 VectorizedArrayType &res,
695 std::bool_constant<true>)
const
697 (void)constant_offset;
701#if DEAL_II_VECTORIZATION_WIDTH_IN_BITS < 512
702 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
706 VectorizedArrayType tmp;
707 tmp.gather(vec_ptr, indices);
709 tmp.scatter(indices, vec_ptr);
717 template <
typename VectorType>
721 const unsigned int constant_offset,
722 typename VectorType::value_type *,
723 VectorizedArrayType &res,
724 std::bool_constant<false>)
const
726 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
732 template <
typename VectorType>
751 template <
typename VectorType>
777 template <
typename Number,
typename VectorizedArrayType>
780 template <
typename VectorType>
789 template <
typename VectorNumberType>
798 template <
typename VectorType>
801 const unsigned int dof_index,
803 VectorizedArrayType *dof_values,
804 std::bool_constant<true>)
const
806 Number *vec_ptr = vec.begin() + dof_index;
807 for (
unsigned int i = 0; i < dofs_per_cell;
808 ++i, vec_ptr += VectorizedArrayType::size())
809 dof_values[i].store(vec_ptr);
814 template <
typename VectorType>
817 const unsigned int dof_index,
819 VectorizedArrayType *dof_values,
820 std::bool_constant<false>)
const
822 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
823 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
824 vector_access(vec, dof_index + v + i * VectorizedArrayType::size()) =
830 template <
typename VectorType>
833 const unsigned int *dof_indices,
835 const unsigned int constant_offset,
836 VectorizedArrayType *dof_values,
837 std::bool_constant<true>)
const
843 vec.begin() + constant_offset);
848 template <
typename VectorType,
bool booltype>
851 const unsigned int *dof_indices,
853 const unsigned int constant_offset,
854 VectorizedArrayType *dof_values,
855 std::bool_constant<false>)
const
857 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
858 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
865 template <
typename VectorType>
868 const unsigned int *dof_indices,
870 VectorizedArrayType *dof_values,
871 std::bool_constant<true> type)
const
874 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
879 template <
typename VectorType,
bool booltype>
882 const unsigned int *dof_indices,
884 VectorizedArrayType *dof_values,
885 std::bool_constant<false> type)
const
888 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
893 template <
typename Number2>
896 const unsigned int dofs_per_cell,
897 std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
898 VectorizedArrayType *dof_values,
899 std::bool_constant<true>)
const
909 template <
typename Number2>
913 std::array<Number2 *, VectorizedArrayType::size()> &,
914 VectorizedArrayType *,
915 std::bool_constant<false>)
const
922 template <
typename VectorType>
926 const unsigned int constant_offset,
927 typename VectorType::value_type *vec_ptr,
928 VectorizedArrayType &res,
929 std::bool_constant<true>)
const
932 res.scatter(indices, vec_ptr);
937 template <
typename VectorType>
941 const unsigned int constant_offset,
942 typename VectorType::value_type *,
943 VectorizedArrayType &res,
944 std::bool_constant<false>)
const
946 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
952 template <
typename VectorType>
969 template <
typename VectorType>
const internal::MatrixFreeFunctions::DoFInfo & get_dof_info(const unsigned int dof_handler_index_component=0) const
unsigned int n_components() const
types::global_dof_index size() const
#define DEAL_II_NAMESPACE_OPEN
constexpr bool running_in_debug_mode()
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NOT_IMPLEMENTED()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
void vector_access_add(VectorType &vec, const unsigned int entry, const typename VectorType::value_type &val)
void vector_access_add_global(VectorType &vec, const types::global_dof_index entry, const typename VectorType::value_type &val)
void check_vector_compatibility(const VectorType &vec, const MatrixFree< dim, Number, VectorizedArrayType > &, const internal::MatrixFreeFunctions::DoFInfo &dof_info)
VectorType::value_type vector_access(const VectorType &vec, const unsigned int entry)
void vector_access_set(VectorType &vec, const unsigned int entry, const typename VectorType::value_type &val)
constexpr unsigned int invalid_unsigned_int
unsigned int global_dof_index
std::shared_ptr< const Utilities::MPI::Partitioner > vector_partitioner
void process_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, typename VectorType::value_type *vec_ptr, VectorizedArrayType &res, std::bool_constant< true >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< false > type) const
void pre_constraints(const Number &input, Number &res) const
void process_empty(VectorizedArrayType &) const
void process_dof(const unsigned int index, VectorType &vec, Number &res) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, const unsigned int constant_offset, VectorizedArrayType *dof_values, std::bool_constant< false >) const
void post_constraints(const Number &, Number &) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< true >) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< false >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, const unsigned int constant_offset, VectorizedArrayType *dof_values, std::bool_constant< true >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< true > type) const
void process_dofs_vectorized_transpose(const unsigned int, std::array< Number2 *, VectorizedArrayType::size()> &, VectorizedArrayType *, std::bool_constant< false >) const
void process_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, typename VectorType::value_type *, VectorizedArrayType &res, std::bool_constant< false >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, std::array< Number2 *, VectorizedArrayType::size()> &global_ptr, VectorizedArrayType *dof_values, std::bool_constant< true >) const
void process_dof(VectorNumberType &global, Number &local) const
void process_constraint(const unsigned int index, const Number weight, VectorType &vec, Number &res) const
void process_dof_global(const types::global_dof_index index, VectorType &vec, Number &res) const
void pre_constraints(const Number &, Number &res) const
void post_constraints(const Number &sum, Number &write_pos) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, const unsigned int constant_offset, VectorizedArrayType *dof_values, std::bool_constant< true >) const
void process_dof_global(const types::global_dof_index index, const VectorType &vec, Number &res) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, const VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< false >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, const VectorType &vec, const unsigned int constant_offset, VectorizedArrayType *dof_values, std::bool_constant< false >) const
void process_constraint(const unsigned int index, const Number weight, const VectorType &vec, Number &res) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< true > type) const
void process_dof_gather(const unsigned int *indices, const VectorType &vec, const unsigned int constant_offset, typename VectorType::value_type *, VectorizedArrayType &res, std::bool_constant< false >) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< true >) const
void process_dof(const VectorNumberType &global, Number &local) const
void process_empty(VectorizedArrayType &res) const
void process_dof(const unsigned int index, const VectorType &vec, Number &res) const
void process_dofs_vectorized_transpose(const unsigned int, const std::array< Number2 *, VectorizedArrayType::size()> &, VectorizedArrayType *, std::bool_constant< false >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, const VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< false > type) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const std::array< Number2 *, VectorizedArrayType::size()> &global_ptr, VectorizedArrayType *dof_values, std::bool_constant< true >) const
void process_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, typename VectorType::value_type *vec_ptr, VectorizedArrayType &res, std::bool_constant< true >) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< false >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, std::array< Number2 *, VectorizedArrayType::size()> &global_ptr, VectorizedArrayType *dof_values, std::bool_constant< true >) const
void process_empty(VectorizedArrayType &) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< true > type) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, const unsigned int constant_offset, VectorizedArrayType *dof_values, std::bool_constant< false >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< false > type) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, const unsigned int constant_offset, VectorizedArrayType *dof_values, std::bool_constant< true >) const
void process_dof_global(const types::global_dof_index index, VectorType &vec, Number &res) const
void pre_constraints(const Number &, Number &) const
void process_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, typename VectorType::value_type *vec_ptr, VectorizedArrayType &res, std::bool_constant< true >) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::bool_constant< true >) const
void process_dofs_vectorized_transpose(const unsigned int, std::array< Number2 *, VectorizedArrayType::size()> &, VectorizedArrayType *, std::bool_constant< false >) const
void process_constraint(const unsigned int, const Number, VectorType &, Number &) const
void process_dof(const unsigned int index, VectorType &vec, Number &res) const
void post_constraints(const Number &, Number &) const
void process_dof(VectorNumberType &global, Number &local) const
void process_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, typename VectorType::value_type *, VectorizedArrayType &res, std::bool_constant< false >) const
void vectorized_load_and_transpose(const unsigned int n_entries, const Number *in, const unsigned int *offsets, VectorizedArray< Number, width > *out)
void vectorized_transpose_and_store(const bool add_into, const unsigned int n_entries, const VectorizedArray< Number, width > *in, const unsigned int *offsets, Number *out)