Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / blockMatrix / CoeffField / DecoupledCoeffField.C
blobefab1e7fea8f68a335c2f3edea6f8bcf2dad2bce
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-6 H. Jasak All rights reserved
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 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
19     for more details.
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  * * * * * * * * * * * * * * //
32 template<class Type>
33 const char* const
34 Foam::DecoupledCoeffField<Type>::typeName("DecoupledCoeffField");
37 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
39 template<class Type>
40 template<class Type2>
41 inline void Foam::DecoupledCoeffField<Type>::checkSize
43     const UList<Type2>& f
44 ) const
46     if (f.size() != this->size())
47     {
48         FatalErrorIn
49         (
50             "void DecoupledCoeffField<Type>::checkSize("
51             "const Field<Type2>& f) const"
52         )   << "Incorrect field size: " << f.size()
53             << " local size: " << size()
54             << abort(FatalError);
55     }
59 template<class Type>
60 typename Foam::DecoupledCoeffField<Type>::scalarTypeField&
61 Foam::DecoupledCoeffField<Type>::toScalar()
63     if (!scalarCoeffPtr_)
64     {
65         // Debug check: demotion
66         if (linearCoeffPtr_)
67         {
68             FatalErrorIn
69             (
70                 "DecoupledCoeffField<Type>::scalarTypeField& "
71                 "DecoupledCoeffField<Type>::toScalar()"
72             )   << "Detected demotion to scalar.  Probably an error"
73                 << abort(FatalError);
74         }
76         scalarCoeffPtr_ =
77             new scalarTypeField(size(), pTraits<scalarType>::zero);
78     }
80     return *scalarCoeffPtr_;
84 template<class Type>
85 typename Foam::DecoupledCoeffField<Type>::linearTypeField&
86 Foam::DecoupledCoeffField<Type>::toLinear()
88     if (!linearCoeffPtr_)
89     {
90         linearCoeffPtr_ =
91             new linearTypeField(size(), pTraits<linearType>::zero);
93         // If scalar is active, promote to linear
94         if (scalarCoeffPtr_)
95         {
96             *linearCoeffPtr_ = (*scalarCoeffPtr_)*pTraits<linearType>::one;
97             deleteDemandDrivenData(scalarCoeffPtr_);
98         }
99     }
101     return *linearCoeffPtr_;
105 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
107 template<class Type>
108 Foam::DecoupledCoeffField<Type>::DecoupledCoeffField(const label size)
110     scalarCoeffPtr_(NULL),
111     linearCoeffPtr_(NULL),
112     size_(size)
116 template<class Type>
117 Foam::DecoupledCoeffField<Type>::DecoupledCoeffField
119     const DecoupledCoeffField<Type>& f
122     refCount(),
123     scalarCoeffPtr_(NULL),
124     linearCoeffPtr_(NULL),
125     size_(f.size())
127     if (f.scalarCoeffPtr_)
128     {
129         scalarCoeffPtr_ = new scalarTypeField(*(f.scalarCoeffPtr_));
130     }
131     else if (f.linearCoeffPtr_)
132     {
133         linearCoeffPtr_ = new linearTypeField(*(f.linearCoeffPtr_));
134     }
138 template<class Type>
139 Foam::DecoupledCoeffField<Type>::DecoupledCoeffField(Istream& is)
141     scalarCoeffPtr_(NULL),
142     linearCoeffPtr_(NULL),
143     size_(0)
145     // Read keyword and pick up allocated field
146     word key(is);
148     if
149     (
150         key
151      == blockCoeffBase::activeLevelNames_[blockCoeffBase::UNALLOCATED]
152     )
153     {
154         size_ = readLabel(is);
155     }
156     else if
157     (
158         key
159      == blockCoeffBase::activeLevelNames_[blockCoeffBase::SCALAR]
160     )
161     {
162         scalarCoeffPtr_ = new scalarTypeField(is);
163         size_ = scalarCoeffPtr_->size();
164     }
165     else if
166     (
167         key
168      == blockCoeffBase::activeLevelNames_[blockCoeffBase::LINEAR]
169     )
170     {
171         linearCoeffPtr_ = new linearTypeField(is);
172         size_ = linearCoeffPtr_->size();
173     }
174     else
175     {
176         FatalIOErrorIn
177         (
178             "DecoupledCoeffField<Type>::DecoupledCoeffField(Istream& is)",
179             is
180         )   << "invalid keyword while reading: " << key
181             << exit(FatalIOError);
182     }
186 template<class Type>
187 Foam::tmp<Foam::DecoupledCoeffField<Type> >
188 Foam::DecoupledCoeffField<Type>::clone() const
190     return tmp<DecoupledCoeffField<Type> >
191     (
192         new DecoupledCoeffField<Type>(*this)
193     );
197 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
199 template<class Type>
200 Foam::DecoupledCoeffField<Type>::~DecoupledCoeffField()
202     this->clear();
206 template<class Type>
207 void Foam::DecoupledCoeffField<Type>::clear()
209     deleteDemandDrivenData(scalarCoeffPtr_);
210     deleteDemandDrivenData(linearCoeffPtr_);
214 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
216 template<class Type>
217 inline Foam::label Foam::DecoupledCoeffField<Type>::size() const
219     return size_;
223 template<class Type>
224 void Foam::DecoupledCoeffField<Type>::negate()
226     if (scalarCoeffPtr_)
227     {
228         scalarCoeffPtr_->negate();
229     }
230     else if (linearCoeffPtr_)
231     {
232         linearCoeffPtr_->negate();
233     }
237 template<class Type>
238 Foam::tmp<Foam::DecoupledCoeffField<Type> >
239 Foam::DecoupledCoeffField<Type>::transpose() const
241     tmp<DecoupledCoeffField<Type> > tt
242     (
243         new DecoupledCoeffField<Type>(this->size())
244     );
245     DecoupledCoeffField<Type>& t = tt();
247     if (scalarCoeffPtr_)
248     {
249         t.toScalar() = *scalarCoeffPtr_;
250     }
251     else if (linearCoeffPtr_)
252     {
253         t.toLinear() = *linearCoeffPtr_;
254     }
255     else
256     {
257         // Not allocated - do nothing
258     }
261     return tt;
265 template<class Type>
266 Foam::blockCoeffBase::activeLevel
267 Foam::DecoupledCoeffField<Type>::activeType() const
269     if (scalarCoeffPtr_)
270     {
271         return blockCoeffBase::SCALAR;
272     }
273     else if (linearCoeffPtr_)
274     {
275         return blockCoeffBase::LINEAR;
276     }
277     else
278     {
279         return blockCoeffBase::UNALLOCATED;
280     }
284 template<class Type>
285 void Foam::DecoupledCoeffField<Type>::checkActive() const
287     label nActive = 0;
289     if (scalarCoeffPtr_) nActive++;
290     if (linearCoeffPtr_) nActive++;
292     if (nActive > 1)
293     {
294         FatalErrorIn
295         (
296             "void Foam::DecoupledCoeffField<Type>::checkActive() const"
297         )   << "Activation/deactivation error.  nActive = " << nActive
298             << abort(FatalError);
299     }
303 template<class Type>
304 const typename Foam::DecoupledCoeffField<Type>::scalarTypeField&
305 Foam::DecoupledCoeffField<Type>::asScalar() const
307     if (!scalarCoeffPtr_)
308     {
309         FatalErrorIn
310         (
311             "DecoupledCoeffField<Type>::scalarTypeField& "
312             "DecoupledCoeffField<Type>::asScalar()"
313         )   << "Requested scalar but active type is: "
314             << blockCoeffBase::activeLevelNames_[this->activeType()]
315             << ".  This is not allowed."
316             << abort(FatalError);
317     }
319     return *scalarCoeffPtr_;
323 template<class Type>
324 const typename Foam::DecoupledCoeffField<Type>::linearTypeField&
325 Foam::DecoupledCoeffField<Type>::asLinear() const
327     if (!linearCoeffPtr_)
328     {
329         FatalErrorIn
330         (
331             "DecoupledCoeffField<Type>::linearTypeField& "
332             "DecoupledCoeffField<Type>::asLinear()"
333         )   << "Requested linear but active type is: "
334             << blockCoeffBase::activeLevelNames_[this->activeType()]
335             << ".  This is not allowed."
336             << abort(FatalError);
337     }
339     return *linearCoeffPtr_;
343 template<class Type>
344 typename Foam::DecoupledCoeffField<Type>::scalarTypeField&
345 Foam::DecoupledCoeffField<Type>::asScalar()
347     if (linearCoeffPtr_)
348     {
349         FatalErrorIn
350         (
351             "DecoupledCoeffField<Type>::scalarTypeField& "
352             "DecoupledCoeffField<Type>::asScalar()"
353         )   << "Requested scalar but active type is: "
354             << blockCoeffBase::activeLevelNames_[this->activeType()]
355             << ".  This is not allowed."
356             << abort(FatalError);
357     }
359     if (!scalarCoeffPtr_)
360     {
361         return this->toScalar();
362     }
364     return *scalarCoeffPtr_;
368 template<class Type>
369 typename Foam::DecoupledCoeffField<Type>::linearTypeField&
370 Foam::DecoupledCoeffField<Type>::asLinear()
372     if (!linearCoeffPtr_)
373     {
374         return this->toLinear();
375     }
377     return *linearCoeffPtr_;
381 template<class Type>
382 Foam::tmp<typename Foam::DecoupledCoeffField<Type>::scalarTypeField>
383 Foam::DecoupledCoeffField<Type>::component(const direction dir) const
385     if (scalarCoeffPtr_)
386     {
387         return *scalarCoeffPtr_;
388     }
389     else if (linearCoeffPtr_)
390     {
391         return linearCoeffPtr_->component(dir);
392     }
393     else
394     {
395         FatalErrorIn
396         (
397             "tmp<DecoupledCoeffField<Type>::scalarTypeField>"
398             "DecoupledCoeffField<Type>::component(const direction dir) const"
399         )   << "Field not allocated."
400             << abort(FatalError);
401     }
403     // Dummy return to keep compiler happy
404     return *scalarCoeffPtr_;
408 template<class Type>
409 Foam::BlockCoeff<Type>
410 Foam::DecoupledCoeffField<Type>::getCoeff(const label index) const
412     BlockCoeff<Type> result;
414     if (scalarCoeffPtr_)
415     {
416         result.asScalar() = (*scalarCoeffPtr_)[index];
417     }
418     else if (linearCoeffPtr_)
419     {
420         result.asLinear() = (*linearCoeffPtr_)[index];
421     }
423     return result;
427 template<class Type>
428 void Foam::DecoupledCoeffField<Type>::setCoeff
430     const label index,
431     const BlockCoeff<Type>& coeff
434     BlockCoeff<Type> result;
436     if (coeff.activeType() == blockCoeffBase::SCALAR)
437     {
438         (*scalarCoeffPtr_)[index] = result.asScalar();
439     }
440     else if (coeff.activeType() == blockCoeffBase::LINEAR)
441     {
442         (*linearCoeffPtr_)[index] = result.asLinear();
443     }
447 template<class Type>
448 void Foam::DecoupledCoeffField<Type>::getSubset
450     DecoupledCoeffField<Type>& f,
451     const label start,
452     const label size
453 ) const
455     // Check sizes
456     if (f.size() != size)
457     {
458         FatalErrorIn
459         (
460             "template<class Type>\n"
461             "void Foam::DecoupledCoeffField<Type>::getSubset\n"
462             "(\n"
463             "    DecoupledCoeffField<Type>& f,\n"
464             "    const label start,\n"
465             "    const label size\n"
466             ") const"
467         )   << "Incompatible sizes: " << f.size() << " and " << size
468             << abort(FatalError);
469     }
471     if (scalarCoeffPtr_)
472     {
473         scalarTypeField& ff = f.asScalar();
475         const scalarTypeField& localF = (*scalarCoeffPtr_);
477         forAll (ff, ffI)
478         {
479             ff[ffI] = localF[start + ffI];
480         }
481     }
482     else if (linearCoeffPtr_)
483     {
484         linearTypeField& ff = f.asLinear();
486         const linearTypeField& localF = (*linearCoeffPtr_);
488         forAll (ff, ffI)
489         {
490             ff[ffI] = localF[start + ffI];
491         }
492     }
496 template<class Type>
497 void Foam::DecoupledCoeffField<Type>::getSubset
499     DecoupledCoeffField<Type>& f,
500     const labelList& addr
501 ) const
503     // Check sizes
504     if (f.size() != addr.size())
505     {
506         FatalErrorIn
507         (
508             "template<class Type>\n"
509             "void Foam::DecoupledCoeffField<Type>::getSubset\n"
510             "(\n"
511             "    DecoupledCoeffField<Type>& f,\n"
512             "    const labelList addr\n"
513             ") const"
514         )   << "Incompatible sizes: " << f.size() << " and " << addr.size()
515             << abort(FatalError);
516     }
518     if (scalarCoeffPtr_)
519     {
520         scalarTypeField& ff = f.asScalar();
522         const scalarTypeField& localF = (*scalarCoeffPtr_);
524         forAll (ff, ffI)
525         {
526             ff[ffI] = localF[addr[ffI]];
527         }
528     }
529     else if (linearCoeffPtr_)
530     {
531         linearTypeField& ff = f.asLinear();
533         const linearTypeField& localF = (*linearCoeffPtr_);
535         forAll (ff, ffI)
536         {
537             ff[ffI] = localF[addr[ffI]];
538         }
539     }
543 template<class Type>
544 void Foam::DecoupledCoeffField<Type>::setSubset
546     const DecoupledCoeffField<Type>& f,
547     const label start,
548     const label size
551     // Check sizes
552     if (f.size() != size)
553     {
554         FatalErrorIn
555         (
556             "template<class Type>\n"
557             "void Foam::DecoupledCoeffField<Type>::setSubset\n"
558             "(\n"
559             "     const DecoupledCoeffField<Type>& f,\n"
560             "    const label start,\n"
561             "    const label size\n"
562             ")"
563         )   << "Incompatible sizes: " << f.size() << " and " << size
564             << abort(FatalError);
565     }
567     if (f.activeType() == blockCoeffBase::SCALAR)
568     {
569         const scalarTypeField& ff = f.asScalar();
571         scalarTypeField& localF = this->asScalar();
573         forAll (ff, ffI)
574         {
575             localF[start + ffI] = ff[ffI];
576         }
577     }
578     else if (f.activeType() == blockCoeffBase::LINEAR)
579     {
580         const linearTypeField& ff = f.asLinear();
582         linearTypeField& localF = this->asLinear();
584         forAll (ff, ffI)
585         {
586             localF[start + ffI] = ff[ffI];
587         }
588     }
592 template<class Type>
593 void Foam::DecoupledCoeffField<Type>::setSubset
595     const DecoupledCoeffField<Type>& f,
596     const labelList& addr
599     // Check sizes
600     if (f.size() != addr.size())
601     {
602         FatalErrorIn
603         (
604             "template<class Type>\n"
605             "void Foam::DecoupledCoeffField<Type>::setSubset\n"
606             "(\n"
607             "    const DecoupledCoeffField<Type>& f,\n"
608             "    const labelList addr\n"
609             ")"
610         )   << "Incompatible sizes: " << f.size() << " and " << addr.size()
611             << abort(FatalError);
612     }
614     if (f.activeType() == blockCoeffBase::SCALAR)
615     {
616         const scalarTypeField& ff = f.asScalar();
618         scalarTypeField& localF = this->asScalar();
620         forAll (ff, ffI)
621         {
622             localF[addr[ffI]] = ff[ffI];
623         }
624     }
625     else if (f.activeType() == blockCoeffBase::LINEAR)
626     {
627         const linearTypeField& ff = f.asLinear();
629         linearTypeField& localF = this->asLinear();
631         forAll (ff, ffI)
632         {
633             localF[addr[ffI]] = ff[ffI];
634         }
635     }
639 template<class Type>
640 void Foam::DecoupledCoeffField<Type>::zeroOutSubset
642     const label start,
643     const label size
646     if (scalarCoeffPtr_)
647     {
648         scalarTypeField& localF = this->asScalar();
650         for (label ffI = 0; ffI < size; ffI++)
651         {
652             localF[start + ffI] = pTraits<scalarType>::zero;
653         }
654     }
655     else if (linearCoeffPtr_)
656     {
657         linearTypeField& localF = this->asLinear();
659         for (label ffI = 0; ffI < size; ffI++)
660         {
661             localF[start + ffI] = pTraits<linearType>::zero;
662         }
663     }
667 template<class Type>
668 void Foam::DecoupledCoeffField<Type>::zeroOutSubset
670     const labelList& addr
673     if (scalarCoeffPtr_)
674     {
675         scalarTypeField& localF = this->asScalar();
677         forAll (addr, ffI)
678         {
679             localF[addr[ffI]] = pTraits<scalarType>::zero;
680         }
681     }
682     else if (linearCoeffPtr_)
683     {
684         linearTypeField& localF = this->asLinear();
686         forAll (addr, ffI)
687         {
688             localF[addr[ffI]] = pTraits<linearType>::zero;
689         }
690     }
694 template<class Type>
695 void Foam::DecoupledCoeffField<Type>::addSubset
697     const DecoupledCoeffField<Type>& f,
698     const labelList& addr
701     // Check sizes
702     if (f.size() != addr.size())
703     {
704         FatalErrorIn
705         (
706             "template<class Type>\n"
707             "void Foam::DecoupledCoeffField<Type>::addSubset\n"
708             "(\n"
709             "    const DecoupledCoeffField<Type>& f,\n"
710             "    const labelList addr\n"
711             ")"
712         )   << "Incompatible sizes: " << f.size() << " and " << addr.size()
713             << abort(FatalError);
714     }
716     if
717     (
718         f.activeType() == blockCoeffBase::LINEAR
719      || this->activeType() == blockCoeffBase::LINEAR
720     )
721     {
722         const linearTypeField& ff = f.asLinear();
724         linearTypeField& localF = this->asLinear();
726         forAll (ff, ffI)
727         {
728             localF[addr[ffI]] += ff[ffI];
729         }
730     }
731     else if
732     (
733         f.activeType() == blockCoeffBase::SCALAR
734      && this->activeType() == blockCoeffBase::SCALAR
735     )
736     {
737         const scalarTypeField& ff = f.asScalar();
739         scalarTypeField& localF = this->asScalar();
741         forAll (ff, ffI)
742         {
743             localF[addr[ffI]] += ff[ffI];
744         }
745     }
746     else
747     {
748         FatalErrorIn
749         (
750             "template<class Type>\n"
751             "void Foam::DecoupledCoeffField<Type>::addSubset\n"
752             "(\n"
753             "    const DecoupledCoeffField<Type>& f,\n"
754             "    const labelList addr\n"
755             ")"
756         )   << "Incompatible combination of types"
757             << abort(FatalError);
758     }
762 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
764 template<class Type>
765 void Foam::DecoupledCoeffField<Type>::operator=
767     const DecoupledCoeffField<Type>& f
770     if (this == &f)
771     {
772         FatalErrorIn
773         (
774             "DecoupledCoeffField<Type>::operator=("
775             "const DecoupledCoeffField<Type>&)"
776         )   << "attempted assignment to self"
777             << abort(FatalError);
778     }
780     // Check field sizes
781     if (f.size() != this->size())
782     {
783         FatalErrorIn
784         (
785             "DecoupledCoeffField<Type>::operator=("
786             "const DecoupledCoeffField<Type>&)"
787         )   << "Incorrect field size: " << f.size()
788             << " local size: " << size()
789             << abort(FatalError);
790     }
792     if (f.scalarCoeffPtr_)
793     {
794         this->toScalar() = *(f.scalarCoeffPtr_);
795     }
796     else if (f.linearCoeffPtr_)
797     {
798         this->toLinear() = *(f.linearCoeffPtr_);
799     }
800     else
801     {
802         // Not allocated - do nothing
803     }
807 template<class Type>
808 void Foam::DecoupledCoeffField<Type>::operator=
810     const tmp<DecoupledCoeffField>& tf
813     if (this == &(tf()))
814     {
815         FatalErrorIn
816         (
817             "DecoupledCoeffField<Type>::operator=("
818             "const tmp<DecoupledCoeffField>&)"
819         )   << "attempted assignment to self"
820             << abort(FatalError);
821     }
823     operator=(tf());
824     tf.clear();
828 #define COMPUTED_BASE_ASSIGNMENT(op)                                          \
829                                                                               \
830 template<class Type>                                                          \
831 void Foam::DecoupledCoeffField<Type>::operator op                             \
832 (                                                                             \
833     const DecoupledCoeffField<Type>& f                                        \
834 )                                                                             \
835 {                                                                             \
836     if (f.size() != this->size())                                             \
837     {                                                                         \
838         FatalErrorIn                                                          \
839         (                                                                     \
840             "void DecoupledCoeffField<tensor>::operator "                     \
841             "op(const DecoupledCoeffField<tensor>& f)"                        \
842         )   << "Incorrect field size: " << f.size()                           \
843             << " local size: " << size()                                      \
844             << abort(FatalError);                                             \
845     }                                                                         \
846                                                                               \
847                                                                               \
848     if (f.scalarCoeffPtr_)                                                    \
849     {                                                                         \
850         this->toScalar() op *(f.scalarCoeffPtr_);                             \
851     }                                                                         \
852     else if (f.linearCoeffPtr_)                                               \
853     {                                                                         \
854         this->toLinear() op *(f.linearCoeffPtr_);                             \
855     }                                                                         \
856     else                                                                      \
857     {                                                                         \
858     }                                                                         \
859 }                                                                             \
860                                                                               \
861 template<class Type>                                                          \
862 void Foam::DecoupledCoeffField<Type>::operator op                             \
863 (                                                                             \
864     const tmp<DecoupledCoeffField<Type> >& tf                                 \
865 )                                                                             \
866 {                                                                             \
867     operator op(tf());                                                        \
868     tf.clear();                                                               \
872 #define COMPUTED_ARG_ASSIGNMENT(op)                                           \
873                                                                               \
874 template<class Type>                                                          \
875 void Foam::DecoupledCoeffField<Type>::operator op(const scalarTypeField& f)   \
876 {                                                                             \
877     checkSize(f);                                                             \
878                                                                               \
879     const blockCoeffBase::activeLevel al = this->activeType();                \
880                                                                               \
881     if (al == blockCoeffBase::UNALLOCATED || al == blockCoeffBase::SCALAR)    \
882     {                                                                         \
883         this->toScalar() op f;                                                \
884     }                                                                         \
885     else if (al == blockCoeffBase::LINEAR)                                    \
886     {                                                                         \
887         this->toLinear() op f*pTraits<linearType>::one;                       \
888     }                                                                         \
889     else                                                                      \
890     {                                                                         \
891     }                                                                         \
892 }                                                                             \
893                                                                               \
894 template<class Type>                                                          \
895 void Foam::DecoupledCoeffField<Type>::operator op                             \
896 (                                                                             \
897     const tmp<scalarTypeField>& tf                                            \
898 )                                                                             \
899 {                                                                             \
900     operator op(tf());                                                        \
901     tf.clear();                                                               \
902 }                                                                             \
903                                                                               \
904                                                                               \
905 template<class Type>                                                          \
906 void Foam::DecoupledCoeffField<Type>::operator op(const linearTypeField& f)   \
907 {                                                                             \
908     checkSize(f);                                                             \
909                                                                               \
910     const blockCoeffBase::activeLevel al = this->activeType();                \
911                                                                               \
912     if                                                                        \
913     (                                                                         \
914         al == blockCoeffBase::UNALLOCATED                                     \
915      || al == blockCoeffBase::SCALAR                                          \
916      || al == blockCoeffBase::LINEAR                                          \
917     )                                                                         \
918     {                                                                         \
919         this->toLinear() op f;                                                \
920     }                                                                         \
921     else                                                                      \
922     {                                                                         \
923     }                                                                         \
924 }                                                                             \
925                                                                               \
926 template<class Type>                                                          \
927 void Foam::DecoupledCoeffField<Type>::operator op                             \
928 (                                                                             \
929     const tmp<linearTypeField>& tf                                            \
930 )                                                                             \
931 {                                                                             \
932     operator op(tf());                                                        \
933     tf.clear();                                                               \
934 }                                                                             \
937 #define COMPUTED_BASE_OPERATOR(TYPE, op)                                      \
938                                                                               \
939 template<class Type>                                                          \
940 void Foam::DecoupledCoeffField<Type>::operator op(const TYPE& t)              \
941 {                                                                             \
942     if (scalarCoeffPtr_)                                                      \
943     {                                                                         \
944         *(scalarCoeffPtr_) op t;                                              \
945     }                                                                         \
946     else if (linearCoeffPtr_)                                                 \
947     {                                                                         \
948         *(linearCoeffPtr_) op t;                                              \
949     }                                                                         \
950     else                                                                      \
951     {                                                                         \
952     }                                                                         \
953 }                                                                             \
954                                                                               \
955 template<class Type>                                                          \
956 void Foam::DecoupledCoeffField<Type>::operator op(const UList<TYPE>& tf)      \
957 {                                                                             \
958     checkSize(tf);                                                            \
959                                                                               \
960     if (scalarCoeffPtr_)                                                      \
961     {                                                                         \
962         *(scalarCoeffPtr_) op tf;                                             \
963     }                                                                         \
964     else if (linearCoeffPtr_)                                                 \
965     {                                                                         \
966         *(linearCoeffPtr_) op tf;                                             \
967     }                                                                         \
968     else                                                                      \
969     {                                                                         \
970     }                                                                         \
971 }                                                                             \
972                                                                               \
973 template<class Type>                                                          \
974 void Foam::DecoupledCoeffField<Type>::operator op                             \
975 (                                                                             \
976     const tmp<Field<TYPE> >& tf                                               \
977 )                                                                             \
978 {                                                                             \
979     operator op(tf());                                                        \
980     tf.clear();                                                               \
984 #define COMPUTED_ASSIGNMENT(op)                                               \
985 COMPUTED_BASE_ASSIGNMENT(op)                                                  \
986 COMPUTED_ARG_ASSIGNMENT(op)
988 // Remaining operator=
989 COMPUTED_ARG_ASSIGNMENT(=)
991 COMPUTED_ASSIGNMENT(+=)
992 COMPUTED_ASSIGNMENT(-=)
994 COMPUTED_BASE_OPERATOR(scalar, *=)
995 COMPUTED_BASE_OPERATOR(scalar, /=)
997 #undef COMPUTED_BASE_OPERATOR
998 #undef COMPUTED_BASE_ASSIGNMENT
999 #undef COMPUTED_ARG_ASSIGNMENT
1000 #undef COMPUTED_ASSIGNMENT
1003 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
1005 template<class Type>
1006 Foam::Ostream& Foam::operator<<(Ostream& os, const DecoupledCoeffField<Type>& f)
1008     // Write active type
1009     os << blockCoeffBase::activeLevelNames_[f.activeType()] << nl;
1011     if (f.activeType() == blockCoeffBase::SCALAR)
1012     {
1013         os << f.asScalar();
1014     }
1015     else if (f.activeType() == blockCoeffBase::LINEAR)
1016     {
1017         os << f.asLinear();
1018     }
1019     else
1020     {
1021         // Not allocated: write size
1022         os << f.size();
1023     }
1025     return os;
1029 template<class Type>
1030 Foam::Ostream& Foam::operator<<
1032     Ostream& os,
1033     const tmp<DecoupledCoeffField<Type> >& tf
1036     os << tf();
1037     tf.clear();
1038     return os;
1042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1044 #   include "DecoupledCoeffFieldFunctions.C"
1047 // ************************************************************************* //