89 Coord<std::conditional_t<std::is_same_v<CurrentDim, EdgeDim1>, EdgeDim2, EdgeDim1>>
operator()(
90 Coord<CurrentDim>
const& current_coord)
const
94 = std::conditional_t<std::is_same_v<CurrentDim, EdgeDim1>, EdgeDim2, EdgeDim1>;
97 using IdxRangeCurrent = std::
98 conditional_t<std::is_same_v<CurrentDim, EdgeDim1>, IdxRangeEdge1, IdxRangeEdge2>;
100 using IdxRangeTarget = std::
101 conditional_t<std::is_same_v<CurrentDim, EdgeDim1>, IdxRangeEdge2, IdxRangeEdge1>;
104 IdxRange<EdgeGrid1, EdgeGrid2>
const
105 combined_idx_range(m_idx_range_patch_1, m_idx_range_patch_2);
106 IdxRangeCurrent
const current_idx_range(combined_idx_range);
107 IdxRangeTarget
const target_idx_range(combined_idx_range);
109 Coord<CurrentDim>
const current_min = ddc::coordinate(current_idx_range.front());
110 double const current_length = ddcHelper::total_interval_length(current_idx_range);
112 Coord<TargetDim>
const target_min = ddc::coordinate(target_idx_range.front());
113 double const target_length = ddcHelper::total_interval_length(target_idx_range);
115 double rescale_x = (current_coord - current_min) / current_length * target_length;
118 if constexpr (!orientations_agree) {
119 rescale_x = target_length - rescale_x;
121 return target_min + rescale_x;
148 = std::conditional_t<std::is_same_v<CurrentIdx, IdxEdge1>, IdxEdge2, IdxEdge1>;
149 IdxTarget target_idx;
150 [[maybe_unused]]
bool is_equivalent_idx_found =
search_for_match(target_idx, current_idx);
151 assert(is_equivalent_idx_found);
214 bool search_for_match(Idx<TargetGrid>& target_idx, Idx<CurrentGrid>
const& current_idx)
const
217 std::is_same_v<CurrentGrid, EdgeGrid1> || std::is_same_v<CurrentGrid, EdgeGrid2>,
218 "Current index must be associated with one of the edges.");
220 std::is_same_v<TargetGrid, EdgeGrid1> || std::is_same_v<TargetGrid, EdgeGrid2>,
221 "Target index must be associated with one of the edges.");
223 !std::is_same_v<TargetGrid, CurrentGrid>,
224 "The types of the indices should be different");
227 using IdxRangeCurrent = IdxRange<CurrentGrid>;
229 using IdxRangeTarget = IdxRange<TargetGrid>;
231 using CurrentCoord = Coord<typename CurrentGrid::continuous_dimension_type>;
233 using IdxTarget =
typename IdxRangeTarget::discrete_element_type;
235 using IdxStepTarget =
typename IdxRangeTarget::discrete_vector_type;
238 bool is_equivalent_idx =
false;
241 IdxRange<EdgeGrid1, EdgeGrid2>
const
242 combined_idx_range(m_idx_range_patch_1, m_idx_range_patch_2);
243 IdxRangeCurrent
const current_idx_range(combined_idx_range);
244 IdxRangeTarget
const target_idx_range(combined_idx_range);
246 int const n_cells_current = current_idx_range.size() - 1;
247 int const n_cells_target = target_idx_range.size() - 1;
250 ddc::is_uniform_point_sampling_v<
251 EdgeGrid1> && ddc::is_uniform_point_sampling_v<EdgeGrid2>) {
253 int const gcd_cells = std::gcd(n_cells_current, n_cells_target);
255 int const current_idx_value = (current_idx - current_idx_range.front()).value();
262 is_equivalent_idx = (current_idx_value % (n_cells_current / gcd_cells) == 0);
265 if (is_equivalent_idx) {
266 double const rescaling_factor = double(n_cells_current) / double(n_cells_target);
267 IdxStepTarget target_idx_step_rescaled(
int(current_idx_value / rescaling_factor));
268 target_idx = IdxTarget(target_idx_range.front());
269 target_idx += target_idx_step_rescaled;
272 IdxStepTarget target_idx_step = IdxTarget(target_idx_range.back()) - target_idx;
273 target_idx = IdxTarget(target_idx_range.front());
274 target_idx += target_idx_step;
279 target_idx = get_target_idx(target_idx_range, current_idx);
280 CurrentCoord
const current_coord(ddc::coordinate(current_idx));
281 CurrentCoord
const target_equivalent_coord((*
this)(ddc::coordinate(target_idx)));
282 is_equivalent_idx = (abs(current_coord - target_equivalent_coord) < 1e-14);
285 return is_equivalent_idx;