Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::faMesh
Description
Finite area mesh. Used for 2-D non-Euclidian finite area method.
SourceFiles
faMesh.C
faMeshDemandDrivenData.C
faMeshPatches.C
faMeshTopology.C
faMeshUpdate.C
Author
Zeljko Tukovic, FMENA
Hrvoje Jasak, Wikki Ltd.
\*---------------------------------------------------------------------------*/
#ifndef faMesh_H
#define faMesh_H
#include "MeshObject.H"
#include "polyMesh.H"
#include "lduMesh.H"
#include "faBoundaryMesh.H"
#include "edgeList.H"
#include "faceList.H"
#include "primitiveFieldsFwd.H"
#include "DimensionedField.H"
#include "areaFieldsFwd.H"
#include "edgeFieldsFwd.H"
#include "uindirectPrimitivePatch.H"
#include "edgeInterpolation.H"
#include "labelIOList.H"
#include "FieldFields.H"
#include "faGlobalMeshData.H"
Andrew Heather
committed
#include "faSchemes.H"
#include "faSolution.H"
#include "data.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class faMeshLduAddressing;
class faMeshMapper;
class faPatchData;
/*---------------------------------------------------------------------------*\
Class faMesh Declaration
\*---------------------------------------------------------------------------*/
class faMesh
:
public MeshObject<polyMesh, Foam::UpdateableMeshObject, faMesh>,
Andrew Heather
committed
public edgeInterpolation,
public faSchemes,
public faSolution,
public data
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Private (internal) classes/structures
//- A (proc, patchi, patchEdgei) tuple used internally for managing
//- patch/patch bookkeeping during construction.
// Finite-area patches are stored with negated indices, which makes
// them readily identifiable and always sort before normal patches.
// Note
struct patchTuple
:
public FixedList<label, 4>
{
// Constructors
// Inherit constructors
using FixedList<label, 4>::FixedList;
//- Default construct as 'invalid'
patchTuple()
{
clear();
}
// Static Member Functions
// Globally consistent ordering
//
// 1. sort left/right as lower/higher processor connection
// 2. sort by proc/patch/patch index
static void sort(UList<Pair<patchTuple>>& list)
{
for (auto& tuples : list)
{
tuples.sort();
}
Foam::stableSort(list);
}
// Member Functions
//- Reset to 'invalid'
void clear()
{
procNo(-1);
patchi(labelMax);
patchEdgei(-1);
meshFacei(-1);
}
//- Valid if proc and edge are non-negative
bool valid() const noexcept
{
return (procNo() >= 0 && patchEdgei() >= 0);
}
// Processor is the first sort index
label procNo() const { return (*this)[0]; }
void procNo(label val) { (*this)[0] = val; }
// PatchId (-ve for finiteArea patches) is the second sort index
label patchi() const { return (*this)[1]; }
void patchi(label val) { (*this)[1] = val; }
// The patch edge index (on the finiteArea patch)
// is the third sort index
label patchEdgei() const { return (*this)[2]; }
void patchEdgei(label val) { (*this)[2] = val; }
// The processor-local mesh face is the fourth sort index
label meshFacei() const { return (*this)[3]; }
void meshFacei(label val) { (*this)[3] = val; }
//- Return the real patchId
label realPatchi() const
{
const label id = patchi();
return (id < 0 ? -(id + 1) : id);
}
//- Set patchId as finiteArea
void faPatchi(label val)
{
patchi(-(val + 1));
}
//- Considered to be finiteArea if patchi < 0
bool is_finiteArea() const noexcept
{
return (patchi() < 0);
}
//- Considered to be processor local
bool is_localProc() const noexcept
{
return (procNo() == Pstream::myProcNo());
}
};
// Private Data
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//- Face labels
labelIOList faceLabels_;
//- Boundary mesh
faBoundaryMesh boundary_;
// Primitive mesh data
//- Edges, addressing into local point list
edgeList edges_;
//- Edge owner
labelList edgeOwner_;
//- Edge neighbour
labelList edgeNeighbour_;
// Primitive size data
//- Number of points
mutable label nPoints_;
//- Number of edges
mutable label nEdges_;
//- Number of internal edges
mutable label nInternalEdges_;
//- Number of faces
mutable label nFaces_;
// Communication support
//- Communicator used for parallel communication
label comm_;
// Demand-driven data
//- Primitive patch
mutable std::unique_ptr<uindirectPrimitivePatch> patchPtr_;
//- List of proc/mesh-face for boundary edge neighbours
mutable std::unique_ptr<List<labelPair>> bndConnectPtr_;
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//- Ldu addressing data
mutable faMeshLduAddressing* lduPtr_;
//- Current time index for motion
// Note. The whole mechanism will be replaced once the
// dimensionedField is created and the dimensionedField
// will take care of the old-time levels.
mutable label curTimeIndex_;
//- Face areas
mutable DimensionedField<scalar, areaMesh>* SPtr_;
//- Face areas old time level
mutable DimensionedField<scalar, areaMesh>* S0Ptr_;
//- Face areas old-old time level
mutable DimensionedField<scalar, areaMesh>* S00Ptr_;
//- Patch starts in the edge list
mutable labelList* patchStartsPtr_;
//- Edge length vectors
mutable edgeVectorField* LePtr_;
//- Mag edge length vectors
mutable edgeScalarField* magLePtr_;
//- Face centres
mutable areaVectorField* centresPtr_;
//- Edge centres
mutable edgeVectorField* edgeCentresPtr_;
//- Face area normals
mutable areaVectorField* faceAreaNormalsPtr_;
//- Edge area normals
mutable edgeVectorField* edgeAreaNormalsPtr_;
//- Point area normals
mutable std::unique_ptr<vectorField> pointAreaNormalsPtr_;
//- Face curvatures
mutable areaScalarField* faceCurvaturesPtr_;
//- Edge transformation tensors
mutable FieldField<Field, tensor>* edgeTransformTensorsPtr_;
//- Whether point normals must be corrected for a patch
mutable boolList* correctPatchPointNormalsPtr_;
//- Parallel info
mutable autoPtr<faGlobalMeshData> globalMeshDataPtr_;
//- Mapping/swapping for boundary edge halo neighbours
mutable std::unique_ptr<faMeshBoundaryHalo> haloMapPtr_;
//- Face centres for boundary edge halo neighbours
mutable std::unique_ptr<pointField> haloFaceCentresPtr_;
//- Face normals for boundary edge halo neighbours
mutable std::unique_ptr<vectorField> haloFaceNormalsPtr_;
//- Use the original method for point normals
static int origPointAreaMethod_;
//- Use quadrics fit
static const int quadricsFit_;
// Private Member Functions
//- No copy construct
faMesh(const faMesh&) = delete;
//- No copy assignment
void operator=(const faMesh&) = delete;
//- Set indirect patch, removing any old one
void initPatch() const;
//- Set primitive mesh data
void setPrimitiveMeshData();
//- Get list of (proc/patchi/patchEdgei/meshFacei) tuple pairs in an
//- globally consistent ordering
List<Pair<patchTuple>> getBoundaryEdgeConnections() const;
//- Determine the boundary edge neighbour connections
void calcBoundaryConnections() const;
//- Define boundary edge neighbours (proc/face) based on
//- gathered topology information
void setBoundaryConnections
(
const List<Pair<patchTuple>>& bndEdgeConnections
) const;
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
// Private member functions to calculate demand driven data
//- Calculate ldu addressing
void calcLduAddressing() const;
//- Calculate patch starts in the edge list
void calcPatchStarts() const;
//- Calculate edge lengths
void calcLe() const;
//- Calculate mag edge lengths
void calcMagLe() const;
//- Calculate face centres
void calcAreaCentres() const;
//- Calculate edge centres
void calcEdgeCentres() const;
//- Calculate face areas
void calcS() const;
//- Calculate face area normals
void calcFaceAreaNormals() const;
//- Calculate edge area normals
void calcEdgeAreaNormals() const;
//- Calculate point area normals
void calcPointAreaNormals_orig(vectorField& result) const;
//- Calculate point area normals
void calcPointAreaNormals(vectorField& result) const;
//- Calculate point area normals by quadrics fit
void calcPointAreaNormalsByQuadricsFit(vectorField& result) const;
//- Calculate face curvatures
void calcFaceCurvatures() const;
//- Calculate edge transformation tensors
void calcEdgeTransformTensors() const;
//- Clear geometry but not the face areas
void clearGeomNotAreas() const;
//- Clear boundary halo information
void clearHalo() const;
//- Clear geometry
void clearGeom() const;
//- Clear addressing
void clearAddressing() const;
//- Clear demand-driven data
void clearOut() const;
// Halo handling
//- Calculate halo centres/normals
void calcHaloFaceGeometry() const;
// Helpers
//- Create a single patch
PtrList<faPatch> createOnePatch
(
const word& patchName,
const word& patchType = ""
) const;
//- Create list of patches from boundary definition
PtrList<faPatch> createPatchList
(
const dictionary& bndDict,
const word& emptyPatchName = "",
const dictionary* defaultPatchDefinition = nullptr
) const;
//- Fatal error if edge labels are out of range
void checkBoundaryEdgeLabelRange(const labelUList& edgeLabels) const;
//- Extract list from contiguous (unordered) boundary data
//- to the locally sorted order.
template<class T>
List<T> boundarySubset
(
const UList<T>& bndField,
const labelUList& edgeLabels
) const
{
#ifdef FULLDEBUG
checkBoundaryEdgeLabelRange(edgeLabels);
#endif
// Like UIndirectList but with an offset
List<T> result(edgeLabels.size());
forAll(edgeLabels, i)
{
result[i] = bndField[edgeLabels[i] - nInternalEdges_];
}
return result;
}
// Public Typedefs
typedef faMesh Mesh;
typedef faBoundaryMesh BoundaryMesh;
//- Runtime type information
TypeName("faMesh");
//- The prefix to local: %finite-area
static const word prefix;
//- The mesh sub-directory name (usually "faMesh")
static word meshSubDir;
//- Construct zero-sized from polyMesh
// Boundary is added using addFaPatches() member function
faMesh(const polyMesh& pMesh, const Foam::zero);
explicit faMesh(const polyMesh& pMesh);
//- Construct for specified face labels without boundary.
// Boundary is added using addFaPatches() member function
faMesh
(
const polyMesh& pMesh,
const UList<label>& faceLabels
//- Construct from single polyPatch
explicit faMesh(const polyPatch& pp);
//- Construct from definition
const polyMesh& pMesh,
const dictionary& faMeshDefinition
);
//- Destructor
virtual ~faMesh();
// Member Functions
//- Add boundary patches. Constructor helper
void addFaPatches
(
PtrList<faPatch>& plist,
const bool validBoundary = true
);
//- Add boundary patches. Constructor helper
void addFaPatches
(
const List<faPatch*>& p,
const bool validBoundary = true
);
// Database
//- Return access to polyMesh
inline const polyMesh& mesh() const;
//- Interface to referenced polyMesh (similar to GeoMesh)
const polyMesh& operator()() const { return mesh(); }
//- Return the local mesh directory (dbDir()/meshSubDir)
fileName meshDir() const;
//- Return reference to time
const Time& time() const;
//- Return the current instance directory for points
// Used in the construction of geometric mesh data dependent
// on points
const fileName& pointsInstance() const;
//- Return the current instance directory for faces
const fileName& facesInstance() const;
// Communication support
//- Return communicator used for parallel communication
inline label comm() const noexcept;
//- Return communicator used for parallel communication
inline label& comm() noexcept;
// Mesh size parameters
//- Number of local mesh points
inline label nPoints() const noexcept;
//- Number of local mesh edges
inline label nEdges() const noexcept;
//- Number of internal faces
inline label nInternalEdges() const noexcept;
//- Number of boundary edges (== nEdges - nInternalEdges)
inline label nBoundaryEdges() const noexcept;
//- Number of patch faces
inline label nFaces() const noexcept;
//- Return local patch points
inline const pointField& points() const;
//- Return local patch edges with reordered boundary
inline const edgeList& edges() const noexcept;
//- Return local patch faces
inline const faceList& faces() const;
inline const labelList& edgeOwner() const noexcept;
inline const labelList& edgeNeighbour() const noexcept;
//- Return true if thisDb() is a valid DB
virtual bool hasDb() const;
//- Return reference to the mesh database
virtual const objectRegistry& thisDb() const;
Andrew Heather
committed
//- Name function is needed to disambiguate those inherited
// from base classes
const word& name() const
{
return thisDb().name();
}
//- Return constant reference to boundary mesh
inline const faBoundaryMesh& boundary() const noexcept;
//- Return the underlying polyMesh face labels
inline const labelList& faceLabels() const noexcept;
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
//- Return parallel info
const faGlobalMeshData& globalData() const;
//- Return ldu addressing
virtual const lduAddressing& lduAddr() const;
//- Return a list of pointers for each patch
// with only those pointing to interfaces being set
virtual lduInterfacePtrsList interfaces() const
{
return boundary().interfaces();
}
//- Internal face owner
const labelUList& owner() const
{
return lduAddr().lowerAddr();
}
//- Internal face neighbour
const labelUList& neighbour() const
{
return lduAddr().upperAddr();
}
//- True if given edge label is internal to the mesh
bool isInternalEdge(const label edgeIndex) const
return (edgeIndex < nInternalEdges_);
//- List of proc/face for the boundary edge neighbours
//- using primitive patch edge numbering.
inline const List<labelPair>& boundaryConnections() const;
//- Boundary edge neighbour processors
//- (does not include own proc)
labelList boundaryProcs() const;
//- List of proc/size for the boundary edge neighbour processors
//- (does not include own proc)
List<labelPair> boundaryProcSizes() const;
//- Mapping/swapping for boundary halo neighbours
const faMeshBoundaryHalo& boundaryHaloMap() const;
//- Face centres of boundary halo neighbours
const pointField& haloFaceCentres() const;
//- Face normals of boundary halo neighbours
const vectorField& haloFaceNormals() const;
//- Face centres of boundary halo neighbours for specified patch
tmp<pointField> haloFaceCentres(const label patchi) const;
//- Face normals of boundary halo neighbours for specified patch
tmp<vectorField> haloFaceNormals(const label patchi) const;
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
//- Is mesh moving
bool moving() const
{
return mesh().moving();
}
//- Update after mesh motion
virtual bool movePoints();
//- Update after topo change
virtual void updateMesh(const mapPolyMesh&);
// Mapping
//- Map all fields in time using given map.
virtual void mapFields(const faMeshMapper& mapper) const;
//- Map face areas in time using given map.
virtual void mapOldAreas(const faMeshMapper& mapper) const;
// Demand-driven data
//- Return constant reference to primitive patch
inline const uindirectPrimitivePatch& patch() const;
//- Return reference to primitive patch
inline uindirectPrimitivePatch& patch();
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
//- Return patch starts
const labelList& patchStarts() const;
//- Return edge length vectors
const edgeVectorField& Le() const;
//- Return edge length magnitudes
const edgeScalarField& magLe() const;
//- Return face centres as areaVectorField
const areaVectorField& areaCentres() const;
//- Return edge centres as edgeVectorField
const edgeVectorField& edgeCentres() const;
//- Return face areas
const DimensionedField<scalar, areaMesh>& S() const;
//- Return old-time face areas
const DimensionedField<scalar, areaMesh>& S0() const;
//- Return old-old-time face areas
const DimensionedField<scalar, areaMesh>& S00() const;
//- Return face area normals
const areaVectorField& faceAreaNormals() const;
//- Return edge area normals
const edgeVectorField& edgeAreaNormals() const;
//- Return point area normals
const vectorField& pointAreaNormals() const;
//- Return face curvatures
const areaScalarField& faceCurvatures() const;
//- Return edge transformation tensors
const FieldField<Field, tensor>& edgeTransformTensors() const;
//- Return internal point labels
labelList internalPoints() const;
//- Return boundary point labels
labelList boundaryPoints() const;
//- Return edge length correction
tmp<edgeScalarField> edgeLengthCorrection() const;
//- Whether point normals should be corrected for a patch
bool correctPatchPointNormals(const label patchID) const;
//- Set whether point normals should be corrected for a patch
boolList& correctPatchPointNormals() const;
Andrew Heather
committed
virtual bool write(const bool valid = true) const;
// Member Operators
bool operator!=(const faMesh& m) const;
bool operator==(const faMesh& m) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "faMeshI.H"
#include "faPatchFaMeshTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //