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