pointPatchFieldNew.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-2018 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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template<class Type>
30 (
31  const word& patchFieldType,
32  const word& actualPatchType,
33  const pointPatch& p,
35 )
36 {
37  if (debug)
38  {
39  InfoInFunction << "Constructing pointPatchField<Type>" << endl;
40  }
41 
42  typename pointPatchConstructorTable::iterator cstrIter =
43  pointPatchConstructorTablePtr_->find(patchFieldType);
44 
45  if (cstrIter == pointPatchConstructorTablePtr_->end())
46  {
48  << "Unknown patchFieldType type "
49  << patchFieldType << nl << nl
50  << "Valid patchField types are :" << endl
51  << pointPatchConstructorTablePtr_->sortedToc()
52  << exit(FatalError);
53  }
54 
55  autoPtr<pointPatchField<Type>> pfPtr(cstrIter()(p, iF));
56 
57  if
58  (
59  actualPatchType == word::null
60  || actualPatchType != p.type()
61  )
62  {
63  if (pfPtr().constraintType() != p.constraintType())
64  {
65  // Use default constraint type
66  typename pointPatchConstructorTable::iterator patchTypeCstrIter =
67  pointPatchConstructorTablePtr_->find(p.type());
68 
69  if (patchTypeCstrIter == pointPatchConstructorTablePtr_->end())
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 patchTypeCstrIter()(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  if (debug)
114  {
115  InfoInFunction << "Constructing pointPatchField<Type>" << endl;
116  }
117 
118  word patchFieldType(dict.lookup("type"));
119 
120  typename dictionaryConstructorTable::iterator cstrIter
121  = dictionaryConstructorTablePtr_->find(patchFieldType);
122 
123  if (cstrIter == dictionaryConstructorTablePtr_->end())
124  {
125  if (!disallowGenericPointPatchField)
126  {
127  cstrIter = dictionaryConstructorTablePtr_->find("generic");
128  }
129 
130  if (cstrIter == dictionaryConstructorTablePtr_->end())
131  {
133  (
134  dict
135  ) << "Unknown patchField type " << patchFieldType
136  << " for patch type " << p.type() << nl << nl
137  << "Valid patchField types are :" << endl
138  << dictionaryConstructorTablePtr_->sortedToc()
139  << exit(FatalIOError);
140  }
141  }
142 
143  // Construct (but not necessarily returned)
144  autoPtr<pointPatchField<Type>> pfPtr(cstrIter()(p, iF, dict));
145 
146  if
147  (
148  !dict.found("patchType")
149  || word(dict.lookup("patchType")) != p.type()
150  )
151  {
152  if (pfPtr().constraintType() == p.constraintType())
153  {
154  // Compatible (constraint-wise) with the patch type
155  return pfPtr;
156  }
157  else
158  {
159  // Use default constraint type
160  typename dictionaryConstructorTable::iterator patchTypeCstrIter
161  = dictionaryConstructorTablePtr_->find(p.type());
162 
163  if (patchTypeCstrIter == dictionaryConstructorTablePtr_->end())
164  {
166  (
167  dict
168  ) << "inconsistent patch and patchField types for \n"
169  << " patch type " << p.type()
170  << " and patchField type " << patchFieldType
171  << exit(FatalIOError);
172  }
173 
174  return patchTypeCstrIter()(p, iF, dict);
175  }
176  }
177 
178  return cstrIter()(p, iF, dict);
179 }
180 
181 
182 template<class Type>
184 (
185  const pointPatchField<Type>& ptf,
186  const pointPatch& p,
188  const pointPatchFieldMapper& pfMapper
189 )
190 {
191  if (debug)
192  {
193  InfoInFunction << "Constructing pointPatchField<Type>" << endl;
194  }
195 
196  typename patchMapperConstructorTable::iterator cstrIter =
197  patchMapperConstructorTablePtr_->find(ptf.type());
198 
199  if (cstrIter == patchMapperConstructorTablePtr_->end())
200  {
202  << "Unknown patchField type "
203  << ptf.type() << nl << nl
204  << "Valid patchField types are :" << endl
205  << patchMapperConstructorTablePtr_->sortedToc()
206  << exit(FatalError);
207  }
208 
209  return cstrIter()(ptf, p, iF, pfMapper);
210 }
211 
212 
213 // ************************************************************************* //
dictionary dict
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:667
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Foam::pointPatchFieldMapper.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Abstract base class for point-mesh patch fields.
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
A class for handling words, derived from string.
Definition: word.H:59
virtual const word & constraintType() const
Return the constraint type this pointPatch implements.
Definition: pointPatch.H:154
static const char nl
Definition: Ostream.H:260
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
Basic pointPatch represents a set of points from the mesh.
Definition: pointPatch.H:56
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
static autoPtr< pointPatchField< Type > > New(const word &, const pointPatch &, const DimensionedField< Type, pointMesh > &)
Return a pointer to a new patchField created on freestore given.
volScalarField & p
word patchFieldType(const PatchField &pf)
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812
IOerror FatalIOError
#define InfoInFunction
Report an information message using Foam::Info.