PICSolver2.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_PIC_SOLVER2_HPP
12 #define CUBBYFLOW_PIC_SOLVER2_HPP
13 
17 
18 namespace CubbyFlow
19 {
31 {
32  public:
33  class Builder;
34 
36  PICSolver2();
37 
39  PICSolver2(const Vector2UZ& resolution, const Vector2D& gridSpacing,
40  const Vector2D& gridOrigin);
41 
43  PICSolver2(const PICSolver2&) = delete;
44 
46  PICSolver2(PICSolver2&&) noexcept = delete;
47 
49  ~PICSolver2() override = default;
50 
52  PICSolver2& operator=(const PICSolver2&) = delete;
53 
55  PICSolver2& operator=(PICSolver2&&) noexcept = delete;
56 
58  [[nodiscard]] ScalarGrid2Ptr GetSignedDistanceField() const;
59 
61  [[nodiscard]] const ParticleSystemData2Ptr& GetParticleSystemData() const;
62 
64  [[nodiscard]] const ParticleEmitter2Ptr& GetParticleEmitter() const;
65 
67  void SetParticleEmitter(const ParticleEmitter2Ptr& newEmitter);
68 
70  [[nodiscard]] static Builder GetBuilder();
71 
72  protected:
74  void OnInitialize() override;
75 
77  void OnBeginAdvanceTimeStep(double timeIntervalInSeconds) override;
78 
80  void ComputeAdvection(double timeIntervalInSeconds) override;
81 
83  [[nodiscard]] ScalarField2Ptr GetFluidSDF() const override;
84 
86  virtual void TransferFromParticlesToGrids();
87 
89  virtual void TransferFromGridsToParticles();
90 
92  virtual void MoveParticles(double timeIntervalInSeconds);
93 
96 
97  private:
98  void ExtrapolateVelocityToAir();
99 
100  void BuildSignedDistanceField();
101 
102  void UpdateParticleEmitter(double timeIntervalInSeconds) const;
103 
104  size_t m_signedDistanceFieldID;
105  ParticleSystemData2Ptr m_particles;
106  ParticleEmitter2Ptr m_particleEmitter;
107 };
108 
110 using PICSolver2Ptr = std::shared_ptr<PICSolver2>;
111 
116 {
117  public:
119  [[nodiscard]] PICSolver2 Build() const;
120 
122  [[nodiscard]] PICSolver2Ptr MakeShared() const;
123 };
124 } // namespace CubbyFlow
125 
126 #endif
2-D Particle-in-Cell (PIC) implementation.
Definition: PICSolver2.hpp:30
static Builder GetBuilder()
Returns builder fox PICSolver2.
Base class for grid-based fluid solver builder.
Definition: GridFluidSolver2.hpp:315
std::shared_ptr< ParticleEmitter2 > ParticleEmitter2Ptr
Shared pointer for the ParticleEmitter2 type.
Definition: ParticleEmitter2.hpp:94
Front-end to create PICSolver2 objects step by step.
Definition: PICSolver2.hpp:115
virtual void MoveParticles(double timeIntervalInSeconds)
Moves particles.
Array2< char > m_vMarkers
Definition: PICSolver2.hpp:95
PICSolver2()
Default constructor.
void ComputeAdvection(double timeIntervalInSeconds) override
Computes the advection term of the fluid solver.
std::shared_ptr< ScalarField2 > ScalarField2Ptr
Shared pointer for the ScalarField2 type.
Definition: ScalarField.hpp:67
const ParticleEmitter2Ptr & GetParticleEmitter() const
Returns the particle emitter.
Array2< char > m_uMarkers
Definition: PICSolver2.hpp:94
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition: ParticleSystemData.hpp:281
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
virtual void TransferFromGridsToParticles()
Transfers velocity field from grids to particles.
Definition: Array-Impl.hpp:19
std::shared_ptr< ScalarGrid2 > ScalarGrid2Ptr
Shared pointer for the ScalarGrid2 type.
Definition: ScalarGrid.hpp:266
PICSolver2 & operator=(const PICSolver2 &)=delete
Deleted copy assignment operator.
ScalarField2Ptr GetFluidSDF() const override
Returns the signed-distance field of the fluid.
void SetParticleEmitter(const ParticleEmitter2Ptr &newEmitter)
Sets the particle emitter.
const ParticleSystemData2Ptr & GetParticleSystemData() const
Returns the particle system data.
std::shared_ptr< PICSolver2 > PICSolver2Ptr
Shared pointer type for the PICSolver2.
Definition: PICSolver2.hpp:110
Abstract base class for grid-based 2-D fluid solver.
Definition: GridFluidSolver2.hpp:35
void OnInitialize() override
Initializes the simulator.
~PICSolver2() override=default
Default virtual destructor.
ScalarGrid2Ptr GetSignedDistanceField() const
Returns the signed-distance field of particles.
void OnBeginAdvanceTimeStep(double timeIntervalInSeconds) override
Invoked before a simulation time-step begins.
virtual void TransferFromParticlesToGrids()
Transfers velocity field from particles to grids.