Loading...
Searching...
No Matches
CustomScalarField.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_CUSTOM_SCALAR_FIELD_HPP
12#define CUBBYFLOW_CUSTOM_SCALAR_FIELD_HPP
13
15
16namespace CubbyFlow
17{
19template <size_t N>
20class CustomScalarField final : public ScalarField<N>
21{
22 public:
23 class Builder;
24
34 std::function<double(const Vector<double, N>&)> customFunction,
35 double derivativeResolution = 1e-3);
36
46 std::function<double(const Vector<double, N>&)> customFunction,
47 std::function<Vector<double, N>(const Vector<double, N>&)>
48 customGradientFunction,
49 double derivativeResolution = 1e-3);
50
53 std::function<double(const Vector<double, N>&)> customFunction,
54 std::function<Vector<double, N>(const Vector<double, N>&)>
55 customGradientFunction,
56 std::function<double(const Vector<double, N>&)>
57 customLaplacianFunction);
58
60 [[nodiscard]] double Sample(const Vector<double, N>& x) const override;
61
63 [[nodiscard]] std::function<double(const Vector<double, N>&)> Sampler()
64 const override;
65
68 const Vector<double, N>& x) const override;
69
71 [[nodiscard]] double Laplacian(const Vector<double, N>& x) const override;
72
75
76 private:
77 std::function<double(const Vector<double, N>&)> m_customFunction;
78 std::function<Vector<double, N>(const Vector<double, N>&)>
79 m_customGradientFunction;
80 std::function<double(const Vector<double, N>&)> m_customLaplacianFunction;
81 double m_resolution = 1e-3;
82};
83
86
89
91using CustomScalarField2Ptr = std::shared_ptr<CustomScalarField2>;
92
94using CustomScalarField3Ptr = std::shared_ptr<CustomScalarField3>;
95
99template <size_t N>
101{
102 public:
105 const std::function<double(const Vector<double, N>&)>& func);
106
109 const std::function<Vector<double, N>(const Vector<double, N>&)>& func);
110
113 const std::function<double(const Vector<double, N>&)>& func);
114
117
120
122 std::shared_ptr<CustomScalarField<N>> MakeShared() const;
123
124 private:
125 double m_resolution = 1e-3;
126 std::function<double(const Vector<double, N>&)> m_customFunction;
127 std::function<Vector<double, N>(const Vector<double, N>&)>
128 m_customGradientFunction;
129 std::function<double(const Vector<double, N>&)> m_customLaplacianFunction;
130};
131} // namespace CubbyFlow
132
133#endif
Front-end to create CustomScalarField objects step by step.
Definition CustomScalarField.hpp:101
std::shared_ptr< CustomScalarField< N > > MakeShared() const
Builds shared pointer of CustomScalarField instance.
Builder & WithLaplacianFunction(const std::function< double(const Vector< double, N > &)> &func)
Returns builder with curl function.
Builder & WithDerivativeResolution(double resolution)
Returns builder with derivative resolution.
Builder & WithGradientFunction(const std::function< Vector< double, N >(const Vector< double, N > &)> &func)
Returns builder with divergence function.
Builder & WithFunction(const std::function< double(const Vector< double, N > &)> &func)
Returns builder with field function.
CustomScalarField< N > Build() const
Builds CustomScalarField.
N-D scalar field with custom field function.
Definition CustomScalarField.hpp:21
CustomScalarField(std::function< double(const Vector< double, N > &)> customFunction, double derivativeResolution=1e-3)
Constructs a field with given function.
CustomScalarField(std::function< double(const Vector< double, N > &)> customFunction, std::function< Vector< double, N >(const Vector< double, N > &)> customGradientFunction, std::function< double(const Vector< double, N > &)> customLaplacianFunction)
Constructs a field with given field, gradient, and Laplacian function.
double Laplacian(const Vector< double, N > &x) const override
Returns the Laplacian at given position x.
std::function< double(const Vector< double, N > &)> Sampler() const override
Returns the sampler function.
static Builder GetBuilder()
Returns builder for CustomScalarField.
double Sample(const Vector< double, N > &x) const override
Returns the sampled value at given position x.
Vector< double, N > Gradient(const Vector< double, N > &x) const override
Returns the gradient vector at given position x.
CustomScalarField(std::function< double(const Vector< double, N > &)> customFunction, std::function< Vector< double, N >(const Vector< double, N > &)> customGradientFunction, double derivativeResolution=1e-3)
Constructs a field with given field and gradient function.
Definition Matrix.hpp:30
Abstract base class for N-D scalar field.
Definition ScalarField.hpp:25
Definition pybind11Utils.hpp:21
std::shared_ptr< CustomScalarField3 > CustomScalarField3Ptr
Shared pointer type for the CustomScalarField3.
Definition CustomScalarField.hpp:94
std::shared_ptr< CustomScalarField2 > CustomScalarField2Ptr
Shared pointer type for the CustomScalarField2.
Definition CustomScalarField.hpp:91