fvGeometryScheme.C
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) 2020-2022 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
26\*---------------------------------------------------------------------------*/
27
28#include "fvGeometryScheme.H"
29#include "fvMesh.H"
30#include "surfaceFields.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
37
39}
40
41
42// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
43
45{
46 if (!mesh_.moving())
47 {
48 return false;
49 }
50
51 const pointField& oldPoints = mesh_.oldPoints();
52 const pointField& currPoints = mesh_.points();
53
54 if (oldPoints.size() != currPoints.size())
55 {
57 << "Old and current points sizes must be the same. "
58 << "Old points:" << oldPoints.size()
59 << " Current points:" << currPoints.size()
60 << abort(FatalError);
61 }
62
63 const faceList& faces = mesh_.faces();
64 const scalar rdt = 1.0/mesh_.time().deltaTValue();
65
66 auto tmeshPhi(const_cast<fvMesh&>(mesh_).setPhi());
67 if (tmeshPhi)
68 {
69 auto& meshPhi = tmeshPhi.ref();
70 auto& meshPhii = meshPhi.primitiveFieldRef();
71 forAll(meshPhii, facei)
72 {
73 const face& f = faces[facei];
74 meshPhii[facei] = f.sweptVol(oldPoints, currPoints)*rdt;
75 }
76
77 auto& meshPhiBf = meshPhi.boundaryFieldRef();
78 for (auto& meshPhip : meshPhiBf)
79 {
80 if (!meshPhip.size())
81 {
82 // Empty patches
83 continue;
84 }
85
86 const auto& pp = meshPhip.patch().patch();
87
88 forAll(pp, facei)
89 {
90 const face& f = pp[facei];
91 meshPhip[facei] = f.sweptVol(oldPoints, currPoints)*rdt;
92 }
93 }
94 }
95
96 return true;
97}
98
99
100// * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
101
103(
104 const fvMesh& mesh,
105 const dictionary& dict,
106 const word& defaultScheme
107)
108{
109 const entry* ePtr = dict.findEntry("method");
110 const word schemeName
111 (
112 ePtr
113 ? word(ePtr->stream())
114 : dict.getOrDefault<word>("type", defaultScheme)
115 );
116
117 DebugInFunction << "Geometry scheme = " << schemeName << endl;
118
119 auto* ctorPtr = dictConstructorTable(schemeName);
120
121 if (!ctorPtr)
122 {
124 (
125 dict,
126 "fvGeometryScheme",
127 schemeName,
128 *dictConstructorTablePtr_
129 ) << exit(FatalIOError);
130 }
131
132 return ctorPtr(mesh, dict);
133}
134
135
136// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137
139{
140 if (mesh_.moving())
141 {
142 // Set the mesh motion fluxes
143 setMeshPhi();
144
145 // Clear out old geometry
146 // Note: this recreates the old primitiveMesh::movePoints behaviour
147 const_cast<fvMesh&>(mesh_).primitiveMesh::clearGeom();
148 }
149}
150
151
153{}
154
155
156// ************************************************************************* //
scalar deltaTValue() const noexcept
Return time step value.
Definition: TimeStateI.H:43
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find for an entry (non-const access) with the given keyword.
Definition: dictionaryI.H:97
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
virtual ITstream & stream() const =0
Return token stream, if entry is a primitive entry.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Abstract base class for geometry calculation schemes.
const fvMesh & mesh_
Hold reference to mesh.
bool setMeshPhi() const
Set the mesh motion flux.
virtual void movePoints()
Update basic geometric properties from provided points.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:162
void updateMesh()
Update for new mesh topology.
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1108
bool moving() const noexcept
Is mesh moving.
Definition: polyMesh.H:534
virtual const pointField & oldPoints() const
Return old points (mesh motion)
Definition: polyMesh.C:1133
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1083
void clearGeom()
Clear geometry.
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define DebugInFunction
Report an information message using Foam::Info.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
IOerror FatalIOError
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
labelList f(nPoints)
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Foam::surfaceFields.