Go to the documentation of this file.
7 #ifndef INCLUDE_JET_GRID_FLUID_SOLVER2_H_
8 #define INCLUDE_JET_GRID_FLUID_SOLVER2_H_
73 double cfl(
double timeIntervalInSeconds)
const;
205 double timeIntervalInSeconds)
const override;
270 double _viscosityCoefficient = 0.0;
271 double _maxCfl = 5.0;
272 bool _useCompressedLinearSys =
false;
284 void beginAdvanceTimeStep(
double timeIntervalInSeconds);
286 void endAdvanceTimeStep(
double timeIntervalInSeconds);
288 void updateCollider(
double timeIntervalInSeconds);
290 void updateEmitter(
double timeIntervalInSeconds);
299 template <
typename DerivedBuilder>
332 template <
typename T>
334 _resolution = resolution;
335 return static_cast<T&
>(*this);
338 template <
typename T>
341 _gridSpacing = gridSpacing;
342 _useDomainSize =
false;
343 return static_cast<T&
>(*this);
346 template <
typename T>
348 _gridSpacing.x = gridSpacing;
349 _gridSpacing.y = gridSpacing;
350 _useDomainSize =
false;
351 return static_cast<T&
>(*this);
354 template <
typename T>
356 _domainSizeX = domainSizeX;
357 _useDomainSize =
true;
358 return static_cast<T&
>(*this);
361 template <
typename T>
363 _gridOrigin = gridOrigin;
364 return static_cast<T&
>(*this);
367 template <
typename T>
369 Vector2D gridSpacing = _gridSpacing;
370 if (_useDomainSize) {
371 gridSpacing.
set(_domainSizeX /
static_cast<double>(_resolution.x));
394 #endif // INCLUDE_JET_GRID_FLUID_SOLVER2_H_
double cfl(double timeIntervalInSeconds) const
Returns the CFL number from the current velocity field for given time interval.
unsigned int numberOfSubTimeSteps(double timeIntervalInSeconds) const override
Returns the required sub-time-steps for given time interval.
void extrapolateIntoCollider(FaceCenteredGrid2 *grid)
Extrapolates given field into the collider-occupied region.
const FaceCenteredGrid2Ptr & velocity() const
Returns the velocity field.
const AdvectionSolver2Ptr & advectionSolver() const
Returns the advection solver instance.
void setGravity(const Vector2D &newGravity)
Sets the gravity of the system.
void setAdvectionSolver(const AdvectionSolver2Ptr &newSolver)
Sets the advection solver.
double maxCfl() const
Returns the max allowed CFL number.
DerivedBuilder & withOrigin(const Vector2D &gridOrigin)
Returns builder with grid origin.
Definition: grid_fluid_solver2.h:362
Vector2D gridSpacing() const
Returns the grid spacing of the grid system data.
void setDiffusionSolver(const GridDiffusionSolver2Ptr &newSolver)
Sets the diffusion solver.
Vector2D getGridSpacing() const
Definition: grid_fluid_solver2.h:368
Vector2< double > Vector2D
Double-type 2D vector.
Definition: vector2.h:340
std::shared_ptr< GridDiffusionSolver2 > GridDiffusionSolver2Ptr
Shared pointer type for the GridDiffusionSolver2.
Definition: grid_diffusion_solver2.h:93
Abstract base class for physics-based animation.
Definition: physics_animation.h:20
void setViscosityCoefficient(double newValue)
Sets the viscosity coefficient.
void setUseCompressedLinearSystem(bool onoff)
Sets whether the solver should use compressed linear system.
bool useCompressedLinearSystem() const
Returns true if the solver is using compressed linear system.
DerivedBuilder & withResolution(const Size2 &resolution)
Returns builder with grid resolution.
Definition: grid_fluid_solver2.h:333
Vector2D gridOrigin() const
Returns the origin of the grid system data.
virtual ~GridFluidSolver2()
Default destructor.
void extrapolateIntoCollider(ScalarGrid2 *grid)
Extrapolates given field into the collider-occupied region.
std::shared_ptr< GridSystemData2 > GridSystemData2Ptr
Shared pointer type of GridSystemData2.
Definition: grid_system_data2.h:237
static Builder builder()
Returns builder fox GridFluidSolver2.
const GridEmitter2Ptr & emitter() const
Returns the emitter.
Abstract base class for grid-based 2-D fluid solver.
Definition: grid_fluid_solver2.h:34
double viscosityCoefficient() const
Returns the viscosity coefficient.
void onAdvanceTimeStep(double timeIntervalInSeconds) override
Called when advancing a single time-step.
DerivedBuilder & withGridSpacing(double gridSpacing)
Returns builder with grid spacing.
Definition: grid_fluid_solver2.h:347
GridFluidSolver2()
Default constructor.
constexpr int kDirectionAll
All direction.
Definition: constants.h:333
2-D face-centered (a.k.a MAC or staggered) grid.
Definition: face_centered_grid2.h:26
ScalarField2Ptr colliderSdf() const
Returns the signed-distance field representation of the collider.
std::shared_ptr< GridFluidSolver2 > GridFluidSolver2Ptr
Shared pointer type for the GridFluidSolver2.
Definition: grid_fluid_solver2.h:294
virtual void computeViscosity(double timeIntervalInSeconds)
Computes the viscosity term using the diffusion solver.
const Collider2Ptr & collider() const
Returns the collider.
Definition: advection_solver2.h:18
std::shared_ptr< ScalarField2 > ScalarField2Ptr
Shared pointer for the ScalarField2 type.
Definition: scalar_field2.h:40
Size2 _resolution
Definition: grid_fluid_solver2.h:323
void resizeGrid(const Size2 &newSize, const Vector2D &newGridSpacing, const Vector2D &newGridOrigin)
Resizes grid system data.
virtual void onEndAdvanceTimeStep(double timeIntervalInSeconds)
Called at the end of a time-step.
Abstract base class for 2-D scalar grid structure.
Definition: scalar_grid2.h:21
void setMaxCfl(double newCfl)
Sets the max allowed CFL number.
double _domainSizeX
Definition: grid_fluid_solver2.h:326
2-D vector class.
Definition: vector2.h:24
std::shared_ptr< AdvectionSolver2 > AdvectionSolver2Ptr
Shared pointer type for the 2-D advection solver.
Definition: advection_solver2.h:113
const GridDiffusionSolver2Ptr & diffusionSolver() const
Returns the diffusion solver instance.
GridFluidSolver2 build() const
Builds GridFluidSolver2.
virtual void onBeginAdvanceTimeStep(double timeIntervalInSeconds)
Called at the beginning of a time-step.
GridFluidSolver2(const Size2 &resolution, const Vector2D &gridSpacing, const Vector2D &gridOrigin)
Constructs solver with initial grid size.
DerivedBuilder & withDomainSizeX(double domainSizeX)
Returns builder with domain size in x-direction.
Definition: grid_fluid_solver2.h:355
std::shared_ptr< Collider2 > Collider2Ptr
Shared pointer type for the Collider2.
Definition: collider2.h:118
std::shared_ptr< FaceCenteredGrid2 > FaceCenteredGrid2Ptr
Shared pointer type for the FaceCenteredGrid2.
Definition: face_centered_grid2.h:230
Abstract base class for 2-D collocated vector grid structure.
Definition: collocated_vector_grid2.h:18
void setPressureSolver(const GridPressureSolver2Ptr &newSolver)
Sets the pressure solver.
void set(T s)
Set both x and y components to s.
GridFluidSolver2Ptr makeShared() const
Builds shared pointer of GridFluidSolver2 instance.
Definition: grid_fluid_solver2.h:386
2-D size class.
Definition: size2.h:19
int closedDomainBoundaryFlag() const
Returns the closed domain boundary flag.
virtual ScalarField2Ptr fluidSdf() const
std::shared_ptr< VectorField2 > VectorField2Ptr
Shared pointer for the VectorField2 type.
Definition: vector_field2.h:40
const Vector2D & gravity() const
Returns the gravity vector of the system.
void setEmitter(const GridEmitter2Ptr &newEmitter)
Sets the emitter.
void setCollider(const Collider2Ptr &newCollider)
Sets the collider.
DerivedBuilder & withGridSpacing(const Vector2D &gridSpacing)
Returns builder with grid spacing.
Definition: grid_fluid_solver2.h:339
std::shared_ptr< GridPressureSolver2 > GridPressureSolver2Ptr
Shared pointer type for the GridPressureSolver2.
Definition: grid_pressure_solver2.h:78
void applyBoundaryCondition()
Applies the boundary condition to the velocity field.
bool _useDomainSize
Definition: grid_fluid_solver2.h:327
void extrapolateIntoCollider(CollocatedVectorGrid2 *grid)
Extrapolates given field into the collider-occupied region.
virtual void computePressure(double timeIntervalInSeconds)
Computes the pressure term using the pressure solver.
std::shared_ptr< GridBoundaryConditionSolver2 > GridBoundaryConditionSolver2Ptr
Shared pointer type for the GridBoundaryConditionSolver2.
Definition: grid_boundary_condition_solver2.h:104
void computeGravity(double timeIntervalInSeconds)
Computes the gravity term.
std::shared_ptr< GridEmitter2 > GridEmitter2Ptr
Shared pointer type for the GridEmitter2.
Definition: grid_emitter2.h:70
void onInitialize() override
Called when it needs to setup initial condition.
void setClosedDomainBoundaryFlag(int flag)
Sets the closed domain boundary flag.
VectorField2Ptr colliderVelocityField() const
Returns the velocity field of the collider.
Vector2D _gridOrigin
Definition: grid_fluid_solver2.h:325
Size2 resolution() const
Returns the resolution of the grid system data.
Vector2D _gridSpacing
Definition: grid_fluid_solver2.h:324
Base class for grid-based fluid solver builder.
Definition: grid_fluid_solver2.h:300
Front-end to create GridFluidSolver2 objects step by step.
Definition: grid_fluid_solver2.h:380
virtual void computeExternalForces(double timeIntervalInSeconds)
Computes the external force terms.
const GridPressureSolver2Ptr & pressureSolver() const
Returns the pressure solver instance.
const GridSystemData2Ptr & gridSystemData() const
Returns the grid system data.
virtual void computeAdvection(double timeIntervalInSeconds)
Computes the advection term using the advection solver.