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 -------------------------------------------------------------------------------
11 License
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 
27 Description
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 
41 namespace Foam
42 {
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 // Read clouds (note: might not be present on all processors)
49 (
50  const fvMesh& mesh,
51  const wordList& cloudNames,
52  const boolUList& haveClouds,
53  const wordRes& selectedFields
54 )
55 {
57 
58  if (!cloudNames.empty())
59  {
60  (void)mesh.tetBasePtIs();
61  }
62 
63  // Mixed exists/missing on various ranks?
64  // Avoid masterRead+broadcast (can cause blocking)
65 
66  auto& handler = Foam::fileHandler();
67  const bool oldDistributed =
68  handler.distributed
69  (
70  !fileOperation::cacheLevel() || handler.distributed()
71  );
72 
73 
74  // Setup clouds
75  forAll(cloudNames, i)
76  {
77  //Pout<< "Loading cloud " << cloudNames[i] << endl;
78  clouds.set
79  (
80  i,
81  new unmappedPassivePositionParticleCloud(mesh, cloudNames[i], false)
82  );
83 
84  //for (passivePositionParticle& p : clouds[i]))
85  //{
86  // Pout<< "Particle position:" << p.position()
87  // << " cell:" << p.cell()
88  // << " with cc:" << mesh.cellCentres()[p.cell()]
89  // << endl;
90  //}
91 
92  IOobjectList cloudObjs(clouds[i], clouds[i].time().timeName());
93 
95  (
96  clouds[i],
97  haveClouds[i],
98  cloudObjs,
99  selectedFields
100  );
101  }
102 
103  // Restore distributed flag
104  handler.distributed(oldDistributed);
105 
106  return clouds;
107 }
108 
109 
110 // Read clouds (note: might not be present on all processors)
111 PtrList<unmappedPassivePositionParticleCloud>
113 (
114  const fvMesh& mesh,
115  const wordRes& selectedFields
116 )
117 {
118  wordList cloudNames;
119  boolList haveClouds;
120  List<wordList> fieldNames;
121 
122  // Find all cloudNames on all processors
124  (
125  mesh,
126  cloudNames,
127  haveClouds,
128  fieldNames
129  );
131  return readLagrangian(mesh, cloudNames, haveClouds, selectedFields);
132 }
133 
134 
136 (
137  autoPtr<parLagrangianDistributor>& distributorPtr,
138  const fvMesh& baseMesh,
139  const fvMesh& mesh,
140  const mapDistributePolyMesh& distMap,
141  const wordRes& selectedFields
142 )
143 {
144  // Clouds (note: might not be present on all processors)
145 
146  wordList cloudNames;
147  boolList haveClouds;
148  List<wordList> fieldNames;
149 
150  // Find all cloudNames on all processors
152  (
153  mesh,
154  cloudNames,
155  haveClouds,
156  fieldNames
157  );
158 
159  if (cloudNames.empty())
160  {
161  // Nothing to do
162  return;
163  }
164 
165  // Use existing or create distributor
166  if (!distributorPtr)
167  {
168  distributorPtr.reset
169  (
170  new parLagrangianDistributor
171  (
172  mesh,
173  baseMesh,
174  mesh.nCells(), // range of cell indices in clouds
175  distMap
176  //writeHandler // Which processors to write
177  )
178  );
179  }
180  const auto& distributor = *distributorPtr;
181 
182  // Mixed exists/missing on various ranks?
183  // Avoid masterRead+broadcast (can cause blocking)
184 
185  auto& handler = Foam::fileHandler();
186  const bool oldDistributed =
187  handler.distributed
188  (
189  !fileOperation::cacheLevel() || handler.distributed()
190  );
191 
192  forAll(cloudNames, cloudi)
193  {
194  const word& cloudName = cloudNames[cloudi];
195 
196  Info<< "Reconstructing lagrangian fields for cloud "
197  << cloudName << nl << endl;
198 
199  autoPtr<mapDistributeBase> lagrangianMapPtr =
200  distributor.distributeLagrangianPositions
201  (
202  cloudName
203  );
204 
205  IOobjectList cloudObjs
206  (
207  mesh,
208  mesh.time().timeName(),
210  );
211 
212  distributor.distributeAllFields
213  (
214  lagrangianMapPtr(),
215  cloudName,
216  haveClouds[cloudi],
217  cloudObjs,
218  selectedFields
219  );
220  }
221 
222  // Restore distributed flag
223  handler.distributed(oldDistributed);
224 }
225 
226 
228 (
229  autoPtr<parLagrangianDistributor>& distributorPtr,
230  const fvMesh& mesh,
231  const label nOldCells,
232  const mapDistributePolyMesh& distMap,
233  PtrList<unmappedPassivePositionParticleCloud>& clouds
234 )
235 {
236  if (clouds.empty())
237  {
238  // Nothing to do
239  return;
240  }
241 
242  // Use existing or create distributor
243  if (!distributorPtr)
244  {
245  distributorPtr.reset
246  (
247  new parLagrangianDistributor
248  (
249  mesh,
250  mesh,
251  nOldCells, // range of cell indices in clouds
252  distMap
253  )
254  );
255  }
256  const auto& distributor = *distributorPtr;
257 
258  for (auto& cloud : clouds)
259  {
260  autoPtr<mapDistributeBase> lagrangianMapPtr =
261  distributor.distributeLagrangianPositions(cloud);
262 
263  distributor.distributeAllStoredFields
264  (
265  lagrangianMapPtr(),
266  cloud
267  );
268  }
269 }
270 
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 } // End namespace Foam
275 
276 #endif
277 
278 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:899
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
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.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
passivePositionParticleCloud but with autoMap and writing disabled. Only used for its objectRegistry ...
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
word timeName
Definition: getTimeIndex.H:3
dynamicFvMesh & mesh
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...
void redistributeLagrangian(autoPtr< parLagrangianDistributor > &distributorPtr, const fvMesh &mesh, const label nOldCells, const mapDistributePolyMesh &distMap, PtrList< unmappedPassivePositionParticleCloud > &clouds)
const word cloudName(propsDict.get< word >("cloud"))
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
void reconstructLagrangian(autoPtr< parLagrangianDistributor > &distributorPtr, const fvMesh &baseMesh, const fvMesh &mesh, const mapDistributePolyMesh &distMap, const wordRes &selectedFields)
static int cacheLevel() noexcept
Return cache level.
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
List< word > wordList
List of word.
Definition: fileName.H:59
label nCells() const noexcept
Number of mesh cells.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< bool > boolList
A List of bools.
Definition: List.H:60
PtrList< unmappedPassivePositionParticleCloud > readLagrangian(const fvMesh &mesh, const wordList &cloudNames, const boolUList &haveClouds, const wordRes &selectedFields)
Namespace for OpenFOAM.
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:79