FreeFOAM The Cross-Platform CFD Toolkit
newFvsPatchField.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27 
28 namespace Foam
29 {
30 
31 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
34 tmp<fvsPatchField<Type> > fvsPatchField<Type>::New
35 (
36  const word& patchFieldType,
37  const fvPatch& p,
39 )
40 {
41  if (debug)
42  {
43  Info<< "fvsPatchField<Type>::New(const word&, const fvPatch&, "
44  "const Field<Type>&) : "
45  "constructing fvsPatchField<Type>"
46  << endl;
47  }
48 
49  typename patchConstructorTable::iterator cstrIter =
50  patchConstructorTablePtr_->find(patchFieldType);
51 
52  if (cstrIter == patchConstructorTablePtr_->end())
53  {
55  (
56  "fvsPatchField<Type>::New(const word&, const fvPatch&, "
57  "const Field<Type>&)"
58  ) << "Unknown patchTypefield type " << patchFieldType
59  << endl << endl
60  << "Valid patchField types are :" << endl
61  << patchConstructorTablePtr_->sortedToc()
62  << exit(FatalError);
63  }
64 
65  typename patchConstructorTable::iterator patchTypeCstrIter =
66  patchConstructorTablePtr_->find(p.type());
67 
68  if (patchTypeCstrIter != patchConstructorTablePtr_->end())
69  {
70  return patchTypeCstrIter()(p, iF);
71  }
72  else
73  {
74  return cstrIter()(p, iF);
75  }
76 }
77 
78 
79 template<class Type>
81 (
82  const fvPatch& p,
84  const dictionary& dict
85 )
86 {
87  if (debug)
88  {
89  Info<< "fvsPatchField<Type>::New(const fvPatch&, const Field<Type>&, "
90  "const dictionary&) : "
91  "constructing fvsPatchField<Type>"
92  << endl;
93  }
94 
95  word patchFieldType(dict.lookup("type"));
96 
97  typename dictionaryConstructorTable::iterator cstrIter
98  = dictionaryConstructorTablePtr_->find(patchFieldType);
99 
100  if (cstrIter == dictionaryConstructorTablePtr_->end())
101  {
102  if (!disallowDefaultFvsPatchField)
103  {
104  cstrIter = dictionaryConstructorTablePtr_->find("default");
105  }
106 
107  if (cstrIter == dictionaryConstructorTablePtr_->end())
108  {
110  (
111  "fvsPatchField<Type>::New(const fvPatch&, const Field<Type>&, "
112  "const dictionary&)",
113  dict
114  ) << "Unknown patchField type " << patchFieldType
115  << " for patch type " << p.type() << endl << endl
116  << "Valid patchField types are :" << endl
117  << dictionaryConstructorTablePtr_->sortedToc()
118  << exit(FatalIOError);
119  }
120  }
121 
122  if
123  (
124  !dict.found("patchType")
125  || word(dict.lookup("patchType")) != p.type()
126  )
127  {
128  typename dictionaryConstructorTable::iterator patchTypeCstrIter
129  = dictionaryConstructorTablePtr_->find(p.type());
130 
131  if
132  (
133  patchTypeCstrIter != dictionaryConstructorTablePtr_->end()
134  && patchTypeCstrIter() != cstrIter()
135  )
136  {
138  (
139  "fvsPatchField<Type>const fvPatch&, const Field<Type>&, "
140  "const dictionary&)",
141  dict
142  ) << "inconsistent patch and patchField types for \n"
143  " patch type " << p.type()
144  << " and patchField type " << patchFieldType
145  << exit(FatalIOError);
146  }
147  }
148 
149  return cstrIter()(p, iF, dict);
150 }
151 
152 
153 // Return a pointer to a new patch created on freestore from
154 // a given fvsPatchField<Type> mapped onto a new patch
155 template<class Type>
157 (
158  const fvsPatchField<Type>& ptf,
159  const fvPatch& p,
161  const fvPatchFieldMapper& pfMapper
162 )
163 {
164  if (debug)
165  {
166  Info<< "fvsPatchField<Type>::New(const fvsPatchField<Type>&,"
167  " const fvPatch&, const Field<Type>&, "
168  "const fvPatchFieldMapper&) : "
169  "constructing fvsPatchField<Type>"
170  << endl;
171  }
172 
173  typename patchMapperConstructorTable::iterator cstrIter =
174  patchMapperConstructorTablePtr_->find(ptf.type());
175 
176  if (cstrIter == patchMapperConstructorTablePtr_->end())
177  {
179  (
180  "fvsPatchField<Type>::New(const fvsPatchField<Type>&, "
181  "const fvPatch&, const Field<Type>&, "
182  "const fvPatchFieldMapper&)"
183  ) << "unknown patchTypefield type " << ptf.type() << endl << endl
184  << "Valid patchField types are :" << endl
185  << patchMapperConstructorTablePtr_->sortedToc()
186  << exit(FatalError);
187  }
188 
189  typename patchMapperConstructorTable::iterator
190  patchTypeCstrIter = patchMapperConstructorTablePtr_->find(p.type());
191 
192  if (patchTypeCstrIter != patchMapperConstructorTablePtr_->end())
193  {
194  return patchTypeCstrIter()(ptf, p, iF, pfMapper);
195  }
196  else
197  {
198  return cstrIter()(ptf, p, iF, pfMapper);
199  }
200 }
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace Foam
206 
207 // ************************ vim: set sw=4 sts=4 et: ************************ //