Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the reordering of a DiscreteDomain #420

Merged
merged 11 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions include/ddc/discrete_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ class DiscreteDomain

KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain&& x) = default;

/**
* @brief Copy a DiscreteDomain by reordering and slicing.
*
* An assign operator to build a DiscreteDomain from another compatible domain.
* A domain is compatible if it either contains the same dimensions as this
* domain (even if they are in a different order) or if it contains at
* the dimensions of this domain plus some additional dimensions which will
* be unused here.
*
* @param domain A compatible domain.
*/
template <class... ODDims>
DiscreteDomain& KOKKOS_FUNCTION operator=(DiscreteDomain<ODDims...> const& domain)
{
m_element_begin = DiscreteElement<DDims...>(domain.front());
m_element_end = m_element_begin + DiscreteVector<DDims...>(domain.extents());
return *this;
}

template <class... ODims>
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain<ODims...> const& other) const
{
Expand Down
34 changes: 34 additions & 0 deletions tests/discrete_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ using DElemXYZ = ddc::DiscreteElement<DDimX, DDimY, DDimZ>;
using DVectXYZ = ddc::DiscreteVector<DDimX, DDimY, DDimZ>;
using DDomXYZ = ddc::DiscreteDomain<DDimX, DDimY, DDimZ>;

using DElemZYX = ddc::DiscreteElement<DDimZ, DDimY, DDimX>;
using DVectZYX = ddc::DiscreteVector<DDimZ, DDimY, DDimX>;
using DDomZYX = ddc::DiscreteDomain<DDimZ, DDimY, DDimX>;

static DElemX constexpr lbound_x(50);
static DVectX constexpr nelems_x(3);
Expand Down Expand Up @@ -234,3 +237,34 @@ TEST(ProductMDomainTest, SliceDomainXToolate)
R"rgx([Aa]ssert.*uid<ODDims>\(m_element_end\).*uid<ODDims>\(odomain\.m_element_end\).*)rgx");
#endif
}

TEST(ProductMDomainTest, Transpose3DConstructor)
{
DDomX const dom_x(lbound_x, nelems_x);
DDomY const dom_y(lbound_y, nelems_y);
DDomZ const dom_z(lbound_z, nelems_z);
DDomXYZ const dom_x_y_z(dom_x, dom_y, dom_z);
DDomZYX const dom_z_y_x(dom_x_y_z);
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.front()), ddc::select<DDimX>(dom_z_y_x.front()));
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.front()), ddc::select<DDimY>(dom_z_y_x.front()));
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.front()), ddc::select<DDimZ>(dom_z_y_x.front()));
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.back()), ddc::select<DDimX>(dom_z_y_x.back()));
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.back()), ddc::select<DDimY>(dom_z_y_x.back()));
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.back()), ddc::select<DDimZ>(dom_z_y_x.back()));
}

TEST(ProductMDomainTest, Transpose3DAssign)
{
DDomX const dom_x(lbound_x, nelems_x);
DDomY const dom_y(lbound_y, nelems_y);
DDomZ const dom_z(lbound_z, nelems_z);
DDomXYZ const dom_x_y_z(dom_x, dom_y, dom_z);
DDomZYX dom_z_y_x;
dom_z_y_x = dom_x_y_z;
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.front()), ddc::select<DDimX>(dom_z_y_x.front()));
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.front()), ddc::select<DDimY>(dom_z_y_x.front()));
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.front()), ddc::select<DDimZ>(dom_z_y_x.front()));
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.back()), ddc::select<DDimX>(dom_z_y_x.back()));
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.back()), ddc::select<DDimY>(dom_z_y_x.back()));
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.back()), ddc::select<DDimZ>(dom_z_y_x.back()));
}
Loading