Alsvinn  0.5.3
The fast FVM simulator with UQ support
interpolate.hpp
Go to the documentation of this file.
1 /* Copyright (c) 2018 ETH Zurich, Kjetil Olsen Lye
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #pragma once
17 #include "alsfvm/volume/Volume.hpp"
19 
20 
21 namespace alsfvm {
22 namespace volume {
23 
24 template<size_t dimension>
26  size_t x, size_t y, size_t z);
27 
28 template<>
30  size_t x, size_t y, size_t z) {
31  out.at(x, y, z) = (in.at(2 * x, y, z) + in.at(2 * x + 1, y, z)) / 2.0;
32 }
33 
34 template<>
36  size_t x, size_t y, size_t z) {
37  out.at(x, y, z) = (in.at(2 * x, 2 * y, z) + in.at(2 * x + 1, 2 * y, z)
38  + in.at(2 * x, 2 * y + 1, z) + in.at(2 * x + 1, 2 * y + 1, z)) / 4.0;
39 }
40 
41 template<>
43  size_t x, size_t y, size_t z) {
44  out.at(x, y, z) = 0;
45 
46  // Do this with for-loop because there are just too many combinations
47  for (size_t i = 0; i < 2; ++i) {
48  for (size_t j = 0; j < 2; ++j) {
49  for (size_t k = 0; k < 2; ++k) {
50  out.at(x, y, z) += in.at(2 * x + k, 2 * y + j, 2 * z + i);
51  }
52  }
53  }
54 
55  out.at(x, y, z) /= 16;
56 }
57 
58 template<size_t dimension>
59 inline void interpolate(Volume& out, const Volume& in) {
60  if (out.getNumberOfXCells() != in.getNumberOfXCells() / 2) {
61  THROW("Currently we only support doing interpolation with the ration 2 to 1.");
62  }
63 
64  size_t nx = out.getTotalNumberOfXCells();
65  size_t ny = out.getTotalNumberOfYCells();
66  size_t nz = out.getTotalNumberOfZCells();
67 
68  size_t ng = out.getNumberOfXGhostCells();
69  bool hasZ = dimension > 2;
70  bool hasY = dimension > 1;
71 
72  for (size_t var = 0; var < out.getNumberOfVariables(); ++var) {
73  auto viewOut = out.getScalarMemoryArea(var)->getView();
74  auto viewIn = in.getScalarMemoryArea(var)->getView();
75 
76  for (size_t z = hasZ * ng; z < nz - hasZ * ng ; ++z) {
77  for (size_t y = hasY * ng; y < ny - hasY * ng; ++y) {
78  for (size_t x = ng; x < nx - ng; ++x) {
79  interpolate<dimension>(viewOut, viewIn, x, y, z);
80  }
81  }
82  }
83  }
84 
85 
86 }
87 }
88 }
#define THROW(message)
Definition: Exception.hpp:27
void interpolate< 3 >(memory::View< real > &out, memory::View< const real > &in, size_t x, size_t y, size_t z)
Definition: interpolate.hpp:42
virtual alsfvm::shared_ptr< memory::Memory< real > > & getScalarMemoryArea(size_t index)
getScalarMemoryArea gets the scalar memory area (real)
Definition: Volume.cpp:107
The Volume class represents a volume (a collection of cells with values for each cell (eg...
Definition: Volume.hpp:30
virtual size_t getNumberOfVariables() const
getNumberOfVariables gets the number of variables used
Definition: Volume.cpp:83
virtual size_t getTotalNumberOfYCells() const
Definition: Volume.cpp:268
size_t nx
Definition: VolumeFactory.cpp:87
virtual size_t getTotalNumberOfZCells() const
Definition: Volume.cpp:275
virtual size_t getNumberOfXGhostCells() const
Definition: Volume.cpp:238
size_t ny
Definition: VolumeFactory.cpp:88
virtual size_t getNumberOfXCells() const
Definition: Volume.cpp:201
void interpolate(memory::View< real > &out, memory::View< const real > &in, size_t x, size_t y, size_t z)
Definition: View.hpp:32
size_t nz
Definition: VolumeFactory.cpp:89
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
virtual size_t getTotalNumberOfXCells() const
Definition: Volume.cpp:261
void interpolate< 1 >(memory::View< real > &out, memory::View< const real > &in, size_t x, size_t y, size_t z)
Definition: interpolate.hpp:29
void interpolate< 2 >(memory::View< real > &out, memory::View< const real > &in, size_t x, size_t y, size_t z)
Definition: interpolate.hpp:35