From ca11a544476b32c68b654f0955a24ab713659a43 Mon Sep 17 00:00:00 2001 From: xiaojing-ubantu Date: Mon, 7 Aug 2023 17:14:57 +0200 Subject: [PATCH 1/3] Nonlinear hardening material and stretching case implemention --- .../shared/inelastic_solid_hardening.h | 112 ++++++ .../xj_stretching/CMakeLists.txt | 17 + .../xj_stretching/xj_stretching.cpp | 373 ++++++++++++++++++ 3 files changed, 502 insertions(+) create mode 100644 tests/user_examples/extra_src/shared/inelastic_solid_hardening.h create mode 100644 tests/user_examples/xj_stretching/CMakeLists.txt create mode 100644 tests/user_examples/xj_stretching/xj_stretching.cpp diff --git a/tests/user_examples/extra_src/shared/inelastic_solid_hardening.h b/tests/user_examples/extra_src/shared/inelastic_solid_hardening.h new file mode 100644 index 0000000000..c5aa4cd55e --- /dev/null +++ b/tests/user_examples/extra_src/shared/inelastic_solid_hardening.h @@ -0,0 +1,112 @@ +/* ------------------------------------------------------------------------- * + * 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-2023 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 inelastic_solid_hardening.h + * @brief These are classes for define properties of elastic solid materials. + * These classes are based on isotropic linear elastic solid. + * Several more complex materials, including neo-hookean, FENE noe-hookean + * and anisotropic muscle, are derived from the basic elastic solid class. + * @author Xiangyu Hu and Chi Zhang + */ +#pragma once + +#include "inelastic_solid.h" + +namespace SPH +{ + +/** + * @class NonlinearHardeningPlasticSolid + * @brief Class for plastic solid with nonlinear hardening + */ +class NonLinearHardeningPlasticSolid : public HardeningPlasticSolid +{ +protected: + Real saturation_flow_stress_, saturation_exponent_; +public: + /** Constructor */ + explicit NonLinearHardeningPlasticSolid(Real rho0, Real youngs_modulus, Real poisson_ratio, Real yield_stress, + Real hardening_modulus, Real saturation_flow_stress, Real saturation_exponent) + : HardeningPlasticSolid(rho0, youngs_modulus, poisson_ratio, yield_stress, hardening_modulus), + saturation_flow_stress_(saturation_flow_stress), saturation_exponent_(saturation_exponent) + { + material_type_name_ = "NonLinearHardeningPlasticSolid"; + + }; + virtual ~NonLinearHardeningPlasticSolid() {}; + + Real NonlinearHardening(Real hardening_parameter_pre) + { + return (hardening_modulus_ * hardening_parameter_pre + yield_stress_ + + (saturation_flow_stress_ - yield_stress_)* (1 - exp(-saturation_exponent_ * hardening_parameter_pre))); + }; + + Real NonlinearHardeningDerivative(Real hardening_parameter_pre) + { + return (hardening_modulus_+ saturation_exponent_ * (saturation_flow_stress_ - yield_stress_) + * exp(-saturation_exponent_ * hardening_parameter_pre)); + }; + + /** compute the stress through defoemation, and plastic relaxation. */ + virtual Matd PlasticConstitutiveRelation(const Matd &F, size_t index_i, Real dt = 0.0) + { + + Matd normalized_F = F * pow(F.determinant(), -OneOverDimensions); + Matd normalized_be = normalized_F * inverse_plastic_strain_[index_i] * normalized_F.transpose(); + Real normalized_be_isentropic = normalized_be.trace() * OneOverDimensions; + Matd deviatoric_PK = DeviatoricKirchhoff(normalized_be - normalized_be_isentropic * Matd::Identity()); + Real deviatoric_PK_norm = deviatoric_PK.norm(); + + Real relax_increment = 0.0; + Real trial_function = deviatoric_PK_norm - sqrt_2_over_3_ * NonlinearHardening(hardening_parameter_[index_i]); + if (trial_function > 0.0) + { + Real renormalized_shear_modulus = normalized_be_isentropic * G0_; + while (trial_function > 0.0) + { + Real function_relax_increment_derivative = -2.0 * renormalized_shear_modulus + * (1.0 + NonlinearHardeningDerivative(hardening_parameter_[index_i] + sqrt_2_over_3_ * relax_increment) / 3.0 / renormalized_shear_modulus); + relax_increment -= trial_function / function_relax_increment_derivative; + + trial_function = deviatoric_PK_norm + - sqrt_2_over_3_ * NonlinearHardening(hardening_parameter_[index_i] + sqrt_2_over_3_ * relax_increment) + - 2.0 * renormalized_shear_modulus * relax_increment; + } + hardening_parameter_[index_i] += sqrt_2_over_3_ * relax_increment; + deviatoric_PK -= 2.0 * renormalized_shear_modulus * relax_increment * deviatoric_PK / deviatoric_PK_norm; + normalized_be = deviatoric_PK / G0_ + normalized_be_isentropic * Matd::Identity(); + + } + + Matd inverse_normalized_F = normalized_F.inverse(); + Matd inverse_normalized_F_T = inverse_normalized_F.transpose();; + inverse_plastic_strain_[index_i] = inverse_normalized_F * normalized_be * inverse_normalized_F_T; + + return (deviatoric_PK + VolumetricKirchhoff(F.determinant()) * Matd::Identity()) * inverse_normalized_F_T; + + }; + + virtual NonLinearHardeningPlasticSolid *ThisObjectPtr() override { return this; }; +}; + +} // namespace SPH diff --git a/tests/user_examples/xj_stretching/CMakeLists.txt b/tests/user_examples/xj_stretching/CMakeLists.txt new file mode 100644 index 0000000000..f9bb76775e --- /dev/null +++ b/tests/user_examples/xj_stretching/CMakeLists.txt @@ -0,0 +1,17 @@ +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") + +add_executable(${PROJECT_NAME}) +aux_source_directory(. DIR_SRCS) +target_sources(${PROJECT_NAME} PRIVATE ${DIR_SRCS}) +target_link_libraries(${PROJECT_NAME} extra_sources_2d) +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}) diff --git a/tests/user_examples/xj_stretching/xj_stretching.cpp b/tests/user_examples/xj_stretching/xj_stretching.cpp new file mode 100644 index 0000000000..39a32b40fc --- /dev/null +++ b/tests/user_examples/xj_stretching/xj_stretching.cpp @@ -0,0 +1,373 @@ +/* ---------------------------------------------------------------------------* +* SPHinXsys: 2D oscillation beam example-one body version * +* ----------------------------------------------------------------------------* +* This is the one of the basic test cases, also the first case for * +* understanding SPH method for solid simulation. * +* In this case, the constraint of the beam is implemented with * +* internal constrained subregion. * +* ----------------------------------------------------------------------------*/ +#include "sphinxsys.h" +#include "inelastic_solid_hardening.h" + +using namespace SPH; +//------------------------------------------------------------------------------ +//global parameters for the case +//------------------------------------------------------------------------------ +Real PL = 0.05334; //beam length +Real PH = 0.012826; //for thick plate; + +//reference particle spacing +Real resolution_ref = PH / 30; +Real BW = resolution_ref * 4.0 ; //boundary width, at least three particles + +/** Domain bounds of the system. */ +BoundingBox system_domain_bounds(Vec2d(-PL / 2.0, -PL / 2.0), + Vec2d(2.0*PL , PL / 2.0)); +// two dimensional should be circle smooth between two parts. +//---------------------------------------------------------------------- +Real rho0_s = 7850.0; /**< Reference density. */ +Real Shear_modulus = 80.1938e9; /**< Poisson ratio. */ +Real Bulk_modulus = 164.21e9; + +Real poisson = (3.0 * Bulk_modulus -2.0 * Shear_modulus)/(6.0 * Bulk_modulus + 2.0 * Shear_modulus); /**< Poisson ratio. */ +Real Youngs_modulus = (9.0 * Shear_modulus * Bulk_modulus)/(3.0* Bulk_modulus + Shear_modulus); + + +Real yield_stress = 0.45e9; +Real hardening_modulus = 1.2924e8; +Real saturation_flow_stress = 7.15e8; +Real saturation_exponent = 16.93; + +Real physical_viscosity = 1.0e4; +Real refer_energy = 0.5*8000*0.01; //40 + +Vecd norm_(1.0, 0.0); +Vecd upper_face_point_(0.02 + 3.0 * resolution_ref, 0.0); +Vecd lower_face_point_(0.02, 0.0); + + +Vecd norm_4(1.0, 0.0); +Vecd upper_face_point_4(0.04 + 3.0 * resolution_ref, 0.0); +Vecd lower_face_point_4(0.04, 0.0); + +//Beam observer location +StdVec observation_location = { Vecd( PL / 2.0 , PH / 2.0 - PH * 0.01) }; + +//---------------------------------------------------------------------- +// Geometric shapes used in the system. +//---------------------------------------------------------------------- + +std::vector beam_left_stretch_shape{ + Vecd(-BW , -PH / 2 ), Vecd(-BW, PH / 2 ), Vecd(0.0, PH / 2 ), + Vecd(0.0, -PH / 2 ), Vecd(-BW, -PH / 2 )}; + +//a beam shape +std::vector beam_shape{ + Vecd(0.0, -PH / 2), Vecd(0.0, PH / 2), + Vecd(PL / 2.0 , PH / 2 - PH * 0.01), + Vecd(PL, PH / 2), Vecd(PL , -PH / 2), + Vecd(PL / 2.0 , -PH / 2 + PH * 0.01), + Vecd(0.0, -PH / 2) }; + +std::vector beam_right_stretch_shape{ + Vecd(PL, -PH / 2 ), Vecd(PL, PH / 2 ), Vecd(PL +BW , PH / 2 ), + Vecd(PL+BW, -PH / 2 ), Vecd(PL, -PH / 2 ) }; + +//---------------------------------------------------------------------- +// Define the beam body +//---------------------------------------------------------------------- +class Beam : public MultiPolygonShape +{ +public: + explicit Beam(const std::string &shape_name) : MultiPolygonShape(shape_name) + { + multi_polygon_.addAPolygon(beam_right_stretch_shape, ShapeBooleanOps::add); + multi_polygon_.addAPolygon(beam_shape, ShapeBooleanOps::add); + multi_polygon_.addAPolygon(beam_left_stretch_shape, ShapeBooleanOps::add); + + } +}; + +class LeftStretchSolidBodyRegion : public solid_dynamics::BaseMotionConstraint +{ +public: + // TODO: use only body part as argment since body can be referred from it already + LeftStretchSolidBodyRegion(BodyPartByParticle &body_part) + :solid_dynamics::BaseMotionConstraint(body_part), + vel_(particles_->vel_), pos_(particles_->pos_){}; + + virtual ~LeftStretchSolidBodyRegion() {}; +protected: + StdLargeVec &vel_; + StdLargeVec &pos_; + virtual void update(size_t index_i, Real Dt = 0.0) + { + pos_[index_i][0] -= 0.5e-4 * Dt; + }; +}; + +class RightStretchSolidBodyRegion : public solid_dynamics::BaseMotionConstraint +{ +public: + // TODO: use only body part as argment since body can be referred from it already + RightStretchSolidBodyRegion(BodyPartByParticle &body_part) + :solid_dynamics::BaseMotionConstraint(body_part), + vel_(particles_->vel_), pos_(particles_->pos_){}; + + virtual ~RightStretchSolidBodyRegion() {}; + +protected: + StdLargeVec &vel_; + StdLargeVec &pos_; + virtual void update(size_t index_i, Real Dt = 0.0) + { + pos_[index_i][0] += 0.5e-4 * Dt; + }; +}; + +MultiPolygon createBeamRightStretchShape() +{ + MultiPolygon multi_polygon; + multi_polygon.addAPolygon(beam_right_stretch_shape, ShapeBooleanOps::add); + return multi_polygon; +}; + +MultiPolygon createBeamLeftStretchShape() +{ + MultiPolygon multi_polygon; + multi_polygon.addAPolygon(beam_left_stretch_shape, ShapeBooleanOps::add); + return multi_polygon; +}; + + +MultiPolygon createConstrainBeamShape() +{ + MultiPolygon multi_polygon; + multi_polygon.addAPolygon(beam_left_stretch_shape, ShapeBooleanOps::add); + multi_polygon.addAPolygon(beam_right_stretch_shape, ShapeBooleanOps::add); + + return multi_polygon; +}; + +class ConstrainXVelocity : public solid_dynamics::BaseMotionConstraint +{ +public: + // TODO: use only body part as argment since body can be referred from it already + ConstrainXVelocity(BodyPartByParticle &body_part) + :solid_dynamics::BaseMotionConstraint(body_part), + vel_(particles_->vel_), pos_(particles_->pos_){}; + + virtual ~ConstrainXVelocity() {}; +protected: + StdLargeVec &vel_; + StdLargeVec &pos_; + virtual void update(size_t index_i, Real dt = 0.0) + { + vel_[index_i] = Vecd(0.0, vel_[index_i][1]); + }; +}; + +//------------------------------------------------------------------------------ +//the main program +//------------------------------------------------------------------------------ +int main(int ac, char *av[]) +{ + //---------------------------------------------------------------------- + // Build up the environment of a SPHSystem with global controls. + //---------------------------------------------------------------------- + SPHSystem system(system_domain_bounds, resolution_ref); + /** Tag for running particle relaxation for the initially body-fitted distribution */ + system.setRunParticleRelaxation(false); + /** Tag for starting with relaxed body-fitted particles distribution */ + system.setReloadParticles(true); + system.handleCommandlineOptions(ac, av); + IOEnvironment io_environment(system); + + //---------------------------------------------------------------------- + // Creating body, materials and particles. + //---------------------------------------------------------------------- + SolidBody beam_body(system, makeShared("StretchingBody")); + beam_body.defineBodyLevelSetShape(); + beam_body.defineParticlesAndMaterial( + rho0_s, Youngs_modulus, poisson, yield_stress, hardening_modulus, saturation_flow_stress, saturation_exponent); + + (!system.RunParticleRelaxation() && system.ReloadParticles()) + ? beam_body.generateParticles(io_environment, beam_body.getName()) + : beam_body.generateParticles(); + + + ObserverBody beam_observer(system, "BeamObserver"); + beam_observer.generateParticles(observation_location); + //---------------------------------------------------------------------- + // 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. + //---------------------------------------------------------------------- + if (system.RunParticleRelaxation()) + { + //---------------------------------------------------------------------- + // Define body relation map used for particle relaxation. + //---------------------------------------------------------------------- + InnerRelation beam_body_inner(beam_body); + //---------------------------------------------------------------------- + // Define the methods for particle relaxation. + //---------------------------------------------------------------------- + SimpleDynamics beam_body_random_particles(beam_body); + relax_dynamics::RelaxationStepInner beam_body_relaxation_step_inner(beam_body_inner); + //---------------------------------------------------------------------- + // Output for particle relaxation. + //---------------------------------------------------------------------- + BodyStatesRecordingToVtp write_ball_state(io_environment, system.real_bodies_); + ReloadParticleIO write_particle_reload_files(io_environment, { &beam_body }); + //---------------------------------------------------------------------- + // Particle relaxation starts here. + //---------------------------------------------------------------------- + beam_body_random_particles.exec(0.25); + write_ball_state.writeToFile(0); + //---------------------------------------------------------------------- + // From here iteration for particle relaxation begins. + //---------------------------------------------------------------------- + int ite = 0; + int relax_step = 1000; + while (ite < relax_step) + { + beam_body_relaxation_step_inner.exec(); + ite += 1; + if (ite % 100 == 0) + { + std::cout << std::fixed << std::setprecision(9) << "Relaxation steps N = " << ite << "\n"; + write_ball_state.writeToFile(ite); + } + } + std::cout << "The physics relaxation process of particles finish !" << std::endl; + write_particle_reload_files.writeToFile(0); + return 0; + } + + InnerRelation beam_body_inner(beam_body); + ContactRelation beam_observer_contact(beam_observer, {&beam_body}); + //----------------------------------------------------------------------------- + //this section define all numerical methods will be used in this case + //----------------------------------------------------------------------------- + + //corrected strong configuration + InteractionWithUpdate beam_corrected_configuration(beam_body_inner); + + //time step size calculation + ReduceDynamics computing_time_step_size(beam_body); + //stress relaxation for the beam + Dynamics1Level stress_relaxation_first_half(beam_body_inner); + Dynamics1Level stress_relaxation_second_half(beam_body_inner); + ReduceDynamics get_kinetic_energy(beam_body); + + BodyRegionByParticle beam_left_stretch(beam_body, makeShared(createBeamLeftStretchShape())); + SimpleDynamics stretch_beam_left_end(beam_left_stretch); + BodyRegionByParticle beam_right_stretch(beam_body, makeShared(createBeamRightStretchShape())); + SimpleDynamics stretch_beam_right_end(beam_right_stretch); + BodyRegionByParticle beam_constrain(beam_body, makeShared(createConstrainBeamShape())); + SimpleDynamics constrain_beam_end(beam_constrain); + + InteractionDynamics beam_deformation_gradient_tensor(beam_body_inner); + DampingWithRandomChoice>> + damping(0.5, beam_body_inner, "Velocity", physical_viscosity); + + //----------------------------------------------------------------------------- + //outputs + //----------------------------------------------------------------------------- + + BodyStatesRecordingToVtp write_beam_states(io_environment, system.real_bodies_); + ReducedQuantityRecording> + write_total_mechanical_energy(io_environment, beam_body); + //---------------------------------------------------------------------- + // Setup computing and initial conditions. + //---------------------------------------------------------------------- + system.initializeSystemCellLinkedLists(); + system.initializeSystemConfigurations(); + beam_corrected_configuration.exec(); + + //---------------------------------------------------------------------- + // Setup computing time-step controls. + //---------------------------------------------------------------------- + int ite = 0; + int Dt_ite = 0; + Real End_Time = 100.0; + + Real D_Time = End_Time /100.0;//time step size for output file + Real Dt = End_Time /10000.0; /**< Time period for stretching */ + Real dt = 0.0; //default acoustic time step sizes + + // statistics for computing time + TickCount t1 = TickCount::now(); + TimeInterval interval; + //----------------------------------------------------------------------------- + //from here the time stepping begines + //----------------------------------------------------------------------------- + write_beam_states.writeToFile(0); + write_total_mechanical_energy.writeToFile(0); + + //computation loop starts + while (GlobalStaticVariables::physical_time_ < End_Time) + { + Real integration_time = 0.0; + //integrate time (loop) until the next output time + while (integration_time < D_Time) + { + Real relaxation_time = 0.0; + stretch_beam_left_end.exec(Dt); + stretch_beam_right_end.exec(Dt); + beam_deformation_gradient_tensor.exec(Dt); + Dt_ite ++; + + int stress_ite = 0; + Real refer_total_kinetic_energy = 10000.0; + while (relaxation_time < Dt) + { + if (refer_total_kinetic_energy > 0.005) + { + stress_relaxation_first_half.exec(dt); + constrain_beam_end.exec(dt); + damping.exec(Dt); + constrain_beam_end.exec(dt); + stress_relaxation_second_half.exec(dt); + + refer_total_kinetic_energy = get_kinetic_energy.exec() / refer_energy; + + ite++; + stress_ite++; + + dt = computing_time_step_size.exec(); + if (ite % 500 == 0) + { + std::cout << "N=" << ite << " Time: " + << GlobalStaticVariables::physical_time_ + << " Dt: " << Dt << " dt: " << dt + << " Dt:dt = " << Dt / dt << + "\n"; + } + } + relaxation_time += dt; + integration_time += dt; + GlobalStaticVariables::physical_time_ += dt; + } + + + std::cout << "refer_total_kinetic_energy " << refer_total_kinetic_energy + << " stress_ite " << stress_ite < Date: Tue, 29 Aug 2023 11:45:14 +0200 Subject: [PATCH 2/3] change to hpp --- ...lastic_solid_hardening.h => inelastic_solid_hardening.hpp} | 2 +- tests/user_examples/xj_stretching/xj_stretching.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename tests/user_examples/extra_src/shared/{inelastic_solid_hardening.h => inelastic_solid_hardening.hpp} (99%) diff --git a/tests/user_examples/extra_src/shared/inelastic_solid_hardening.h b/tests/user_examples/extra_src/shared/inelastic_solid_hardening.hpp similarity index 99% rename from tests/user_examples/extra_src/shared/inelastic_solid_hardening.h rename to tests/user_examples/extra_src/shared/inelastic_solid_hardening.hpp index c5aa4cd55e..c5eb49a874 100644 --- a/tests/user_examples/extra_src/shared/inelastic_solid_hardening.h +++ b/tests/user_examples/extra_src/shared/inelastic_solid_hardening.hpp @@ -21,7 +21,7 @@ * * * ------------------------------------------------------------------------- */ /** - * @file inelastic_solid_hardening.h + * @file inelastic_solid_hardening.hpp * @brief These are classes for define properties of elastic solid materials. * These classes are based on isotropic linear elastic solid. * Several more complex materials, including neo-hookean, FENE noe-hookean diff --git a/tests/user_examples/xj_stretching/xj_stretching.cpp b/tests/user_examples/xj_stretching/xj_stretching.cpp index 39a32b40fc..e5f2595056 100644 --- a/tests/user_examples/xj_stretching/xj_stretching.cpp +++ b/tests/user_examples/xj_stretching/xj_stretching.cpp @@ -7,7 +7,7 @@ * internal constrained subregion. * * ----------------------------------------------------------------------------*/ #include "sphinxsys.h" -#include "inelastic_solid_hardening.h" +#include "inelastic_solid_hardening.hpp" using namespace SPH; //------------------------------------------------------------------------------ @@ -370,4 +370,4 @@ int main(int ac, char *av[]) std::cout << "Total iterations computation: " << GlobalStaticVariables::physical_time_/dt << std::endl; return 0; -} \ No newline at end of file +} From 43f8214fbb6e627d9a11c35ddb942b4971e0a060 Mon Sep 17 00:00:00 2001 From: Tang-U-b Date: Tue, 29 Aug 2023 22:33:22 +0200 Subject: [PATCH 3/3] modify cmake --- ...dening.hpp => inelastic_solid_hardening.h} | 2 +- .../xj_stretching/CMakeLists.txt | 32 +++++++++++++++---- tests/user_examples/xj_stretching/run_test.sh | 2 ++ .../xj_stretching/xj_stretching.cpp | 2 +- 4 files changed, 29 insertions(+), 9 deletions(-) rename tests/user_examples/extra_src/shared/{inelastic_solid_hardening.hpp => inelastic_solid_hardening.h} (99%) create mode 100644 tests/user_examples/xj_stretching/run_test.sh diff --git a/tests/user_examples/extra_src/shared/inelastic_solid_hardening.hpp b/tests/user_examples/extra_src/shared/inelastic_solid_hardening.h similarity index 99% rename from tests/user_examples/extra_src/shared/inelastic_solid_hardening.hpp rename to tests/user_examples/extra_src/shared/inelastic_solid_hardening.h index c5eb49a874..e0c2cda74b 100644 --- a/tests/user_examples/extra_src/shared/inelastic_solid_hardening.hpp +++ b/tests/user_examples/extra_src/shared/inelastic_solid_hardening.h @@ -21,7 +21,7 @@ * * * ------------------------------------------------------------------------- */ /** - * @file inelastic_solid_hardening.hpp + * @file inelastic_solid_hardening.h * @brief These are classes for define properties of elastic solid materials. * These classes are based on isotropic linear elastic solid. * Several more complex materials, including neo-hookean, FENE noe-hookean diff --git a/tests/user_examples/xj_stretching/CMakeLists.txt b/tests/user_examples/xj_stretching/CMakeLists.txt index f9bb76775e..7434f894db 100644 --- a/tests/user_examples/xj_stretching/CMakeLists.txt +++ b/tests/user_examples/xj_stretching/CMakeLists.txt @@ -1,17 +1,35 @@ -STRING(REGEX REPLACE ".*/(.*)" "\\1" CURRENT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${SPHINXSYS_PROJECT_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(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) SET(BUILD_INPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/input") SET(BUILD_RELOAD_PATH "${EXECUTABLE_OUTPUT_PATH}/reload") + + + -add_executable(${PROJECT_NAME}) aux_source_directory(. DIR_SRCS) -target_sources(${PROJECT_NAME} PRIVATE ${DIR_SRCS}) +ADD_EXECUTABLE(${PROJECT_NAME} ${DIR_SRCS}) + +target_link_libraries(${PROJECT_NAME} sphinxsys_2d GTest::gtest GTest::gtest_main) target_link_libraries(${PROJECT_NAME} extra_sources_2d) + 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}) + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + add_test(NAME ${PROJECT_NAME}_particle_relaxation COMMAND ${PROJECT_NAME} --r=true + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) + add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME} --r=false --i=true + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) +else() + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh + DESTINATION ${EXECUTABLE_OUTPUT_PATH}) + add_test(NAME ${PROJECT_NAME} COMMAND bash ${EXECUTABLE_OUTPUT_PATH}/run_test.sh + WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) +endif() diff --git a/tests/user_examples/xj_stretching/run_test.sh b/tests/user_examples/xj_stretching/run_test.sh new file mode 100644 index 0000000000..8aaa13ab55 --- /dev/null +++ b/tests/user_examples/xj_stretching/run_test.sh @@ -0,0 +1,2 @@ +./xj_stretching --r=true +./xj_stretching --r=false --i=true diff --git a/tests/user_examples/xj_stretching/xj_stretching.cpp b/tests/user_examples/xj_stretching/xj_stretching.cpp index e5f2595056..7233b7e595 100644 --- a/tests/user_examples/xj_stretching/xj_stretching.cpp +++ b/tests/user_examples/xj_stretching/xj_stretching.cpp @@ -7,7 +7,7 @@ * internal constrained subregion. * * ----------------------------------------------------------------------------*/ #include "sphinxsys.h" -#include "inelastic_solid_hardening.hpp" +#include "inelastic_solid_hardening.h" using namespace SPH; //------------------------------------------------------------------------------