Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / blockMatrix / CoeffField / scalarCoeffField.C
blob1b7b17c52bea20332e825938356c2e5b15f35c6e
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 Class
26     scalarCoeffField
28 Description
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
58     return *this;
62 Foam::scalarField&
63 Foam::CoeffField<Foam::scalar>::asScalar()
65     return *this;
69 const Foam::scalarField&
70 Foam::CoeffField<Foam::scalar>::asLinear() const
72     return *this;
76 Foam::scalarField&
77 Foam::CoeffField<Foam::scalar>::asLinear()
79     return *this;
83 Foam::BlockCoeff<Foam::scalar>
84 Foam::CoeffField<Foam::scalar>::getCoeff(const label index) const
86     BlockCoeff<scalar> result;
88     result.asScalar() = (operator[](index));
90     return result;
94 void Foam::CoeffField<Foam::scalar>::setCoeff
96     const label index,
97     const BlockCoeff<scalar>& coeff
100     operator[](index) = coeff.asScalar();
104 void Foam::CoeffField<Foam::scalar>::getSubset
106     CoeffField<scalar>& f,
107     const label start,
108     const label size
109 ) const
111     // Check sizes
112     if (f.size() != size)
113     {
114         FatalErrorIn
115         (
116             "void Foam::CoeffField<Foam::scalar>::getSubset\n"
117             "(\n"
118             "    CoeffField<scalar>& f,\n"
119             "    const label start,\n"
120             "    const label size\n"
121             ") const"
122         )   << "Incompatible sizes: " << f.size() << " and " << size
123             << abort(FatalError);
124     }
126     const scalarField& localF = *this;
128     forAll (f, fI)
129     {
130         f[fI] = localF[start + fI];
131     }
135 void Foam::CoeffField<Foam::scalar>::getSubset
137     CoeffField<scalar>& f,
138     const labelList& addr
139 ) const
141     // Check sizes
142     if (f.size() != addr.size())
143     {
144         FatalErrorIn
145         (
146             "void Foam::CoeffField<Foam::scalar>::getSubset\n"
147             "(\n"
148             "    CoeffField<scalar>& f,\n"
149             "    const labelList addr\n"
150             ") const"
151         )   << "Incompatible sizes: " << f.size() << " and " << addr.size()
152             << abort(FatalError);
153     }
155     const scalarField& localF = *this;
157     forAll (f, fI)
158     {
159         f[fI] = localF[addr[fI]];
160     }
164 void Foam::CoeffField<Foam::scalar>::setSubset
166     const CoeffField<scalar>& f,
167     const label start,
168     const label size
171     // Check sizes
172     if (f.size() != size)
173     {
174         FatalErrorIn
175         (
176             "void Foam::CoeffField<Foam::scalar>::setSubset\n"
177             "(\n"
178             "     const CoeffField<scalar>& f,\n"
179             "    const label start,\n"
180             "    const label size\n"
181             ")"
182         )   << "Incompatible sizes: " << f.size() << " and " << size
183             << abort(FatalError);
184     }
186     scalarField& localF = *this;
188     forAll (f, fI)
189     {
190         localF[start + fI] = f[fI];
191     }
195 void Foam::CoeffField<Foam::scalar>::setSubset
197     const CoeffField<scalar>& f,
198     const labelList& addr
201     // Check sizes
202     if (f.size() != addr.size())
203     {
204         FatalErrorIn
205         (
206             "void Foam::CoeffField<Foam::scalar>::setSubset\n"
207             "(\n"
208             "    const CoeffField<scalar>& f,\n"
209             "    const labelList addr\n"
210             ")"
211         )   << "Incompatible sizes: " << f.size() << " and " << addr.size()
212             << abort(FatalError);
213     }
215     scalarField& localF = this->asScalar();
217     forAll (f, fI)
218     {
219         localF[addr[fI]] = f[fI];
220     }
224 void Foam::CoeffField<Foam::scalar>::zeroOutSubset
226     const label start,
227     const label size
230     scalarField& localF = *this;
232     for (label ffI = 0; ffI < size; ffI++)
233     {
234         localF[start + ffI] = pTraits<scalar>::zero;
235     }
239 void Foam::CoeffField<Foam::scalar>::zeroOutSubset
241     const labelList& addr
244     scalarField& localF = *this;
246     forAll (addr, ffI)
247     {
248         localF[addr[ffI]] = pTraits<scalar>::zero;
249     }
253 void Foam::CoeffField<Foam::scalar>::addSubset
255     const CoeffField<scalar>& f,
256     const labelList& addr
259     // Check sizes
260     if (f.size() != addr.size())
261     {
262         FatalErrorIn
263         (
264             "void Foam::CoeffField<Foam::scalar>::addSubset\n"
265             "(\n"
266             "    const CoeffField<scalar>& f,\n"
267             "    const labelList addr\n"
268             ")"
269         )   << "Incompatible sizes: " << f.size() << " and " << addr.size()
270             << abort(FatalError);
271     }
273     scalarField& localF = this->asScalar();
275     forAll (f, fI)
276     {
277         localF[addr[fI]] += f[fI];
278     }
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);
302     return os;
306 Foam::Ostream& Foam::operator<<
308     Ostream& os,
309     const tmp<CoeffField<scalar> >& tf
312     os << tf();
313     tf.clear();
314     return os;
318 /* * * * * * * * * * * * * * * * Global functions  * * * * * * * * * * * * * */
320 template<>
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();
326     result = 1.0/f;
328     return tresult;
332 template<>
333 void Foam::negate
335     CoeffField<scalar>& f,
336     const CoeffField<scalar>& f1
339     f = f1;
340     f.negate();
344 template<>
345 void Foam::multiply
347     scalarField& f,
348     const CoeffField<scalar>& f1,
349     const scalar& f2
352     const scalarField& sf = f1;
353     f = sf*f2;
357 template<>
358 void Foam::multiply
360     scalarField& f,
361     const CoeffField<scalar>& f1,
362     const scalarField& f2
365     const scalarField& sf = f1;
366     f = sf*f2;
370 template<>
371 void Foam::multiply
373     scalarField& f,
374     const scalarField& f1,
375     const CoeffField<scalar>& f2
378     const scalarField& sf = f2;
379     f = f1*sf;
383 // ************************************************************************* //