Line data Source code
1 : ///////////////////////////////////////////////////////////////////////////////
2 : // 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.
30 : ///////////////////////////////////////////////////////////////////////////////
31 :
32 : #include "gals/cpu/interpolation/hermite.h"
33 :
34 : #include <math.h>
35 :
36 : template <typename T>
37 54 : GALS::CPU::InterpolatedFields<GALS::CPU::Vec3<T>> GALS::INTERPOLATION::Hermite<T, GALS::CPU::Grid<T, 1>>::interpolate(
38 : const GALS::CPU::Grid<typename GALS::CPU::Grid<T, 1>::value_type, GALS::CPU::Grid<T, 1>::dim> &grid,
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 : {
42 54 : GALS::CPU::InterpolatedFields<GALS::CPU::Vec3<T>> hermite_fields;
43 :
44 : using T_GRID = GALS::CPU::Grid<T, 1>;
45 : const int dim = T_GRID::dim;
46 : const int axis = 0;
47 : const auto &axis_vectors = GALS::CPU::Grid<typename T_GRID::value_type, T_GRID::dim>::axis_vectors;
48 108 : const GALS::CPU::Vec3<int> base_node_id = grid.baseNodeId(x_interp);
49 108 : 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 108 : const typename T_GRID::position_type x_base = grid(base_node_id);
52 54 : const auto &dx = grid.dX();
53 54 : const auto &one_over_dx = grid.oneOverDX();
54 :
55 54 : T eta = (x_interp[0] - x_base[0]) * one_over_dx[0];
56 :
57 216 : const ControlPoints<T> &control_points = GALS::INTERPOLATION::get_control_points(
58 108 : levelset.phiPrev()(base_node_id), levelset.psiPrev()(base_node_id)[axis], levelset.phiPrev()(base_node_id_p1),
59 162 : levelset.psiPrev()(base_node_id_p1)[axis], dx[axis], use_gradient_limiting);
60 :
61 216 : hermite_fields.phi_interpolated = control_points.c_30 * B0(eta) + control_points.c_21 * B1(eta) +
62 108 : control_points.c_12 * B2(eta) + control_points.c_03 * B3(eta);
63 270 : hermite_fields.psi_interpolated[axis] = (control_points.c_30 * B0_Prime(eta) + control_points.c_21 * B1_Prime(eta) +
64 162 : control_points.c_12 * B2_Prime(eta) + control_points.c_03 * B3_Prime(eta)) *
65 54 : 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 54 : return hermite_fields;
82 : }
83 :
84 : template <typename T>
85 5 : void GALS::INTERPOLATION::Hermite<T, GALS::CPU::Grid<T, 1>>::compute(
86 : const GALS::CPU::Array<GALS::CPU::Grid<T, 1>, typename GALS::CPU::Grid<T, 1>::position_type> &x_interp,
87 : GALS::CPU::Levelset<GALS::CPU::Grid<T, 1>, T> &levelset)
88 : {
89 : typedef GALS::CPU::Grid<T, 1> T_GRID;
90 :
91 10 : const GALS::CPU::Vec3<int> num_cells_interp = x_interp.numCells();
92 5 : const T_GRID &grid = levelset.grid();
93 10 : const GALS::CPU::Vec3<typename T_GRID::value_type> dx = grid.dX();
94 : const auto &axis_vectors = GALS::CPU::Grid<typename T_GRID::value_type, T_GRID::dim>::axis_vectors;
95 :
96 113 : for (int i = 0; i < num_cells_interp[0]; ++i)
97 162 : for (int j = 0; j < num_cells_interp[1]; ++j)
98 162 : for (int k = 0; k < num_cells_interp[2]; ++k) {
99 54 : const auto &hermite_fields = this->interpolate(grid, x_interp(i, j, k), levelset);
100 :
101 54 : levelset.phiInterpPrev()(i, j, k) = hermite_fields.phi_interpolated;
102 54 : levelset.psiInterpPrev()(i, j, k) = hermite_fields.psi_interpolated;
103 : }
104 5 : }
105 :
106 3 : template class GALS::INTERPOLATION::Hermite<double, GALS::CPU::Grid<double, 1>>;
|