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 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 {
40  DebugInFunction << "Constructing faPatchField<Type>" << endl;
41 
42  auto cstrIter = patchConstructorTablePtr_->cfind(patchFieldType);
43 
44  if (!cstrIter.found())
45  {
47  (
48  "patchField",
49  patchFieldType,
50  *patchConstructorTablePtr_
51  ) << exit(FatalError);
52  }
53 
54  auto patchTypeCstrIter = patchConstructorTablePtr_->cfind(p.type());
55 
56  if
57  (
58  actualPatchType == word::null
59  || actualPatchType != p.type()
60  )
61  {
62  if (patchTypeCstrIter.found())
63  {
64  return patchTypeCstrIter()(p, iF);
65  }
66  else
67  {
68  return cstrIter()(p, iF);
69  }
70  }
71 
72 
73  tmp<faPatchField<Type>> tfap = cstrIter()(p, iF);
74 
75  // Check if constraint type override and store patchType if so
76  if (patchTypeCstrIter.found())
77  {
78  tfap.ref().patchType() = actualPatchType;
79  }
80  return tfap;
81 }
82 
83 
84 template<class Type>
86 (
87  const word& patchFieldType,
88  const faPatch& p,
90 )
91 {
92  return New(patchFieldType, word::null, p, iF);
93 }
94 
95 
96 template<class Type>
98 (
99  const faPatch& p,
101  const dictionary& dict
102 )
103 {
104  DebugInFunction << "Constructing faPatchField<Type>" << endl;
105 
106  const word patchFieldType(dict.get<word>("type"));
107 
108  auto cstrIter = dictionaryConstructorTablePtr_->cfind(patchFieldType);
109 
110  if (!cstrIter.found())
111  {
112  if (!disallowGenericFaPatchField)
113  {
114  cstrIter = dictionaryConstructorTablePtr_->cfind("generic");
115  }
116 
117  if (!cstrIter.found())
118  {
120  << "Unknown patchField type " << patchFieldType
121  << " for patch type " << p.type() << nl << nl
122  << "Valid patchField types are :" << nl
123  << dictionaryConstructorTablePtr_->sortedToc()
124  << exit(FatalIOError);
125  }
126  }
127 
128  auto patchTypeCstrIter = dictionaryConstructorTablePtr_->cfind(p.type());
129 
130  if (patchTypeCstrIter.found() && *patchTypeCstrIter != *cstrIter)
131  {
133  << "inconsistent patch and patchField types for \n"
134  << " patch type " << p.type()
135  << " and patchField type " << patchFieldType
136  << exit(FatalIOError);
137  }
138 
139  return cstrIter()(p, iF, dict);
140 }
141 
142 
143 template<class Type>
145 (
146  const faPatchField<Type>& ptf,
147  const faPatch& p,
149  const faPatchFieldMapper& pfMapper
150 )
151 {
152  DebugInFunction << "Constructing faPatchField<Type>" << endl;
153 
154  auto cstrIter = patchMapperConstructorTablePtr_->cfind(ptf.type());
155 
156  if (!cstrIter.found())
157  {
159  (
160  "patchField",
161  ptf.type(),
162  *patchMapperConstructorTablePtr_
163  ) << exit(FatalError);
164  }
165 
166  auto patchTypeCstrIter = patchMapperConstructorTablePtr_->cfind(p.type());
167 
168  if (patchTypeCstrIter.found())
169  {
170  return patchTypeCstrIter()(ptf, p, iF, pfMapper);
171  }
172 
173  return cstrIter()(ptf, p, iF, pfMapper);
174 }
175 
176 
177 // ************************************************************************* //
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:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::faPatchField::New
static tmp< faPatchField< Type > > New(const word &patchFieldType, const word &actualPatchType, const faPatch &, const DimensionedField< Type, areaMesh > &)
Return a pointer to a new patchField created on freestore given.
Definition: faPatchFieldNew.C:33
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::faPatchFieldMapper
Definition: faPatchFieldMapper.H:44
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:258
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:356
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:121
FatalErrorInLookup
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:359
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:372
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:375
Foam::faPatch
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:65
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54