MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SolenoidalProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6
7/**
8 * @class SolenoidalProcessor
9 * @brief VolumeFieldProcessor subtracting a pressure gradient from a
10 * velocity field, leaving it divergence-free.
11 *
12 * Central differences on the six axis neighbours of the pressure field,
13 * clamped at the lattice boundary, mirroring DivergenceProcessor's
14 * stencil in the opposite direction.
15 *
16 * The pressure solve carries no time step or density factor, so pressure
17 * absorbs both and the correction is the plain difference v - grad(p).
18 * Introducing a scale here would apply the factor twice.
19 *
20 * Closes the incompressible chain: advect, divergence, pressure,
21 * solenoidal. Correctness is observable by running divergence again after
22 * this stage and reading the result, which approaches zero on the
23 * interior as the Jacobi iteration count rises.
24 *
25 * Boundary cells receive a clamped one-sided gradient rather than a wall
26 * condition. Normal velocity at the lattice edge is not forced to zero,
27 * so a seed with wall-normal flow drains the domain.
28 */
29class MAYAFLUX_API SolenoidalProcessor : public VolumeFieldProcessor {
30public:
31 /**
32 * @brief Construct a gradient subtraction stage.
33 * @param pressure_field Name of the scalar field differentiated. Must
34 * have stride sizeof(float).
35 * @param velocity_field Name of the field corrected. Must have stride
36 * sizeof(glm::vec4) and be double-buffered.
37 * @param shader_path Path to the compute shader.
38 */
40 std::string pressure_field,
41 std::string velocity_field,
42 const std::string& shader_path);
43
44 /**
45 * @brief Construct a gradient subtraction stage from a generated ShaderSpec.
46 * @param pressure_field Name of the scalar field differentiated.
47 * @param velocity_field Name of the field corrected.
48 * @param spec ShaderSpec implementing the stencil.
49 */
51 std::string pressure_field,
52 std::string velocity_field,
54
55 /** @brief Name of the field this stage differentiates. */
56 [[nodiscard]] const std::string& get_pressure_field() const { return m_pressure_field; }
57
58 /** @brief Name of the field this stage corrects. */
59 [[nodiscard]] const std::string& get_velocity_field() const { return m_velocity_field; }
60
61private:
62 /**
63 * @brief Build the binding table for the two field names.
64 * @param pressure_field Field differentiated.
65 * @param velocity_field Field corrected, bound in both slots.
66 * @return Table binding pressure read and both velocity slots.
67 */
68 static std::vector<FieldBinding> make_bindings(
69 const std::string& pressure_field, const std::string& velocity_field);
70
71 std::string m_pressure_field;
72 std::string m_velocity_field;
73};
74
75} // namespace MayaFlux::Buffers
const std::string & get_velocity_field() const
Name of the field this stage corrects.
const std::string & get_pressure_field() const
Name of the field this stage differentiates.
VolumeFieldProcessor subtracting a pressure gradient from a velocity field, leaving it divergence-fre...
ComputeProcessor operating on named fields of a VolumeGridBuffer.
Complete declarative description of a generated compute shader.