Peano 4
Loading...
Searching...
No Matches
BoundaryConditions.cpp
Go to the documentation of this file.
1// This file is part of the ExaHyPE2 project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
4
6#include "peano4/utils/Loop.h"
7#include "PatchUtils.h"
8
9
11 std::function< void(
12 const double* __restrict__ Qinside,
13 double * __restrict__ Qoutside,
16 double t,
17 double dt,
18 int normal
19 ) > boundaryCondition,
22 double t,
23 double dt,
24 int numberOfVolumesPerAxisInPatch,
25 int overlap,
26 int unknowns,
27 int faceNumber,
28 double* __restrict__ Q
29) {
30 static tarch::logging::Log _log( "exahype2::fv" );
31
32 auto serialisePatchIndex = [&](tarch::la::Vector<Dimensions,int> overlapCell) {{
33 int base = 1;
34 int result = 0;
35 for (int d=0; d<Dimensions; d++) {{
36 result += overlapCell(d) * base;
37 if (d==faceNumber % Dimensions) {{
38 base *= 2*overlap;
39 }}
40 else {{
41 base *= numberOfVolumesPerAxisInPatch;
42 }}
43 }}
44 return result;
45 }};
46
47 logTraceInWith4Arguments( "applyBoundaryConditions(...)", faceCentre, patchSize, numberOfVolumesPerAxisInPatch, faceNumber);
48
49 tarch::la::Vector<Dimensions,double> volumeH = exahype2::fv::getVolumeSize(patchSize, numberOfVolumesPerAxisInPatch);
50 tarch::la::Vector<Dimensions,double> faceOffset = faceCentre - 0.5 * patchSize;
51 faceOffset(faceNumber%Dimensions) += 0.5 * patchSize(faceNumber%Dimensions);
52
53 dfore(volume,numberOfVolumesPerAxisInPatch,faceNumber % Dimensions,0) {
54 tarch::la::Vector<Dimensions,int> insideVolume = volume;
55 tarch::la::Vector<Dimensions,int> outsideVolume = volume;
56 tarch::la::Vector<Dimensions,double> x = faceOffset + tarch::la::multiplyComponents( tarch::la::convertScalar<double>(volume)+tarch::la::Vector<Dimensions,double>(0.5), volumeH);
57
58 x(faceNumber%Dimensions) -= 0.5 * volumeH(faceNumber%Dimensions);
59
60 for (int layer=0; layer<overlap; layer++){
61 if (faceNumber<Dimensions) {
62 insideVolume(faceNumber % Dimensions) = overlap-layer;
63 outsideVolume(faceNumber % Dimensions) = overlap-1-layer;
64
65 int insideVolumeSerialised = serialisePatchIndex(insideVolume);
66 int outsideVolumeSerialised = serialisePatchIndex(outsideVolume);
67
69 "applyBoundaryConditions(...)",
70 insideVolume << "->" << outsideVolume << " (" << insideVolumeSerialised << "->" << outsideVolumeSerialised << "): " <<
71 "(" << *(Q + insideVolumeSerialised * unknowns) << ",...)^T->" <<
72 "(" << *(Q + outsideVolumeSerialised * unknowns) << ",...)^T"
73 );
74
75 boundaryCondition(
76 Q + insideVolumeSerialised * unknowns,
77 Q + outsideVolumeSerialised * unknowns,
78 x, volumeH, t, dt, faceNumber
79 );
80 }
81 else {
82 insideVolume(faceNumber % Dimensions) = layer+overlap-1;
83 outsideVolume(faceNumber % Dimensions) = layer+overlap;
84
85 int insideVolumeSerialised = serialisePatchIndex(insideVolume);
86 int outsideVolumeSerialised = serialisePatchIndex(outsideVolume);
87
89 "applyBoundaryConditions(...)",
90 insideVolume << "->" << outsideVolume << " (" << insideVolumeSerialised << "->" << outsideVolumeSerialised << "): " <<
91 "(" << *(Q + insideVolumeSerialised * unknowns) << ",...)^T->" <<
92 "(" << *(Q + outsideVolumeSerialised * unknowns) << ",...)^T"
93 );
94
95 boundaryCondition(
96 Q + insideVolumeSerialised * unknowns,
97 Q + outsideVolumeSerialised * unknowns,
98 x, volumeH, t, dt, faceNumber
99 );
100 }
101 }
102 }
103
104 logTraceOut( "applyBoundaryConditions(...)" );
105}
106
107
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
#define logTraceOut(methodName)
Definition Log.h:379
#define logTraceInWith4Arguments(methodName, argument0, argument1, argument2, argument3)
Definition Log.h:373
#define dfore(counter, max, dim, value)
This is an exclusive d-dimensional for loop.
Definition Loop.h:937
Log Device.
Definition Log.h:516
static tarch::la::Vector< 2, double > getVolumeSize(const tarch::la::Vector< 2, double > &h, int numberOfVolumesPerAxisInPatch)
We need this routine within vectorised and GPUised code.
Definition PatchUtils.h:24
void applyBoundaryConditions(std::function< void(const double *__restrict__ Qinside, double *__restrict__ Qoutside, const tarch::la::Vector< Dimensions, double > &faceCentre, const tarch::la::Vector< Dimensions, double > &volumeH, double t, double dt, int normal) > boundaryCondition, const tarch::la::Vector< Dimensions, double > &faceCentre, const tarch::la::Vector< Dimensions, double > &patchSize, double t, double dt, int numberOfVolumesPerAxisInPatch, int overlap, int unknowns, int faceNumber, double *__restrict__ Q)
Apply boundary conditions.
Matrix< Rows, Cols, Scalar > multiplyComponents(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
tarch::logging::Log _log("examples::unittests")
Simple vector class.
Definition Vector.h:134