faMeshTools.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-2024 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::faMeshTools
28 
29 Description
30  A collection of tools for operating on an faMesh.
31 
32 SourceFiles
33  faMeshTools.C
34  faMeshToolsChecks.C
35  faMeshToolsProcAddr.C
36  faMeshToolsTemplates.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Foam_faMeshTools_H
41 #define Foam_faMeshTools_H
42 
43 #include "faMesh.H"
44 #include "areaFieldsFwd.H"
45 #include "edgeFieldsFwd.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward Declarations
53 class fileOperation;
54 class mapDistributePolyMesh;
55 class polyMesh;
56 class IOobject;
57 
58 /*---------------------------------------------------------------------------*\
59  Class faMeshTools Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class faMeshTools
63 {
64  // Private Member Functions
65 
66  // Read mesh if available. Otherwise create empty mesh with same non-proc
67  // patches as proc0 mesh.
68  // Has two modes of operation.
69  // If the readHandler is non-nullptr, use it to decide on availability.
70  // Requires:
71  // - all processors to have all patches (and in same order).
72  // - io.instance() set to facesInstance
73  static autoPtr<faMesh> loadOrCreateMeshImpl
74  (
75  const IOobject& io,
76  refPtr<fileOperation>* readHandlerPtr, // Can be nullptr
77  const polyMesh& pMesh,
78  const bool decompose, // Only used if readHandlerPtr == nullptr
79  const bool verbose = false
80  );
81 
82 
83 
84 public:
85 
86  //- Unregister the faMesh from its associated polyMesh
87  //- to prevent triggering on polyMesh changes etc.
88  static void unregisterMesh(const faMesh& mesh);
89 
90  //- Force creation of everything that might vaguely be used by patches.
91  // This is fairly horrible.
92  static void forceDemandDriven(faMesh& mesh);
93 
94 
95  //- Read mesh or create dummy mesh (0 faces, >0 patches).
96  // Works in two modes according to masterOnlyReading:
97  // true : create a dummy mesh for all procs
98  // false: checks locally for mesh directories and only creates dummy mesh
99  // if not present
100  static autoPtr<faMesh> newMesh
101  (
103  const IOobject& io,
104  const polyMesh& pMesh,
105  const bool masterOnlyReading,
106  const bool verbose = false
107  );
108 
109  // Read mesh if available. Otherwise create empty mesh with same non-proc
110  // patches as proc0 mesh. Requires:
111  // - all processors to have all patches (and in same order).
112  // - io.instance() set to facesInstance
114  (
116  const IOobject& io,
117  const polyMesh& pMesh,
118  const bool decompose,
119  const bool verbose = false
120  );
121 
122  // Read mesh if available. Otherwise create empty mesh with same non-proc
123  // patches as proc0 mesh. Requires:
124  // - all processors to have all patches (and in same order).
125  // - io.instance() set to facesInstance
127  (
129  const IOobject& io,
130  const polyMesh& pMesh,
132  refPtr<fileOperation>& readHandler,
133  const bool verbose = false
134  );
135 
136 
137  //- Read decompose/reconstruct addressing
139  (
140  const faMesh& mesh,
141  const autoPtr<faMesh>& baseMeshPtr
142  );
143 
144  //- Write decompose/reconstruct addressing
145  //
146  // \param mesh
147  // \param faDistMap
148  // \param decompose running in decompose vs reconstruct mode
149  // \param writeHandler file handler
150  // \param procMesh (optional) processor mesh in reconstruct mode
151  //
152  // \note Since the faMesh holds a reference to a polyMesh,
153  // in reconstruct mode it will refer to the base mesh, but
154  // we need a means to proc addressing into the processor locations.
155  // This is the purpose of the additional procMesh reference
156  static void writeProcAddressing
157  (
158  const faMesh& mesh,
159  const mapDistributePolyMesh& faDistMap,
160  const bool decompose,
161  refPtr<fileOperation>& writeHandler,
162  const faMesh* procMesh = nullptr
163  );
164 
165 
166  //- Flatten an edge field into linear addressing
167  // Optionally use primitive patch edge ordering
168  template<class Type>
170  (
172  const bool primitiveOrdering = false
173  );
174 
175  //- Report mesh information
176  static void printMeshChecks
177  (
178  const faMesh& mesh,
179  const int verbose = 1
180  );
181 };
182 
183 
184 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 
186 } // End namespace Foam
187 
188 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
189 
190 #ifdef NoRepository
191  #include "faMeshToolsTemplates.C"
192 #endif
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #endif
197 
198 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:133
static autoPtr< faMesh > newMesh(const IOobject &io, const polyMesh &pMesh, const bool masterOnlyReading, const bool verbose=false)
Read mesh or create dummy mesh (0 faces, >0 patches).
Definition: faMeshTools.C:66
static void writeProcAddressing(const faMesh &mesh, const mapDistributePolyMesh &faDistMap, const bool decompose, refPtr< fileOperation > &writeHandler, const faMesh *procMesh=nullptr)
Write decompose/reconstruct addressing.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Generic GeometricField class.
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
static mapDistributePolyMesh readProcAddressing(const faMesh &mesh, const autoPtr< faMesh > &baseMeshPtr)
Read decompose/reconstruct addressing.
Forwards for edge field types.
dynamicFvMesh & mesh
static autoPtr< faMesh > loadOrCreateMesh(const IOobject &io, const polyMesh &pMesh, const bool decompose, const bool verbose=false)
Definition: faMeshTools.C:576
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))
static void unregisterMesh(const faMesh &mesh)
Unregister the faMesh from its associated polyMesh to prevent triggering on polyMesh changes etc...
Definition: faMeshTools.C:33
static void printMeshChecks(const faMesh &mesh, const int verbose=1)
Report mesh information.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
static tmp< Field< Type > > flattenEdgeField(const GeometricField< Type, faePatchField, edgeMesh > &fld, const bool primitiveOrdering=false)
Flatten an edge field into linear addressing.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
static void forceDemandDriven(faMesh &mesh)
Force creation of everything that might vaguely be used by patches.
Definition: faMeshTools.C:45
Forwards and collection of common area field types.
Namespace for OpenFOAM.
A collection of tools for operating on an faMesh.
Definition: faMeshTools.H:57