FDMMGLinearSystem2-Impl.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: FDMMGLinearSystem2-Impl.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Multigrid-syle 2-D linear system.
6 > Created Time: 2017/11/02
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_FDM_MG_LINEAR_SYSTEM2_IMPL_H
10 #define CUBBYFLOW_FDM_MG_LINEAR_SYSTEM2_IMPL_H
11 
12 namespace CubbyFlow
13 {
14  template <typename T>
15  void FDMMGUtils2::ResizeArrayWithCoarsest(const Size2& coarsestResolution,
16  size_t numberOfLevels, std::vector<Array2<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  Size2 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  }
31  }
32 
33  template <typename T>
34  void FDMMGUtils2::ResizeArrayWithFinest(const Size2& finestResolution,
35  size_t maxNumberOfLevels, std::vector<Array2<T>>* levels)
36  {
37  Size2 res = finestResolution;
38  size_t i = 1;
39 
40  for (; i < maxNumberOfLevels; ++i)
41  {
42  if (res.x % 2 == 0 && res.y % 2 == 0)
43  {
44  res.x = res.x >> 1;
45  res.y = res.y >> 1;
46  }
47  else
48  {
49  break;
50  }
51  }
52 
53  ResizeArrayWithCoarsest(res, i, levels);
54  }
55 }
56 
57 #endif
static void ResizeArrayWithFinest(const Size2 &finestResolution, size_t maxNumberOfLevels, std::vector< Array2< T >> *levels)
Resizes the array with the finest resolution and max number of levels.
Definition: FDMMGLinearSystem2-Impl.h:34
T x
X (or the first) component of the point.
Definition: Point2.h:28
2-D point class.
Definition: Point2.h:25
constexpr size_t ONE_SIZE
One size_t.
Definition: Constants.h:45
T y
Y (or the second) component of the point.
Definition: Point2.h:34
Definition: pybind11Utils.h:24
static void ResizeArrayWithCoarsest(const Size2 &coarsestResolution, size_t numberOfLevels, std::vector< Array2< T >> *levels)
Resizes the array with the coarsest resolution and number of levels.
Definition: FDMMGLinearSystem2-Impl.h:15
2-D array class.
Definition: Array2.h:42