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 "demandDrivenData.H"
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 typename Foam::DecoupledBlockCoeff<Type>::scalarType&
32 Foam::DecoupledBlockCoeff<Type>::toScalar()
36 // Debug check: demotion
41 "DecoupledBlockCoeff<Type>::scalarType& "
42 "DecoupledBlockCoeff<Type>::toScalar()"
43 ) << "Detected demotion to scalar. Probably an error"
47 scalarCoeffPtr_ = new scalarType(pTraits<scalarType>::zero);
50 return *scalarCoeffPtr_;
55 typename Foam::DecoupledBlockCoeff<Type>::linearType&
56 Foam::DecoupledBlockCoeff<Type>::toLinear()
60 linearCoeffPtr_ = new linearType(pTraits<linearType>::zero);
62 // If scalar is active, promote to linear
65 *linearCoeffPtr_ = (*scalarCoeffPtr_)*pTraits<linearType>::one;
66 deleteDemandDrivenData(scalarCoeffPtr_);
70 return *linearCoeffPtr_;
74 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
77 Foam::DecoupledBlockCoeff<Type>::DecoupledBlockCoeff()
79 scalarCoeffPtr_(NULL),
85 Foam::DecoupledBlockCoeff<Type>::DecoupledBlockCoeff
87 const DecoupledBlockCoeff<Type>& f
90 scalarCoeffPtr_(NULL),
93 if (f.scalarCoeffPtr_)
95 scalarCoeffPtr_ = new scalarType(*(f.scalarCoeffPtr_));
97 else if (f.linearCoeffPtr_)
99 linearCoeffPtr_ = new linearType(*(f.linearCoeffPtr_));
105 Foam::DecoupledBlockCoeff<Type>::DecoupledBlockCoeff(Istream& is)
107 scalarCoeffPtr_(NULL),
108 linearCoeffPtr_(NULL)
110 // Read keyword and pick up allocated field
116 == blockCoeffBase::activeLevelNames_[blockCoeffBase::UNALLOCATED]
123 == blockCoeffBase::activeLevelNames_[blockCoeffBase::SCALAR]
126 scalarCoeffPtr_ = new scalarType(readScalar(is));
131 == blockCoeffBase::activeLevelNames_[blockCoeffBase::LINEAR]
134 linearCoeffPtr_ = new linearType(is);
140 "DecoupledBlockCoeff<Type>::DecoupledBlockCoeff(Istream& is)",
142 ) << "invalid keyword while reading: " << key
143 << exit(FatalIOError);
149 Foam::DecoupledBlockCoeff<Type> Foam::DecoupledBlockCoeff<Type>::clone() const
151 return DecoupledBlockCoeff<Type>(*this);
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
158 Foam::DecoupledBlockCoeff<Type>::~DecoupledBlockCoeff()
165 void Foam::DecoupledBlockCoeff<Type>::clear()
167 deleteDemandDrivenData(scalarCoeffPtr_);
168 deleteDemandDrivenData(linearCoeffPtr_);
172 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
175 Foam::blockCoeffBase::activeLevel
176 Foam::DecoupledBlockCoeff<Type>::activeType() const
180 return blockCoeffBase::SCALAR;
182 else if (linearCoeffPtr_)
184 return blockCoeffBase::LINEAR;
188 return blockCoeffBase::UNALLOCATED;
194 void Foam::DecoupledBlockCoeff<Type>::checkActive() const
198 if (scalarCoeffPtr_) nActive++;
199 if (linearCoeffPtr_) nActive++;
205 "void Foam::DecoupledBlockCoeff<Type>::checkActive() const"
206 ) << "Activation/deactivation error. nActive = " << nActive
207 << abort(FatalError);
213 const typename Foam::DecoupledBlockCoeff<Type>::scalarType&
214 Foam::DecoupledBlockCoeff<Type>::asScalar() const
216 if (!scalarCoeffPtr_)
220 "DecoupledBlockCoeff<Type>::scalarType& "
221 "DecoupledBlockCoeff<Type>::asScalar()"
222 ) << "Requested scalar but active type is: "
223 << blockCoeffBase::activeLevelNames_[this->activeType()]
224 << ". This is not allowed."
225 << abort(FatalError);
228 return *scalarCoeffPtr_;
233 const typename Foam::DecoupledBlockCoeff<Type>::linearType&
234 Foam::DecoupledBlockCoeff<Type>::asLinear() const
236 if (!linearCoeffPtr_)
240 "DecoupledBlockCoeff<Type>::linearType& "
241 "DecoupledBlockCoeff<Type>::asLinear()"
242 ) << "Requested linear but active type is: "
243 << blockCoeffBase::activeLevelNames_[this->activeType()]
244 << ". This is not allowed."
245 << abort(FatalError);
248 return *linearCoeffPtr_;
253 typename Foam::DecoupledBlockCoeff<Type>::scalarType&
254 Foam::DecoupledBlockCoeff<Type>::asScalar()
260 "DecoupledBlockCoeff<Type>::scalarType& "
261 "DecoupledBlockCoeff<Type>::asScalar()"
262 ) << "Requested scalar but active type is: "
263 << blockCoeffBase::activeLevelNames_[this->activeType()]
264 << ". This is not allowed."
265 << abort(FatalError);
268 if (!scalarCoeffPtr_)
270 return this->toScalar();
273 return *scalarCoeffPtr_;
278 typename Foam::DecoupledBlockCoeff<Type>::linearType&
279 Foam::DecoupledBlockCoeff<Type>::asLinear()
281 if (!linearCoeffPtr_)
283 return this->toLinear();
286 return *linearCoeffPtr_;
291 typename Foam::DecoupledBlockCoeff<Type>::scalarType
292 Foam::DecoupledBlockCoeff<Type>::component(const direction dir) const
296 return *scalarCoeffPtr_;
298 else if (linearCoeffPtr_)
300 return linearCoeffPtr_->component(dir);
306 "tmp<DecoupledBlockCoeff<Type>::scalarType>"
307 "DecoupledBlockCoeff<Type>::component(const direction dir) const"
308 ) << " not allocated."
309 << abort(FatalError);
312 // Dummy return to keep compiler happy
313 return *scalarCoeffPtr_;
317 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
320 void Foam::DecoupledBlockCoeff<Type>::operator=
322 const DecoupledBlockCoeff<Type>& f
329 "DecoupledBlockCoeff<Type>::operator=("
330 "const DecoupledBlockCoeff<Type>&)"
331 ) << "attempted assignment to self"
332 << abort(FatalError);
335 if (f.scalarCoeffPtr_)
337 this->toScalar() = *(f.scalarCoeffPtr_);
339 else if (f.linearCoeffPtr_)
341 this->toLinear() = *(f.linearCoeffPtr_);
345 // Not allocated - do nothing
350 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
353 Foam::Ostream& Foam::operator<<(Ostream& os, const DecoupledBlockCoeff<Type>& f)
356 os << blockCoeffBase::activeLevelNames_[f.activeType()] << nl;
358 if (f.scalarCoeffPtr_)
360 os << *(f.scalarCoeffPtr_);
362 else if (f.linearCoeffPtr_)
364 os << *(f.linearCoeffPtr_);
371 // ************************************************************************* //