FDMUtils.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_FDM_UTILS_HPP
12 #define CUBBYFLOW_FDM_UTILS_HPP
13 
14 #include <Core/Array/ArrayView.hpp>
15 #include <Core/Matrix/Matrix.hpp>
16 
17 namespace CubbyFlow
18 {
21 Vector2D Gradient2(const ConstArrayView2<double>& data,
22  const Vector2D& gridSpacing, size_t i, size_t j);
23 
26 std::array<Vector2D, 2> Gradient2(const ConstArrayView2<Vector2D>& data,
27  const Vector2D& gridSpacing, size_t i,
28  size_t j);
29 
32 Vector3D Gradient3(const ConstArrayView3<double>& data,
33  const Vector3D& gridSpacing, size_t i, size_t j, size_t k);
34 
37 std::array<Vector3D, 3> Gradient3(const ConstArrayView3<Vector3D>& data,
38  const Vector3D& gridSpacing, size_t i,
39  size_t j, size_t k);
40 
43 double Laplacian2(const ConstArrayView2<double>& data,
44  const Vector2D& gridSpacing, size_t i, size_t j);
45 
48 Vector2D Laplacian2(const ConstArrayView2<Vector2D>& data,
49  const Vector2D& gridSpacing, size_t i, size_t j);
50 
53 double Laplacian3(const ConstArrayView3<double>& data,
54  const Vector3D& gridSpacing, size_t i, size_t j, size_t k);
55 
58 Vector3D Laplacian3(const ConstArrayView3<Vector3D>& data,
59  const Vector3D& gridSpacing, size_t i, size_t j, size_t k);
60 
63 double Divergence2(const ConstArrayView2<Vector2D>& data,
64  const Vector2D& gridSpacing, size_t i, size_t j);
65 
68 double Divergence3(const ConstArrayView3<Vector3D>& data,
69  const Vector3D& gridSpacing, size_t i, size_t j, size_t k);
70 
73 double Curl2(const ConstArrayView2<Vector2D>& data, const Vector2D& gridSpacing,
74  size_t i, size_t j);
75 
78 Vector3D Curl3(const ConstArrayView3<Vector3D>& data,
79  const Vector3D& gridSpacing, size_t i, size_t j, size_t k);
80 
81 template <size_t N>
83 {
84  // Do nothing
85 };
86 
87 template <>
88 struct GetFDMUtils<2>
89 {
91  const Vector2D& gridSpacing, const Vector2UZ& idx)
92  {
93  return Gradient2(data, gridSpacing, idx.x, idx.y);
94  }
95 
96  static double Laplacian(const ConstArrayView2<double>& data,
97  const Vector2D& gridSpacing, const Vector2UZ& idx)
98  {
99  return Laplacian2(data, gridSpacing, idx.x, idx.y);
100  }
101 
102  static double Divergence(const ConstArrayView2<Vector2D>& data,
103  const Vector2D& gridSpacing, const Vector2UZ& idx)
104  {
105  return Divergence2(data, gridSpacing, idx.x, idx.y);
106  }
107 
108  static double Curl(const ConstArrayView2<Vector2D>& data,
109  const Vector2D& gridSpacing, const Vector2UZ& idx)
110  {
111  return Curl2(data, gridSpacing, idx.x, idx.y);
112  }
113 };
114 
115 template <>
116 struct GetFDMUtils<3>
117 {
119  const Vector3D& gridSpacing, const Vector3UZ& idx)
120  {
121  return Gradient3(data, gridSpacing, idx.x, idx.y, idx.z);
122  }
123 
124  static double Laplacian(const ConstArrayView3<double>& data,
125  const Vector3D& gridSpacing, const Vector3UZ& idx)
126  {
127  return Laplacian3(data, gridSpacing, idx.x, idx.y, idx.z);
128  }
129 
130  static double Divergence(const ConstArrayView3<Vector3D>& data,
131  const Vector3D& gridSpacing, const Vector3UZ& idx)
132  {
133  return Divergence3(data, gridSpacing, idx.x, idx.y, idx.z);
134  }
135 
137  const Vector3D& gridSpacing, const Vector3UZ& idx)
138  {
139  return Curl3(data, gridSpacing, idx.x, idx.y, idx.z);
140  }
141 };
142 } // namespace CubbyFlow
143 
144 #endif
Vector2D Gradient2(const ConstArrayView2< double > &data, const Vector2D &gridSpacing, size_t i, size_t j)
Returns 2-D gradient vector from given 2-D scalar grid-like array data, gridSpacing, and array index (i, j).
double Divergence2(const ConstArrayView2< Vector2D > &data, const Vector2D &gridSpacing, size_t i, size_t j)
Returns divergence value from given 2-D vector grid-like array data, gridSpacing, and array index (i...
static double Laplacian(const ConstArrayView3< double > &data, const Vector3D &gridSpacing, const Vector3UZ &idx)
Definition: FDMUtils.hpp:124
static double Divergence(const ConstArrayView3< Vector3D > &data, const Vector3D &gridSpacing, const Vector3UZ &idx)
Definition: FDMUtils.hpp:130
static Vector3D Gradient(const ConstArrayView3< double > &data, const Vector3D &gridSpacing, const Vector3UZ &idx)
Definition: FDMUtils.hpp:118
Vector3D Curl3(const ConstArrayView3< Vector3D > &data, const Vector3D &gridSpacing, size_t i, size_t j, size_t k)
Returns curl value from given 3-D vector grid-like array data, gridSpacing, and array index (i...
static double Divergence(const ConstArrayView2< Vector2D > &data, const Vector2D &gridSpacing, const Vector2UZ &idx)
Definition: FDMUtils.hpp:102
double Curl2(const ConstArrayView2< Vector2D > &data, const Vector2D &gridSpacing, size_t i, size_t j)
Returns curl value from given 2-D vector grid-like array data, gridSpacing, and array index (i...
double Laplacian3(const ConstArrayView3< double > &data, const Vector3D &gridSpacing, size_t i, size_t j, size_t k)
Returns Laplacian value from given 3-D scalar grid-like array data, gridSpacing, and array index (i...
static double Curl(const ConstArrayView2< Vector2D > &data, const Vector2D &gridSpacing, const Vector2UZ &idx)
Definition: FDMUtils.hpp:108
Definition: FDMUtils.hpp:82
static double Laplacian(const ConstArrayView2< double > &data, const Vector2D &gridSpacing, const Vector2UZ &idx)
Definition: FDMUtils.hpp:96
Definition: Matrix.hpp:27
Vector3D Gradient3(const ConstArrayView3< double > &data, const Vector3D &gridSpacing, size_t i, size_t j, size_t k)
Returns 3-D gradient vector from given 3-D scalar grid-like array data, gridSpacing, and array index (i, j, k).
Definition: pybind11Utils.hpp:20
Vector2< double > Vector2D
Definition: Matrix.hpp:774
static Vector3D Curl(const ConstArrayView3< Vector3D > &data, const Vector3D &gridSpacing, const Vector3UZ &idx)
Definition: FDMUtils.hpp:136
double Laplacian2(const ConstArrayView2< double > &data, const Vector2D &gridSpacing, size_t i, size_t j)
Returns Laplacian value from given 2-D scalar grid-like array data, gridSpacing, and array index (i...
static Vector2D Gradient(const ConstArrayView2< double > &data, const Vector2D &gridSpacing, const Vector2UZ &idx)
Definition: FDMUtils.hpp:90
Generic N-dimensional array class interface.
Definition: Array.hpp:32
double Divergence3(const ConstArrayView3< Vector3D > &data, const Vector3D &gridSpacing, size_t i, size_t j, size_t k)
Returns diverence value from given 3-D vector grid-like array data, gridSpacing, and array index (i...
Vector3< double > Vector3D
Definition: Matrix.hpp:787