MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
DivergenceProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6
7/**
8 * @class DivergenceProcessor
9 * @brief VolumeFieldProcessor computing the divergence of a vector field
10 * into a scalar field by central differences.
11 *
12 * Central differences on the six axis neighbours, clamped at the lattice
13 * boundary, which gives boundary cells a one-sided estimate. The result
14 * is the right-hand side of the pressure Poisson equation, and read
15 * directly it is also the residual probe for a completed incompressible
16 * chain.
17 *
18 * The output field is written but never read by this stage, so it may be
19 * single-buffered and is not swapped.
20 *
21 * The collocated stencil decouples odd and even cells in principle. If
22 * high-frequency noise appears in the downstream pressure field, the fix
23 * is a staggered velocity layout, which changes indexing rather than
24 * class structure.
25 */
26class MAYAFLUX_API DivergenceProcessor : public VolumeFieldProcessor {
27public:
28 /**
29 * @brief Construct a divergence stage.
30 * @param velocity_field Name of the field differentiated. Must have
31 * stride sizeof(glm::vec4).
32 * @param divergence_field Name of the scalar field written. Must have
33 * stride sizeof(float).
34 * @param shader_path Path to the compute shader.
35 */
37 std::string velocity_field,
38 std::string divergence_field,
39 const std::string& shader_path);
40
41 /**
42 * @brief Construct a divergence stage from a generated ShaderSpec.
43 * @param velocity_field Name of the field differentiated.
44 * @param divergence_field Name of the scalar field written.
45 * @param spec ShaderSpec implementing the stencil.
46 */
48 std::string velocity_field,
49 std::string divergence_field,
51
52 /** @brief Name of the field this stage differentiates. */
53 [[nodiscard]] const std::string& get_velocity_field() const { return m_velocity_field; }
54
55 /** @brief Name of the field this stage writes. */
56 [[nodiscard]] const std::string& get_divergence_field() const { return m_divergence_field; }
57
58private:
59 /**
60 * @brief Build the binding table for the two field names.
61 * @param velocity_field Field differentiated.
62 * @param divergence_field Field written.
63 * @return Table binding velocity read and divergence write.
64 */
65 static std::vector<FieldBinding> make_bindings(
66 const std::string& velocity_field, const std::string& divergence_field);
67
68 std::string m_velocity_field;
69 std::string m_divergence_field;
70};
71
72} // namespace MayaFlux::Buffers
const std::string & get_velocity_field() const
Name of the field this stage differentiates.
const std::string & get_divergence_field() const
Name of the field this stage writes.
VolumeFieldProcessor computing the divergence of a vector field into a scalar field by central differ...
ComputeProcessor operating on named fields of a VolumeGridBuffer.
Complete declarative description of a generated compute shader.