1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 \*---------------------------------------------------------------------------*/
27 #include "demandDrivenData.H"
28 #include "expandTensorField.H"
30 // * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
33 const char* const Foam::CoeffField<Type>::typeName("CoeffField");
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 inline void Foam::CoeffField<Type>::checkSize(const UList<Type2>& f) const
42 if (f.size() != this->size())
46 "void CoeffField<Type>::checkSize(const Field<Type2>& f) const"
47 ) << "Incorrect field size: " << f.size()
48 << " local size: " << size()
55 typename Foam::CoeffField<Type>::scalarTypeField&
56 Foam::CoeffField<Type>::toScalar()
60 // Debug check: demotion
61 if (linearCoeffPtr_ || squareCoeffPtr_)
65 "CoeffField<Type>::scalarTypeField& "
66 "CoeffField<Type>::toScalar()"
67 ) << "Detected demotion to scalar. Probably an error"
72 new scalarTypeField(size(), pTraits<scalarType>::zero);
75 return *scalarCoeffPtr_;
80 typename Foam::CoeffField<Type>::linearTypeField&
81 Foam::CoeffField<Type>::toLinear()
85 // Debug check: demotion
90 "CoeffField<Type>::linearTypeField& "
91 "CoeffField<Type>::toLinear()"
92 ) << "Detected demotion to linear. Probably an error"
97 new linearTypeField(size(), pTraits<linearType>::zero);
99 // If scalar is active, promote to linear
102 expandScalar(*linearCoeffPtr_, *scalarCoeffPtr_);
103 deleteDemandDrivenData(scalarCoeffPtr_);
107 return *linearCoeffPtr_;
112 typename Foam::CoeffField<Type>::squareTypeField&
113 Foam::CoeffField<Type>::toSquare()
115 if (!squareCoeffPtr_)
118 new squareTypeField(this->size(), pTraits<squareType>::zero);
120 // If scalar is active, promote to square
123 expandScalar(*squareCoeffPtr_, *scalarCoeffPtr_);
124 deleteDemandDrivenData(scalarCoeffPtr_);
127 // If linear is active, promote to square
130 expandLinear(*squareCoeffPtr_, *linearCoeffPtr_);
131 deleteDemandDrivenData(linearCoeffPtr_);
135 return *squareCoeffPtr_;
139 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
142 Foam::CoeffField<Type>::CoeffField(const label size)
144 scalarCoeffPtr_(NULL),
145 linearCoeffPtr_(NULL),
146 squareCoeffPtr_(NULL),
152 Foam::CoeffField<Type>::CoeffField(const CoeffField<Type>& f)
155 scalarCoeffPtr_(NULL),
156 linearCoeffPtr_(NULL),
157 squareCoeffPtr_(NULL),
160 if (f.scalarCoeffPtr_)
162 scalarCoeffPtr_ = new scalarTypeField(*(f.scalarCoeffPtr_));
164 else if (f.linearCoeffPtr_)
166 linearCoeffPtr_ = new linearTypeField(*(f.linearCoeffPtr_));
168 else if (f.squareCoeffPtr_)
170 squareCoeffPtr_ = new squareTypeField(*(f.squareCoeffPtr_));
176 Foam::CoeffField<Type>::CoeffField(Istream& is)
178 scalarCoeffPtr_(NULL),
179 linearCoeffPtr_(NULL),
180 squareCoeffPtr_(NULL),
183 // Read keyword and pick up allocated field
189 == blockCoeffBase::activeLevelNames_[blockCoeffBase::UNALLOCATED]
192 size_ = readLabel(is);
197 == blockCoeffBase::activeLevelNames_[blockCoeffBase::SCALAR]
200 scalarCoeffPtr_ = new scalarTypeField(is);
201 size_ = scalarCoeffPtr_->size();
206 == blockCoeffBase::activeLevelNames_[blockCoeffBase::LINEAR]
209 linearCoeffPtr_ = new linearTypeField(is);
210 size_ = linearCoeffPtr_->size();
215 == blockCoeffBase::activeLevelNames_[blockCoeffBase::SQUARE]
218 squareCoeffPtr_ = new squareTypeField(is);
219 size_ = squareCoeffPtr_->size();
225 "CoeffField<Type>::CoeffField(Istream& is)",
227 ) << "invalid keyword while reading: " << key
228 << exit(FatalIOError);
234 Foam::tmp<Foam::CoeffField<Type> > Foam::CoeffField<Type>::clone() const
236 return tmp<CoeffField<Type> >(new CoeffField<Type>(*this));
240 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
243 Foam::CoeffField<Type>::~CoeffField()
250 void Foam::CoeffField<Type>::clear()
252 deleteDemandDrivenData(scalarCoeffPtr_);
253 deleteDemandDrivenData(linearCoeffPtr_);
254 deleteDemandDrivenData(squareCoeffPtr_);
258 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
261 inline Foam::label Foam::CoeffField<Type>::size() const
268 void Foam::CoeffField<Type>::negate()
272 scalarCoeffPtr_->negate();
274 else if (linearCoeffPtr_)
276 linearCoeffPtr_->negate();
278 else if (squareCoeffPtr_)
280 squareCoeffPtr_->negate();
286 Foam::tmp<Foam::CoeffField<Type> > Foam::CoeffField<Type>::transpose() const
288 tmp<CoeffField<Type> > tt(new CoeffField<Type>(this->size()));
289 CoeffField<Type>& t = tt();
293 t.toScalar() = *scalarCoeffPtr_;
295 else if (linearCoeffPtr_)
297 t.toLinear() = *linearCoeffPtr_;
299 else if (squareCoeffPtr_)
301 t.toSquare() = this->asSquare().T();
305 // Not allocated - do nothing
314 Foam::blockCoeffBase::activeLevel
315 Foam::CoeffField<Type>::activeType() const
319 return blockCoeffBase::SCALAR;
321 else if (linearCoeffPtr_)
323 return blockCoeffBase::LINEAR;
325 else if (squareCoeffPtr_)
327 return blockCoeffBase::SQUARE;
331 return blockCoeffBase::UNALLOCATED;
337 void Foam::CoeffField<Type>::checkActive() const
341 if (scalarCoeffPtr_) nActive++;
342 if (linearCoeffPtr_) nActive++;
343 if (squareCoeffPtr_) nActive++;
347 FatalErrorIn("void Foam::CoeffField<Type>::checkActive() const")
348 << "Activation/deactivation error. nActive = " << nActive
349 << abort(FatalError);
355 const typename Foam::CoeffField<Type>::scalarTypeField&
356 Foam::CoeffField<Type>::asScalar() const
358 if (!scalarCoeffPtr_)
362 "CoeffField<Type>::scalarTypeField& "
363 "CoeffField<Type>::asScalar()"
364 ) << "Requested scalar but active type is: "
365 << blockCoeffBase::activeLevelNames_[this->activeType()]
366 << ". This is not allowed."
367 << abort(FatalError);
370 return *scalarCoeffPtr_;
375 const typename Foam::CoeffField<Type>::linearTypeField&
376 Foam::CoeffField<Type>::asLinear() const
378 if (!linearCoeffPtr_)
382 "CoeffField<Type>::linearTypeField& "
383 "CoeffField<Type>::asLinear()"
384 ) << "Requested linear but active type is: "
385 << blockCoeffBase::activeLevelNames_[this->activeType()]
386 << ". This is not allowed."
387 << abort(FatalError);
390 return *linearCoeffPtr_;
395 const typename Foam::CoeffField<Type>::squareTypeField&
396 Foam::CoeffField<Type>::asSquare() const
398 if (!squareCoeffPtr_)
402 "CoeffField<Type>::squareTypeField& "
403 "CoeffField<Type>::asSquare()"
404 ) << "Requested square but active type is: "
405 << blockCoeffBase::activeLevelNames_[this->activeType()]
406 << ". This is not allowed."
407 << abort(FatalError);
410 return *squareCoeffPtr_;
415 typename Foam::CoeffField<Type>::scalarTypeField&
416 Foam::CoeffField<Type>::asScalar()
418 if (linearCoeffPtr_ || squareCoeffPtr_)
422 "CoeffField<Type>::scalarTypeField& "
423 "CoeffField<Type>::asScalar()"
424 ) << "Requested scalar but active type is: "
425 << blockCoeffBase::activeLevelNames_[this->activeType()]
426 << ". This is not allowed."
427 << abort(FatalError);
430 if (!scalarCoeffPtr_)
432 return this->toScalar();
435 return *scalarCoeffPtr_;
440 typename Foam::CoeffField<Type>::linearTypeField&
441 Foam::CoeffField<Type>::asLinear()
447 "CoeffField<Type>::linearTypeField& "
448 "CoeffField<Type>::asLinear()"
449 ) << "Requested linear but active type is: "
450 << blockCoeffBase::activeLevelNames_[this->activeType()]
451 << ". This is not allowed."
452 << abort(FatalError);
455 if (!linearCoeffPtr_)
457 return this->toLinear();
460 return *linearCoeffPtr_;
465 typename Foam::CoeffField<Type>::squareTypeField&
466 Foam::CoeffField<Type>::asSquare()
468 if (!squareCoeffPtr_)
470 return this->toSquare();
473 return *squareCoeffPtr_;
478 Foam::tmp<typename Foam::CoeffField<Type>::scalarTypeField>
479 Foam::CoeffField<Type>::component(const direction dir) const
483 return *scalarCoeffPtr_;
485 else if (linearCoeffPtr_)
487 return linearCoeffPtr_->component(dir);
489 else if (squareCoeffPtr_)
491 linearTypeField lc(this->size());
492 contractLinear(lc, *squareCoeffPtr_);
494 return lc.component(dir);
500 "tmp<CoeffField<Type>::scalarTypeField>"
501 "CoeffField<Type>::component(const direction dir) const"
502 ) << "Field not allocated."
503 << abort(FatalError);
506 // Dummy return to keep compiler happy
507 return *scalarCoeffPtr_;
512 Foam::BlockCoeff<Type>
513 Foam::CoeffField<Type>::getCoeff(const label index) const
515 BlockCoeff<Type> result;
519 result.asScalar() = (*scalarCoeffPtr_)[index];
521 else if (linearCoeffPtr_)
523 result.asLinear() = (*linearCoeffPtr_)[index];
525 else if (squareCoeffPtr_)
527 result.asSquare() = (*squareCoeffPtr_)[index];
535 void Foam::CoeffField<Type>::setCoeff
538 const BlockCoeff<Type>& coeff
541 BlockCoeff<Type> result;
543 if (coeff.activeType() == blockCoeffBase::SCALAR)
545 (*scalarCoeffPtr_)[index] = result.asScalar();
547 else if (coeff.activeType() == blockCoeffBase::LINEAR)
549 (*linearCoeffPtr_)[index] = result.asLinear();
551 else if (coeff.activeType() == blockCoeffBase::SQUARE)
553 (*squareCoeffPtr_)[index] = result.asSquare();
559 void Foam::CoeffField<Type>::getSubset
567 if (f.size() != size)
571 "template<class Type>\n"
572 "void Foam::CoeffField<Type>::getSubset\n"
574 " CoeffField<Type>& f,\n"
575 " const label start,\n"
576 " const label size\n"
578 ) << "Incompatible sizes: " << f.size() << " and " << size
579 << abort(FatalError);
584 scalarTypeField& ff = f.asScalar();
586 const scalarTypeField& localF = (*scalarCoeffPtr_);
590 ff[ffI] = localF[start + ffI];
593 else if (linearCoeffPtr_)
595 linearTypeField& ff = f.asLinear();
597 const linearTypeField& localF = (*linearCoeffPtr_);
601 ff[ffI] = localF[start + ffI];
604 else if (squareCoeffPtr_)
606 squareTypeField& ff = f.asSquare();
608 const squareTypeField& localF = (*squareCoeffPtr_);
612 ff[ffI] = localF[start + ffI];
619 void Foam::CoeffField<Type>::getSubset
622 const labelList& addr
626 if (f.size() != addr.size())
630 "template<class Type>\n"
631 "void Foam::CoeffField<Type>::getSubset\n"
633 " CoeffField<Type>& f,\n"
634 " const labelList addr\n"
636 ) << "Incompatible sizes: " << f.size() << " and " << addr.size()
637 << abort(FatalError);
642 scalarTypeField& ff = f.asScalar();
644 const scalarTypeField& localF = (*scalarCoeffPtr_);
648 ff[ffI] = localF[addr[ffI]];
651 else if (linearCoeffPtr_)
653 linearTypeField& ff = f.asLinear();
655 const linearTypeField& localF = (*linearCoeffPtr_);
659 ff[ffI] = localF[addr[ffI]];
662 else if (squareCoeffPtr_)
664 squareTypeField& ff = f.asSquare();
666 const squareTypeField& localF = (*squareCoeffPtr_);
670 ff[ffI] = localF[addr[ffI]];
677 void Foam::CoeffField<Type>::setSubset
679 const CoeffField<Type>& f,
685 if (f.size() != size)
689 "template<class Type>\n"
690 "void Foam::CoeffField<Type>::setSubset\n"
692 " const CoeffField<Type>& f,\n"
693 " const label start,\n"
694 " const label size\n"
696 ) << "Incompatible sizes: " << f.size() << " and " << size
697 << abort(FatalError);
700 if (f.activeType() == blockCoeffBase::SCALAR)
702 const scalarTypeField& ff = f.asScalar();
704 scalarTypeField& localF = this->asScalar();
708 localF[start + ffI] = ff[ffI];
711 else if (f.activeType() == blockCoeffBase::LINEAR)
713 const linearTypeField& ff = f.asLinear();
715 linearTypeField& localF = this->asLinear();
719 localF[start + ffI] = ff[ffI];
722 else if (f.activeType() == blockCoeffBase::SQUARE)
724 const squareTypeField& ff = f.asSquare();
726 squareTypeField& localF = this->asSquare();
730 localF[start + ffI] = ff[ffI];
737 void Foam::CoeffField<Type>::setSubset
739 const CoeffField<Type>& f,
740 const labelList& addr
744 if (f.size() != addr.size())
748 "template<class Type>\n"
749 "void Foam::CoeffField<Type>::setSubset\n"
751 " const CoeffField<Type>& f,\n"
752 " const labelList addr\n"
754 ) << "Incompatible sizes: " << f.size() << " and " << addr.size()
755 << abort(FatalError);
758 if (f.activeType() == blockCoeffBase::SCALAR)
760 const scalarTypeField& ff = f.asScalar();
762 scalarTypeField& localF = this->asScalar();
766 localF[addr[ffI]] = ff[ffI];
769 else if (f.activeType() == blockCoeffBase::LINEAR)
771 const linearTypeField& ff = f.asLinear();
773 linearTypeField& localF = this->asLinear();
777 localF[addr[ffI]] = ff[ffI];
780 else if (f.activeType() == blockCoeffBase::SQUARE)
782 const squareTypeField& ff = f.asSquare();
784 squareTypeField& localF = this->asSquare();
788 localF[addr[ffI]] = ff[ffI];
795 void Foam::CoeffField<Type>::zeroOutSubset
803 scalarTypeField& localF = this->asScalar();
805 for (label ffI = 0; ffI < size; ffI++)
807 localF[start + ffI] = pTraits<scalarType>::zero;
810 else if (linearCoeffPtr_)
812 linearTypeField& localF = this->asLinear();
814 for (label ffI = 0; ffI < size; ffI++)
816 localF[start + ffI] = pTraits<linearType>::zero;
819 else if (squareCoeffPtr_)
821 squareTypeField& localF = this->asSquare();
823 for (label ffI = 0; ffI < size; ffI++)
825 localF[start + ffI] = pTraits<squareType>::zero;
832 void Foam::CoeffField<Type>::zeroOutSubset
834 const labelList& addr
839 scalarTypeField& localF = this->asScalar();
843 localF[addr[ffI]] = pTraits<scalarType>::zero;
846 else if (linearCoeffPtr_)
848 linearTypeField& localF = this->asLinear();
852 localF[addr[ffI]] = pTraits<linearType>::zero;
855 else if (squareCoeffPtr_)
857 squareTypeField& localF = this->asSquare();
861 localF[addr[ffI]] = pTraits<squareType>::zero;
868 void Foam::CoeffField<Type>::addSubset
870 const CoeffField<Type>& f,
871 const labelList& addr
875 if (f.size() != addr.size())
879 "template<class Type>\n"
880 "void Foam::CoeffField<Type>::addSubset\n"
882 " const CoeffField<Type>& f,\n"
883 " const labelList addr\n"
885 ) << "Incompatible sizes: " << f.size() << " and " << addr.size()
886 << abort(FatalError);
889 if (this->activeType() == blockCoeffBase::SQUARE)
891 if (f.activeType() == blockCoeffBase::SQUARE)
893 squareTypeField& localF = this->asSquare();
895 const squareTypeField& ff = f.asSquare();
899 localF[addr[ffI]] += ff[ffI];
902 else if (f.activeType() == blockCoeffBase::LINEAR)
904 squareTypeField& localF = this->asSquare();
906 squareTypeField ff(f.size());
907 expandLinear(ff, f.asLinear());
911 localF[addr[ffI]] += ff[ffI];
914 else if (f.activeType() == blockCoeffBase::SCALAR)
916 squareTypeField& localF = this->asSquare();
918 squareTypeField ff(f.size());
919 expandScalar(ff, f.asScalar());
923 localF[addr[ffI]] += ff[ffI];
927 else if (this->activeType() == blockCoeffBase::LINEAR)
929 if (f.activeType() == blockCoeffBase::SQUARE)
931 squareTypeField& localF = this->asSquare();
933 const squareTypeField& ff = f.asSquare();
937 localF[addr[ffI]] += ff[ffI];
940 if (f.activeType() == blockCoeffBase::LINEAR)
942 linearTypeField& localF = this->asLinear();
944 const linearTypeField& ff = f.asLinear();
948 localF[addr[ffI]] += ff[ffI];
951 else if (f.activeType() == blockCoeffBase::SCALAR)
953 linearTypeField& localF = this->asLinear();
955 linearTypeField ff(f.size());
956 expandScalar(ff, f.asScalar());
960 localF[addr[ffI]] += ff[ffI];
964 else if (this->activeType() == blockCoeffBase::SCALAR)
966 if (f.activeType() == blockCoeffBase::SQUARE)
968 squareTypeField& localF = this->asSquare();
970 const squareTypeField& ff = f.asSquare();
974 localF[addr[ffI]] += ff[ffI];
977 if (f.activeType() == blockCoeffBase::LINEAR)
979 linearTypeField& localF = this->asLinear();
981 const linearTypeField& ff = f.asLinear();
985 localF[addr[ffI]] += ff[ffI];
988 else if (f.activeType() == blockCoeffBase::SCALAR)
990 const scalarTypeField& ff = f.asScalar();
992 scalarTypeField& localF = this->asScalar();
996 localF[addr[ffI]] += ff[ffI];
1004 "template<class Type>\n"
1005 "void Foam::CoeffField<Type>::addSubset\n"
1007 " const CoeffField<Type>& f,\n"
1008 " const labelList addr\n"
1010 ) << "Incompatible combination of types"
1011 << abort(FatalError);
1016 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
1018 template<class Type>
1019 void Foam::CoeffField<Type>::operator=(const CoeffField<Type>& f)
1023 FatalErrorIn("CoeffField<Type>::operator=(const CoeffField<Type>&)")
1024 << "attempted assignment to self"
1025 << abort(FatalError);
1028 // Check field sizes
1029 if (f.size() != this->size())
1033 "void CoeffField<Type>::operator=(const CoeffField<Type>& f)"
1034 ) << "Incorrect field size: " << f.size()
1035 << " local size: " << size()
1036 << abort(FatalError);
1039 if (f.scalarCoeffPtr_)
1041 this->toScalar() = *(f.scalarCoeffPtr_);
1043 else if (f.linearCoeffPtr_)
1045 this->toLinear() = *(f.linearCoeffPtr_);
1047 else if (f.squareCoeffPtr_)
1049 this->toSquare() = *(f.squareCoeffPtr_);
1053 // Not allocated - do nothing
1058 template<class Type>
1059 void Foam::CoeffField<Type>::operator=(const tmp<CoeffField>& tf)
1061 if (this == &(tf()))
1063 FatalErrorIn("CoeffField<Type>::operator=(const tmp<CoeffField>&)")
1064 << "attempted assignment to self"
1065 << abort(FatalError);
1073 #define COMPUTED_BASE_ASSIGNMENT(op) \
1075 template<class Type> \
1076 void Foam::CoeffField<Type>::operator op(const CoeffField<Type>& f) \
1078 if (f.size() != this->size()) \
1082 "void CoeffField<tensor>::operator " \
1083 "op(const CoeffField<tensor>& f)" \
1084 ) << "Incorrect field size: " << f.size() \
1085 << " local size: " << size() \
1086 << abort(FatalError); \
1089 if (this->activeType() == blockCoeffBase::SQUARE) \
1091 if (f.activeType() == blockCoeffBase::SQUARE) \
1093 this->asSquare() op f.asSquare(); \
1095 else if (f.activeType() == blockCoeffBase::LINEAR) \
1097 squareTypeField ff(f.size()); \
1098 expandLinear(ff, f.asLinear()); \
1100 this->asSquare() op ff; \
1102 else if (f.activeType() == blockCoeffBase::SCALAR) \
1104 squareTypeField ff(f.size()); \
1105 expandScalar(ff, f.asScalar()); \
1107 this->asSquare() op ff; \
1110 else if (this->activeType() == blockCoeffBase::LINEAR) \
1112 if (f.activeType() == blockCoeffBase::SQUARE) \
1114 this->asSquare() op f.asSquare(); \
1116 if (f.activeType() == blockCoeffBase::LINEAR) \
1118 this->asLinear() op f.asLinear(); \
1120 else if (f.activeType() == blockCoeffBase::SCALAR) \
1122 linearTypeField ff(f.size()); \
1123 expandScalar(ff, f.asScalar()); \
1125 this->asLinear() op ff; \
1128 else if (this->activeType() == blockCoeffBase::SCALAR) \
1130 if (f.activeType() == blockCoeffBase::SQUARE) \
1132 this->asSquare() op f.asSquare(); \
1134 if (f.activeType() == blockCoeffBase::LINEAR) \
1136 this->asLinear() op f.asLinear(); \
1138 else if (f.activeType() == blockCoeffBase::SCALAR) \
1140 this->asScalar() op f.asScalar(); \
1145 template<class Type> \
1146 void Foam::CoeffField<Type>::operator op(const tmp<CoeffField<Type> >& tf) \
1148 operator op(tf()); \
1153 #define COMPUTED_ARG_ASSIGNMENT(op) \
1155 template<class Type> \
1156 void Foam::CoeffField<Type>::operator op(const scalarTypeField& f) \
1160 const blockCoeffBase::activeLevel al = this->activeType(); \
1162 if (al == blockCoeffBase::UNALLOCATED || al == blockCoeffBase::SCALAR) \
1164 this->toScalar() op f; \
1166 else if (al == blockCoeffBase::LINEAR) \
1168 this->toLinear() op f*pTraits<linearType>::one; \
1170 else if (al == blockCoeffBase::SQUARE) \
1172 squareTypeField stf(f.size()); \
1173 expandScalar(stf, f); \
1174 this->toSquare() op stf; \
1181 template<class Type> \
1182 void Foam::CoeffField<Type>::operator op(const tmp<scalarTypeField>& tf) \
1184 operator op(tf()); \
1189 template<class Type> \
1190 void Foam::CoeffField<Type>::operator op(const linearTypeField& f) \
1194 const blockCoeffBase::activeLevel al = this->activeType(); \
1198 al == blockCoeffBase::UNALLOCATED \
1199 || al == blockCoeffBase::SCALAR \
1200 || al == blockCoeffBase::LINEAR \
1203 this->toLinear() op f; \
1205 else if (al == blockCoeffBase::SQUARE) \
1207 squareTypeField stf(f.size()); \
1208 expandLinear(stf, f); \
1209 this->toSquare() op stf; \
1216 template<class Type> \
1217 void Foam::CoeffField<Type>::operator op(const tmp<linearTypeField>& tf) \
1219 operator op(tf()); \
1224 template<class Type> \
1225 void Foam::CoeffField<Type>::operator op(const squareTypeField& f) \
1228 this->toSquare() op f; \
1231 template<class Type> \
1232 void Foam::CoeffField<Type>::operator op(const tmp<squareTypeField>& tf) \
1234 operator op(tf()); \
1238 #define COMPUTED_BASE_OPERATOR(TYPE, op) \
1240 template<class Type> \
1241 void Foam::CoeffField<Type>::operator op(const TYPE& t) \
1243 if (scalarCoeffPtr_) \
1245 *(scalarCoeffPtr_) op t; \
1247 else if (linearCoeffPtr_) \
1249 *(linearCoeffPtr_) op t; \
1251 else if (squareCoeffPtr_) \
1253 *(squareCoeffPtr_) op t; \
1260 template<class Type> \
1261 void Foam::CoeffField<Type>::operator op(const UList<TYPE>& tf) \
1265 if (scalarCoeffPtr_) \
1267 *(scalarCoeffPtr_) op tf; \
1269 else if (linearCoeffPtr_) \
1271 *(linearCoeffPtr_) op tf; \
1273 else if (squareCoeffPtr_) \
1275 *(squareCoeffPtr_) op tf; \
1282 template<class Type> \
1283 void Foam::CoeffField<Type>::operator op(const tmp<Field<TYPE> >& tf) \
1285 operator op(tf()); \
1290 #define COMPUTED_ASSIGNMENT(op) \
1291 COMPUTED_BASE_ASSIGNMENT(op) \
1292 COMPUTED_ARG_ASSIGNMENT(op)
1294 // Remaining operator=
1295 COMPUTED_ARG_ASSIGNMENT(=)
1297 COMPUTED_ASSIGNMENT(+=)
1298 COMPUTED_ASSIGNMENT(-=)
1300 COMPUTED_BASE_OPERATOR(scalar, *=)
1301 COMPUTED_BASE_OPERATOR(scalar, /=)
1303 #undef COMPUTED_BASE_OPERATOR
1304 #undef COMPUTED_BASE_ASSIGNMENT
1305 #undef COMPUTED_ARG_ASSIGNMENT
1306 #undef COMPUTED_ASSIGNMENT
1309 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
1311 template<class Type>
1312 Foam::Ostream& Foam::operator<<(Ostream& os, const CoeffField<Type>& f)
1314 // Write active type
1315 os << blockCoeffBase::activeLevelNames_[f.activeType()] << nl;
1317 if (f.activeType() == blockCoeffBase::SCALAR)
1321 else if (f.activeType() == blockCoeffBase::LINEAR)
1325 else if (f.activeType() == blockCoeffBase::SQUARE)
1331 // Not allocated: write size
1339 template<class Type>
1340 Foam::Ostream& Foam::operator<<(Ostream& os, const tmp<CoeffField<Type> >& tf)
1348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1350 # include "CoeffFieldFunctions.C"
1353 // ************************************************************************* //