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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of2011 OpenFOAM.
10 
11  2011 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  2011 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 with2011 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,
34  const DimensionedField<Type, pointMesh>& iF
35 )
36 {
37  if (debug)
38  {
39  Info<< "PointPatchField<Type>::"
40  "New(const word&, const word&"
41  ", const pointPatch&, const Field<Type>&) : "
42  "constructing pointPatchField<Type>"
43  << endl;
44  }
45 
46  typename pointPatchConstructorTable::iterator cstrIter =
47  pointPatchConstructorTablePtr_->find(patchFieldType);
48 
49  if (cstrIter == pointPatchConstructorTablePtr_->end())
50  {
52  << "Unknown patchFieldType type "
53  << patchFieldType << nl << nl
54  << "Valid patchField types are :" << endl
55  << pointPatchConstructorTablePtr_->sortedToc()
56  << exit(FatalError);
57  }
58 
59  autoPtr<pointPatchField<Type> > pfPtr(cstrIter()(p, iF));
60 
61  if
62  (
63  actualPatchType == word::null
64  || actualPatchType != p.type()
65  )
66  {
67  if (pfPtr().constraintType() != p.constraintType())
68  {
69  // Use default constraint type
70  typename pointPatchConstructorTable::iterator patchTypeCstrIter =
71  pointPatchConstructorTablePtr_->find(p.type());
72 
73  if (patchTypeCstrIter == pointPatchConstructorTablePtr_->end())
74  {
76  << "inconsistent patch and patchField types for \n"
77  << " patch type " << p.type()
78  << " and patchField type " << patchFieldType
79  << exit(FatalError);
80  }
81 
82  return patchTypeCstrIter()(p, iF);
83  }
84  }
85  else
86  {
87  if (pointPatchConstructorTablePtr_->found(p.type()))
88  {
89  pfPtr().patchType() = actualPatchType;
90  }
91  }
92 
93  return pfPtr;
94 }
95 
96 
97 template<class Type>
99 (
100  const word& patchFieldType,
101  const pointPatch& p,
102  const DimensionedField<Type, pointMesh>& iF
103 )
104 {
105  return New(patchFieldType, word::null, p, iF);
106 }
107 
108 
109 template<class Type>
111 (
112  const pointPatch& p,
113  const DimensionedField<Type, pointMesh>& iF,
114  const dictionary& dict
115 )
116 {
117  if (debug)
118  {
119  Info<< "PointPatchField<Type>::"
120  "New(const pointPatch&, const Field<Type>&, const dictionary&)"
121  " : constructing pointPatchField<Type>"
122  << endl;
123  }
124 
125  word patchFieldType(dict.lookup("type"));
126 
127  typename dictionaryConstructorTable::iterator cstrIter
128  = dictionaryConstructorTablePtr_->find(patchFieldType);
129 
130  if (cstrIter == dictionaryConstructorTablePtr_->end())
131  {
132  if (!disallowGenericPointPatchField)
133  {
134  cstrIter = dictionaryConstructorTablePtr_->find("generic");
135  }
136 
137  if (cstrIter == dictionaryConstructorTablePtr_->end())
138  {
140  (
141  dict
142  ) << "Unknown patchField type " << patchFieldType
143  << " for patch type " << p.type() << nl << nl
144  << "Valid patchField types are :" << endl
145  << dictionaryConstructorTablePtr_->sortedToc()
146  << exit(FatalIOError);
147  }
148  }
149 
150  // Construct (but not necesarily returned)
151  autoPtr<pointPatchField<Type> > pfPtr(cstrIter()(p, iF, dict));
152 
153  if
154  (
155  !dict.found("patchType")
156  || word(dict.lookup("patchType")) != p.type()
157  )
158  {
159  if (pfPtr().constraintType() == p.constraintType())
160  {
161  // Compatible (constraint-wise) with the patch type
162  return pfPtr;
163  }
164  else
165  {
166  // Use default constraint type
167  typename dictionaryConstructorTable::iterator patchTypeCstrIter
168  = dictionaryConstructorTablePtr_->find(p.type());
169 
170  if (patchTypeCstrIter == dictionaryConstructorTablePtr_->end())
171  {
173  (
174  dict
175  ) << "inconsistent patch and patchField types for \n"
176  << " patch type " << p.type()
177  << " and patchField type " << patchFieldType
178  << exit(FatalIOError);
179  }
180 
181  return patchTypeCstrIter()(p, iF, dict);
182  }
183  }
184 
185  return cstrIter()(p, iF, dict);
186 }
187 
188 
189 // Return a pointer to a new patch created on freestore from
190 // a given pointPatchField<Type> mapped onto a new patch
191 template<class Type>
193 (
194  const pointPatchField<Type>& ptf,
195  const pointPatch& p,
196  const DimensionedField<Type, pointMesh>& iF,
197  const pointPatchFieldMapper& pfMapper
198 )
199 {
200  if (debug)
201  {
202  Info<< "PointPatchField<Type>::"
203  "New(const pointPatchField<Type>&,"
204  " const pointPatch&, const Field<Type>&, "
205  "const pointPatchFieldMapper&) : "
206  "constructing pointPatchField<Type>"
207  << endl;
208  }
209 
210  typename patchMapperConstructorTable::iterator cstrIter =
211  patchMapperConstructorTablePtr_->find(ptf.type());
212 
213  if (cstrIter == patchMapperConstructorTablePtr_->end())
214  {
216  << "Unknown patchField type "
217  << ptf.type() << nl << nl
218  << "Valid patchField types are :" << endl
219  << patchMapperConstructorTablePtr_->sortedToc()
220  << exit(FatalError);
221  }
222 
223  return cstrIter()(ptf, p, iF, pfMapper);
224 }
225 
226 
227 // ************************************************************************* //
p
p
Definition: pEqn.H:62
Foam::compressible::New
autoPtr< BasicCompressibleTurbulenceModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleTurbulenceModel::transportModel &transport, const word &propertiesName)
Definition: turbulentFluidThermoModel.C:36
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.
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330