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-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::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  (
102  const IOobject& io,
103  const polyMesh& pMesh,
104  const bool masterOnlyReading,
105  const bool verbose = false
106  );
107 
108  // Read mesh if available. Otherwise create empty mesh with same non-proc
109  // patches as proc0 mesh. Requires:
110  // - all processors to have all patches (and in same order).
111  // - io.instance() set to facesInstance
113  (
114  const IOobject& io,
115  const polyMesh& pMesh,
116  const bool decompose,
117  const bool verbose = false
118  );
119 
120  // Read mesh if available. Otherwise create empty mesh with same non-proc
121  // patches as proc0 mesh. Requires:
122  // - all processors to have all patches (and in same order).
123  // - io.instance() set to facesInstance
125  (
126  const IOobject& io,
127  const polyMesh& pMesh,
129  refPtr<fileOperation>& readHandler,
130  const bool verbose = false
131  );
132 
133 
134  //- Read decompose/reconstruct addressing
136  (
137  const faMesh& mesh,
138  const autoPtr<faMesh>& baseMeshPtr
139  );
140 
141  //- Write decompose/reconstruct addressing
142  //
143  // \param mesh
144  // \param faDistMap
145  // \param decompose running in decompose vs reconstruct mode
146  // \param writeHandler file handler
147  // \param procMesh (optional) processor mesh in reconstruct mode
148  //
149  // \note Since the faMesh holds a reference to a polyMesh,
150  // in reconstruct mode it will refer to the base mesh, but
151  // we need a means to proc addressing into the processor locations.
152  // This is the purpose of the additional procMesh reference
153  static void writeProcAddressing
154  (
155  const faMesh& mesh,
156  const mapDistributePolyMesh& faDistMap,
157  const bool decompose,
158  refPtr<fileOperation>& writeHandler,
159  const faMesh* procMesh = nullptr
160  );
161 
162 
163  //- Flatten an edge field into linear addressing
164  // Optionally use primitive patch edge ordering
165  template<class Type>
167  (
169  const bool primitiveOrdering = false
170  );
171 
172  //- Report mesh information
173  static void printMeshChecks
174  (
175  const faMesh& mesh,
176  const int verbose = 1
177  );
178 };
179 
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 } // End namespace Foam
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 #ifdef NoRepository
188  #include "faMeshToolsTemplates.C"
189 #endif
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 #endif
194 
195 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:87
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.
Definition: areaFieldsFwd.H:50
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:580
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:74
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:172
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