Peano
Loading...
Searching...
No Matches
Tracer.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
3#include "Tracer.h"
4
5#include "PatchUtils.h"
6#include "peano4/utils/Loop.h"
7#include "tarch/logging/Log.h"
8
11 int voxelsPerAxis,
13) {
15
16 assertion(voxelsPerAxis > 0);
17 double cartesianMeshH = marker.h()(0) / voxelsPerAxis;
18
19 for (int d = 0; d < Dimensions; d++) {
20 double positionWithinPatch = particleX(d) - marker.getOffset()(d);
21 result(d) = static_cast<int>(std::floor(positionWithinPatch / cartesianMeshH));
22 result(d) = std::max(0, result(d));
23 result(d) = std::min(voxelsPerAxis - 1, result(d));
24 }
25
26 return result;
27}
28
31 int voxelsPerAxis,
33) {
35
36 assertion3(voxelsPerAxis>=2, marker, voxelsPerAxis, particleX);
37 double cartesianMeshH = marker.h()(0) / voxelsPerAxis;
38
39 for (int d = 0; d < Dimensions; d++) {
40 double biasedPositionWithinPatch = particleX(d) - marker.getOffset()(d) - cartesianMeshH / 2.0;
41 result(d) = static_cast<int>(std::floor(biasedPositionWithinPatch / cartesianMeshH));
42 result(d) = std::max(0, result(d));
43 result(d) = std::min(voxelsPerAxis - 2, result(d));
44 }
45
46 return result;
47}
48
51 int voxelsPerAxis,
52 int unknownsPerVoxel,
53 const double* __restrict__ Q,
55 int unknown
56) {
58 marker, voxelsPerAxis, particleX
59 );
60
61 int voxelIndex = peano4::utils::dLinearised(voxel, voxelsPerAxis);
62
63 return Q[voxelIndex * unknownsPerVoxel + unknown];
64}
65
68 int voxelsPerAxis,
69 int unknownsPerVoxel,
70 const double* __restrict__ Q,
72 int unknown
73) {
74 static tarch::logging::Log _log( "exahype2::fv::internal" );
75 tarch::la::Vector<Dimensions, int> biasedVoxel = mapBiasedParticleOntoVoxel(marker, voxelsPerAxis, particleX);
76
77 double h = getVolumeLength(marker.h(), voxelsPerAxis);
78
79 double result = 0.0;
80 dfor2(k)
81 tarch::la::Vector<Dimensions, int> currentVoxel = biasedVoxel + k;
82 tarch::la::Vector<Dimensions, double> currentVoxelX = getVolumeCentre(
83 marker.x(), marker.h(), voxelsPerAxis, currentVoxel
84 );
85 int currentVoxelIndex = peano4::utils::dLinearised(currentVoxel, voxelsPerAxis);
86 double weight = 1.0;
87 for (int d = 0; d < Dimensions; d++) {
88 double relativeDistance = std::abs(currentVoxelX(d) - particleX(d)) / h;
89 if (particleX(d) < currentVoxelX(d) and currentVoxel(d) == 0) {
90 weight = 1.0;
91 }
92 else if (particleX(d) > currentVoxelX(d) and currentVoxel(d) == voxelsPerAxis - 1) {
93 weight = 1.0;
94 } else if (relativeDistance < 1.0) {
95 weight *= (1.0 - relativeDistance);
96 } else {
97 weight = 0.0;
98 }
99 assertion3( tarch::la::smallerEquals(weight, 1.0), weight, k, relativeDistance );
100 }
101 if (weight > 0.0) {
102 result += weight * Q[currentVoxelIndex * unknownsPerVoxel + unknown];
103 }
105 //if (unknown==0){
106 // //std::cout << "exahype2::fv::internal::projectValueOntoParticle_piecewiseLinear(): Q_0(should close to 1.0 always)=" << result <<std::endl;
107 // logInfo( "projectValueOntoParticle_piecewiseLinear(...)", "particle x=" << ::toString(particleX) << ", marker=" << marker.toString()
108 // << ", biasedVoxel=" << ::toString(biasedVoxel)<<", result=" << result );
109 //}
110
111 return result;
112}
#define assertion3(expr, param0, param1, param2)
#define assertion(expr)
#define dfor2(counter)
Shortcut For dfor(counter,2)
Definition Loop.h:911
#define enddforx
I prefer to use this macro for dforx instead of a closing bracket as many syntax parser fail otherwis...
Definition Loop.h:933
tarch::logging::Log _log("::")
Log Device.
Definition Log.h:516
double projectValueOntoParticle_piecewiseConstant(const peano4::datamanagement::CellMarker &marker, int voxelsPerAxis, int unknownsPerVoxel, const double *__restrict__ Q, const tarch::la::Vector< Dimensions, double > &particleX, int unknown)
Project one quantity from the patch data onto the particle.
Definition Tracer.cpp:49
double projectValueOntoParticle_piecewiseLinear(const peano4::datamanagement::CellMarker &marker, int voxelsPerAxis, int unknownsPerVoxel, const double *__restrict__ Q, const tarch::la::Vector< Dimensions, double > &particleX, int unknown)
Definition Tracer.cpp:66
tarch::la::Vector< Dimensions, int > mapParticleOntoVoxel(const peano4::datamanagement::CellMarker &marker, int voxelsPerAxis, const tarch::la::Vector< Dimensions, double > &particleX)
Assume that we have a particle suspended in a cell.
Definition Tracer.cpp:9
tarch::la::Vector< Dimensions, int > mapBiasedParticleOntoVoxel(const peano4::datamanagement::CellMarker &marker, int voxelsPerAxis, const tarch::la::Vector< Dimensions, double > &particleX)
Similar to mapParticleOntoVoxel() but this time, we always take the biased voxel to the left.
Definition Tracer.cpp:29
double getVolumeLength(const tarch::la::Vector< 2, double > &h, int numberOfVolumesPerAxisInPatch)
With GCC 10, it was impossible to return/copy the vector class.
CPUGPUMethod int dLinearised(const tarch::la::Vector< Dimensions, int > &counter, int max)
Map d-dimensional vector onto integer index.
Definition Loop.cpp:106
CF abs(const CF &cf)
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Simple vector class.
Definition Vector.h:134