OpenLB 1.8.1
Loading...
Searching...
No Matches
superLatticePointExtraction.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2025 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 CORE_SUPER_LATTICE_POINT_EXTRACTION_HH
25#define CORE_SUPER_LATTICE_POINT_EXTRACTION_HH
26
28
29namespace olb {
30
31template <typename T, typename DESCRIPTOR, typename FUNCTOR>
32void SuperLatticePointExtraction<T,DESCRIPTOR,FUNCTOR>::updateExtractionResultD(
33 FieldArrayD<T,DESCRIPTOR,Platform::CPU_SISD,typename FUNCTOR::result_field>& resultD)
34{
35 LoadBalancer<T>& load = _sLattice.getLoadBalancer();
36 std::map<int,int> rankLocalPointsIndex;
37 for (const auto& [iC, iExtracted, physR] : _rankLocalPoints) {
38 auto& block = _sampleD.getBlock(load.loc(iC));
39 auto iPoint = rankLocalPointsIndex[iC]++;
40 auto point = block.get(iPoint);
41
42 resultD.setField(iExtracted, point.template getField<typename FUNCTOR::result_field>());
43 }
44}
45
46template <typename T, typename DESCRIPTOR, typename FUNCTOR>
49 const std::vector<Vector<T,DESCRIPTOR::d>>& points)
50 : _sLattice(sLattice),
51 _sampleD(sLattice.getLoadBalancer()),
52 _couplingO(PointExtractionO<FUNCTOR>{},
53 names::Lattice{}, sLattice,
54 names::Points{}, _sampleD),
55 _extractionPointD(points.size()),
56 _extractionResultD(points.size())
57{
58 const auto& geometry = _sLattice.getCuboidDecomposition();
59 LoadBalancer<T>& load = _sLattice.getLoadBalancer();
60
61 for (int iC=0; iC < geometry.size(); ++iC) {
62 _rankLocalPointsSize[iC] = 0;
63 }
64
65 for (std::size_t iG=0; iG < points.size(); ++iG) {
66 const auto& physR = points[iG];
67 _extractionPointD.setField(iG, physR);
68 if (auto iC = geometry.getC(physR)) {
69 if (load.isLocal(*iC)) {
70 _rankLocalPoints.emplace_back(*iC, iG, physR);
71 _rankLocalPointsSize[*iC]++;
72 }
73 }
74 }
75
76 std::map<int,int> rankLocalPointsIndex;
77 for (auto [iC, size] : _rankLocalPointsSize) {
78 if (load.isLocal(iC)) {
79 auto& block = _sampleD.getBlock(load.loc(iC));
80 block.resize({size,1,1});
81 rankLocalPointsIndex[iC] = 0;
82 }
83 }
84
85 for (auto& [iC, iG, physR] : _rankLocalPoints) {
86 auto& block = _sampleD.getBlock(load.loc(iC));
87 auto iPoint = rankLocalPointsIndex[iC]++;
88 auto point = block.get(iPoint);
89 point.template setField<fields::PHYS_R>(physR);
90 }
91
92 _sampleD.setProcessingContext(ProcessingContext::Simulation);
93}
94
95template <typename T, typename DESCRIPTOR, typename FUNCTOR>
97{
98 _couplingO.execute();
99 _sampleD.setProcessingContext(ProcessingContext::Evaluation);
100
101#ifdef PARALLEL_MODE_MPI
103 _extractionResultD.getSize());
104
105 updateExtractionResultD(localResultD);
106
107 for (unsigned iD=0; iD < DESCRIPTOR::template size<typename FUNCTOR::result_field>(); ++iD) {
108 singleton::mpi().reduce(localResultD[iD].data(),
109 _extractionResultD[iD].data(),
110 _extractionResultD[iD].size(),
111 MPI_SUM);
112 }
113#else
114 updateExtractionResultD(_extractionResultD);
115#endif
116}
117
118}
119
120#endif
SoA storage for instances of a single FIELD.
SuperLatticePointExtraction(SuperLattice< T, DESCRIPTOR > &sLattice, const std::vector< Vector< T, DESCRIPTOR::d > > &points)
Super class maintaining block lattices for a cuboid decomposition.
Plain old scalar vector.
void reduce(T &sendVal, T &recvVal, MPI_Op op, int root=0, MPI_Comm=MPI_COMM_WORLD)
Reduction operation toward one processor.
MpiManager & mpi()
Top level namespace for all of OpenLB.
@ Simulation
Data available on host for e.g. functor evaluation.