diff --git a/applications/test/dimensionedType/Test-dimensionedType.C b/applications/test/dimensionedType/Test-dimensionedType.C index 892552fa7082c575e76bcec73e980e9c3e1938dd..04c7fda5328abf87ae8cecaf823284acbb382861 100644 --- a/applications/test/dimensionedType/Test-dimensionedType.C +++ b/applications/test/dimensionedType/Test-dimensionedType.C @@ -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; } } diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C index 822113e3aa90788b1d95c726f86dc1bbd4934fd6..20de92e33efecd055ae87ca335f1728328c2ff26 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.C @@ -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> diff --git a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H index 0b84e6cc62bd63860b619d7aecf6a38058f5b6fd..472dbc71eef783736177a82576c83526d1e59a10 100644 --- a/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H +++ b/src/OpenFOAM/dimensionedTypes/dimensionedType/dimensionedType.H @@ -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