isoAdvectionTemplates.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) 2016-2017 DHI
9  Copyright (C) 2016-2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "isoAdvection.H"
30 
31 // ************************************************************************* //
32 
33 template<typename Type>
34 Type Foam::isoAdvection::faceValue
35 (
36  const GeometricField<Type, fvsPatchField, surfaceMesh>& f,
37  const label facei
38 ) const
39 {
40  if (mesh_.isInternalFace(facei))
41  {
42  return f.primitiveField()[facei];
43  }
44  else
45  {
46  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
47 
48  // Boundary face. Find out which face of which patch
49  const label patchi = pbm.patchID()[facei - mesh_.nInternalFaces()];
50 
51  if (patchi < 0 || patchi >= pbm.size())
52  {
54  << "Cannot find patch for face " << facei
55  << abort(FatalError);
56  }
57 
58  // Handle empty patches
59  const polyPatch& pp = pbm[patchi];
60  if (isA<emptyPolyPatch>(pp) || pp.empty())
61  {
62  return pTraits<Type>::zero;
63  }
64 
65  const label patchFacei = pp.whichFace(facei);
66  return f.boundaryField()[patchi][patchFacei];
67  }
68 }
69 
70 
71 template<typename Type>
72 void Foam::isoAdvection::setFaceValue
73 (
74  GeometricField<Type, fvsPatchField, surfaceMesh>& f,
75  const label facei,
76  const Type& value
77 ) const
78 {
79  if (mesh_.isInternalFace(facei))
80  {
81  f.primitiveFieldRef()[facei] = value;
82  }
83  else
84  {
85  const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
86 
87  // Boundary face. Find out which face of which patch
88  const label patchi = pbm.patchID()[facei - mesh_.nInternalFaces()];
89 
90  if (patchi < 0 || patchi >= pbm.size())
91  {
93  << "Cannot find patch for face " << facei
94  << abort(FatalError);
95  }
96 
97  // Handle empty patches
98  const polyPatch& pp = pbm[patchi];
99  if (isA<emptyPolyPatch>(pp) || pp.empty())
100  {
101  return;
102  }
103 
104  const label patchFacei = pp.whichFace(facei);
105 
106  f.boundaryFieldRef()[patchi][patchFacei] = value;
107  }
108 }
109 
110 
111 // ************************************************************************* //
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Number of internal faces.
Definition: primitiveMeshI.H:78
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
isoAdvection.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
f
labelList f(nPoints)
Foam::primitiveMesh::isInternalFace
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
Definition: primitiveMeshI.H:102