Alsvinn  0.5.3
The fast FVM simulator with UQ support
ValueAtBoundary.hpp
Go to the documentation of this file.
1 #pragma once
3 #include "alsfvm/memory/View.hpp"
4 #include "alsfvm/types.hpp"
5 #ifdef __CUDA_ARCH__
6  #include <cuda.h>
7 #endif
8 #include <stdio.h>
9 namespace alsfvm {
10 namespace boundary {
11 
13 template<Type BoundaryType>
15 public:
16 
17 };
18 
19 template<>
21 public:
22  template<class T>
24  const memory::View<T>& view,
25  ivec3 discretePosition,
26  ivec3 numberOfCellsWithoutGhostCells,
27  ivec3 numberGhostCells) {
28 
29  const auto positivePosition = makePositive(discretePosition,
30  numberOfCellsWithoutGhostCells);
31 
32  const auto moduloPosition = ivec3{positivePosition.x % numberOfCellsWithoutGhostCells.x,
33  positivePosition.y % numberOfCellsWithoutGhostCells.y,
34  positivePosition.z % numberOfCellsWithoutGhostCells.z};
35 
36  const auto positionPeriodic = moduloPosition + numberGhostCells;
37 
38  return view.at(view.index(positionPeriodic.x, positionPeriodic.y,
39  positionPeriodic.z));
40  }
41 
42 private:
43  static __device__ __host__ int makePositive(int position, int N) {
44  while (position < 0) {
45  position += N;
46  }
47 
48  return position;
49 
50  }
51  static __device__ __host__ ivec3 makePositive(ivec3 position,
52  ivec3 numberOfCells) {
53  return ivec3{makePositive(position.x, numberOfCells.x),
54  makePositive(position.y, numberOfCells.y),
55  makePositive(position.z, numberOfCells.z)};
56 
57  }
58 };
59 
60 
61 
62 template<>
64 public:
65  template<class T>
67  const memory::View<T>& view,
68  ivec3 discretePosition,
69  ivec3 numberOfCellsWithoutGhostCells,
70  ivec3 numberGhostCells) {
71  // fixes for cuda.
72  using namespace std;
73 
74  const auto innerPosition = ivec3{
75  max(0, min(discretePosition.x, numberOfCellsWithoutGhostCells.x - 1)),
76  max(0, min(discretePosition.y, numberOfCellsWithoutGhostCells.y - 1)),
77  max(0, min(discretePosition.z, numberOfCellsWithoutGhostCells.z - 1))
78  };
79 
80  const auto positionWithGhostCells = innerPosition + numberGhostCells;
81 #if 0
82  printf("N: %02d, gc: %02d, given: %02d, wo gc: %02d, inner: %02d, index: %02d, value: %f\n",
83  numberOfCellsWithoutGhostCells.x, numberGhostCells.x,
84  discretePosition.x,
85  discretePosition.x - numberGhostCells.x,
86  innerPosition.x, view.index(positionWithGhostCells.x, positionWithGhostCells.y,
87  positionWithGhostCells.z), view.at(view.index(positionWithGhostCells.x,
88  positionWithGhostCells.y,
89 
90  positionWithGhostCells.z)));
91 #endif
92  return view.at(view.index(positionWithGhostCells.x, positionWithGhostCells.y,
93  positionWithGhostCells.z));
94  }
95 
96 };
97 } // namespace boundary
98 } // namespace alsfvm
T z
Definition: vec3.hpp:28
__device__ static __host__ T getValueAtBoundary(const memory::View< T > &view, ivec3 discretePosition, ivec3 numberOfCellsWithoutGhostCells, ivec3 numberGhostCells)
Definition: ValueAtBoundary.hpp:66
__device__ __host__ size_t index(size_t x, size_t y, size_t z) const
index computes the linear index of the given cell
Definition: View.hpp:116
#define __host__
Definition: types.hpp:46
__device__ __host__ T & at(size_t x, size_t y, size_t z)
at returns a reference to the element at the given location
Definition: View.hpp:65
Neumann boundary.
Definition: Type.hpp:27
__device__ static __host__ T getValueAtBoundary(const memory::View< T > &view, ivec3 discretePosition, ivec3 numberOfCellsWithoutGhostCells, ivec3 numberGhostCells)
Definition: ValueAtBoundary.hpp:23
Periodic boundary conditions.
Definition: Type.hpp:24
__device__ __host__ int makePositive(int position, int N)
Definition: structure_common.hpp:27
Simple templated class to get the value at the boundary.
Definition: ValueAtBoundary.hpp:14
#define __device__
Definition: types.hpp:45
Definition: View.hpp:32
T y
Definition: vec3.hpp:27
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
T x
Definition: vec3.hpp:26