Peano 4
Loading...
Searching...
No Matches
MultiscaleTransitions.cpp
Go to the documentation of this file.
2
5#include "peano4/utils/Loop.h"
6
7
8namespace {
9 tarch::logging::Log _log("toolbox::particles");
10} // namespace
11
12
13double toolbox::particles::relativeSpatialOwnershipTolerance(const ::peano4::datamanagement::CellMarker& marker) {
14 return internal::relativeReleaseOwnershipSpatialSortingTolerance(marker) * tarch::la::NUMERICAL_ZERO_DIFFERENCE;
15}
16
17double toolbox::particles::internal::relativeReleaseOwnershipSpatialSortingTolerance(const ::peano4::datamanagement::VertexMarker& marker) {
19}
20
21
22double toolbox::particles::internal::relativeReleaseOwnershipSpatialSortingTolerance(const ::peano4::datamanagement::CellMarker& marker) {
24}
25
26
27double toolbox::particles::internal::relativeGrabOwnershipSpatialSortingTolerance(const ::peano4::datamanagement::VertexMarker& marker) {
29}
30
31
32double toolbox::particles::internal::relativeGrabOwnershipSpatialSortingTolerance(const ::peano4::datamanagement::CellMarker& marker) {
34}
35
36
37bool toolbox::particles::internal::fitsIntoLevel(double searchRadius, const ::peano4::datamanagement::CellMarker& marker) {
38 return tarch::la::greaterEquals(tarch::la::min(marker.h()), 2.0 * searchRadius);
39}
40
41
42bool toolbox::particles::internal::fitsIntoLevel(double searchRadius, const ::peano4::datamanagement::VertexMarker& marker) {
43 return tarch::la::greaterEquals(tarch::la::min(marker.h()), 2.0 * searchRadius);
44}
45
46
49) {
50 std::bitset<Dimensions> destAssociation;
51
52 // marker.x() gives me the centre of the cell
53 for (int d = 0; d < Dimensions; d++) {
54 destAssociation[d] = tarch::la::greaterEquals(x(d), cellCentre(d));
55 }
56
57 return destAssociation;
58}
59
60
62 bool isLocal, double searchRadius, const tarch::la::Vector<Dimensions, double>& x, const peano4::datamanagement::VertexMarker marker
63) {
64 const double tolerance = internal::relativeReleaseOwnershipSpatialSortingTolerance(marker) * tarch::la::NUMERICAL_ZERO_DIFFERENCE;
65 if (not isLocal) {
67 }
68 else if (internal::fitsIntoLevel(searchRadius, marker) and marker.isContainedInAdjacentCells(x, 0.5, tolerance)) {
70 }
71 else if (
72 marker.isParentCellLocal()
73 and
74 peano4::datamanagement::CellMarker::isContained(x, marker.getInvokingParentCellsCentre(), marker.h() * 3.0, tolerance)
75 ) {
76 std::bitset<Dimensions> target = internal::getParticleAssociationWithinCell(x, marker.getInvokingParentCellsCentre());
77 if (
78 marker.isParentVertexLocal(target.to_ulong())
79 and
81 ) {
82 return target.to_ulong();
83 } else {
85 }
86 }
87 else {
89 }
90}
91
92
94 bool isLocal, double searchRadius, const tarch::la::Vector<Dimensions, double>& x, const peano4::datamanagement::CellMarker& marker, int numberOfVertexWithinCell
95) {
96 if (not isLocal) {
98 } else {
99 const std::bitset<Dimensions> currentAssociation = numberOfVertexWithinCell;
100 const std::bitset<Dimensions> destAssociation = internal::getParticleAssociationWithinCell(x, marker.x());
101
102 // marker.x() gives me the centre of the cell
103 bool remainsOnSameLevel = internal::fitsIntoLevel(searchRadius, marker);
104 for (int d = 0; d < Dimensions; d++) {
105 remainsOnSameLevel &= tarch::la::smallerEquals(std::abs(x(d) - marker.x()(d)), marker.h()(d) * ReleaseOwnershipSpatialSortingTolerance);
106 }
107
108 if (remainsOnSameLevel and currentAssociation == destAssociation) {
110 } else if (remainsOnSameLevel) {
111 logDebug(
112 "getParticleReassociationInstructionWithinCellWithIntraCellReassignment(...)",
113 "reassign particle at "
114 << x << " within cell " << marker.toString() << " which had been associated with vertex " << currentAssociation << " but belongs to " << destAssociation
115 );
116 return destAssociation.to_ulong();
117 } else if (not marker.isParentLocal()) {
119 } else {
120 logDebug(
121 "getParticleReassociationInstructionWithinCellWithIntraCellReassignment(...)",
122 "lift particle at " << x << " from cell " << marker.toString() << " as difference is " << (x - marker.x())
123 );
124
125 const std::bitset<Dimensions> coarseDestAssociation = internal::getParticleAssociationWithinCell(x, marker.getInvokingParentCellsCentre());
126
127 return coarseDestAssociation.to_ulong() + TwoPowerD;
128 }
129 }
130 return -65536;
131}
132
133
135 bool result = internal::fitsIntoLevel(searchRadius, marker)
136 and marker.isContainedInAdjacentCells(x, 0.5, internal::relativeGrabOwnershipSpatialSortingTolerance(marker) * tarch::la::NUMERICAL_ZERO_DIFFERENCE);
137
139 not (result and liftParticleAssociatedWithVertex(true, searchRadius, x, marker)==ParticleReassociationInstruction_SieveGlobally),
140 searchRadius,
141 x,
142 marker.toString()
143 );
144
145 return result;
146}
147
148
150 bool belongsIntoNeighbouringCells = marker.isContainedInAdjacentCells(
151 x, 0.5, internal::relativeGrabOwnershipSpatialSortingTolerance(marker) * tarch::la::NUMERICAL_ZERO_DIFFERENCE
152 );
153
154 bool fitsIntoCurrentMeshLevel = internal::fitsIntoLevel(searchRadius, marker);
155 bool willNotBeDroppedFurther = not internal::fitsIntoLevel(searchRadius * 3.0, marker) or not marker.hasBeenRefined();
156
157 return belongsIntoNeighbouringCells and fitsIntoCurrentMeshLevel and willNotBeDroppedFurther;
158}
159
160
162 return (marker.hasBeenRefined() or marker.willBeRefined()) and internal::fitsIntoLevel(searchRadius * 3.0, marker);
163}
164
165
167 return (marker.hasBeenRefined() or marker.willBeRefined()) and internal::fitsIntoLevel(searchRadius * 3.0, marker);
168}
169
170
172 std::bitset<TwoPowerD> result = 0;
173
174 dfor2(k) {
177 adjacentCellCentre = marker.x() + tarch::la::multiplyComponents(tarch::la::convertScalar<double>(adjacentCell) + tarch::la::Vector<Dimensions, double>(-0.5), marker.h());
179 x, adjacentCellCentre, marker.h(), internal::relativeGrabOwnershipSpatialSortingTolerance(marker) * tarch::la::NUMERICAL_ZERO_DIFFERENCE
180 );
181 }
183
184 return result;
185}
#define assertion3(expr, param0, param1, param2)
we integrate over each cell and then take the sum across each of the cells We also consider the terms that enter the f$ k
#define TwoPowerD
Definition Globals.h:19
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
#define dfor2(counter)
Shortcut For dfor(counter,2)
Definition Loop.h:906
#define enddforx
I prefer to use this macro for dforx instead of a closing bracket as many syntax parser fail otherwis...
Definition Loop.h:928
Log Device.
Definition Log.h:516
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
constexpr double NUMERICAL_ZERO_DIFFERENCE
Definition Scalar.h:17
double max(double a, double b, double c)
I need the maximum of three values all the time, to I decided to write a function for this.
Definition Scalar.cpp:8
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Matrix< Rows, Cols, Scalar > multiplyComponents(const Matrix< Rows, X, Scalar > &lhs, const Matrix< X, Cols, Scalar > &rhs)
Scalar min(const Vector< Size, Scalar > &vector)
Returns the element with minimal value (NOT absolute value).
std::bitset< Dimensions > getParticleAssociationWithinCell(const tarch::la::Vector< Dimensions, double > &x, const tarch::la::Vector< Dimensions, double > &cellCentre)
Find out which vertex should hold a particle.
double relativeGrabOwnershipSpatialSortingTolerance(const ::peano4::datamanagement::VertexMarker &marker)
double relativeReleaseOwnershipSpatialSortingTolerance(const ::peano4::datamanagement::VertexMarker &marker)
bool fitsIntoLevel(double searchRadius, const ::peano4::datamanagement::CellMarker &marker)
bool particleWillBeDroppedFurther(const Particle &particle, const peano4::datamanagement::CellMarker &marker)
Will the particle be dropped further throughout the traversal.
constexpr int ParticleReassociationInstruction_SieveGlobally
ParticleReassociationInstruction getParticleReassociationInstructionWithinCellWithIntraCellReassignment(const Particle &p, const peano4::datamanagement::CellMarker &marker, int numberOfVertexWithinCell)
If you use this operation, you can be sure that every particle is associated to the right vertex afte...
bool sieveParticle(const Particle &particle, const peano4::datamanagement::VertexMarker &marker)
A particle is to be sieved into a vertex if.
bool particleAssignedToVertexWillBeLocal(const tarch::la::Vector< Dimensions, double > &x, const peano4::datamanagement::VertexMarker &marker)
Definition particles.cpp:6
bool dropParticle(const Particle &particle, const peano4::datamanagement::VertexMarker &marker)
double relativeSpatialOwnershipTolerance(const ::peano4::datamanagement::CellMarker &marker)
Ownership tolerance.
ParticleReassociationInstruction liftParticleAssociatedWithVertex(const Particle &p, const peano4::datamanagement::VertexMarker marker)
Take particle from current vertex and lift it or keep it local.
std::bitset< TwoPowerD > getAdjacentCellsOwningParticle(const tarch::la::Vector< Dimensions, double > &x, const peano4::datamanagement::VertexMarker &marker)
Find out which adjacent cell will hold a particle.
constexpr double ReleaseOwnershipSpatialSortingTolerance
Sorting tolerance.
constexpr double GrabOwnershipSpatialSortingTolerance
constexpr int ParticleReassociationInstruction_Keep
tarch::logging::Log _log("examples::unittests")
bool isContained(const tarch::la::Vector< Dimensions, double > &x, double tolerance=tarch::la::NUMERICAL_ZERO_DIFFERENCE) const
Is x contained within cell identified by marker object.
Vertex marker to provide information about selected vertex.
Simple vector class.
Definition Vector.h:134