17#ifndef dealii_matrix_free_h
18#define dealii_matrix_free_h
110 typename Number = double,
115 std::is_same<Number, typename VectorizedArrayType::value_type>::value,
116 "Type of Number and of VectorizedArrayType do not match.");
587 template <
typename QuadratureType,
typename number2,
typename MappingType>
592 const QuadratureType & quad,
616 template <
typename QuadratureType,
typename number2,
typename MappingType>
621 const std::vector<QuadratureType> & quad,
631 template <
typename QuadratureType,
typename number2,
typename MappingType>
636 const QuadratureType & quad,
793 template <
typename OutVector,
typename InVector>
799 const std::pair<unsigned int, unsigned int> &)> &cell_operation,
801 const InVector & src,
802 const bool zero_dst_vector =
false)
const;
850 template <
typename CLASS,
typename OutVector,
typename InVector>
856 const
std::pair<unsigned
int, unsigned
int> &) const,
857 const CLASS * owning_class,
860 const
bool zero_dst_vector = false) const;
865 template <
typename CLASS,
typename OutVector,
typename InVector>
871 const
std::pair<unsigned
int, unsigned
int> &),
872 CLASS * owning_class,
875 const
bool zero_dst_vector = false) const;
961 template <
typename CLASS,
typename OutVector,
typename InVector>
967 const
std::pair<unsigned
int, unsigned
int> &) const,
968 const CLASS * owning_class,
971 const
std::function<void(const unsigned
int, const unsigned
int)>
972 &operation_before_loop,
973 const
std::function<void(const unsigned
int, const unsigned
int)>
974 & operation_after_loop,
975 const unsigned
int dof_handler_index_pre_post = 0) const;
980 template <
typename CLASS,
typename OutVector,
typename InVector>
986 const
std::pair<unsigned
int, unsigned
int> &),
987 CLASS * owning_class,
990 const
std::function<void(const unsigned
int, const unsigned
int)>
991 &operation_before_loop,
992 const
std::function<void(const unsigned
int, const unsigned
int)>
993 & operation_after_loop,
994 const unsigned
int dof_handler_index_pre_post = 0) const;
1000 template <
typename OutVector,
typename InVector>
1006 const std::pair<unsigned int, unsigned int> &)> &cell_operation,
1008 const InVector & src,
1009 const std::function<
void(
const unsigned int,
const unsigned int)>
1010 &operation_before_loop,
1011 const std::function<
void(
const unsigned int,
const unsigned int)>
1012 & operation_after_loop,
1013 const unsigned int dof_handler_index_pre_post = 0)
const;
1090 template <
typename OutVector,
typename InVector>
1096 const std::pair<unsigned int, unsigned int> &)> &cell_operation,
1097 const std::function<
1101 const std::pair<unsigned int, unsigned int> &)> &face_operation,
1102 const std::function<
void(
1106 const std::pair<unsigned int, unsigned int> &)> &boundary_operation,
1108 const InVector & src,
1109 const bool zero_dst_vector =
false,
1200 template <
typename CLASS,
typename OutVector,
typename InVector>
1203 void (CLASS::*cell_operation)(const
MatrixFree &,
1206 const
std::pair<unsigned
int, unsigned
int> &)
1208 void (CLASS::*face_operation)(const
MatrixFree &,
1211 const
std::pair<unsigned
int, unsigned
int> &)
1213 void (CLASS::*boundary_operation)(
1217 const
std::pair<unsigned
int, unsigned
int> &) const,
1218 const CLASS * owning_class,
1220 const InVector & src,
1221 const
bool zero_dst_vector = false,
1230 template <
typename CLASS,
typename OutVector,
typename InVector>
1232 loop(
void (CLASS::*cell_operation)(
1236 const
std::pair<unsigned
int, unsigned
int> &),
1237 void (CLASS::*face_operation)(
1241 const
std::pair<unsigned
int, unsigned
int> &),
1242 void (CLASS::*boundary_operation)(
1246 const
std::pair<unsigned
int, unsigned
int> &),
1247 CLASS * owning_class,
1249 const InVector & src,
1250 const
bool zero_dst_vector = false,
1375 template <
typename CLASS,
typename OutVector,
typename InVector>
1378 void (CLASS::*cell_operation)(const
MatrixFree &,
1381 const
std::pair<unsigned
int, unsigned
int> &)
1383 void (CLASS::*face_operation)(const
MatrixFree &,
1386 const
std::pair<unsigned
int, unsigned
int> &)
1388 void (CLASS::*boundary_operation)(
1392 const
std::pair<unsigned
int, unsigned
int> &) const,
1393 const CLASS * owning_class,
1395 const InVector &src,
1396 const
std::function<void(const unsigned
int, const unsigned
int)>
1397 &operation_before_loop,
1398 const
std::function<void(const unsigned
int, const unsigned
int)>
1399 & operation_after_loop,
1400 const unsigned
int dof_handler_index_pre_post = 0,
1409 template <
typename CLASS,
typename OutVector,
typename InVector>
1411 loop(
void (CLASS::*cell_operation)(
1415 const
std::pair<unsigned
int, unsigned
int> &),
1416 void (CLASS::*face_operation)(
1420 const
std::pair<unsigned
int, unsigned
int> &),
1421 void (CLASS::*boundary_operation)(
1425 const
std::pair<unsigned
int, unsigned
int> &),
1426 const CLASS * owning_class,
1428 const InVector &src,
1429 const
std::function<void(const unsigned
int, const unsigned
int)>
1430 &operation_before_loop,
1431 const
std::function<void(const unsigned
int, const unsigned
int)>
1432 & operation_after_loop,
1433 const unsigned
int dof_handler_index_pre_post = 0,
1444 template <
typename OutVector,
typename InVector>
1450 const std::pair<unsigned int, unsigned int> &)> &cell_operation,
1451 const std::function<
1455 const std::pair<unsigned int, unsigned int> &)> &face_operation,
1456 const std::function<
void(
1460 const std::pair<unsigned int, unsigned int> &)> &boundary_operation,
1462 const InVector & src,
1463 const std::function<
void(
const unsigned int,
const unsigned int)>
1464 &operation_before_loop,
1465 const std::function<
void(
const unsigned int,
const unsigned int)>
1466 & operation_after_loop,
1467 const unsigned int dof_handler_index_pre_post = 0,
1537 template <
typename CLASS,
typename OutVector,
typename InVector>
1543 const
std::pair<unsigned
int, unsigned
int> &) const,
1544 const CLASS * owning_class,
1546 const InVector & src,
1547 const
bool zero_dst_vector = false,
1554 template <
typename CLASS,
typename OutVector,
typename InVector>
1560 const
std::pair<unsigned
int, unsigned
int> &),
1561 CLASS * owning_class,
1563 const InVector & src,
1564 const
bool zero_dst_vector = false,
1571 template <
typename OutVector,
typename InVector>
1577 const std::pair<unsigned int, unsigned int> &)>
1580 const InVector & src,
1581 const bool zero_dst_vector =
false,
1592 std::pair<unsigned int, unsigned int>
1594 const unsigned int fe_degree,
1595 const unsigned int dof_handler_index = 0)
const;
1603 std::pair<unsigned int, unsigned int>
1605 const std::pair<unsigned int, unsigned int> &range,
1606 const unsigned int fe_index,
1607 const unsigned int dof_handler_index = 0)
const;
1620 const std::pair<unsigned int, unsigned int> range)
const;
1627 const bool is_interior_face =
true)
const;
1640 template <
typename T>
1649 template <
typename T>
1666 template <
typename VectorType>
1669 const unsigned int dof_handler_index = 0)
const;
1688 template <
typename Number2>
1691 const unsigned int dof_handler_index = 0)
const;
1703 const std::shared_ptr<const Utilities::MPI::Partitioner> &
1727 const std::vector<unsigned int> &
1742 const unsigned int dof_handler_index = 0);
1753 template <
int spacedim>
1852 const unsigned int face_number)
const;
1884 const unsigned int lane_index,
1885 const unsigned int dof_handler_index = 0)
const;
1894 const unsigned int lane_index)
const;
1918 std::pair<typename DoFHandler<dim>::cell_iterator,
unsigned int>
1920 const unsigned int lane_index,
1921 const bool interior =
true,
1922 const unsigned int fe_component = 0)
const;
1968 const unsigned int hp_active_fe_index = 0)
const;
1975 const unsigned int hp_active_fe_index = 0)
const;
1983 const unsigned int hp_active_fe_index = 0)
const;
1991 const unsigned int hp_active_fe_index = 0)
const;
1998 const unsigned int hp_active_fe_index = 0)
const;
2005 const unsigned int hp_active_fe_index = 0)
const;
2021 const std::pair<unsigned int, unsigned int> cell_batch_range)
const;
2027 std::pair<unsigned int, unsigned int>
2029 const std::pair<unsigned int, unsigned int> face_batch_range)
const;
2049 std::pair<unsigned int, unsigned int>
2083 template <
typename StreamType>
2111 const internal::MatrixFreeFunctions::
2112 MappingInfo<dim, Number, VectorizedArrayType> &
2147 const unsigned int quad_index = 0,
2148 const unsigned int fe_base_element = 0,
2149 const unsigned int hp_active_fe_index = 0,
2150 const unsigned int hp_active_quad_index = 0)
const;
2156 VectorizedArrayType::size()> &
2216 template <
typename number2,
int q_dim>
2222 const std::vector<IndexSet> & locally_owned_set,
2232 template <
typename number2>
2236 const std::vector<IndexSet> & locally_owned_set,
2264 std::vector<internal::MatrixFreeFunctions::DoFInfo>
dof_info;
2347 std::list<std::pair<bool, AlignedVector<VectorizedArrayType>>>>
2354 mutable std::list<std::pair<bool, AlignedVector<Number>>>
2371template <
int dim,
typename Number,
typename VectorizedArrayType>
2372template <
typename T>
2377 vec.
resize(this->n_cell_batches() + this->n_ghost_cell_batches());
2382template <
int dim,
typename Number,
typename VectorizedArrayType>
2383template <
typename T>
2388 vec.
resize(this->n_inner_face_batches() + this->n_boundary_face_batches() +
2389 this->n_ghost_inner_face_batches());
2394template <
int dim,
typename Number,
typename VectorizedArrayType>
2395template <
typename VectorType>
2399 const unsigned int comp)
const
2402 "This function is not supported for block vectors.");
2404 Assert(task_info.n_procs == 1,
2405 ExcMessage(
"This function can only be used in serial."));
2408 vec.reinit(dof_info[comp].vector_partitioner->size());
2413template <
int dim,
typename Number,
typename VectorizedArrayType>
2414template <
typename Number2>
2418 const unsigned int comp)
const
2421 vec.
reinit(dof_info[comp].vector_partitioner, task_info.communicator_sm);
2426template <
int dim,
typename Number,
typename VectorizedArrayType>
2427inline const std::shared_ptr<const Utilities::MPI::Partitioner> &
2429 const unsigned int comp)
const
2432 return dof_info[comp].vector_partitioner;
2437template <
int dim,
typename Number,
typename VectorizedArrayType>
2438inline const std::vector<unsigned int> &
2440 const unsigned int comp)
const
2443 return dof_info[comp].constrained_dofs;
2448template <
int dim,
typename Number,
typename VectorizedArrayType>
2453 return dof_handlers.size();
2458template <
int dim,
typename Number,
typename VectorizedArrayType>
2461 const unsigned int dof_no)
const
2465 return dof_handlers[dof_no]->get_fe().n_base_elements();
2470template <
int dim,
typename Number,
typename VectorizedArrayType>
2479template <
int dim,
typename Number,
typename VectorizedArrayType>
2483 return task_info.n_active_cells;
2488template <
int dim,
typename Number,
typename VectorizedArrayType>
2492 return *(task_info.cell_partition_data.end() - 2);
2497template <
int dim,
typename Number,
typename VectorizedArrayType>
2501 return *(task_info.cell_partition_data.end() - 1) -
2502 *(task_info.cell_partition_data.end() - 2);
2507template <
int dim,
typename Number,
typename VectorizedArrayType>
2511 if (task_info.face_partition_data.size() == 0)
2513 return task_info.face_partition_data.back();
2518template <
int dim,
typename Number,
typename VectorizedArrayType>
2522 if (task_info.face_partition_data.size() == 0)
2524 return task_info.boundary_partition_data.back() -
2525 task_info.face_partition_data.back();
2530template <
int dim,
typename Number,
typename VectorizedArrayType>
2534 if (task_info.face_partition_data.size() == 0)
2536 return face_info.faces.size() - task_info.boundary_partition_data.back();
2541template <
int dim,
typename Number,
typename VectorizedArrayType>
2544 const unsigned int face_batch_index)
const
2546 Assert(face_batch_index >= task_info.boundary_partition_data[0] &&
2547 face_batch_index < task_info.boundary_partition_data.back(),
2549 task_info.boundary_partition_data[0],
2550 task_info.boundary_partition_data.back()));
2556template <
int dim,
typename Number,
typename VectorizedArrayType>
2559 const unsigned int cell_batch_index,
2560 const unsigned int face_number)
const
2564 Assert(face_info.cell_and_face_boundary_id.size(0) >= n_cell_batches(),
2568 for (
unsigned int v = 0;
2569 v < n_active_entries_per_cell_batch(cell_batch_index);
2572 face_info.cell_and_face_boundary_id(cell_batch_index, face_number, v);
2578template <
int dim,
typename Number,
typename VectorizedArrayType>
2579inline const internal::MatrixFreeFunctions::
2580 MappingInfo<dim, Number, VectorizedArrayType> &
2583 return mapping_info;
2588template <
int dim,
typename Number,
typename VectorizedArrayType>
2591 const unsigned int dof_index)
const
2594 return dof_info[dof_index];
2599template <
int dim,
typename Number,
typename VectorizedArrayType>
2603 return constraint_pool_row_index.size() - 1;
2608template <
int dim,
typename Number,
typename VectorizedArrayType>
2609inline const Number *
2611 const unsigned int row)
const
2614 return constraint_pool_data.empty() ?
2616 constraint_pool_data.data() + constraint_pool_row_index[row];
2621template <
int dim,
typename Number,
typename VectorizedArrayType>
2622inline const Number *
2624 const unsigned int row)
const
2627 return constraint_pool_data.empty() ?
2629 constraint_pool_data.data() + constraint_pool_row_index[row + 1];
2634template <
int dim,
typename Number,
typename VectorizedArrayType>
2635inline std::pair<unsigned int, unsigned int>
2637 const std::pair<unsigned int, unsigned int> &range,
2638 const unsigned int degree,
2639 const unsigned int dof_handler_component)
const
2641 if (dof_info[dof_handler_component].cell_active_fe_index.empty())
2644 dof_info[dof_handler_component].fe_index_conversion.size(), 1);
2646 dof_info[dof_handler_component].fe_index_conversion[0].size(), 1);
2647 if (dof_info[dof_handler_component].fe_index_conversion[0][0] == degree)
2650 return {range.second, range.second};
2654 dof_info[dof_handler_component].fe_index_from_degree(0, degree);
2655 if (fe_index >= dof_info[dof_handler_component].max_fe_index)
2656 return {range.second, range.second};
2658 return create_cell_subrange_hp_by_index(range,
2660 dof_handler_component);
2665template <
int dim,
typename Number,
typename VectorizedArrayType>
2668 const unsigned int cell_batch_index)
const
2671 return VectorizedArrayType::size() > 1 &&
2672 cell_level_index[(cell_batch_index + 1) * VectorizedArrayType::size() -
2673 1] == cell_level_index[(cell_batch_index + 1) *
2674 VectorizedArrayType::size() -
2680template <
int dim,
typename Number,
typename VectorizedArrayType>
2684 return shape_info.size(2);
2688template <
int dim,
typename Number,
typename VectorizedArrayType>
2691 const std::pair<unsigned int, unsigned int> range)
const
2693 const auto &fe_indices = dof_info[0].cell_active_fe_index;
2695 if (fe_indices.empty() ==
true)
2698 const auto index = fe_indices[range.first];
2700 for (
unsigned int i = range.first; i < range.second; ++i)
2708template <
int dim,
typename Number,
typename VectorizedArrayType>
2711 const std::pair<unsigned int, unsigned int> range,
2712 const bool is_interior_face)
const
2714 const auto &fe_indices = dof_info[0].cell_active_fe_index;
2716 if (fe_indices.empty() ==
true)
2719 if (is_interior_face)
2721 const unsigned int index =
2722 fe_indices[face_info.faces[range.first].cells_interior[0] /
2723 VectorizedArrayType::size()];
2725 for (
unsigned int i = range.first; i < range.second; ++i)
2727 fe_indices[face_info.faces[i].cells_interior[0] /
2728 VectorizedArrayType::size()]);
2734 const unsigned int index =
2735 fe_indices[face_info.faces[range.first].cells_exterior[0] /
2736 VectorizedArrayType::size()];
2738 for (
unsigned int i = range.first; i < range.second; ++i)
2740 fe_indices[face_info.faces[i].cells_exterior[0] /
2741 VectorizedArrayType::size()]);
2749template <
int dim,
typename Number,
typename VectorizedArrayType>
2752 const unsigned int cell_batch_index)
const
2756 const std::vector<unsigned char> &n_lanes_filled =
2757 dof_info[0].n_vectorization_lanes_filled
2761 return n_lanes_filled[cell_batch_index];
2766template <
int dim,
typename Number,
typename VectorizedArrayType>
2769 const unsigned int face_batch_index)
const
2773 const std::vector<unsigned char> &n_lanes_filled =
2774 dof_info[0].n_vectorization_lanes_filled
2777 return n_lanes_filled[face_batch_index];
2782template <
int dim,
typename Number,
typename VectorizedArrayType>
2785 const unsigned int dof_handler_index,
2786 const unsigned int active_fe_index)
const
2788 return dof_info[dof_handler_index].dofs_per_cell[active_fe_index];
2793template <
int dim,
typename Number,
typename VectorizedArrayType>
2796 const unsigned int quad_index,
2797 const unsigned int active_fe_index)
const
2800 return mapping_info.cell_data[quad_index]
2801 .descriptor[active_fe_index]
2807template <
int dim,
typename Number,
typename VectorizedArrayType>
2810 const unsigned int dof_handler_index,
2811 const unsigned int active_fe_index)
const
2813 return dof_info[dof_handler_index].dofs_per_face[active_fe_index];
2818template <
int dim,
typename Number,
typename VectorizedArrayType>
2821 const unsigned int quad_index,
2822 const unsigned int active_fe_index)
const
2825 return mapping_info.face_data[quad_index]
2826 .descriptor[active_fe_index]
2832template <
int dim,
typename Number,
typename VectorizedArrayType>
2835 const unsigned int dof_handler_index)
const
2837 return dof_info[dof_handler_index].vector_partitioner->locally_owned_range();
2842template <
int dim,
typename Number,
typename VectorizedArrayType>
2845 const unsigned int dof_handler_index)
const
2847 return dof_info[dof_handler_index].vector_partitioner->ghost_indices();
2852template <
int dim,
typename Number,
typename VectorizedArrayType>
2855 const unsigned int dof_handler_index,
2856 const unsigned int index_quad,
2857 const unsigned int index_fe,
2858 const unsigned int active_fe_index,
2859 const unsigned int active_quad_index)
const
2862 const unsigned int ind =
2863 dof_info[dof_handler_index].global_base_element_offset + index_fe;
2868 return shape_info(ind, index_quad, active_fe_index, active_quad_index);
2873template <
int dim,
typename Number,
typename VectorizedArrayType>
2875 VectorizedArrayType::size()> &
2877 const unsigned int face_batch_index)
const
2880 return face_info.faces[face_batch_index];
2885template <
int dim,
typename Number,
typename VectorizedArrayType>
2890 return face_info.cell_and_face_to_plain_faces;
2895template <
int dim,
typename Number,
typename VectorizedArrayType>
2898 const unsigned int quad_index,
2899 const unsigned int active_fe_index)
const
2902 return mapping_info.cell_data[quad_index]
2903 .descriptor[active_fe_index]
2909template <
int dim,
typename Number,
typename VectorizedArrayType>
2912 const unsigned int quad_index,
2913 const unsigned int active_fe_index)
const
2916 return mapping_info.face_data[quad_index]
2917 .descriptor[active_fe_index]
2923template <
int dim,
typename Number,
typename VectorizedArrayType>
2926 const std::pair<unsigned int, unsigned int> range)
const
2928 auto result = get_cell_category(range.first);
2930 for (
unsigned int i = range.first; i < range.second; ++i)
2931 result =
std::max(result, get_cell_category(i));
2938template <
int dim,
typename Number,
typename VectorizedArrayType>
2939inline std::pair<unsigned int, unsigned int>
2941 const std::pair<unsigned int, unsigned int> range)
const
2943 auto result = get_face_category(range.first);
2945 for (
unsigned int i = range.first; i < range.second; ++i)
2947 result.first =
std::max(result.first, get_face_category(i).
first);
2948 result.second =
std::max(result.second, get_face_category(i).
second);
2956template <
int dim,
typename Number,
typename VectorizedArrayType>
2959 const unsigned int cell_batch_index)
const
2962 AssertIndexRange(cell_batch_index, dof_info[0].cell_active_fe_index.size());
2963 if (dof_info[0].cell_active_fe_index.empty())
2966 return dof_info[0].cell_active_fe_index[cell_batch_index];
2971template <
int dim,
typename Number,
typename VectorizedArrayType>
2972inline std::pair<unsigned int, unsigned int>
2974 const unsigned int face_batch_index)
const
2977 if (dof_info[0].cell_active_fe_index.empty())
2978 return std::make_pair(0U, 0U);
2980 std::pair<unsigned int, unsigned int> result = std::make_pair(0U, 0U);
2981 for (
unsigned int v = 0;
2982 v < VectorizedArrayType::size() &&
2983 face_info.faces[face_batch_index].cells_interior[v] !=
2988 dof_info[0].cell_active_fe_index[face_info.faces[face_batch_index]
2989 .cells_interior[v] /
2990 VectorizedArrayType::size()]);
2991 if (face_info.faces[face_batch_index].cells_exterior[0] !=
2993 for (
unsigned int v = 0;
2994 v < VectorizedArrayType::size() &&
2995 face_info.faces[face_batch_index].cells_exterior[v] !=
3000 dof_info[0].cell_active_fe_index[face_info.faces[face_batch_index]
3001 .cells_exterior[v] /
3002 VectorizedArrayType::size()]);
3010template <
int dim,
typename Number,
typename VectorizedArrayType>
3014 return indices_are_initialized;
3019template <
int dim,
typename Number,
typename VectorizedArrayType>
3023 return mapping_is_initialized;
3027template <
int dim,
typename Number,
typename VectorizedArrayType>
3036template <
int dim,
typename Number,
typename VectorizedArrayType>
3041 std::list<std::pair<bool, AlignedVector<VectorizedArrayType>>>;
3042 list_type &data = scratch_pad.get();
3043 for (
typename list_type::iterator it = data.begin(); it != data.end(); ++it)
3044 if (it->first ==
false)
3050 return &data.front().second;
3055template <
int dim,
typename Number,
typename VectorizedArrayType>
3061 std::list<std::pair<bool, AlignedVector<VectorizedArrayType>>>;
3062 list_type &data = scratch_pad.get();
3063 for (
typename list_type::iterator it = data.begin(); it != data.end(); ++it)
3064 if (&it->second == scratch)
3075template <
int dim,
typename Number,
typename VectorizedArrayType>
3081 scratch_pad_non_threadsafe.
begin();
3082 it != scratch_pad_non_threadsafe.end();
3084 if (it->first ==
false)
3089 scratch_pad_non_threadsafe.push_front(
3091 return &scratch_pad_non_threadsafe.front().second;
3096template <
int dim,
typename Number,
typename VectorizedArrayType>
3103 scratch_pad_non_threadsafe.
begin();
3104 it != scratch_pad_non_threadsafe.end();
3106 if (&it->second == scratch)
3121 namespace MatrixFreeImplementation
3123 template <
int dim,
int spacedim>
3124 inline std::vector<IndexSet>
3125 extract_locally_owned_index_sets(
3127 const unsigned int level)
3129 std::vector<IndexSet> locally_owned_set;
3130 locally_owned_set.reserve(dofh.size());
3131 for (
unsigned int j = 0; j < dofh.size(); ++j)
3133 locally_owned_set.push_back(dofh[j]->locally_owned_dofs());
3135 locally_owned_set.push_back(dofh[j]->locally_owned_mg_dofs(
level));
3136 return locally_owned_set;
3143template <
int dim,
typename Number,
typename VectorizedArrayType>
3144template <
typename QuadratureType,
typename number2,
typename MappingType>
3147 const MappingType & mapping,
3150 const QuadratureType & quad,
3154 std::vector<const DoFHandler<dim, dim> *> dof_handlers;
3155 std::vector<const AffineConstraints<number2> *> constraints;
3157 dof_handlers.push_back(&dof_handler);
3158 constraints.push_back(&constraints_in);
3160 std::vector<IndexSet> locally_owned_sets =
3161 internal::MatrixFreeImplementation::extract_locally_owned_index_sets(
3162 dof_handlers, additional_data.
mg_level);
3164 std::vector<hp::QCollection<dim>> quad_hp;
3165 quad_hp.emplace_back(quad);
3177template <
int dim,
typename Number,
typename VectorizedArrayType>
3178template <
typename QuadratureType,
typename number2,
typename MappingType>
3181 const MappingType & mapping,
3184 const QuadratureType & quad,
3188 std::vector<IndexSet> locally_owned_set =
3189 internal::MatrixFreeImplementation::extract_locally_owned_index_sets(
3190 dof_handler, additional_data.
mg_level);
3191 std::vector<hp::QCollection<dim>> quad_hp;
3192 quad_hp.emplace_back(quad);
3204template <
int dim,
typename Number,
typename VectorizedArrayType>
3205template <
typename QuadratureType,
typename number2,
typename MappingType>
3208 const MappingType & mapping,
3211 const std::vector<QuadratureType> & quad,
3215 std::vector<IndexSet> locally_owned_set =
3216 internal::MatrixFreeImplementation::extract_locally_owned_index_sets(
3217 dof_handler, additional_data.
mg_level);
3218 std::vector<hp::QCollection<dim>> quad_hp;
3219 for (
unsigned int q = 0; q < quad.size(); ++q)
3220 quad_hp.emplace_back(quad[q]);
3247 template <
int dim,
typename Number,
typename VectorizedArrayType>
3248 struct VectorDataExchange
3255 static constexpr unsigned int channel_shift = 20;
3264 const ::MatrixFree<dim, Number, VectorizedArrayType> &matrix_free,
3265 const typename ::MatrixFree<dim, Number, VectorizedArrayType>::
3266 DataAccessOnFaces vector_face_access,
3267 const unsigned
int n_components)
3268 : matrix_free(matrix_free)
3269 , vector_face_access(
3270 matrix_free.get_task_info().face_partition_data.empty() ?
3271 ::
MatrixFree<dim, Number, VectorizedArrayType>::
3272 DataAccessOnFaces::unspecified :
3274 , ghosts_were_set(false)
3275# ifdef DEAL_II_WITH_MPI
3276 , tmp_data(n_components)
3277 , requests(n_components)
3281 if (this->vector_face_access !=
3283 DataAccessOnFaces::unspecified)
3284 for (unsigned
int c = 0; c < matrix_free.n_components(); ++c)
3286 matrix_free.get_dof_info(c).vector_exchanger_face_variants.size(),
3295 ~VectorDataExchange()
3297# ifdef DEAL_II_WITH_MPI
3298 for (
unsigned int i = 0; i < tmp_data.size(); ++i)
3299 if (tmp_data[i] !=
nullptr)
3300 matrix_free.release_scratch_data_non_threadsafe(tmp_data[i]);
3310 template <
typename VectorType>
3312 find_vector_in_mf(
const VectorType &vec,
3313 const bool check_global_compatibility =
true)
const
3316 for (
unsigned int c = 0; c < matrix_free.n_components(); ++c)
3317 if (vec.get_partitioner().get() ==
3318 matrix_free.get_dof_info(c).vector_partitioner.get())
3322 for (
unsigned int c = 0; c < matrix_free.n_components(); ++c)
3323 if (check_global_compatibility ?
3324 vec.get_partitioner()->is_globally_compatible(
3325 *matrix_free.get_dof_info(c).vector_partitioner) :
3326 vec.get_partitioner()->is_compatible(
3327 *matrix_free.get_dof_info(c).vector_partitioner))
3343 get_partitioner(
const unsigned int mf_component)
const
3346 .vector_exchanger_face_variants.size(),
3348 if (vector_face_access ==
3350 DataAccessOnFaces::
none)
3351 return *matrix_free.get_dof_info(mf_component)
3352 .vector_exchanger_face_variants[0];
3353 else if (vector_face_access ==
3355 DataAccessOnFaces::
values)
3356 return *matrix_free.get_dof_info(mf_component)
3357 .vector_exchanger_face_variants[1];
3358 else if (vector_face_access ==
3361 return *matrix_free.get_dof_info(mf_component)
3362 .vector_exchanger_face_variants[2];
3363 else if (vector_face_access ==
3365 DataAccessOnFaces::values_all_faces)
3366 return *matrix_free.get_dof_info(mf_component)
3367 .vector_exchanger_face_variants[3];
3368 else if (vector_face_access ==
3370 DataAccessOnFaces::gradients_all_faces)
3371 return *matrix_free.get_dof_info(mf_component)
3372 .vector_exchanger_face_variants[4];
3374 return *matrix_free.get_dof_info(mf_component).vector_exchanger.get();
3382 template <
typename VectorType,
3383 std::enable_if_t<is_not_parallel_vector<VectorType>, VectorType>
3386 update_ghost_values_start(
const unsigned int ,
3387 const VectorType & )
3395 template <
typename VectorType,
3396 std::enable_if_t<!has_update_ghost_values_start<VectorType> &&
3397 !is_not_parallel_vector<VectorType>,
3398 VectorType> * =
nullptr>
3400 update_ghost_values_start(
const unsigned int component_in_block_vector,
3401 const VectorType & vec)
3403 (void)component_in_block_vector;
3404 const bool ghosts_set = vec.has_ghost_elements();
3406 Assert(matrix_free.get_task_info().allow_ghosted_vectors_in_loops ||
3407 ghosts_set ==
false,
3411 ghosts_were_set =
true;
3413 vec.update_ghost_values();
3423 template <
typename VectorType,
3424 std::enable_if_t<has_update_ghost_values_start<VectorType> &&
3425 !has_exchange_on_subset<VectorType>,
3426 VectorType> * =
nullptr>
3428 update_ghost_values_start(
const unsigned int component_in_block_vector,
3429 const VectorType & vec)
3431 (void)component_in_block_vector;
3432 const bool ghosts_set = vec.has_ghost_elements();
3434 Assert(matrix_free.get_task_info().allow_ghosted_vectors_in_loops ||
3435 ghosts_set ==
false,
3439 ghosts_were_set =
true;
3441 vec.update_ghost_values_start(component_in_block_vector + channel_shift);
3452 template <
typename VectorType,
3453 std::enable_if_t<has_update_ghost_values_start<VectorType> &&
3454 has_exchange_on_subset<VectorType>,
3455 VectorType> * =
nullptr>
3457 update_ghost_values_start(
const unsigned int component_in_block_vector,
3458 const VectorType & vec)
3461 std::is_same<Number, typename VectorType::value_type>::value,
3462 "Type mismatch between VectorType and VectorDataExchange");
3463 (void)component_in_block_vector;
3464 const bool ghosts_set = vec.has_ghost_elements();
3466 Assert(matrix_free.get_task_info().allow_ghosted_vectors_in_loops ||
3467 ghosts_set ==
false,
3471 ghosts_were_set =
true;
3473 if (vec.size() != 0)
3475# ifdef DEAL_II_WITH_MPI
3476 const unsigned int mf_component = find_vector_in_mf(vec);
3478 const auto &part = get_partitioner(mf_component);
3480 if (part.n_ghost_indices() == 0 && part.n_import_indices() == 0 &&
3481 part.n_import_sm_procs() == 0)
3484 tmp_data[component_in_block_vector] =
3485 matrix_free.acquire_scratch_data_non_threadsafe();
3486 tmp_data[component_in_block_vector]->resize_fast(
3487 part.n_import_indices());
3490 part.export_to_ghosted_array_start(
3491 component_in_block_vector * 2 + channel_shift,
3493 vec.shared_vector_data(),
3495 part.locally_owned_size(),
3496 matrix_free.get_dof_info(mf_component)
3497 .vector_partitioner->n_ghost_indices()),
3499 part.n_import_indices()),
3500 this->requests[component_in_block_vector]);
3511 template <
typename VectorType,
3512 std::enable_if_t<!has_update_ghost_values_start<VectorType>,
3513 VectorType> * =
nullptr>
3515 update_ghost_values_finish(
const unsigned int ,
3516 const VectorType & )
3526 template <
typename VectorType,
3527 std::enable_if_t<has_update_ghost_values_start<VectorType> &&
3528 !has_exchange_on_subset<VectorType>,
3529 VectorType> * =
nullptr>
3531 update_ghost_values_finish(
const unsigned int component_in_block_vector,
3532 const VectorType & vec)
3534 (void)component_in_block_vector;
3535 vec.update_ghost_values_finish();
3546 template <
typename VectorType,
3547 std::enable_if_t<has_update_ghost_values_start<VectorType> &&
3548 has_exchange_on_subset<VectorType>,
3549 VectorType> * =
nullptr>
3551 update_ghost_values_finish(
const unsigned int component_in_block_vector,
3552 const VectorType & vec)
3555 std::is_same<Number, typename VectorType::value_type>::value,
3556 "Type mismatch between VectorType and VectorDataExchange");
3557 (void)component_in_block_vector;
3559 if (vec.size() != 0)
3561# ifdef DEAL_II_WITH_MPI
3565 const unsigned int mf_component = find_vector_in_mf(vec);
3567 const auto &part = get_partitioner(mf_component);
3569 if (part.n_ghost_indices() != 0 || part.n_import_indices() != 0 ||
3570 part.n_import_sm_procs() != 0)
3572 part.export_to_ghosted_array_finish(
3574 vec.shared_vector_data(),
3576 part.locally_owned_size(),
3577 matrix_free.get_dof_info(mf_component)
3578 .vector_partitioner->n_ghost_indices()),
3579 this->requests[component_in_block_vector]);
3581 matrix_free.release_scratch_data_non_threadsafe(
3582 tmp_data[component_in_block_vector]);
3583 tmp_data[component_in_block_vector] =
nullptr;
3589 vec.set_ghost_state(
true);
3597 template <
typename VectorType,
3598 std::enable_if_t<is_not_parallel_vector<VectorType>, VectorType>
3601 compress_start(
const unsigned int ,
3611 template <
typename VectorType,
3612 std::enable_if_t<!has_compress_start<VectorType> &&
3613 !is_not_parallel_vector<VectorType>,
3614 VectorType> * =
nullptr>
3616 compress_start(
const unsigned int component_in_block_vector,
3619 (void)component_in_block_vector;
3631 template <
typename VectorType,
3632 std::enable_if_t<has_compress_start<VectorType> &&
3633 !has_exchange_on_subset<VectorType>,
3634 VectorType> * =
nullptr>
3636 compress_start(
const unsigned int component_in_block_vector,
3639 (void)component_in_block_vector;
3641 vec.compress_start(component_in_block_vector + channel_shift);
3652 template <
typename VectorType,
3653 std::enable_if_t<has_compress_start<VectorType> &&
3654 has_exchange_on_subset<VectorType>,
3655 VectorType> * =
nullptr>
3657 compress_start(
const unsigned int component_in_block_vector,
3661 std::is_same<Number, typename VectorType::value_type>::value,
3662 "Type mismatch between VectorType and VectorDataExchange");
3663 (void)component_in_block_vector;
3666 if (vec.size() != 0)
3668# ifdef DEAL_II_WITH_MPI
3669 const unsigned int mf_component = find_vector_in_mf(vec);
3671 const auto &part = get_partitioner(mf_component);
3673 if (part.n_ghost_indices() == 0 && part.n_import_indices() == 0 &&
3674 part.n_import_sm_procs() == 0)
3677 tmp_data[component_in_block_vector] =
3678 matrix_free.acquire_scratch_data_non_threadsafe();
3679 tmp_data[component_in_block_vector]->resize_fast(
3680 part.n_import_indices());
3683 part.import_from_ghosted_array_start(
3685 component_in_block_vector * 2 + channel_shift,
3687 vec.shared_vector_data(),
3689 matrix_free.get_dof_info(mf_component)
3690 .vector_partitioner->n_ghost_indices()),
3692 part.n_import_indices()),
3693 this->requests[component_in_block_vector]);
3705 typename VectorType,
3706 std::enable_if_t<!has_compress_start<VectorType>, VectorType> * =
nullptr>
3708 compress_finish(
const unsigned int ,
3719 template <
typename VectorType,
3720 std::enable_if_t<has_compress_start<VectorType> &&
3721 !has_exchange_on_subset<VectorType>,
3722 VectorType> * =
nullptr>
3724 compress_finish(
const unsigned int component_in_block_vector,
3727 (void)component_in_block_vector;
3739 template <
typename VectorType,
3740 std::enable_if_t<has_compress_start<VectorType> &&
3741 has_exchange_on_subset<VectorType>,
3742 VectorType> * =
nullptr>
3744 compress_finish(
const unsigned int component_in_block_vector,
3748 std::is_same<Number, typename VectorType::value_type>::value,
3749 "Type mismatch between VectorType and VectorDataExchange");
3750 (void)component_in_block_vector;
3751 if (vec.size() != 0)
3753# ifdef DEAL_II_WITH_MPI
3757 const unsigned int mf_component = find_vector_in_mf(vec);
3759 const auto &part = get_partitioner(mf_component);
3761 if (part.n_ghost_indices() != 0 || part.n_import_indices() != 0 ||
3762 part.n_import_sm_procs() != 0)
3764 part.import_from_ghosted_array_finish(
3767 vec.shared_vector_data(),
3769 matrix_free.get_dof_info(mf_component)
3770 .vector_partitioner->n_ghost_indices()),
3772 tmp_data[component_in_block_vector]->begin(),
3773 part.n_import_indices()),
3774 this->requests[component_in_block_vector]);
3776 matrix_free.release_scratch_data_non_threadsafe(
3777 tmp_data[component_in_block_vector]);
3778 tmp_data[component_in_block_vector] =
nullptr;
3784 MPI_Barrier(matrix_free.get_task_info().communicator_sm);
3796 template <
typename VectorType,
3797 std::enable_if_t<is_not_parallel_vector<VectorType>, VectorType>
3800 reset_ghost_values(
const VectorType & )
const
3809 template <
typename VectorType,
3810 std::enable_if_t<!has_exchange_on_subset<VectorType> &&
3811 !is_not_parallel_vector<VectorType>,
3812 VectorType> * =
nullptr>
3814 reset_ghost_values(
const VectorType &vec)
const
3816 if (ghosts_were_set ==
true)
3819 vec.zero_out_ghost_values();
3829 template <
typename VectorType,
3830 std::enable_if_t<has_exchange_on_subset<VectorType>, VectorType>
3833 reset_ghost_values(
const VectorType &vec)
const
3836 std::is_same<Number, typename VectorType::value_type>::value,
3837 "Type mismatch between VectorType and VectorDataExchange");
3838 if (ghosts_were_set ==
true)
3841 if (vec.size() != 0)
3843# ifdef DEAL_II_WITH_MPI
3846 const unsigned int mf_component = find_vector_in_mf(vec);
3848 const auto &part = get_partitioner(mf_component);
3850 if (part.n_ghost_indices() > 0)
3855 part.locally_owned_size(),
3856 matrix_free.get_dof_info(mf_component)
3857 .vector_partitioner->n_ghost_indices()));
3863 vec.set_ghost_state(
false);
3873 template <
typename VectorType,
3874 std::enable_if_t<has_exchange_on_subset<VectorType>, VectorType>
3877 zero_vector_region(
const unsigned int range_index, VectorType &vec)
const
3880 std::is_same<Number, typename VectorType::value_type>::value,
3881 "Type mismatch between VectorType and VectorDataExchange");
3886 const unsigned int mf_component = find_vector_in_mf(vec,
false);
3888 matrix_free.get_dof_info(mf_component);
3896 for (
unsigned int id =
3915 template <
typename VectorType,
3916 std::enable_if_t<!has_exchange_on_subset<VectorType>, VectorType>
3918 typename VectorType::value_type * =
nullptr>
3920 zero_vector_region(
const unsigned int range_index, VectorType &vec)
const
3923 vec =
typename VectorType::value_type();
3933 zero_vector_region(
const unsigned int, ...)
const
3937 "which provide VectorType::value_type"));
3942 const ::MatrixFree<dim, Number, VectorizedArrayType> &matrix_free;
3943 const typename ::MatrixFree<dim, Number, VectorizedArrayType>::
3944 DataAccessOnFaces vector_face_access;
3945 bool ghosts_were_set;
3946# ifdef DEAL_II_WITH_MPI
3947 std::vector<AlignedVector<Number> *> tmp_data;
3948 std::vector<std::vector<MPI_Request>> requests;
3952 template <
typename VectorStruct>
3954 n_components(
const VectorStruct &vec);
3956 template <
typename VectorStruct>
3958 n_components_block(
const VectorStruct &vec,
3959 std::integral_constant<bool, true>)
3961 unsigned int components = 0;
3962 for (
unsigned int bl = 0; bl < vec.n_blocks(); ++bl)
3963 components += n_components(vec.block(bl));
3967 template <
typename VectorStruct>
3969 n_components_block(
const VectorStruct &, std::integral_constant<bool, false>)
3974 template <
typename VectorStruct>
3976 n_components(
const VectorStruct &vec)
3978 return n_components_block(
3982 template <
typename VectorStruct>
3984 n_components(
const std::vector<VectorStruct> &vec)
3986 unsigned int components = 0;
3987 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
3988 components += n_components_block(
3994 template <
typename VectorStruct>
3996 n_components(
const std::vector<VectorStruct *> &vec)
3998 unsigned int components = 0;
3999 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4000 components += n_components_block(
4013 template <
typename VectorStruct,
4014 std::enable_if_t<!has_communication_block_size<VectorStruct>,
4015 VectorStruct> * =
nullptr>
4016 constexpr unsigned int
4017 get_communication_block_size(
const VectorStruct &)
4024 template <
typename VectorStruct,
4025 std::enable_if_t<has_communication_block_size<VectorStruct>,
4026 VectorStruct> * =
nullptr>
4027 constexpr unsigned int
4028 get_communication_block_size(
const VectorStruct &)
4030 return VectorStruct::communication_block_size;
4035 template <
typename VectorType,
4036 std::enable_if_t<is_not_parallel_vector<VectorType>, VectorType> * =
4039 has_ghost_elements(
const VectorType &vec)
4047 template <
typename VectorType,
4048 std::enable_if_t<!is_not_parallel_vector<VectorType>, VectorType>
4051 has_ghost_elements(
const VectorType &vec)
4053 return vec.has_ghost_elements();
4068 typename VectorStruct,
4070 typename VectorizedArrayType,
4071 std::enable_if_t<IsBlockVector<VectorStruct>::value, VectorStruct>
4074 update_ghost_values_start(
4075 const VectorStruct & vec,
4076 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger,
4077 const unsigned int channel = 0)
4079 if (get_communication_block_size(vec) < vec.n_blocks())
4081 const bool ghosts_set = vec.has_ghost_elements();
4083 Assert(exchanger.matrix_free.get_task_info()
4084 .allow_ghosted_vectors_in_loops ||
4085 ghosts_set ==
false,
4089 exchanger.ghosts_were_set =
true;
4091 vec.update_ghost_values();
4095 for (
unsigned int i = 0; i < vec.n_blocks(); ++i)
4096 update_ghost_values_start(vec.block(i), exchanger, channel + i);
4104 typename VectorStruct,
4106 typename VectorizedArrayType,
4107 std::enable_if_t<!IsBlockVector<VectorStruct>::value, VectorStruct>
4110 update_ghost_values_start(
4111 const VectorStruct & vec,
4112 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger,
4113 const unsigned int channel = 0)
4115 exchanger.update_ghost_values_start(channel, vec);
4122 typename VectorStruct,
4124 typename VectorizedArrayType>
4126 update_ghost_values_start(
4127 const std::vector<VectorStruct> & vec,
4128 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4130 unsigned int component_index = 0;
4131 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4133 update_ghost_values_start(vec[comp], exchanger, component_index);
4134 component_index += n_components(vec[comp]);
4142 typename VectorStruct,
4144 typename VectorizedArrayType>
4146 update_ghost_values_start(
4147 const std::vector<VectorStruct *> & vec,
4148 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4150 unsigned int component_index = 0;
4151 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4153 update_ghost_values_start(*vec[comp], exchanger, component_index);
4154 component_index += n_components(*vec[comp]);
4166 typename VectorStruct,
4168 typename VectorizedArrayType,
4169 std::enable_if_t<IsBlockVector<VectorStruct>::value, VectorStruct>
4172 update_ghost_values_finish(
4173 const VectorStruct & vec,
4174 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger,
4175 const unsigned int channel = 0)
4177 if (get_communication_block_size(vec) < vec.n_blocks())
4183 for (
unsigned int i = 0; i < vec.n_blocks(); ++i)
4184 update_ghost_values_finish(vec.block(i), exchanger, channel + i);
4191 typename VectorStruct,
4193 typename VectorizedArrayType,
4194 std::enable_if_t<!IsBlockVector<VectorStruct>::value, VectorStruct>
4197 update_ghost_values_finish(
4198 const VectorStruct & vec,
4199 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger,
4200 const unsigned int channel = 0)
4202 exchanger.update_ghost_values_finish(channel, vec);
4209 typename VectorStruct,
4211 typename VectorizedArrayType>
4213 update_ghost_values_finish(
4214 const std::vector<VectorStruct> & vec,
4215 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4217 unsigned int component_index = 0;
4218 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4220 update_ghost_values_finish(vec[comp], exchanger, component_index);
4221 component_index += n_components(vec[comp]);
4229 typename VectorStruct,
4231 typename VectorizedArrayType>
4233 update_ghost_values_finish(
4234 const std::vector<VectorStruct *> & vec,
4235 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4237 unsigned int component_index = 0;
4238 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4240 update_ghost_values_finish(*vec[comp], exchanger, component_index);
4241 component_index += n_components(*vec[comp]);
4253 typename VectorStruct,
4255 typename VectorizedArrayType,
4256 std::enable_if_t<IsBlockVector<VectorStruct>::value, VectorStruct>
4261 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger,
4262 const unsigned int channel = 0)
4264 if (get_communication_block_size(vec) < vec.n_blocks())
4267 for (
unsigned int i = 0; i < vec.n_blocks(); ++i)
4268 compress_start(vec.block(i), exchanger, channel + i);
4275 typename VectorStruct,
4277 typename VectorizedArrayType,
4278 std::enable_if_t<!IsBlockVector<VectorStruct>::value, VectorStruct>
4283 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger,
4284 const unsigned int channel = 0)
4286 exchanger.compress_start(channel, vec);
4293 typename VectorStruct,
4295 typename VectorizedArrayType>
4298 std::vector<VectorStruct> & vec,
4299 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4301 unsigned int component_index = 0;
4302 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4304 compress_start(vec[comp], exchanger, component_index);
4305 component_index += n_components(vec[comp]);
4313 typename VectorStruct,
4315 typename VectorizedArrayType>
4318 std::vector<VectorStruct *> & vec,
4319 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4321 unsigned int component_index = 0;
4322 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4324 compress_start(*vec[comp], exchanger, component_index);
4325 component_index += n_components(*vec[comp]);
4337 typename VectorStruct,
4339 typename VectorizedArrayType,
4340 std::enable_if_t<IsBlockVector<VectorStruct>::value, VectorStruct>
4345 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger,
4346 const unsigned int channel = 0)
4348 if (get_communication_block_size(vec) < vec.n_blocks())
4354 for (
unsigned int i = 0; i < vec.n_blocks(); ++i)
4355 compress_finish(vec.block(i), exchanger, channel + i);
4362 typename VectorStruct,
4364 typename VectorizedArrayType,
4365 std::enable_if_t<!IsBlockVector<VectorStruct>::value, VectorStruct>
4370 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger,
4371 const unsigned int channel = 0)
4373 exchanger.compress_finish(channel, vec);
4380 typename VectorStruct,
4382 typename VectorizedArrayType>
4385 std::vector<VectorStruct> & vec,
4386 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4388 unsigned int component_index = 0;
4389 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4391 compress_finish(vec[comp], exchanger, component_index);
4392 component_index += n_components(vec[comp]);
4400 typename VectorStruct,
4402 typename VectorizedArrayType>
4405 std::vector<VectorStruct *> & vec,
4406 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4408 unsigned int component_index = 0;
4409 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4411 compress_finish(*vec[comp], exchanger, component_index);
4412 component_index += n_components(*vec[comp]);
4428 typename VectorStruct,
4430 typename VectorizedArrayType,
4431 std::enable_if_t<IsBlockVector<VectorStruct>::value, VectorStruct>
4435 const VectorStruct & vec,
4436 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4439 if (exchanger.ghosts_were_set ==
true)
4442 for (
unsigned int i = 0; i < vec.n_blocks(); ++i)
4443 reset_ghost_values(vec.block(i), exchanger);
4450 typename VectorStruct,
4452 typename VectorizedArrayType,
4453 std::enable_if_t<!IsBlockVector<VectorStruct>::value, VectorStruct>
4457 const VectorStruct & vec,
4458 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4460 exchanger.reset_ghost_values(vec);
4467 typename VectorStruct,
4469 typename VectorizedArrayType>
4472 const std::vector<VectorStruct> & vec,
4473 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4476 if (exchanger.ghosts_were_set ==
true)
4479 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4480 reset_ghost_values(vec[comp], exchanger);
4487 typename VectorStruct,
4489 typename VectorizedArrayType>
4492 const std::vector<VectorStruct *> & vec,
4493 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4496 if (exchanger.ghosts_were_set ==
true)
4499 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4500 reset_ghost_values(*vec[comp], exchanger);
4511 typename VectorStruct,
4513 typename VectorizedArrayType,
4514 std::enable_if_t<IsBlockVector<VectorStruct>::value, VectorStruct>
4518 const unsigned int range_index,
4520 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4522 for (
unsigned int i = 0; i < vec.n_blocks(); ++i)
4523 exchanger.zero_vector_region(range_index, vec.block(i));
4530 typename VectorStruct,
4532 typename VectorizedArrayType,
4533 std::enable_if_t<!IsBlockVector<VectorStruct>::value, VectorStruct>
4537 const unsigned int range_index,
4539 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4541 exchanger.zero_vector_region(range_index, vec);
4548 typename VectorStruct,
4550 typename VectorizedArrayType>
4553 const unsigned int range_index,
4554 std::vector<VectorStruct> & vec,
4555 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4557 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4558 zero_vector_region(range_index, vec[comp], exchanger);
4565 typename VectorStruct,
4567 typename VectorizedArrayType>
4570 const unsigned int range_index,
4571 std::vector<VectorStruct *> & vec,
4572 VectorDataExchange<dim, Number, VectorizedArrayType> &exchanger)
4574 for (
unsigned int comp = 0; comp < vec.size(); ++comp)
4575 zero_vector_region(range_index, *vec[comp], exchanger);
4583 template <
typename VectorStruct1,
typename VectorStruct2>
4585 apply_operation_to_constrained_dofs(
const std::vector<unsigned int> &,
4586 const VectorStruct1 &,
4590 template <
typename Number>
4592 apply_operation_to_constrained_dofs(
4593 const std::vector<unsigned int> & constrained_dofs,
4597 for (
const unsigned int i : constrained_dofs)
4598 dst.local_element(i) = src.local_element(i);
4602 namespace MatrixFreeFunctions
4606 template <
typename,
typename,
typename,
typename,
bool>
4607 struct InterfaceSelector
4611 template <
typename MF,
4615 struct InterfaceSelector<MF, InVector, OutVector, Container, true>
4617 using function_type = void (Container::*)(
4621 const
std::pair<unsigned
int, unsigned
int> &) const;
4625 template <
typename MF,
4629 struct InterfaceSelector<MF, InVector, OutVector, Container, false>
4631 using function_type =
4632 void (Container::*)(const MF &,
4635 const
std::pair<unsigned
int, unsigned
int> &);
4643 template <
typename MF,
4648 class MFWorker :
public MFWorkerInterface
4652 using function_type =
typename MatrixFreeFunctions::
4653 InterfaceSelector<MF, InVector, OutVector, Container, is_constant>::
4657 MFWorker(
const MF & matrix_free,
4658 const InVector & src,
4660 const bool zero_dst_vector_setting,
4661 const Container & container,
4662 function_type cell_function,
4663 function_type face_function,
4664 function_type boundary_function,
4665 const typename MF::DataAccessOnFaces src_vector_face_access =
4666 MF::DataAccessOnFaces::none,
4667 const typename MF::DataAccessOnFaces dst_vector_face_access =
4668 MF::DataAccessOnFaces::none,
4669 const std::function<
void(
const unsigned int,
const unsigned int)>
4670 &operation_before_loop = {},
4671 const std::function<void(
const unsigned int,
const unsigned int)>
4672 & operation_after_loop = {},
4673 const unsigned int dof_handler_index_pre_post = 0)
4674 : matrix_free(matrix_free)
4675 , container(const_cast<Container &>(container))
4676 , cell_function(cell_function)
4677 , face_function(face_function)
4678 , boundary_function(boundary_function)
4681 , src_data_exchanger(matrix_free,
4682 src_vector_face_access,
4684 , dst_data_exchanger(matrix_free,
4685 dst_vector_face_access,
4688 , zero_dst_vector_setting(zero_dst_vector_setting &&
4689 !src_and_dst_are_same)
4690 , operation_before_loop(operation_before_loop)
4691 , operation_after_loop(operation_after_loop)
4692 , dof_handler_index_pre_post(dof_handler_index_pre_post)
4694 Assert(!has_ghost_elements(dst),
4695 ExcMessage(
"The destination vector passed to the matrix-free "
4696 "loop is ghosted. This is not allowed."));
4701 cell(
const std::pair<unsigned int, unsigned int> &cell_range)
override
4703 if (cell_function !=
nullptr && cell_range.second > cell_range.first)
4704 for (
unsigned int i = 0; i < matrix_free.n_active_fe_indices(); ++i)
4706 const auto cell_subrange =
4707 matrix_free.create_cell_subrange_hp_by_index(cell_range, i);
4709 if (cell_subrange.second <= cell_subrange.first)
4713 cell_function)(matrix_free, this->dst, this->src, cell_subrange);
4718 cell(
const unsigned int range_index)
override
4720 process_range(cell_function,
4721 matrix_free.get_task_info().cell_partition_data_hp_ptr,
4722 matrix_free.get_task_info().cell_partition_data_hp,
4727 face(
const unsigned int range_index)
override
4729 process_range(face_function,
4730 matrix_free.get_task_info().face_partition_data_hp_ptr,
4731 matrix_free.get_task_info().face_partition_data_hp,
4736 boundary(
const unsigned int range_index)
override
4738 process_range(boundary_function,
4739 matrix_free.get_task_info().boundary_partition_data_hp_ptr,
4740 matrix_free.get_task_info().boundary_partition_data_hp,
4746 process_range(
const function_type & fu,
4747 const std::vector<unsigned int> &ptr,
4748 const std::vector<unsigned int> &data,
4749 const unsigned int range_index)
4755 for (
unsigned int i = ptr[range_index]; i < ptr[range_index + 1]; ++i)
4758 (container.*fu)(matrix_free,
4761 std::make_pair(data[2 * i], data[2 * i + 1]));
4773 vector_update_ghosts_start()
override
4775 if (!src_and_dst_are_same)
4776 internal::update_ghost_values_start(src, src_data_exchanger);
4781 vector_update_ghosts_finish()
override
4783 if (!src_and_dst_are_same)
4784 internal::update_ghost_values_finish(src, src_data_exchanger);
4789 vector_compress_start()
override
4791 internal::compress_start(dst, dst_data_exchanger);
4796 vector_compress_finish()
override
4798 internal::compress_finish(dst, dst_data_exchanger);
4799 if (!src_and_dst_are_same)
4800 internal::reset_ghost_values(src, src_data_exchanger);
4805 zero_dst_vector_range(
const unsigned int range_index)
override
4807 if (zero_dst_vector_setting)
4808 internal::zero_vector_region(range_index, dst, dst_data_exchanger);
4812 cell_loop_pre_range(
const unsigned int range_index)
override
4814 if (operation_before_loop)
4817 matrix_free.get_dof_info(dof_handler_index_pre_post);
4824 operation_before_loop,
4831 for (
unsigned int id =
4842 cell_loop_post_range(
const unsigned int range_index)
override
4844 if (operation_after_loop)
4848 const std::vector<unsigned int> &partition_row_index =
4849 matrix_free.get_task_info().partition_row_index;
4851 partition_row_index[partition_row_index.size() - 2] - 1)
4852 apply_operation_to_constrained_dofs(
4853 matrix_free.get_constrained_dofs(dof_handler_index_pre_post),
4858 matrix_free.get_dof_info(dof_handler_index_pre_post);
4865 operation_after_loop,
4872 for (
unsigned int id =
4883 const MF & matrix_free;
4884 Container & container;
4885 function_type cell_function;
4886 function_type face_function;
4887 function_type boundary_function;
4889 const InVector &src;
4891 VectorDataExchange<MF::dimension,
4892 typename MF::value_type,
4893 typename MF::vectorized_value_type>
4895 VectorDataExchange<MF::dimension,
4896 typename MF::value_type,
4897 typename MF::vectorized_value_type>
4899 const bool src_and_dst_are_same;
4900 const bool zero_dst_vector_setting;
4901 const std::function<void(
const unsigned int,
const unsigned int)>
4902 operation_before_loop;
4903 const std::function<void(
const unsigned int,
const unsigned int)>
4904 operation_after_loop;
4905 const unsigned int dof_handler_index_pre_post;
4914 template <
class MF,
typename InVector,
typename OutVector>
4915 struct MFClassWrapper
4917 using function_type =
4918 std::function<void(
const MF &,
4921 const std::pair<unsigned int, unsigned int> &)>;
4923 MFClassWrapper(
const function_type cell,
4924 const function_type face,
4925 const function_type boundary)
4928 , boundary(boundary)
4932 cell_integrator(
const MF & mf,
4934 const InVector & src,
4935 const std::pair<unsigned int, unsigned int> &range)
const
4938 cell(mf, dst, src, range);
4942 face_integrator(
const MF & mf,
4944 const InVector & src,
4945 const std::pair<unsigned int, unsigned int> &range)
const
4948 face(mf, dst, src, range);
4952 boundary_integrator(
4955 const InVector & src,
4956 const std::pair<unsigned int, unsigned int> &range)
const
4959 boundary(mf, dst, src, range);
4962 const function_type cell;
4963 const function_type face;
4964 const function_type boundary;
4971template <
int dim,
typename Number,
typename VectorizedArrayType>
4972template <
typename OutVector,
typename InVector>
4978 const std::pair<unsigned int, unsigned int> &)>
4981 const InVector &src,
4982 const bool zero_dst_vector)
const
4985 internal::MFClassWrapper<MatrixFree<dim, Number, VectorizedArrayType>,
4988 Wrapper wrap(cell_operation,
nullptr,
nullptr);
4989 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
4999 &Wrapper::cell_integrator,
5000 &Wrapper::face_integrator,
5001 &Wrapper::boundary_integrator);
5003 task_info.loop(worker);
5008template <
int dim,
typename Number,
typename VectorizedArrayType>
5009template <
typename OutVector,
typename InVector>
5015 const std::pair<unsigned int, unsigned int> &)>
5018 const InVector &src,
5019 const std::function<
void(
const unsigned int,
const unsigned int)>
5020 &operation_before_loop,
5021 const std::function<
void(
const unsigned int,
const unsigned int)>
5022 & operation_after_loop,
5023 const unsigned int dof_handler_index_pre_post)
const
5026 internal::MFClassWrapper<MatrixFree<dim, Number, VectorizedArrayType>,
5029 Wrapper wrap(cell_operation,
nullptr,
nullptr);
5030 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5040 &Wrapper::cell_integrator,
5041 &Wrapper::face_integrator,
5042 &Wrapper::boundary_integrator,
5043 DataAccessOnFaces::none,
5044 DataAccessOnFaces::none,
5045 operation_before_loop,
5046 operation_after_loop,
5047 dof_handler_index_pre_post);
5049 task_info.loop(worker);
5054template <
int dim,
typename Number,
typename VectorizedArrayType>
5055template <
typename OutVector,
typename InVector>
5061 const std::pair<unsigned int, unsigned int> &)>
5066 const std::pair<unsigned int, unsigned int> &)>
5071 const std::pair<unsigned int, unsigned int> &)>
5072 & boundary_operation,
5074 const InVector & src,
5075 const bool zero_dst_vector,
5076 const DataAccessOnFaces dst_vector_face_access,
5077 const DataAccessOnFaces src_vector_face_access)
const
5080 internal::MFClassWrapper<MatrixFree<dim, Number, VectorizedArrayType>,
5083 Wrapper wrap(cell_operation, face_operation, boundary_operation);
5084 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5094 &Wrapper::cell_integrator,
5095 &Wrapper::face_integrator,
5096 &Wrapper::boundary_integrator,
5097 src_vector_face_access,
5098 dst_vector_face_access);
5100 task_info.loop(worker);
5105template <
int dim,
typename Number,
typename VectorizedArrayType>
5106template <
typename CLASS,
typename OutVector,
typename InVector>
5109 void (CLASS::*function_pointer)(
5110 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5113 const
std::pair<unsigned
int, unsigned
int> &) const,
5114 const CLASS * owning_class,
5116 const InVector &src,
5117 const
bool zero_dst_vector) const
5119 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5137template <
int dim,
typename Number,
typename VectorizedArrayType>
5138template <
typename CLASS,
typename OutVector,
typename InVector>
5141 void (CLASS::*function_pointer)(
5142 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5145 const
std::pair<unsigned
int, unsigned
int> &) const,
5146 const CLASS * owning_class,
5148 const InVector &src,
5149 const
std::function<void(const unsigned
int, const unsigned
int)>
5150 &operation_before_loop,
5151 const
std::function<void(const unsigned
int, const unsigned
int)>
5152 & operation_after_loop,
5153 const unsigned
int dof_handler_index_pre_post) const
5155 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5170 operation_before_loop,
5171 operation_after_loop,
5172 dof_handler_index_pre_post);
5178template <
int dim,
typename Number,
typename VectorizedArrayType>
5179template <
typename CLASS,
typename OutVector,
typename InVector>
5182 void (CLASS::*cell_operation)(
5183 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5186 const
std::pair<unsigned
int, unsigned
int> &) const,
5187 void (CLASS::*face_operation)(
5188 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5191 const
std::pair<unsigned
int, unsigned
int> &) const,
5192 void (CLASS::*boundary_operation)(
5193 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5196 const
std::pair<unsigned
int, unsigned
int> &) const,
5197 const CLASS * owning_class,
5199 const InVector & src,
5200 const
bool zero_dst_vector,
5201 const DataAccessOnFaces dst_vector_face_access,
5202 const DataAccessOnFaces src_vector_face_access) const
5204 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5217 src_vector_face_access,
5218 dst_vector_face_access);
5224template <
int dim,
typename Number,
typename VectorizedArrayType>
5225template <
typename CLASS,
typename OutVector,
typename InVector>
5228 void (CLASS::*function_pointer)(
5229 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5232 const
std::pair<unsigned
int, unsigned
int> &),
5233 CLASS * owning_class,
5235 const InVector &src,
5236 const
bool zero_dst_vector) const
5238 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5256template <
int dim,
typename Number,
typename VectorizedArrayType>
5257template <
typename CLASS,
typename OutVector,
typename InVector>
5260 void (CLASS::*function_pointer)(
5261 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5264 const
std::pair<unsigned
int, unsigned
int> &),
5265 CLASS * owning_class,
5267 const InVector &src,
5268 const
std::function<void(const unsigned
int, const unsigned
int)>
5269 &operation_before_loop,
5270 const
std::function<void(const unsigned
int, const unsigned
int)>
5271 & operation_after_loop,
5272 const unsigned
int dof_handler_index_pre_post) const
5274 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5289 operation_before_loop,
5290 operation_after_loop,
5291 dof_handler_index_pre_post);
5297template <
int dim,
typename Number,
typename VectorizedArrayType>
5298template <
typename CLASS,
typename OutVector,
typename InVector>
5301 void (CLASS::*cell_operation)(
5302 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5305 const
std::pair<unsigned
int, unsigned
int> &),
5306 void (CLASS::*face_operation)(
5307 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5310 const
std::pair<unsigned
int, unsigned
int> &),
5311 void (CLASS::*boundary_operation)(
5312 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5315 const
std::pair<unsigned
int, unsigned
int> &),
5316 CLASS * owning_class,
5318 const InVector & src,
5319 const
bool zero_dst_vector,
5320 const DataAccessOnFaces dst_vector_face_access,
5321 const DataAccessOnFaces src_vector_face_access) const
5323 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5336 src_vector_face_access,
5337 dst_vector_face_access);
5343template <
int dim,
typename Number,
typename VectorizedArrayType>
5344template <
typename OutVector,
typename InVector>
5350 const std::pair<unsigned int, unsigned int> &)>
5355 const std::pair<unsigned int, unsigned int> &)>
5360 const std::pair<unsigned int, unsigned int> &)>
5361 & boundary_operation,
5363 const InVector &src,
5364 const std::function<
void(
const unsigned int,
const unsigned int)>
5365 &operation_before_loop,
5366 const std::function<
void(
const unsigned int,
const unsigned int)>
5367 & operation_after_loop,
5368 const unsigned int dof_handler_index_pre_post,
5369 const DataAccessOnFaces dst_vector_face_access,
5370 const DataAccessOnFaces src_vector_face_access)
const
5373 internal::MFClassWrapper<MatrixFree<dim, Number, VectorizedArrayType>,
5376 Wrapper wrap(cell_operation, face_operation, boundary_operation);
5377 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5387 &Wrapper::cell_integrator,
5388 &Wrapper::face_integrator,
5389 &Wrapper::boundary_integrator,
5390 src_vector_face_access,
5391 dst_vector_face_access,
5392 operation_before_loop,
5393 operation_after_loop,
5394 dof_handler_index_pre_post);
5396 task_info.loop(worker);
5401template <
int dim,
typename Number,
typename VectorizedArrayType>
5402template <
typename CLASS,
typename OutVector,
typename InVector>
5405 void (CLASS::*cell_operation)(const
MatrixFree &,
5408 const
std::pair<unsigned
int, unsigned
int> &)
5410 void (CLASS::*face_operation)(const
MatrixFree &,
5413 const
std::pair<unsigned
int, unsigned
int> &)
5415 void (CLASS::*boundary_operation)(
5419 const
std::pair<unsigned
int, unsigned
int> &) const,
5420 const CLASS * owning_class,
5422 const InVector &src,
5423 const
std::function<void(const unsigned
int, const unsigned
int)>
5424 &operation_before_loop,
5425 const
std::function<void(const unsigned
int, const unsigned
int)>
5426 & operation_after_loop,
5427 const unsigned
int dof_handler_index_pre_post,
5428 const DataAccessOnFaces dst_vector_face_access,
5429 const DataAccessOnFaces src_vector_face_access) const
5431 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5444 src_vector_face_access,
5445 dst_vector_face_access,
5446 operation_before_loop,
5447 operation_after_loop,
5448 dof_handler_index_pre_post);
5454template <
int dim,
typename Number,
typename VectorizedArrayType>
5455template <
typename CLASS,
typename OutVector,
typename InVector>
5458 void (CLASS::*cell_operation)(const
MatrixFree &,
5461 const
std::pair<unsigned
int, unsigned
int> &),
5462 void (CLASS::*face_operation)(const
MatrixFree &,
5465 const
std::pair<unsigned
int, unsigned
int> &),
5466 void (CLASS::*boundary_operation)(
5470 const
std::pair<unsigned
int, unsigned
int> &),
5471 const CLASS * owning_class,
5473 const InVector &src,
5474 const
std::function<void(const unsigned
int, const unsigned
int)>
5475 &operation_before_loop,
5476 const
std::function<void(const unsigned
int, const unsigned
int)>
5477 & operation_after_loop,
5478 const unsigned
int dof_handler_index_pre_post,
5479 const DataAccessOnFaces dst_vector_face_access,
5480 const DataAccessOnFaces src_vector_face_access) const
5482 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5495 src_vector_face_access,
5496 dst_vector_face_access,
5497 operation_before_loop,
5498 operation_after_loop,
5499 dof_handler_index_pre_post);
5505template <
int dim,
typename Number,
typename VectorizedArrayType>
5506template <
typename CLASS,
typename OutVector,
typename InVector>
5509 void (CLASS::*function_pointer)(
5510 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5513 const
std::pair<unsigned
int, unsigned
int> &) const,
5514 const CLASS * owning_class,
5516 const InVector & src,
5517 const
bool zero_dst_vector,
5518 const DataAccessOnFaces src_vector_face_access) const
5520 auto src_vector_face_access_temp = src_vector_face_access;
5526 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5539 src_vector_face_access_temp,
5546template <
int dim,
typename Number,
typename VectorizedArrayType>
5547template <
typename CLASS,
typename OutVector,
typename InVector>
5550 void (CLASS::*function_pointer)(
5551 const
MatrixFree<dim, Number, VectorizedArrayType> &,
5554 const
std::pair<unsigned
int, unsigned
int> &),
5555 CLASS * owning_class,
5557 const InVector & src,
5558 const
bool zero_dst_vector,
5559 const DataAccessOnFaces src_vector_face_access) const
5561 auto src_vector_face_access_temp = src_vector_face_access;
5567 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5580 src_vector_face_access_temp,
5587template <
int dim,
typename Number,
typename VectorizedArrayType>
5588template <
typename OutVector,
typename InVector>
5594 const std::pair<unsigned int, unsigned int> &)>
5597 const InVector & src,
5598 const bool zero_dst_vector,
5599 const DataAccessOnFaces src_vector_face_access)
const
5601 auto src_vector_face_access_temp = src_vector_face_access;
5602 if (DataAccessOnFaces::gradients == src_vector_face_access_temp)
5603 src_vector_face_access_temp = DataAccessOnFaces::gradients_all_faces;
5604 else if (DataAccessOnFaces::values == src_vector_face_access_temp)
5605 src_vector_face_access_temp = DataAccessOnFaces::values_all_faces;
5608 internal::MFClassWrapper<MatrixFree<dim, Number, VectorizedArrayType>,
5611 Wrapper wrap(cell_operation,
nullptr,
nullptr);
5613 internal::MFWorker<MatrixFree<dim, Number, VectorizedArrayType>,
5623 &Wrapper::cell_integrator,
5624 &Wrapper::face_integrator,
5625 &Wrapper::boundary_integrator,
5626 src_vector_face_access_temp,
5627 DataAccessOnFaces::none);
5628 task_info.loop(worker);
void resize(const size_type new_size)
void reinit(const size_type size, const bool omit_zeroing_entries=false)
Abstract base class for mapping classes.
unsigned int n_active_fe_indices() const
std::pair< typename DoFHandler< dim >::cell_iterator, unsigned int > get_face_iterator(const unsigned int face_batch_index, const unsigned int lane_index, const bool interior=true, const unsigned int fe_component=0) const
void loop_cell_centric(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &), CLASS *owning_class, OutVector &dst, const InVector &src, const bool zero_dst_vector=false, const DataAccessOnFaces src_vector_face_access=DataAccessOnFaces::unspecified) const
internal::MatrixFreeFunctions::MappingInfo< dim, Number, VectorizedArrayType > mapping_info
unsigned int get_cell_active_fe_index(const std::pair< unsigned int, unsigned int > range) const
const internal::MatrixFreeFunctions::TaskInfo & get_task_info() const
unsigned int n_ghost_cell_batches() const
void loop(const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &)> &cell_operation, const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &)> &face_operation, const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &)> &boundary_operation, OutVector &dst, const InVector &src, const bool zero_dst_vector=false, const DataAccessOnFaces dst_vector_face_access=DataAccessOnFaces::unspecified, const DataAccessOnFaces src_vector_face_access=DataAccessOnFaces::unspecified) const
const internal::MatrixFreeFunctions::ShapeInfo< VectorizedArrayType > & get_shape_info(const unsigned int dof_handler_index_component=0, const unsigned int quad_index=0, const unsigned int fe_base_element=0, const unsigned int hp_active_fe_index=0, const unsigned int hp_active_quad_index=0) const
void initialize_dof_handlers(const std::vector< const DoFHandler< dim, dim > * > &dof_handlers, const AdditionalData &additional_data)
types::boundary_id get_boundary_id(const unsigned int face_batch_index) const
Table< 4, internal::MatrixFreeFunctions::ShapeInfo< VectorizedArrayType > > shape_info
void print(std::ostream &out) const
void update_mapping(const std::shared_ptr< hp::MappingCollection< dim > > &mapping)
const Table< 3, unsigned int > & get_cell_and_face_to_plain_faces() const
unsigned int n_inner_face_batches() const
unsigned int n_active_entries_per_cell_batch(const unsigned int cell_batch_index) const
void update_mapping(const Mapping< dim > &mapping)
const Quadrature< dim > & get_quadrature(const unsigned int quad_index=0, const unsigned int hp_active_fe_index=0) const
const internal::MatrixFreeFunctions::FaceToCellTopology< VectorizedArrayType::size()> & get_face_info(const unsigned int face_batch_index) const
unsigned int get_mg_level() const
void print_memory_consumption(StreamType &out) const
bool mapping_initialized() const
void cell_loop(const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &)> &cell_operation, OutVector &dst, const InVector &src, const std::function< void(const unsigned int, const unsigned int)> &operation_before_loop, const std::function< void(const unsigned int, const unsigned int)> &operation_after_loop, const unsigned int dof_handler_index_pre_post=0) const
void internal_reinit(const std::shared_ptr< hp::MappingCollection< dim > > &mapping, const std::vector< const DoFHandler< dim, dim > * > &dof_handlers, const std::vector< const AffineConstraints< number2 > * > &constraint, const std::vector< IndexSet > &locally_owned_set, const std::vector< hp::QCollection< q_dim > > &quad, const AdditionalData &additional_data)
unsigned int get_n_q_points_face(const unsigned int quad_index=0, const unsigned int hp_active_fe_index=0) const
const internal::MatrixFreeFunctions::DoFInfo & get_dof_info(const unsigned int dof_handler_index_component=0) const
AlignedVector< VectorizedArrayType > * acquire_scratch_data() const
bool at_irregular_cell(const unsigned int cell_batch_index) const
~MatrixFree() override=default
const AffineConstraints< Number > & get_affine_constraints(const unsigned int dof_handler_index=0) const
void copy_from(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free_base)
void initialize_face_data_vector(AlignedVector< T > &vec) const
unsigned int get_dofs_per_cell(const unsigned int dof_handler_index=0, const unsigned int hp_active_fe_index=0) const
unsigned int n_constraint_pool_entries() const
void cell_loop(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &), CLASS *owning_class, OutVector &dst, const InVector &src, const std::function< void(const unsigned int, const unsigned int)> &operation_before_loop, const std::function< void(const unsigned int, const unsigned int)> &operation_after_loop, const unsigned int dof_handler_index_pre_post=0) const
const Number * constraint_pool_begin(const unsigned int pool_index) const
AlignedVector< Number > * acquire_scratch_data_non_threadsafe() const
const IndexSet & get_locally_owned_set(const unsigned int dof_handler_index=0) const
unsigned int get_dofs_per_face(const unsigned int dof_handler_index=0, const unsigned int hp_active_fe_index=0) const
internal::MatrixFreeFunctions::TaskInfo task_info
const DoFHandler< dim > & get_dof_handler(const unsigned int dof_handler_index=0) const
void release_scratch_data(const AlignedVector< VectorizedArrayType > *memory) const
void loop(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &) const, void(CLASS::*face_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &) const, void(CLASS::*boundary_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &) const, const CLASS *owning_class, OutVector &dst, const InVector &src, const bool zero_dst_vector=false, const DataAccessOnFaces dst_vector_face_access=DataAccessOnFaces::unspecified, const DataAccessOnFaces src_vector_face_access=DataAccessOnFaces::unspecified) const
bool mapping_is_initialized
void loop_cell_centric(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &) const, const CLASS *owning_class, OutVector &dst, const InVector &src, const bool zero_dst_vector=false, const DataAccessOnFaces src_vector_face_access=DataAccessOnFaces::unspecified) const
void initialize_dof_vector(LinearAlgebra::distributed::Vector< Number2 > &vec, const unsigned int dof_handler_index=0) const
DoFHandler< dim >::cell_iterator get_cell_iterator(const unsigned int cell_batch_index, const unsigned int lane_index, const unsigned int dof_handler_index=0) const
MatrixFree(const MatrixFree< dim, Number, VectorizedArrayType > &other)
std::pair< unsigned int, unsigned int > create_cell_subrange_hp(const std::pair< unsigned int, unsigned int > &range, const unsigned int fe_degree, const unsigned int dof_handler_index=0) const
std::pair< unsigned int, unsigned int > create_cell_subrange_hp_by_index(const std::pair< unsigned int, unsigned int > &range, const unsigned int fe_index, const unsigned int dof_handler_index=0) const
std::pair< unsigned int, unsigned int > get_face_range_category(const std::pair< unsigned int, unsigned int > face_batch_range) const
void cell_loop(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &) const, const CLASS *owning_class, OutVector &dst, const InVector &src, const std::function< void(const unsigned int, const unsigned int)> &operation_before_loop, const std::function< void(const unsigned int, const unsigned int)> &operation_after_loop, const unsigned int dof_handler_index_pre_post=0) const
std::vector< std::pair< unsigned int, unsigned int > > cell_level_index
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_vector_partitioner(const unsigned int dof_handler_index=0) const
const internal::MatrixFreeFunctions::MappingInfo< dim, Number, VectorizedArrayType > & get_mapping_info() const
std::vector< Number > constraint_pool_data
VectorizedArrayType vectorized_value_type
unsigned int n_cell_batches() const
const IndexSet & get_ghost_set(const unsigned int dof_handler_index=0) const
std::pair< int, int > get_cell_level_and_index(const unsigned int cell_batch_index, const unsigned int lane_index) const
bool indices_initialized() const
const Quadrature< dim - 1 > & get_face_quadrature(const unsigned int quad_index=0, const unsigned int hp_active_fe_index=0) const
unsigned int get_cell_category(const unsigned int cell_batch_index) const
Threads::ThreadLocalStorage< std::list< std::pair< bool, AlignedVector< VectorizedArrayType > > > > scratch_pad
unsigned int get_matrix_free_cell_index(const typename Triangulation< dim >::cell_iterator &cell) const
std::size_t memory_consumption() const
std::pair< unsigned int, unsigned int > get_face_category(const unsigned int face_batch_index) const
unsigned int n_boundary_face_batches() const
void cell_loop(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &) const, const CLASS *owning_class, OutVector &dst, const InVector &src, const bool zero_dst_vector=false) const
std::list< std::pair< bool, AlignedVector< Number > > > scratch_pad_non_threadsafe
const Number * constraint_pool_end(const unsigned int pool_index) const
void loop_cell_centric(const std::function< void(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &)> &cell_operation, OutVector &dst, const InVector &src, const bool zero_dst_vector=false, const DataAccessOnFaces src_vector_face_access=DataAccessOnFaces::unspecified) const
std::vector< SmartPointer< const DoFHandler< dim > > > dof_handlers
void initialize_indices(const std::vector< const AffineConstraints< number2 > * > &constraint, const std::vector< IndexSet > &locally_owned_set, const AdditionalData &additional_data)
std::vector< SmartPointer< const AffineConstraints< Number > > > affine_constraints
unsigned int n_components() const
unsigned int n_physical_cells() const
void initialize_dof_vector(VectorType &vec, const unsigned int dof_handler_index=0) const
unsigned int get_n_q_points(const unsigned int quad_index=0, const unsigned int hp_active_fe_index=0) const
void reinit(const MappingType &mapping, const std::vector< const DoFHandler< dim > * > &dof_handler, const std::vector< const AffineConstraints< number2 > * > &constraint, const QuadratureType &quad, const AdditionalData &additional_data=AdditionalData())
std::vector< unsigned int > mf_cell_indices
void cell_loop(const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &)> &cell_operation, OutVector &dst, const InVector &src, const bool zero_dst_vector=false) const
void loop(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &), void(CLASS::*face_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &), void(CLASS::*boundary_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &), const CLASS *owning_class, OutVector &dst, const InVector &src, const std::function< void(const unsigned int, const unsigned int)> &operation_before_loop, const std::function< void(const unsigned int, const unsigned int)> &operation_after_loop, const unsigned int dof_handler_index_pre_post=0, const DataAccessOnFaces dst_vector_face_access=DataAccessOnFaces::unspecified, const DataAccessOnFaces src_vector_face_access=DataAccessOnFaces::unspecified) const
void cell_loop(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &), CLASS *owning_class, OutVector &dst, const InVector &src, const bool zero_dst_vector=false) const
std::vector< internal::MatrixFreeFunctions::DoFInfo > dof_info
void initialize_cell_data_vector(AlignedVector< T > &vec) const
unsigned int n_ghost_inner_face_batches() const
void release_scratch_data_non_threadsafe(const AlignedVector< Number > *memory) const
void renumber_dofs(std::vector< types::global_dof_index > &renumbering, const unsigned int dof_handler_index=0)
unsigned int get_face_active_fe_index(const std::pair< unsigned int, unsigned int > range, const bool is_interior_face=true) const
unsigned int n_active_entries_per_face_batch(const unsigned int face_batch_index) const
bool indices_are_initialized
internal::MatrixFreeFunctions::FaceInfo< VectorizedArrayType::size()> face_info
void reinit(const MappingType &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< number2 > &constraint, const QuadratureType &quad, const AdditionalData &additional_data=AdditionalData())
unsigned int get_cell_range_category(const std::pair< unsigned int, unsigned int > cell_batch_range) const
void loop(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &), void(CLASS::*face_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &), void(CLASS::*boundary_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &), CLASS *owning_class, OutVector &dst, const InVector &src, const bool zero_dst_vector=false, const DataAccessOnFaces dst_vector_face_access=DataAccessOnFaces::unspecified, const DataAccessOnFaces src_vector_face_access=DataAccessOnFaces::unspecified) const
void reinit(const MappingType &mapping, const std::vector< const DoFHandler< dim > * > &dof_handler, const std::vector< const AffineConstraints< number2 > * > &constraint, const std::vector< QuadratureType > &quad, const AdditionalData &additional_data=AdditionalData())
std::array< types::boundary_id, VectorizedArrayType::size()> get_faces_by_cells_boundary_id(const unsigned int cell_batch_index, const unsigned int face_number) const
std::vector< unsigned int > constraint_pool_row_index
void loop(const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &)> &cell_operation, const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &)> &face_operation, const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &)> &boundary_operation, OutVector &dst, const InVector &src, const std::function< void(const unsigned int, const unsigned int)> &operation_before_loop, const std::function< void(const unsigned int, const unsigned int)> &operation_after_loop, const unsigned int dof_handler_index_pre_post=0, const DataAccessOnFaces dst_vector_face_access=DataAccessOnFaces::unspecified, const DataAccessOnFaces src_vector_face_access=DataAccessOnFaces::unspecified) const
const std::vector< unsigned int > & get_constrained_dofs(const unsigned int dof_handler_index=0) const
unsigned int cell_level_index_end_local
unsigned int n_base_elements(const unsigned int dof_handler_index) const
void loop(void(CLASS::*cell_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &) const, void(CLASS::*face_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &) const, void(CLASS::*boundary_operation)(const MatrixFree &, OutVector &, const InVector &, const std::pair< unsigned int, unsigned int > &) const, const CLASS *owning_class, OutVector &dst, const InVector &src, const std::function< void(const unsigned int, const unsigned int)> &operation_before_loop, const std::function< void(const unsigned int, const unsigned int)> &operation_after_loop, const unsigned int dof_handler_index_pre_post=0, const DataAccessOnFaces dst_vector_face_access=DataAccessOnFaces::unspecified, const DataAccessOnFaces src_vector_face_access=DataAccessOnFaces::unspecified) const
static bool is_supported(const FiniteElement< dim, spacedim > &fe)
static constexpr unsigned int dimension
A class that provides a separate storage location on each thread that accesses the object.
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
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_default
No update.
VectorType::value_type * begin(VectorType &V)
unsigned int minimum_parallel_grain_size
const types::boundary_id invalid_boundary_id
static const unsigned int invalid_unsigned_int
void apply_to_subranges(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, const Function &f, const unsigned int grainsize)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
unsigned short int fe_index
TasksParallelScheme tasks_parallel_scheme
bool hold_all_faces_to_owned_cells
UpdateFlags mapping_update_flags_inner_faces
AdditionalData(const TasksParallelScheme tasks_parallel_scheme=partition_partition, const unsigned int tasks_block_size=0, const UpdateFlags mapping_update_flags=update_gradients|update_JxW_values, const UpdateFlags mapping_update_flags_boundary_faces=update_default, const UpdateFlags mapping_update_flags_inner_faces=update_default, const UpdateFlags mapping_update_flags_faces_by_cells=update_default, const unsigned int mg_level=numbers::invalid_unsigned_int, const bool store_plain_indices=true, const bool initialize_indices=true, const bool initialize_mapping=true, const bool overlap_communication_computation=true, const bool hold_all_faces_to_owned_cells=false, const bool cell_vectorization_categories_strict=false, const bool allow_ghosted_vectors_in_loops=true)
std::vector< unsigned int > cell_vectorization_category
AdditionalData & operator=(const AdditionalData &other)
bool cell_vectorization_categories_strict
UpdateFlags mapping_update_flags_boundary_faces
UpdateFlags mapping_update_flags
UpdateFlags mapping_update_flags_faces_by_cells
AdditionalData(const AdditionalData &other)
bool allow_ghosted_vectors_in_loops
unsigned int tasks_block_size
bool overlap_communication_computation
@ dof_access_face_interior
std::vector< unsigned int > cell_loop_pre_list_index
std::vector< unsigned int > cell_loop_post_list_index
std::vector< std::pair< unsigned int, unsigned int > > vector_zero_range_list
std::shared_ptr< const Utilities::MPI::Partitioner > vector_partitioner
std::vector< std::pair< unsigned int, unsigned int > > cell_loop_pre_list
std::vector< unsigned int > vector_zero_range_list_index
std::vector< std::pair< unsigned int, unsigned int > > cell_loop_post_list
void loop(MFWorkerInterface &worker) const