CustomScalarField2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: CustomScalarField2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D scalar field with custom field function.
6 > Created Time: 2017/03/15
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_CUSTOM_SCALAR_FIELD2_H
10 #define CUBBYFLOW_CUSTOM_SCALAR_FIELD2_H
11 
13 
14 namespace CubbyFlow
15 {
17  class CustomScalarField2 final : public ScalarField2
18  {
19  public:
20  class Builder;
21 
31  const std::function<double(const Vector2D&)>& customFunction,
32  double derivativeResolution = 1e-3);
33 
43  const std::function<double(const Vector2D&)>& customFunction,
44  const std::function<Vector2D(const Vector2D&)>& customGradientFunction,
45  double derivativeResolution = 1e-3);
46 
49  const std::function<double(const Vector2D&)>& customFunction,
50  const std::function<Vector2D(const Vector2D&)>& customGradientFunction,
51  const std::function<double(const Vector2D&)>& customLaplacianFunction);
52 
54  double Sample(const Vector2D& x) const override;
55 
57  std::function<double(const Vector2D&)> Sampler() const override;
58 
60  Vector2D Gradient(const Vector2D& x) const override;
61 
63  double Laplacian(const Vector2D& x) const override;
64 
66  static Builder GetBuilder();
67 
68  private:
69  std::function<double(const Vector2D&)> m_customFunction;
70  std::function<Vector2D(const Vector2D&)> m_customGradientFunction;
71  std::function<double(const Vector2D&)> m_customLaplacianFunction;
72  double m_resolution = 1e-3;
73  };
74 
76  using CustomScalarField2Ptr = std::shared_ptr<CustomScalarField2>;
77 
82  {
83  public:
85  Builder& WithFunction(const std::function<double(const Vector2D&)>& func);
86 
88  Builder& WithGradientFunction(const std::function<Vector2D(const Vector2D&)>& func);
89 
91  Builder& WithLaplacianFunction(const std::function<double(const Vector2D&)>& func);
92 
94  Builder& WithDerivativeResolution(double resolution);
95 
97  CustomScalarField2 Build() const;
98 
101 
102  private:
103  double m_resolution = 1e-3;
104  std::function<double(const Vector2D&)> m_customFunction;
105  std::function<Vector2D(const Vector2D&)> m_customGradientFunction;
106  std::function<double(const Vector2D&)> m_customLaplacianFunction;
107  };
108 }
109 
110 #endif
std::shared_ptr< CustomScalarField2 > CustomScalarField2Ptr
Shared pointer type for the CustomScalarField2.
Definition: CustomScalarField2.h:76
CustomScalarField2(const std::function< double(const Vector2D &)> &customFunction, double derivativeResolution=1e-3)
Constructs a field with given function.
Builder & WithGradientFunction(const std::function< Vector2D(const Vector2D &)> &func)
Returns builder with divergence function.
Abstract base class for 2-D scalar field.
Definition: ScalarField2.h:21
Builder & WithLaplacianFunction(const std::function< double(const Vector2D &)> &func)
Returns builder with curl function.
2-D scalar field with custom field function.
Definition: CustomScalarField2.h:17
CustomScalarField2 Build() const
Builds CustomScalarField2.
double Laplacian(const Vector2D &x) const override
Returns the Laplacian at given position x.
double Sample(const Vector2D &x) const override
Returns the sampled value at given position x.
static Builder GetBuilder()
Returns builder for CustomScalarField2.
Vector2D Gradient(const Vector2D &x) const override
Returns the gradient vector at given position x.
Definition: pybind11Utils.h:24
Vector2< double > Vector2D
Double-type 2D vector.
Definition: Vector2.h:341
CustomScalarField2Ptr MakeShared() const
Builds shared pointer of CustomScalarField2 instance.
std::function< double(const Vector2D &)> Sampler() const override
Returns the sampler function.
Builder & WithDerivativeResolution(double resolution)
Returns builder with derivative resolution.
2-D vector class.
Definition: Vector2.h:26
Front-end to create CustomScalarField2 objects step by step.
Definition: CustomScalarField2.h:81
Builder & WithFunction(const std::function< double(const Vector2D &)> &func)
Returns builder with field function.