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
30 \*---------------------------------------------------------------------------*/
32 #include "scalarCoeffField.H"
34 // * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
36 const char* const Foam::CoeffField<Foam::scalar>::typeName("CoeffField");
39 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 Foam::blockCoeffBase::activeLevel
42 Foam::CoeffField<Foam::scalar>::activeType() const
44 return blockCoeffBase::SCALAR;
48 Foam::tmp<Foam::CoeffField<Foam::scalar> >
49 Foam::CoeffField<Foam::scalar>::transpose() const
51 return tmp<CoeffField<scalar> >(new CoeffField<scalar>(*this));
55 const Foam::scalarField&
56 Foam::CoeffField<Foam::scalar>::asScalar() const
63 Foam::CoeffField<Foam::scalar>::asScalar()
69 const Foam::scalarField&
70 Foam::CoeffField<Foam::scalar>::asLinear() const
77 Foam::CoeffField<Foam::scalar>::asLinear()
83 Foam::BlockCoeff<Foam::scalar>
84 Foam::CoeffField<Foam::scalar>::getCoeff(const label index) const
86 BlockCoeff<scalar> result;
88 result.asScalar() = (operator[](index));
94 void Foam::CoeffField<Foam::scalar>::setCoeff
97 const BlockCoeff<scalar>& coeff
100 operator[](index) = coeff.asScalar();
104 void Foam::CoeffField<Foam::scalar>::getSubset
106 CoeffField<scalar>& f,
112 if (f.size() != size)
116 "void Foam::CoeffField<Foam::scalar>::getSubset\n"
118 " CoeffField<scalar>& f,\n"
119 " const label start,\n"
120 " const label size\n"
122 ) << "Incompatible sizes: " << f.size() << " and " << size
123 << abort(FatalError);
126 const scalarField& localF = *this;
130 f[fI] = localF[start + fI];
135 void Foam::CoeffField<Foam::scalar>::getSubset
137 CoeffField<scalar>& f,
138 const labelList& addr
142 if (f.size() != addr.size())
146 "void Foam::CoeffField<Foam::scalar>::getSubset\n"
148 " CoeffField<scalar>& f,\n"
149 " const labelList addr\n"
151 ) << "Incompatible sizes: " << f.size() << " and " << addr.size()
152 << abort(FatalError);
155 const scalarField& localF = *this;
159 f[fI] = localF[addr[fI]];
164 void Foam::CoeffField<Foam::scalar>::setSubset
166 const CoeffField<scalar>& f,
172 if (f.size() != size)
176 "void Foam::CoeffField<Foam::scalar>::setSubset\n"
178 " const CoeffField<scalar>& f,\n"
179 " const label start,\n"
180 " const label size\n"
182 ) << "Incompatible sizes: " << f.size() << " and " << size
183 << abort(FatalError);
186 scalarField& localF = *this;
190 localF[start + fI] = f[fI];
195 void Foam::CoeffField<Foam::scalar>::setSubset
197 const CoeffField<scalar>& f,
198 const labelList& addr
202 if (f.size() != addr.size())
206 "void Foam::CoeffField<Foam::scalar>::setSubset\n"
208 " const CoeffField<scalar>& f,\n"
209 " const labelList addr\n"
211 ) << "Incompatible sizes: " << f.size() << " and " << addr.size()
212 << abort(FatalError);
215 scalarField& localF = this->asScalar();
219 localF[addr[fI]] = f[fI];
224 void Foam::CoeffField<Foam::scalar>::zeroOutSubset
230 scalarField& localF = *this;
232 for (label ffI = 0; ffI < size; ffI++)
234 localF[start + ffI] = pTraits<scalar>::zero;
239 void Foam::CoeffField<Foam::scalar>::zeroOutSubset
241 const labelList& addr
244 scalarField& localF = *this;
248 localF[addr[ffI]] = pTraits<scalar>::zero;
253 void Foam::CoeffField<Foam::scalar>::addSubset
255 const CoeffField<scalar>& f,
256 const labelList& addr
260 if (f.size() != addr.size())
264 "void Foam::CoeffField<Foam::scalar>::addSubset\n"
266 " const CoeffField<scalar>& f,\n"
267 " const labelList addr\n"
269 ) << "Incompatible sizes: " << f.size() << " and " << addr.size()
270 << abort(FatalError);
273 scalarField& localF = this->asScalar();
277 localF[addr[fI]] += f[fI];
282 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
284 void Foam::CoeffField<Foam::scalar>::operator=(const scalarField& f)
286 scalarField::operator=(f);
290 void Foam::CoeffField<Foam::scalar>::operator=(const tmp<scalarField>& tf)
292 scalarField::operator=(tf);
296 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
298 Foam::Ostream& Foam::operator<<(Ostream& os, const CoeffField<scalar>& f)
300 os << static_cast<const scalarField&>(f);
306 Foam::Ostream& Foam::operator<<
309 const tmp<CoeffField<scalar> >& tf
318 /* * * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * */
321 Foam::tmp<Foam::CoeffField<Foam::scalar> >
322 Foam::inv(const CoeffField<scalar>& f)
324 tmp<CoeffField<scalar> > tresult(new CoeffField<scalar>(f.size()));
325 scalarField& result = tresult();
335 CoeffField<scalar>& f,
336 const CoeffField<scalar>& f1
348 const CoeffField<scalar>& f1,
352 const scalarField& sf = f1;
361 const CoeffField<scalar>& f1,
362 const scalarField& f2
365 const scalarField& sf = f1;
374 const scalarField& f1,
375 const CoeffField<scalar>& f2
378 const scalarField& sf = f2;
383 // ************************************************************************* //