diff --git a/exercice_3/src/CMakeLists.txt b/exercice_3/src/CMakeLists.txt index a2df682..07d7fb3 100644 --- a/exercice_3/src/CMakeLists.txt +++ b/exercice_3/src/CMakeLists.txt @@ -1,82 +1,85 @@ cmake_minimum_required (VERSION 3.1) project (Particles) set(CMAKE_CXX_STANDARD 14) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") ################################################################ # libpart ################################################################ add_library(part compute_boundary.cc compute_verlet_integration.cc particle.cc planet.cc compute_gravity.cc csv_reader.cc particles_factory_interface.cc planets_factory.cc compute_contact.cc compute_kinetic_energy.cc csv_writer.cc system.cc compute_energy.cc compute_potential_energy.cc ping_pong_ball.cc material_point.cc system_evolution.cc ping_pong_balls_factory.cc compute_interaction.cc compute_temperature.cc material_points_factory.cc ) ################################################################ # FFTW ################################################################ option(USE_FFTW "Use FFTW library" ON) if (USE_FFTW) set(FFTW_LIBRARY_PATH CACHE PATH "Where to search FFTW3") find_library(FFTW_LIBRARY fftw3 ${FFTW_LIBRARY_PATH}) target_link_libraries(part fftw3) endif (USE_FFTW) add_executable(particles main.cc) target_link_libraries(particles part) ################################################################ # Google test ################################################################ include(GoogleTest) enable_testing() find_package(GTest) if (GTEST_FOUND) include_directories(${GTEST_INCLUDE_DIRS}) add_executable(test_kepler test_kepler.cc) add_executable(test_fft test_fft.cc) +add_executable(test_temperature test_temperature.cc) target_link_libraries(test_kepler part ${GTEST_BOTH_LIBRARIES} pthread) target_link_libraries(test_fft part ${GTEST_BOTH_LIBRARIES} ${FFTW_LIBRARY} pthread) +target_link_libraries(test_temperature part ${GTEST_BOTH_LIBRARIES} ${FFTW_LIBRARY} pthread) gtest_discover_tests(test_kepler) gtest_discover_tests(test_fft) +gtest_discover_tests(test_temperature) endif() ################################################################ # Doxygen ################################################################ find_package(Doxygen) if (DOXYGEN_FOUND) # to set other options, read: https://cmake.org/cmake/help/v3.9/module/FindDoxygen.html doxygen_add_docs( doxygen ${PROJECT_SOURCE_DIR} COMMENT "Generate html pages" ) add_custom_target(doc DEPENDS doxygen) endif(DOXYGEN_FOUND) diff --git a/exercice_3/src/test_temperature.cc b/exercice_3/src/test_temperature.cc new file mode 100644 index 0000000..7e8bb22 --- /dev/null +++ b/exercice_3/src/test_temperature.cc @@ -0,0 +1,41 @@ +#include "compute_temperature.hh" +#include "material_points_factory.hh" +#include "my_types.hh" +#include "system_evolution.hh" +#include + +/*****************************************************************/ +TEST(COMPUTE_TEMPERATURE, homogeneous) { + UInt N = 512; + + System system = System(); + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + // auto &val = std::get<2>(entry); + std::stringstream sstr; + // position (i, j, 0); temperature 10; 0 for the rest + std::string line = + std::to_string(i) + " " + std::to_string(i) + " 0 0 0 0 0 0 0 0 10 0"; + sstr << line; + auto p = MaterialPointsFactory::getInstance().createParticle(); + sstr >> *p; + system.addParticle(std::move(p)); + } + } + + ComputeTemperature compute_temperature = ComputeTemperature(); + // test 5 iterations - nothing should change regardless of the number of + // iterations + int nsteps = 5; + for (int step = 0; step < nsteps; ++step) + compute_temperature.compute(system); + + UInt nb_particles = system.getNbParticles(); + + for (UInt p = 0; p < nb_particles; ++p) { + MaterialPoint *mpoint = + static_cast(&system.getParticle(p)); + ASSERT_NEAR(mpoint->getTemperature(), 10, 1e-10); + } +}