Peano 4
Loading...
Searching...
No Matches
particles.cpph
Go to the documentation of this file.
3
4
5template <typename Iterator>
6Iterator toolbox::particles::particleIsDuplicate(const typename Iterator::value_type& particle, Iterator begin, const Iterator& end) {
7 static tarch::logging::Log _log( "toolbox::particles" );
8 while (begin != end) {
9 if (tarch::la::equals((*begin)->getX(), particle->getX(), SpatialDuplicateTolerance)) {
10 logDebug( "particleIsDuplicate(...)", "particles " << particle->toString() << " and " << (*begin)->toString() << " are the same" );
11 return begin;
12 }
13 begin++;
14 }
15 return begin;
16}
17
18
19template <typename Particle>
21 const Particle& particle, const tarch::la::Vector<Dimensions, double>& domainOffset, const tarch::la::Vector<Dimensions, double>& domainWidth
22) {
23 return particle.getParallelState() == Particle::ParallelState::Local and tarch::la::allGreaterEquals(particle.getX(), domainOffset)
24 and tarch::la::allSmallerEquals(particle.getX(), domainOffset + domainWidth);
25}
26
27
28template <typename Particle, typename ParticleSet>
31 const std::vector<Particle*>& newParticles,
33 int spacetreeId
34) {
35 for (auto& p : newParticles) {
36 insertParticleIntoCell(marker, p, fineGridVertices);
37 }
38}
39
40
41template <typename Particle, typename ParticleSet>
43 const peano4::datamanagement::CellMarker& marker, Particle* newParticle, peano4::datamanagement::VertexEnumerator<ParticleSet>& fineGridVertices, int spacetreeId
44) {
45 static tarch::logging::Log _log("toolbox::particles");
46 std::bitset<Dimensions> targetVertex;
47 for (int d = 0; d < Dimensions; d++) {
49 tarch::la::greaterEquals(newParticle->getX()(d), marker.x()(d) - marker.h()(d) / 2.0), marker.toString(), newParticle->toString(), marker.x()(d) - marker.h()(d) / 2.0, d
50 );
52 tarch::la::smallerEquals(newParticle->getX()(d), marker.x()(d) + marker.h()(d) / 2.0), marker.toString(), newParticle->toString(), marker.x()(d) + marker.h()(d) / 2.0, d
53 );
54 targetVertex[d] = newParticle->getX()(d) > marker.x()(d);
55 }
56
57 assertion3( tarch::la::smaller(2.0 * newParticle->getSearchRadius(), tarch::la::min(marker.h())), marker.toString(), newParticle->toString(), spacetreeId );
58
59 newParticle->setParallelState(Particle::ParallelState::Local);
60 newParticle->setCellH(marker.h());
61
62 const int linearisedTargetVertex = targetVertex.to_ulong();
63
65 "insertParticleIntoCell(...)",
66 "assign particle "
67 << newParticle->toString() << " to vertex " << linearisedTargetVertex << " in cell " << marker.toString()
68 << " (vertex=" << fineGridVertices(targetVertex.to_ulong()).toString() << ")"
69 );
70 fineGridVertices(linearisedTargetVertex).addParticle(newParticle);
71
73 toolbox::particles::assignmentchecks::pruneTypeName<Particle>(),
74 newParticle->getX(),
75 true, // is local
76 marker.x() - 0.5 * marker.h() + tarch::la::multiplyComponents(tarch::la::Vector<Dimensions, double>(targetVertex), marker.h()),
77 marker.h(),
78 spacetreeId,
79 "toolbox::particles::insertParticleIntoCell()",
80 true
81 );
82}
#define assertion4(expr, param0, param1, param2, param3)
#define assertion3(expr, param0, param1, param2)
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
Log Device.
Definition Log.h:516
bool allGreaterEquals(const Vector< Size, Scalar > &lhs, const Scalar &cmp, const Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
static bool smaller(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE) InlineMethod
Smaller operator for floating point values.
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
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, bool isLocal, const tarch::la::Vector< Dimensions, double > &vertexX, const tarch::la::Vector< Dimensions, double > &vertexH, int treeId, const std::string &trace, bool particleIsNew=false)
Assign a particle to a vertex.
constexpr double SpatialDuplicateTolerance
Default tolerance to decide when two particles are the same.
Definition particles.h:18
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.
Definition particles.cpph:6
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.
tarch::logging::Log _log("examples::unittests")
Vertex enumerator within array.
Simple vector class.
Definition Vector.h:134