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