16#ifndef dealii_matrix_free_vector_access_internal_h
17#define dealii_matrix_free_vector_access_internal_h
28# include <boost/algorithm/string/join.hpp>
42 std::enable_if_t<is_serial_vector_or_array<VectorType>::value,
44 inline typename VectorType::value_type
53 template <
typename VectorType,
54 std::enable_if_t<is_serial_vector_or_array<VectorType>::value,
55 VectorType> * =
nullptr>
56 inline typename VectorType::value_type &
69 std::enable_if_t<has_local_element<VectorType>, VectorType> * =
nullptr>
70 inline typename VectorType::value_type &
73 return vec.local_element(entry);
81 std::enable_if_t<has_local_element<VectorType>,
VectorType> * =
nullptr>
82 inline typename VectorType::value_type
83 vector_access(
const VectorType &vec,
const unsigned int entry)
85 return vec.local_element(entry);
92 std::enable_if_t<has_add_local_element<VectorType>,
VectorType> * =
nullptr>
95 const unsigned int entry,
96 const typename VectorType::value_type &val)
98 vec.add_local_element(entry, val);
103 template <
typename VectorType,
104 std::enable_if_t<!has_add_local_element<VectorType>, VectorType> * =
108 const unsigned int entry,
109 const typename VectorType::value_type &val)
118 std::enable_if_t<has_add_local_element<VectorType>,
VectorType> * =
nullptr>
122 const typename VectorType::value_type &val)
129 template <
typename VectorType,
130 std::enable_if_t<!has_add_local_element<VectorType>, VectorType> * =
135 const typename VectorType::value_type &val)
144 std::enable_if_t<has_set_local_element<VectorType>,
VectorType> * =
nullptr>
147 const unsigned int entry,
148 const typename VectorType::value_type &val)
150 vec.set_local_element(entry, val);
155 template <
typename VectorType,
156 std::enable_if_t<!has_set_local_element<VectorType>, VectorType> * =
160 const unsigned int entry,
161 const typename VectorType::value_type &val)
174 typename VectorizedArrayType,
176 std::enable_if_t<!has_partitioners_are_compatible<VectorType>,
180 const VectorType &vec,
196 typename VectorizedArrayType,
198 std::enable_if_t<has_partitioners_are_compatible<VectorType>,
199 VectorType> * =
nullptr>
202 const VectorType &vec,
215 for (
unsigned int i = 0; i < matrix_free.
n_components(); ++i)
224 std::vector<std::string> dof_indices_with_compatible_partitioners;
226 for (
unsigned int i = 0; i < matrix_free.
n_components(); ++i)
227 if (vec.partitioners_are_compatible(
229 dof_indices_with_compatible_partitioners.push_back(
232 if (dof_indices_with_compatible_partitioners.empty())
235 ExcMessage(
"The parallel layout of the given vector is "
236 "compatible neither with the Partitioner of the "
237 "current FEEvaluation with dof_handler_index=" +
238 std::to_string(dof_index) +
239 " nor with any Partitioner in MatrixFree. A "
240 "potential reason is that you did not use "
241 "MatrixFree::initialize_dof_vector() to get a "
242 "compatible vector."));
249 "The parallel layout of the given vector is "
250 "not compatible with the Partitioner of the "
251 "current FEEvaluation with dof_handler_index=" +
252 std::to_string(dof_index) +
253 ". However, the underlying "
254 "MatrixFree contains Partitioner objects that are compatible. "
255 "They have the following dof_handler_index values: " +
256 boost::algorithm::join(dof_indices_with_compatible_partitioners,
258 ". Did you want to pass any of these values to the "
259 "constructor of the current FEEvaluation object or "
260 "did you not use MatrixFree::initialize_dof_vector() "
261 "with dof_handler_index=" +
262 std::to_string(dof_index) +
264 "compatible vector?"));
278 template <
typename Number,
typename VectorizedArrayType>
281 template <
typename VectorType>
284 const VectorType &vec,
292 template <
typename VectorNumberType>
301 template <
typename VectorType>
304 const unsigned int dof_index,
306 VectorizedArrayType *dof_values,
307 std::bool_constant<true>)
const
313 dofs_per_cell, dof_index, vec, dof_values, std::bool_constant<false>());
315 const Number *vec_ptr = vec.begin() + dof_index;
316 for (
unsigned int i = 0; i < dofs_per_cell;
317 ++i, vec_ptr += VectorizedArrayType::size())
318 dof_values[i].load(vec_ptr);
324 template <
typename VectorType>
327 const unsigned int dof_index,
328 const VectorType &vec,
329 VectorizedArrayType *dof_values,
330 std::bool_constant<false>)
const
332 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
333 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
335 vector_access(vec, dof_index + v + i * VectorizedArrayType::size());
340 template <
typename VectorType>
343 const unsigned int *dof_indices,
345 const unsigned int constant_offset,
346 VectorizedArrayType *dof_values,
347 std::bool_constant<true>)
const
350 vec.begin() + constant_offset,
357 template <
typename VectorType>
360 const unsigned int *dof_indices,
361 const VectorType &vec,
362 const unsigned int constant_offset,
363 VectorizedArrayType *dof_values,
364 std::bool_constant<false>)
const
366 for (
unsigned int d = 0; d < dofs_per_cell; ++d)
367 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
374 template <
typename VectorType>
377 const unsigned int *dof_indices,
379 VectorizedArrayType *dof_values,
380 std::bool_constant<true> type)
const
383 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
388 template <
typename VectorType>
391 const unsigned int *dof_indices,
392 const VectorType &vec,
393 VectorizedArrayType *dof_values,
394 std::bool_constant<false> type)
const
397 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
402 template <
typename Number2>
405 const unsigned int dofs_per_cell,
406 const std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
407 VectorizedArrayType *dof_values,
408 std::bool_constant<true>)
const
417 template <
typename Number2>
421 const std::array<Number2 *, VectorizedArrayType::size()> &,
422 VectorizedArrayType *,
423 std::bool_constant<false>)
const
432 template <
typename VectorType>
436 const unsigned int constant_offset,
437 typename VectorType::value_type *vec_ptr,
438 VectorizedArrayType &res,
439 std::bool_constant<true>)
const
441 (void)constant_offset;
453 std::bool_constant<false>());
455 res.gather(vec_ptr, indices);
463 template <
typename VectorType>
466 const VectorType &vec,
467 const unsigned int constant_offset,
468 typename VectorType::value_type *,
469 VectorizedArrayType &res,
470 std::bool_constant<false>)
const
472 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
478 template <
typename VectorType>
481 const VectorType &vec,
497 template <
typename VectorType>
501 const VectorType &vec,
520 res = VectorizedArrayType();
528 template <
typename Number,
typename VectorizedArrayType>
531 template <
typename VectorType>
539 template <
typename VectorNumberType>
548 template <
typename VectorType>
551 const unsigned int dof_index,
553 VectorizedArrayType *dof_values,
554 std::bool_constant<true>)
const
556 Number *vec_ptr = vec.begin() + dof_index;
557 for (
unsigned int i = 0; i < dofs_per_cell;
558 ++i, vec_ptr += VectorizedArrayType::size())
560 VectorizedArrayType tmp;
562 tmp += dof_values[i];
569 template <
typename VectorType>
572 const unsigned int dof_index,
574 VectorizedArrayType *dof_values,
575 std::bool_constant<false>)
const
577 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
578 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
580 dof_index + v + i * VectorizedArrayType::size(),
586 template <
typename VectorType>
589 const unsigned int *dof_indices,
591 const unsigned int constant_offset,
592 VectorizedArrayType *dof_values,
593 std::bool_constant<true>)
const
599 vec.begin() + constant_offset);
604 template <
typename VectorType>
607 const unsigned int *dof_indices,
609 const unsigned int constant_offset,
610 VectorizedArrayType *dof_values,
611 std::bool_constant<false>)
const
613 for (
unsigned int d = 0; d < dofs_per_cell; ++d)
614 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
616 dof_indices[v] + constant_offset + d,
622 template <
typename VectorType>
625 const unsigned int *dof_indices,
627 VectorizedArrayType *dof_values,
628 std::bool_constant<true> type)
const
631 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
636 template <
typename VectorType>
639 const unsigned int *dof_indices,
641 VectorizedArrayType *dof_values,
642 std::bool_constant<false> type)
const
645 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
650 template <
typename Number2>
653 const unsigned int dofs_per_cell,
654 std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
655 VectorizedArrayType *dof_values,
656 std::bool_constant<true>)
const
666 template <
typename Number2>
670 std::array<Number2 *, VectorizedArrayType::size()> &,
671 VectorizedArrayType *,
672 std::bool_constant<false>)
const
681 template <
typename VectorType>
685 const unsigned int constant_offset,
686 typename VectorType::value_type *vec_ptr,
687 VectorizedArrayType &res,
688 std::bool_constant<true>)
const
690 (void)constant_offset;
694#if DEAL_II_VECTORIZATION_WIDTH_IN_BITS < 512
695 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
699 VectorizedArrayType tmp;
700 tmp.gather(vec_ptr, indices);
702 tmp.scatter(indices, vec_ptr);
710 template <
typename VectorType>
714 const unsigned int constant_offset,
715 typename VectorType::value_type *,
716 VectorizedArrayType &res,
717 std::bool_constant<false>)
const
719 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
725 template <
typename VectorType>
744 template <
typename VectorType>
770 template <
typename Number,
typename VectorizedArrayType>
773 template <
typename VectorType>
782 template <
typename VectorNumberType>
791 template <
typename VectorType>
794 const unsigned int dof_index,
796 VectorizedArrayType *dof_values,
797 std::bool_constant<true>)
const
799 Number *vec_ptr = vec.begin() + dof_index;
800 for (
unsigned int i = 0; i < dofs_per_cell;
801 ++i, vec_ptr += VectorizedArrayType::size())
802 dof_values[i].store(vec_ptr);
807 template <
typename VectorType>
810 const unsigned int dof_index,
812 VectorizedArrayType *dof_values,
813 std::bool_constant<false>)
const
815 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
816 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
817 vector_access(vec, dof_index + v + i * VectorizedArrayType::size()) =
823 template <
typename VectorType>
826 const unsigned int *dof_indices,
828 const unsigned int constant_offset,
829 VectorizedArrayType *dof_values,
830 std::bool_constant<true>)
const
836 vec.begin() + constant_offset);
841 template <
typename VectorType,
bool booltype>
844 const unsigned int *dof_indices,
846 const unsigned int constant_offset,
847 VectorizedArrayType *dof_values,
848 std::bool_constant<false>)
const
850 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
851 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
858 template <
typename VectorType>
861 const unsigned int *dof_indices,
863 VectorizedArrayType *dof_values,
864 std::bool_constant<true> type)
const
867 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
872 template <
typename VectorType,
bool booltype>
875 const unsigned int *dof_indices,
877 VectorizedArrayType *dof_values,
878 std::bool_constant<false> type)
const
881 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
886 template <
typename Number2>
889 const unsigned int dofs_per_cell,
890 std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
891 VectorizedArrayType *dof_values,
892 std::bool_constant<true>)
const
902 template <
typename Number2>
906 std::array<Number2 *, VectorizedArrayType::size()> &,
907 VectorizedArrayType *,
908 std::bool_constant<false>)
const
915 template <
typename VectorType>
919 const unsigned int constant_offset,
920 typename VectorType::value_type *vec_ptr,
921 VectorizedArrayType &res,
922 std::bool_constant<true>)
const
925 (void)constant_offset;
928 res.scatter(indices, vec_ptr);
933 template <
typename VectorType>
937 const unsigned int constant_offset,
938 typename VectorType::value_type *,
939 VectorizedArrayType &res,
940 std::bool_constant<false>)
const
942 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
948 template <
typename VectorType>
965 template <
typename VectorType>
const internal::MatrixFreeFunctions::DoFInfo & get_dof_info(const unsigned int dof_handler_index_component=0) const
unsigned int n_components() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define DEAL_II_NOT_IMPLEMENTED()
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 check_vector_compatibility(const VectorType &vec, const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const internal::MatrixFreeFunctions::DoFInfo &dof_info)
void vector_access_add_global(VectorType &vec, const types::global_dof_index entry, const typename VectorType::value_type &val)
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)
static const unsigned int invalid_unsigned_int
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)