FDMMGLinearSystem3-Impl.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: FDMMGLinearSystem3-Impl.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Multigrid-syle 3-D linear system.
6 > Created Time: 2017/11/03
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_FDM_MG_LINEAR_SYSTEM3_IMPL_H
10 #define CUBBYFLOW_FDM_MG_LINEAR_SYSTEM3_IMPL_H
11 
12 namespace CubbyFlow
13 {
14  template <typename T>
15  void FDMMGUtils3::ResizeArrayWithCoarsest(const Size3& coarsestResolution,
16  size_t numberOfLevels, std::vector<Array3<T>>* levels)
17  {
18  numberOfLevels = std::max(numberOfLevels, ONE_SIZE);
19 
20  levels->resize(numberOfLevels);
21 
22  // Level 0 is the finest level, thus takes coarsestResolution ^ numberOfLevels.
23  // Level numberOfLevels - 1 is the coarsest, taking coarsestResolution.
24  Size3 res = coarsestResolution;
25  for (size_t level = 0; level < numberOfLevels; ++level)
26  {
27  (*levels)[numberOfLevels - level - 1].Resize(res);
28  res.x = res.x << 1;
29  res.y = res.y << 1;
30  res.z = res.z << 1;
31  }
32  }
33 
34  template <typename T>
35  void FDMMGUtils3::ResizeArrayWithFinest(const Size3& finestResolution,
36  size_t maxNumberOfLevels, std::vector<Array3<T>>* levels)
37  {
38  Size3 res = finestResolution;
39  size_t i = 1;
40 
41  for (; i < maxNumberOfLevels; ++i)
42  {
43  if (res.x % 2 == 0 && res.y % 2 == 0 && res.z % 2 == 0)
44  {
45  res.x = res.x >> 1;
46  res.y = res.y >> 1;
47  res.z = res.z >> 1;
48  }
49  else
50  {
51  break;
52  }
53  }
54 
55  ResizeArrayWithCoarsest(res, i, levels);
56  }
57 }
58 
59 #endif
static void ResizeArrayWithCoarsest(const Size3 &coarsestResolution, size_t numberOfLevels, std::vector< Array3< T >> *levels)
Resizes the array with the coarsest resolution and number of levels.
Definition: FDMMGLinearSystem3-Impl.h:15
constexpr size_t ONE_SIZE
One size_t.
Definition: Constants.h:45
3-D point class.
Definition: Point3.h:26
Definition: pybind11Utils.h:24
T z
Z (or the third) component of the point.
Definition: Point3.h:38
T y
Y (or the second) component of the point.
Definition: Point3.h:35
T x
X (or the first) component of the point.
Definition: Point3.h:29
static void ResizeArrayWithFinest(const Size3 &finestResolution, size_t maxNumberOfLevels, std::vector< Array3< T >> *levels)
Resizes the array with the finest resolution and max number of levels.
Definition: FDMMGLinearSystem3-Impl.h:35
3-D array class.
Definition: Array3.h:45