Loading...
Searching...
No Matches
redistributeLagrangian.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2015-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Description
28 Reading, reconstruct, redistribution of lagrangian fields.
29
30\*---------------------------------------------------------------------------*/
31
32#ifndef Foam_redistributeLagrangian_H
33#define Foam_redistributeLagrangian_H
34
37#include "fileOperation.H"
38
39// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40
41namespace Foam
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46// Read clouds (note: might not be present on all processors)
49(
50 const fvMesh& mesh,
51 const UList<word>& cloudNames,
52 const boolUList& haveClouds,
53 const wordRes& selectedFields
54)
55{
56 if (!cloudNames.empty())
57 {
58 (void)mesh.tetBasePtIs();
59 }
60
61 // Mixed exists/missing on various ranks?
62 // Avoid masterRead+broadcast (can cause blocking)
63
64 auto& handler = Foam::fileHandler();
65 const bool oldDistributed =
66 handler.distributed
67 (
68 !fileOperation::cacheLevel() || handler.distributed()
69 );
70
71
72 // Setup clouds
74
75 forAll(cloudNames, i)
76 {
77 const auto& cloudName = cloudNames[i];
78 //Pout<< "Loading cloud " << cloudName << endl;
79
80 auto& cloud = clouds.emplace_set(i, mesh, cloudName, false);
81
82 //for (passivePositionParticle& p : cloud)
83 //{
84 // Pout<< "Particle position:" << p.position()
85 // << " cell:" << p.cell()
86 // << " with cc:" << mesh.cellCentres()[p.cell()]
87 // << endl;
88 //}
89
90 IOobjectList cloudObjs(cloud, cloud.time().timeName());
91
93 (
94 cloud,
95 haveClouds.test(i),
96 cloudObjs,
97 selectedFields
98 );
99 }
100
101 // Restore distributed flag
102 handler.distributed(oldDistributed);
103
104 return clouds;
105}
106
107
108// Read clouds (note: might not be present on all processors)
109PtrList<unmappedPassivePositionParticleCloud>
111(
112 const fvMesh& mesh,
113 const wordRes& selectedFields
114)
115{
116 wordList cloudNames;
117 boolList haveClouds;
118 List<wordList> fieldNames;
119
120 // Find all cloudNames on all processors
122 (
123 mesh,
124 cloudNames,
125 haveClouds,
126 fieldNames
127 );
128
129 return readLagrangian(mesh, cloudNames, haveClouds, selectedFields);
130}
131
132
134(
135 autoPtr<parLagrangianDistributor>& distributorPtr,
136 const fvMesh& baseMesh,
137 const fvMesh& mesh,
138 const mapDistributePolyMesh& distMap,
139 const wordRes& selectedFields
140)
141{
142 // Clouds (note: might not be present on all processors)
143
144 wordList cloudNames;
145 boolList haveClouds;
146 List<wordList> fieldNames;
147
148 // Find all cloudNames on all processors
150 (
151 mesh,
152 cloudNames,
153 haveClouds,
154 fieldNames
155 );
156
157 if (cloudNames.empty())
158 {
159 // Nothing to do
160 return;
161 }
162
163 // Use existing or create distributor
164 if (!distributorPtr)
165 {
166 distributorPtr.reset
167 (
169 (
170 mesh,
171 baseMesh,
172 mesh.nCells(), // range of cell indices in clouds
173 distMap
174 //writeHandler // Which processors to write
175 )
176 );
177 }
178 const auto& distributor = *distributorPtr;
179
180 // Mixed exists/missing on various ranks?
181 // Avoid masterRead+broadcast (can cause blocking)
182
183 auto& handler = Foam::fileHandler();
184 const bool oldDistributed =
185 handler.distributed
186 (
187 !fileOperation::cacheLevel() || handler.distributed()
188 );
189
190 forAll(cloudNames, cloudi)
191 {
192 const word& cloudName = cloudNames[cloudi];
193
194 Info<< "Reconstructing lagrangian fields for cloud "
195 << cloudName << nl << endl;
196
197 autoPtr<mapDistributeBase> lagrangianMapPtr =
198 distributor.distributeLagrangianPositions
199 (
201 );
202
203 IOobjectList cloudObjs
204 (
205 mesh,
206 mesh.time().timeName(),
208 );
209
210 distributor.distributeAllFields
211 (
212 lagrangianMapPtr(),
213 cloudName,
214 haveClouds[cloudi],
215 cloudObjs,
216 selectedFields
217 );
218 }
220 // Restore distributed flag
221 handler.distributed(oldDistributed);
222}
223
224
226(
227 autoPtr<parLagrangianDistributor>& distributorPtr,
228 const fvMesh& mesh,
229 const label nOldCells,
230 const mapDistributePolyMesh& distMap,
231 PtrList<unmappedPassivePositionParticleCloud>& clouds
232)
233{
234 if (clouds.empty())
235 {
236 // Nothing to do
237 return;
238 }
239
240 // Use existing or create distributor
241 if (!distributorPtr)
242 {
243 distributorPtr.reset
244 (
246 (
247 mesh,
248 mesh,
249 nOldCells, // range of cell indices in clouds
250 distMap
251 )
252 );
253 }
254 const auto& distributor = *distributorPtr;
255
256 for (auto& cloud : clouds)
257 {
258 autoPtr<mapDistributeBase> lagrangianMapPtr =
259 distributor.distributeLagrangianPositions(cloud);
260
261 distributor.distributeAllStoredFields
262 (
263 lagrangianMapPtr(),
264 cloud
265 );
266 }
267}
268
269
270// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271
272} // End namespace Foam
273
274#endif
275
276// ************************************************************************* //
const word cloudName(propsDict.get< word >("cloud"))
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
T & emplace_set(const label i, Args &&... args)
Construct and set a new element at given position, (discard old element at that location).
Definition PtrListI.H:191
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition Time.C:714
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
bool test(const label i) const
Test bool value at specified position, always false for out-of-range access.
Definition UList.H:852
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Definition UList.H:701
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
Definition UPtrListI.H:99
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
Definition autoPtrI.H:37
A cloud is a registry collection of lagrangian particles.
Definition cloud.H:56
static const word prefix
The prefix to local: lagrangian.
Definition cloud.H:79
static int cacheLevel() noexcept
Return cache level.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
const Time & time() const
Return the top-level database.
Definition fvMesh.H:360
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
const Time & time() const noexcept
Return time registry.
Lagrangian field redistributor.
static label readAllFields(const passivePositionParticleCloud &cloud, const bool haveCloud, const IOobjectList &objects, const wordRes &selectedFields=wordRes())
Read and store all fields for known cloud field types.
static void findClouds(const fvMesh &, wordList &cloudNames, boolList &haveClouds, List< wordList > &objectNames)
Find all clouds (on all processors) and for each cloud all the objects. Result will be synchronised o...
label nCells() const noexcept
Number of mesh cells.
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
PtrList< unmappedPassivePositionParticleCloud > readLagrangian(const fvMesh &mesh, const UList< word > &cloudNames, const boolUList &haveClouds, const wordRes &selectedFields)
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
void reconstructLagrangian(autoPtr< parLagrangianDistributor > &distributorPtr, const fvMesh &baseMesh, const fvMesh &mesh, const mapDistributePolyMesh &distMap, const wordRes &selectedFields)
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
List< bool > boolList
A List of bools.
Definition List.H:60
UList< bool > boolUList
A UList of bools.
Definition UList.H:73
void redistributeLagrangian(autoPtr< parLagrangianDistributor > &distributorPtr, const fvMesh &mesh, const label nOldCells, const mapDistributePolyMesh &distMap, PtrList< unmappedPassivePositionParticleCloud > &clouds)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299