pointPatchFieldNew.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) 2011-2016 OpenFOAM Foundation
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 pointPatch& p,
38 )
39 {
40  DebugInFunction << "Constructing pointPatchField<Type>" << endl;
41 
42  auto* ctorPtr = pointPatchConstructorTable(patchFieldType);
43 
44  if (!ctorPtr)
45  {
47  (
48  "patchFieldType",
49  patchFieldType,
50  *pointPatchConstructorTablePtr_
51  ) << exit(FatalError);
52  }
53 
54  autoPtr<pointPatchField<Type>> pfPtr(ctorPtr(p, iF));
55 
56  if
57  (
58  actualPatchType.empty()
59  || actualPatchType != p.type()
60  )
61  {
62  if (pfPtr().constraintType() != p.constraintType())
63  {
64  // Incompatible (constraint-wise) with the patch type
65  // - use default constraint type
66 
67  auto* patchTypeCtor = pointPatchConstructorTable(p.type());
68 
69  if (!patchTypeCtor)
70  {
72  << "Inconsistent patch and patchField types for\n"
73  << " patch type " << p.type()
74  << " and patchField type " << patchFieldType
75  << exit(FatalError);
76  }
77 
78  return patchTypeCtor(p, iF);
79  }
80  }
81  else
82  {
83  if (pointPatchConstructorTablePtr_->found(p.type()))
84  {
85  pfPtr().patchType() = actualPatchType;
86  }
87  }
88 
89  return pfPtr;
90 }
91 
92 
93 template<class Type>
95 (
96  const word& patchFieldType,
97  const pointPatch& p,
99 )
100 {
101  return New(patchFieldType, word::null, p, iF);
102 }
103 
104 
105 template<class Type>
107 (
108  const pointPatch& p,
110  const dictionary& dict
111 )
112 {
113  DebugInFunction << "Constructing pointPatchField<Type>" << endl;
114 
115  const word patchFieldType(dict.get<word>("type"));
116 
117  auto* ctorPtr = dictionaryConstructorTable(patchFieldType);
118 
119  if (!ctorPtr)
120  {
121  if (!disallowGenericPointPatchField)
122  {
123  ctorPtr = dictionaryConstructorTable("generic");
124  }
125 
126  if (!ctorPtr)
127  {
129  << "Unknown patchField type " << patchFieldType
130  << " for patch type " << p.type() << nl << nl
131  << "Valid patchField types :" << endl
132  << dictionaryConstructorTablePtr_->sortedToc()
133  << exit(FatalIOError);
134  }
135  }
136 
137  // Construct (but not necessarily returned)
138  autoPtr<pointPatchField<Type>> pfPtr(ctorPtr(p, iF, dict));
139 
140  if
141  (
142  !dict.found("patchType")
143  || dict.get<word>("patchType") != p.type()
144  )
145  {
146  if (pfPtr().constraintType() != p.constraintType())
147  {
148  // Incompatible (constraint-wise) with the patch type
149  // - use default constraint type
150 
151  auto* patchTypeCtor = dictionaryConstructorTable(p.type());
152 
153  if (!patchTypeCtor)
154  {
156  << "Inconsistent patch and patchField types for\n"
157  << " patch type " << p.type()
158  << " and patchField type " << patchFieldType
159  << exit(FatalIOError);
160  }
161 
162  return patchTypeCtor(p, iF, dict);
163  }
164  }
165 
166  return pfPtr;
167 }
168 
169 
170 template<class Type>
172 (
173  const pointPatchField<Type>& ptf,
174  const pointPatch& p,
176  const pointPatchFieldMapper& pfMapper
177 )
178 {
179  DebugInFunction << "Constructing pointPatchField<Type>" << endl;
180 
181  auto* ctorPtr = patchMapperConstructorTable(ptf.type());
182 
183  if (!ctorPtr)
184  {
186  (
187  "patchField",
188  ptf.type(),
189  *patchMapperConstructorTablePtr_
190  ) << exit(FatalError);
191  }
192 
193  return ctorPtr(ptf, p, iF, pfMapper);
194 }
195 
196 
197 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
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: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::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:95
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:453
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::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54