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 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 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 namespace Foam
64 {
65 
66 // Forward Declarations
67 class mapDistributePolyMesh;
68 class mapDistributeBase;
69 class IOobjectList;
70 
71 /*---------------------------------------------------------------------------*\
72  Class parPointFieldDistributor Declaration
73 \*---------------------------------------------------------------------------*/
74 
76 {
77  // Private Data
78 
79  //- The source mesh reference
80  const pointMesh& srcMesh_;
81 
82  //- Number of points in the old (source) mesh
83  const label nOldPoints_;
84 
85  //- The pointPatch mesh points
86  PtrList<labelList> patchMeshPoints_;
87 
88  //- The target (destination) mesh reference
89  refPtr<pointMesh> tgtMeshRef_;
90 
91  //- Distribution map reference
93 
94  //- Point patch mappers
95  PtrList<mapDistributeBase> patchPointMaps_;
96 
97  //- Do I need to write (eg, master only for reconstruct)
98  bool isWriteProc_;
99 
100 
101  // Private Member Functions
102 
103  //- No copy construct
105 
106  //- No copy assignment
107  void operator=(const parPointFieldDistributor&) = delete;
108 
109 
110 public:
111 
112  //- Output verbosity when writing
113  static int verbose_;
114 
115 
116  // Constructors
117 
118  //- Basic construction
119  //
120  // \param srcMesh The source pointMesh
121  // \param savePoints Call saveMeshPoints() immediately
122  // \param isWriteProc Tagged for output writing (on this proc)
123  explicit parPointFieldDistributor
124  (
125  const pointMesh& srcMesh,
126  const bool savePoints = false,
127  const bool isWriteProc = false
128  );
129 
130  //- Full construction of source/target
131  //
132  // \param srcMesh The source pointMesh
133  // \param tgtMesh The target pointMesh
134  // \param distMap The distribution map
135  // \param savePoints Call saveMeshPoints() immediately
136  // \param isWriteProc Tagged for output writing (on this proc)
137  explicit parPointFieldDistributor
138  (
139  const pointMesh& srcMesh,
140  const pointMesh& tgtMesh,
141  const mapDistributePolyMesh& distMap,
142  const bool savePoints = false,
143  const bool isWriteProc = false
144  );
145 
146 
147  // Member Functions
148 
149  //- True if meshPoints (per boundary) for the source mesh
150  //- have been saved
151  bool hasMeshPoints() const;
152 
153  //- True if patch maps (per boundary) exist
154  bool hasPatchPointMaps() const;
155 
156  //- True if a target mesh/distribution map has been attached
157  bool hasTarget() const;
158 
159  //- Clear out meshPoints (per boundary) for the source mesh
160  void clearMeshPoints();
161 
162  //- Clear out patch maps (per boundary)
163  void clearPatchPointMaps();
164 
165  //- Create/recreate meshPoints (per boundary) for the source mesh
166  void saveMeshPoints();
167 
168  //- Construct per-patch addressing
169  void createPatchPointMaps();
170 
171  //- Clear target mesh / distribution map
172  void resetTarget();
173 
174  //- Reset target mesh / distribution map
175  void resetTarget
176  (
177  const pointMesh& tgtMesh,
178  const mapDistributePolyMesh& distMap
179  );
180 
181  //- Get status of write enabled (on this proc)
182  bool isWriteProc() const noexcept
183  {
184  return isWriteProc_;
185  }
186 
187  //- Change status of write enabled (on this proc)
188  bool isWriteProc(const bool on) noexcept
189  {
190  bool old(isWriteProc_);
191  isWriteProc_ = on;
192  return old;
193  }
194 
195 
196  // Field Mapping
197 
198  //- Read, distribute and write all/selected point field types
199  //- (scalar, vector, ... types)
200  label distributeAllFields
201  (
202  const IOobjectList& objects,
203  const wordRes& selectedFields = wordRes()
204  ) const;
205 
206 
207  //- Distribute point field
208  template<class Type>
209  tmp<GeometricField<Type, pointPatchField, pointMesh>>
211  (
212  const GeometricField<Type, pointPatchField, pointMesh>& fld
213  ) const;
214 
215  //- Read and distribute point field
216  template<class Type>
217  tmp<GeometricField<Type, pointPatchField, pointMesh>>
219  (
220  const IOobject& fieldObject
221  ) const;
222 
223  //- Read, distribute and write all/selected point fields
224  template<class Type>
226  (
227  const IOobjectList& objects,
228  const wordRes& selectedFields = wordRes()
229  ) const;
230 
231  //- Distributed each (unregistered!) point field
232  //- and store the result on its objectRegistry
233  template<class Type>
234  void distributeAndStore
235  (
237  ) const;
238 };
239 
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 } // End namespace Foam
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 #ifdef NoRepository
249 #endif
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 #endif
254 
255 // ************************************************************************* //
void clearMeshPoints()
Clear out meshPoints (per boundary) for the source mesh.
void clearPatchPointMaps()
Clear out patch maps (per boundary)
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.
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
bool isWriteProc() const noexcept
Get status of write enabled (on this proc)
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:47
const direction noexcept
Definition: Scalar.H:258
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
Namespace for OpenFOAM.