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 -------------------------------------------------------------------------------
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 \*---------------------------------------------------------------------------*/
27 
28 #include "fvGeometryScheme.H"
29 #include "fvMesh.H"
30 #include "surfaceFields.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(fvGeometryScheme, 0);
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", keyType::LITERAL);
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  }
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 
152 void Foam::fvGeometryScheme::updateMesh(const mapPolyMesh& mpm)
153 {}
154 
155 
156 // ************************************************************************* //
Foam::surfaceFields.
dictionary dict
const fvMesh & mesh_
Hold reference to mesh.
scalar deltaTValue() const noexcept
Return time step value.
Definition: TimeStateI.H:49
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
bool setMeshPhi() const
Set the mesh motion flux.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual void updateMesh(const mapPolyMesh &mpm)
Update mesh for topology changes.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1078
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
void clearGeom()
Clear geometry.
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
#define DebugInFunction
Report an information message using Foam::Info.
virtual const pointField & oldPoints() const
Return old points (mesh motion)
Definition: polyMesh.C:1128
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1103
String literal.
Definition: keyType.H:82
errorManip< error > abort(error &err)
Definition: errorManip.H:139
static tmp< fvGeometryScheme > New(const fvMesh &mesh, const dictionary &dict, const word &defaultScheme)
Return new tmp interpolation scheme.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
bool moving() const noexcept
Is mesh moving.
Definition: polyMesh.H:731
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
tmp< surfaceScalarField > meshPhi(const volVectorField &U)
Definition: fvcMeshPhi.C:29
virtual void movePoints()
Update basic geometric properties from provided points.
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:84
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
virtual ITstream & stream() const =0
Return token stream, if entry is a primitive entry.
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:635
Abstract base class for geometry calculation schemes.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...