Go to the documentation of this file.
7 #ifndef INCLUDE_JET_GRID_FLUID_SOLVER3_H_
8 #define INCLUDE_JET_GRID_FLUID_SOLVER3_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 _gridSpacing.z = gridSpacing;
351 _useDomainSize =
false;
352 return static_cast<T&
>(*this);
355 template <
typename T>
357 _domainSizeX = domainSizeX;
358 _useDomainSize =
true;
359 return static_cast<T&
>(*this);
362 template <
typename T>
364 _gridOrigin = gridOrigin;
365 return static_cast<T&
>(*this);
368 template <
typename T>
370 Vector3D gridSpacing = _gridSpacing;
371 if (_useDomainSize) {
372 gridSpacing.
set(_domainSizeX /
static_cast<double>(_resolution.x));
395 #endif // INCLUDE_JET_GRID_FLUID_SOLVER3_H_
std::shared_ptr< FaceCenteredGrid3 > FaceCenteredGrid3Ptr
Shared pointer type for the FaceCenteredGrid3.
Definition: face_centered_grid3.h:285
void set(T s)
Set all x, y, and z components to s.
const AdvectionSolver3Ptr & advectionSolver() const
Returns the advection solver instance.
DerivedBuilder & withOrigin(const Vector3D &gridOrigin)
Returns builder with grid origin.
Definition: grid_fluid_solver3.h:363
GridFluidSolver3(const Size3 &resolution, const Vector3D &gridSpacing, const Vector3D &gridOrigin)
Constructs solver with initial grid size.
std::shared_ptr< GridPressureSolver3 > GridPressureSolver3Ptr
Shared pointer type for the GridPressureSolver3.
Definition: grid_pressure_solver3.h:78
std::shared_ptr< GridFluidSolver3 > GridFluidSolver3Ptr
Shared pointer type for the GridFluidSolver3.
Definition: grid_fluid_solver3.h:294
Size3 resolution() const
Returns the resolution of the grid system data.
virtual void computeViscosity(double timeIntervalInSeconds)
Computes the viscosity term using the diffusion solver.
DerivedBuilder & withResolution(const Size3 &resolution)
Returns builder with grid resolution.
Definition: grid_fluid_solver3.h:333
std::shared_ptr< AdvectionSolver3 > AdvectionSolver3Ptr
Shared pointer type for the 3-D advection solver.
Definition: advection_solver3.h:115
std::shared_ptr< GridDiffusionSolver3 > GridDiffusionSolver3Ptr
Shared pointer type for the GridDiffusionSolver3.
Definition: grid_diffusion_solver3.h:94
Abstract base class for physics-based animation.
Definition: physics_animation.h:20
virtual void computeExternalForces(double timeIntervalInSeconds)
Computes the external force terms.
Front-end to create GridFluidSolver3 objects step by step.
Definition: grid_fluid_solver3.h:381
const GridSystemData3Ptr & gridSystemData() const
Returns the grid system data.
void setCollider(const Collider3Ptr &newCollider)
Sets the collider.
void setClosedDomainBoundaryFlag(int flag)
Sets the closed domain boundary flag.
virtual void computePressure(double timeIntervalInSeconds)
Computes the pressure term using the pressure solver.
void setGravity(const Vector3D &newGravity)
Sets the gravity of the system.
virtual ~GridFluidSolver3()
Default destructor.
void setViscosityCoefficient(double newValue)
Sets the viscosity coefficient.
DerivedBuilder & withGridSpacing(double gridSpacing)
Returns builder with grid spacing.
Definition: grid_fluid_solver3.h:347
void applyBoundaryCondition()
Applies the boundary condition to the velocity field.
Size3 _resolution
Definition: grid_fluid_solver3.h:323
double viscosityCoefficient() const
Returns the viscosity coefficient.
void extrapolateIntoCollider(FaceCenteredGrid3 *grid)
Extrapolates given field into the collider-occupied region.
void extrapolateIntoCollider(CollocatedVectorGrid3 *grid)
Extrapolates given field into the collider-occupied region.
Abstract base class for 3-D collocated vector grid structure.
Definition: collocated_vector_grid3.h:18
constexpr int kDirectionAll
All direction.
Definition: constants.h:333
Vector3D _gridSpacing
Definition: grid_fluid_solver3.h:324
const Collider3Ptr & collider() const
Returns the collider.
void computeGravity(double timeIntervalInSeconds)
Computes the gravity term.
void setAdvectionSolver(const AdvectionSolver3Ptr &newSolver)
Sets the advection solver.
DerivedBuilder & withDomainSizeX(double domainSizeX)
Returns builder with domain size in x-direction.
Definition: grid_fluid_solver3.h:356
const GridEmitter3Ptr & emitter() const
Returns the emitter.
Definition: advection_solver2.h:18
const GridDiffusionSolver3Ptr & diffusionSolver() const
Returns the diffusion solver instance.
int closedDomainBoundaryFlag() const
Returns the closed domain boundary flag.
std::shared_ptr< GridSystemData3 > GridSystemData3Ptr
Shared pointer type of GridSystemData3.
Definition: grid_system_data3.h:237
Vector3D gridSpacing() const
Returns the grid spacing of the grid system data.
GridFluidSolver3()
Default constructor.
Base class for grid-based fluid solver builder.
Definition: grid_fluid_solver3.h:300
void setDiffusionSolver(const GridDiffusionSolver3Ptr &newSolver)
Sets the diffusion solver.
void setUseCompressedLinearSystem(bool onoff)
Sets whether the solver should use compressed linear system.
void resizeGrid(const Size3 &newSize, const Vector3D &newGridSpacing, const Vector3D &newGridOrigin)
Resizes grid system data.
ScalarField3Ptr colliderSdf() const
Returns the signed-distance field representation of the collider.
virtual void computeAdvection(double timeIntervalInSeconds)
Computes the advection term using the advection solver.
bool _useDomainSize
Definition: grid_fluid_solver3.h:327
3-D face-centered (a.k.a MAC or staggered) grid.
Definition: face_centered_grid3.h:26
static Builder builder()
Returns builder fox GridFluidSolver3.
std::shared_ptr< ScalarField3 > ScalarField3Ptr
Shared pointer for the ScalarField3 type.
Definition: scalar_field3.h:40
3-D size class.
Definition: size3.h:19
std::shared_ptr< GridBoundaryConditionSolver3 > GridBoundaryConditionSolver3Ptr
Shared pointer type for the GridBoundaryConditionSolver3.
Definition: grid_boundary_condition_solver3.h:104
void extrapolateIntoCollider(ScalarGrid3 *grid)
Extrapolates given field into the collider-occupied region.
Vector3D _gridOrigin
Definition: grid_fluid_solver3.h:325
Vector3D gridOrigin() const
Returns the origin of the grid system data.
void setMaxCfl(double newCfl)
Sets the max allowed CFL number.
double cfl(double timeIntervalInSeconds) const
Returns the CFL number from the current velocity field for given time interval.
virtual void onBeginAdvanceTimeStep(double timeIntervalInSeconds)
Called at the beginning of a time-step.
Vector3D getGridSpacing() const
Definition: grid_fluid_solver3.h:369
Abstract base class for grid-based 3-D fluid solver.
Definition: grid_fluid_solver3.h:34
GridFluidSolver3Ptr makeShared() const
Builds shared pointer of GridFluidSolver3 instance.
Definition: grid_fluid_solver3.h:387
GridFluidSolver3 build() const
Builds GridFluidSolver3.
double _domainSizeX
Definition: grid_fluid_solver3.h:326
void onAdvanceTimeStep(double timeIntervalInSeconds) override
Called when advancing a single time-step.
Abstract base class for 3-D scalar grid structure.
Definition: scalar_grid3.h:21
Vector3< double > Vector3D
Double-type 3D vector.
Definition: vector3.h:349
void setEmitter(const GridEmitter3Ptr &newEmitter)
Sets the emitter.
3-D vector class.
Definition: vector3.h:25
VectorField3Ptr colliderVelocityField() const
Returns the velocity field of the collider.
virtual void onEndAdvanceTimeStep(double timeIntervalInSeconds)
Called at the end of a time-step.
const GridPressureSolver3Ptr & pressureSolver() const
Returns the pressure solver instance.
void onInitialize() override
Called when it needs to setup initial condition.
const FaceCenteredGrid3Ptr & velocity() const
Returns the velocity field.
std::shared_ptr< Collider3 > Collider3Ptr
Shared pointer type for the Collider2.
Definition: collider3.h:118
bool useCompressedLinearSystem() const
Returns true if the solver is using compressed linear system.
virtual ScalarField3Ptr fluidSdf() const
double maxCfl() const
Returns the max allowed CFL number.
const Vector3D & gravity() const
Returns the gravity vector of the system.
std::shared_ptr< VectorField3 > VectorField3Ptr
Shared pointer for the VectorField3 type.
Definition: vector_field3.h:40
std::shared_ptr< GridEmitter3 > GridEmitter3Ptr
Shared pointer type for the GridEmitter3.
Definition: grid_emitter3.h:70
unsigned int numberOfSubTimeSteps(double timeIntervalInSeconds) const override
Returns the required sub-time-steps for given time interval.
DerivedBuilder & withGridSpacing(const Vector3D &gridSpacing)
Returns builder with grid spacing.
Definition: grid_fluid_solver3.h:339
void setPressureSolver(const GridPressureSolver3Ptr &newSolver)
Sets the pressure solver.