14#ifndef dealii_matrix_free_vector_access_internal_h
15#define dealii_matrix_free_vector_access_internal_h
25#include <boost/algorithm/string/join.hpp>
38 std::enable_if_t<is_serial_vector_or_array<VectorType>::value,
40 inline typename VectorType::value_type
49 template <
typename VectorType,
50 std::enable_if_t<is_serial_vector_or_array<VectorType>::value,
51 VectorType> * =
nullptr>
52 inline typename VectorType::value_type &
65 std::enable_if_t<has_local_element<VectorType>, VectorType> * =
nullptr>
66 inline typename VectorType::value_type &
69 return vec.local_element(entry);
77 std::enable_if_t<has_local_element<VectorType>,
VectorType> * =
nullptr>
78 inline typename VectorType::value_type
79 vector_access(
const VectorType &vec,
const unsigned int entry)
81 return vec.local_element(entry);
88 std::enable_if_t<has_add_local_element<VectorType>,
VectorType> * =
nullptr>
91 const unsigned int entry,
92 const typename VectorType::value_type &val)
94 vec.add_local_element(entry, val);
99 template <
typename VectorType,
100 std::enable_if_t<!has_add_local_element<VectorType>, VectorType> * =
104 const unsigned int entry,
105 const typename VectorType::value_type &val)
114 std::enable_if_t<has_add_local_element<VectorType>,
VectorType> * =
nullptr>
118 const typename VectorType::value_type &val)
125 template <
typename VectorType,
126 std::enable_if_t<!has_add_local_element<VectorType>, VectorType> * =
131 const typename VectorType::value_type &val)
140 std::enable_if_t<has_set_local_element<VectorType>,
VectorType> * =
nullptr>
143 const unsigned int entry,
144 const typename VectorType::value_type &val)
146 vec.set_local_element(entry, val);
151 template <
typename VectorType,
152 std::enable_if_t<!has_set_local_element<VectorType>, VectorType> * =
156 const unsigned int entry,
157 const typename VectorType::value_type &val)
170 typename VectorizedArrayType,
172 std::enable_if_t<!has_partitioners_are_compatible<VectorType>,
176 const VectorType &vec,
188 typename VectorizedArrayType,
190 std::enable_if_t<has_partitioners_are_compatible<VectorType>,
191 VectorType> * =
nullptr>
194 const VectorType &vec,
209 for (
unsigned int i = 0; i < matrix_free.
n_components(); ++i)
219 std::vector<std::string> dof_indices_with_compatible_partitioners;
221 for (
unsigned int i = 0; i < matrix_free.
n_components(); ++i)
222 if (vec.partitioners_are_compatible(
224 dof_indices_with_compatible_partitioners.push_back(
227 if (dof_indices_with_compatible_partitioners.empty())
231 "The parallel layout of the given vector is "
232 "compatible neither with the Partitioner of the "
233 "current FEEvaluation with dof_handler_index=" +
234 std::to_string(dof_index) +
235 " nor with any Partitioner in MatrixFree. A "
236 "potential reason is that you did not use "
237 "MatrixFree::initialize_dof_vector() to get a "
238 "compatible vector."));
245 "The parallel layout of the given vector is "
246 "not compatible with the Partitioner of the "
247 "current FEEvaluation with dof_handler_index=" +
248 std::to_string(dof_index) +
249 ". However, the underlying "
250 "MatrixFree contains Partitioner objects that are compatible. "
251 "They have the following dof_handler_index values: " +
252 boost::algorithm::join(
253 dof_indices_with_compatible_partitioners,
", ") +
254 ". Did you want to pass any of these values to the "
255 "constructor of the current FEEvaluation object or "
256 "did you not use MatrixFree::initialize_dof_vector() "
257 "with dof_handler_index=" +
258 std::to_string(dof_index) +
260 "compatible vector?"));
274 template <
typename Number,
typename VectorizedArrayType>
277 template <
typename VectorType>
280 const VectorType &vec,
288 template <
typename VectorNumberType>
297 template <
typename VectorType>
300 const unsigned int dof_index,
302 VectorizedArrayType *dof_values,
303 std::bool_constant<true>)
const
313 std::bool_constant<false>());
317 const Number *vec_ptr = vec.begin() + dof_index;
318 for (
unsigned int i = 0; i < dofs_per_cell;
319 ++i, vec_ptr += VectorizedArrayType::size())
320 dof_values[i].load(vec_ptr);
326 template <
typename VectorType>
329 const unsigned int dof_index,
330 const VectorType &vec,
331 VectorizedArrayType *dof_values,
332 std::bool_constant<false>)
const
334 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
335 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
337 vector_access(vec, dof_index + v + i * VectorizedArrayType::size());
342 template <
typename VectorType>
345 const unsigned int *dof_indices,
347 const unsigned int constant_offset,
348 VectorizedArrayType *dof_values,
349 std::bool_constant<true>)
const
352 vec.begin() + constant_offset,
359 template <
typename VectorType>
362 const unsigned int *dof_indices,
363 const VectorType &vec,
364 const unsigned int constant_offset,
365 VectorizedArrayType *dof_values,
366 std::bool_constant<false>)
const
368 for (
unsigned int d = 0; d < dofs_per_cell; ++d)
369 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
376 template <
typename VectorType>
379 const unsigned int *dof_indices,
381 VectorizedArrayType *dof_values,
382 std::bool_constant<true> type)
const
385 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
390 template <
typename VectorType>
393 const unsigned int *dof_indices,
394 const VectorType &vec,
395 VectorizedArrayType *dof_values,
396 std::bool_constant<false> type)
const
399 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
404 template <
typename Number2>
407 const unsigned int dofs_per_cell,
408 const std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
409 VectorizedArrayType *dof_values,
410 std::bool_constant<true>)
const
417 const std::array<
const Number2 *, VectorizedArrayType::size()
> &>(
424 template <
typename Number2>
428 const std::array<Number2 *, VectorizedArrayType::size()> &,
429 VectorizedArrayType *,
430 std::bool_constant<false>)
const
439 template <
typename VectorType>
442 const VectorType &vec,
443 const unsigned int constant_offset,
444 typename VectorType::value_type *vec_ptr,
445 VectorizedArrayType &res,
446 std::bool_constant<true>)
const
448 (void)constant_offset;
461 std::bool_constant<false>());
465 res.gather(vec_ptr, indices);
473 template <
typename VectorType>
476 const VectorType &vec,
477 const unsigned int constant_offset,
478 typename VectorType::value_type *,
479 VectorizedArrayType &res,
480 std::bool_constant<false>)
const
482 res = VectorizedArrayType();
484 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
491 template <
typename VectorType>
494 const VectorType &vec,
510 template <
typename VectorType>
514 const VectorType &vec,
533 res = VectorizedArrayType();
541 template <
typename Number,
typename VectorizedArrayType>
544 template <
typename VectorType>
552 template <
typename VectorNumberType>
561 template <
typename VectorType>
564 const unsigned int dof_index,
566 VectorizedArrayType *dof_values,
567 std::bool_constant<true>)
const
569 Number *vec_ptr = vec.begin() + dof_index;
570 for (
unsigned int i = 0; i < dofs_per_cell;
571 ++i, vec_ptr += VectorizedArrayType::size())
573 VectorizedArrayType tmp;
575 tmp += dof_values[i];
582 template <
typename VectorType>
585 const unsigned int dof_index,
587 VectorizedArrayType *dof_values,
588 std::bool_constant<false>)
const
590 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
591 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
593 dof_index + v + i * VectorizedArrayType::size(),
599 template <
typename VectorType>
602 const unsigned int *dof_indices,
604 const unsigned int constant_offset,
605 VectorizedArrayType *dof_values,
606 std::bool_constant<true>)
const
612 vec.begin() + constant_offset);
617 template <
typename VectorType>
620 const unsigned int *dof_indices,
622 const unsigned int constant_offset,
623 VectorizedArrayType *dof_values,
624 std::bool_constant<false>)
const
626 for (
unsigned int d = 0; d < dofs_per_cell; ++d)
627 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
629 dof_indices[v] + constant_offset + d,
635 template <
typename VectorType>
638 const unsigned int *dof_indices,
640 VectorizedArrayType *dof_values,
641 std::bool_constant<true> type)
const
644 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
649 template <
typename VectorType>
652 const unsigned int *dof_indices,
654 VectorizedArrayType *dof_values,
655 std::bool_constant<false> type)
const
658 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
663 template <
typename Number2>
666 const unsigned int dofs_per_cell,
667 std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
668 VectorizedArrayType *dof_values,
669 std::bool_constant<true>)
const
679 template <
typename Number2>
683 std::array<Number2 *, VectorizedArrayType::size()> &,
684 VectorizedArrayType *,
685 std::bool_constant<false>)
const
694 template <
typename VectorType>
698 const unsigned int constant_offset,
699 typename VectorType::value_type *vec_ptr,
700 const VectorizedArrayType res,
701 std::bool_constant<true>)
const
703 (void)constant_offset;
717 std::bool_constant<false>());
721 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
723 vec_ptr[indices[v]] += res[v];
731 template <
typename VectorType>
735 const unsigned int constant_offset,
736 typename VectorType::value_type *,
737 const VectorizedArrayType res,
738 std::bool_constant<false>)
const
740 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
747 template <
typename VectorType>
766 template <
typename VectorType>
792 template <
typename Number,
typename VectorizedArrayType>
795 template <
typename VectorType>
804 template <
typename VectorNumberType>
813 template <
typename VectorType>
816 const unsigned int dof_index,
818 VectorizedArrayType *dof_values,
819 std::bool_constant<true>)
const
821 Number *vec_ptr = vec.begin() + dof_index;
822 for (
unsigned int i = 0; i < dofs_per_cell;
823 ++i, vec_ptr += VectorizedArrayType::size())
824 dof_values[i].store(vec_ptr);
829 template <
typename VectorType>
832 const unsigned int dof_index,
834 VectorizedArrayType *dof_values,
835 std::bool_constant<false>)
const
837 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
838 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
839 vector_access(vec, dof_index + v + i * VectorizedArrayType::size()) =
845 template <
typename VectorType>
848 const unsigned int *dof_indices,
850 const unsigned int constant_offset,
851 VectorizedArrayType *dof_values,
852 std::bool_constant<true>)
const
858 vec.begin() + constant_offset);
863 template <
typename VectorType,
bool booltype>
866 const unsigned int *dof_indices,
868 const unsigned int constant_offset,
869 VectorizedArrayType *dof_values,
870 std::bool_constant<false>)
const
872 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
873 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
880 template <
typename VectorType>
883 const unsigned int *dof_indices,
885 VectorizedArrayType *dof_values,
886 std::bool_constant<true> type)
const
889 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
894 template <
typename VectorType,
bool booltype>
897 const unsigned int *dof_indices,
899 VectorizedArrayType *dof_values,
900 std::bool_constant<false> type)
const
903 dofs_per_cell, dof_indices, vec, 0, dof_values, type);
908 template <
typename Number2>
911 const unsigned int dofs_per_cell,
912 std::array<Number2 *, VectorizedArrayType::size()> &global_ptr,
913 VectorizedArrayType *dof_values,
914 std::bool_constant<true>)
const
924 template <
typename Number2>
928 std::array<Number2 *, VectorizedArrayType::size()> &,
929 VectorizedArrayType *,
930 std::bool_constant<false>)
const
937 template <
typename VectorType>
941 const unsigned int constant_offset,
942 typename VectorType::value_type *vec_ptr,
943 const VectorizedArrayType res,
944 std::bool_constant<true>)
const
947 res.scatter(indices, vec_ptr);
952 template <
typename VectorType>
956 const unsigned int constant_offset,
957 typename VectorType::value_type *,
958 const VectorizedArrayType res,
959 std::bool_constant<false>)
const
961 for (
unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
968 template <
typename VectorType>
985 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_OPENMP_SIMD_PRAGMA
#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
* * * RotationFunction< dim, Number >::RotationFunction Number(dim)
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
std::shared_ptr< const Utilities::MPI::Partitioner > vector_partitioner
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_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_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, typename VectorType::value_type *vec_ptr, const VectorizedArrayType res, std::bool_constant< true >) 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 *, const VectorizedArrayType res, std::bool_constant< 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 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_dof_gather(const unsigned int *indices, const 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, 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_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_dof_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, typename VectorType::value_type *, const VectorizedArrayType res, 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_dof_global(const types::global_dof_index index, VectorType &vec, Number &res) const
void pre_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_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_gather(const unsigned int *indices, VectorType &vec, const unsigned int constant_offset, typename VectorType::value_type *vec_ptr, const VectorizedArrayType res, std::bool_constant< true >) const
void process_dof(VectorNumberType &global, Number &local) 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)