/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "genericPointPatchField.H"
#include "fieldMapper.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
Foam::genericPointPatchField::genericPointPatchField
(
const pointPatch& p,
const DimensionedField& iF,
const dictionary& dict
)
:
genericFieldBase(dict.lookup("type")),
calculatedPointPatchField(p, iF, dict),
dict_(dict)
{
forAllConstIter(dictionary, dict_, iter)
{
if (iter().keyword() != "type")
{
if
(
iter().isStream()
&& iter().stream().size()
)
{
ITstream& is = iter().stream();
// Read first token
token firstToken(is);
if
(
firstToken.isWord()
&& firstToken.wordToken() == "nonuniform"
)
{
token fieldToken(is);
if (!fieldToken.isCompound())
{
if
(
fieldToken.isLabel()
&& fieldToken.labelToken() == 0
)
{
scalarFields_.insert
(
iter().keyword(),
new scalarField(0)
);
}
else
{
FatalIOErrorInFunction(dict)
<< "\n token following 'nonuniform' "
"is not a compound"
<< "\n on patch " << this->patch().name()
<< " of field "
<< this->internalField().name()
<< " in file "
<< this->internalField().objectPath()
<< exit(FatalIOError);
}
}
#define ReadTypeField(Type, nullArg) \
else if \
( \
fieldToken.compoundToken().type() \
== token::Compound>::typeName \
) \
{ \
Field* fPtr = new Field; \
fPtr->transfer \
( \
dynamicCast>> \
( \
fieldToken.transferCompoundToken(is) \
) \
); \
\
if (fPtr->size() != this->size()) \
{ \
FatalIOErrorInFunction(dict) \
<< "\n size of field " \
<< iter().keyword() \
<< " (" << fPtr->size() << ')' \
<< " is not the same size as the patch (" \
<< this->size() << ')' \
<< "\n on patch " \
<< this->patch().name() \
<< " of field " \
<< this->internalField().name() \
<< " in file " \
<< this->internalField().objectPath() \
<< exit(FatalIOError); \
} \
\
Type##Fields_.insert(iter().keyword(), fPtr); \
}
FOR_ALL_FIELD_TYPES(ReadTypeField)
#undef ReadTypeField
}
}
}
}
}
template
Foam::genericPointPatchField::genericPointPatchField
(
const genericPointPatchField& ptf,
const pointPatch& p,
const DimensionedField& iF,
const fieldMapper& mapper
)
:
genericFieldBase(ptf),
calculatedPointPatchField(ptf, p, iF, mapper),
dict_(ptf.dict_)
{
#define MapTypeFields(Type, nullArg) \
forAllConstIter(HashPtrTable>, ptf.Type##Fields_, iter) \
{ \
Type##Fields_.insert \
( \
iter.key(), \
mapper(*iter()).ptr() \
); \
}
FOR_ALL_FIELD_TYPES(MapTypeFields);
#undef MapTypeFields
}
template
Foam::genericPointPatchField::genericPointPatchField
(
const genericPointPatchField& ptf,
const DimensionedField& iF
)
:
genericFieldBase(ptf),
calculatedPointPatchField(ptf, iF),
dict_(ptf.dict_)
#define CopyTypeFields(Type, nullArg) \
, Type##Fields_(ptf.Type##Fields_)
FOR_ALL_FIELD_TYPES(CopyTypeFields)
#undef CopyTypeFields
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
void Foam::genericPointPatchField::map
(
const pointPatchField& ptf,
const fieldMapper& mapper
)
{
const genericPointPatchField& dptf =
refCast>(ptf);
#define MapTypeFields(Type, nullArg) \
forAllIter(HashPtrTable>, Type##Fields_, iter) \
{ \
HashPtrTable>::const_iterator dptfIter = \
dptf.Type##Fields_.find(iter.key()); \
\
if (dptfIter != dptf.Type##Fields_.end()) \
{ \
mapper(*iter(), *dptfIter()); \
} \
}
FOR_ALL_FIELD_TYPES(MapTypeFields);
#undef MapTypeFields
}
template
void Foam::genericPointPatchField::reset
(
const pointPatchField& ptf
)
{
const genericPointPatchField& dptf =
refCast>(ptf);
#define ResetTypeFields(Type, nullArg) \
forAllIter(HashPtrTable>, Type##Fields_, iter) \
{ \
HashPtrTable>::const_iterator dptfIter = \
dptf.Type##Fields_.find(iter.key()); \
\
if (dptfIter != dptf.Type##Fields_.end()) \
{ \
iter()->reset(*dptfIter()); \
} \
}
FOR_ALL_FIELD_TYPES(ResetTypeFields);
#undef ResetTypeFields
}
template
void Foam::genericPointPatchField::write(Ostream& os) const
{
writeEntry(os, "type", actualTypeName());
forAllConstIter(dictionary, dict_, iter)
{
if (iter().keyword() != "type")
{
if
(
iter().isStream()
&& iter().stream().size()
&& iter().stream()[0].isWord()
&& iter().stream()[0].wordToken() == "nonuniform"
)
{
#define WriteTypeFieldEntry(Type, nullArg) \
else if (Type##Fields_.found(iter().keyword())) \
{ \
writeEntry \
( \
os, \
iter().keyword(), \
*Type##Fields_.find(iter().keyword())() \
); \
}
if (false) {} FOR_ALL_FIELD_TYPES(WriteTypeFieldEntry)
#undef WriteTypeFieldEntry
}
else
{
iter().write(os);
}
}
}
}
// ************************************************************************* //