ENH: add exprResult output of a field without dictionary keywords
This commit is contained in:
parent
13ea1b70fe
commit
4a3998c698
@ -624,21 +624,7 @@ void Foam::expressions::exprResult::writeDict
|
||||
os.writeEntryIfDifferent<Switch>("isPointValue", false, isPointData_);
|
||||
os.writeEntry<Switch>("isSingleValue", isUniform_);
|
||||
|
||||
const bool ok =
|
||||
(
|
||||
writeValueFieldChecked<scalar>(os)
|
||||
|| writeValueFieldChecked<vector>(os)
|
||||
|| writeValueFieldChecked<tensor>(os)
|
||||
|| writeValueFieldChecked<symmTensor>(os)
|
||||
|| writeValueFieldChecked<sphericalTensor>(os)
|
||||
|| writeValueFieldChecked<bool>(os)
|
||||
);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Unknown data type " << valType_ << endl;
|
||||
}
|
||||
this->writeField(os, "value");
|
||||
}
|
||||
|
||||
if (subDict)
|
||||
@ -650,6 +636,38 @@ void Foam::expressions::exprResult::writeDict
|
||||
}
|
||||
|
||||
|
||||
void Foam::expressions::exprResult::writeField
|
||||
(
|
||||
Ostream& os,
|
||||
const word& keyword
|
||||
) const
|
||||
{
|
||||
// const auto oldFmt = os.format(IOstream::ASCII);
|
||||
|
||||
DebugInFunction
|
||||
<< Foam::name(this) << nl
|
||||
<< "Format: "
|
||||
<< IOstreamOption::formatNames[os.format()] << nl;
|
||||
|
||||
const bool ok =
|
||||
(
|
||||
writeFieldChecked<scalar>(keyword, os)
|
||||
|| writeFieldChecked<vector>(keyword, os)
|
||||
|| writeFieldChecked<tensor>(keyword, os)
|
||||
|| writeFieldChecked<symmTensor>(keyword, os)
|
||||
|| writeFieldChecked<sphericalTensor>(keyword, os)
|
||||
|| writeFieldChecked<label>(keyword, os)
|
||||
|| writeFieldChecked<bool>(keyword, os)
|
||||
);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Unknown data type " << valType_ << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::expressions::exprResult::writeValue
|
||||
(
|
||||
Ostream& os
|
||||
|
@ -214,10 +214,11 @@ class exprResult
|
||||
template<class Type>
|
||||
bool writeSingleValueChecked(Ostream& os) const;
|
||||
|
||||
//- Type-checked writing of "value" field entry
|
||||
//- Type-checked writing field as entry (if keyword is non-empty)
|
||||
//- or as plain field (if keyword is empty)
|
||||
// \return True if the type check was satisfied
|
||||
template<class Type>
|
||||
bool writeValueFieldChecked(Ostream& os) const;
|
||||
bool writeFieldChecked(const word& keyword, Ostream& os) const;
|
||||
|
||||
//- Type-checked forwarding to Field::writeEntry
|
||||
// \return True if the type check was satisfied
|
||||
@ -516,6 +517,9 @@ public:
|
||||
//- Write entry as dictionary contents
|
||||
void writeDict(Ostream& os, const bool subDict=true) const;
|
||||
|
||||
//- Write the field, optionally as an entry
|
||||
void writeField(Ostream& os, const word& keyword = "") const;
|
||||
|
||||
//- Write the single value, or the first value from field
|
||||
void writeValue(Ostream& os) const;
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2012-2018 Bernhard Gschaider <bgschaid@hfd-research.com>
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2012-2018 Bernhard Gschaider
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -496,7 +496,11 @@ bool Foam::expressions::exprResult::writeSingleValueChecked(Ostream& os) const
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::expressions::exprResult::writeValueFieldChecked(Ostream& os) const
|
||||
bool Foam::expressions::exprResult::writeFieldChecked
|
||||
(
|
||||
const word& keyword,
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
if (!isType<Type>())
|
||||
{
|
||||
@ -508,26 +512,46 @@ bool Foam::expressions::exprResult::writeValueFieldChecked(Ostream& os) const
|
||||
if (isUniform_)
|
||||
{
|
||||
const Type& val = single_.get<Type>();
|
||||
os.writeEntry("value", val);
|
||||
if (keyword.empty())
|
||||
{
|
||||
os << val;
|
||||
}
|
||||
else
|
||||
{
|
||||
os.writeEntry(keyword, val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Zero-sized
|
||||
const Field<Type> fld;
|
||||
fld.writeEntry("value", os);
|
||||
// Zero-sized - could write nothing, or a zero value
|
||||
if (keyword.empty())
|
||||
{
|
||||
os << pTraits<Type>::zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
Field<Type>().writeEntry(keyword, os);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const Field<Type>& fld = *static_cast<const Field<Type>*>(fieldPtr_);
|
||||
|
||||
if (isUniform_)
|
||||
if (keyword.empty())
|
||||
{
|
||||
os.writeEntry("value", fld.first());
|
||||
os << fld;
|
||||
}
|
||||
else
|
||||
{
|
||||
fld.writeEntry("value", os);
|
||||
if (isUniform_)
|
||||
{
|
||||
os.writeEntry(keyword, fld.first());
|
||||
}
|
||||
else
|
||||
{
|
||||
fld.writeEntry(keyword, os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user