fvPatchTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "fvPatch.H"
27 #include "SlicedDimensionedField.H"
28 #include "objectRegistry.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const UList<Type>& f
36 ) const
37 {
38  tmp<Field<Type>> tpif(new Field<Type>(size()));
39  Field<Type>& pif = tpif.ref();
40 
41  const labelUList& faceCells = this->faceCells();
42 
43  forAll(pif, facei)
44  {
45  pif[facei] = f[faceCells[facei]];
46  }
47 
48  return tpif;
49 }
50 
51 
52 template<class Type>
54 (
55  const UList<Type>& f,
56  Field<Type>& pif
57 ) const
58 {
59  pif.setSize(size());
60 
61  const labelUList& faceCells = this->faceCells();
62 
63  forAll(pif, facei)
64  {
65  pif[facei] = f[faceCells[facei]];
66  }
67 }
68 
69 
70 template<class GeometricField, class Type>
72 (
73  const GeometricField& gf
74 ) const
75 {
76  return gf.boundaryField()[index()];
77 }
78 
79 
80 template<class GeometricField, class Type>
82 (
83  GeometricField& gf
84 ) const
85 {
86  return gf.boundaryFieldRef()[index()];
87 }
88 
89 
90 template<class GeometricField, class Type>
92 (
93  const word& name
94 ) const
95 {
96  return patchField<GeometricField, Type>
97  (
98  db().template lookupObject<GeometricField>(name)
99  );
100 }
101 
102 
103 template<class Type>
106 (
107  const word& name
108 ) const
109 {
110  typedef GeometricField<Type, fvMesh> volFieldType;
111  typedef GeometricField<Type, surfaceMesh> surfaceFieldType;
112 
113  const bool haveVf = db().template foundObject<volFieldType>(name);
114  const bool haveSf = db().template foundObject<surfaceFieldType>(name);
115 
116  if (!haveVf && !haveSf)
117  {
119  << nl << " request for " << volFieldType::typeName
120  << " or " << surfaceFieldType::typeName << " " << name
121  << " from objectRegistry " << db().name()
122  << " failed\n available objects of type "
123  << volFieldType::typeName << " are" << nl
124  << db().toc<volFieldType>()
125  << "\n available objects of type "
126  << surfaceFieldType::typeName << " are" << nl
127  << db().toc<surfaceFieldType>()
128  << abort(FatalError);
129  }
130 
131  const IOobject io
132  (
133  name + '_' + this->name(),
134  time().name(),
135  db(),
138  false
139  );
140 
141  if (haveVf)
142  {
143  const volFieldType& vf =
144  db().template lookupObject<volFieldType>(name);
145 
147  (
149  (
150  io,
151  *this,
152  vf.dimensions(),
153  vf.boundaryField()[index()]
154  ),
155  true
156  );
157  }
158  else // if (haveSf)
159  {
160  const surfaceFieldType& sf =
161  db().template lookupObject<surfaceFieldType>(name);
162 
164  (
166  (
167  io,
168  *this,
169  sf.dimensions(),
170  sf.boundaryField()[index()]
171  ),
172  true
173  );
174  }
175 }
176 
177 
178 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
const dimensionSet & dimensions() const
Return dimensions.
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
GeoMesh::template PatchField< Type > Patch
Type of the patch field of which the Boundary is composed.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
void setSize(const label)
Reset size of List.
Definition: List.C:281
Specialisation of DimensionedField which holds a slice of a given complete field in such a form that ...
virtual label size() const
Return size.
Definition: fvPatch.H:147
const GeometricField::Patch & patchField(const GeometricField &) const
Return the corresponding patchField of the named field.
tmp< Field< Type > > patchInternalField(const UList< Type > &) const
Return given internal field next to patch as patch field.
tmp< DimensionedField< Type, fvPatch > > lookupField(const word &) const
Lookup a dimensioned field for this geometry.
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:79
const GeometricField::Patch & lookupPatchField(const word &name) const
Lookup and return the patchField of the named field from the.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
A class for handling words, derived from string.
Definition: word.H:63
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
volScalarField sf(fieldObject, mesh)
const dimensionSet time
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
static const char nl
Definition: Ostream.H:297
labelList f(nPoints)