From cd68d8be5a20afd720c21ce5340c3a1161a0f8ea Mon Sep 17 00:00:00 2001 From: Xiangyu Hu Date: Tue, 18 Jul 2023 21:19:07 +0200 Subject: [PATCH 1/4] naming --- .../2d_flow_stream_around_fish.cpp | 2 +- .../2d_flow_stream_around_fish.h | 4 ++-- .../composite_material.cpp | 2 +- .../composite_material.h | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.cpp b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.cpp index 03cd7ae672..9b87e57828 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.cpp +++ b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.cpp @@ -36,7 +36,7 @@ int main(int ac, char *av[]) SolidBody fish_body(system, makeShared("FishBody")); fish_body.defineAdaptationRatios(1.15, 2.0); fish_body.defineBodyLevelSetShape()->writeLevelSet(io_environment); - fish_body.defineParticlesAndMaterial(); + fish_body.defineParticlesAndMaterial(); // Using relaxed particle distribution if needed (!system.RunParticleRelaxation() && system.ReloadParticles()) ? fish_body.generateParticles(io_environment, fish_body.getName()) diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h index c60e993ba6..659a08b6ce 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h +++ b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h @@ -147,10 +147,10 @@ class TimeDependentAcceleration : public Gravity }; // Material ID -class SolidBodyMaterial : public CompositeMaterial +class FishBodyComposite : public CompositeSolid { public: - SolidBodyMaterial() : CompositeMaterial(rho0_s) + FishBodyComposite() : CompositeSolid(rho0_s) { add(rho0_s, Youngs_modulus1, poisson); add(rho0_s, Youngs_modulus2, poisson); diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp index 217bc9fdd9..cfb48cef0f 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp +++ b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp @@ -5,7 +5,7 @@ namespace SPH { //=================================================================================================// -void CompositeMaterial::initializeLocalParameters(BaseParticles *base_particles) +void CompositeSolid::initializeLocalParameters(BaseParticles *base_particles) { ElasticSolid::initializeLocalParameters(base_particles); base_particles->registerVariable(material_id_, "MaterialID"); diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h index 240654bae3..f5b0df9820 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h +++ b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h @@ -8,8 +8,8 @@ namespace SPH { -/**@class CompositeMaterial*/ -class CompositeMaterial : public ElasticSolid +/**@class CompositeSolid*/ +class CompositeSolid : public ElasticSolid { protected: UniquePtrsKeeper composite_ptrs_keeper_; @@ -18,11 +18,11 @@ class CompositeMaterial : public ElasticSolid public: StdLargeVec material_id_; - explicit CompositeMaterial(Real rho0) : ElasticSolid(rho0) + explicit CompositeSolid(Real rho0) : ElasticSolid(rho0) { - material_type_name_ = "CompositeMaterial"; + material_type_name_ = "CompositeSolid"; }; - virtual ~CompositeMaterial(){}; + virtual ~CompositeSolid(){}; virtual void initializeLocalParameters(BaseParticles *base_particles) override; From cde381276e52cc51ea42ae896d8168582ffda5fd Mon Sep 17 00:00:00 2001 From: Xiangyu Hu Date: Tue, 18 Jul 2023 23:25:56 +0200 Subject: [PATCH 2/4] to test locally --- src/shared/materials/elastic_solid.h | 4 ++ .../solid_dynamics/elastic_dynamics.cpp | 5 +- .../2d_flow_stream_around_fish.cpp | 3 +- .../2d_flow_stream_around_fish.h | 11 ++-- .../active_model.cpp | 60 +++++++++---------- .../active_model.h | 31 +++++----- .../composite_material.cpp | 5 -- .../composite_material.h | 17 ------ 8 files changed, 55 insertions(+), 81 deletions(-) diff --git a/src/shared/materials/elastic_solid.h b/src/shared/materials/elastic_solid.h index 892d9c8896..730d27605d 100644 --- a/src/shared/materials/elastic_solid.h +++ b/src/shared/materials/elastic_solid.h @@ -72,6 +72,10 @@ class ElasticSolid : public Solid /** 2nd Piola-Kirchhoff stress through deformation. */ virtual Matd StressPK2(Matd &deformation, size_t particle_index_i) = 0; + virtual Matd StressPK1(Matd &deformation, size_t particle_index_i) + { + return deformation * StressPK2(deformation, particle_index_i); + }; /** Cauchy stress through Eulerian Almansi strain tensor. */ virtual Matd StressCauchy(Matd &almansi_strain, Matd &F, size_t particle_index_i) = 0; /** Numerical damping stress using right Cauchy tensor. */ diff --git a/src/shared/particle_dynamics/solid_dynamics/elastic_dynamics.cpp b/src/shared/particle_dynamics/solid_dynamics/elastic_dynamics.cpp index 7186e0272f..763b1e4e59 100644 --- a/src/shared/particle_dynamics/solid_dynamics/elastic_dynamics.cpp +++ b/src/shared/particle_dynamics/solid_dynamics/elastic_dynamics.cpp @@ -70,8 +70,7 @@ Integration1stHalf:: numerical_dissipation_factor_ = 0.25; } //=================================================================================================// -Integration1stHalfPK2:: - Integration1stHalfPK2(BaseInnerRelation &inner_relation) +Integration1stHalfPK2::Integration1stHalfPK2(BaseInnerRelation &inner_relation) : Integration1stHalf(inner_relation){}; //=================================================================================================// void Integration1stHalfPK2::initialization(size_t index_i, Real dt) @@ -81,7 +80,7 @@ void Integration1stHalfPK2::initialization(size_t index_i, Real dt) rho_[index_i] = rho0_ / F_[index_i].determinant(); // obtain the first Piola-Kirchhoff stress from the second Piola-Kirchhoff stress // it seems using reproducing correction here increases convergence rate near the free surface - stress_PK1_B_[index_i] = F_[index_i] * elastic_solid_.StressPK2(F_[index_i], index_i) * B_[index_i]; + stress_PK1_B_[index_i] = elastic_solid_.StressPK1(F_[index_i], index_i) * B_[index_i]; } //=================================================================================================// Integration1stHalfKirchhoff:: diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.cpp b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.cpp index 9b87e57828..d03dc95bbc 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.cpp +++ b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.cpp @@ -4,7 +4,6 @@ * @author Yaru Ren and Xiangyu Hu */ #include "2d_flow_stream_around_fish.h" -#include "active_model.h" #include "sphinxsys.h" using namespace SPH; @@ -151,7 +150,7 @@ int main(int ac, char *av[]) SimpleDynamics imposing_active_strain(fish_body); ReduceDynamics fish_body_computing_time_step_size(fish_body); /** Stress relaxation for the inserted body. */ - Dynamics1Level fish_body_stress_relaxation_first_half(fish_inner); + Dynamics1Level fish_body_stress_relaxation_first_half(fish_inner); Dynamics1Level fish_body_stress_relaxation_second_half(fish_inner); /** Update norm .*/ SimpleDynamics fish_body_update_normal(fish_body); diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h index 659a08b6ce..8107c7ad08 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h +++ b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h @@ -1,8 +1,9 @@ #include "2d_fish_and_bones.h" +#include "active_model.h" #include "composite_material.h" #include "sphinxsys.h" -#define PI 3.1415926 + using namespace SPH; //---------------------------------------------------------------------- // Basic geometry parameters and numerical setup. @@ -200,10 +201,8 @@ class ImposingActiveStrain explicit ImposingActiveStrain(SolidBody &solid_body) : solid_dynamics::ElasticDynamicsInitialCondition(solid_body), material_id_(*particles_->getVariableByName("MaterialID")), - pos0_(*particles_->getVariableByName("InitialPosition")) - { - particles_->registerVariable(active_strain_, "ActiveStrain"); - }; + pos0_(*particles_->getVariableByName("InitialPosition")), + active_strain_(*particles_->getVariableByName("ActiveStrain")){}; virtual void update(size_t index_i, Real dt = 0.0) { if (material_id_[index_i] == 0) @@ -230,5 +229,5 @@ class ImposingActiveStrain protected: StdLargeVec &material_id_; StdLargeVec &pos0_; - StdLargeVec active_strain_; + StdLargeVec &active_strain_; }; diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/active_model.cpp b/tests/user_examples/test_2d_flow_stream_around_fish/active_model.cpp index f1bbc19a9f..5886d6a405 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/active_model.cpp +++ b/tests/user_examples/test_2d_flow_stream_around_fish/active_model.cpp @@ -1,40 +1,36 @@ #include "active_model.h" -#include + +#include "base_particles.hpp" namespace SPH { - //=========================================================================================================// - namespace solid_dynamics - { - //=================================================================================================// - ActiveIntegration1stHalf:: - ActiveIntegration1stHalf(BaseInnerRelation &inner_relation) - : Integration1stHalfPK2(inner_relation), active_strain_(*particles_->getVariableByName("ActiveStrain")) - , material_id_(*particles_->getVariableByName("MaterialID")) - { - particles_->registerVariable(F_0, "ActiveTensor"); - particles_->registerVariable(E_e, "ElasticStrain"); - } - //=================================================================================================// - void ActiveIntegration1stHalf::initialization(size_t index_i, Real dt) - { - Integration1stHalfPK2::initialization(index_i,dt); - - // Calculate the active deformation gradient - F_0[index_i] = Matd::Identity(); - F_0[index_i] = (material_id_[index_i] == 0) ? ((2.0 * active_strain_[index_i] + Matd::Identity()).llt().matrixL()) : F_0[index_i]; - - // Calculate the elastic deformation - Matd F_e = F_[index_i] * F_0[index_i].inverse(); - Matd F_0_star = F_0[index_i].determinant() * (F_0[index_i].inverse()).transpose(); +//=================================================================================================// +ActiveModelSolid::ActiveModelSolid(Real rho0, Real youngs_modulus, Real poisson_ratio) + : SaintVenantKirchhoffSolid(rho0, youngs_modulus, poisson_ratio) +{ + material_type_name_ = "ActiveModelSolid"; +} +//=============================================================================================// +void ActiveModelSolid::initializeLocalParameters(BaseParticles *base_particles) +{ + SaintVenantKirchhoffSolid::initializeLocalParameters(base_particles); + base_particles->registerVariable(active_strain_, "ActiveStrain"); +} +//=================================================================================================// +Matd ActiveModelSolid::StressPK1(Matd &F, size_t index_i) +{ + // Calculate the active deformation gradient + Matd F0 = (2.0 * active_strain_[index_i] + Matd::Identity()).llt().matrixL(); + Matd F0_inv = F0.inverse(); - // Calculate the elastic strain - E_e[index_i] = (material_id_[index_i] == 0) ? (0.5 * (F_[index_i].transpose() * F_[index_i] - Matd::Identity()) - active_strain_[index_i]) : F_[index_i]; + // Calculate the elastic deformation + Matd F_e = F * F0_inv; + Matd F0_star = F0.determinant() * F0_inv.transpose(); - stress_PK1_B_[index_i] = F_e * elastic_solid_.StressPK2(E_e[index_i], index_i) * F_0_star * B_[index_i]; - } - //=================================================================================================// - } - //=================================================================================================// + // Calculate the elastic strain + Matd E_e = 0.5 * (F.transpose() * F - Matd::Identity()) - active_strain_[index_i]; + return F_e * (lambda0_ * E_e.trace() * Matd::Identity() + 2.0 * G0_ * E_e) * F0_star; } //=================================================================================================// +} // namespace SPH +//=================================================================================================// diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/active_model.h b/tests/user_examples/test_2d_flow_stream_around_fish/active_model.h index 3bcef409db..6534597c89 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/active_model.h +++ b/tests/user_examples/test_2d_flow_stream_around_fish/active_model.h @@ -6,22 +6,21 @@ namespace SPH { - namespace solid_dynamics - { - /** - * @class ActiveIntegration1stHalf - */ - class ActiveIntegration1stHalf : public Integration1stHalfPK2 - { - public: - explicit ActiveIntegration1stHalf(BaseInnerRelation &inner_relation); - virtual ~ActiveIntegration1stHalf(){}; - void initialization(size_t index_i, Real dt = 0.0); +/** + * @class ActiveModelSolid + */ +class ActiveModelSolid : public SaintVenantKirchhoffSolid +{ + StdLargeVec active_strain_; + + public: + explicit ActiveModelSolid(Real rho0, Real youngs_modulus, Real poisson_ratio); + virtual ~ActiveModelSolid(){}; - protected: - StdLargeVec &active_strain_,F_0, E_e; - StdLargeVec& material_id_; - }; - } + /** initialize the local properties, fiber and sheet direction. */ + virtual void initializeLocalParameters(BaseParticles *base_particles) override; + /** second Piola-Kirchhoff stress related with green-lagrangian deformation tensor */ + virtual Matd StressPK1(Matd &deformation, size_t particle_index_i); +}; } #endif // ACTIVE_MODEL_H \ No newline at end of file diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp index cfb48cef0f..8d0bf069de 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp +++ b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp @@ -21,10 +21,5 @@ MaterialIdInitialization::MaterialIdInitialization(SPHBody &sph_body) material_id_(*particles_->getVariableByName("MaterialID")), pos0_(*particles_->getVariableByName("InitialPosition")){}; //=================================================================================================// -Matd ActiveModelSolid::StressPK2(Matd &F, size_t particle_index_i) -{ - return lambda0_ * F.trace() * Matd::Identity() + 2.0 * G0_ * F; -} -//=================================================================================================// } // namespace SPH //=================================================================================================// \ No newline at end of file diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h index f5b0df9820..02a625b366 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h +++ b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h @@ -73,22 +73,5 @@ class MaterialIdInitialization StdLargeVec &material_id_; StdLargeVec &pos0_; }; - -/** - * @class ActiveModelSolid - */ -class ActiveModelSolid : public SaintVenantKirchhoffSolid -{ - public: - explicit ActiveModelSolid(Real rho0, Real youngs_modulus, Real poisson_ratio) - : SaintVenantKirchhoffSolid(rho0, youngs_modulus, poisson_ratio) - { - material_type_name_ = "ActiveModelSolid"; - }; - virtual ~ActiveModelSolid(){}; - - /** second Piola-Kirchhoff stress related with green-lagrangian deformation tensor */ - virtual Matd StressPK2(Matd &deformation, size_t particle_index_i); -}; } // namespace SPH #endif // COMPOSITE_MATERIAL_H From 9fe309767e4cdb1eb65f8596419d292d4173dd39 Mon Sep 17 00:00:00 2001 From: xiangyu_hu Date: Wed, 19 Jul 2023 08:37:08 +0200 Subject: [PATCH 3/4] to test all cases --- src/shared/materials/elastic_solid.cpp | 23 +++++++++++-------- src/shared/materials/elastic_solid.h | 7 +++--- .../composite_material.h | 15 ++++++++---- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/shared/materials/elastic_solid.cpp b/src/shared/materials/elastic_solid.cpp index 2f5c3de2f7..6b05611ca6 100644 --- a/src/shared/materials/elastic_solid.cpp +++ b/src/shared/materials/elastic_solid.cpp @@ -53,13 +53,18 @@ Real LinearElasticSolid::getLambda(Real youngs_modulus, Real poisson_ratio) return nu_ * youngs_modulus / (1.0 + poisson_ratio) / (1.0 - 2.0 * poisson_ratio); } //=================================================================================================// -Matd LinearElasticSolid::StressPK2(Matd &F, size_t particle_index_i) +Matd LinearElasticSolid::StressPK1(Matd &F, size_t index_i) +{ + return F * StressPK2(F, index_i); +} +//=================================================================================================// +Matd LinearElasticSolid::StressPK2(Matd &F, size_t index_i) { Matd strain = 0.5 * (F.transpose() + F) - Matd::Identity(); return lambda0_ * strain.trace() * Matd::Identity() + 2.0 * G0_ * strain; } //=================================================================================================// -Matd LinearElasticSolid::StressCauchy(Matd &almansi_strain, Matd &F, size_t particle_index_i) +Matd LinearElasticSolid::StressCauchy(Matd &almansi_strain, Matd &F, size_t index_i) { return lambda0_ * almansi_strain.trace() * Matd::Identity() + 2.0 * G0_ * almansi_strain; } @@ -69,13 +74,13 @@ Real LinearElasticSolid::VolumetricKirchhoff(Real J) return K0_ * J * (J - 1); } //=================================================================================================// -Matd SaintVenantKirchhoffSolid::StressPK2(Matd &F, size_t particle_index_i) +Matd SaintVenantKirchhoffSolid::StressPK2(Matd &F, size_t index_i) { Matd strain = 0.5 * (F.transpose() * F - Matd::Identity()); return lambda0_ * strain.trace() * Matd::Identity() + 2.0 * G0_ * strain; } //=================================================================================================// -Matd NeoHookeanSolid::StressPK2(Matd &F, size_t particle_index_i) +Matd NeoHookeanSolid::StressPK2(Matd &F, size_t index_i) { // This formulation allows negative determinant of F. Please refer Eq. (12) in // Smith et al. (2018) Stable Neo-Hookean Flesh Simulation. @@ -85,7 +90,7 @@ Matd NeoHookeanSolid::StressPK2(Matd &F, size_t particle_index_i) return G0_ * Matd::Identity() + (lambda0_ * (J - 1.0) - G0_) * J * right_cauchy.inverse(); } //=================================================================================================// -Matd NeoHookeanSolid::StressCauchy(Matd &almansi_strain, Matd &F, size_t particle_index_i) +Matd NeoHookeanSolid::StressCauchy(Matd &almansi_strain, Matd &F, size_t index_i) { Real J = F.determinant(); Matd B = (-2.0 * almansi_strain + Matd::Identity()).inverse(); @@ -100,7 +105,7 @@ Real NeoHookeanSolid::VolumetricKirchhoff(Real J) return 0.5 * K0_ * (J * J - 1); } //=================================================================================================// -Matd NeoHookeanSolidIncompressible::StressPK2(Matd &F, size_t particle_index_i) +Matd NeoHookeanSolidIncompressible::StressPK2(Matd &F, size_t index_i) { Matd right_cauchy = F.transpose() * F; Real I_1 = right_cauchy.trace(); // first strain invariant @@ -109,7 +114,7 @@ Matd NeoHookeanSolidIncompressible::StressPK2(Matd &F, size_t particle_index_i) } //=================================================================================================// Matd NeoHookeanSolidIncompressible:: - StressCauchy(Matd &almansi_strain, Matd &F, size_t particle_index_i) + StressCauchy(Matd &almansi_strain, Matd &F, size_t index_i) { // TODO: implement return {}; @@ -136,7 +141,7 @@ OrthotropicSolid::OrthotropicSolid(Real rho_0, std::array a, s CalculateAllLambda(); }; //=================================================================================================// -Matd OrthotropicSolid::StressPK2(Matd &F, size_t particle_index_i) +Matd OrthotropicSolid::StressPK2(Matd &F, size_t index_i) { Matd strain = 0.5 * (F.transpose() * F - Matd::Identity()); Matd stress_PK2 = Matd::Zero(); @@ -166,7 +171,7 @@ void OrthotropicSolid::CalculateA0() A_[i] = a_[i] * a_[i].transpose(); } //=================================================================================================// -Matd FeneNeoHookeanSolid::StressPK2(Matd &F, size_t particle_index_i) +Matd FeneNeoHookeanSolid::StressPK2(Matd &F, size_t index_i) { Matd right_cauchy = F.transpose() * F; Matd strain = 0.5 * (right_cauchy - Matd::Identity()); diff --git a/src/shared/materials/elastic_solid.h b/src/shared/materials/elastic_solid.h index 730d27605d..ad7410e952 100644 --- a/src/shared/materials/elastic_solid.h +++ b/src/shared/materials/elastic_solid.h @@ -70,12 +70,10 @@ class ElasticSolid : public Solid Real BulkModulus() { return K0_; }; Real PoissonRatio() { return nu_; }; + /** 1st Piola-Kirchhoff stress through deformation. */ + virtual Matd StressPK1(Matd &deformation, size_t particle_index_i) = 0; /** 2nd Piola-Kirchhoff stress through deformation. */ virtual Matd StressPK2(Matd &deformation, size_t particle_index_i) = 0; - virtual Matd StressPK1(Matd &deformation, size_t particle_index_i) - { - return deformation * StressPK2(deformation, particle_index_i); - }; /** Cauchy stress through Eulerian Almansi strain tensor. */ virtual Matd StressCauchy(Matd &almansi_strain, Matd &F, size_t particle_index_i) = 0; /** Numerical damping stress using right Cauchy tensor. */ @@ -119,6 +117,7 @@ class LinearElasticSolid : public ElasticSolid explicit LinearElasticSolid(Real rho0, Real youngs_modulus, Real poisson_ratio); virtual ~LinearElasticSolid(){}; + virtual Matd StressPK1(Matd &deformation, size_t particle_index_i) override; virtual Matd StressPK2(Matd &deformation, size_t particle_index_i) override; virtual Matd StressCauchy(Matd &almansi_strain, Matd &F, size_t particle_index_i) override; /** Volumetric Kirchhoff stress from determinate */ diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h index 02a625b366..10390af5ce 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h +++ b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h @@ -26,17 +26,22 @@ class CompositeSolid : public ElasticSolid virtual void initializeLocalParameters(BaseParticles *base_particles) override; - virtual Matd StressPK2(Matd &deformation, size_t particle_index_i) override + virtual Matd StressPK2(Matd &deformation, size_t index_i) override { - return composite_materials_[material_id_[particle_index_i]]->StressPK2(deformation, particle_index_i); + return composite_materials_[material_id_[index_i]]->StressPK2(deformation, index_i); }; - Real CompositeDensity(size_t particle_index_i) + virtual Matd StressPK1(Matd &deformation, size_t index_i) override { - return composite_materials_[material_id_[particle_index_i]]->ReferenceDensity(); + return composite_materials_[material_id_[index_i]]->StressPK1(deformation, index_i); }; - virtual Matd StressCauchy(Matd &almansi_strain, Matd &F, size_t particle_index_i) override + Real CompositeDensity(size_t index_i) + { + return composite_materials_[material_id_[index_i]]->ReferenceDensity(); + }; + + virtual Matd StressCauchy(Matd &almansi_strain, Matd &F, size_t index_i) override { return Matd::Identity(); }; From b2f87eaf5a89e43604492d213c92e062697c8763 Mon Sep 17 00:00:00 2001 From: Xiangyu Hu Date: Wed, 19 Jul 2023 09:24:40 +0200 Subject: [PATCH 4/4] to test locally --- src/shared/materials/complex_solid.cpp | 57 +++++++++++++ src/shared/materials/complex_solid.h | 55 ++++++++++++- .../2d_flow_stream_around_fish.h | 1 - .../active_model.h | 8 +- .../composite_material.cpp | 25 ------ .../composite_material.h | 82 ------------------- 6 files changed, 115 insertions(+), 113 deletions(-) create mode 100644 src/shared/materials/complex_solid.cpp delete mode 100644 tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp delete mode 100644 tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h diff --git a/src/shared/materials/complex_solid.cpp b/src/shared/materials/complex_solid.cpp new file mode 100644 index 0000000000..6a28f6c437 --- /dev/null +++ b/src/shared/materials/complex_solid.cpp @@ -0,0 +1,57 @@ +/** + * @file complex_solid.cpp + * @brief These are classes for define complex solid materials. + * @author Yaru Ren and Xiangyu Hu + */ + +#include "complex_solid.h" + +#include "base_local_dynamics.h" +#include "base_particles.hpp" + +namespace SPH +{ +//=================================================================================================// +CompositeSolid::CompositeSolid(Real rho0) + : ElasticSolid(rho0) +{ + material_type_name_ = "CompositeSolid"; +} +//=================================================================================================// +Matd CompositeSolid::StressPK2(Matd &deformation, size_t index_i) +{ + return composite_materials_[material_id_[index_i]]->StressPK2(deformation, index_i); +} +//=================================================================================================// +Matd CompositeSolid::StressPK1(Matd &deformation, size_t index_i) +{ + return composite_materials_[material_id_[index_i]]->StressPK1(deformation, index_i); +} +//=================================================================================================// +Matd CompositeSolid::StressCauchy(Matd &almansi_strain, Matd &F, size_t index_i) +{ + return Matd::Identity(); +} +//=================================================================================================// +Real CompositeSolid::CompositeDensity(size_t index_i) +{ + return composite_materials_[material_id_[index_i]]->ReferenceDensity(); +} +//=================================================================================================// +void CompositeSolid::initializeLocalParameters(BaseParticles *base_particles) +{ + ElasticSolid::initializeLocalParameters(base_particles); + base_particles->registerVariable(material_id_, "MaterialID"); + + for (size_t i = 0; i < composite_materials_.size(); ++i) + { + composite_materials_[i]->initializeLocalParameters(base_particles); + } +} +//=================================================================================================// +MaterialIdInitialization::MaterialIdInitialization(SPHBody &sph_body) + : LocalDynamics(sph_body), GeneralDataDelegateSimple(sph_body), + material_id_(*particles_->getVariableByName("MaterialID")), + pos0_(*particles_->getVariableByName("InitialPosition")){}; +//=================================================================================================// +} // namespace SPH diff --git a/src/shared/materials/complex_solid.h b/src/shared/materials/complex_solid.h index a4023417d2..08ee09e390 100644 --- a/src/shared/materials/complex_solid.h +++ b/src/shared/materials/complex_solid.h @@ -26,9 +26,11 @@ * @author Chi ZHang and Xiangyu Hu */ -#pragma once +#ifndef COMPLEX_SOLID_H +#define COMPLEX_SOLID_H #include "elastic_solid.h" +#include namespace SPH { @@ -53,4 +55,55 @@ class ActiveMuscle : public MuscleType virtual Matd StressPK2(Matd &deformation, size_t index_i) override; virtual ActiveMuscle *ThisObjectPtr() override { return this; }; }; + +/** + * @class CompositeSolid + */ +class CompositeSolid : public ElasticSolid +{ + StdLargeVec material_id_; + + protected: + UniquePtrsKeeper composite_ptrs_keeper_; + StdVec composite_materials_; + + public: + explicit CompositeSolid(Real rho0); + virtual ~CompositeSolid(){}; + + virtual void initializeLocalParameters(BaseParticles *base_particles) override; + virtual Matd StressPK2(Matd &deformation, size_t index_i) override; + virtual Matd StressPK1(Matd &deformation, size_t index_i) override; + virtual Matd StressCauchy(Matd &almansi_strain, Matd &F, size_t index_i) override; + virtual Real VolumetricKirchhoff(Real J) override { return 0.0; }; + virtual std::string getRelevantStressMeasureName() override { return "PK2"; }; + + Real CompositeDensity(size_t index_i); + + template + void add(Args &&...args) + { + ElasticSolid *added_material = + composite_ptrs_keeper_.createPtr(std::forward(args)...); + composite_materials_.push_back(added_material); + c0_ = SMAX(c0_, added_material->ReferenceSoundSpeed()); + setContactStiffness(c0_); + }; +}; + +/** + * @class MaterialIdInitialization + */ +class MaterialIdInitialization + : public LocalDynamics, + public GeneralDataDelegateSimple +{ + public: + explicit MaterialIdInitialization(SPHBody &sph_body); + + protected: + StdLargeVec &material_id_; + StdLargeVec &pos0_; +}; } // namespace SPH +#endif // COMPLEX_SOLID_H diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h index 8107c7ad08..d568b31f66 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h +++ b/tests/user_examples/test_2d_flow_stream_around_fish/2d_flow_stream_around_fish.h @@ -1,7 +1,6 @@ #include "2d_fish_and_bones.h" #include "active_model.h" -#include "composite_material.h" #include "sphinxsys.h" using namespace SPH; diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/active_model.h b/tests/user_examples/test_2d_flow_stream_around_fish/active_model.h index 6534597c89..66892274c2 100644 --- a/tests/user_examples/test_2d_flow_stream_around_fish/active_model.h +++ b/tests/user_examples/test_2d_flow_stream_around_fish/active_model.h @@ -1,8 +1,8 @@ #ifndef ACTIVE_MODEL_H #define ACTIVE_MODEL_H +#include "complex_solid.h" #include "elastic_dynamics.h" -#include "composite_material.h" namespace SPH { @@ -20,7 +20,7 @@ class ActiveModelSolid : public SaintVenantKirchhoffSolid /** initialize the local properties, fiber and sheet direction. */ virtual void initializeLocalParameters(BaseParticles *base_particles) override; /** second Piola-Kirchhoff stress related with green-lagrangian deformation tensor */ - virtual Matd StressPK1(Matd &deformation, size_t particle_index_i); + virtual Matd StressPK1(Matd &deformation, size_t particle_index_i) override; }; -} -#endif // ACTIVE_MODEL_H \ No newline at end of file +} // namespace SPH +#endif // ACTIVE_MODEL_H diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp deleted file mode 100644 index 8d0bf069de..0000000000 --- a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "composite_material.h" -#include "base_local_dynamics.h" -#include "base_particles.hpp" - -namespace SPH -{ -//=================================================================================================// -void CompositeSolid::initializeLocalParameters(BaseParticles *base_particles) -{ - ElasticSolid::initializeLocalParameters(base_particles); - base_particles->registerVariable(material_id_, "MaterialID"); - - for (size_t i = 0; i < composite_materials_.size(); ++i) - { - composite_materials_[i]->initializeLocalParameters(base_particles); - } -} -//=================================================================================================// -MaterialIdInitialization::MaterialIdInitialization(SPHBody &sph_body) - : LocalDynamics(sph_body), GeneralDataDelegateSimple(sph_body), - material_id_(*particles_->getVariableByName("MaterialID")), - pos0_(*particles_->getVariableByName("InitialPosition")){}; -//=================================================================================================// -} // namespace SPH - //=================================================================================================// \ No newline at end of file diff --git a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h b/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h deleted file mode 100644 index 10390af5ce..0000000000 --- a/tests/user_examples/test_2d_flow_stream_around_fish/composite_material.h +++ /dev/null @@ -1,82 +0,0 @@ - -#ifndef COMPOSITE_MATERIAL_H -#define COMPOSITE_MATERIAL_H - -#include "elastic_solid.h" - -#include - -namespace SPH -{ -/**@class CompositeSolid*/ -class CompositeSolid : public ElasticSolid -{ - protected: - UniquePtrsKeeper composite_ptrs_keeper_; - StdVec composite_materials_; - - public: - StdLargeVec material_id_; - - explicit CompositeSolid(Real rho0) : ElasticSolid(rho0) - { - material_type_name_ = "CompositeSolid"; - }; - virtual ~CompositeSolid(){}; - - virtual void initializeLocalParameters(BaseParticles *base_particles) override; - - virtual Matd StressPK2(Matd &deformation, size_t index_i) override - { - return composite_materials_[material_id_[index_i]]->StressPK2(deformation, index_i); - }; - - virtual Matd StressPK1(Matd &deformation, size_t index_i) override - { - return composite_materials_[material_id_[index_i]]->StressPK1(deformation, index_i); - }; - - Real CompositeDensity(size_t index_i) - { - return composite_materials_[material_id_[index_i]]->ReferenceDensity(); - }; - - virtual Matd StressCauchy(Matd &almansi_strain, Matd &F, size_t index_i) override - { - return Matd::Identity(); - }; - - virtual Real VolumetricKirchhoff(Real J) override - { - return 0.0; - }; - - virtual std::string getRelevantStressMeasureName() override { return "PK2"; }; - - template - void add(Args &&...args) - { - ElasticSolid *added_material = - composite_ptrs_keeper_.createPtr(std::forward(args)...); - composite_materials_.push_back(added_material); - c0_ = SMAX(c0_, added_material->ReferenceSoundSpeed()); - setContactStiffness(c0_); - }; -}; - -/** - * @class MaterialIdInitialization - */ -class MaterialIdInitialization - : public LocalDynamics, - public GeneralDataDelegateSimple -{ - public: - explicit MaterialIdInitialization(SPHBody &sph_body); - - protected: - StdLargeVec &material_id_; - StdLargeVec &pos0_; -}; -} // namespace SPH -#endif // COMPOSITE_MATERIAL_H