1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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 #include "genericFvPatchField.H"
27 #include "fvPatchFieldMapper.H"
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 Foam::genericFvPatchField<Type>::genericFvPatchField
35 const DimensionedField<Type, volMesh>& iF
38 calculatedFvPatchField<Type>(p, iF)
42 "genericFvPatchField<Type>::genericFvPatchField"
43 "(const fvPatch& p, const DimensionedField<Type, volMesh>& iF)"
44 ) << "Not Implemented\n "
45 << "Trying to construct an genericFvPatchField on patch "
46 << this->patch().name()
47 << " of field " << this->dimensionedInternalField().name()
53 Foam::genericFvPatchField<Type>::genericFvPatchField
56 const DimensionedField<Type, volMesh>& iF,
57 const dictionary& dict
60 calculatedFvPatchField<Type>(p, iF, dict, false),
61 actualTypeName_(dict.lookup("type")),
64 if (!dict.found("value"))
68 "genericFvPatchField<Type>::genericFvPatchField"
69 "(const fvPatch&, const Field<Type>&, const dictionary&)",
71 ) << "\n Cannot find 'value' entry"
72 << " on patch " << this->patch().name()
73 << " of field " << this->dimensionedInternalField().name()
74 << " in file " << this->dimensionedInternalField().objectPath()
76 << " which is required to set the"
77 " values of the generic patch field." << nl
78 << " (Actual type " << actualTypeName_ << ")" << nl
79 << "\n Please add the 'value' entry to the write function "
80 "of the user-defined boundary-condition\n"
81 << exit(FatalIOError);
84 forAllConstIter(dictionary, dict_, iter)
86 if (iter().keyword() != "type" && iter().keyword() != "value")
91 && iter().stream().size()
94 ITstream& is = iter().stream();
102 && firstToken.wordToken() == "nonuniform"
105 token fieldToken(is);
107 if (!fieldToken.isCompound())
112 && fieldToken.labelToken() == 0
125 "genericFvPatchField<Type>::genericFvPatchField"
126 "(const fvPatch&, const Field<Type>&, "
127 "const dictionary&)",
129 ) << "\n token following 'nonuniform' "
131 << "\n on patch " << this->patch().name()
133 << this->dimensionedInternalField().name()
135 << this->dimensionedInternalField().objectPath()
136 << exit(FatalIOError);
141 fieldToken.compoundToken().type()
142 == token::Compound<List<scalar> >::typeName
145 scalarField* fPtr = new scalarField;
148 dynamicCast<token::Compound<List<scalar> > >
150 fieldToken.transferCompoundToken()
154 if (fPtr->size() != this->size())
158 "genericFvPatchField<Type>::genericFvPatchField"
159 "(const fvPatch&, const Field<Type>&, "
160 "const dictionary&)",
162 ) << "\n size of field " << iter().keyword()
163 << " (" << fPtr->size() << ')'
164 << " is not the same size as the patch ("
165 << this->size() << ')'
166 << "\n on patch " << this->patch().name()
168 << this->dimensionedInternalField().name()
170 << this->dimensionedInternalField().objectPath()
171 << exit(FatalIOError);
174 scalarFields_.insert(iter().keyword(), fPtr);
178 fieldToken.compoundToken().type()
179 == token::Compound<List<vector> >::typeName
182 vectorField* fPtr = new vectorField;
185 dynamicCast<token::Compound<List<vector> > >
187 fieldToken.transferCompoundToken()
191 if (fPtr->size() != this->size())
195 "genericFvPatchField<Type>::genericFvPatchField"
196 "(const fvPatch&, const Field<Type>&, "
197 "const dictionary&)",
199 ) << "\n size of field " << iter().keyword()
200 << " (" << fPtr->size() << ')'
201 << " is not the same size as the patch ("
202 << this->size() << ')'
203 << "\n on patch " << this->patch().name()
205 << this->dimensionedInternalField().name()
207 << this->dimensionedInternalField().objectPath()
208 << exit(FatalIOError);
211 vectorFields_.insert(iter().keyword(), fPtr);
215 fieldToken.compoundToken().type()
216 == token::Compound<List<sphericalTensor> >::typeName
219 sphericalTensorField* fPtr = new sphericalTensorField;
224 token::Compound<List<sphericalTensor> >
227 fieldToken.transferCompoundToken()
231 if (fPtr->size() != this->size())
235 "genericFvPatchField<Type>::genericFvPatchField"
236 "(const fvPatch&, const Field<Type>&, "
237 "const dictionary&)",
239 ) << "\n size of field " << iter().keyword()
240 << " (" << fPtr->size() << ')'
241 << " is not the same size as the patch ("
242 << this->size() << ')'
243 << "\n on patch " << this->patch().name()
245 << this->dimensionedInternalField().name()
247 << this->dimensionedInternalField().objectPath()
248 << exit(FatalIOError);
251 sphericalTensorFields_.insert(iter().keyword(), fPtr);
255 fieldToken.compoundToken().type()
256 == token::Compound<List<symmTensor> >::typeName
259 symmTensorField* fPtr = new symmTensorField;
264 token::Compound<List<symmTensor> >
267 fieldToken.transferCompoundToken()
271 if (fPtr->size() != this->size())
275 "genericFvPatchField<Type>::genericFvPatchField"
276 "(const fvPatch&, const Field<Type>&, "
277 "const dictionary&)",
279 ) << "\n size of field " << iter().keyword()
280 << " (" << fPtr->size() << ')'
281 << " is not the same size as the patch ("
282 << this->size() << ')'
283 << "\n on patch " << this->patch().name()
285 << this->dimensionedInternalField().name()
287 << this->dimensionedInternalField().objectPath()
288 << exit(FatalIOError);
291 symmTensorFields_.insert(iter().keyword(), fPtr);
295 fieldToken.compoundToken().type()
296 == token::Compound<List<tensor> >::typeName
299 tensorField* fPtr = new tensorField;
302 dynamicCast<token::Compound<List<tensor> > >
304 fieldToken.transferCompoundToken()
308 if (fPtr->size() != this->size())
312 "genericFvPatchField<Type>::genericFvPatchField"
313 "(const fvPatch&, const Field<Type>&, "
314 "const dictionary&)",
316 ) << "\n size of field " << iter().keyword()
317 << " (" << fPtr->size() << ')'
318 << " is not the same size as the patch ("
319 << this->size() << ')'
320 << "\n on patch " << this->patch().name()
322 << this->dimensionedInternalField().name()
324 << this->dimensionedInternalField().objectPath()
325 << exit(FatalIOError);
328 tensorFields_.insert(iter().keyword(), fPtr);
334 "genericFvPatchField<Type>::genericFvPatchField"
335 "(const fvPatch&, const Field<Type>&, "
336 "const dictionary&)",
338 ) << "\n compound " << fieldToken.compoundToken()
340 << "\n on patch " << this->patch().name()
342 << this->dimensionedInternalField().name()
344 << this->dimensionedInternalField().objectPath()
345 << exit(FatalIOError);
351 && firstToken.wordToken() == "uniform"
354 token fieldToken(is);
356 if (!fieldToken.isPunctuation())
370 // Read as scalarList.
371 is.putBack(fieldToken);
375 if (l.size() == vector::nComponents)
377 vector vs(l[0], l[1], l[2]);
382 new vectorField(this->size(), vs)
385 else if (l.size() == sphericalTensor::nComponents)
387 sphericalTensor vs(l[0]);
389 sphericalTensorFields_.insert
392 new sphericalTensorField(this->size(), vs)
395 else if (l.size() == symmTensor::nComponents)
397 symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
399 symmTensorFields_.insert
402 new symmTensorField(this->size(), vs)
405 else if (l.size() == tensor::nComponents)
417 new tensorField(this->size(), vs)
424 "genericFvPatchField<Type>::genericFvPatchField"
425 "(const fvPatch&, const Field<Type>&, "
426 "const dictionary&)",
428 ) << "\n unrecognised native type " << l
429 << "\n on patch " << this->patch().name()
431 << this->dimensionedInternalField().name()
433 << this->dimensionedInternalField().objectPath()
434 << exit(FatalIOError);
445 Foam::genericFvPatchField<Type>::genericFvPatchField
447 const genericFvPatchField<Type>& ptf,
449 const DimensionedField<Type, volMesh>& iF,
450 const fvPatchFieldMapper& mapper
453 calculatedFvPatchField<Type>(ptf, p, iF, mapper),
454 actualTypeName_(ptf.actualTypeName_),
459 HashPtrTable<scalarField>,
467 new scalarField(*iter(), mapper)
473 HashPtrTable<vectorField>,
481 new vectorField(*iter(), mapper)
487 HashPtrTable<sphericalTensorField>,
488 ptf.sphericalTensorFields_,
492 sphericalTensorFields_.insert
495 new sphericalTensorField(*iter(), mapper)
501 HashPtrTable<symmTensorField>,
502 ptf.symmTensorFields_,
506 symmTensorFields_.insert
509 new symmTensorField(*iter(), mapper)
515 HashPtrTable<tensorField>,
523 new tensorField(*iter(), mapper)
530 Foam::genericFvPatchField<Type>::genericFvPatchField
532 const genericFvPatchField<Type>& ptf
535 calculatedFvPatchField<Type>(ptf),
536 actualTypeName_(ptf.actualTypeName_),
538 scalarFields_(ptf.scalarFields_),
539 vectorFields_(ptf.vectorFields_),
540 sphericalTensorFields_(ptf.sphericalTensorFields_),
541 symmTensorFields_(ptf.symmTensorFields_),
542 tensorFields_(ptf.tensorFields_)
547 Foam::genericFvPatchField<Type>::genericFvPatchField
549 const genericFvPatchField<Type>& ptf,
550 const DimensionedField<Type, volMesh>& iF
553 calculatedFvPatchField<Type>(ptf, iF),
554 actualTypeName_(ptf.actualTypeName_),
556 scalarFields_(ptf.scalarFields_),
557 vectorFields_(ptf.vectorFields_),
558 sphericalTensorFields_(ptf.sphericalTensorFields_),
559 symmTensorFields_(ptf.symmTensorFields_),
560 tensorFields_(ptf.tensorFields_)
564 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
567 void Foam::genericFvPatchField<Type>::autoMap
569 const fvPatchFieldMapper& m
572 calculatedFvPatchField<Type>::autoMap(m);
576 HashPtrTable<scalarField>,
586 HashPtrTable<vectorField>,
596 HashPtrTable<sphericalTensorField>,
597 sphericalTensorFields_,
606 HashPtrTable<symmTensorField>,
616 HashPtrTable<tensorField>,
627 void Foam::genericFvPatchField<Type>::rmap
629 const fvPatchField<Type>& ptf,
630 const labelList& addr
633 calculatedFvPatchField<Type>::rmap(ptf, addr);
635 const genericFvPatchField<Type>& dptf =
636 refCast<const genericFvPatchField<Type> >(ptf);
640 HashPtrTable<scalarField>,
645 HashPtrTable<scalarField>::const_iterator dptfIter =
646 dptf.scalarFields_.find(iter.key());
648 if (dptfIter != dptf.scalarFields_.end())
650 iter()->rmap(*dptfIter(), addr);
656 HashPtrTable<vectorField>,
661 HashPtrTable<vectorField>::const_iterator dptfIter =
662 dptf.vectorFields_.find(iter.key());
664 if (dptfIter != dptf.vectorFields_.end())
666 iter()->rmap(*dptfIter(), addr);
672 HashPtrTable<sphericalTensorField>,
673 sphericalTensorFields_,
677 HashPtrTable<sphericalTensorField>::const_iterator dptfIter =
678 dptf.sphericalTensorFields_.find(iter.key());
680 if (dptfIter != dptf.sphericalTensorFields_.end())
682 iter()->rmap(*dptfIter(), addr);
688 HashPtrTable<symmTensorField>,
693 HashPtrTable<symmTensorField>::const_iterator dptfIter =
694 dptf.symmTensorFields_.find(iter.key());
696 if (dptfIter != dptf.symmTensorFields_.end())
698 iter()->rmap(*dptfIter(), addr);
704 HashPtrTable<tensorField>,
709 HashPtrTable<tensorField>::const_iterator dptfIter =
710 dptf.tensorFields_.find(iter.key());
712 if (dptfIter != dptf.tensorFields_.end())
714 iter()->rmap(*dptfIter(), addr);
721 Foam::tmp<Foam::Field<Type> >
722 Foam::genericFvPatchField<Type>::valueInternalCoeffs
724 const tmp<scalarField>&
729 "genericFvPatchField<Type>::"
730 "valueInternalCoeffs(const tmp<scalarField>&) const"
732 "valueInternalCoeffs cannot be called for a genericFvPatchField"
733 " (actual type " << actualTypeName_ << ")"
734 << "\n on patch " << this->patch().name()
735 << " of field " << this->dimensionedInternalField().name()
736 << " in file " << this->dimensionedInternalField().objectPath()
737 << "\n You are probably trying to solve for a field with a "
738 "generic boundary condition."
746 Foam::tmp<Foam::Field<Type> >
747 Foam::genericFvPatchField<Type>::valueBoundaryCoeffs
749 const tmp<scalarField>&
754 "genericFvPatchField<Type>::"
755 "valueBoundaryCoeffs(const tmp<scalarField>&) const"
757 "valueBoundaryCoeffs cannot be called for a genericFvPatchField"
758 " (actual type " << actualTypeName_ << ")"
759 << "\n on patch " << this->patch().name()
760 << " of field " << this->dimensionedInternalField().name()
761 << " in file " << this->dimensionedInternalField().objectPath()
762 << "\n You are probably trying to solve for a field with a "
763 "generic boundary condition."
771 Foam::tmp<Foam::Field<Type> >
772 Foam::genericFvPatchField<Type>::gradientInternalCoeffs() const
776 "genericFvPatchField<Type>::"
777 "gradientInternalCoeffs() const"
779 "gradientInternalCoeffs cannot be called for a genericFvPatchField"
780 " (actual type " << actualTypeName_ << ")"
781 << "\n on patch " << this->patch().name()
782 << " of field " << this->dimensionedInternalField().name()
783 << " in file " << this->dimensionedInternalField().objectPath()
784 << "\n You are probably trying to solve for a field with a "
785 "generic boundary condition."
792 Foam::tmp<Foam::Field<Type> >
793 Foam::genericFvPatchField<Type>::gradientBoundaryCoeffs() const
797 "genericFvPatchField<Type>::"
798 "gradientBoundaryCoeffs() const"
800 "gradientBoundaryCoeffs cannot be called for a genericFvPatchField"
801 " (actual type " << actualTypeName_ << ")"
802 << "\n on patch " << this->patch().name()
803 << " of field " << this->dimensionedInternalField().name()
804 << " in file " << this->dimensionedInternalField().objectPath()
805 << "\n You are probably trying to solve for a field with a "
806 "generic boundary condition."
814 void Foam::genericFvPatchField<Type>::write(Ostream& os) const
816 os.writeKeyword("type") << actualTypeName_ << token::END_STATEMENT << nl;
818 forAllConstIter(dictionary, dict_, iter)
820 if (iter().keyword() != "type" && iter().keyword() != "value")
825 && iter().stream().size()
826 && iter().stream()[0].isWord()
827 && iter().stream()[0].wordToken() == "nonuniform"
830 if (scalarFields_.found(iter().keyword()))
832 scalarFields_.find(iter().keyword())()
833 ->writeEntry(iter().keyword(), os);
835 else if (vectorFields_.found(iter().keyword()))
837 vectorFields_.find(iter().keyword())()
838 ->writeEntry(iter().keyword(), os);
840 else if (sphericalTensorFields_.found(iter().keyword()))
842 sphericalTensorFields_.find(iter().keyword())()
843 ->writeEntry(iter().keyword(), os);
845 else if (symmTensorFields_.found(iter().keyword()))
847 symmTensorFields_.find(iter().keyword())()
848 ->writeEntry(iter().keyword(), os);
850 else if (tensorFields_.found(iter().keyword()))
852 tensorFields_.find(iter().keyword())()
853 ->writeEntry(iter().keyword(), os);
863 this->writeEntry("value", os);
867 // ************************************************************************* //