Skip to content
Snippets Groups Projects
Commit 72c4b318 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: added dimensionedType::writeEntry method

- writing of dictionary entry with the name of the dimensionedType
  suppressed if it is identical to the keyword.
  This corresponds to the input requirements.
parent dd87c983
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -41,31 +41,38 @@ int main(int argc, char *argv[])
dimensionedTensor dt2("dt2", dimLength, tensor(1, 1, 2, 3, 4, 5, 6, 7, 8));
Info<< "cmptMultiply(dt, dt2): " << cmptMultiply(dt, dt2) << endl;
Info<< "cmptDivide(dt, dt2): " << cmptDivide(dt, dt2) << endl;
Info<< nl
<< "cmptMultiply(dt, dt2): " << cmptMultiply(dt, dt2) << nl
<< "cmptDivide(dt, dt2): " << cmptDivide(dt, dt2) << endl;
{
Pout<< "dimensionSet construct from is:"
<< dimensionSet(IStringStream("[Pa m^2 s^-2]")())
string dimString("[Pa m^2 s^-2]");
IStringStream is("[Pa m^2 s^-2]");
Pout<< nl;
Pout<< "dimensionSet construct from (is) with contents "
<< dimString << " = " << dimensionSet(is)
<< endl;
IStringStream is("[Pa m^2 s^-2]");
is.rewind();
dimensionSet dset(dimless);
is >> dset;
Pout<< "dimensionSet read:" << dset << endl;
}
{
Pout<< "construct from is:"
Pout<< nl
<< "construct from (is) = "
<< dimensionedScalar(IStringStream("bla [Pa mm^2 s^-2] 3.0")())
<< endl;
Pout<< "construct from name,is:"
Pout<< "construct from (name,is) = "
<< dimensionedScalar
(
"ABC",
IStringStream("[Pa mm^2 s^-2] 3.0")()
) << endl;
Pout<< "construct from name,dimensionSet,is:"
Pout<< "construct from (name,dims,is) = "
<< dimensionedScalar
(
"ABC",
......@@ -77,6 +84,14 @@ int main(int argc, char *argv[])
dimensionedScalar ds;
is >> ds;
Pout<< "read:" << ds << endl;
Info<< "writeEntry:" << nl;
Info<< "abc> "; ds.writeEntry("abc", Info);
Info<< endl;
Info<< "bla> "; ds.writeEntry("bla", Info);
Info<< endl;
}
}
......
......@@ -405,6 +405,32 @@ Foam::Istream& Foam::dimensioned<Type>::read
}
template<class Type>
void Foam::dimensioned<Type>::writeEntry
(
const word& keyword,
Ostream& os
) const
{
os.writeKeyword(keyword);
if (keyword != name_)
{
// The name, only if different from keyword
os << name_ << token::SPACE;
}
// The dimensions
scalar mult(1.0);
dimensions_.write(os, mult);
// The value
os << token::SPACE << value_/mult << token::END_STATEMENT << endl;
os.check(FUNCTION_NAME);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type>
......
......@@ -248,6 +248,11 @@ public:
//- using units from table
Istream& read(Istream& is, const HashTable<dimensionedScalar>& readSet);
//- Write as a dictionary entry with keyword.
// The name is not written when it is identical to keyword.
// The dimensions are always written.
void writeEntry(const word& keyword, Ostream& os) const;
// Member Operators
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment