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-2022 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 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 // Read clouds (note: might not be present on all processors)
48 (
49  const fvMesh& mesh,
50  const wordList& cloudNames,
51  const wordRes& selectedFields
52 )
53 {
55 
56  if (!cloudNames.empty())
57  {
58  (void)mesh.tetBasePtIs();
59  }
60 
61  // Setup clouds
62  forAll(cloudNames, i)
63  {
64  //Pout<< "Loading cloud " << cloudNames[i] << endl;
65  clouds.set
66  (
67  i,
68  new unmappedPassivePositionParticleCloud(mesh, cloudNames[i], false)
69  );
70 
71  //for (passivePositionParticle& p : clouds[i]))
72  //{
73  // Pout<< "Particle position:" << p.position()
74  // << " cell:" << p.cell()
75  // << " with cc:" << mesh.cellCentres()[p.cell()]
76  // << endl;
77  //}
78 
79  IOobjectList cloudObjs(clouds[i], clouds[i].time().timeName());
80 
81  //Pout<< "Found cloud objects:" << cloudObjs.names() << endl;
82 
84  (
85  clouds[i],
86  cloudObjs,
87  selectedFields
88  );
89  }
90 
91  return clouds;
92 }
93 
94 
95 // Read clouds (note: might not be present on all processors)
96 PtrList<unmappedPassivePositionParticleCloud>
98 (
99  const fvMesh& mesh,
100  const wordRes& selectedFields
101 )
102 {
103  wordList cloudNames;
104  List<wordList> fieldNames;
105  // Find all cloudNames on all processors
106  parLagrangianDistributor::findClouds(mesh, cloudNames, fieldNames);
108  return readLagrangian(mesh, cloudNames, selectedFields);
109 }
110 
111 
113 (
114  autoPtr<parLagrangianDistributor>& distributorPtr,
115  const fvMesh& baseMesh,
116  const fvMesh& mesh,
117  const mapDistributePolyMesh& distMap,
118  const wordRes& selectedFields
119 )
120 {
121  // Clouds (note: might not be present on all processors)
122 
123  wordList cloudNames;
124  List<wordList> fieldNames;
125  // Find all cloudNames on all processors
126  parLagrangianDistributor::findClouds(mesh, cloudNames, fieldNames);
127 
128  if (cloudNames.empty())
129  {
130  // Nothing to do
131  return;
132  }
133 
134  // Use existing or create distributor
135  if (!distributorPtr)
136  {
137  distributorPtr.reset
138  (
139  new parLagrangianDistributor
140  (
141  mesh,
142  baseMesh,
143  mesh.nCells(), // range of cell indices in clouds
144  distMap
145  )
146  );
147  }
148  const auto& distributor = *distributorPtr;
149 
150  for (const word& cloudName : cloudNames)
151  {
152  Info<< "Reconstructing lagrangian fields for cloud "
153  << cloudName << nl << endl;
154 
155  IOobjectList cloudObjs
156  (
157  mesh,
158  mesh.time().timeName(),
160  );
161 
162  autoPtr<mapDistributeBase> lagrangianMapPtr =
163  distributor.distributeLagrangianPositions
164  (
165  cloudName
166  );
167 
168  distributor.distributeAllFields
169  (
170  lagrangianMapPtr(),
171  cloudName,
172  cloudObjs,
173  selectedFields
174  );
175  }
176 }
177 
178 
180 (
181  autoPtr<parLagrangianDistributor>& distributorPtr,
182  const fvMesh& mesh,
183  const label nOldCells,
184  const mapDistributePolyMesh& distMap,
185  PtrList<unmappedPassivePositionParticleCloud>& clouds
186 )
187 {
188  if (clouds.empty())
189  {
190  // Nothing to do
191  return;
192  }
193 
194  // Use existing or create distributor
195  if (!distributorPtr)
196  {
197  distributorPtr.reset
198  (
199  new parLagrangianDistributor
200  (
201  mesh,
202  mesh,
203  nOldCells, // range of cell indices in clouds
204  distMap
205  )
206  );
207  }
208  const auto& distributor = *distributorPtr;
209 
210  for (auto& cloud : clouds)
211  {
212  autoPtr<mapDistributeBase> lagrangianMapPtr =
213  distributor.distributeLagrangianPositions(cloud);
214 
215  distributor.distributeAllStoredFields
216  (
217  lagrangianMapPtr(),
218  cloud
219  );
220  }
221 }
222 
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 } // End namespace Foam
227 
228 #endif
229 
230 // ************************************************************************* //
static void findClouds(const fvMesh &, wordList &cloudNames, List< wordList > &objectNames)
Find all clouds (on all processors) and for each cloud all the objects. Result will be synchronised o...
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:894
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:632
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:362
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:414
word timeName
Definition: getTimeIndex.H:3
dynamicFvMesh & mesh
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
void reconstructLagrangian(autoPtr< parLagrangianDistributor > &distributorPtr, const fvMesh &baseMesh, const fvMesh &mesh, const mapDistributePolyMesh &distMap, const wordRes &selectedFields)
static word timeName(const scalar t, const int precision=precision_)
Return time name of given scalar time formatted with the given precision.
Definition: Time.C:770
List< word > wordList
List of word.
Definition: fileName.H:58
PtrList< unmappedPassivePositionParticleCloud > readLagrangian(const fvMesh &mesh, const wordList &cloudNames, const wordRes &selectedFields)
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:79
messageStream Info
Information stream (stdout output on master, null elsewhere)
static label readAllFields(const passivePositionParticleCloud &cloud, const IOobjectList &objects, const wordRes &selectedFields=wordRes())
Read and store all fields for known cloud field types.
Namespace for OpenFOAM.
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:93