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-------------------------------------------------------------------------------
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
38// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39
40namespace Foam
41{
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45// Read clouds (note: might not be present on all processors)
46PtrList<unmappedPassivePositionParticleCloud>
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)
96PtrList<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);
107
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 (
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 (
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,
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 (
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// ************************************************************************* //
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
const T * set(const label i) const
Definition: PtrList.H:138
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
Definition: UPtrListI.H:113
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
Definition: autoPtrI.H:117
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:60
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:87
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Lagrangian field redistributor.
static void findClouds(const fvMesh &, wordList &cloudNames, List< wordList > &objectNames)
static label readAllFields(const passivePositionParticleCloud &cloud, const IOobjectList &objects, const wordRes &selectedFields=wordRes())
Read and store all fields for known cloud field types.
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:906
label nCells() const noexcept
Number of mesh cells.
passivePositionParticleCloud but with autoMap and writing disabled. Only used for its objectRegistry ...
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
word timeName
Definition: getTimeIndex.H:3
Namespace for OpenFOAM.
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:372
PtrList< unmappedPassivePositionParticleCloud > readLagrangian(const fvMesh &mesh, const wordList &cloudNames, const wordRes &selectedFields)
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:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
const word cloudName(propsDict.get< word >("cloud"))