Alsvinn  0.5.3
The fast FVM simulator with UQ support
displacements.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 
18 #include <vector>
19 #include "alsfvm/types.hpp"
21 
22 namespace alsfvm {
23 namespace mpi {
24 namespace cartesian {
46 inline std::vector<int> computeDisplacements(int side, int dimensions,
47  ivec3 numberOfCellsPerDirection,
48  int ghostCells, int baseOffset) {
49 
50  const int numberOfSegments = computeNumberOfSegments(side, dimensions,
51  numberOfCellsPerDirection);
52 
53  if (side % 2 ==
54  1) { // we should subtract the offset since we are on a "right side/top side/back side"
55  baseOffset *= -1;
56  }
57 
58  std::vector<int> displacements(numberOfSegments, 0);
59 
60  for (int i = 0; i < numberOfSegments; ++i) {
61  if (dimensions == 1) {
62  displacements[i] = side * (numberOfCellsPerDirection.x - ghostCells)
63  + baseOffset;
64 
65  } else if (dimensions == 2) {
66  if ( side < 2) {
67 
68  if (side > 0 || i > 0) {
69  displacements[i] = (numberOfCellsPerDirection.x);
70  }
71 
72  if (i == 0 && side == 1) {
73  displacements[i] -= ghostCells;
74  }
75 
76  if (i == 0) {
77  displacements[i] += baseOffset;
78  }
79 
80  if (i > 0) {
81  displacements[i] += displacements[i - 1];
82  }
83 
84  } else {
85  displacements[i] += baseOffset * numberOfCellsPerDirection.x;
86 
87  if (side > 2) { // bottom side does not have any displacement
88  // we only have two segments in dimension 2 for the y-direction,
89  // and the first one is 0 displacement, therefore, we do not add
90  // displacements[i-1]
91  displacements[i] += numberOfCellsPerDirection.x * (numberOfCellsPerDirection.y)
92  - numberOfCellsPerDirection.x * ghostCells;
93  }
94 
95  }
96  } else {
97  if ( side < 2) {
98  if (i == 0) {
99  displacements[i] += baseOffset;
100  }
101 
102  if (side > 0 || i > 0) {
103  displacements[i] += (numberOfCellsPerDirection.x);
104  }
105 
106  if (i == 0 && side == 1) {
107  displacements[i] -= ghostCells;
108  }
109 
110  if (i > 0) {
111  displacements[i] += displacements[i - 1];
112  }
113 
114  } else if (side < 4) {
115  if (i == 0) {
116  displacements[i] += baseOffset * numberOfCellsPerDirection.x;
117  }
118 
119  if (side > 2 || i > 0) {
120  displacements[i] += numberOfCellsPerDirection.x * (numberOfCellsPerDirection.y);
121  }
122 
123  if (i == 0 && side == 3) {
124  displacements[i] -= ghostCells * numberOfCellsPerDirection.x;
125  }
126 
127  if (i > 0) {
128  displacements[i] += displacements[i - 1];
129  }
130 
131  } else {
132 
133  displacements[i] += numberOfCellsPerDirection.x *
134  numberOfCellsPerDirection.y * (baseOffset);
135 
136  // There is only one segment in the z direction, and it only needs
137  // displacement if it is the back side
138  if (side == 5) {
139  displacements[i] += numberOfCellsPerDirection.x *
140  numberOfCellsPerDirection.y * (numberOfCellsPerDirection.z) -
141  numberOfCellsPerDirection.x * numberOfCellsPerDirection.y * ghostCells;
142  }
143 
144  }
145  }
146  }
147 
148  return displacements;
149 }
150 }
151 }
152 }
T z
Definition: vec3.hpp:28
Definition: vec3.hpp:25
int computeNumberOfSegments(int side, int dimensions, ivec3 numberOfCellsPerDirection)
Definition: number_of_segments.hpp:39
std::vector< int > computeDisplacements(int side, int dimensions, ivec3 numberOfCellsPerDirection, int ghostCells, int baseOffset)
Definition: displacements.hpp:46
T y
Definition: vec3.hpp:27
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
T x
Definition: vec3.hpp:26