Skip to content

Commit

Permalink
Merge pull request #673 from Xiangyu-Hu/xiangyu/buffer_consistency
Browse files Browse the repository at this point in the history
Xiangyu/buffer consistency
  • Loading branch information
Xiangyu-Hu authored Oct 10, 2024
2 parents 51bd245 + 60d9903 commit 00815cb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
14 changes: 7 additions & 7 deletions src/shared/geometries/complex_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
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;
}
//=================================================================================================//
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)
Expand Down
20 changes: 10 additions & 10 deletions src/shared/geometries/complex_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,7 +56,7 @@ class ComplexShape : public BinaryShapes
virtual ~ComplexShape(){};

template <typename... Args>
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<LevelSetShape>(
Expand All @@ -80,22 +80,22 @@ class AlignedBoxShape : public TransformShape<GeometricShapeBox>
public:
/** construct directly */
template <typename... Args>
explicit AlignedBoxShape(int upper_bound_axis, const Transform &transform, Args &&... args)
explicit AlignedBoxShape(int upper_bound_axis, const Transform &transform, Args &&...args)
: TransformShape<GeometricShapeBox>(transform, std::forward<Args>(args)...),
alignment_axis_(upper_bound_axis){};
/** construct from a shape already has aligned boundaries */
template <typename... Args>
explicit AlignedBoxShape(int upper_bound_axis, const Shape &shape, Args &&... args)
explicit AlignedBoxShape(int upper_bound_axis, const Shape &shape, Args &&...args)
: TransformShape<GeometricShapeBox>(
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>(args)...),
alignment_axis_(upper_bound_axis){};
virtual ~AlignedBoxShape(){};

Vecd HalfSize() { return halfsize_; }
bool checkInBounds(const Vecd &probe_point);
bool checkUpperBound(const Vecd &probe_point);
bool checkLowerBound(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, 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ class BidirectionalBuffer
{
particles_->addVariableToSort<int>("BufferParticleIndicator");
};
virtual ~TagBufferParticles(){};
virtual ~TagBufferParticles() {};

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]))
{
buffer_particle_indicator_[index_i] = part_id_;
}
};

protected:
Expand All @@ -95,18 +98,19 @@ class BidirectionalBuffer
p_(particles_->getVariableDataByName<Real>("Pressure")),
previous_surface_indicator_(particles_->getVariableDataByName<int>("PreviousSurfaceIndicator")),
buffer_particle_indicator_(particles_->getVariableDataByName<int>("BufferParticleIndicator")),
upper_bound_fringe_(0.5 * sph_body_.getSPHBodyResolutionRef()),
physical_time_(sph_system_.getSystemVariableDataByName<Real>("PhysicalTime")),
target_pressure_(target_pressure)
{
particle_buffer_.checkParticlesReserved();
};
virtual ~Injection(){};
virtual ~Injection() {};

void update(size_t index_i, Real dt = 0.0)
{
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())
{
Expand Down Expand Up @@ -135,6 +139,7 @@ class BidirectionalBuffer
Vecd *pos_;
Real *rho_, *p_;
int *previous_surface_indicator_, *buffer_particle_indicator_;
Real upper_bound_fringe_;
Real *physical_time_;

private:
Expand All @@ -149,8 +154,8 @@ class BidirectionalBuffer
part_id_(aligned_box_part.getPartID()),
aligned_box_(aligned_box_part.getAlignedBoxShape()),
pos_(particles_->getVariableDataByName<Vecd>("Position")),
buffer_particle_indicator_(particles_->getVariableDataByName<int>("BufferParticleIndicator")){};
virtual ~Deletion(){};
buffer_particle_indicator_(particles_->getVariableDataByName<int>("BufferParticleIndicator")) {};
virtual ~Deletion() {};

void update(size_t index_i, Real dt = 0.0)
{
Expand All @@ -161,7 +166,6 @@ class BidirectionalBuffer
buffer_particle_indicator_[index_i] == part_id_ &&
index_i < particles_->TotalRealParticles())
{

particles_->switchToBufferParticle(index_i);
}
mutex_switch.unlock();
Expand All @@ -178,10 +182,11 @@ class BidirectionalBuffer

public:
BidirectionalBuffer(BodyAlignedBoxByCell &aligned_box_part, ParticleBuffer<Base> &particle_buffer)
: target_pressure_(*this), tag_buffer_particles(aligned_box_part),
: 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<TagBufferParticles, ExecutionPolicy> tag_buffer_particles;
SimpleDynamics<Injection, ExecutionPolicy> injection;
Expand Down

0 comments on commit 00815cb

Please sign in to comment.