diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90efd637c6..fe71a13a45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,10 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 + - uses: actions/checkout@v2 + with: + submodules: '3rd_party/pybind11@3cc7e42' + - name: Install system dependencies run: | @@ -121,6 +124,9 @@ jobs: steps: - uses: actions/checkout@v3 # Checks-out the repository under ${{github.workspace}} + with: + submodules: '3rd_party/pybind11@3cc7e42' + - name: Update ccache and ninja # For correct caching with ccache on Windows shell: bash @@ -210,6 +216,9 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 + with: + submodules: '3rd_party/pybind11@3cc7e42' + - name: Install system dependencies run: | diff --git a/.gitmodules b/.gitmodules index b869143701..141227c17d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "3rd_party/wasmtbb"] path = 3rd_party/wasmtbb url = https://github.com/hpcwasm/wasmtbb.git +[submodule "3rd_party/pybind11"] + path = 3rd_party/pybind11 + url = https://github.com/pybind/pybind11.git diff --git a/3rd_party/pybind11 b/3rd_party/pybind11 new file mode 160000 index 0000000000..3cc7e4258c --- /dev/null +++ b/3rd_party/pybind11 @@ -0,0 +1 @@ +Subproject commit 3cc7e4258c15a6a19ba5e0b62a220b1a6196d4eb diff --git a/CMakeLists.txt b/CMakeLists.txt index e4266f64e4..2a71a80775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES Windows) else() target_compile_options(sphinxsys_core INTERFACE $<$:-Werror>) target_compile_options(sphinxsys_core INTERFACE $<$:-Wall>) + target_compile_options(sphinxsys_core INTERFACE $<$:-fPIC>) # For pybind in Linux # target_compile_options(sphinxsys_core INTERFACE $<$:-Wextra>) # TODO: # target_compile_options(sphinxsys_core INTERFACE $<$:-Wpedantic>) # For strict C++ standard compliance # TODO: endif() @@ -80,6 +81,7 @@ endif() #------ Setup the concrete libraries add_subdirectory(SPHINXsys) add_subdirectory(modules) +add_subdirectory(3rd_party/pybind11) #------ Setup the tests if(SPHINXSYS_BUILD_TESTS) diff --git a/SPHINXsys/src/for_2D_build/geometries/level_set_supplementary.cpp b/SPHINXsys/src/for_2D_build/geometries/level_set_supplementary.cpp index f0916fec34..40c0f9d590 100644 --- a/SPHINXsys/src/for_2D_build/geometries/level_set_supplementary.cpp +++ b/SPHINXsys/src/for_2D_build/geometries/level_set_supplementary.cpp @@ -1,6 +1,5 @@ #include "level_set.h" -#include "mesh_with_data_packages.hpp" #include "mesh_iterators.hpp" #include "base_kernel.h" #include "base_particles.h" diff --git a/SPHINXsys/src/for_3D_build/geometries/level_set_supplementary.cpp b/SPHINXsys/src/for_3D_build/geometries/level_set_supplementary.cpp index 403498ba20..40c63dd7c7 100644 --- a/SPHINXsys/src/for_3D_build/geometries/level_set_supplementary.cpp +++ b/SPHINXsys/src/for_3D_build/geometries/level_set_supplementary.cpp @@ -1,5 +1,4 @@ #include "level_set.h" -#include "mesh_with_data_packages.hpp" #include "mesh_iterators.hpp" #include "base_kernel.h" #include "base_particles.h" diff --git a/SPHINXsys/src/shared/geometries/level_set.cpp b/SPHINXsys/src/shared/geometries/level_set.cpp index 7624221db2..7efd708634 100644 --- a/SPHINXsys/src/shared/geometries/level_set.cpp +++ b/SPHINXsys/src/shared/geometries/level_set.cpp @@ -1,8 +1,6 @@ #include "level_set.h" #include "adaptation.h" -#include "mesh_with_data_packages.hpp" - namespace SPH { //=================================================================================================// diff --git a/SPHINXsys/src/shared/geometries/level_set.h b/SPHINXsys/src/shared/geometries/level_set.h index c7c2c6bfbd..3a9f12a441 100644 --- a/SPHINXsys/src/shared/geometries/level_set.h +++ b/SPHINXsys/src/shared/geometries/level_set.h @@ -29,7 +29,7 @@ #ifndef LEVEL_SET_H #define LEVEL_SET_H -#include "mesh_with_data_packages.h" +#include "mesh_with_data_packages.hpp" #include "adaptation.h" #include "base_geometry.h" diff --git a/SPHINXsys/src/shared/include/sphinxsys.h b/SPHINXsys/src/shared/include/sphinxsys.h index e98256bcb1..0a0eaef9da 100644 --- a/SPHINXsys/src/shared/include/sphinxsys.h +++ b/SPHINXsys/src/shared/include/sphinxsys.h @@ -41,5 +41,6 @@ #include "io_all.h" #include "parameterization.h" #include "regression_test.h" +#include "sph_python.h" #endif //SPHINXSYS_H diff --git a/SPHINXsys/src/shared/sphinxsys_python/sph_python.h b/SPHINXsys/src/shared/sphinxsys_python/sph_python.h new file mode 100644 index 0000000000..064eecb62a --- /dev/null +++ b/SPHINXsys/src/shared/sphinxsys_python/sph_python.h @@ -0,0 +1,45 @@ +/* -------------------------------------------------------------------------* + * SPHinXsys * + * -------------------------------------------------------------------------* + * SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle* + * Hydrodynamics for industrial compleX systems. It provides C++ APIs for * + * physical accurate simulation and aims to model coupled industrial dynamic* + * systems including fluid, solid, multi-body dynamics and beyond with SPH * + * (smoothed particle hydrodynamics), a meshless computational method using * + * particle discretization. * + * * + * SPHinXsys is partially funded by German Research Foundation * + * (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1, * + * HU1527/12-1 and HU1527/12-4 * + * * + * Portions copyright (c) 2017-2022 Technical University of Munich and * + * the authors' affiliations. * + * * + * Licensed under the Apache License, Version 2.0 (the "License"); you may * + * not use this file except in compliance with the License. You may obtain a* + * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * + * * + * ------------------------------------------------------------------------*/ +/** + * @file sph_python.h + * @brief Interface for sph and pyhton code. + */ + +#ifndef SPH_PYTHON_H +#define SPH_PYTHON_H + +namespace SPH { + + class SphPython + { + public: + explicit SphPython() {}; + virtual ~SphPython() {}; + + //*** Functions for override. ***// + virtual int cmakeTest() = 0; + virtual void runCase(Real End_time) = 0; + }; +}; + +#endif // SPH_PYTHON_H \ No newline at end of file diff --git a/tests/2d_examples/test_2d_dambreak_python/CMakeLists.txt b/tests/2d_examples/test_2d_dambreak_python/CMakeLists.txt new file mode 100644 index 0000000000..8b145ee15b --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/CMakeLists.txt @@ -0,0 +1,28 @@ +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) # main (top) cmake dir + +set(CMAKE_VERBOSE_MAKEFILE on) + +STRING( REGEX REPLACE ".*/(.*)" "\\1" CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} ) +PROJECT("${CURRENT_FOLDER}") + +SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) +SET(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin/") +SET(BUILD_INPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/input") +SET(BUILD_RELOAD_PATH "${EXECUTABLE_OUTPUT_PATH}/reload") +SET(BUILD_BIND_PATH "${EXECUTABLE_OUTPUT_PATH}/bind") + +file(MAKE_DIRECTORY ${BUILD_INPUT_PATH}) +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/regression_test_tool/ + DESTINATION ${BUILD_INPUT_PATH}) + +file(MAKE_DIRECTORY ${BUILD_BIND_PATH}) +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/pybind_tool/ + DESTINATION ${BUILD_BIND_PATH}) + +aux_source_directory(. DIR_SRCS) +pybind11_add_module(${PROJECT_NAME} ${EXECUTABLE_OUTPUT_PATH} ${DIR_SRCS} ) +set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") +target_link_libraries(${PROJECT_NAME} PRIVATE sphinxsys_2d) + +add_test(NAME ${PROJECT_NAME} COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pybind_tool/pybind_test.py) +set_tests_properties(${PROJECT_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "1") diff --git a/tests/2d_examples/test_2d_dambreak_python/dambreak_python.cpp b/tests/2d_examples/test_2d_dambreak_python/dambreak_python.cpp new file mode 100644 index 0000000000..1767c324ae --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/dambreak_python.cpp @@ -0,0 +1,298 @@ +/** + * @file dambreak_python.cpp + * @brief 2D dambreak example with pybind11 for python. + * @details This is the one of the basic test cases, also the first case for + * understanding SPH method for fluid simulation. + * @author Luhui Han, Chi Zhang and Xiangyu Hu + */ +#include //pybind11 Library. +#include "sphinxsys.h" //SPHinXsys Library. +namespace py = pybind11; +using namespace SPH; // Namespace cite here. +//---------------------------------------------------------------------- +// Basic geometry parameters and numerical setup. +//---------------------------------------------------------------------- +class Parameter +{ +protected: + Real DL = 5.366; /**< Water tank length. */ + Real DH = 5.366; /**< Water tank height. */ + Real LL = 2.0; /**< Water column length. */ + Real LH = 1.0; /**< Water column height. */ + Real particle_spacing_ref = 0.025; /**< Initial reference particle spacing. */ + Real BW = particle_spacing_ref * 4; /**< Thickness of tank wall. */ + //---------------------------------------------------------------------- + // Material parameters. + //---------------------------------------------------------------------- + Real rho0_f = 1.0; /**< Reference density of fluid. */ + Real gravity_g = 1.0; /**< Gravity. */ + Real U_max = 2.0 * sqrt(gravity_g * LH); /**< Characteristic velocity. */ + Real c_f = 10.0 * U_max; /**< Reference sound speed. */ + //---------------------------------------------------------------------- + // Geometric shapes used in this case. + //---------------------------------------------------------------------- + Vec2d water_block_halfsize = Vec2d(0.5 * LL, 0.5 * LH); // local center at origin + Vec2d water_block_translation = water_block_halfsize; // translation to global coordinates + Vec2d outer_wall_halfsize = Vec2d(0.5 * DL + BW, 0.5 * DH + BW); + Vec2d outer_wall_translation = Vec2d(-BW, -BW) + outer_wall_halfsize; + Vec2d inner_wall_halfsize = Vec2d(0.5 * DL, 0.5 * DH); + Vec2d inner_wall_translation = inner_wall_halfsize; +}; +//---------------------------------------------------------------------- +// Complex shape for wall boundary, note that no partial overlap is allowed +// for the shapes in a complex shape. +//---------------------------------------------------------------------- +class WallBoundary : public ComplexShape, public Parameter +{ +public: + explicit WallBoundary(const std::string &shape_name) : ComplexShape(shape_name) + { + add>(Transform2d(outer_wall_translation), outer_wall_halfsize); + subtract>(Transform2d(inner_wall_translation), inner_wall_halfsize); + } +}; +//---------------------------------------------------------------------- +// Define system, geometry, material, particles and all other things. +//---------------------------------------------------------------------- +class PreSettingCase : public Parameter +{ +protected: + BoundingBox system_domain_bounds; + SPHSystem sph_system; + IOEnvironment io_environment; + FluidBody water_block; + SolidBody wall_boundary; + StdVec observation_location; + ObserverBody fluid_observer; + +public: + PreSettingCase(): + system_domain_bounds(Vec2d(-BW, -BW), Vec2d(DL + BW, DH + BW)), + sph_system(system_domain_bounds, particle_spacing_ref), + io_environment(sph_system), + water_block(sph_system, makeShared>( + Transform2d(water_block_translation), water_block_halfsize, "WaterBody")), + wall_boundary(sph_system, makeShared("WallBoundary")), + observation_location({ Vecd(DL, 0.2) }), + fluid_observer(sph_system, "FluidObserver") + { + //---------------------------------------------------------------------- + // Creating bodies with corresponding materials and particles. + //---------------------------------------------------------------------- + water_block.defineParticlesAndMaterial(rho0_f, c_f); + water_block.generateParticles(); + + wall_boundary.defineParticlesAndMaterial(); + wall_boundary.generateParticles(); + wall_boundary.addBodyStateForRecording("NormalDirection"); + + fluid_observer.generateParticles(observation_location); + } +}; +//---------------------------------------------------------------------- +// Define environment. +//---------------------------------------------------------------------- +class Environment : public SphPython, public PreSettingCase +{ +protected: + //---------------------------------------------------------------------- + // Define body relation map. + // The contact map gives the topological connections between the bodies. + // Basically the the range of bodies to build neighbor particle lists. + //---------------------------------------------------------------------- + ComplexRelation water_block_complex; + ContactRelation fluid_observer_contact; + //---------------------------------------------------------------------- + // Define the numerical methods used in the simulation. + // Note that there may be data dependence on the sequence of constructions. + //---------------------------------------------------------------------- + Dynamics1Level fluid_pressure_relaxation; + Dynamics1Level fluid_density_relaxation; + InteractionWithUpdate fluid_density_by_summation; + SimpleDynamics wall_boundary_normal_direction; + SharedPtr gravity_ptr; + SimpleDynamics fluid_step_initialization; + ReduceDynamics fluid_advection_time_step; + ReduceDynamics fluid_acoustic_time_step; + //---------------------------------------------------------------------- + // Define the methods for I/O operations, observations + // and regression tests of the simulation. + //---------------------------------------------------------------------- + BodyStatesRecordingToVtp body_states_recording; + RestartIO restart_io; + RegressionTestDynamicTimeWarping>> + write_water_mechanical_energy; + RegressionTestDynamicTimeWarping> + write_recorded_water_pressure; + //---------------------------------------------------------------------- + // Setup for time-stepping control + //---------------------------------------------------------------------- + int screen_output_interval = 100; + int observation_sample_interval = screen_output_interval * 2; + int restart_output_interval = screen_output_interval * 10; + Real output_interval = 0.1; + //---------------------------------------------------------------------- + // Statistics for CPU time + //---------------------------------------------------------------------- + tick_count t1 = tick_count::now(); + tick_count::interval_t interval; + tick_count::interval_t interval_computing_time_step; + tick_count::interval_t interval_computing_fluid_pressure_relaxation; + tick_count::interval_t interval_updating_configuration; + tick_count time_instance; + +public: + explicit Environment(int set_restart_step) : + SphPython(), + PreSettingCase(), + water_block_complex(water_block, { &wall_boundary }), + fluid_observer_contact(fluid_observer, { &water_block }), + fluid_pressure_relaxation(water_block_complex), + fluid_density_relaxation(water_block_complex), + fluid_density_by_summation(water_block_complex), + wall_boundary_normal_direction(wall_boundary), + gravity_ptr(makeShared(Vecd(0.0, -gravity_g))), + fluid_step_initialization(water_block, gravity_ptr), + fluid_advection_time_step(water_block, U_max), + fluid_acoustic_time_step(water_block), + body_states_recording(io_environment, sph_system.real_bodies_), + restart_io(io_environment, sph_system.real_bodies_), + write_water_mechanical_energy(io_environment, water_block, gravity_ptr), + write_recorded_water_pressure("Pressure", io_environment, fluid_observer_contact) + { + //---------------------------------------------------------------------- + // Prepare the simulation with cell linked list, configuration + // and case specified initial condition if necessary. + //---------------------------------------------------------------------- + /** set restart step. */ + sph_system.setRestartStep(set_restart_step); + sph_system.initializeSystemCellLinkedLists(); + sph_system.initializeSystemConfigurations(); + wall_boundary_normal_direction.parallel_exec(); + //---------------------------------------------------------------------- + // Load restart file if necessary. + //---------------------------------------------------------------------- + if (sph_system.RestartStep() != 0) + { + GlobalStaticVariables::physical_time_ = restart_io.readRestartFiles(sph_system.RestartStep()); + water_block.updateCellLinkedList(); + water_block_complex.updateConfiguration(); + fluid_observer_contact.updateConfiguration(); + } + //---------------------------------------------------------------------- + // First output before the main loop. + //---------------------------------------------------------------------- + body_states_recording.writeToFile(); + write_water_mechanical_energy.writeToFile(sph_system.RestartStep()); + write_recorded_water_pressure.writeToFile(sph_system.RestartStep()); + } + + virtual ~Environment() {}; + //---------------------------------------------------------------------- + // For ctest. + //---------------------------------------------------------------------- + int cmakeTest() + { + return 1; + } + //---------------------------------------------------------------------- + // Main loop starts here. + //---------------------------------------------------------------------- + void runCase(Real End_time) + { + /** Set restart number of iterations. */ + size_t number_of_iterations = sph_system.RestartStep(); + while (GlobalStaticVariables::physical_time_ < End_time) + { + Real integration_time = 0.0; + /** Integrate time (loop) until the next output time. */ + while (integration_time < output_interval) + { + /** outer loop for dual-time criteria time-stepping. */ + time_instance = tick_count::now(); + fluid_step_initialization.parallel_exec(); + Real advection_dt = fluid_advection_time_step.parallel_exec(); + fluid_density_by_summation.parallel_exec(); + interval_computing_time_step += tick_count::now() - time_instance; + + time_instance = tick_count::now(); + Real relaxation_time = 0.0; + Real acoustic_dt = 0.0; + while (relaxation_time < advection_dt) + { + /** inner loop for dual-time criteria time-stepping. */ + acoustic_dt = fluid_acoustic_time_step.parallel_exec(); + fluid_pressure_relaxation.parallel_exec(acoustic_dt); + fluid_density_relaxation.parallel_exec(acoustic_dt); + relaxation_time += acoustic_dt; + integration_time += acoustic_dt; + GlobalStaticVariables::physical_time_ += acoustic_dt; + } + interval_computing_fluid_pressure_relaxation += tick_count::now() - time_instance; + + /** screen output, write body reduced values and restart files */ + if (number_of_iterations % screen_output_interval == 0) + { + std::cout << std::fixed << std::setprecision(9) << "N=" << number_of_iterations << " Time = " + << GlobalStaticVariables::physical_time_ + << " advection_dt = " << advection_dt << " acoustic_dt = " << acoustic_dt << "\n"; + + if (number_of_iterations % observation_sample_interval == 0 && number_of_iterations != sph_system.RestartStep()) + { + write_water_mechanical_energy.writeToFile(number_of_iterations); + write_recorded_water_pressure.writeToFile(number_of_iterations); + } + if (number_of_iterations % restart_output_interval == 0) + restart_io.writeToFile(number_of_iterations); + } + number_of_iterations++; + + /** Update cell linked list and configuration. */ + time_instance = tick_count::now(); + water_block.updateCellLinkedListWithParticleSort(100); + water_block_complex.updateConfiguration(); + fluid_observer_contact.updateConfiguration(); + interval_updating_configuration += tick_count::now() - time_instance; + } + + body_states_recording.writeToFile(); + tick_count t2 = tick_count::now(); + tick_count t3 = tick_count::now(); + interval += t3 - t2; + } + tick_count t4 = tick_count::now(); + + tick_count::interval_t tt; + tt = t4 - t1 - interval; + std::cout << "Total wall time for computation: " << tt.seconds() + << " seconds." << std::endl; + std::cout << std::fixed << std::setprecision(9) << "interval_computing_time_step =" + << interval_computing_time_step.seconds() << "\n"; + std::cout << std::fixed << std::setprecision(9) << "interval_computing_fluid_pressure_relaxation = " + << interval_computing_fluid_pressure_relaxation.seconds() << "\n"; + std::cout << std::fixed << std::setprecision(9) << "interval_updating_configuration = " + << interval_updating_configuration.seconds() << "\n"; + + if (sph_system.generate_regression_data_) + { + write_water_mechanical_energy.generateDataBase(1.0e-3); + write_recorded_water_pressure.generateDataBase(1.0e-3); + } + else if (sph_system.RestartStep() == 0) + { + write_water_mechanical_energy.newResultTest(); + write_recorded_water_pressure.newResultTest(); + } + } +}; +//---------------------------------------------------------------------- +// Use pybind11 to expose. +//---------------------------------------------------------------------- +/** test_2d_dambreak_python should be same with the project name */ +PYBIND11_MODULE(test_2d_dambreak_python, m) +{ + py::class_(m, "dambreak_from_sph_cpp") + .def(py::init()) + .def("CmakeTest", &Environment::cmakeTest) + .def("RunCase", &Environment::runCase); +} diff --git a/tests/2d_examples/test_2d_dambreak_python/pybind_tool/pybind_test.py b/tests/2d_examples/test_2d_dambreak_python/pybind_tool/pybind_test.py new file mode 100644 index 0000000000..462e62df06 --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/pybind_tool/pybind_test.py @@ -0,0 +1,28 @@ +# !/usr/bin/env python3 +import os +import sys +import platform +import argparse +# add dynamic link library or shared object to python env +# attention: match current python version with the version exposing the cpp code +sys_str = platform.system() +path_1 = os.path.abspath(os.path.join(os.getcwd(), '../..')) +if sys_str == 'Windows': + path_2 = 'lib\\RelWithDebInfo' +elif sys_str == 'Linux': + path_2 = 'lib' +else: + # depend on the system + path_2 = 'lib' +path = os.path.join(path_1, path_2) +sys.path.append(path) +# change import depending on the project name +import test_2d_dambreak_python as test_2d + +ctest = test_2d.dambreak_from_sph_cpp(0) +result = ctest.CmakeTest() + +return result + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/pybind_tool/pybind_tool.py b/tests/2d_examples/test_2d_dambreak_python/pybind_tool/pybind_tool.py new file mode 100644 index 0000000000..a04c8a60c6 --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/pybind_tool/pybind_tool.py @@ -0,0 +1,34 @@ +# !/usr/bin/env python3 +import os +import sys +import platform +import argparse +# add dynamic link library or shared object to python env +# attention: match current python version with the version exposing the cpp code +sys_str = platform.system() +path_1 = os.path.abspath(os.path.join(os.getcwd(), '../..')) +if sys_str == 'Windows': + path_2 = 'lib\\RelWithDebInfo' +elif sys_str == 'Linux': + path_2 = 'lib' +else: + # depend on the system + path_2 = 'lib' +path = os.path.join(path_1, path_2) +sys.path.append(path) +# change import depending on the project name +import test_2d_dambreak_python as test_2d + +parser = argparse.ArgumentParser() +# set case parameters +parser.add_argument("--restart_step", default=0, type=int) +parser.add_argument("--end_time", default=20, type=int) +case = parser.parse_args() +# set project from class, which is set in cpp pybind module +project = test_2d.dambreak_from_sph_cpp(case.restart_step) +print('Start running: ') +project.RunCase(case.end_time) +print('End!') + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_Run_0_result.xml b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_Run_0_result.xml new file mode 100644 index 0000000000..fe63aab918 --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_Run_0_result.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_Run_14_result.xml b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_Run_14_result.xml new file mode 100644 index 0000000000..26f2c5636c --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_Run_14_result.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_Run_7_result.xml b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_Run_7_result.xml new file mode 100644 index 0000000000..6e76b39aa6 --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_Run_7_result.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_dtwdistance.xml b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_dtwdistance.xml new file mode 100644 index 0000000000..a11b3bba5e --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_dtwdistance.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_runtimes.dat b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_runtimes.dat new file mode 100644 index 0000000000..9c41804468 --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/FluidObserver_Pressure_runtimes.dat @@ -0,0 +1,3 @@ +true +15 +4 \ No newline at end of file diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_Run_0_result.xml b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_Run_0_result.xml new file mode 100644 index 0000000000..e3eefe99ba --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_Run_0_result.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_Run_10_result.xml b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_Run_10_result.xml new file mode 100644 index 0000000000..b9e557093d --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_Run_10_result.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_Run_5_result.xml b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_Run_5_result.xml new file mode 100644 index 0000000000..859285cd4c --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_Run_5_result.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_dtwdistance.xml b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_dtwdistance.xml new file mode 100644 index 0000000000..eaf89cd547 --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_dtwdistance.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_runtimes.dat b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_runtimes.dat new file mode 100644 index 0000000000..452899ced3 --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/WaterBody_TotalMechanicalEnergy_runtimes.dat @@ -0,0 +1,3 @@ +true +16 +4 \ No newline at end of file diff --git a/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/regression_test_tool.py b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/regression_test_tool.py new file mode 100644 index 0000000000..8f3d795957 --- /dev/null +++ b/tests/2d_examples/test_2d_dambreak_python/regression_test_tool/regression_test_tool.py @@ -0,0 +1,44 @@ +# !/usr/bin/env python3 +import os +import sys + +path = os.path.abspath('../../../../../PythonScriptStore/RegressionTest') +sys.path.append(path) +from regression_test_base_tool import SphinxsysRegressionTest + +""" +case name: test_2d_dambreak +""" + +case_name = "test_2d_dambreak" +body_name = "WaterBody" +parameter_name = "TotalMechanicalEnergy" +body_name_1 = "FluidObserver" +parameter_name_1 = "Pressure" + +number_of_run_times = 0 +converged = 0 +sphinxsys = SphinxsysRegressionTest(case_name, body_name, parameter_name) +sphinxsys_1 = SphinxsysRegressionTest(case_name, body_name_1, parameter_name_1) + + +while True: + print("Now start a new run......") + sphinxsys.run_case() + number_of_run_times += 1 + converged = sphinxsys.read_dat_file() + converged_1 = sphinxsys_1.read_dat_file() + print("Please note: This is the", number_of_run_times, "run!") + if number_of_run_times <= 200: + if (converged == "true") and (converged_1 == "true"): + print("The tested parameters of all variables are converged, and the run will stop here!") + break + elif converged != "true": + print("The tested parameters of", sphinxsys.sphinxsys_parameter_name, "are not converged!") + continue + elif converged_1 != "true": + print("The tested parameters of", sphinxsys_1.sphinxsys_parameter_name, "are not converged!") + continue + else: + print("It's too many runs but still not converged, please try again!") + break