PICSolver2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: PICSolver2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D Particle-in-Cell (PIC) implementation.
6 > Created Time: 2017/09/12
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_PIC_SOLVER2_H
10 #define CUBBYFLOW_PIC_SOLVER2_H
11 
15 
16 namespace CubbyFlow
17 {
29  {
30  public:
31  class Builder;
32 
34  PICSolver2();
35 
37  PICSolver2(
38  const Size2& resolution,
39  const Vector2D& gridSpacing,
40  const Vector2D& gridOrigin);
41 
43  virtual ~PICSolver2();
44 
47 
50 
53 
55  void SetParticleEmitter(const ParticleEmitter2Ptr& newEmitter);
56 
58  static Builder GetBuilder();
59 
60  protected:
63 
65  void OnInitialize() override;
66 
68  void OnBeginAdvanceTimeStep(double timeIntervalInSeconds) override;
69 
71  void ComputeAdvection(double timeIntervalInSeconds) override;
72 
74  ScalarField2Ptr GetFluidSDF() const override;
75 
77  virtual void TransferFromParticlesToGrids();
78 
80  virtual void TransferFromGridsToParticles();
81 
83  virtual void MoveParticles(double timeIntervalInSeconds);
84 
85  private:
86  size_t m_signedDistanceFieldID;
87  ParticleSystemData2Ptr m_particles;
88  ParticleEmitter2Ptr m_particleEmitter;
89 
90  void ExtrapolateVelocityToAir() const;
91 
92  void BuildSignedDistanceField();
93 
94  void UpdateParticleEmitter(double timeIntervalInSeconds) const;
95  };
96 
98  using PICSolver2Ptr = std::shared_ptr<PICSolver2>;
99 
103  class PICSolver2::Builder final : public GridFluidSolverBuilderBase2<PICSolver2::Builder>
104  {
105  public:
107  PICSolver2 Build() const;
108 
110  PICSolver2Ptr MakeShared() const;
111  };
112 }
113 
114 #endif
PICSolver2Ptr MakeShared() const
Builds shared pointer of PicSolver2 instance.
2-D Particle-in-Cell (PIC) implementation.
Definition: PICSolver2.h:28
static Builder GetBuilder()
Returns builder fox PICSolver2.
Base class for grid-based fluid solver builder.
Definition: GridFluidSolver2.h:303
std::shared_ptr< ParticleEmitter2 > ParticleEmitter2Ptr
Shared pointer for the ParticleEmitter2 type.
Definition: ParticleEmitter2.h:71
Front-end to create PICSolver2 objects step by step.
Definition: PICSolver2.h:103
virtual void MoveParticles(double timeIntervalInSeconds)
Moves particles.
Array2< char > m_vMarkers
Definition: PICSolver2.h:62
2-D point class.
Definition: Point2.h:25
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: ScalarField2.h:44
virtual ~PICSolver2()
Default destructor.
const ParticleEmitter2Ptr & GetParticleEmitter() const
Returns the particle emitter.
PICSolver2 Build() const
Builds PICSolver2.
Array2< char > m_uMarkers
Definition: PICSolver2.h:61
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition: ParticleSystemData2.h:250
Definition: pybind11Utils.h:24
virtual void TransferFromGridsToParticles()
Transfers velocity field from grids to particles.
std::shared_ptr< ScalarGrid2 > ScalarGrid2Ptr
Shared pointer for the ScalarGrid2 type.
Definition: ScalarGrid2.h:179
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.h:98
Abstract base class for grid-based 2-D fluid solver.
Definition: GridFluidSolver2.h:33
2-D vector class.
Definition: Vector2.h:26
void OnInitialize() override
Initializes the simulator.
2-D array class.
Definition: Array2.h:42
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.