OpenLB 1.7
Loading...
Searching...
No Matches
particleStatistics.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 Nicolas Hafen, Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24
25
26#ifndef PARTICLE_STATISTICS_H
27#define PARTICLE_STATISTICS_H
28
29
30namespace olb {
31
32namespace particles {
33
34namespace statistics {
35
37template<typename T, typename S, typename PARTICLETYPE, typename F>
39 SuperParticleSystem<T, PARTICLETYPE>& sParticleSystem, std::vector<S>& data, int noSampledQuantities, F f, int root=0 )
40{
41 //Set number of quantities (including globiC at first position)
42 int noQ = noSampledQuantities + 1;
43 //Retrieve load balancer and set up samples vector
44 auto& loadBalancer = sParticleSystem.getSuperStructure().getLoadBalancer();
45 std::vector<S> samples(loadBalancer.size()*noQ);
46 //Iterate over particle systems
48 [&](ParticleSystem<T,PARTICLETYPE>& particleSystem, int iC, int globiC){
49 //Set index for samples array
50 int idx = iC*noQ;
51 samples[idx] = globiC;
52 //Perform requested sampling (assuming globiC at first pos)
53 f ( particleSystem, globiC, idx+1, samples );
54 });
55
56 //Execute gathering
57 const int numTasks = singleton::mpi().getSize();
58 const int recvBufSize = samples.size()*numTasks;
59 data.resize(recvBufSize);
60 int sendCount = samples.size();
61 int recvCounts[numTasks];
62 int displs[numTasks];
63 std::fill(recvCounts,&recvCounts[numTasks],sendCount);
64 std::generate(displs,&displs[numTasks],[&sendCount,n = 0] () mutable { return sendCount*n++; });
65#ifdef PARALLEL_MODE_MPI
66 singleton::mpi().gatherv<S>(samples.data(), sendCount, data.data(),
67 recvCounts, displs, root);
68#endif
69}
70
72template<typename T, typename PARTICLETYPE, typename PCONDITION = conditions::valid_particles>
73std::vector<std::size_t> gatherActivity(
75{
76 //Set sampling properties
77 unsigned noSampledQuantities = 2;
78 std::vector<std::size_t> dataV;
79 //Evaluate particle system statistics
80 evaluateParticleSystemStatistics( sParticleSystem, dataV, noSampledQuantities,
81 [](ParticleSystem<T,PARTICLETYPE>& particleSystem, int globiC, int idx, auto& samples){
82 //Introduce couters for sampled quantities
83 std::size_t noP = 0;
84 std::size_t noActive = 0;
85 //Iterate over particles
86 forParticlesInParticleSystem<T,PARTICLETYPE,PCONDITION>( particleSystem,
87 [&](Particle<T,PARTICLETYPE>& particle){
88 //Evaluate counter increment
89 if ( access::isActive(particle) ){ ++noActive; }
90 ++noP;
91 },globiC); //forParticlesInParticleSystem<T,PARTICLETYPE,PCONDITION>
92 //Update samples vector with counters
93 samples[idx+0] = noActive;
94 samples[idx+1] = noP;
95 });
96 //Return gathered dataV
97 return dataV;
98}
99
100
102template<typename T, typename PARTICLETYPE>
104 OstreamManager clout ( std::cout, "Activity" );
105 auto activityStatistics = gatherActivity( sParticleSystem );
106 unsigned noQ = 3;
107 for (int idx=0; idx<activityStatistics.size(); idx+=noQ ){
108 clout << "ParticleSystem " << activityStatistics[idx] << ":"
109 << " active=" << activityStatistics[idx+1]
110 << "/" << activityStatistics[idx+2]
111 << std::endl;
112 }
113}
114
115
116
117
118
119} //namespace statistics
120
121} //namespace particles
122
123} //namespace olb
124
125
126#endif
class for marking output with some text
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
SuperStructure< T, PARTICLETYPE::d > & getSuperStructure()
int getSize() const
Returns the number of processes.
void gatherv(T *sendBuf, int sendCount, T *recvBuf, int *recvCounts, int *displs, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Gather data from multiple processors to one processor.
bool isActive(Particle< T, PARTICLETYPE > particle)
void forSystemsInSuperParticleSystem(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, F f)
std::vector< std::size_t > gatherActivity(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem)
Gather number of active particles and total number for each cuboid.
void printActivityGathered(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem)
Print activity gathered a main processor.
void evaluateParticleSystemStatistics(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, std::vector< S > &data, int noSampledQuantities, F f, int root=0)
Evaluate particle statistics for each cuboid (each ParticleSystem)
MpiManager & mpi()
Top level namespace for all of OpenLB.