faPatchFieldNew.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 Wikki Ltd
9  Copyright (C) 2019-2021 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 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const word& patchFieldType,
35  const word& actualPatchType,
36  const faPatch& p,
38 )
39 {
41  << "Constructing faPatchField<Type> "
42  << "patchFieldType:" << patchFieldType
43  << "actualPatchType:" << actualPatchType
44  << "p.Type():" << p.type()
45  << endl;
46 
47  auto* ctorPtr = patchConstructorTable(patchFieldType);
48 
49  if (!ctorPtr)
50  {
52  (
53  "patchField",
54  patchFieldType,
55  *patchConstructorTablePtr_
56  ) << exit(FatalError);
57  }
58 
59  auto* patchTypeCtor = patchConstructorTable(p.type());
60 
61  if
62  (
63  actualPatchType == word::null
64  || actualPatchType != p.type()
65  )
66  {
67  if (patchTypeCtor)
68  {
69  return patchTypeCtor(p, iF);
70  }
71  else
72  {
73  return ctorPtr(p, iF);
74  }
75  }
76 
77 
78  tmp<faPatchField<Type>> tfap = ctorPtr(p, iF);
79 
80  // Check if constraint type override and store patchType if so
81  if (patchTypeCtor)
82  {
83  tfap.ref().patchType() = actualPatchType;
84  }
85  return tfap;
86 }
87 
88 
89 template<class Type>
91 (
92  const word& patchFieldType,
93  const faPatch& p,
95 )
96 {
97  return New(patchFieldType, word::null, p, iF);
98 }
99 
100 
101 template<class Type>
103 (
104  const faPatch& p,
106  const dictionary& dict
107 )
108 {
109  DebugInFunction << "Constructing faPatchField<Type>" << endl;
110 
111  const word patchFieldType(dict.get<word>("type"));
112 
113  auto* ctorPtr = dictionaryConstructorTable(patchFieldType);
114 
115  if (!ctorPtr)
116  {
117  if (!disallowGenericFaPatchField)
118  {
119  ctorPtr = dictionaryConstructorTable("generic");
120  }
121 
122  if (!ctorPtr)
123  {
125  << "Unknown patchField type " << patchFieldType
126  << " for patch type " << p.type() << nl << nl
127  << "Valid patchField types are :" << nl
128  << dictionaryConstructorTablePtr_->sortedToc()
129  << exit(FatalIOError);
130  }
131  }
132 
133  auto* patchTypeCtor = dictionaryConstructorTable(p.type());
134 
135  if (patchTypeCtor && patchTypeCtor != ctorPtr)
136  {
138  << "inconsistent patch and patchField types for \n"
139  << " patch type " << p.type()
140  << " and patchField type " << patchFieldType
141  << exit(FatalIOError);
142  }
143 
144  return ctorPtr(p, iF, dict);
145 }
146 
147 
148 template<class Type>
150 (
151  const faPatchField<Type>& ptf,
152  const faPatch& p,
154  const faPatchFieldMapper& pfMapper
155 )
156 {
157  DebugInFunction << "Constructing faPatchField<Type>" << endl;
158 
159  auto* ctorPtr = patchMapperConstructorTable(ptf.type());
160 
161  if (!ctorPtr)
162  {
164  (
165  "patchField",
166  ptf.type(),
167  *patchMapperConstructorTablePtr_
168  ) << exit(FatalError);
169  }
170 
171  auto* patchTypeCtor = patchMapperConstructorTable(p.type());
172 
173  if (patchTypeCtor)
174  {
175  return patchTypeCtor(ptf, p, iF, pfMapper);
176  }
177 
178  return ctorPtr(ptf, p, iF, pfMapper);
179 }
180 
181 
182 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::faPatchField
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:50
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::faPatchField::New
static tmp< faPatchField< Type > > New(const word &patchFieldType, const word &actualPatchType, const faPatch &, const DimensionedField< Type, areaMesh > &)
Definition: faPatchFieldNew.C:33
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::faPatchFieldMapper
Definition: faPatchFieldMapper.H:44
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:227
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
FatalErrorInLookup
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:457
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::nl
constexpr char nl
Definition: Ostream.H:404
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::faPatch
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:69
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54