Gradient Augmented Levelset Implementation in CPU & GPU
hermite-1d.cc (Latest change: Author:Lakshman Anumolu <acrlakshman@yahoo.co.in>, 2019-07-21 16:12:22 -0500, [commit: d791c50])
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 <math.h>
35 
36 template <typename T>
39  const typename GALS::CPU::Grid<T, 1>::position_type &x_interp,
40  const GALS::CPU::Levelset<GALS::CPU::Grid<T, 1>, T> &levelset, const bool use_gradient_limiting)
41 {
43 
45  const int dim = T_GRID::dim;
46  const int axis = 0;
48  const GALS::CPU::Vec3<int> base_node_id = grid.baseNodeId(x_interp);
49  const GALS::CPU::Vec3<int> base_node_id_p1 = GALS::CPU::Vec3<int>(base_node_id[0] + axis_vectors(0, 0), 0, 0);
50 
51  const typename T_GRID::position_type x_base = grid(base_node_id);
52  const auto &dx = grid.dX();
53  const auto &one_over_dx = grid.oneOverDX();
54 
55  T eta = (x_interp[0] - x_base[0]) * one_over_dx[0];
56 
58  levelset.phiPrev()(base_node_id), levelset.psiPrev()(base_node_id)[axis], levelset.phiPrev()(base_node_id_p1),
59  levelset.psiPrev()(base_node_id_p1)[axis], dx[axis], use_gradient_limiting);
60 
61  hermite_fields.phi_interpolated = control_points.c_30 * B0(eta) + control_points.c_21 * B1(eta) +
62  control_points.c_12 * B2(eta) + control_points.c_03 * B3(eta);
63  hermite_fields.psi_interpolated[axis] = (control_points.c_30 * B0_Prime(eta) + control_points.c_21 * B1_Prime(eta) +
64  control_points.c_12 * B2_Prime(eta) + control_points.c_03 * B3_Prime(eta)) *
65  one_over_dx[axis];
66 
67  // Debug
68  // std::cout << std::scientific;
69  // std::cout << "eta = " << eta << "; xi = " << x_interp[0] << std::endl
70  //<< "\t; phi_b = " << levelset.phiPrev()(base_node_id)
71  //<< "\t; phi_bp1 = " << levelset.phiPrev()(base_node_id_p1) << std::endl
72  //<< "\t; psi_b = " << levelset.psiPrev()(base_node_id)
73  //<< "\t; psi_bp1 = " << levelset.psiPrev()(base_node_id_p1) << std::endl
74  //<< "\t; phi_i = " << hermite_fields.phi_interpolated
75  //<< "\t; psi_i = " << hermite_fields.psi_interpolated[axis] << std::endl;
76  // std::cout << "\tfirst: c30 = " << control_points.c_30 << "; B0(eta) = " << B0(eta) << std::endl;
77  // std::cout << "\tsecond: c21 = " << control_points.c_21 << "; B1(eta) = " << B1(eta) << std::endl;
78  // std::cout << "\tthird: c12 = " << control_points.c_12 << "; B2(eta) = " << B2(eta) << std::endl;
79  // std::cout << "\tfourth: c03 = " << control_points.c_03 << "; B3(eta) = " << B3(eta) << std::endl;
80 
81  return hermite_fields;
82 }
83 
84 template <typename T>
88 {
90 
91  const GALS::CPU::Vec3<int> num_cells_interp = x_interp.numCells();
92  const T_GRID &grid = levelset.grid();
95 
96  for (int i = 0; i < num_cells_interp[0]; ++i)
97  for (int j = 0; j < num_cells_interp[1]; ++j)
98  for (int k = 0; k < num_cells_interp[2]; ++k) {
99  const auto &hermite_fields = this->interpolate(grid, x_interp(i, j, k), levelset);
100 
101  levelset.phiInterpPrev()(i, j, k) = hermite_fields.phi_interpolated;
102  levelset.psiInterpPrev()(i, j, k) = hermite_fields.psi_interpolated;
103  }
104 }
105 
T B0(T eta)
cubic Bernstein polynomials
Definition: hermite.h:57
T B0_Prime(T eta)
Definition: hermite.h:81
const Vec3< T > & dX() const
Definition: grid.cc:144
T value_type
Definition: grid.h:71
T B2_Prime(T eta)
Definition: hermite.h:93
static struct ControlPoints< T > get_control_points(const T &phi_0, const T &phi_x_0, const T &phi_1, const T &phi_x_1, const T &dx, bool use_gradient_limiting=false)
Definition: hermite.h:116
T B3_Prime(T eta)
Definition: hermite.h:99
T B1_Prime(T eta)
Definition: hermite.h:87