Skip to content

Commit

Permalink
Merge pull request #418 from Xiangyu-Hu/fix/clean_after_test
Browse files Browse the repository at this point in the history
state-recording switch
  • Loading branch information
Xiangyu-Hu authored Aug 30, 2023
2 parents 93b6c62 + 9107fb7 commit 1a06b77
Show file tree
Hide file tree
Showing 239 changed files with 2,103 additions and 2,279 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ jobs:
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
-D SPHINXSYS_CI=ON \
-D SPHINXSYS_USE_FLOAT=OFF \
-D TEST_STATE_RECORDING=OFF \
-D SPHINXSYS_MODULE_OPENCASCADE=ON \
-S ${{github.workspace}} \
-B ${{github.workspace}}/build
Expand Down Expand Up @@ -292,6 +293,7 @@ jobs:
-D CMAKE_TOOLCHAIN_FILE="${{github.workspace}}\vcpkg\scripts\buildsystems\vcpkg.cmake" `
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache `
-D SPHINXSYS_CI=ON `
-D TEST_STATE_RECORDING=OFF `
-S ${{github.workspace}} `
-B C:\build
Expand Down Expand Up @@ -388,6 +390,7 @@ jobs:
-D CMAKE_TOOLCHAIN_FILE="${{github.workspace}}/vcpkg/scripts/buildsystems/vcpkg.cmake" \
-D CMAKE_C_COMPILER_LAUNCHER=ccache -D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
-D SPHINXSYS_CI=ON \
-D TEST_STATE_RECORDING=OFF \
-S ${{github.workspace}} \
-B ${{github.workspace}}/build
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ include(Common) # brings macro to current namespace
option(SPHINXSYS_2D "Build sphinxsys_2d library" ON)
option(SPHINXSYS_3D "Build sphinxsys_3d library" ON)
option(SPHINXSYS_BUILD_TESTS "Build tests" ON)
option(TEST_STATE_RECORDING "State recording when run Ctest" ON)
option(SPHINXSYS_DEVELOPER_MODE "Developer mode has more flags active for code quality" ON)
option(SPHINXSYS_USE_FLOAT "Build using float (single-precision floating-point format) as primary type" OFF)
option(SPHINXSYS_MODULE_OPENCASCADE "Build extension relying on OpenCASCADE" OFF)
Expand Down
16 changes: 16 additions & 0 deletions PythonScriptStore/RegressionTest/regression_test_base_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def run_particle_relaxation(self) -> None:
def run_case(self) -> None:
print('Start case simulation...')
print(self.enter_sphinxsys_exec_folder)
command = f".{os.sep}{self.sphinxsys_case_name} --r=false --rt=true"
os.system(self.enter_sphinxsys_exec_folder)
os.system(command)
print('Simulating case is finished...')

def run_case_with_reload(self) -> None:
print('Start case simulation with particle reload...')
print(self.enter_sphinxsys_exec_folder)
command = f".{os.sep}{self.sphinxsys_case_name} --r=false --i=true --rt=true"
os.system(self.enter_sphinxsys_exec_folder)
os.system(command)
Expand Down Expand Up @@ -96,6 +104,14 @@ def run_particle_relaxation(self) -> None:
def run_case(self) -> None:
print('Start case simulation...')
print(self.enter_sphinxsys_exec_folder)
command = f".{os.sep}{self.sphinxsys_case_name} --r=false --rt=true"
os.chdir(self.sphinxsys_exec_path)
os.system(command)
print('Simulating case is finished...')

def run_case_with_reload(self) -> None:
print('Start case simulation with particle reload...')
print(self.enter_sphinxsys_exec_folder)
command = f".{os.sep}{self.sphinxsys_case_name} --r=false --i=true --rt=true"
os.chdir(self.sphinxsys_exec_path)
os.system(command)
Expand Down
4 changes: 2 additions & 2 deletions modules/opencascade/tests/test_3d_aortic_valve/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ target_link_libraries(${PROJECT_NAME} sphinxsys_opencascade)
set_target_properties(${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}")

add_test(NAME ${PROJECT_NAME}
COMMAND ${PROJECT_NAME}
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
COMMAND ${PROJECT_NAME} --state_recording=${TEST_STATE_RECORDING}
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
26 changes: 13 additions & 13 deletions modules/opencascade/tests/test_3d_aortic_valve/aortic_valve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
* @details We use this case to test the particle generation and relaxation for a surface geometry (3D).
*/

#include "sphinxsys.h" // SPHinXsys Library.
#include "relax_dynamics_surface.h"
#include "sphinxsys.h" // SPHinXsys Library.
#include "surface_shape.h"


using namespace SPH;
//----------------------------------------------------------------------
// Set the file path to the data file.
Expand Down Expand Up @@ -66,12 +65,12 @@ class CylinderParticleGenerator : public SurfaceParticleGenerator
Standard_Real v2 = DELTA2;

std::vector<Vecd> points;
for (size_t k = 0; k <= 1 / DELTA1; k++)
for (size_t k = 0; k <= 1 / DELTA1; k++)
{
Standard_Real u = u1 + k * DELTA1;
points.push_back(a->getCartesianPoint(u, 0));
}
for (size_t k = 0; k <= 1 / DELTA1-1; k++)
for (size_t k = 0; k <= 1 / DELTA1 - 1; k++)
{
Standard_Real v = v1 + k * DELTA1;
points.push_back(a->getCartesianPoint(0, v));
Expand All @@ -93,12 +92,12 @@ class CylinderParticleGenerator : public SurfaceParticleGenerator
{
v1 = 0.5;
u1 = 0.5;
double VDELTA = 0.005;
double UDELTA = 0.005;
Standard_Real v = v1 + k * VDELTA;
double V_DELTA = 0.005;
double U_DELTA = 0.005;
Standard_Real v = v1 + k * V_DELTA;
for (size_t n = 0; n <= 20; n++)
{
Standard_Real u = u1 + n * UDELTA;
Standard_Real u = u1 + n * U_DELTA;
points.push_back(a->getCartesianPoint(u, v));
}
}
Expand All @@ -121,19 +120,20 @@ int main(int ac, char *av[])
//----------------------------------------------------------------------
// Build up a SPHSystem.
//----------------------------------------------------------------------
SPHSystem system(system_domain_bounds, particle_spacing_ref);
IOEnvironment io_environment(system);
SPHSystem sph_system(system_domain_bounds, particle_spacing_ref);
sph_system.handleCommandlineOptions(ac, av); // handle command line arguments
IOEnvironment io_environment(sph_system);
//----------------------------------------------------------------------
// Creating body, materials and particles.
//----------------------------------------------------------------------
SolidBody leaflet(system, makeShared<SurfaceShapeSTEP>(full_path_to_geometry, "Leaflet"));
SolidBody leaflet(sph_system, makeShared<SurfaceShapeSTEP>(full_path_to_geometry, "Leaflet"));
// here dummy linear elastic solid is use because no solid dynamics in particle relaxation
leaflet.defineParticlesAndMaterial<ShellParticles, SaintVenantKirchhoffSolid>(1.0, 1.0, 0.0);
leaflet.generateParticles<CylinderParticleGenerator>();
//----------------------------------------------------------------------
// Define simple file input and outputs functions.
//----------------------------------------------------------------------
BodyStatesRecordingToVtp write_relaxed_particles(io_environment, system.real_bodies_);
BodyStatesRecordingToVtp write_relaxed_particles(io_environment, sph_system.real_bodies_);
MeshRecordingToPlt write_mesh_cell_linked_list(io_environment, leaflet.getCellLinkedList());
//----------------------------------------------------------------------
// Define body relation map.
Expand All @@ -149,7 +149,7 @@ int main(int ac, char *av[])
relax_dynamics::RelaxationStepInnerSecondHalf leaflet_relaxation_second_half(leaflet_inner);
/** Constrain the boundary. */
BoundaryGeometry boundary_geometry(leaflet, "BoundaryGeometry");
SimpleDynamics<relax_dynamics::ConstrainSurfaceBodyRegion> constrain_holder(boundary_geometry);
SimpleDynamics<relax_dynamics::ConstrainSurfaceBodyRegion> constrain_holder(boundary_geometry);
SimpleDynamics<relax_dynamics::SurfaceNormalDirection> surface_normal_direction(leaflet);
//----------------------------------------------------------------------
// Particle relaxation starts here.
Expand Down
4 changes: 3 additions & 1 deletion src/shared/io_system/io_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class BodyStatesRecording : public BaseIO
{
public:
BodyStatesRecording(IOEnvironment &io_environment, SPHBodyVector bodies)
: BaseIO(io_environment), bodies_(bodies){};
: BaseIO(io_environment), bodies_(bodies),
state_recording_(io_environment.sph_system_.StateRecording()){};
BodyStatesRecording(IOEnvironment &io_environment, SPHBody &body)
: BodyStatesRecording(io_environment, {&body}){};
virtual ~BodyStatesRecording(){};
Expand All @@ -110,6 +111,7 @@ class BodyStatesRecording : public BaseIO

protected:
SPHBodyVector bodies_;
bool state_recording_;

virtual void writeWithFileName(const std::string &sequence) = 0;
};
Expand Down
20 changes: 13 additions & 7 deletions src/shared/io_system/io_plt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ void BodyStatesRecordingToPlt::writeWithFileName(const std::string &sequence)
{
if (body->checkNewlyUpdated())
{
std::string filefullpath = io_environment_.output_folder_ +
"/SPHBody_" + body->getName() + "_" + sequence + ".plt";
if (fs::exists(filefullpath))
BaseParticles &base_particles = body->getBaseParticles();
base_particles.computeDrivedVariables();

if (state_recording_)
{
fs::remove(filefullpath);
std::string filefullpath = io_environment_.output_folder_ +
"/SPHBody_" + body->getName() + "_" + sequence + ".plt";
if (fs::exists(filefullpath))
{
fs::remove(filefullpath);
}
std::ofstream out_file(filefullpath.c_str(), std::ios::trunc);
body->writeParticlesToPltFile(out_file);
out_file.close();
}
std::ofstream out_file(filefullpath.c_str(), std::ios::trunc);
body->writeParticlesToPltFile(out_file);
out_file.close();
}
body->setNotNewlyUpdated();
}
Expand Down
137 changes: 74 additions & 63 deletions src/shared/io_system/io_vtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,72 @@ void BodyStatesRecordingToVtp::writeWithFileName(const std::string &sequence)
{
if (body->checkNewlyUpdated())
{
std::string filefullpath = io_environment_.output_folder_ + "/" + body->getName() + "_" + sequence + ".vtp";
if (fs::exists(filefullpath))
{
fs::remove(filefullpath);
}
std::ofstream out_file(filefullpath.c_str(), std::ios::trunc);
// begin of the XML file
out_file << "<?xml version=\"1.0\"?>\n";
out_file << "<VTKFile type=\"PolyData\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
out_file << " <PolyData>\n";

BaseParticles &base_particles = body->getBaseParticles();
size_t total_real_particles = base_particles.total_real_particles_;
out_file << " <Piece Name =\"" << body->getName() << "\" NumberOfPoints=\"" << total_real_particles
<< "\" NumberOfVerts=\"" << total_real_particles << "\">\n";

// write current/final particle positions first
out_file << " <Points>\n";
out_file << " <DataArray Name=\"Position\" type=\"Float32\" NumberOfComponents=\"3\" Format=\"ascii\">\n";
out_file << " ";
for (size_t i = 0; i != total_real_particles; ++i)
base_particles.computeDrivedVariables();

if (state_recording_)
{
Vec3d particle_position = upgradeToVec3d(base_particles.pos_[i]);
out_file << particle_position[0] << " " << particle_position[1] << " " << particle_position[2] << " ";
std::string filefullpath = io_environment_.output_folder_ + "/" + body->getName() + "_" + sequence + ".vtp";
if (fs::exists(filefullpath))
{
fs::remove(filefullpath);
}
std::ofstream out_file(filefullpath.c_str(), std::ios::trunc);
// begin of the XML file
out_file << "<?xml version=\"1.0\"?>\n";
out_file << "<VTKFile type=\"PolyData\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
out_file << " <PolyData>\n";

size_t total_real_particles = base_particles.total_real_particles_;
out_file << " <Piece Name =\"" << body->getName() << "\" NumberOfPoints=\"" << total_real_particles
<< "\" NumberOfVerts=\"" << total_real_particles << "\">\n";

// write current/final particle positions first
out_file << " <Points>\n";
out_file << " <DataArray Name=\"Position\" type=\"Float32\" NumberOfComponents=\"3\" Format=\"ascii\">\n";
out_file << " ";
for (size_t i = 0; i != total_real_particles; ++i)
{
Vec3d particle_position = upgradeToVec3d(base_particles.pos_[i]);
out_file << particle_position[0] << " " << particle_position[1] << " " << particle_position[2] << " ";
}
out_file << std::endl;
out_file << " </DataArray>\n";
out_file << " </Points>\n";

// write header of particles data
out_file << " <PointData Vectors=\"vector\">\n";
body->writeParticlesToVtpFile(out_file);

out_file << " </PointData>\n";

// write empty cells
out_file << " <Verts>\n";
out_file << " <DataArray type=\"Int32\" Name=\"connectivity\" Format=\"ascii\">\n";
out_file << " ";
for (size_t i = 0; i != total_real_particles; ++i)
{
out_file << i << " ";
}
out_file << std::endl;
out_file << " </DataArray>\n";
out_file << " <DataArray type=\"Int32\" Name=\"offsets\" Format=\"ascii\">\n";
out_file << " ";
for (size_t i = 0; i != total_real_particles; ++i)
{
out_file << i + 1 << " ";
}
out_file << std::endl;
out_file << " </DataArray>\n";
out_file << " </Verts>\n";

out_file << " </Piece>\n";

out_file << " </PolyData>\n";
out_file << "</VTKFile>\n";

out_file.close();
}
out_file << std::endl;
out_file << " </DataArray>\n";
out_file << " </Points>\n";

// write header of particles data
out_file << " <PointData Vectors=\"vector\">\n";
body->writeParticlesToVtpFile(out_file);

out_file << " </PointData>\n";

// write empty cells
out_file << " <Verts>\n";
out_file << " <DataArray type=\"Int32\" Name=\"connectivity\" Format=\"ascii\">\n";
out_file << " ";
for (size_t i = 0; i != total_real_particles; ++i)
{
out_file << i << " ";
}
out_file << std::endl;
out_file << " </DataArray>\n";
out_file << " <DataArray type=\"Int32\" Name=\"offsets\" Format=\"ascii\">\n";
out_file << " ";
for (size_t i = 0; i != total_real_particles; ++i)
{
out_file << i + 1 << " ";
}
out_file << std::endl;
out_file << " </DataArray>\n";
out_file << " </Verts>\n";

out_file << " </Piece>\n";

out_file << " </PolyData>\n";
out_file << "</VTKFile>\n";

out_file.close();
}
body->setNotNewlyUpdated();
}
Expand All @@ -86,11 +91,17 @@ void BodyStatesRecordingToVtpString::writeWithFileName(const std::string &sequen
{
if (body->checkNewlyUpdated())
{
const auto &vtuName = body->getName() + "_" + sequence + ".vtu";
std::stringstream sstream;
// begin of the XML file
writeVtu(sstream, body);
_vtuData[vtuName] = sstream.str();
BaseParticles &base_particles = body->getBaseParticles();
base_particles.computeDrivedVariables();

if (state_recording_)
{
const auto &vtuName = body->getName() + "_" + sequence + ".vtu";
std::stringstream sstream;
// begin of the XML file
writeVtu(sstream, body);
_vtuData[vtuName] = sstream.str();
}
}
body->setNotNewlyUpdated();
}
Expand Down
14 changes: 8 additions & 6 deletions src/shared/particles/base_particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ void BaseParticles::writePltFileHeader(std::ofstream &output_file)
};
}
//=================================================================================================//
void BaseParticles::computeDrivedVariables()
{
for (auto &derived_variable : derived_variables_)
{
derived_variable->exec();
}
}
//=================================================================================================//
void BaseParticles::writePltFileParticleData(std::ofstream &output_file, size_t index)
{
// write particle positions and index first
Expand Down Expand Up @@ -187,12 +195,6 @@ void BaseParticles::writeParticlesToPltFile(std::ofstream &output_file)
writePltFileHeader(output_file);
output_file << "\n";

// compute derived particle variables
for (auto &derived_variable : derived_variables_)
{
derived_variable->exec();
}

size_t total_real_particles = total_real_particles_;
for (size_t i = 0; i != total_real_particles; ++i)
{
Expand Down
1 change: 1 addition & 0 deletions src/shared/particles/base_particles.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class BaseParticles

template <class DerivedVariableMethod, class... Ts>
void addDerivedVariableToWrite(Ts &&...);
void computeDrivedVariables();
//----------------------------------------------------------------------
// Particle data for sorting
//----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 1a06b77

Please sign in to comment.