Skip to content

Commit

Permalink
adapted planet tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nknk567 committed Nov 12, 2024
1 parent 42cbb40 commit 5f8a2d8
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 81 deletions.
8 changes: 4 additions & 4 deletions main/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ set(SPH_EXA_INCLUDE_DIRS ${CSTONE_DIR} ${COOLING_DIR} ${RYOANJI_DIR} ${SPH_DIR}
${PLANET_DIR})

function(enableGrackle exename)
if (SPH_EXA_WITH_GRACKLE)
if(SPH_EXA_WITH_GRACKLE)
target_compile_definitions(${exename} PUBLIC SPH_EXA_HAVE_GRACKLE)
target_compile_definitions(${exename} PUBLIC CONFIG_BFLOAT_8)
target_link_libraries(${exename} PRIVATE grackle)
target_link_libraries(${exename} PRIVATE cooler)
endif ()
endif()
endfunction()

add_subdirectory(init)
Expand All @@ -25,6 +25,6 @@ endif ()

include(setup_gitinfo)
configure_file(
version.h.in
${CMAKE_BINARY_DIR}/main/src/version.h
version.h.in
${CMAKE_BINARY_DIR}/main/src/version.h
)
1 change: 0 additions & 1 deletion main/src/propagator/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "nbody.hpp"
#include "std_hydro.hpp"
#include "ve_hydro.hpp"

#include "ve_hydro_bdt.hpp"
#ifdef SPH_EXA_HAVE_GRACKLE
#include "std_hydro_grackle.hpp"
Expand Down
1 change: 0 additions & 1 deletion physics/Planet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
cmake_minimum_required(VERSION 3.17)

#project(sphexa-planet)
set(CMAKE_CXX_STANDARD 20)

set(CSTONE_DIR ${CMAKE_SOURCE_DIR}/domain/include)
Expand Down
6 changes: 5 additions & 1 deletion physics/Planet/include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

if(CMAKE_CUDA_COMPILER)
if(CMAKE_HIP_COMPILER)
set_source_files_properties(computeCentralForce_gpu.cu accretion_gpu.cu betaCooling_gpu.cu eos_polytropic_gpu.cu PROPERTIES LANGUAGE HIP)
endif()

if(CMAKE_CUDA_COMPILER OR CMAKE_HIP_COMPILER)
add_library(planet_gpu OBJECT computeCentralForce_gpu.cu accretion_gpu.cu betaCooling_gpu.cu eos_polytropic_gpu.cu)
target_include_directories(planet_gpu PRIVATE ${CSTONE_DIR} ${SPH_DIR})
target_compile_definitions(planet_gpu PRIVATE USE_CUDA)
Expand Down
2 changes: 1 addition & 1 deletion physics/Planet/include/accretion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace planet
{

//! @brief Flag particles for removal. Overwrites keys.
//! @brief Flag particles for removal. Overwrites keys for the removed particles.
template<typename Dataset, typename StarData>
void computeAccretionCondition(size_t first, size_t last, Dataset& d, StarData& star)
{
Expand Down
2 changes: 1 addition & 1 deletion physics/Planet/include/betaCooling_gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ void betaCoolingGPU(size_t first, size_t last, Dataset& d, StarData& star);
template<typename Dataset, typename StarData>
double duTimestepGPU(size_t first, size_t last, const Dataset& d, const StarData& star);

} // namespace planet
} // namespace planet
2 changes: 1 addition & 1 deletion physics/Planet/include/computeCentralForce_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,4 @@ void computeCentralForceGPU(size_t first, size_t last, Dataset& d, StarData& sta
}

