Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Nov 25, 2023
1 parent f75f087 commit ab0d6c7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 140 deletions.
11 changes: 10 additions & 1 deletion res/cmake/def.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@


set (PHARE_FLAGS ${PHARE_FLAGS})
# Per compiler CXXFLAGS
set (PHARE_FLAGS ${PHARE_FLAGS} )
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set (PHARE_FLAGS ${PHARE_FLAGS} )
else() # !Clang
# --param=min-pagesize=0 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
# --param=evrp-mode-legacy https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329
set (PHARE_FLAGS ${PHARE_FLAGS} --param=min-pagesize=0 --param=evrp-mode-legacy )
endif() # clang

set (PHARE_WERROR_FLAGS ${PHARE_FLAGS} ${PHARE_WERROR_FLAGS})
set (PHARE_PYTHONPATH "${CMAKE_BINARY_DIR}:${CMAKE_SOURCE_DIR}/pyphare")
set (PHARE_BASE_LIBS )
Expand Down
4 changes: 2 additions & 2 deletions src/core/data/grid/gridlayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ namespace core
/**
* @brief the number of ghost nodes on each side of the mesh for a given centering
*/
NO_DISCARD auto static constexpr nbrGhosts(
NO_DISCARD std::uint32_t static constexpr nbrGhosts(
QtyCentering /*centering*/ = QtyCentering::primal)
{ // Both dual and primal ghosts are the same!
static_assert(nbrDualGhosts_() == nbrPrimalGhosts_());
Expand All @@ -569,7 +569,7 @@ namespace core


template<typename Centering, Centering centering>
NO_DISCARD auto static constexpr nbrGhosts()
NO_DISCARD std::uint32_t static constexpr nbrGhosts()
{
if constexpr (centering == QtyCentering::dual)
return nbrDualGhosts_();
Expand Down
7 changes: 4 additions & 3 deletions src/core/utilities/box/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ struct Box

Box() = default;

constexpr Box(std::array<Type, dim> _lower, std::array<Type, dim> _upper)
constexpr Box(std::array<Type, dim> const& _lower, std::array<Type, dim> const& _upper)
: lower{_lower}
, upper{_upper}
{
}

template<typename T, std::size_t s>
Box(Point<T, s> _lower, Point<T, s> _upper)
Box(Point<T, s> const& _lower, Point<T, s> const& _upper)
: lower{_lower}
, upper{_upper}
{
}

NO_DISCARD bool operator==(Box const& box) const
template<typename T2>
NO_DISCARD bool operator==(Box<T2, dim> const& box) const
{
return box.lower == lower && box.upper == upper;
}
Expand Down
9 changes: 5 additions & 4 deletions src/core/utilities/point/point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ namespace core
}


constexpr Point(std::array<Type, dim> coords)
: r{std::move(coords)}
constexpr Point(std::array<Type, dim> const& coords)
: r{coords}
{
}

Expand All @@ -69,15 +69,16 @@ namespace core
NO_DISCARD auto const& operator[](std::size_t i) const { return r[i]; }


NO_DISCARD bool operator==(Point const& p) const
template<typename T2>
NO_DISCARD bool operator==(Point<T2, dim> const& p) const
{
bool areEqual = true;
for (std::size_t i = 0; i < dim; ++i)
{
static_assert(std::is_integral_v<Type>,
"this function is only valid for integral type of Point");

areEqual &= ((*this)[i] == p[i]);
areEqual &= int_equals((*this)[i], p[i]); // handles signed differences
}
return areEqual;
}
Expand Down
27 changes: 27 additions & 0 deletions src/core/utilities/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,33 @@ NO_DISCARD auto none(Container const& container)
}


template<typename SignedInt, typename UnsignedInt>
bool diff_sign_int_equals(SignedInt const& i0, UnsignedInt const& i1)
{
static_assert(std::is_unsigned_v<UnsignedInt>);
static_assert(std::is_signed_v<SignedInt>);
static_assert(sizeof(UnsignedInt) >= sizeof(SignedInt), "Bad int comparison!");
if (i0 < 0)
return false;
return static_cast<UnsignedInt>(i0) == i1;
}


template<typename Int0, typename Int1>
bool int_equals(Int0 const& i0, Int1 const& i1)
{
if constexpr (std::is_same_v<Int0, Int1>)
return i0 == i1;
else
{
if constexpr (std::is_unsigned_v<Int0> and std::is_signed_v<Int1>)
return diff_sign_int_equals(i1, i0);
if constexpr (std::is_unsigned_v<Int1> and std::is_signed_v<Int0>)
return diff_sign_int_equals(i0, i1);
}
// reaching here == compiler error
}



} // namespace PHARE::core
Expand Down
126 changes: 0 additions & 126 deletions src/phare/phare_init_2d.py

This file was deleted.

10 changes: 6 additions & 4 deletions tests/core/data/gridlayout/gridlayout_amr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ TEST(GridLayout, canTransformAnAMRIndexIntoALocalIndex)

TEST(GridLayout, canTransformAnAMRBoxIntoALocalBox)
{
GridLayout<GridLayoutImplYee<1, 1>> layout{{0.1}, {50u}, {{0.}}, Box{Point{50}, Point{99}}};
std::size_t constexpr static dim = 1;
GridLayout<GridLayoutImplYee<dim, 1>> layout{{0.1}, {50u}, {{0.}}, Box{Point{50}, Point{99}}};

int nGhosts = layout.nbrGhosts(QtyCentering::dual);
auto AMRBox = Box{Point{55}, Point{65}};
auto expectedLocalBox = Box<std::uint32_t, 1>{Point{nGhosts + 5}, Point{nGhosts + 15}};
std::uint32_t nGhosts = layout.nbrGhosts(QtyCentering::dual);
auto AMRBox = Box<int, dim>{Point<int, dim>{55}, Point<int, dim>{65}};
auto expectedLocalBox = Box<std::uint32_t, dim>{Point<std::uint32_t, dim>{nGhosts + 5},
Point<std::uint32_t, dim>{nGhosts + 15}};

EXPECT_EQ(expectedLocalBox, layout.AMRToLocal(AMRBox));
}

0 comments on commit ab0d6c7

Please sign in to comment.