Gradient Augmented Levelset Implementation in CPU & GPU
velocity.cc (Latest change: Author:Lakshman Anumolu <acrlakshman@yahoo.co.in>, 2019-07-27 14:14:10 -0500, [commit: 0b0a8dc])
Go to the documentation of this file.
1 // Copyright 2019 Lakshman Anumolu, Raunak Bardia.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
33 
34 #include <string>
35 
37 
38 template <typename T_GRID, typename T>
40  : m_grid(grid), m_inputs(inputs)
41 {
42 }
43 
44 template <typename T_GRID, typename T>
46 {
47 }
48 
49 template <typename T_GRID, typename T>
51  const GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>>& positions, const T time,
52  GALS::CPU::LevelsetVelocity<T_GRID, T>& levelset_velocity)
53 {
54  const GALS::CPU::Vec3<int> num_cells = positions.numCells();
55  const auto& velocity_name = m_inputs.name;
56 
57  switch (velocity_name_map[velocity_name]) {
59  auto& velocity = levelset_velocity.velocity();
60 
61  if (T_GRID::dim == 1)
63  "GALS::ANALYTICAL_FIELDS::Velocity::compute: CIRCULAR velocity field for 1D grid.");
64 
65  T coeff = pi() / static_cast<T>(3.15);
66  GALS::CPU::Vec3<T> velocity_node;
67 
68  for (int i = 0; i < num_cells[0]; ++i)
69  for (int j = 0; j < num_cells[1]; ++j)
70  for (int k = 0; k < num_cells[2]; ++k) {
71  for (int cmpt = 0; cmpt < T_GRID::dim; ++cmpt) {
72  if (cmpt == 0) velocity_node[cmpt] = coeff * (m_inputs.center[cmpt] - positions(i, j, k)[cmpt + 1]);
73  if (cmpt == 1) velocity_node[cmpt] = coeff * (positions(i, j, k)[cmpt - 1] - m_inputs.center[cmpt]);
74  }
75 
76  velocity(i, j, k) = velocity_node;
77  }
78 
79  // Compute velocity gradient using analytical expressions.
80  if (!strcmp(m_inputs.gradient_scheme.c_str(), "ANALYTICAL")) {
81  auto& velocity_gradient = levelset_velocity.velocityGradient();
82 
83  for (int i = 0; i < num_cells[0]; ++i)
84  for (int j = 0; j < num_cells[1]; ++j)
85  for (int k = 0; k < num_cells[2]; ++k) {
86  for (int cmpt = 0; cmpt < T_GRID::dim; ++cmpt) {
87  for (int derv = 0; derv < T_GRID::dim; ++derv) {
88  if (cmpt == 0 && derv == 0) velocity_gradient[cmpt][derv] = static_cast<T>(0);
89  if (cmpt == 0 && derv == 1) velocity_gradient[cmpt][derv] = -coeff;
90  if (cmpt == 1 && derv == 0) velocity_gradient[cmpt][derv] = coeff;
91  if (cmpt == 1 && derv == 1) velocity_gradient[cmpt][derv] = static_cast<T>(0);
92  }
93  }
94  }
95  }
96 
97  break;
98  }
99 
100  default:
101  break;
102  }
103 }
104 
Array< T_GRID, Mat3< T > > & velocityGradient()
#define GALS_FUNCTION_NOT_IMPLEMENTED(var)
Definition: utilities.h:40
static std::map< std::string, VelocityFieldNames > velocity_name_map
Definition: velocity.h:54
Array< T_GRID, Vec3< T > > & velocity()
std::vector< double > center
Uniform velocity magnitudes of all components.
Definition: velocity.h:44
void compute(const GALS::CPU::Array< T_GRID, GALS::CPU::Vec3< T >> &positions, const T time, GALS::CPU::LevelsetVelocity< T_GRID, T > &levelset_velocity)
Definition: velocity.cc:50
static double pi()
Definition: utilities.h:55
std::string gradient_scheme
Center of velocity field for few velocity types.
Definition: velocity.h:45