FDMMGLinearSystem3-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_SYSTEM3_IMPL_HPP
12 #define CUBBYFLOW_FDM_MG_LINEAR_SYSTEM3_IMPL_HPP
13 
14 namespace CubbyFlow
15 {
16 template <typename T>
17 void FDMMGUtils3::ResizeArrayWithCoarsest(const Vector3UZ& coarsestResolution,
18  size_t numberOfLevels,
19  std::vector<Array3<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  Vector3UZ 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  res.z = res.z << 1;
35  }
36 }
37 
38 template <typename T>
39 void FDMMGUtils3::ResizeArrayWithFinest(const Vector3UZ& finestResolution,
40  size_t maxNumberOfLevels,
41  std::vector<Array3<T>>* levels)
42 {
43  Vector3UZ res = finestResolution;
44  size_t i = 1;
45 
46  for (; i < maxNumberOfLevels; ++i)
47  {
48  if (res.x % 2 == 0 && res.y % 2 == 0 && res.z % 2 == 0)
49  {
50  res.x = res.x >> 1;
51  res.y = res.y >> 1;
52  res.z = res.z >> 1;
53  }
54  else
55  {
56  break;
57  }
58  }
59 
60  ResizeArrayWithCoarsest(res, i, levels);
61 }
62 } // namespace CubbyFlow
63 
64 #endif
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 ResizeArrayWithFinest(const Vector3UZ &finestResolution, size_t maxNumberOfLevels, std::vector< Array3< T >> *levels)
Resizes the array with the finest resolution and max number of levels.
Definition: FDMMGLinearSystem3-Impl.hpp:39
static void ResizeArrayWithCoarsest(const Vector3UZ &coarsestResolution, size_t numberOfLevels, std::vector< Array3< T >> *levels)
Resizes the array with the coarsest resolution and number of levels.
Definition: FDMMGLinearSystem3-Impl.hpp:17