pointPatchFieldNew.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield |2011 OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const word& patchFieldType,
35  const word& actualPatchType,
36  const pointPatch& p,
38 )
39 {
40  DebugInFunction << "Constructing pointPatchField<Type>" << endl;
41 
42  auto cstrIter = pointPatchConstructorTablePtr_->cfind(patchFieldType);
43 
44  if (!cstrIter.found())
45  {
47  (
48  "patchFieldType",
49  patchFieldType,
50  *pointPatchConstructorTablePtr_
51  ) << exit(FatalError);
52  }
53 
54  autoPtr<pointPatchField<Type>> pfPtr(cstrIter()(p, iF));
55 
56  if
57  (
58  actualPatchType == word::null
59  || actualPatchType != p.type()
60  )
61  {
62  if (pfPtr().constraintType() != p.constraintType())
63  {
64  // Use default constraint type
65  auto patchTypeCstrIter =
66  pointPatchConstructorTablePtr_->cfind(p.type());
67 
68  if (!patchTypeCstrIter.found())
69  {
71  << "inconsistent patch and patchField types for \n"
72  << " patch type " << p.type()
73  << " and patchField type " << patchFieldType
74  << exit(FatalError);
75  }
76 
77  return patchTypeCstrIter()(p, iF);
78  }
79  }
80  else
81  {
82  if (pointPatchConstructorTablePtr_->found(p.type()))
83  {
84  pfPtr().patchType() = actualPatchType;
85  }
86  }
87 
88  return pfPtr;
89 }
90 
91 
92 template<class Type>
94 (
95  const word& patchFieldType,
96  const pointPatch& p,
98 )
99 {
100  return New(patchFieldType, word::null, p, iF);
101 }
102 
103 
104 template<class Type>
106 (
107  const pointPatch& p,
109  const dictionary& dict
110 )
111 {
112  DebugInFunction << "Constructing pointPatchField<Type>" << endl;
113 
114  const word patchFieldType(dict.get<word>("type"));
115 
116  auto cstrIter = dictionaryConstructorTablePtr_->cfind(patchFieldType);
117 
118  if (!cstrIter.found())
119  {
120  if (!disallowGenericPointPatchField)
121  {
122  cstrIter = dictionaryConstructorTablePtr_->cfind("generic");
123  }
124 
125  if (!cstrIter.found())
126  {
128  << "Unknown patchField type " << patchFieldType
129  << " for patch type " << p.type() << nl << nl
130  << "Valid patchField types :" << endl
131  << dictionaryConstructorTablePtr_->sortedToc()
132  << exit(FatalIOError);
133  }
134  }
135 
136  // Construct (but not necessarily returned)
137  autoPtr<pointPatchField<Type>> pfPtr(cstrIter()(p, iF, dict));
138 
139  if
140  (
141  !dict.found("patchType")
142  || dict.get<word>("patchType") != p.type()
143  )
144  {
145  if (pfPtr().constraintType() == p.constraintType())
146  {
147  // Compatible (constraint-wise) with the patch type
148  return pfPtr;
149  }
150  else
151  {
152  // Use default constraint type
153  auto patchTypeCstrIter
154  = dictionaryConstructorTablePtr_->cfind(p.type());
155 
156  if (!patchTypeCstrIter.found())
157  {
159  << "Inconsistent patch and patchField types for\n"
160  << " patch type " << p.type()
161  << " and patchField type " << patchFieldType
162  << exit(FatalIOError);
163  }
164 
165  return patchTypeCstrIter()(p, iF, dict);
166  }
167  }
168 
169  return cstrIter()(p, iF, dict);
170 }
171 
172 
173 template<class Type>
175 (
176  const pointPatchField<Type>& ptf,
177  const pointPatch& p,
179  const pointPatchFieldMapper& pfMapper
180 )
181 {
182  DebugInFunction << "Constructing pointPatchField<Type>" << endl;
183 
184  auto cstrIter = patchMapperConstructorTablePtr_->cfind(ptf.type());
185 
186  if (!cstrIter.found())
187  {
189  (
190  "patchField",
191  ptf.type(),
192  *patchMapperConstructorTablePtr_
193  ) << exit(FatalError);
194  }
195 
196  return cstrIter()(ptf, p, iF, pfMapper);
197 }
198 
199 
200 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::pointPatch
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:58
Foam::pointPatchField
Abstract base class for point-mesh patch fields.
Definition: pointMVCWeight.H:60
Foam::pointPatchFieldMapper
Foam::pointPatchFieldMapper.
Definition: pointPatchFieldMapper.H:48
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:365
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:385
Foam::pointPatchField::New
static autoPtr< pointPatchField< Type > > New(const word &, const pointPatch &, const DimensionedField< Type, pointMesh > &)
Return a pointer to a new patchField created on freestore given.
Definition: pointPatchFieldNew.C:94
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::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54