17 std::unique_ptr<PressureCalculator::Interface>&& pressureCalculator,
18 std::unique_ptr<SurfaceDetector::Interface>&& surfaceDetector
45 particle.pressure = pressures[particle.id];
54 auto pressures = explicitPressureCalculator->calc(
particles);
56 particle.pressure = pressures[particle.id];
64#pragma omp parallel for
70 p.acceleration.setZero();
80#pragma omp parallel for
85 Eigen::Vector3d viscosityTerm = Eigen::Vector3d::Zero();
87 for (
auto& neighbor : pi.neighbors) {
91 double w =
weight(neighbor.distance, re);
92 viscosityTerm += (pj.velocity - pi.velocity) * w;
97 pi.acceleration += viscosityTerm;
102#pragma omp parallel for
108 p.acceleration.setZero();
117 for (
auto& neighbor : pi.neighbors) {
124 double invMi = pi.inverseDensity();
126 double mass = 1.0 / (invMi + invMj);
128 Eigen::Vector3d normal = (pj.
position - pi.position).normalized();
129 double relVel = (pj.
velocity - pi.velocity).dot(normal);
130 double impulse = 0.0;
133 pi.velocity -= impulse * invMi * normal;
134 pj.
velocity += impulse * invMj * normal;
137 double positionImpulse = depth * mass;
138 pi.position -= positionImpulse * invMi * normal;
139 pj.
position += positionImpulse * invMj * normal;
149#pragma omp parallel for
151 pi.numberDensity = 0.0;
156 for (
auto& neighbor : pi.neighbors)
157 pi.numberDensity +=
weight(neighbor.distance, re);
162#pragma omp parallel for
178#pragma omp parallel for
180 p.minimumPressure = p.pressure;
187 for (
auto& neighbor : pi.neighbors) {
194 if (neighbor.distance < re) {
195 pi.minimumPressure = std::min(pi.minimumPressure, pj.
pressure);
205#pragma omp parallel for
210 Eigen::Vector3d grad = Eigen::Vector3d::Zero();
211 for (
auto& neighbor : pi.neighbors) {
216 if (neighbor.distance < re) {
217 double w =
weight(neighbor.distance, re);
219 double dist2 = (pj.
position - pi.position).squaredNorm();
220 double pij = (pj.
pressure - pi.minimumPressure) / dist2;
221 grad += (pj.
position - pi.position) * pij * w;
225 pi.acceleration -= grad / pi.density;
230#pragma omp parallel for
237 p.acceleration.setZero();
253 cerr <<
"ERROR: Courant number is larger than CFL condition. Courant = " <<
courant << endl;
void setMinimumPressure(const double &re)
set minimum pressure for pressure gradient calculation
void calViscosity(const double &re)
calculate viscosity term of Navier-Stokes equation
std::unique_ptr< PressureCalculator::Interface > pressureCalculator
Interface for pressure calculation.
void moveParticleUsingPressureGradient()
move particles in correction step
Settings settings
Settings for the simulation.
double courant
Maximum courant number among all particles.
void calPressureGradient(const double &re)
calculate pressure gradient term
RefValues refValuesForLaplacian
Reference values for the simulation ( , )
void moveParticle()
move particles in prediction step
void setBoundaryCondition()
set boundary condition of pressure Poisson equation
RefValues refValuesForNumberDensity
Reference values for the simulation ( , )
void calCourant()
calculate Courant number
void collision()
calculate collision between particles when they are too close
NeighborSearcher neighborSearcher
Neighbor searcher for neighbor search.
std::unique_ptr< SurfaceDetector::Interface > surfaceDetector
Interface for free surface detection.
void calNumberDensity(const double &re)
calculate number density of each particle
RefValues refValuesForGradient
Reference values for the simulation ( , )
void calGravity()
calculate gravity term
Particles particles
Particles in the simulation.
Domain domain
Domain of the simulation.
void setNeighbors(Particles &particles)
Class for particle in MPS method.
double inverseDensity() const
calculate inverse of density for collision
Eigen::Vector3d position
position of the particle
double pressure
pressure of the particle
int id
index of the particle
double minimumPressure
minimum pressure of the particle
Eigen::Vector3d velocity
velocity of the particle
ParticleType type
type of the particle
int size() const
Get the number of particles.
Class for explicit pressure calculation.
Struct for reference values of MPS method.
double n0
reference value of number density for source term of pressure Poisson equation
double lambda
coefficient for laplacian
@ Inner
inner fluid particle
@ FreeSurface
free surface particle
@ Ghost
Ghost particle (outside of the domain, not used for calculation)
@ DummyWall
Dummy wall particle (pressure is not calculated)
Eigen::Vector3d gravity
Gravity.
double reMax
Maximum of effective radius.
double collisionDistance
Distance for collision detection.
double particleDistance
Initial distance between particles.
int dim
Dimension of the simulation.
double re_forNumberDensity
Effective radius for number density.
double kinematicViscosity
Kinematic viscosity.
double cflCondition
CFL condition.
double coefficientOfRestitution
Coefficient of restitution.
double re_forGradient
Effective radius for gradient.
Domain domain
domain of the simulation
double re_forLaplacian
Effective radius for Laplacian.
double weight(double dis, double re)
Wight function for MPS method presented by Koshizuka and Oka, 1996