template void computeCentralForceGPU(size_t, size_t, sphexa::ParticlesData<cstone::GpuTag>&, StarData&);
} // namespace planet
} // namespace planet
2 changes: 1 addition & 1 deletion physics/Planet/include/computeCentralForce_gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ namespace planet
{
template<typename Dataset, typename StarData>
void computeCentralForceGPU(size_t first, size_t last, Dataset& d, StarData& star);
}
}
2 changes: 1 addition & 1 deletion physics/Planet/include/star_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ struct StarData
std::array<double, 3> p_removed_local{};
//! @brief du-timestep (local to rank)
double t_du{};
};
};
24 changes: 12 additions & 12 deletions physics/Planet/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
set(UNIT_TESTS planet_test.cpp accretion.cpp)
set(testname planet_tests)
add_executable(${testname} ${UNIT_TESTS})
target_compile_options(${testname} PRIVATE -Wall -Wextra)
target_compile_definitions(${testname} PUBLIC SPH_EXA_HAVE_H5PART)
target_include_directories(${testname} PRIVATE ${MPI_CXX_INCLUDE_PATH})
target_include_directories(${testname} PRIVATE ${PLANET_DIR} ${CSTONE_DIR} ${SPH_DIR} ${PROJECT_SOURCE_DIR}/include ${MAIN_APP_DIR})
set(testname PlanetTests)
set(exename planet_tests)
add_executable(${exename} ${UNIT_TESTS})
target_compile_options(${exename} PRIVATE -Wall -Wextra)
target_compile_definitions(${exename} PUBLIC SPH_EXA_HAVE_H5PART)
target_include_directories(${exename} PRIVATE ${MPI_CXX_INCLUDE_PATH})
target_include_directories(${exename} PRIVATE ${PLANET_DIR} ${CSTONE_DIR} ${SPH_DIR} ${PROJECT_SOURCE_DIR}/include ${MAIN_APP_DIR})

#target_link_libraries(${testname} PRIVATE grackle)
#target_link_libraries(${testname} PRIVATE cooler)
target_link_libraries(${testname} PRIVATE ${MPI_CXX_LIBRARIES} GTest::gtest_main)
#target_compile_definitions(${testname} PRIVATE PROJECT_SOURCE_DIR="${CMAKE_SOURCE_DIR}")
add_test(NAME ${testname} COMMAND ${testname})
target_link_libraries(${exename} PRIVATE ${MPI_CXX_LIBRARIES} GTest::gtest_main)

install(TARGETS ${testname} RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}/physics)
set(cmd ${exename})
list(PREPEND cmd "${MPIEXEC_EXECUTABLE}" " " "${MPIEXEC_NUMPROC_FLAG}" " 2 ")
add_test(NAME ${testname} COMMAND ${cmd})
install(TARGETS ${exename} RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}/physics)
60 changes: 9 additions & 51 deletions physics/Planet/test/accretion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ struct AccretionTest : public ::testing::Test
using ConservedFields = util::FieldList<"vx", "vy", "vz", "m">;
using DependentFields = util::FieldList<"keys", "u", "rho">;

inline constexpr static size_t n_elements = 20;
inline constexpr static size_t n_elements3 = n_elements * n_elements * n_elements;
inline constexpr static double inner_limit = 0.2;
inline constexpr static double dt = 1.;
inline constexpr static size_t n_elements = 20;
inline constexpr static size_t n_elements3 = n_elements * n_elements * n_elements;
inline constexpr static double inner_limit = 0.2;
inline constexpr static double initial_star_mass = 1.;
inline constexpr static double dt = 1.;

sphexa::ParticlesData<cstone::CpuTag> data;
std::unique_ptr<cstone::Domain<KeyType, T>> domain_ptr = nullptr;
Expand Down Expand Up @@ -66,6 +67,8 @@ struct AccretionTest : public ::testing::Test

star.inner_size = inner_limit;
star.removal_limit_h = INFINITY;
star.fixed_star = 0;
star.m = initial_star_mass;
}

