Peano 4
Loading...
Searching...
No Matches
FixedBoundary.cpp
Go to the documentation of this file.
1#include "FixedBoundary.h"
2
3
7 double maxV,
8 double maxDt,
9 double h,
10 const tarch::la::Vector<Dimensions, double>& domainOffset,
12 double relativeDomainHalo
13) {
14 static tarch::logging::Log _log( "swift2::boundaryconditions" );
17
18 assertion1( relativeDomainHalo>=0.0, relativeDomainHalo );
19 assertion1( relativeDomainHalo<=1.0, relativeDomainHalo );
20
21 const double domainHalo = relativeDomainHalo * h;
22
23 const double relativeBufferDueToTimeStepping = 0.5 * h + maxV * maxDt;
24 for (int d=0; d<Dimensions; d++) {
25 // reposition particle left
26 if ( tarch::la::smallerEquals( particleX(d), domainOffset(d) ) ) {
27 logWarning( "getUpdateDueToFixedBoundaryCondition()", "reset particle at " << particleX << " as it penetrates left boundary along axis " << d );
28 newX(d) = domainOffset(d);
29 }
30
31 // reposition particle right
32 if ( tarch::la::greaterEquals( particleX(d), domainOffset(d) + domainSize(d)) ) {
33 logWarning( "getUpdateDueToFixedBoundaryCondition()", "reset particle at " << particleX << " as it penetrates right boundary along axis " << d );
34 newX(d) = domainOffset(d) + domainSize(d);
35 }
36
37 // damp velocity left
38 if (
39 tarch::la::smallerEquals(particleX(d), domainOffset(d) + relativeBufferDueToTimeStepping)
40 and
41 particleV(d)<0.0
42 ) {
43 double scaleOriginalVelocity = (particleX(d) - domainOffset(d)) / relativeBufferDueToTimeStepping;
44 assertion5(scaleOriginalVelocity>=0.0, scaleOriginalVelocity, particleX, domainOffset, relativeBufferDueToTimeStepping, h );
45 assertion5(scaleOriginalVelocity<=1.0, scaleOriginalVelocity, particleX, domainOffset, relativeBufferDueToTimeStepping, h );
46 newV(d) = scaleOriginalVelocity * particleV(d);
47 }
48
49
50 // damp velocity right
51 if (
52 tarch::la::greaterEquals(particleX(d), domainOffset(d) + domainSize(d) - relativeBufferDueToTimeStepping)
53 and
54 particleV(d)>0.0
55 ) {
56 double scaleOriginalVelocity = (domainOffset(d) + domainSize(d) - particleX(d)) / relativeBufferDueToTimeStepping;
57 assertion5(scaleOriginalVelocity>=0.0, scaleOriginalVelocity, particleX, domainOffset, relativeBufferDueToTimeStepping, h );
58 assertion5(scaleOriginalVelocity<=1.0, scaleOriginalVelocity, particleX, domainOffset, relativeBufferDueToTimeStepping, h );
59 newV(d) = scaleOriginalVelocity * particleV(d);
60 }
61 }
62
63 return {newX, newV};
64}
65
#define assertion1(expr, param)
#define assertion5(expr, param0, param1, param2, param3, param4)
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:440
Log Device.
Definition Log.h:516
std::pair< tarch::la::Vector< Dimensions, double >, tarch::la::Vector< Dimensions, double > > getUpdateDueToFixedBoundaryCondition(const tarch::la::Vector< Dimensions, double > &particleX, const tarch::la::Vector< Dimensions, double > &particleV, double maxV, double maxDt, double h, const tarch::la::Vector< Dimensions, double > &domainOffset, const tarch::la::Vector< Dimensions, double > &domainSize, double relativeDomainHalo)
Determine updated position and velocity due to boundary conditions.
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
tarch::logging::Log _log("examples::unittests")
Simple vector class.
Definition Vector.h:134