Loading...
Searching...
No Matches
ParticleSystemSolver2.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_PARTICLE_SYSTEM_SOLVER2_HPP
12#define CUBBYFLOW_PARTICLE_SYSTEM_SOLVER2_HPP
13
21
22namespace CubbyFlow
23{
37{
38 public:
39 class Builder;
40
43
45 ParticleSystemSolver2(double radius, double mass);
46
49
52
55
58
61
64
74
77
88
91
94
104
107
110
113
116
119
129
132
133 protected:
136
139
142
145
148
151
156
159
160 private:
161 void BeginAdvanceTimeStep(double timeStepInSeconds);
162
163 void EndAdvanceTimeStep(double timeStepInSeconds);
164
165 void AccumulateExternalForces();
166
167 void TimeIntegration(double timeStepInSeconds);
168
169 void UpdateCollider(double timeStepInSeconds) const;
170
171 void UpdateEmitter(double timeStepInSeconds) const;
172
173 double m_dragCoefficient = 1e-4;
174 double m_restitutionCoefficient = 0.0;
175 Vector2D m_gravity = Vector2D{ 0.0, GRAVITY };
176
177 ParticleSystemData2Ptr m_particleSystemData;
178 ParticleSystemData2::VectorData m_newPositions;
179 ParticleSystemData2::VectorData m_newVelocities;
180 Collider2Ptr m_collider;
181 ParticleEmitter2Ptr m_emitter;
182 VectorField2Ptr m_wind;
183};
184
186using ParticleSystemSolver2Ptr = std::shared_ptr<ParticleSystemSolver2>;
187
191template <typename DerivedBuilder>
193{
194 public:
197
200
201 protected:
202 double m_radius = 1e-3;
203 double m_mass = 1e-3;
204};
205
206template <typename T>
208{
209 m_radius = radius;
210 return static_cast<T&>(*this);
211}
212
213template <typename T>
215{
216 m_mass = mass;
217 return static_cast<T&>(*this);
218}
219
233} // namespace CubbyFlow
234
235#endif
Generic N-dimensional array class interface.
Definition ArrayView.hpp:26
Definition Matrix.hpp:30
Front-end to create ParticleSystemSolver2 objects step by step.
Definition ParticleSystemSolver2.hpp:225
ParticleSystemSolver2Ptr MakeShared() const
Builds shared pointer of ParticleSystemSolver2 instance.
ParticleSystemSolver2 Build() const
Builds ParticleSystemSolver2.
Basic 2-D particle system solver.
Definition ParticleSystemSolver2.hpp:37
static Builder GetBuilder()
Returns builder fox ParticleSystemSolver2.
void SetWind(const VectorField2Ptr &newWind)
Sets the wind.
virtual void AccumulateForces(double timeStepInSeconds)
Accumulates forces applied to the particles.
void SetParticleSystemData(const ParticleSystemData2Ptr &newParticles)
Assign a new particle system data.
void SetEmitter(const ParticleEmitter2Ptr &newEmitter)
Sets the emitter.
void OnInitialize() override
Initializes the simulator.
ParticleSystemSolver2(double radius, double mass)
Constructs a solver with particle parameters.
ParticleSystemSolver2()
Constructs an empty solver.
ParticleSystemSolver2(ParticleSystemSolver2 &&) noexcept=delete
Deleted move constructor.
const ParticleEmitter2Ptr & GetEmitter() const
Returns the emitter.
const Vector2D & GetGravity() const
Returns the gravity.
double GetDragCoefficient() const
Returns the drag coefficient.
const Collider2Ptr & GetCollider() const
Returns the collider.
virtual void OnBeginAdvanceTimeStep(double timeStepInSeconds)
Called when a time-step is about to begin.
virtual void OnEndAdvanceTimeStep(double timeStepInSeconds)
Called after a time-step is completed.
double GetRestitutionCoefficient() const
Gets the restitution coefficient.
void SetDragCoefficient(double newDragCoefficient)
Sets the drag coefficient.
void SetCollider(const Collider2Ptr &newCollider)
Sets the collider.
const VectorField2Ptr & GetWind() const
Returns the wind field.
void ResolveCollision()
Resolves any collisions occurred by the particles.
void SetRestitutionCoefficient(double newRestitutionCoefficient)
Sets the restitution coefficient.
void SetGravity(const Vector2D &newGravity)
Sets the gravity.
void OnAdvanceTimeStep(double timeStepInSeconds) override
Called to advance a single time-step.
ParticleSystemSolver2(const ParticleSystemSolver2 &)=delete
Deleted copy constructor.
const ParticleSystemData2Ptr & GetParticleSystemData() const
Returns the particle system data.
Base class for particle-based solver builder.
Definition ParticleSystemSolver2.hpp:193
DerivedBuilder & WithRadius(double radius)
Returns builder with particle radius.
Definition ParticleSystemSolver2.hpp:207
double m_radius
Definition ParticleSystemSolver2.hpp:202
DerivedBuilder & WithMass(double mass)
Returns builder with mass per particle.
Definition ParticleSystemSolver2.hpp:214
double m_mass
Definition ParticleSystemSolver2.hpp:203
Abstract base class for physics-based animation.
Definition PhysicsAnimation.hpp:25
Definition pybind11Utils.hpp:21
constexpr double GRAVITY
Definition Constants.hpp:299
std::shared_ptr< ParticleSystemSolver2 > ParticleSystemSolver2Ptr
Shared pointer type for the ParticleSystemSolver2.
Definition ParticleSystemSolver2.hpp:186
std::shared_ptr< Collider2 > Collider2Ptr
Shared pointer type for the Collider2.
Definition Collider.hpp:141
std::shared_ptr< ParticleEmitter2 > ParticleEmitter2Ptr
Shared pointer for the ParticleEmitter2 type.
Definition ParticleEmitter2.hpp:94
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition ParticleSystemData.hpp:281
std::shared_ptr< VectorField2 > VectorField2Ptr
Shared pointer for the VectorField2 type.
Definition VectorField.hpp:87