diff --git a/CMakeLists.txt b/CMakeLists.txt index 740d0c2..502435a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,17 +48,27 @@ SET(mpm_point_gen_src add_executable(mpm_point_generator ${mpm_point_gen_src}) # Unit test -SET(test_src - ${PROJECT_SOURCE_DIR}/tests/test.cc +SET(unit_test_src + ${PROJECT_SOURCE_DIR}/tests/unit_test.cc ${PROJECT_SOURCE_DIR}/tests/point_test.cc ${PROJECT_SOURCE_DIR}/tests/material_properties_test.cc ) -add_executable(mpm_point_generator_test ${test_src}) +add_executable(mpm_point_generator_unit_test ${unit_test_src}) + +# Regression test +SET(regression_test_src + ${PROJECT_SOURCE_DIR}/tests/regression_test.cc + ${PROJECT_SOURCE_DIR}/tests/gmsh_test.cc +) +add_executable(mpm_point_generator_regression_test ${regression_test_src}) option(EIGEN3_HEADER_PATH "path to eigen3 header files, command line option" "") -add_test(NAME mpm_point_generator_test COMMAND $) +add_test(NAME mpm_point_generator_unit_test COMMAND $) +include(CTest) + +add_test(NAME mpm_point_generator_regression_test COMMAND $) include(CTest) find_program( MEMORYCHECK_COMMAND valgrind ) @@ -67,7 +77,7 @@ set( MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1" ) # Coverage find_package(codecov) add_coverage(mpm_point_generator) -add_coverage(mpm_point_generator_test) - +add_coverage(mpm_point_generator_unit_test) +add_coverage(mpm_point_generator_regression_test) -install(TARGETS mpm_point_generator mpm_point_generator_test RUNTIME DESTINATION bin) +install(TARGETS mpm_point_generator mpm_point_generator_unit_test mpm_point_generator_regression_test RUNTIME DESTINATION bin) diff --git a/bin/cube_test.msh b/bin/cube_test.msh new file mode 100644 index 0000000..5bb19bb --- /dev/null +++ b/bin/cube_test.msh @@ -0,0 +1,75 @@ +$MeshFormat +2.2 0 8 +$EndMeshFormat +$Nodes +18 +1 0 0 0 +2 1 0 0 +3 0 1 0 +4 1 1 0 +5 0 0 1 +6 1 0 1 +7 1 1 1 +8 0 1 1 +9 0.5 0 0 +10 0.5 1 0 +11 0.5 0 1 +12 0.5 1 1 +13 0 0 0.5 +14 1 0 0.5 +15 1 1 0.5 +16 0 1 0.5 +17 0.5 0 0.5 +18 0.5 1 0.5 +$EndNodes +$Elements +48 +1 15 2 0 1 1 +2 15 2 0 2 2 +3 15 2 0 3 3 +4 15 2 0 4 4 +5 15 2 0 5 5 +6 15 2 0 6 6 +7 15 2 0 10 7 +8 15 2 0 14 8 +9 1 2 0 1 1 9 +10 1 2 0 1 9 2 +11 1 2 0 2 3 10 +12 1 2 0 2 10 4 +13 1 2 0 3 1 3 +14 1 2 0 4 2 4 +15 1 2 0 7 5 11 +16 1 2 0 7 11 6 +17 1 2 0 8 6 7 +18 1 2 0 9 7 12 +19 1 2 0 9 12 8 +20 1 2 0 10 8 5 +21 1 2 0 12 1 13 +22 1 2 0 12 13 5 +23 1 2 0 13 2 14 +24 1 2 0 13 14 6 +25 1 2 0 17 4 15 +26 1 2 0 17 15 7 +27 1 2 0 21 3 16 +28 1 2 0 21 16 8 +29 3 2 0 5 1 9 10 3 +30 3 2 0 5 9 2 4 10 +31 3 2 0 14 1 9 17 13 +32 3 2 0 14 13 17 11 5 +33 3 2 0 14 9 2 14 17 +34 3 2 0 14 17 14 6 11 +35 3 2 0 18 2 4 15 14 +36 3 2 0 18 14 15 7 6 +37 3 2 0 22 3 16 18 10 +38 3 2 0 22 16 8 12 18 +39 3 2 0 22 10 18 15 4 +40 3 2 0 22 18 12 7 15 +41 3 2 0 26 1 13 16 3 +42 3 2 0 26 13 5 8 16 +43 3 2 0 27 5 11 12 8 +44 3 2 0 27 11 6 7 12 +45 5 2 0 1 1 9 10 3 13 17 18 16 +46 5 2 0 1 13 17 18 16 5 11 12 8 +47 5 2 0 1 9 2 4 10 17 14 15 18 +48 5 2 0 1 17 14 15 18 11 6 7 12 +$EndElements \ No newline at end of file diff --git a/tests/gmsh_test.cc b/tests/gmsh_test.cc new file mode 100644 index 0000000..2405c2e --- /dev/null +++ b/tests/gmsh_test.cc @@ -0,0 +1,88 @@ +// GMSH test +#include +#include + +#include + +#include "catch.hpp" +#include "material_points.h" +#include "gmsh.h" +#include "regression_global.h" + + +//! Alias for JSON +#include "json.hpp" +using json = nlohmann::json; + +//! \brief Check that IO will store right values +TEST_CASE("GMSH is checked in 3D", "[GMSH][3D]") { + + //! 3D Test of IO Class + const unsigned DIM = 3; + const double tolerance = 1.E-12; + + //! Make json object with material in it + json material_json= { + {"density", 2000}, + {"k0", 0.5} + }; + + //! Make pointers to mesh and MaterialProperties + auto mesh = std::unique_ptr> (new GMSH<3, 8>()); + auto material = std::shared_ptr (new MaterialProperties(material_json)); + + mesh->read_mesh(filename); + mesh->compute_material_points(1); + mesh->assign_material_properties(material); + mesh->compute_stresses(); + + //! Check number of vertices + REQUIRE(mesh->nvertices() == 18); + + //! Get coordinates and stress + std::vector coordinates = mesh->coordinates(); + std::vector stresses = mesh->stress(); + + //! Check size + REQUIRE(mesh->coordinates().size() == 4); + + //! Check coordinates + REQUIRE(coordinates.at(0)[0] == Approx(0.25).epsilon(tolerance)); + REQUIRE(coordinates.at(0)[1] == Approx(0.50).epsilon(tolerance)); + REQUIRE(coordinates.at(0)[2] == Approx(0.25).epsilon(tolerance)); + REQUIRE(coordinates.at(1)[0] == Approx(0.25).epsilon(tolerance)); + REQUIRE(coordinates.at(1)[1] == Approx(0.50).epsilon(tolerance)); + REQUIRE(coordinates.at(1)[2] == Approx(0.75).epsilon(tolerance)); + REQUIRE(coordinates.at(2)[0] == Approx(0.75).epsilon(tolerance)); + REQUIRE(coordinates.at(2)[1] == Approx(0.50).epsilon(tolerance)); + REQUIRE(coordinates.at(2)[2] == Approx(0.25).epsilon(tolerance)); + REQUIRE(coordinates.at(3)[0] == Approx(0.75).epsilon(tolerance)); + REQUIRE(coordinates.at(3)[1] == Approx(0.50).epsilon(tolerance)); + REQUIRE(coordinates.at(3)[2] == Approx(0.75).epsilon(tolerance)); + + //! Check stress + REQUIRE(stresses.at(0)[0] == Approx(-4905).epsilon(tolerance)); + REQUIRE(stresses.at(0)[1] == Approx(-4905).epsilon(tolerance)); + REQUIRE(stresses.at(0)[2] == Approx(-9810).epsilon(tolerance)); + REQUIRE(stresses.at(0)[3] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(0)[4] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(0)[5] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(1)[0] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(1)[1] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(1)[2] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(1)[3] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(1)[4] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(1)[5] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(2)[0] == Approx(-4905).epsilon(tolerance)); + REQUIRE(stresses.at(2)[1] == Approx(-4905).epsilon(tolerance)); + REQUIRE(stresses.at(2)[2] == Approx(-9810).epsilon(tolerance)); + REQUIRE(stresses.at(2)[3] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(2)[4] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(2)[5] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(3)[0] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(3)[1] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(3)[2] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(3)[3] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(3)[4] == Approx(0).epsilon(tolerance)); + REQUIRE(stresses.at(3)[5] == Approx(0).epsilon(tolerance)); +} \ No newline at end of file diff --git a/tests/regression_global.h b/tests/regression_global.h new file mode 100644 index 0000000..9355a90 --- /dev/null +++ b/tests/regression_global.h @@ -0,0 +1,6 @@ +#ifndef REGRESSION_GLOBAL_H_ +#define REGRESSION_GLOBAL_H_ + +extern std::string filename; + +#endif // REGRESSION_GLOBAL_H_ diff --git a/tests/regression_test.cc b/tests/regression_test.cc new file mode 100644 index 0000000..781b7db --- /dev/null +++ b/tests/regression_test.cc @@ -0,0 +1,27 @@ +#define CATCH_CONFIG_RUNNER +#include "catch.hpp" +#include "regression_global.h" + +std::string filename; + +int main(int argc, char** argv) { + + try { + //! Check the number of arguments + if (argc != 2) { + std::cout << "Usage: ./mpm_point_generator_regression_test /path/to/meshfile.msh\n"; + throw std::runtime_error("Incorrect number of input arguments"); + } + + //! Pass the argument of the file + filename = argv[1]; + + int result = Catch::Session().run(); + + return ( result < 0xff ? result : 0xff ); + + } catch (std::exception& except) { + std::cout << "Caught exception: " << except.what() << '\n'; + } + +} \ No newline at end of file diff --git a/tests/test.cc b/tests/unit_test.cc similarity index 100% rename from tests/test.cc rename to tests/unit_test.cc