Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::faMeshTools
28
29Description
30 A collection of tools for operating on an faMesh.
31
32SourceFiles
33 faMeshTools.cxx
34 faMeshTools.txx
35 faMeshToolsChecks.cxx
36 faMeshToolsProcAddr.cxx
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
49namespace Foam
50{
51
52// Forward Declarations
53class fileOperation;
55class polyMesh;
56class IOobject;
58/*---------------------------------------------------------------------------*\
59 Class faMeshTools Declaration
60\*---------------------------------------------------------------------------*/
61
62class 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> loadOrCreateMesh_impl
74 (
75 const word& areaName,
76 const IOobject& io, // Describes the base polyMesh
77 refPtr<fileOperation>* readHandlerPtr, // Can be nullptr
78 const polyMesh& pMesh,
79 const bool decompose, // Only used if readHandlerPtr == nullptr
80 const bool verbose = false
81 );
82
83
84public:
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.
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
101 (
103 const word& areaName,
105 const IOobject& io,
106 const polyMesh& pMesh,
107 const bool masterOnlyReading,
108 const bool verbose = false
109 );
110
111 //- Read mesh or create dummy mesh (0 faces, >0 patches).
112 // Works in two modes according to masterOnlyReading:
113 // true : create a dummy mesh for all procs
114 // false: checks locally for mesh directories and only creates dummy mesh
115 // if not present
116 static inline autoPtr<faMesh> newMesh
117 (
119 const IOobject& io,
120 const polyMesh& pMesh,
121 const bool masterOnlyReading,
122 const bool verbose = false
123 )
124 {
126 (
127 word::null, // == defaultRegion
128 io,
129 pMesh,
130 masterOnlyReading,
131 verbose
132 );
133 }
134
135 // Read mesh if available. Otherwise create empty mesh with same non-proc
136 // patches as proc0 mesh. Requires:
137 // - all processors to have all patches (and in same order).
138 // - io.instance() set to facesInstance
140 (
142 const word& areaName,
144 const IOobject& io,
145 const polyMesh& pMesh,
146 const bool decompose,
147 const bool verbose = false
148 );
149
150 // Read mesh if available. Otherwise create empty mesh with same non-proc
151 // patches as proc0 mesh. Requires:
152 // - all processors to have all patches (and in same order).
153 // - io.instance() set to facesInstance
155 (
157 const IOobject& io,
158 const polyMesh& pMesh,
159 const bool decompose,
160 const bool verbose = false
161 )
162 {
164 (
165 word::null, // == defaultRegion
166 io,
167 pMesh,
168 decompose,
169 verbose
170 );
171 }
172
173 // Read mesh if available. Otherwise create empty mesh with same non-proc
174 // patches as proc0 mesh. Requires:
175 // - all processors to have all patches (and in same order).
176 // - io.instance() set to facesInstance
178 (
180 const word& areaName,
182 const IOobject& io,
183 const polyMesh& pMesh,
185 refPtr<fileOperation>& readHandler,
186 const bool verbose = false
187 );
188
189 // Read mesh if available. Otherwise create empty mesh with same non-proc
190 // patches as proc0 mesh. Requires:
191 // - all processors to have all patches (and in same order).
192 // - io.instance() set to facesInstance
194 (
196 const IOobject& io,
197 const polyMesh& pMesh,
200 const bool verbose = false
201 )
202 {
204 (
205 word::null, // == defaultRegion
206 io,
207 pMesh,
208 readHandler,
209 verbose
210 );
211 }
212
213
214 //- Read decompose/reconstruct addressing
216 (
217 const faMesh& mesh,
218 const faMesh* baseMeshPtr
219 );
220
221 //- Write decompose/reconstruct addressing
222 //
223 // \note Since the faMesh holds a reference to a polyMesh,
224 // in reconstruct mode it will refer to the base mesh, but
225 // we need a means to proc addressing into the processor locations.
226 // This is the purpose of the additional procMesh reference
227 static void writeProcAddressing
228 (
229 const faMesh& mesh,
230 const mapDistributePolyMesh& faDistMap,
232 const bool decompose,
234 refPtr<fileOperation>& writeHandler,
236 const faMesh* procMesh = nullptr
237 );
239
240 //- Flatten an edge field into linear addressing
241 // Optionally use primitive patch edge ordering
242 template<class Type>
244 (
246 const bool primitiveOrdering = false
247 );
248
249 //- Report mesh information
250 static void printMeshChecks
251 (
252 const faMesh& mesh,
253 const int verbose = 1
254 );
255
256
257 // Housekeeping
258
259 //- Read decompose/reconstruct addressing
261 (
262 const faMesh& procMesh,
263 const autoPtr<faMesh>& baseMeshPtr
264 );
265};
267
268// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269
270} // End namespace Foam
271
272// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273
274#ifdef NoRepository
275 #include "faMeshTools.txx"
276#endif
277
278// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279
280#endif
281
282// ************************************************************************* //
Forwards and collection of common area field types.
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic GeometricField class.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A collection of tools for operating on an faMesh.
Definition faMeshTools.H:58
static void forceDemandDriven(faMesh &mesh)
Force creation of everything that might vaguely be used by patches.
static autoPtr< faMesh > newMesh(const word &areaName, const IOobject &io, const polyMesh &pMesh, const bool masterOnlyReading, const bool verbose=false)
Read mesh or create dummy mesh (0 faces, >0 patches).
static mapDistributePolyMesh readProcAddressing(const faMesh &mesh, const faMesh *baseMeshPtr)
Read decompose/reconstruct addressing.
static void writeProcAddressing(const faMesh &mesh, const mapDistributePolyMesh &faDistMap, const bool decompose, refPtr< fileOperation > &writeHandler, const faMesh *procMesh=nullptr)
Write decompose/reconstruct addressing.
static autoPtr< faMesh > loadOrCreateMesh(const word &areaName, const IOobject &io, const polyMesh &pMesh, refPtr< fileOperation > &readHandler, const bool verbose=false)
static mapDistributePolyMesh readProcAddressing(const faMesh &procMesh, const autoPtr< faMesh > &baseMeshPtr)
Read decompose/reconstruct addressing.
static void unregisterMesh(const faMesh &mesh)
Unregister the faMesh from its associated polyMesh to prevent triggering on polyMesh changes etc.
static autoPtr< faMesh > loadOrCreateMesh(const IOobject &io, const polyMesh &pMesh, const bool decompose, const bool verbose=false)
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).
static autoPtr< faMesh > loadOrCreateMesh(const IOobject &io, const polyMesh &pMesh, refPtr< fileOperation > &readHandler, const bool verbose=false)
static void printMeshChecks(const faMesh &mesh, const int verbose=1)
Report mesh information.
static tmp< Field< Type > > flattenEdgeField(const GeometricField< Type, faePatchField, edgeMesh > &fld, const bool primitiveOrdering=false)
Flatten an edge field into linear addressing.
static autoPtr< faMesh > loadOrCreateMesh(const word &areaName, const IOobject &io, const polyMesh &pMesh, const bool decompose, const bool verbose=false)
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition faMesh.H:140
An encapsulation of filesystem-related operations.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
static const word null
An empty word.
Definition word.H:84
dynamicFvMesh & mesh
Forwards for edge field types.
const auto & io
Namespace for OpenFOAM.