From 8f8a4dc68238964f79f9da96b5ecc221cd3538a7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 22 Jan 2019 15:11:28 +0100 Subject: [PATCH] ENH: add foamDictionary -precision option (issue #1177) - since foamDictionary doesn't use system/controlDict it will use the standard default precision. The '-precision' option allows adjusting that value. --- applications/test/limits/Test-limits.C | 17 +++++++++++-- .../foamDictionary/foamDictionary.C | 25 ++++++++++++++++++- .../surface/surfaceConvert/surfaceConvert.C | 17 +++++++------ etc/config.sh/completion_cache | 4 +-- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/applications/test/limits/Test-limits.C b/applications/test/limits/Test-limits.C index 4123d475d8..ef6d1dc86c 100644 --- a/applications/test/limits/Test-limits.C +++ b/applications/test/limits/Test-limits.C @@ -40,20 +40,33 @@ using namespace Foam; int main(int argc, char *argv[]) { //NONE Info<<"int16:" << pTraits::max << nl; + Info<<"=max=" << nl; + Info<<"uint8:" << std::numeric_limits::max() << nl; Info<<"int16:" << std::numeric_limits::max() << nl; Info<<"int32:" << pTraits::max << nl; - Info<<"int64:" << pTraits::max << nl; Info<<"uint32:" << pTraits::max << nl; + Info<<"int64:" << pTraits::max << nl; Info<<"uint64:" << pTraits::max << nl; Info<< nl; cout<<"int16:" << std::numeric_limits::max() << nl; cout<<"int32:" << pTraits::max << nl; - cout<<"int64:" << pTraits::max << nl; cout<<"uint32:" << pTraits::max << nl; + cout<<"int64:" << pTraits::max << nl; cout<<"uint64:" << pTraits::max << nl; + Info<< nl << "=digits=" << nl; + + cout<<"int16:" << std::numeric_limits::digits << nl; + cout<<"int32:" << std::numeric_limits::digits << nl; + cout<<"uint32:" << std::numeric_limits::digits << nl; + cout<<"int64:" << std::numeric_limits::digits << nl; + cout<<"uint64:" << std::numeric_limits::digits << nl; + cout<<"float:" << std::numeric_limits::digits << nl; + cout<<"double:" << std::numeric_limits::digits << nl; + cout<<"long double:" << std::numeric_limits::digits << nl; + Info << "---\nEnd\n" << endl; return 0; diff --git a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C index 7844b57033..ae857b376c 100644 --- a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C +++ b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -64,6 +64,9 @@ Usage - \par -disableFunctionEntries Do not expand macros or directives (\#include etc) + - \par -precision int + Set default write precision for IOstreams + Example usage: - Change simulation to run for one timestep only: \verbatim @@ -307,6 +310,12 @@ int main(int argc, char *argv[]) "As per -diff, but locate the file as per foamEtcFile" ); argList::addOptionCompat("diff-etc", {"diffEtc", 1712}); + argList::addOption + ( + "precision", + "int", + "Set default write precision for IOstreams" + ); argList::addBoolOption ( @@ -346,6 +355,20 @@ int main(int argc, char *argv[]) entry::disableFunctionEntries = true; } + // Set the default output precision + { + const unsigned prec = args.lookupOrDefault("precision", 0u); + if (prec) + { + // if (Pstream::master()) + // { + // Serr<< "Output write precision set to " << prec << endl; + // } + + IOstream::defaultPrecision(prec); + Sout.precision(prec); + } + } const fileName dictFileName(args[1]); diff --git a/applications/utilities/surface/surfaceConvert/surfaceConvert.C b/applications/utilities/surface/surfaceConvert/surfaceConvert.C index 001f163fa7..21414d94ed 100644 --- a/applications/utilities/surface/surfaceConvert/surfaceConvert.C +++ b/applications/utilities/surface/surfaceConvert/surfaceConvert.C @@ -89,20 +89,23 @@ int main(int argc, char *argv[]) ); argList::addOption ( - "writePrecision", - "label", + "precision", + "int", "Write to output with the specified precision" ); + argList::addOptionCompat("precision", {"writePrecision", 1812}); argList args(argc, argv); - if (args.found("writePrecision")) { - const label prec = args.opt