ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / OpenFOAM / fields / pointPatchFields / pointPatchField / pointPatchFieldNew.C
blob1bc079359b3ce757d944a013f92e5fe4e639bc03
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
28 template<class Type>
29 Foam::autoPtr<Foam::pointPatchField<Type> > Foam::pointPatchField<Type>::New
31     const word& patchFieldType,
32     const word& actualPatchType,
33     const pointPatch& p,
34     const DimensionedField<Type, pointMesh>& iF
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     }
46     typename pointPatchConstructorTable::iterator cstrIter =
47         pointPatchConstructorTablePtr_->find(patchFieldType);
49     if (cstrIter == pointPatchConstructorTablePtr_->end())
50     {
51         FatalErrorIn
52         (
53             "PointPatchField<Type>::New"
54             "(const word&, const word&, const pointPatch&, const Field<Type>&)"
55         )   << "Unknown patchFieldType type "
56             << patchFieldType << nl << nl
57             << "Valid patchField types are :" << endl
58             << pointPatchConstructorTablePtr_->sortedToc()
59             << exit(FatalError);
60     }
62     autoPtr<pointPatchField<Type> > pfPtr(cstrIter()(p, iF));
64     if
65     (
66         actualPatchType == word::null
67      || actualPatchType != p.type()
68     )
69     {
70         if (pfPtr().constraintType() != p.constraintType())
71         {
72             // Use default constraint type
73             typename pointPatchConstructorTable::iterator patchTypeCstrIter =
74                 pointPatchConstructorTablePtr_->find(p.type());
76             if (patchTypeCstrIter == pointPatchConstructorTablePtr_->end())
77             {
78                 FatalErrorIn
79                 (
80                     "PointPatchField<Type>::New"
81                     "(const word&, const word&"
82                     ", const pointPatch&, const Field<Type>&)"
83                 )   << "inconsistent patch and patchField types for \n"
84                     << "    patch type " << p.type()
85                     << " and patchField type " << patchFieldType
86                     << exit(FatalError);
87             }
89             return patchTypeCstrIter()(p, iF);
90         }
91     }
93     return pfPtr;
97 template<class Type>
98 Foam::autoPtr<Foam::pointPatchField<Type> > Foam::pointPatchField<Type>::New
100     const word& patchFieldType,
101     const pointPatch& p,
102     const DimensionedField<Type, pointMesh>& iF
105     return New(patchFieldType, word::null, p, iF);
109 template<class Type>
110 Foam::autoPtr<Foam::pointPatchField<Type> > Foam::pointPatchField<Type>::New
112     const pointPatch& p,
113     const DimensionedField<Type, pointMesh>& iF,
114     const dictionary& dict
117     if (debug)
118     {
119         Info<< "PointPatchField<Type>::"
120                "New(const pointPatch&, const Field<Type>&, const dictionary&)"
121                " : constructing pointPatchField<Type>"
122             << endl;
123     }
125     word patchFieldType(dict.lookup("type"));
127     typename dictionaryConstructorTable::iterator cstrIter
128         = dictionaryConstructorTablePtr_->find(patchFieldType);
130     if (cstrIter == dictionaryConstructorTablePtr_->end())
131     {
132         if (!disallowGenericPointPatchField)
133         {
134             cstrIter = dictionaryConstructorTablePtr_->find("generic");
135         }
137         if (cstrIter == dictionaryConstructorTablePtr_->end())
138         {
139             FatalIOErrorIn
140             (
141                 "PointPatchField<Type>::"
142                 "New(const pointPatch&, const Field<Type>&, const dictionary&)",
143                 dict
144             )   << "Unknown patchField type " << patchFieldType
145                 << " for patch type " << p.type() << nl << nl
146                 << "Valid patchField types are :" << endl
147                 << dictionaryConstructorTablePtr_->sortedToc()
148                 << exit(FatalIOError);
149         }
150     }
152     // Construct (but not necesarily returned)
153     autoPtr<pointPatchField<Type> > pfPtr(cstrIter()(p, iF, dict));
155     if
156     (
157        !dict.found("patchType")
158      || word(dict.lookup("patchType")) != p.type()
159     )
160     {
161         if (pfPtr().constraintType() == p.constraintType())
162         {
163             // Compatible (constraint-wise) with the patch type
164             return pfPtr;
165         }
166         else
167         {
168             // Use default constraint type
169             typename dictionaryConstructorTable::iterator patchTypeCstrIter
170                 = dictionaryConstructorTablePtr_->find(p.type());
172             if (patchTypeCstrIter == dictionaryConstructorTablePtr_->end())
173             {
174                 FatalIOErrorIn
175                 (
176                     "PointPatchField<Type>const pointPatch&, "
177                     "const Field<Type>&, const dictionary&)",
178                     dict
179                 )   << "inconsistent patch and patchField types for \n"
180                     << "    patch type " << p.type()
181                     << " and patchField type " << patchFieldType
182                     << exit(FatalIOError);
183             }
185             return patchTypeCstrIter()(p, iF, dict);
186         }
187     }
189     return cstrIter()(p, iF, dict);
193 // Return a pointer to a new patch created on freestore from
194 // a given pointPatchField<Type> mapped onto a new patch
195 template<class Type>
196 Foam::autoPtr<Foam::pointPatchField<Type> > Foam::pointPatchField<Type>::New
198     const pointPatchField<Type>& ptf,
199     const pointPatch& p,
200     const DimensionedField<Type, pointMesh>& iF,
201     const pointPatchFieldMapper& pfMapper
204     if (debug)
205     {
206         Info<< "PointPatchField<Type>::"
207                "New(const pointPatchField<Type>&,"
208                " const pointPatch&, const Field<Type>&, "
209                "const pointPatchFieldMapper&) : "
210                "constructing pointPatchField<Type>"
211             << endl;
212     }
214     typename patchMapperConstructorTable::iterator cstrIter =
215         patchMapperConstructorTablePtr_->find(ptf.type());
217     if (cstrIter == patchMapperConstructorTablePtr_->end())
218     {
219         FatalErrorIn
220         (
221             "PointPatchField<Type>::New"
222             "("
223             "const pointPatchField<Type>&, "
224             "const pointPatch&, "
225             "const DimensionedField<Type, pointMesh>&, "
226             "const pointPatchFieldMapper&"
227             ")"
228         )   << "Unknown patchField type "
229             << ptf.type() << nl << nl
230             << "Valid patchField types are :" << endl
231             << patchMapperConstructorTablePtr_->sortedToc()
232             << exit(FatalError);
233     }
235     return cstrIter()(ptf, p, iF, pfMapper);
239 // ************************************************************************* //