Peano 4
Loading...
Searching...
No Matches
ParticleSearchRadiusCalculation.cpph
Go to the documentation of this file.
2#include "tarch/logging/Log.h"
3
4template <typename Particle>
6 const std::list<Particle*>& localParticles,
7 const std::list<Particle*>& activeParticles,
8 int targetNumberOfNeighbourParticles,
9 double maxGrowthPerSweep,
10 double shrinkingFactor
11) {
12 assertion(shrinkingFactor < 1.0);
13 assertion(maxGrowthPerSweep > 1.0);
14
15 static tarch::logging::Log _log("swift2::kernels");
16
17 auto countParticlesWithinSearchRadius = [&](Particle* localParticle) -> int {
18 const double R2 = localParticle->getSearchRadius() * localParticle->getSearchRadius();
19 int interactingParticles = -1; // self-interaction will reset to 0
20 for (auto* activeParticle : activeParticles) {
21 double distanceSquared = tarch::la::norm2Squared(activeParticle->getX() - localParticle->getX());
22 if (distanceSquared <= R2) {
23 interactingParticles++;
24 }
25 assertion(interactingParticles >= 0);
26 return interactingParticles;
27 }
28 };
29
30 for (auto* localParticle : localParticles) {
31 int interactingParticles = countParticlesWithinSearchRadius(localParticle);
33 "adoptInteractionRadiusAndTriggerRerun(...)",
34 "particle " << localParticle->toString() << " has " << interactingParticles << " interacting neighbours"
35 );
36 if (interactingParticles < targetNumberOfNeighbourParticles) {
37 const double oldR = localParticle->getSearchRadius();
38 localParticle->setSearchRadius(oldR * maxGrowthPerSweep);
39 int newNumberOfInteractingParticles = countParticlesWithinSearchRadius(localParticle);
40 if (newNumberOfInteractingParticles > interactingParticles and newNumberOfInteractingParticles < targetNumberOfNeighbourParticles) {
42 "adoptInteractionRadiusAndTriggerRerun(...)",
43 "increasing the search radius of particle " << localParticle->toString(
44 ) << " did pay off, but there are still to few neighbours. Trigger re-analysis"
45 );
46 localParticle->getSpecies().setRerunPreviousGridSweep();
47 } else if (newNumberOfInteractingParticles > interactingParticles) {
49 "adoptInteractionRadiusAndTriggerRerun(...)",
50 "increasing the search radius of particle " << localParticle->toString() << " did pay off"
51 );
52 } else {
54 "adoptInteractionRadiusAndTriggerRerun(...)",
55 "increasing the search radius of particle " << localParticle->toString(
56 ) << " was useless, so keep old search radius"
57 );
58 localParticle->setSearchRadius(oldSearch);
59 }
60 } else if (interactingParticles > targetNumberOfNeighbourParticles) {
61 const double oldR = localParticle->getSearchRadius();
62 localParticle->setSearchRadius(oldR * shrinkingFactor);
63 int newNumberOfInteractingParticles = countParticlesWithinSearchRadius(localParticle);
64 if (newNumberOfInteractingParticles < targetNumberOfNeighbourParticles) {
66 "adoptInteractionRadiusAndTriggerRerun(...)",
67 "increasing the search radius of particle " << localParticle->toString(
68 ) << " was too aggressive, so roll back"
69 );
70 localParticle->setSearchRadius(oldR);
71 }
72 }
73 }
74}
#define assertion(expr)
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
Log Device.
Definition Log.h:516
void adoptInteractionRadiusAndTriggerRerun(const std::list< Particle * > &localParticles, const std::list< Particle * > &activeParticles, int targetNumberOfNeighbourParticles, double maxGrowthPerSweep=2.0, double shrinkingFactor=0.8)
This routine runs over all the local particles and tries to ensure that the number of particles equal...
Scalar norm2Squared(const Vector< Size, Scalar > &vector)
tarch::logging::Log _log("examples::unittests")