17#ifndef dealii_matrix_free_vector_access_internal_h
18#define dealii_matrix_free_vector_access_internal_h
29# include <boost/algorithm/string/join.hpp>
44 std::enable_if_t<!has_local_element<VectorType>, VectorType> * =
nullptr>
45 inline typename VectorType::value_type
58 std::enable_if_t<!has_local_element<VectorType>, VectorType> * =
nullptr>
59 inline typename VectorType::value_type &
72 std::enable_if_t<has_local_element<VectorType>, VectorType> * =
nullptr>
73 inline typename VectorType::value_type &
76 return vec.local_element(entry);
84 std::enable_if_t<has_local_element<VectorType>, VectorType> * =
nullptr>
85 inline typename VectorType::value_type
86 vector_access(
const VectorType &vec,
const unsigned int entry)
88 return vec.local_element(entry);
95 std::enable_if_t<has_add_local_element<VectorType>, VectorType> * =
nullptr>
98 const unsigned int entry,
99 const typename VectorType::value_type &val)
101 vec.add_local_element(entry, val);
106 template <
typename VectorType,
107 std::enable_if_t<!has_add_local_element<VectorType>, VectorType> * =
111 const unsigned int entry,
112 const typename VectorType::value_type &val)
121 std::enable_if_t<has_add_local_element<VectorType>, VectorType> * =
nullptr>
125 const typename VectorType::value_type &val)
132 template <
typename VectorType,
133 std::enable_if_t<!has_add_local_element<VectorType>, VectorType> * =
138 const typename VectorType::value_type &val)
147 std::enable_if_t<has_set_local_element<VectorType>, VectorType> * =
nullptr>
150 const unsigned int entry,
151 const typename VectorType::value_type &val)
153 vec.set_local_element(entry, val);
158 template <
typename VectorType,
159 std::enable_if_t<!has_set_local_element<VectorType>, VectorType> * =
163 const unsigned int entry,
164 const typename VectorType::value_type &val)
177 typename VectorizedArrayType,
179 std::enable_if_t<!has_partitioners_are_compatible<VectorType>,
180 VectorType> * =
nullptr>
183 const VectorType & vec,
199 typename VectorizedArrayType,
201 std::enable_if_t<has_partitioners_are_compatible<VectorType>,
202 VectorType> * =
nullptr>
205 const VectorType & vec,
218 for (
unsigned int i = 0; i < matrix_free.
n_components(); ++i)
227 std::vector<std::string> dof_indices_with_compatible_partitioners;
229 for (
unsigned int i = 0; i < matrix_free.
n_components(); ++i)
230 if (vec.partitioners_are_compatible(
232 dof_indices_with_compatible_partitioners.push_back(
235 if (dof_indices_with_compatible_partitioners.empty())
238 ExcMessage(
"The parallel layout of the given vector is "
239 "compatible neither with the Partitioner of the "
240 "current FEEvaluation with dof_handler_index=" +
241 std::to_string(dof_index) +
242 " nor with any Partitioner in MatrixFree. A "
243 "potential reason is that you did not use "
244 "MatrixFree::initialize_dof_vector() to get a "
245 "compatible vector."));
252 "The parallel layout of the given vector is "
253 "not compatible with the Partitioner of the "
254 "current FEEvaluation with dof_handler_index=" +
255 std::to_string(dof_index) +
256 ". However, the underlying "
257 "MatrixFree contains Partitioner objects that are compatible. "
258 "They have the following dof_handler_index values: " +
259 boost::algorithm::join(dof_indices_with_compatible_partitioners,
261 ". Did you want to pass any of these values to the "
262 "constructor of the current FEEvaluation object or "
263 "did you not use MatrixFree::initialize_dof_vector() "
264 "with dof_handler_index=" +
265 std::to_string(dof_index) +
267 "compatible vector?"));
281 template <
typename Number,
typename VectorizedArrayType>
284 template <
typename VectorType>
287 const VectorType & vec,
295 template <
typename VectorNumberType>
304 template <
typename VectorType>
307 const unsigned int dof_index,
309 VectorizedArrayType *dof_values,
310 std::integral_constant<bool, true>)
const
319 std::integral_constant<bool, false>());
321 const Number *vec_ptr = vec.begin() + dof_index;
322 for (
unsigned int i = 0; i < dofs_per_cell;
323 ++i, vec_ptr += VectorizedArrayType::size())
324 dof_values[i].load(vec_ptr);
330 template <
typename VectorType>
333 const unsigned int dof_index,
334 const VectorType & vec,
335 VectorizedArrayType *dof_values,
336 std::integral_constant<bool, false>)
const
338 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
339 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
341 vector_access(vec, dof_index + v + i * VectorizedArrayType::size());
346 template <
typename VectorType>
349 const unsigned int * dof_indices,
351 const unsigned int constant_offset,
352 VectorizedArrayType *dof_values,
353 std::integral_constant<bool, true>)
const
356 vec.begin() + constant_offset,
363 template <
typename VectorType>
366 const unsigned int * dof_indices,
367 const VectorType & vec,
368 const unsigned int constant_offset,
369 VectorizedArrayType *dof_values,
370 std::integral_constant<bool, false>)
const
372 for (
unsigned int d = 0; d < dofs_per_cell; ++d)
373 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
380 template <
typename VectorType>
383 const unsigned int dofs_per_cell,
384 const unsigned int * dof_indices,
386 VectorizedArrayType * dof_values,
387 std::integral_constant<bool, true> type)
const
390 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
395 template <
typename VectorType>
398 const unsigned int dofs_per_cell,
399 const unsigned int * dof_indices,
400 const VectorType & vec,
401 VectorizedArrayType * dof_values,
402 std::integral_constant<bool, false> type)
const
405 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
410 template <
typename Number2>
413 const unsigned int dofs_per_cell,
414 const std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
415 VectorizedArrayType * dof_values,
416 std::integral_constant<bool, true>)
const
425 template <
typename Number2>
429 const std::array<Number2 *, VectorizedArrayType::size()> &,
430 VectorizedArrayType *,
431 std::integral_constant<bool, false>)
const
440 template <
typename VectorType>
444 const unsigned int constant_offset,
445 VectorizedArrayType &res,
446 std::integral_constant<bool, true>)
const
455 std::integral_constant<bool, false>());
457 res.gather(vec.begin() + constant_offset, indices);
465 template <
typename VectorType>
468 const VectorType & vec,
469 const unsigned int constant_offset,
470 VectorizedArrayType &res,
471 std::integral_constant<bool, false>)
const
473 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
479 template <
typename VectorType>
482 const VectorType & vec,
498 template <
typename VectorType>
502 const VectorType & vec,
521 res = VectorizedArrayType();
529 template <
typename Number,
typename VectorizedArrayType>
532 template <
typename VectorType>
540 template <
typename VectorNumberType>
549 template <
typename VectorType>
552 const unsigned int dof_index,
554 VectorizedArrayType *dof_values,
555 std::integral_constant<bool, true>)
const
557 Number *vec_ptr = vec.begin() + dof_index;
558 for (
unsigned int i = 0; i < dofs_per_cell;
559 ++i, vec_ptr += VectorizedArrayType::size())
561 VectorizedArrayType tmp;
563 tmp += dof_values[i];
570 template <
typename VectorType>
573 const unsigned int dof_index,
575 VectorizedArrayType *dof_values,
576 std::integral_constant<bool, false>)
const
578 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
579 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
581 dof_index + v + i * VectorizedArrayType::size(),
587 template <
typename VectorType>
590 const unsigned int * dof_indices,
592 const unsigned int constant_offset,
593 VectorizedArrayType *dof_values,
594 std::integral_constant<bool, true>)
const
600 vec.begin() + constant_offset);
605 template <
typename VectorType>
608 const unsigned int * dof_indices,
610 const unsigned int constant_offset,
611 VectorizedArrayType *dof_values,
612 std::integral_constant<bool, false>)
const
614 for (
unsigned int d = 0; d < dofs_per_cell; ++d)
615 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
617 dof_indices[v] + constant_offset + d,
623 template <
typename VectorType>
626 const unsigned int dofs_per_cell,
627 const unsigned int * dof_indices,
629 VectorizedArrayType * dof_values,
630 std::integral_constant<bool, true> type)
const
633 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
638 template <
typename VectorType>
641 const unsigned int dofs_per_cell,
642 const unsigned int * dof_indices,
644 VectorizedArrayType * dof_values,
645 std::integral_constant<bool, false> type)
const
648 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
653 template <
typename Number2>
656 const unsigned int dofs_per_cell,
657 std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
658 VectorizedArrayType * dof_values,
659 std::integral_constant<bool, true>)
const
669 template <
typename Number2>
673 std::array<Number2 *, VectorizedArrayType::size()> &,
674 VectorizedArrayType *,
675 std::integral_constant<bool, false>)
const
684 template <
typename VectorType>
688 const unsigned int constant_offset,
689 VectorizedArrayType &res,
690 std::integral_constant<bool, true>)
const
692#if DEAL_II_VECTORIZATION_WIDTH_IN_BITS < 512
693 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
697 VectorizedArrayType tmp;
698 tmp.gather(vec.begin() + constant_offset, indices);
700 tmp.scatter(indices, vec.begin() + constant_offset);
708 template <
typename VectorType>
712 const unsigned int constant_offset,
713 VectorizedArrayType &res,
714 std::integral_constant<bool, false>)
const
716 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
722 template <
typename VectorType>
741 template <
typename VectorType>
767 template <
typename Number,
typename VectorizedArrayType>
770 template <
typename VectorType>
779 template <
typename VectorNumberType>
788 template <
typename VectorType>
791 const unsigned int dof_index,
793 VectorizedArrayType *dof_values,
794 std::integral_constant<bool, true>)
const
796 Number *vec_ptr = vec.begin() + dof_index;
797 for (
unsigned int i = 0; i < dofs_per_cell;
798 ++i, vec_ptr += VectorizedArrayType::size())
799 dof_values[i].store(vec_ptr);
804 template <
typename VectorType>
807 const unsigned int dof_index,
809 VectorizedArrayType *dof_values,
810 std::integral_constant<bool, false>)
const
812 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
813 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
814 vector_access(vec, dof_index + v + i * VectorizedArrayType::size()) =
820 template <
typename VectorType>
823 const unsigned int * dof_indices,
825 const unsigned int constant_offset,
826 VectorizedArrayType *dof_values,
827 std::integral_constant<bool, true>)
const
833 vec.begin() + constant_offset);
838 template <
typename VectorType,
bool booltype>
841 const unsigned int * dof_indices,
843 const unsigned int constant_offset,
844 VectorizedArrayType *dof_values,
845 std::integral_constant<bool, false>)
const
847 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
848 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
855 template <
typename VectorType>
858 const unsigned int dofs_per_cell,
859 const unsigned int * dof_indices,
861 VectorizedArrayType * dof_values,
862 std::integral_constant<bool, true> type)
const
865 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
870 template <
typename VectorType,
bool booltype>
873 const unsigned int dofs_per_cell,
874 const unsigned int * dof_indices,
876 VectorizedArrayType * dof_values,
877 std::integral_constant<bool, false> type)
const
880 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
885 template <
typename Number2>
888 const unsigned int dofs_per_cell,
889 std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
890 VectorizedArrayType * dof_values,
891 std::integral_constant<bool, true>)
const
901 template <
typename Number2>
905 std::array<Number2 *, VectorizedArrayType::size()> &,
906 VectorizedArrayType *,
907 std::integral_constant<bool, false>)
const
914 template <
typename VectorType>
918 const unsigned int constant_offset,
919 VectorizedArrayType &res,
920 std::integral_constant<bool, true>)
const
922 res.scatter(indices, vec.begin() + constant_offset);
927 template <
typename VectorType>
931 const unsigned int constant_offset,
932 VectorizedArrayType &res,
933 std::integral_constant<bool, false>)
const
935 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
941 template <
typename VectorType>
958 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
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
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, VectorizedArrayType &res, std::integral_constant< bool, true >) const
void pre_constraints(const Number &input, Number &res) const
void process_dofs_vectorized_transpose(const unsigned int, std::array< Number2 *, VectorizedArrayType::size()> &, VectorizedArrayType *, std::integral_constant< bool, false >) 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::integral_constant< bool, true >) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, true >) const
void post_constraints(const Number &, Number &) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, std::array< Number2 *, VectorizedArrayType::size()> &global_ptr, VectorizedArrayType *dof_values, std::integral_constant< bool, true >) const
void process_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, VectorizedArrayType &res, std::integral_constant< bool, 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::integral_constant< bool, false >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, false > type) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, true > type) const
void process_dof(VectorNumberType &global, Number &local) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, false >) 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 process_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, VectorizedArrayType &res, std::integral_constant< bool, true >) const
void process_dof_gather(const unsigned int *indices, const VectorType &vec, const unsigned int constant_offset, VectorizedArrayType &res, std::integral_constant< bool, false >) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, true >) 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, VectorizedArrayType *dof_values, std::integral_constant< bool, true > type) 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::integral_constant< bool, 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, const VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, 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::integral_constant< bool, true >) const
void process_dof(const VectorNumberType &global, Number &local) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const std::array< Number2 *, VectorizedArrayType::size()> &global_ptr, VectorizedArrayType *dof_values, std::integral_constant< bool, true >) const
void process_empty(VectorizedArrayType &res) const
void process_dofs_vectorized_transpose(const unsigned int, const std::array< Number2 *, VectorizedArrayType::size()> &, VectorizedArrayType *, std::integral_constant< bool, false >) const
void process_dof(const unsigned int index, const VectorType &vec, Number &res) 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::integral_constant< bool, false >) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, true >) const
void process_empty(VectorizedArrayType &) const
void process_dofs_vectorized_transpose(const unsigned int, std::array< Number2 *, VectorizedArrayType::size()> &, VectorizedArrayType *, std::integral_constant< bool, false >) 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_dofs_vectorized_transpose(const unsigned int dofs_per_cell, std::array< Number2 *, VectorizedArrayType::size()> &global_ptr, VectorizedArrayType *dof_values, std::integral_constant< bool, true >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, 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::integral_constant< bool, true >) const
void process_dofs_vectorized(const unsigned int dofs_per_cell, const unsigned int dof_index, VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, 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 process_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, VectorizedArrayType &res, std::integral_constant< bool, true >) const
void process_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, VectorizedArrayType &res, std::integral_constant< bool, false >) const
void post_constraints(const Number &, Number &) const
void process_dof(VectorNumberType &global, Number &local) 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::integral_constant< bool, false >) const
void process_dofs_vectorized_transpose(const unsigned int dofs_per_cell, const unsigned int *dof_indices, VectorType &vec, VectorizedArrayType *dof_values, std::integral_constant< bool, false > type) 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)