FDMMGLinearSystem2-Impl.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_MG_LINEAR_SYSTEM2_IMPL_HPP
12 #define CUBBYFLOW_FDM_MG_LINEAR_SYSTEM2_IMPL_HPP
13 
14 namespace CubbyFlow
15 {
16 template <typename T>
17 void FDMMGUtils2::ResizeArrayWithCoarsest(const Vector2UZ& coarsestResolution,
18  size_t numberOfLevels,
19  std::vector<Array2<T>>* levels)
20 {
21  numberOfLevels = std::max(numberOfLevels, ONE_SIZE);
22 
23  levels->resize(numberOfLevels);
24 
25  // Level 0 is the finest level, thus takes coarsestResolution ^
26  // numberOfLevels. Level numberOfLevels - 1 is the coarsest, taking
27  // coarsestResolution.
28  Vector2UZ res = coarsestResolution;
29  for (size_t level = 0; level < numberOfLevels; ++level)
30  {
31  (*levels)[numberOfLevels - level - 1].Resize(res);
32  res.x = res.x << 1;
33  res.y = res.y << 1;
34  }
35 }
36 
37 template <typename T>
38 void FDMMGUtils2::ResizeArrayWithFinest(const Vector2UZ& finestResolution,
39  size_t maxNumberOfLevels,
40  std::vector<Array2<T>>* levels)
41 {
42  Vector2UZ res = finestResolution;
43  size_t i = 1;
44 
45  for (; i < maxNumberOfLevels; ++i)
46  {
47  if (res.x % 2 == 0 && res.y % 2 == 0)
48  {
49  res.x = res.x >> 1;
50  res.y = res.y >> 1;
51  }
52  else
53  {
54  break;
55  }
56  }
57 
58  ResizeArrayWithCoarsest(res, i, levels);
59 }
60 } // namespace CubbyFlow
61 
62 #endif
static void ResizeArrayWithFinest(const Vector2UZ &finestResolution, size_t maxNumberOfLevels, std::vector< Array2< T >> *levels)
Resizes the array with the finest resolution and max number of levels.
Definition: FDMMGLinearSystem2-Impl.hpp:38
constexpr size_t ONE_SIZE
One size_t.
Definition: Constants.hpp:47
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
static void ResizeArrayWithCoarsest(const Vector2UZ &coarsestResolution, size_t numberOfLevels, std::vector< Array2< T >> *levels)
Resizes the array with the coarsest resolution and number of levels.
Definition: FDMMGLinearSystem2-Impl.hpp:17