void initData()
Expand Down Expand Up @@ -159,7 +162,7 @@ struct AccretionTest : public ::testing::Test
void testExchangeAndAccreteOnStar()
{
// Check if mass of star = mass of accreted particles
EXPECT_NEAR(star.m, 1. + mass_inside, 1e-9);
EXPECT_NEAR(star.m, initial_star_mass + mass_inside, 1e-9);
// Check momentum of star
EXPECT_NEAR(star.position_m1[0] / dt * star.m, momentum_inside_x, 1e-4);
EXPECT_NEAR(star.position_m1[1] / dt * star.m, momentum_inside_y, 1e-4);
Expand All @@ -169,7 +172,7 @@ struct AccretionTest : public ::testing::Test

TEST_F(AccretionTest, testAccretion)
{
// if (numRanks != 2) throw std::runtime_error("Must be excuted with two ranks");
if (numRanks != 2) throw std::runtime_error("Must be excuted with two ranks");

initData();

Expand All @@ -191,48 +194,3 @@ TEST_F(AccretionTest, testAccretion)
EXPECT_TRUE(n_inside == 0);
EXPECT_TRUE(n_inside_with_halos == 0);
}

TEST_F(AccretionTest, testAccretion2)
{
initData();

sync();

/*const size_t first = domain_ptr->startIndex();
const size_t last = domain_ptr->endIndex();
const double star_size2 = star.inner_size * star.inner_size;
double accr_mass{};
double accr_mom[3]{};
size_t n_accreted{};
size_t n_removed{};
for (size_t i = first; i < last; i++)
{
const double dx = data.x[i] - star.position[0];
const double dy = data.y[i] - star.position[1];
const double dz = data.z[i] - star.position[2];
const double dist2 = dx * dx + dy * dy + dz * dz;
if (dist2 < 0.02) {
printf("i: %zu\n", i);
printf("dx, dy, dz: %lf\t%lf\t%lf\n", dx, dy, dz);
data.keys[i] = cstone::removeKey<KeyType>::value; }
}*/

// data.keys[1831] = cstone::removeKey<KeyType>::value;
// data.keys[3609] = cstone::removeKey<KeyType>::value;
// data.keys[7331] = cstone::removeKey<KeyType>::value;
//
// data.keys[2168] = cstone::removeKey<KeyType>::value;
// data.keys[4390] = cstone::removeKey<KeyType>::value;
// data.keys[5826] = cstone::removeKey<KeyType>::value;
// data.keys[5830] = cstone::removeKey<KeyType>::value;
// data.keys[5831] = cstone::removeKey<KeyType>::value;
// data.keys[5832] = cstone::removeKey<KeyType>::value;
// data.keys[6168] = cstone::removeKey<KeyType>::value;

sync();
printf("count: %zu\n", data.keys.size());
}
2 changes: 2 additions & 0 deletions physics/Planet/test/planet_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ TEST_F(PlanetTest, testStarPosition)
star.position = {0., 1., 0.};
star.position_m1 = {0., 0., 0.};
star.force_local = {1., 0., 0.};
star.m = 1.0;
star.fixed_star = 0;

planet::computeAndExchangeStarPosition(star, 1., 1., rank);
if (rank == 0)
Expand Down
6 changes: 0 additions & 6 deletions sph/include/sph/eos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ HOST_DEVICE_FUN auto idealGasEOS_u(T1 u, T2 rho, T3 gamma)
template<class T1, class T2, class T3>
HOST_DEVICE_FUN auto idealGasEOSTemp(T1 temp, T2 rho, T3 mui, T1 gamma)
{
using Tc = std::common_type_t<T1, T2, T3>;
return idealGasEOS_u(idealGasCv(mui, gamma) * temp, rho, gamma);
/*Tc tmp = idealGasCv(mui, gamma) * temp * (gamma - Tc(1));
Tc p = rho * tmp;
Tc c = std::sqrt(tmp);
return util::tuple<Tc, Tc>{p, c};*/
}

/*! @brief Polytropic EOS for a 1.4 M_sun and 12.8 km neutron star
Expand Down

0 comments on commit 5f8a2d8

Please sign in to comment.