/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "Field.H"
#include "units.H"
#include "dictionary.H"
#include "contiguous.H"
#include "expressionAssert.H"
// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
template
const char* const Foam::Field::typeName("Field");
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::Field::Field()
:
List()
{}
template
Foam::Field::Field(const label size)
:
List(size)
{}
template
Foam::Field::Field(const label size, const Type& t)
:
List(size, t)
{}
template
Foam::Field::Field(const label size, const zero)
:
List(size, Zero)
{}
template
Foam::Field::Field(const UList& list)
:
List(list)
{}
template
Foam::Field::Field(List&& f)
:
List(move(f))
{}
template
Foam::Field::Field(const UIndirectList& list)
:
List(list)
{}
template
Foam::Field::Field(const Field& f)
:
tmp>::refCount(),
List(f)
{}
template
Foam::Field::Field(Field& f, bool reuse)
:
List(f, reuse)
{}
template
Foam::Field::Field(Field&& f)
:
tmp>::refCount(),
List(move(f))
{}
template
Foam::Field::Field(const tmp>& tf)
:
List(const_cast&>(tf()), tf.isTmp())
{
tf.clear();
}
template
Foam::Field::Field
(
const UList& mapF,
const labelUList& mapAddressing
)
:
List(mapAddressing.size())
{
map(mapF, mapAddressing);
}
template
Foam::Field::Field
(
const tmp>& tmapF,
const labelUList& mapAddressing
)
:
List(mapAddressing.size())
{
map(tmapF, mapAddressing);
}
template
Foam::Field::Field
(
const UList& mapF,
const labelListList& mapAddressing,
const scalarListList& mapWeights
)
:
List(mapAddressing.size())
{
map(mapF, mapAddressing, mapWeights);
}
template
Foam::Field::Field
(
const tmp>& tmapF,
const labelListList& mapAddressing,
const scalarListList& mapWeights
)
:
List(mapAddressing.size())
{
map(tmapF, mapAddressing, mapWeights);
}
template
Foam::Field::Field(Istream& is)
:
List(is)
{}
template
Foam::Field::Field
(
const word& keyword,
const dictionary& dict,
const label s
)
:
Field(keyword, units::any, dict, s)
{}
template
Foam::Field::Field
(
const word& keyword,
const unitSet& defaultUnits,
const dictionary& dict,
const label s
)
{
if (s)
{
ITstream& is = dict.lookup(keyword);
// Read first token
token firstToken(is);
// Read the units if they are before the values
unitSet units(defaultUnits);
const bool haveUnits = units.readIfPresent(keyword, dict, is);
// Read the values
if (firstToken.isWord())
{
if (firstToken.wordToken() == "uniform")
{
this->setSize(s);
operator=(pTraits(is));
}
else if (firstToken.wordToken() == "nonuniform")
{
is >> static_cast&>(*this);
if (this->size() != s)
{
FatalIOErrorInFunction(dict)
<< "size " << this->size()
<< " is not equal to the given value of " << s
<< exit(FatalIOError);
}
}
else
{
FatalIOErrorInFunction(dict)
<< "expected keyword 'uniform' or 'nonuniform', found "
<< firstToken.wordToken()
<< exit(FatalIOError);
}
}
else
{
FatalIOErrorInFunction(dict)
<< "expected keyword 'uniform' or 'nonuniform', found "
<< firstToken.info()
<< exit(FatalIOError);
}
// Read the units if they are after the value
if (!haveUnits && !is.eof())
{
units.readIfPresent(keyword, dict, is);
}
// Modify the values by the unit conversion
units.makeStandard(*this);
}
}
template
template
Foam::Field::Field(const Expression& e)
:
List(expression::getFirst(e))
{
#ifdef FULLDEBUG
expression::assertSameAllContainerProperty(e);
#endif
std::copy
(
expression::beginNew(e),
expression::endNew(e),
this->begin()
);
}
template
Foam::tmp> Foam::Field::clone() const
{
return tmp>(new Field(*this));
}
template
Foam::tmp> Foam::Field::New
(
const tmp>& tf1,
const bool initRet
)
{
if (tf1.isTmp())
{
return tf1;
}
else
{
tmp> rtf(new Field(tf1().size()));
if (initRet)
{
rtf.ref() = tf1();
}
return rtf;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
const Foam::UList& Foam::Field::copySelf
(
const UList& mapF,
tmp>& tmapF
) const
{
if (static_cast*>(this) == &mapF)
{
tmapF = clone();
}
return tmapF.valid() ? tmapF() : mapF;
}
template
void Foam::Field::map
(
const UList& mapF0,
const labelUList& mapAddressing
)
{
Field& f = *this;
tmp> tmapF;
const UList& mapF = copySelf(mapF0, tmapF);
if (f.size() != mapAddressing.size())
{
f.setSize(mapAddressing.size());
}
if (mapF.size() > 0)
{
forAll(f, i)
{
const label mapi = mapAddressing[i];
if (mapi >= 0)
{
f[i] = mapF[mapi];
}
}
}
}
template
void Foam::Field::map
(
const tmp>& tmapF,
const labelUList& mapAddressing
)
{
map(tmapF(), mapAddressing);
tmapF.clear();
}
template
void Foam::Field::map
(
const UList& mapF0,
const labelListList& mapAddressing,
const scalarListList& mapWeights
)
{
if (mapWeights.size() != mapAddressing.size())
{
FatalErrorInFunction
<< mapWeights.size() << " map size: " << mapAddressing.size()
<< abort(FatalError);
}
Field& f = *this;
tmp> tmapF;
const UList& mapF = copySelf(mapF0, tmapF);
if (this->size() != mapAddressing.size())
{
this->setSize(mapAddressing.size());
}
forAll(f, i)
{
const labelList& localAddrs = mapAddressing[i];
const scalarList& localWeights = mapWeights[i];
f[i] = Zero;
forAll(localAddrs, j)
{
f[i] += localWeights[j]*mapF[localAddrs[j]];
}
}
}
template
void Foam::Field::map
(
const tmp>& tmapF,
const labelListList& mapAddressing,
const scalarListList& mapWeights
)
{
map(tmapF(), mapAddressing, mapWeights);
tmapF.clear();
}
template
void Foam::Field::rmap
(
const UList& mapF0,
const labelUList& mapAddressing
)
{
Field& f = *this;
tmp> tmapF;
const UList& mapF = copySelf(mapF0, tmapF);
forAll(mapF, i)
{
const label mapi = mapAddressing[i];
if (mapi >= 0)
{
f[mapi] = mapF[i];
}
}
}
template
void Foam::Field::rmap
(
const tmp>& tmapF,
const labelUList& mapAddressing
)
{
rmap(tmapF(), mapAddressing);
tmapF.clear();
}
template
void Foam::Field::rmap
(
const UList& mapF0,
const labelUList& mapAddressing,
const UList& mapWeights
)
{
Field& f = *this;
tmp> tmapF;
const UList& mapF = copySelf(mapF0, tmapF);
f = Zero;
forAll(mapF, i)
{
f[mapAddressing[i]] += mapF[i]*mapWeights[i];
}
}
template
void Foam::Field::rmap
(
const tmp>& tmapF,
const labelUList& mapAddressing,
const UList& mapWeights
)
{
rmap(tmapF(), mapAddressing, mapWeights);
tmapF.clear();
}
template
void Foam::Field::reset(const Field& rhs)
{
if (this == &rhs)
{
FatalErrorInFunction
<< "attempted assignment to self"
<< abort(FatalError);
}
List::operator=(rhs);
}
template
void Foam::Field::reset(const UList& rhs)
{
List::operator=(rhs);
}
template
void Foam::Field::negate()
{
forAll(*this, i)
{
this->operator[](i) = -this->operator[](i);
}
}
template
void Foam::Field::replace
(
const direction d,
const UList& sf
)
{
forAll(sf, i)
{
setComponent(this->operator[](i), d) = sf[i];
}
}
template
void Foam::Field::replace
(
const direction d,
const tmp>& tsf
)
{
replace(d, tsf());
tsf.clear();
}
template
template
void Foam::Field::replace
(
const direction d,
const Expression& e
)
{
forAll(*this, i)
{
setComponent(this->operator[](i), d) = expression::access(e, i);
}
}
template
void Foam::Field::replace
(
const direction d,
const cmptType& c
)
{
forAll(*this, i)
{
setComponent(this->operator[](i), d) = c;
}
}
template
void Foam::Field::boundLower(const Type& lower)
{
forAll(*this, i)
{
this->operator[](i) = max(this->operator[](i), lower);
}
}
template
void Foam::Field::boundUpper(const Type& upper)
{
forAll(*this, i)
{
this->operator[](i) = min(this->operator[](i), upper);
}
}
template
void Foam::Field::bound(const Type& lower, const Type& upper)
{
forAll(*this, i)
{
this->operator[](i) = maxMin(this->operator[](i), lower, upper);
}
}
template
template
VSForm Foam::Field::block(const label start) const
{
VSForm vs;
for (direction i=0; ioperator[](start + i);
}
return vs;
}
template
void Foam::Field::append(const Type& t)
{
List::append(t);
}
template
void Foam::Field::append(const Field& f)
{
List::append(f);
}
template
void Foam::Field::append(const tmp>& tf)
{
List::append(tf);
tf.clear();
}
template
template
void Foam::Field::append(const Expression& e)
{
// Error if any field in the expression is a different size
#ifdef FULLDEBUG
expression::assertSameAllContainerProperty(e);
#endif
// If expression contains this
{
append(eval(e));
}
// else
// {
// const label s = this->size();
// // Resize the field to that of the first field in the expression
// List::resize(s + expression::getFirst(e));
// std::copy(expression::begin(e), expression::end(e), this->begin()+s);
// }
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template
void Foam::Field::operator=(const Field& rhs)
{
if (this == &rhs)
{
FatalErrorInFunction
<< "attempted assignment to self"
<< abort(FatalError);
}
List::operator=(rhs);
}
template
void Foam::Field::operator=(Field&& rhs)
{
if (this == &rhs)
{
FatalErrorInFunction
<< "attempted assignment to self"
<< abort(FatalError);
}
List::operator=(move(rhs));
}
template
void Foam::Field::operator=(const UList& rhs)
{
List::operator=(rhs);
}
template
void Foam::Field::operator=(List&& rhs)
{
List::operator=(move(rhs));
}
template
void Foam::Field::operator=(const tmp& rhs)
{
if (this == &(rhs()))
{
FatalErrorInFunction
<< "attempted assignment to self"
<< abort(FatalError);
}
List::operator=(rhs());
}
template
void Foam::Field::operator=(const typename Foam::Field::pType& t)
{
List::operator=(t);
}
template
void Foam::Field::operator=(const zero)
{
List::operator=(Zero);
}
template
template
void Foam::Field::operator=(const VectorSpace