Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitbucket main #83

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions SPHINXsys/src/for_2D_build/common/data_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace SPH {
using Matd = Mat2d;
using SymMatd = SymMat2d;
using AngularVecd = Real;
const int indexAngularVector = 0;


using Transformd = Transform2d;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,49 @@ namespace SPH {
}
}
//=================================================================================================//
void ShellParticleGeneratorLattice::createBaseParticles(BaseParticles* base_particles)
{
// Calculate the total volume and
// count the number of cells inside the body volume, where we might put particles.
Xiangyu-Hu marked this conversation as resolved.
Show resolved Hide resolved
std::unique_ptr<BaseMesh> mesh(new BaseMesh(domain_bounds_, lattice_spacing_, 0));
Vecu number_of_lattices = mesh->NumberOfCellsFromNumberOfGridPoints(mesh->NumberOfGridPoints());
for (size_t i = 0; i < number_of_lattices[0]; ++i)
for (size_t j = 0; j < number_of_lattices[1]; ++j) {
Vecd particle_position = mesh->CellPositionFromIndex(Vecu(i, j));
if (body_shape_->checkNotFar(particle_position, lattice_spacing_))
{
if (body_shape_->checkContain(particle_position))
{
number_of_cells_++;
total_volume_ += lattice_spacing_ * lattice_spacing_;
}
}
}
Real number_of_particles = total_volume_ / avg_particle_volume_ + 0.5;
planned_number_of_particles_ = int(number_of_particles);

// Calculate the interval based on the number of particles.
Real interval = (Real)planned_number_of_particles_ / (Real)number_of_cells_;
if (interval <= 0) interval = 1; // It has to be lager than 0.
Xiangyu-Hu marked this conversation as resolved.
Show resolved Hide resolved
Real random_real = 0.0;
// Add a particle in each interval, randomly. We will skip the last intervals if we already reach the number of particles
for (size_t i = 0; i < number_of_lattices[0]; ++i)
for (size_t j = 0; j < number_of_lattices[1]; ++j)
{
Xiangyu-Hu marked this conversation as resolved.
Show resolved Hide resolved
Vecd particle_position = mesh->CellPositionFromIndex(Vecu(i, j));
if (body_shape_->checkNotFar(particle_position, lattice_spacing_))
Xiangyu-Hu marked this conversation as resolved.
Show resolved Hide resolved
{
if (body_shape_->checkContain(particle_position))
{
random_real = (Real)rand() / (RAND_MAX);
// If the random_real is smaller than the interval, add a particle, only if we haven't reached the max. number of particles
if (random_real <= interval && base_particles->total_real_particles_ < planned_number_of_particles_)
{
createABaseParticle(base_particles, particle_position, avg_particle_volume_);
}
}
}
}
}
//=================================================================================================//
}
1 change: 0 additions & 1 deletion SPHINXsys/src/for_3D_build/common/data_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace SPH {
using Matd = Mat3d;
using SymMatd = SymMat3d;
using AngularVecd = Vec3d;
const int indexAngularVector = 1;

using Transformd = Transform3d;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,50 @@ namespace SPH {
}
}
//=================================================================================================//
void ShellParticleGeneratorLattice::createBaseParticles(BaseParticles* base_particles)
{
// Calculate the total volume and
// count the number of cells inside the body volume, where we might put particles.
std::unique_ptr<BaseMesh> mesh(new BaseMesh(domain_bounds_, lattice_spacing_, 0));
Xiangyu-Hu marked this conversation as resolved.
Show resolved Hide resolved
Vecu number_of_lattices = mesh->NumberOfCellsFromNumberOfGridPoints(mesh->NumberOfGridPoints());
for (size_t i = 0; i < number_of_lattices[0]; ++i)
for (size_t j = 0; j < number_of_lattices[1]; ++j)
for (size_t k = 0; k < number_of_lattices[2]; ++k) {
Vecd particle_position = mesh->CellPositionFromIndex(Vecu(i, j, k));
if (body_shape_->checkNotFar(particle_position, lattice_spacing_))
{
if (body_shape_->checkContain(particle_position))
{
number_of_cells_++;
total_volume_ += lattice_spacing_ * lattice_spacing_ * lattice_spacing_;
}
}
}
Real number_of_particles = total_volume_ / avg_particle_volume_ + 0.5;
planned_number_of_particles_ = int(number_of_particles);

// Calculate the interval based on the number of particles.
Real interval = planned_number_of_particles_ / (number_of_cells_ + TinyReal);
if (interval <= 0) interval = 1; // It has to be lager than 0.
Real random_real = 0.0;
// Add a particle in each interval, randomly. We will skip the last intervals if we already reach the number of particles.
for (size_t i = 0; i < number_of_lattices[0]; ++i)
for (size_t j = 0; j < number_of_lattices[1]; ++j)
for (size_t k = 0; k < number_of_lattices[2]; ++k) {
Vecd particle_position = mesh->CellPositionFromIndex(Vecu(i, j, k));
if (body_shape_->checkNotFar(particle_position, lattice_spacing_))
{
if (body_shape_->checkContain(particle_position))
{
random_real = (Real)rand() / (RAND_MAX);
// If the random_real is smaller than the interval, add a particle, only if we haven't reached the max. number of particles.
if (random_real <= interval && base_particles->total_real_particles_ < planned_number_of_particles_)
{
createABaseParticle(base_particles, particle_position, avg_particle_volume_);
}
}
}
}
}
//=================================================================================================//
}
10 changes: 6 additions & 4 deletions SPHINXsys/src/shared/adaptations/adaptation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
namespace SPH
{
//=================================================================================================//
SPHAdaptation::SPHAdaptation(Real h_spacing_ratio, Real system_resolution_ratio, Real small_shift_factor)
SPHAdaptation::SPHAdaptation(Real h_spacing_ratio, Real system_resolution_ratio,
Real small_shift_factor, Real level_set_refinement_ratio)
: h_spacing_ratio_(h_spacing_ratio),
system_resolution_ratio_(system_resolution_ratio),
local_refinement_level_(0),
Expand All @@ -26,7 +27,8 @@ namespace SPH
kernel_(kernel_ptr_keeper_.createPtr<KernelWendlandC2>()),
sph_body_(nullptr), system_domain_bounds_(),
base_particles_(nullptr),
small_shift_factor_(small_shift_factor)
small_shift_factor_(small_shift_factor),
level_set_refinement_ratio_(level_set_refinement_ratio)
{};
//=================================================================================================//
void SPHAdaptation::initialize(SPHBody *sph_body)
Expand Down Expand Up @@ -111,7 +113,7 @@ namespace SPH
//=================================================================================================//
UniquePtr<BaseLevelSet> SPHAdaptation::createLevelSet(Shape &shape)
{
return makeUnique<LevelSet>(shape.findBounds(), ReferenceSpacing(), shape, *this);
return makeUnique<LevelSet>(shape.findBounds(), ReferenceSpacing() / level_set_refinement_ratio_, shape, *this);
}
//=================================================================================================//
ParticleWithLocalRefinement::
Expand All @@ -136,7 +138,7 @@ namespace SPH
void ParticleWithLocalRefinement::assignBaseParticles(BaseParticles *base_particles)
{
SPHAdaptation::assignBaseParticles(base_particles);
base_particles->registerAVariable<indexScalar, Real>(h_ratio_, "SmoothingLengthRatio", 1.0);
base_particles->registerAVariable<Real>(h_ratio_, "SmoothingLengthRatio", 1.0);
}
//=================================================================================================//
UniquePtr<BaseCellLinkedList> ParticleWithLocalRefinement::createCellLinkedList()
Expand Down
5 changes: 4 additions & 1 deletion SPHINXsys/src/shared/adaptations/adaptation.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ namespace SPH
BaseParticles *base_particles_;

Real small_shift_factor_; /**< small shift for level generation. TODO: this should be clarified for its usage. */
Real level_set_refinement_ratio_;/**< ratio of level set resolution to system resolution, set to 1.0 by default. */

public:
SPHAdaptation(Real h_spacing_ratio = 1.3, Real system_resolution_ratio = 1.0, Real small_shift_factor = 0.75);
SPHAdaptation(Real h_spacing_ratio = 1.3, Real system_resolution_ratio = 1.0,
Real small_shift_factor = 0.75, Real level_set_refinement_ratio = 1.0);
virtual ~SPHAdaptation(){};
/** Note: called after construction of this and derived classes. */
virtual void initialize(SPHBody *sph_body);
Expand Down Expand Up @@ -137,6 +139,7 @@ namespace SPH
virtual UniquePtr<BaseCellLinkedList> createCellLinkedList() override;
virtual UniquePtr<BaseLevelSet> createLevelSet(Shape &shape) override;
};

/**
* @class ParticleSpacingByBodyShape
* @brief Adaptive resolutions within a SPH body according to the distance to the body surface.
Expand Down
2 changes: 1 addition & 1 deletion SPHINXsys/src/shared/bodies/body_relation.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace SPH
SearchDepthVariableSmoothingLength(SPHBody &sph_body, CellLinkedList *target_cell_linked_list)
: inv_grid_spacing_(1.0 / target_cell_linked_list->GridSpacing()),
kernel_(sph_body.sph_adaptation_->getKernel()),
h_ratio_(*sph_body.base_particles_->getVariableByName<indexScalar, Real>("SmoothingLengthRatio")){};
h_ratio_(*sph_body.base_particles_->getVariableByName<Real>("SmoothingLengthRatio")){};
int operator()(size_t particle_index) const
{
return 1 + (int)floor(kernel_->CutOffRadius(h_ratio_[particle_index]) * inv_grid_spacing_);
Expand Down
Loading