From b689205449423dc49dd768e43100d85fc9d88002 Mon Sep 17 00:00:00 2001 From: Xiangyu Hu Date: Sat, 5 Oct 2024 09:58:32 +0000 Subject: [PATCH 1/5] to test locally --- src/shared/geometries/complex_shape.cpp | 6 +++--- src/shared/geometries/complex_shape.h | 16 ++++++++-------- .../pressure_boundary/bidirectional_buffer.h | 9 +++++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/shared/geometries/complex_shape.cpp b/src/shared/geometries/complex_shape.cpp index b0270930b9..05d1f36cf5 100644 --- a/src/shared/geometries/complex_shape.cpp +++ b/src/shared/geometries/complex_shape.cpp @@ -3,11 +3,11 @@ namespace SPH { //=================================================================================================// -bool AlignedBoxShape::checkInBounds(const Vecd &probe_point) +bool AlignedBoxShape::checkInBounds(const Vecd &probe_point, Real lower_bound_fringe, Real upper_bound_fringe) { Vecd position_in_frame = transform_.shiftBaseStationToFrame(probe_point); - return position_in_frame[alignment_axis_] >= -halfsize_[alignment_axis_] && - position_in_frame[alignment_axis_] <= halfsize_[alignment_axis_] + return position_in_frame[alignment_axis_] >= -halfsize_[alignment_axis_] - lower_bound_fringe && + position_in_frame[alignment_axis_] <= halfsize_[alignment_axis_] + upper_bound_fringe ? true : false; } diff --git a/src/shared/geometries/complex_shape.h b/src/shared/geometries/complex_shape.h index da1ce20f63..4f093f5a6f 100644 --- a/src/shared/geometries/complex_shape.h +++ b/src/shared/geometries/complex_shape.h @@ -41,11 +41,11 @@ class LevelSetShape; /** * @class ComplexShape - * @brief For now, if the level set shape (for particle relaxation) - * will be generated from the complex shape, - * partially overlapped shapes are not allowed for 3D problems. + * @brief For now, if the level set shape (for particle relaxation) + * will be generated from the complex shape, + * partially overlapped shapes are not allowed for 3D problems. * However, if only the contain function - * is used, for example generating particles using lattice generator, + * is used, for example generating particles using lattice generator, * partially overlapped shapes are allowed. **/ class ComplexShape : public BinaryShapes @@ -56,7 +56,7 @@ class ComplexShape : public BinaryShapes virtual ~ComplexShape(){}; template - LevelSetShape *defineLevelSetShape(SPHBody &sph_body, const std::string &shape_name, Args &&... args) + LevelSetShape *defineLevelSetShape(SPHBody &sph_body, const std::string &shape_name, Args &&...args) { size_t index = getSubShapeIndexByName(shape_name); LevelSetShape *level_set_shape = sub_shape_ptrs_keeper_[index].createPtr( @@ -80,12 +80,12 @@ class AlignedBoxShape : public TransformShape public: /** construct directly */ template - explicit AlignedBoxShape(int upper_bound_axis, const Transform &transform, Args &&... args) + explicit AlignedBoxShape(int upper_bound_axis, const Transform &transform, Args &&...args) : TransformShape(transform, std::forward(args)...), alignment_axis_(upper_bound_axis){}; /** construct from a shape already has aligned boundaries */ template - explicit AlignedBoxShape(int upper_bound_axis, const Shape &shape, Args &&... args) + explicit AlignedBoxShape(int upper_bound_axis, const Shape &shape, Args &&...args) : TransformShape( Transform(Vecd(0.5 * (shape.bounding_box_.second_ + shape.bounding_box_.first_))), 0.5 * (shape.bounding_box_.second_ - shape.bounding_box_.first_), std::forward(args)...), @@ -93,7 +93,7 @@ class AlignedBoxShape : public TransformShape virtual ~AlignedBoxShape(){}; Vecd HalfSize() { return halfsize_; } - bool checkInBounds(const Vecd &probe_point); + bool checkInBounds(const Vecd &probe_point, Real lower_bound_fringe = 0.0, Real upper_bound_fringe = 0.0); bool checkUpperBound(const Vecd &probe_point); bool checkLowerBound(const Vecd &probe_point); bool checkNearUpperBound(const Vecd &probe_point, Real threshold); diff --git a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h index 1167429f34..fbf3f38355 100644 --- a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h +++ b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h @@ -62,6 +62,7 @@ class BidirectionalBuffer part_id_(aligned_box_part.getPartID()), pos_(particles_->getVariableDataByName("Position")), aligned_box_(aligned_box_part.getAlignedBoxShape()), + upper_bound_fringe_(-sph_body_.getSPHBodyResolutionRef()), buffer_particle_indicator_(particles_->registerStateVariable("BufferParticleIndicator")) { particles_->addVariableToSort("BufferParticleIndicator"); @@ -70,13 +71,17 @@ class BidirectionalBuffer virtual void update(size_t index_i, Real dt = 0.0) { - buffer_particle_indicator_[index_i] = aligned_box_.checkInBounds(pos_[index_i]) ? part_id_ : 0; + if (aligned_box_.checkInBounds(pos_[index_i], 0.0, upper_bound_fringe_)) + { + buffer_particle_indicator_[index_i] = part_id_; + } }; protected: int part_id_; Vecd *pos_; AlignedBoxShape &aligned_box_; + Real upper_bound_fringe_; int *buffer_particle_indicator_; }; @@ -120,7 +125,6 @@ class BidirectionalBuffer Real sound_speed = fluid_.getSoundSpeed(rho_[index_i]); p_[index_i] = target_pressure_(p_[index_i], *physical_time_); rho_[index_i] = p_[index_i] / pow(sound_speed, 2.0) + fluid_.ReferenceDensity(); - previous_surface_indicator_[index_i] = 1; mutex_switch.unlock(); } } @@ -163,6 +167,7 @@ class BidirectionalBuffer { particles_->switchToBufferParticle(index_i); + buffer_particle_indicator_[index_i] = 0; } mutex_switch.unlock(); } From 715c394bec85964b6f77cc64034917cdd38d3007 Mon Sep 17 00:00:00 2001 From: xiangyu_hu Date: Sat, 5 Oct 2024 17:06:49 +0200 Subject: [PATCH 2/5] indentify initialization and update buffer particles --- .../shared/pressure_boundary/bidirectional_buffer.h | 13 ++++++++----- .../test_2d_T_pipe_VIPO_shell/T_pipe_VIPO_shell.cpp | 12 ++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h index fbf3f38355..0ce4222c46 100644 --- a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h +++ b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h @@ -57,14 +57,14 @@ class BidirectionalBuffer class TagBufferParticles : public BaseLocalDynamics { public: - TagBufferParticles(BodyAlignedBoxByCell &aligned_box_part) + TagBufferParticles(BodyAlignedBoxByCell &aligned_box_part, bool is_initialization = false) : BaseLocalDynamics(aligned_box_part), part_id_(aligned_box_part.getPartID()), pos_(particles_->getVariableDataByName("Position")), aligned_box_(aligned_box_part.getAlignedBoxShape()), - upper_bound_fringe_(-sph_body_.getSPHBodyResolutionRef()), buffer_particle_indicator_(particles_->registerStateVariable("BufferParticleIndicator")) { + upper_bound_fringe_ = is_initialization ? 0.0 : -sph_body_.getSPHBodyResolutionRef(); particles_->addVariableToSort("BufferParticleIndicator"); }; virtual ~TagBufferParticles(){}; @@ -81,8 +81,8 @@ class BidirectionalBuffer int part_id_; Vecd *pos_; AlignedBoxShape &aligned_box_; - Real upper_bound_fringe_; int *buffer_particle_indicator_; + Real upper_bound_fringe_; }; class Injection : public BaseLocalDynamics @@ -183,12 +183,15 @@ class BidirectionalBuffer public: BidirectionalBuffer(BodyAlignedBoxByCell &aligned_box_part, ParticleBuffer &particle_buffer) - : target_pressure_(*this), tag_buffer_particles(aligned_box_part), + : target_pressure_(*this), + buffer_particles_initialization(aligned_box_part, true), + buffer_particles_update(aligned_box_part), injection(aligned_box_part, particle_buffer, target_pressure_), deletion(aligned_box_part){}; virtual ~BidirectionalBuffer(){}; - SimpleDynamics tag_buffer_particles; + SimpleDynamics buffer_particles_initialization; + SimpleDynamics buffer_particles_update; SimpleDynamics injection; SimpleDynamics deletion; }; diff --git a/tests/extra_source_and_tests/test_2d_T_pipe_VIPO_shell/T_pipe_VIPO_shell.cpp b/tests/extra_source_and_tests/test_2d_T_pipe_VIPO_shell/T_pipe_VIPO_shell.cpp index 64e7bbc479..281b6b279a 100644 --- a/tests/extra_source_and_tests/test_2d_T_pipe_VIPO_shell/T_pipe_VIPO_shell.cpp +++ b/tests/extra_source_and_tests/test_2d_T_pipe_VIPO_shell/T_pipe_VIPO_shell.cpp @@ -374,9 +374,9 @@ int main(int ac, char *av[]) water_block_complex.updateConfiguration(); shell_water_contact.updateConfiguration(); boundary_indicator.exec(); - left_bidirection_buffer.tag_buffer_particles.exec(); - right_up_bidirection_buffer.tag_buffer_particles.exec(); - right_down_bidirection_buffer.tag_buffer_particles.exec(); + left_bidirection_buffer.buffer_particles_initialization.exec(); + right_up_bidirection_buffer.buffer_particles_initialization.exec(); + right_down_bidirection_buffer.buffer_particles_initialization.exec(); //---------------------------------------------------------------------- // Setup computing and initial conditions. //---------------------------------------------------------------------- @@ -493,9 +493,9 @@ int main(int ac, char *av[]) interval_updating_configuration += TickCount::now() - time_instance; boundary_indicator.exec(); - left_bidirection_buffer.tag_buffer_particles.exec(); - right_up_bidirection_buffer.tag_buffer_particles.exec(); - right_down_bidirection_buffer.tag_buffer_particles.exec(); + left_bidirection_buffer.buffer_particles_update.exec(); + right_up_bidirection_buffer.buffer_particles_update.exec(); + right_down_bidirection_buffer.buffer_particles_update.exec(); } TickCount t2 = TickCount::now(); body_states_recording.writeToFile(); From 7be448ef5695fb793b1a6f81b482fa87292ee7e0 Mon Sep 17 00:00:00 2001 From: xiangyu_hu Date: Sat, 5 Oct 2024 21:56:23 +0200 Subject: [PATCH 3/5] injection after full particle leaving the buffer --- src/shared/geometries/complex_shape.cpp | 8 ++++---- src/shared/geometries/complex_shape.h | 4 ++-- .../pressure_boundary/bidirectional_buffer.h | 16 +++++++--------- .../T_pipe_VIPO_shell.cpp | 12 ++++++------ 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/shared/geometries/complex_shape.cpp b/src/shared/geometries/complex_shape.cpp index 05d1f36cf5..d76ddc5b5b 100644 --- a/src/shared/geometries/complex_shape.cpp +++ b/src/shared/geometries/complex_shape.cpp @@ -12,16 +12,16 @@ bool AlignedBoxShape::checkInBounds(const Vecd &probe_point, Real lower_bound_fr : false; } //=================================================================================================// -bool AlignedBoxShape::checkUpperBound(const Vecd &probe_point) +bool AlignedBoxShape::checkUpperBound(const Vecd &probe_point, Real upper_bound_fringe) { Vecd position_in_frame = transform_.shiftBaseStationToFrame(probe_point); - return position_in_frame[alignment_axis_] > halfsize_[alignment_axis_] ? true : false; + return position_in_frame[alignment_axis_] > halfsize_[alignment_axis_] + upper_bound_fringe ? true : false; } //=================================================================================================// -bool AlignedBoxShape::checkLowerBound(const Vecd &probe_point) +bool AlignedBoxShape::checkLowerBound(const Vecd &probe_point, Real lower_bound_fringe) { Vecd position_in_frame = transform_.shiftBaseStationToFrame(probe_point); - return position_in_frame[alignment_axis_] < -halfsize_[alignment_axis_] ? true : false; + return position_in_frame[alignment_axis_] < -halfsize_[alignment_axis_] - lower_bound_fringe ? true : false; } //=================================================================================================// bool AlignedBoxShape::checkNearUpperBound(const Vecd &probe_point, Real threshold) diff --git a/src/shared/geometries/complex_shape.h b/src/shared/geometries/complex_shape.h index 4f093f5a6f..cabbdabbc3 100644 --- a/src/shared/geometries/complex_shape.h +++ b/src/shared/geometries/complex_shape.h @@ -94,8 +94,8 @@ class AlignedBoxShape : public TransformShape Vecd HalfSize() { return halfsize_; } bool checkInBounds(const Vecd &probe_point, Real lower_bound_fringe = 0.0, Real upper_bound_fringe = 0.0); - bool checkUpperBound(const Vecd &probe_point); - bool checkLowerBound(const Vecd &probe_point); + bool checkUpperBound(const Vecd &probe_point, Real upper_bound_fringe = 0.0); + bool checkLowerBound(const Vecd &probe_point, Real lower_bound_fringe = 0.0); bool checkNearUpperBound(const Vecd &probe_point, Real threshold); bool checkNearLowerBound(const Vecd &probe_point, Real threshold); Vecd getUpperPeriodic(const Vecd &probe_point); diff --git a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h index 0ce4222c46..acafacf827 100644 --- a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h +++ b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h @@ -57,21 +57,20 @@ class BidirectionalBuffer class TagBufferParticles : public BaseLocalDynamics { public: - TagBufferParticles(BodyAlignedBoxByCell &aligned_box_part, bool is_initialization = false) + TagBufferParticles(BodyAlignedBoxByCell &aligned_box_part) : BaseLocalDynamics(aligned_box_part), part_id_(aligned_box_part.getPartID()), pos_(particles_->getVariableDataByName("Position")), aligned_box_(aligned_box_part.getAlignedBoxShape()), buffer_particle_indicator_(particles_->registerStateVariable("BufferParticleIndicator")) { - upper_bound_fringe_ = is_initialization ? 0.0 : -sph_body_.getSPHBodyResolutionRef(); particles_->addVariableToSort("BufferParticleIndicator"); }; virtual ~TagBufferParticles(){}; virtual void update(size_t index_i, Real dt = 0.0) { - if (aligned_box_.checkInBounds(pos_[index_i], 0.0, upper_bound_fringe_)) + if (aligned_box_.checkInBounds(pos_[index_i])) { buffer_particle_indicator_[index_i] = part_id_; } @@ -82,7 +81,6 @@ class BidirectionalBuffer Vecd *pos_; AlignedBoxShape &aligned_box_; int *buffer_particle_indicator_; - Real upper_bound_fringe_; }; class Injection : public BaseLocalDynamics @@ -100,6 +98,7 @@ class BidirectionalBuffer p_(particles_->getVariableDataByName("Pressure")), previous_surface_indicator_(particles_->getVariableDataByName("PreviousSurfaceIndicator")), buffer_particle_indicator_(particles_->getVariableDataByName("BufferParticleIndicator")), + upper_bound_fringe_(0.5 * sph_body_.getSPHBodyResolutionRef()), physical_time_(sph_system_.getSystemVariableDataByName("PhysicalTime")), target_pressure_(target_pressure) { @@ -111,7 +110,7 @@ class BidirectionalBuffer { if (!aligned_box_.checkInBounds(pos_[index_i])) { - if (aligned_box_.checkUpperBound(pos_[index_i]) && + if (aligned_box_.checkUpperBound(pos_[index_i], upper_bound_fringe_) && buffer_particle_indicator_[index_i] == part_id_ && index_i < particles_->TotalRealParticles()) { @@ -139,6 +138,7 @@ class BidirectionalBuffer Vecd *pos_; Real *rho_, *p_; int *previous_surface_indicator_, *buffer_particle_indicator_; + Real upper_bound_fringe_; Real *physical_time_; private: @@ -184,14 +184,12 @@ class BidirectionalBuffer public: BidirectionalBuffer(BodyAlignedBoxByCell &aligned_box_part, ParticleBuffer &particle_buffer) : target_pressure_(*this), - buffer_particles_initialization(aligned_box_part, true), - buffer_particles_update(aligned_box_part), + tag_buffer_particles(aligned_box_part), injection(aligned_box_part, particle_buffer, target_pressure_), deletion(aligned_box_part){}; virtual ~BidirectionalBuffer(){}; - SimpleDynamics buffer_particles_initialization; - SimpleDynamics buffer_particles_update; + SimpleDynamics tag_buffer_particles; SimpleDynamics injection; SimpleDynamics deletion; }; diff --git a/tests/extra_source_and_tests/test_2d_T_pipe_VIPO_shell/T_pipe_VIPO_shell.cpp b/tests/extra_source_and_tests/test_2d_T_pipe_VIPO_shell/T_pipe_VIPO_shell.cpp index 281b6b279a..64e7bbc479 100644 --- a/tests/extra_source_and_tests/test_2d_T_pipe_VIPO_shell/T_pipe_VIPO_shell.cpp +++ b/tests/extra_source_and_tests/test_2d_T_pipe_VIPO_shell/T_pipe_VIPO_shell.cpp @@ -374,9 +374,9 @@ int main(int ac, char *av[]) water_block_complex.updateConfiguration(); shell_water_contact.updateConfiguration(); boundary_indicator.exec(); - left_bidirection_buffer.buffer_particles_initialization.exec(); - right_up_bidirection_buffer.buffer_particles_initialization.exec(); - right_down_bidirection_buffer.buffer_particles_initialization.exec(); + left_bidirection_buffer.tag_buffer_particles.exec(); + right_up_bidirection_buffer.tag_buffer_particles.exec(); + right_down_bidirection_buffer.tag_buffer_particles.exec(); //---------------------------------------------------------------------- // Setup computing and initial conditions. //---------------------------------------------------------------------- @@ -493,9 +493,9 @@ int main(int ac, char *av[]) interval_updating_configuration += TickCount::now() - time_instance; boundary_indicator.exec(); - left_bidirection_buffer.buffer_particles_update.exec(); - right_up_bidirection_buffer.buffer_particles_update.exec(); - right_down_bidirection_buffer.buffer_particles_update.exec(); + left_bidirection_buffer.tag_buffer_particles.exec(); + right_up_bidirection_buffer.tag_buffer_particles.exec(); + right_down_bidirection_buffer.tag_buffer_particles.exec(); } TickCount t2 = TickCount::now(); body_states_recording.writeToFile(); From b7082500bac04d6715d3acde27978ca55f5e5096 Mon Sep 17 00:00:00 2001 From: Xiangyu Date: Mon, 7 Oct 2024 17:21:22 +0200 Subject: [PATCH 4/5] reverse wrongly deleted line --- .../pressure_boundary/bidirectional_buffer.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h index acafacf827..7934f545d1 100644 --- a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h +++ b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h @@ -66,7 +66,7 @@ class BidirectionalBuffer { particles_->addVariableToSort("BufferParticleIndicator"); }; - virtual ~TagBufferParticles(){}; + virtual ~TagBufferParticles() {}; virtual void update(size_t index_i, Real dt = 0.0) { @@ -104,7 +104,7 @@ class BidirectionalBuffer { particle_buffer_.checkParticlesReserved(); }; - virtual ~Injection(){}; + virtual ~Injection() {}; void update(size_t index_i, Real dt = 0.0) { @@ -124,6 +124,7 @@ class BidirectionalBuffer Real sound_speed = fluid_.getSoundSpeed(rho_[index_i]); p_[index_i] = target_pressure_(p_[index_i], *physical_time_); rho_[index_i] = p_[index_i] / pow(sound_speed, 2.0) + fluid_.ReferenceDensity(); + previous_surface_indicator_[index_i] = 1; mutex_switch.unlock(); } } @@ -153,8 +154,8 @@ class BidirectionalBuffer part_id_(aligned_box_part.getPartID()), aligned_box_(aligned_box_part.getAlignedBoxShape()), pos_(particles_->getVariableDataByName("Position")), - buffer_particle_indicator_(particles_->getVariableDataByName("BufferParticleIndicator")){}; - virtual ~Deletion(){}; + buffer_particle_indicator_(particles_->getVariableDataByName("BufferParticleIndicator")) {}; + virtual ~Deletion() {}; void update(size_t index_i, Real dt = 0.0) { @@ -183,11 +184,11 @@ class BidirectionalBuffer public: BidirectionalBuffer(BodyAlignedBoxByCell &aligned_box_part, ParticleBuffer &particle_buffer) - : target_pressure_(*this), + : target_pressure_(*this), tag_buffer_particles(aligned_box_part), injection(aligned_box_part, particle_buffer, target_pressure_), - deletion(aligned_box_part){}; - virtual ~BidirectionalBuffer(){}; + deletion(aligned_box_part) {}; + virtual ~BidirectionalBuffer() {}; SimpleDynamics tag_buffer_particles; SimpleDynamics injection; From 60d99030eef03a2593c6a66e828e5963e0cd984e Mon Sep 17 00:00:00 2001 From: Xiangyu Date: Mon, 7 Oct 2024 17:27:21 +0200 Subject: [PATCH 5/5] delete a line which has not effect --- .../extra_src/shared/pressure_boundary/bidirectional_buffer.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h index 7934f545d1..1d1357e2e1 100644 --- a/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h +++ b/tests/extra_source_and_tests/extra_src/shared/pressure_boundary/bidirectional_buffer.h @@ -166,9 +166,7 @@ class BidirectionalBuffer buffer_particle_indicator_[index_i] == part_id_ && index_i < particles_->TotalRealParticles()) { - particles_->switchToBufferParticle(index_i); - buffer_particle_indicator_[index_i] = 0; } mutex_switch.unlock(); }