OpenLB 1.7
Loading...
Searching...
No Matches
statistics.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 Adrian Kummerlaender
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#ifndef GPU_CUDA_STATISTICS_HH
25#define GPU_CUDA_STATISTICS_HH
26
27#include "statistics.h"
28
29#include <thrust/reduce.h>
30#include <thrust/execution_policy.h>
31
32namespace olb {
33
34namespace gpu {
35
36namespace cuda {
37
39template <typename T, typename U>
40struct pair {
43
45 first{},
46 second{}
47 { }
48
50 first{init},
51 second{init}
52 { }
53
54 pair(T a, U b) any_platform:
55 first{a},
56 second{b}
57 { }
58
59};
60
62template <typename T>
67
69 const second_argument_type& rhs) const {
70 return {lhs.first < rhs.first ? rhs.first : lhs.first,
71 lhs.second + rhs.second};
72 }
73};
74
75}
76
77}
78
79template <typename T, typename DESCRIPTOR>
82{
83 if (!blockLattice.statisticsEnabled()) {
84 return;
85 }
86
88 auto& statisticGenerated = blockLattice.template getField<descriptors::STATISTIC_GENERATED>();
89 auto& statistic = blockLattice.template getField<descriptors::STATISTIC>();
90 std::size_t nCells = thrust::reduce(thrust::device,
91 statisticGenerated[0].deviceData(),
92 statisticGenerated[0].deviceData() + blockLattice.getNcells(),
93 T{0},
94 thrust::plus<T>());
95 T rhoSum = thrust::reduce(thrust::device,
96 statistic[0].deviceData(),
97 statistic[0].deviceData() + blockLattice.getNcells(),
98 T{0},
99 thrust::plus<T>());
100 auto [maxU, uSqrSum] = thrust::reduce(thrust::device,
101 statistic[1].deviceData(),
102 statistic[1].deviceData() + blockLattice.getNcells(),
103 gpu::cuda::pair{std::numeric_limits<T>::min(), T{0}},
105
106 typename LatticeStatistics<T>::Aggregatable statistics{
107 .nCells = nCells,
108 .avRho = rhoSum,
109 .avEnergy = uSqrSum,
110 .maxU = maxU
111 };
112 blockLattice.getStatistics().incrementStats(statistics);
113
114 blockLattice.getStatistics().reset();
115}
116
117
118}
119
120#endif
bool statisticsEnabled() const
std::size_t getNcells() const
Get number of cells.
Implementation of BlockLattice on a concrete PLATFORM.
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78
Function object for simulateneously computing maximum and sum in a single thrust::reduce.
Definition statistics.hh:63
__device__ result_type operator()(const first_argument_type &lhs, const second_argument_type &rhs) const
Definition statistics.hh:68
Plain pair type with single-value constructor for use in gpu::cuda::maximum_and_plus.
Definition statistics.hh:40
pair(T init) any_platform
Definition statistics.hh:49
pair(T a, U b) any_platform
Definition statistics.hh:54
pair() any_platform
Definition statistics.hh:44