parPointFieldDistributor.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) 2022-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::parPointFieldDistributor
28 
29 Description
30  Distributor/redistributor for point fields,
31  uses a two (or three) stage construction.
32 
33  The inconvenient multi-stage construction is needed since the
34  pointMesh is directly associated with a polyMesh, which will probably
35  have changed while creating the target mesh. This means that it is
36  necessary to save the size of the source mesh and all of its
37  patch meshPoints prior to making any changes (eg, creating the target
38  mesh).
39 
40  -# Create with specified source mesh
41  -# Save the meshPoints (per boundary) for the source mesh
42  -# Attach a target mesh and mesh distribution
43  -# Map the point fields
44  .
45 
46  Runs in parallel. Redistributes from srcMesh to tgtMesh.
47 
48 SourceFiles
49  parPointFieldDistributor.C
50  parPointFieldDistributorTemplates.C
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef Foam_parPointFieldDistributor_H
55 #define Foam_parPointFieldDistributor_H
56 
57 #include "PtrList.H"
58 #include "pointMesh.H"
59 #include "pointFieldsFwd.H"
60 #include "Switch.H"
61 
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 
64 namespace Foam
65 {
66 
67 // Forward Declarations
68 class mapDistributePolyMesh;
69 class mapDistributeBase;
70 class IOobjectList;
71 
72 /*---------------------------------------------------------------------------*\
73  Class parPointFieldDistributor Declaration
74 \*---------------------------------------------------------------------------*/
75 
77 {
78  // Private Data
79 
80  //- The source mesh reference
81  const pointMesh& srcMesh_;
82 
83  //- Number of points in the old (source) mesh
84  const label nOldPoints_;
85 
86  //- The pointPatch mesh points
87  PtrList<labelList> patchMeshPoints_;
88 
89  //- The target (destination) mesh reference
90  refPtr<pointMesh> tgtMeshRef_;
91 
92  //- Distribution map reference
94 
95  //- Point patch mappers
96  PtrList<mapDistributeBase> patchPointMaps_;
97 
98  //- Storage for dummy handler (when using bool control)
99  refPtr<fileOperation> dummyHandler_;
100 
101  //- Write control via a file handler
102  refPtr<fileOperation>& writeHandler_;
103 
104  //- Write control as a bool
105  Switch isWriteProc_;
106 
107 
108 public:
109 
110  //- Output verbosity when writing
111  static int verbose_;
112 
113 
114  // Generated Methods
115 
116  //- No copy construct
118 
119  //- No copy assignment
120  void operator=(const parPointFieldDistributor&) = delete;
121 
122 
123  // Constructors
124 
125  //- Basic construction
126  //
127  // \param srcMesh The source pointMesh
128  // \param savePoints Call saveMeshPoints() immediately
129  // \param isWriteProc Tagged for output writing (on this proc)
130  explicit parPointFieldDistributor
131  (
132  const pointMesh& srcMesh,
133  const bool savePoints, // normally false
134  const bool isWriteProc
135  );
136 
137  //- Basic construction
138  //
139  // \param srcMesh The source pointMesh
140  // \param savePoints Call saveMeshPoints() immediately
141  // \param writeHandler Valid for output writing (on this proc)
142  explicit parPointFieldDistributor
143  (
144  const pointMesh& srcMesh,
145  const bool savePoints, // normally false
146  refPtr<fileOperation>& writeHandler
147  );
148 
149  //- Full construction of source/target
150  //
151  // \param srcMesh The source pointMesh
152  // \param tgtMesh The target pointMesh
153  // \param distMap The distribution map
154  // \param savePoints Call saveMeshPoints() immediately
155  // \param isWriteProc Tagged for output writing (on this proc)
156  explicit parPointFieldDistributor
157  (
158  const pointMesh& srcMesh,
159  const pointMesh& tgtMesh,
160  const mapDistributePolyMesh& distMap,
161  const bool savePoints, // normally false
162  const bool isWriteProc
163  );
164 
165  //- Full construction of source/target
166  //
167  // \param srcMesh The source pointMesh
168  // \param tgtMesh The target pointMesh
169  // \param distMap The distribution map
170  // \param savePoints Call saveMeshPoints() immediately
171  // \param writeHandler Valid for output writing (on this proc)
172  explicit parPointFieldDistributor
173  (
174  const pointMesh& srcMesh,
175  const pointMesh& tgtMesh,
176  const mapDistributePolyMesh& distMap,
177  const bool savePoints, // normally false
178  refPtr<fileOperation>& writeHandler
179  );
180 
181 
182  // Member Functions
183 
184  //- True if meshPoints (per boundary) for the source mesh
185  //- have been saved
186  bool hasMeshPoints() const;
187 
188  //- True if patch maps (per boundary) exist
189  bool hasPatchPointMaps() const;
190 
191  //- True if a target mesh/distribution map has been attached
192  bool hasTarget() const;
193 
194  //- Clear out meshPoints (per boundary) for the source mesh
195  void clearMeshPoints();
196 
197  //- Clear out patch maps (per boundary)
198  void clearPatchPointMaps();
199 
200  //- Create/recreate meshPoints (per boundary) for the source mesh
201  void saveMeshPoints();
202 
203  //- Construct per-patch addressing
204  void createPatchPointMaps();
205 
206  //- Clear target mesh / distribution map
207  void resetTarget();
208 
209  //- Reset target mesh / distribution map
210  void resetTarget
211  (
212  const pointMesh& tgtMesh,
213  const mapDistributePolyMesh& distMap
214  );
215 
216 
217  // Field Mapping
218 
219  //- Read, distribute and write all/selected point field types
220  //- (scalar, vector, ... types)
221  label distributeAllFields
222  (
223  const IOobjectList& objects,
224  const wordRes& selectedFields = wordRes()
225  ) const;
226 
227 
228  //- Distribute point field
229  template<class Type>
232  (
234  ) const;
235 
236  //- Read and distribute point field
237  template<class Type>
240  (
241  const IOobject& fieldObject
242  ) const;
243 
244  //- Read, distribute and write all/selected point fields
245  template<class Type>
247  (
248  const IOobjectList& objects,
249  const wordRes& selectedFields = wordRes()
250  ) const;
251 
252  //- Distributed each (unregistered!) point field
253  //- and store the result on its objectRegistry
254  template<class Type>
255  void distributeAndStore
256  (
258  ) const;
259 };
260 
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 } // End namespace Foam
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #ifdef NoRepository
270 #endif
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 #endif
275 
276 // ************************************************************************* //
void clearMeshPoints()
Clear out meshPoints (per boundary) for the source mesh.
void clearPatchPointMaps()
Clear out patch maps (per boundary)
void operator=(const parPointFieldDistributor &)=delete
No copy assignment.
void saveMeshPoints()
Create/recreate meshPoints (per boundary) for the source mesh.
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
void createPatchPointMaps()
Construct per-patch addressing.
label distributeAllFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
Read, distribute and write all/selected point field types (scalar, vector, ... types) ...
void resetTarget()
Clear target mesh / distribution map.
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
Definition: Switch.H:77
tmp< GeometricField< Type, pointPatchField, pointMesh > > distributePointField(const IOobject &fieldObject) const
Read and distribute point field.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Forwards and collection of common point field types.
bool hasPatchPointMaps() const
True if patch maps (per boundary) exist.
Distributor/redistributor for point fields, uses a two (or three) stage construction.
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
static int verbose_
Output verbosity when writing.
bool hasMeshPoints() const
True if meshPoints (per boundary) for the source mesh have been saved.
label distributePointFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
Read, distribute and write all/selected point fields.
bool hasTarget() const
True if a target mesh/distribution map has been attached.
tmp< GeometricField< Type, pointPatchField, pointMesh > > distributeField(const GeometricField< Type, pointPatchField, pointMesh > &fld) const
Distribute point field.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
void distributeAndStore(const PtrList< GeometricField< Type, pointPatchField, pointMesh >> &) const
Distributed each (unregistered!) point field and store the result on its objectRegistry.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
parPointFieldDistributor(const parPointFieldDistributor &)=delete
No copy construct.
Namespace for OpenFOAM.