1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 " or link the boundary-condition into libfoamUtil.so"
82 << exit(FatalIOError);
87 dictionary::const_iterator iter = dict_.begin();
92 if (iter().keyword() != "type" && iter().keyword() != "value")
97 && iter().stream().size()
100 ITstream& is = iter().stream();
103 token firstToken(is);
108 && firstToken.wordToken() == "nonuniform"
111 token fieldToken(is);
113 if (!fieldToken.isCompound())
118 && fieldToken.labelToken() == 0
131 "genericFvPatchField<Type>::genericFvPatchField"
132 "(const fvPatch&, const Field<Type>&, "
133 "const dictionary&)",
135 ) << "\n token following 'nonuniform' "
137 << "\n on patch " << this->patch().name()
139 << this->dimensionedInternalField().name()
141 << this->dimensionedInternalField().objectPath()
142 << exit(FatalIOError);
147 fieldToken.compoundToken().type()
148 == token::Compound<List<scalar> >::typeName
151 scalarField* fPtr = new scalarField;
154 dynamicCast<token::Compound<List<scalar> > >
156 fieldToken.transferCompoundToken()
160 if (fPtr->size() != this->size())
164 "genericFvPatchField<Type>::genericFvPatchField"
165 "(const fvPatch&, const Field<Type>&, "
166 "const dictionary&)",
168 ) << "\n size of field " << iter().keyword()
169 << " (" << fPtr->size() << ')'
170 << " is not the same size as the patch ("
171 << this->size() << ')'
172 << "\n on patch " << this->patch().name()
174 << this->dimensionedInternalField().name()
176 << this->dimensionedInternalField().objectPath()
177 << exit(FatalIOError);
180 scalarFields_.insert(iter().keyword(), fPtr);
184 fieldToken.compoundToken().type()
185 == token::Compound<List<vector> >::typeName
188 vectorField* fPtr = new vectorField;
191 dynamicCast<token::Compound<List<vector> > >
193 fieldToken.transferCompoundToken()
197 if (fPtr->size() != this->size())
201 "genericFvPatchField<Type>::genericFvPatchField"
202 "(const fvPatch&, const Field<Type>&, "
203 "const dictionary&)",
205 ) << "\n size of field " << iter().keyword()
206 << " (" << fPtr->size() << ')'
207 << " is not the same size as the patch ("
208 << this->size() << ')'
209 << "\n on patch " << this->patch().name()
211 << this->dimensionedInternalField().name()
213 << this->dimensionedInternalField().objectPath()
214 << exit(FatalIOError);
217 vectorFields_.insert(iter().keyword(), fPtr);
221 fieldToken.compoundToken().type()
222 == token::Compound<List<sphericalTensor> >::typeName
225 sphericalTensorField* fPtr = new sphericalTensorField;
230 token::Compound<List<sphericalTensor> >
233 fieldToken.transferCompoundToken()
237 if (fPtr->size() != this->size())
241 "genericFvPatchField<Type>::genericFvPatchField"
242 "(const fvPatch&, const Field<Type>&, "
243 "const dictionary&)",
245 ) << "\n size of field " << iter().keyword()
246 << " (" << fPtr->size() << ')'
247 << " is not the same size as the patch ("
248 << this->size() << ')'
249 << "\n on patch " << this->patch().name()
251 << this->dimensionedInternalField().name()
253 << this->dimensionedInternalField().objectPath()
254 << exit(FatalIOError);
257 sphericalTensorFields_.insert(iter().keyword(), fPtr);
261 fieldToken.compoundToken().type()
262 == token::Compound<List<symmTensor> >::typeName
265 symmTensorField* fPtr = new symmTensorField;
270 token::Compound<List<symmTensor> >
273 fieldToken.transferCompoundToken()
277 if (fPtr->size() != this->size())
281 "genericFvPatchField<Type>::genericFvPatchField"
282 "(const fvPatch&, const Field<Type>&, "
283 "const dictionary&)",
285 ) << "\n size of field " << iter().keyword()
286 << " (" << fPtr->size() << ')'
287 << " is not the same size as the patch ("
288 << this->size() << ')'
289 << "\n on patch " << this->patch().name()
291 << this->dimensionedInternalField().name()
293 << this->dimensionedInternalField().objectPath()
294 << exit(FatalIOError);
297 symmTensorFields_.insert(iter().keyword(), fPtr);
301 fieldToken.compoundToken().type()
302 == token::Compound<List<tensor> >::typeName
305 tensorField* fPtr = new tensorField;
308 dynamicCast<token::Compound<List<tensor> > >
310 fieldToken.transferCompoundToken()
314 if (fPtr->size() != this->size())
318 "genericFvPatchField<Type>::genericFvPatchField"
319 "(const fvPatch&, const Field<Type>&, "
320 "const dictionary&)",
322 ) << "\n size of field " << iter().keyword()
323 << " (" << fPtr->size() << ')'
324 << " is not the same size as the patch ("
325 << this->size() << ')'
326 << "\n on patch " << this->patch().name()
328 << this->dimensionedInternalField().name()
330 << this->dimensionedInternalField().objectPath()
331 << exit(FatalIOError);
334 tensorFields_.insert(iter().keyword(), fPtr);
340 "genericFvPatchField<Type>::genericFvPatchField"
341 "(const fvPatch&, const Field<Type>&, "
342 "const dictionary&)",
344 ) << "\n compound " << fieldToken.compoundToken()
346 << "\n on patch " << this->patch().name()
348 << this->dimensionedInternalField().name()
350 << this->dimensionedInternalField().objectPath()
351 << exit(FatalIOError);
357 && firstToken.wordToken() == "uniform"
360 token fieldToken(is);
362 if (!fieldToken.isPunctuation())
376 // Read as scalarList.
377 is.putBack(fieldToken);
381 if (l.size() == vector::nComponents)
383 vector vs(l[0], l[1], l[2]);
388 new vectorField(this->size(), vs)
391 else if (l.size() == sphericalTensor::nComponents)
393 sphericalTensor vs(l[0]);
395 sphericalTensorFields_.insert
398 new sphericalTensorField(this->size(), vs)
401 else if (l.size() == symmTensor::nComponents)
403 symmTensor vs(l[0], l[1], l[2], l[3], l[4], l[5]);
405 symmTensorFields_.insert
408 new symmTensorField(this->size(), vs)
411 else if (l.size() == tensor::nComponents)
423 new tensorField(this->size(), vs)
430 "genericFvPatchField<Type>::genericFvPatchField"
431 "(const fvPatch&, const Field<Type>&, "
432 "const dictionary&)",
434 ) << "\n unrecognised native type " << l
435 << "\n on patch " << this->patch().name()
437 << this->dimensionedInternalField().name()
439 << this->dimensionedInternalField().objectPath()
440 << exit(FatalIOError);
451 Foam::genericFvPatchField<Type>::genericFvPatchField
453 const genericFvPatchField<Type>& ptf,
455 const DimensionedField<Type, volMesh>& iF,
456 const fvPatchFieldMapper& mapper
459 calculatedFvPatchField<Type>(ptf, p, iF, mapper),
460 actualTypeName_(ptf.actualTypeName_),
465 HashPtrTable<scalarField>::const_iterator iter =
466 ptf.scalarFields_.begin();
467 iter != ptf.scalarFields_.end();
471 scalarFields_.insert(iter.key(), new scalarField(*iter(), mapper));
476 HashPtrTable<vectorField>::const_iterator iter =
477 ptf.vectorFields_.begin();
478 iter != ptf.vectorFields_.end();
482 vectorFields_.insert(iter.key(), new vectorField(*iter(), mapper));
487 HashPtrTable<sphericalTensorField>::const_iterator iter =
488 ptf.sphericalTensorFields_.begin();
489 iter != ptf.sphericalTensorFields_.end();
493 sphericalTensorFields_.insert
496 new sphericalTensorField(*iter(), mapper)
502 HashPtrTable<symmTensorField>::const_iterator iter =
503 ptf.symmTensorFields_.begin();
504 iter != ptf.symmTensorFields_.end();
508 symmTensorFields_.insert
511 new symmTensorField(*iter(), mapper)
517 HashPtrTable<symmTensor4thOrderField>::const_iterator iter =
518 ptf.symmTensor4thOrderFields_.begin();
519 iter != ptf.symmTensor4thOrderFields_.end();
523 symmTensor4thOrderFields_.insert
526 new symmTensor4thOrderField(*iter(), mapper)
532 HashPtrTable<diagTensorField>::const_iterator iter =
533 ptf.diagTensorFields_.begin();
534 iter != ptf.diagTensorFields_.end();
538 diagTensorFields_.insert
541 new diagTensorField(*iter(), mapper)
547 HashPtrTable<tensorField>::const_iterator iter =
548 ptf.tensorFields_.begin();
549 iter != ptf.tensorFields_.end();
553 tensorFields_.insert(iter.key(), new tensorField(*iter(), mapper));
559 Foam::genericFvPatchField<Type>::genericFvPatchField
561 const genericFvPatchField<Type>& ptf
564 calculatedFvPatchField<Type>(ptf),
565 actualTypeName_(ptf.actualTypeName_),
567 scalarFields_(ptf.scalarFields_),
568 vectorFields_(ptf.vectorFields_),
569 sphericalTensorFields_(ptf.sphericalTensorFields_),
570 symmTensorFields_(ptf.symmTensorFields_),
571 tensorFields_(ptf.tensorFields_)
576 Foam::genericFvPatchField<Type>::genericFvPatchField
578 const genericFvPatchField<Type>& ptf,
579 const DimensionedField<Type, volMesh>& iF
582 calculatedFvPatchField<Type>(ptf, iF),
583 actualTypeName_(ptf.actualTypeName_),
585 scalarFields_(ptf.scalarFields_),
586 vectorFields_(ptf.vectorFields_),
587 sphericalTensorFields_(ptf.sphericalTensorFields_),
588 symmTensorFields_(ptf.symmTensorFields_),
589 tensorFields_(ptf.tensorFields_)
593 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
596 void Foam::genericFvPatchField<Type>::autoMap
598 const fvPatchFieldMapper& m
601 calculatedFvPatchField<Type>::autoMap(m);
605 HashPtrTable<scalarField>::iterator iter = scalarFields_.begin();
606 iter != scalarFields_.end();
615 HashPtrTable<vectorField>::iterator iter = vectorFields_.begin();
616 iter != vectorFields_.end();
625 HashPtrTable<sphericalTensorField>::iterator iter =
626 sphericalTensorFields_.begin();
627 iter != sphericalTensorFields_.end();
636 HashPtrTable<symmTensorField>::iterator iter =
637 symmTensorFields_.begin();
638 iter != symmTensorFields_.end();
647 HashPtrTable<tensorField>::iterator iter = tensorFields_.begin();
648 iter != tensorFields_.end();
658 void Foam::genericFvPatchField<Type>::rmap
660 const fvPatchField<Type>& ptf,
661 const labelList& addr
664 calculatedFvPatchField<Type>::rmap(ptf, addr);
666 const genericFvPatchField<Type>& dptf =
667 refCast<const genericFvPatchField<Type> >(ptf);
671 HashPtrTable<scalarField>::iterator iter = scalarFields_.begin();
672 iter != scalarFields_.end();
676 HashPtrTable<scalarField>::const_iterator dptfIter =
677 dptf.scalarFields_.find(iter.key());
679 if (dptfIter != dptf.scalarFields_.end())
681 iter()->rmap(*dptfIter(), addr);
687 HashPtrTable<vectorField>::iterator iter = vectorFields_.begin();
688 iter != vectorFields_.end();
692 HashPtrTable<vectorField>::const_iterator dptfIter =
693 dptf.vectorFields_.find(iter.key());
695 if (dptfIter != dptf.vectorFields_.end())
697 iter()->rmap(*dptfIter(), addr);
703 HashPtrTable<sphericalTensorField>::iterator iter =
704 sphericalTensorFields_.begin();
705 iter != sphericalTensorFields_.end();
709 HashPtrTable<sphericalTensorField>::const_iterator dptfIter =
710 dptf.sphericalTensorFields_.find(iter.key());
712 if (dptfIter != dptf.sphericalTensorFields_.end())
714 iter()->rmap(*dptfIter(), addr);
720 HashPtrTable<symmTensorField>::iterator iter =
721 symmTensorFields_.begin();
722 iter != symmTensorFields_.end();
726 HashPtrTable<symmTensorField>::const_iterator dptfIter =
727 dptf.symmTensorFields_.find(iter.key());
729 if (dptfIter != dptf.symmTensorFields_.end())
731 iter()->rmap(*dptfIter(), addr);
737 HashPtrTable<tensorField>::iterator iter = tensorFields_.begin();
738 iter != tensorFields_.end();
742 HashPtrTable<tensorField>::const_iterator dptfIter =
743 dptf.tensorFields_.find(iter.key());
745 if (dptfIter != dptf.tensorFields_.end())
747 iter()->rmap(*dptfIter(), addr);
754 Foam::tmp<Foam::Field<Type> >
755 Foam::genericFvPatchField<Type>::valueInternalCoeffs
757 const tmp<scalarField>&
762 "genericFvPatchField<Type>::"
763 "valueInternalCoeffs(const tmp<scalarField>&) const"
765 "valueInternalCoeffs cannot be called for a genericFvPatchField"
766 " (actual type " << actualTypeName_ << ")"
767 << "\n on patch " << this->patch().name()
768 << " of field " << this->dimensionedInternalField().name()
769 << " in file " << this->dimensionedInternalField().objectPath()
770 << "\n You are probably trying to solve for a field with a "
771 "generic boundary condition."
779 Foam::tmp<Foam::Field<Type> >
780 Foam::genericFvPatchField<Type>::valueBoundaryCoeffs
782 const tmp<scalarField>&
787 "genericFvPatchField<Type>::"
788 "valueBoundaryCoeffs(const tmp<scalarField>&) const"
790 "valueBoundaryCoeffs cannot be called for a genericFvPatchField"
791 " (actual type " << actualTypeName_ << ")"
792 << "\n on patch " << this->patch().name()
793 << " of field " << this->dimensionedInternalField().name()
794 << " in file " << this->dimensionedInternalField().objectPath()
795 << "\n You are probably trying to solve for a field with a "
796 "generic boundary condition."
804 Foam::tmp<Foam::Field<Type> >
805 Foam::genericFvPatchField<Type>::gradientInternalCoeffs() const
809 "genericFvPatchField<Type>::"
810 "gradientInternalCoeffs() const"
812 "gradientInternalCoeffs cannot be called for a genericFvPatchField"
813 " (actual type " << actualTypeName_ << ")"
814 << "\n on patch " << this->patch().name()
815 << " of field " << this->dimensionedInternalField().name()
816 << " in file " << this->dimensionedInternalField().objectPath()
817 << "\n You are probably trying to solve for a field with a "
818 "generic boundary condition."
825 Foam::tmp<Foam::Field<Type> >
826 Foam::genericFvPatchField<Type>::gradientBoundaryCoeffs() const
830 "genericFvPatchField<Type>::"
831 "gradientBoundaryCoeffs() const"
833 "gradientBoundaryCoeffs cannot be called for a genericFvPatchField"
834 " (actual type " << actualTypeName_ << ")"
835 << "\n on patch " << this->patch().name()
836 << " of field " << this->dimensionedInternalField().name()
837 << " in file " << this->dimensionedInternalField().objectPath()
838 << "\n You are probably trying to solve for a field with a "
839 "generic boundary condition."
847 void Foam::genericFvPatchField<Type>::write(Ostream& os) const
849 os.writeKeyword("type") << actualTypeName_ << token::END_STATEMENT << nl;
853 dictionary::const_iterator iter = dict_.begin();
858 if (iter().keyword() != "type" && iter().keyword() != "value")
863 && iter().stream().size()
864 && iter().stream()[0].isWord()
865 && iter().stream()[0].wordToken() == "nonuniform"
868 if (scalarFields_.found(iter().keyword()))
870 scalarFields_.find(iter().keyword())()
871 ->writeEntry(iter().keyword(), os);
873 else if (vectorFields_.found(iter().keyword()))
875 vectorFields_.find(iter().keyword())()
876 ->writeEntry(iter().keyword(), os);
878 else if (sphericalTensorFields_.found(iter().keyword()))
880 sphericalTensorFields_.find(iter().keyword())()
881 ->writeEntry(iter().keyword(), os);
883 else if (symmTensorFields_.found(iter().keyword()))
885 symmTensorFields_.find(iter().keyword())()
886 ->writeEntry(iter().keyword(), os);
888 else if (tensorFields_.found(iter().keyword()))
890 tensorFields_.find(iter().keyword())()
891 ->writeEntry(iter().keyword(), os);
901 this->writeEntry("value", os);
905 // ************************************************************************* //