Peano
Loading...
Searching...
No Matches
particles.cpph
Go to the documentation of this file.
3#include "peano4/utils/Loop.h"
4
7
8
9#include "internal.h"
10
11
12template <typename Iterator>
14 const typename Iterator::value_type& particle,
15 Iterator begin,
16 const Iterator& end
17) {
18 static tarch::logging::Log _log("toolbox::particles");
19 while (begin != end) {
21 (*begin)->getX(),
22 particle->getX(),
24 )) {
26 "particleIsDuplicate(...)",
27 "particles "
28 << particle->toString() << " and " << (*begin)->toString()
29 << " are the same"
30 );
31 return begin;
32 }
33 begin++;
34 }
35 return begin;
36}
37
38
39template <typename Particle>
41 const Particle& particle,
42 const tarch::la::Vector<Dimensions, double>& domainOffset,
44) {
45 return particle.getParallelState() == Particle::ParallelState::Local
46 and tarch::la::allGreaterEquals(particle.getX(), domainOffset)
47 and tarch::la::
48 allSmallerEquals(particle.getX(), domainOffset + domainWidth);
49}
50
51
52template <typename Particle, typename ParticleSet>
55 const std::vector<Particle*>& newParticles,
57 int spacetreeId
58) {
59 for (auto& p : newParticles) {
60 insertParticleIntoCell(marker, p, fineGridVertices);
61 }
62}
63
64
67 const std::bitset<Dimensions>& assignedVertex,
68 auto& particle
69) {
70 const tarch::la::Vector< Dimensions, double > vertexPositionOfAssignedVertex =
71 marker.getOffset()
72 +
75 marker.h()
76 );
78 vertexPositionOfAssignedVertex,
79 marker.h(),
80 particle
81 );
82}
83
84
87 auto& particle
88) {
90 marker.x(),
91 marker.h(),
92 particle
93 );
94}
95
96
100 auto& particle
101) {
102 std::bitset<TwoPowerD> result = 0;
103
104 dfor2(k)
105 tarch::la::Vector< Dimensions, double > adjacentCellCentre =
106 x - 0.5 * h
107 +
109 tarch::la::convertScalar< double >(k),
110 h
111 );
112
114 particle.getX(),
115 adjacentCellCentre,
116 h,
118 );
120
121 particle.setContainedInAdjacentCell( result );
122}
123
124
125template <typename Particle, typename ParticleSet>
128 Particle* newParticle,
130 int spacetreeId
131) {
132 static tarch::logging::Log _log("toolbox::particles");
133 std::bitset<Dimensions> targetVertex;
134 for (int d = 0; d < Dimensions; d++) {
137 newParticle->getX()(d),
138 marker.x()(d) - marker.h()(d) / 2.0
139 ),
140 marker.toString(),
141 newParticle->toString(),
142 marker.x()(d) - marker.h()(d) / 2.0,
143 d
144 );
147 newParticle->getX()(d),
148 marker.x()(d) + marker.h()(d) / 2.0
149 ),
150 marker.toString(),
151 newParticle->toString(),
152 marker.x()(d) + marker.h()(d) / 2.0,
153 d
154 );
155 targetVertex[d] = newParticle->getX()(d) > marker.x()(d);
156 }
157
159 tarch::la::
160 smaller(2.0 * newParticle->getSearchRadius(), tarch::la::min(marker.h())),
161 marker.toString(),
162 newParticle->toString(),
163 spacetreeId
164 );
165
166 newParticle->setParallelState(Particle::ParallelState::Local);
167 newParticle->setCellH(marker.h());
168 updateContainedInAdjacentCellProperty( marker, targetVertex, *newParticle );
169
170 const int linearisedTargetVertex = targetVertex.to_ulong();
171
172 logDebug(
173 "insertParticleIntoCell(...)",
174 "assign particle "
175 << newParticle->toString() << " to vertex " << linearisedTargetVertex
176 << " in cell " << marker.toString() << " (vertex="
177 << fineGridVertices(targetVertex.to_ulong()).toString() << ")"
178 );
179 fineGridVertices(linearisedTargetVertex).addParticle(newParticle);
180
181#if PeanoDebug > 0
182 int partID = newParticle->getPartid();
183#else
184 int partID = -1;
185#endif
186
188 vertexX = marker.x() - 0.5 * marker.h()
191 marker.h()
192 );
193
195 toolbox::particles::assignmentchecks::pruneTypeName<Particle>(),
196 newParticle->getX(),
197 partID,
198 true, // is always local, we set that a few lines above
199 vertexX,
200 marker.h(), // vertexH
201 spacetreeId,
202 "toolbox::particles::insertParticleIntoCell()",
203 vertexX,
204 marker.h(),
205 true // particle is new
206 );
207}
#define assertion4(expr, param0, param1, param2, param3)
#define assertion3(expr, param0, param1, param2)
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
#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
Log Device.
Definition Log.h:516
tarch::logging::Log _log("exahype2::fv")
My collection of tiny vector operations.
bool allGreaterEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
constexpr double NUMERICAL_ZERO_DIFFERENCE
Definition Scalar.h:17
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool allSmallerEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.
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).
void assignParticleToVertex(const std::string &particleName, const tarch::la::Vector< Dimensions, double > &particleX, const int particleID, bool isLocal, const tarch::la::Vector< Dimensions, double > &vertexX, const tarch::la::Vector< Dimensions, double > &vertexH, int treeId, const std::string &trace, const tarch::la::Vector< Dimensions, double > &prevVertexX, const tarch::la::Vector< Dimensions, double > &prevVertexH, bool particleIsNew=false, bool reassignmentOnSameTreeDepthAllowed=false)
Assign a particle to a vertex.
double relativeGrabOwnershipSpatialSortingTolerance(const ::peano4::datamanagement::VertexMarker &marker)
Definition internal.cpp:23
constexpr double SpatialDuplicateTolerance
Default tolerance to decide when two particles are the same.
Definition particles.h:18
void updateContainedInAdjacentCellProperty(const peano4::datamanagement::CellMarker &marker, const std::bitset< Dimensions > &assignedVertex, auto &particle)
Update helper flag per particle for cell.
void insertParticleIntoCell(const peano4::datamanagement::CellMarker &marker, Particle *newParticles, peano4::datamanagement::VertexEnumerator< ParticleSet > &fineGridVertices, int spacetreeId)
Insert particle into cell.
Iterator particleIsDuplicate(const typename Iterator::value_type &particle, Iterator begin, const Iterator &end)
Check if there's already a particle at p's position in the set.
void insertParticlesIntoCell(const peano4::datamanagement::CellMarker &marker, const std::vector< Particle * > &newParticles, peano4::datamanagement::VertexEnumerator< ParticleSet > &fineGridVertices, int spacetreeId)
Insert particle into a cell.
bool particleWillStayWithinComputationalDomain(const Particle &particle, const tarch::la::Vector< Dimensions, double > &domainOffset, const tarch::la::Vector< Dimensions, double > &domainWidth)
Return true if and only if.
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 enumerator within array.
Vertex marker to provide information about selected vertex.
Simple vector class.
Definition Vector.h:150