PICSolver3.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_SOLVER3_HPP
12 #define CUBBYFLOW_PIC_SOLVER3_HPP
13 
17 
18 namespace CubbyFlow
19 {
31 {
32  public:
33  class Builder;
34 
36  PICSolver3();
37 
39  PICSolver3(const Vector3UZ& resolution, const Vector3D& gridSpacing,
40  const Vector3D& gridOrigin);
41 
43  PICSolver3(const PICSolver3&) = delete;
44 
46  PICSolver3(PICSolver3&&) noexcept = delete;
47 
49  ~PICSolver3() override = default;
50 
52  PICSolver3& operator=(const PICSolver3&) = delete;
53 
55  PICSolver3& operator=(PICSolver3&&) noexcept = delete;
56 
58  [[nodiscard]] ScalarGrid3Ptr GetSignedDistanceField() const;
59 
61  [[nodiscard]] const ParticleSystemData3Ptr& GetParticleSystemData() const;
62 
64  [[nodiscard]] const ParticleEmitter3Ptr& GetParticleEmitter() const;
65 
67  void SetParticleEmitter(const ParticleEmitter3Ptr& 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]] ScalarField3Ptr GetFluidSDF() const override;
84 
86  virtual void TransferFromParticlesToGrids();
87 
89  virtual void TransferFromGridsToParticles();
90 
92  virtual void MoveParticles(double timeIntervalInSeconds);
93 
97 
98  private:
99  void ExtrapolateVelocityToAir();
100 
101  void BuildSignedDistanceField();
102 
103  void UpdateParticleEmitter(double timeIntervalInSeconds) const;
104 
105  size_t m_signedDistanceFieldID;
106  ParticleSystemData3Ptr m_particles;
107  ParticleEmitter3Ptr m_particleEmitter;
108 };
109 
111 using PICSolver3Ptr = std::shared_ptr<PICSolver3>;
112 
117 {
118  public:
120  [[nodiscard]] PICSolver3 Build() const;
121 
123  [[nodiscard]] PICSolver3Ptr MakeShared() const;
124 };
125 } // namespace CubbyFlow
126 
127 #endif
void OnBeginAdvanceTimeStep(double timeIntervalInSeconds) override
Invoked before a simulation time-step begins.
Array3< char > m_vMarkers
Definition: PICSolver3.hpp:95
std::shared_ptr< ParticleEmitter3 > ParticleEmitter3Ptr
Shared pointer for the ParticleEmitter3 type.
Definition: ParticleEmitter3.hpp:94
virtual void MoveParticles(double timeIntervalInSeconds)
Moves particles.
std::shared_ptr< ScalarField3 > ScalarField3Ptr
Shared pointer for the ScalarField3 type.
Definition: ScalarField.hpp:70
std::shared_ptr< ParticleSystemData3 > ParticleSystemData3Ptr
Shared pointer type of ParticleSystemData3.
Definition: ParticleSystemData.hpp:284
void OnInitialize() override
Initializes the simulator.
3-D Particle-in-Cell (PIC) implementation.
Definition: PICSolver3.hpp:30
virtual void TransferFromGridsToParticles()
Transfers velocity field from grids to particles.
std::shared_ptr< ScalarGrid3 > ScalarGrid3Ptr
Shared pointer for the ScalarGrid3 type.
Definition: ScalarGrid.hpp:269
Base class for grid-based fluid solver builder.
Definition: GridFluidSolver3.hpp:315
Front-end to create PICSolver3 objects step by step.
Definition: PICSolver3.hpp:116
PICSolver3()
Default constructor.
Definition: Matrix.hpp:27
~PICSolver3() override=default
Default virtual destructor.
PICSolver3 & operator=(const PICSolver3 &)=delete
Deleted copy assignment operator.
Definition: pybind11Utils.hpp:20
Abstract base class for grid-based 3-D fluid solver.
Definition: GridFluidSolver3.hpp:35
Definition: Array-Impl.hpp:19
Array3< char > m_uMarkers
Definition: PICSolver3.hpp:94
virtual void TransferFromParticlesToGrids()
Transfers velocity field from particles to grids.
std::shared_ptr< PICSolver3 > PICSolver3Ptr
Shared pointer type for the PICSolver3.
Definition: PICSolver3.hpp:111
ScalarGrid3Ptr GetSignedDistanceField() const
Returns the signed-distance field of particles.
const ParticleEmitter3Ptr & GetParticleEmitter() const
Returns the particle emitter.
const ParticleSystemData3Ptr & GetParticleSystemData() const
Returns the particle system data.
Array3< char > m_wMarkers
Definition: PICSolver3.hpp:96
ScalarField3Ptr GetFluidSDF() const override
Returns the signed-distance field of the fluid.
static Builder GetBuilder()
Returns builder fox PICSolver3.
void SetParticleEmitter(const ParticleEmitter3Ptr &newEmitter)
Sets the particle emitter.
void ComputeAdvection(double timeIntervalInSeconds) override
Computes the advection term of the fluid solver.