/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "DimensionedField.H"
#include "DimensionedFieldFunction.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template class PrimitiveField>
void Foam::DimensionedField::readField
(
const dictionary& dict,
const word& keyword
)
{
const dimensionSet dims(dict.lookup("dimensions"));
// Set the dimensions if invalid (not already set)
// otherwise check for consistency
if (dimensions_ == dimensions::invalid)
{
dimensions_.reset(dims);
}
else
{
if (dims != dimensions_)
{
FatalIOErrorInFunction(dict)
<< "Inconsistent dimensions specified for " << this->name()
<< " " << dims
<< ", required dimensions are " << this->dimensions()
<< exit(FatalIOError);
}
}
if (dict.isDict(keyword))
{
DimensionedFieldFunction
<
DimensionedField
>::New
(
dict.subDict(keyword),
*this
)->evaluate();
}
else
{
PrimitiveField f
(
keyword,
dimensions_,
dict,
mesh_.size()
);
this->transfer(f);
}
}
template class PrimitiveField>
bool Foam::DimensionedField::readIfPresent
(
const word& fieldDictEntry
)
{
if
(
this->readOpt() == IOobject::MUST_READ
|| this->readOpt() == IOobject::MUST_READ_IF_MODIFIED
)
{
WarningInFunction
<< "read option IOobject::MUST_READ or MUST_READ_IF_MODIFIED"
<< " suggests that a read constructor for field " << this->name()
<< " would be more appropriate." << endl;
}
if
(
this->readOpt() == IOobject::READ_IF_PRESENT
&& this->headerOk()
)
{
readField(dictionary(readStream(typeName)), fieldDictEntry);
readOldTimeIfPresent();
return true;
}
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template class PrimitiveField>
Foam::DimensionedField::DimensionedField
(
const IOobject& io,
const GeoMesh& mesh,
const dictionary& fieldDict,
const dimensionSet& dims,
const word& fieldDictEntry
)
:
regIOobject(io),
PrimitiveField(0),
OldTimeField(this->time().timeIndex()),
mesh_(mesh),
dimensions_(dims)
{
readField(fieldDict, fieldDictEntry);
}
template class PrimitiveField>
Foam::DimensionedField::DimensionedField
(
const IOobject& io,
const GeoMesh& mesh,
const dimensionSet& dims,
const word& fieldDictEntry
)
:
regIOobject(io),
PrimitiveField(0),
OldTimeField(this->time().timeIndex()),
mesh_(mesh),
dimensions_(dims)
{
readField(dictionary(readStream(typeName)), fieldDictEntry);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template class PrimitiveField>
bool Foam::DimensionedField::writeData
(
Ostream& os,
const word& fieldDictEntry
) const
{
writeEntry(os, "dimensions", dimensions());
os << nl;
writeEntry
(
os,
fieldDictEntry,
static_cast&>(*this)
);
// Check state of Ostream
os.check
(
"bool DimensionedField::writeData"
"(Ostream& os, const word& fieldDictEntry) const"
);
return (os.good());
}
template class PrimitiveField>
bool Foam::DimensionedField::writeData
(
Ostream& os
) const
{
return writeData(os, "value");
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template class PrimitiveField>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const DimensionedField& df
)
{
df.writeData(os);
return os;
}
// ************************************************************************* //