diff --git a/src/faOptions/sources/derived/externalFileSource/externalFileSource.C b/src/faOptions/sources/derived/externalFileSource/externalFileSource.C index 6f0a35080e..a1d2333616 100644 --- a/src/faOptions/sources/derived/externalFileSource/externalFileSource.C +++ b/src/faOptions/sources/derived/externalFileSource/externalFileSource.C @@ -65,7 +65,11 @@ Foam::fa::externalFileSource::externalFileSource mesh_, IOobject::NO_READ, IOobject::NO_WRITE, - false // Do not register + ( + dict.getOrDefault("store", false) + ? IOobject::REGISTER + : IOobject::NO_REGISTER + ) ), regionMesh(), dimensionedScalar(dimPressure, Zero) @@ -75,6 +79,10 @@ Foam::fa::externalFileSource::externalFileSource { fieldNames_.resize(1, fieldName_); + /// FUTURE? + /// // Optional entry (mandatory = false) + /// pExt_.dimensions().readEntry("dimensions", dict, false); + fa::option::resetApplied(); read(dict); @@ -155,7 +163,7 @@ bool Foam::fa::externalFileSource::read(const dictionary& dict) new PatchFunction1Types::MappedFile ( p, - "uniformValue", + "uniformValue", // entryName dict, tableName_, // field table name true // face values diff --git a/src/faOptions/sources/derived/externalFileSource/externalFileSource.H b/src/faOptions/sources/derived/externalFileSource/externalFileSource.H index a2056e18b0..74a0faa4d9 100644 --- a/src/faOptions/sources/derived/externalFileSource/externalFileSource.H +++ b/src/faOptions/sources/derived/externalFileSource/externalFileSource.H @@ -54,6 +54,7 @@ Usage type | Type name: externalFileSource | word | yes | - fieldName | Name of operand field | word | yes | - tableName | Name of operand table file | word | yes | - + store | Register external field 'pExt' | bool | no | false \endtable The inherited entries are elaborated in: diff --git a/src/fileFormats/Make/files b/src/fileFormats/Make/files index 7b633c6b3f..53d04f7852 100644 --- a/src/fileFormats/Make/files +++ b/src/fileFormats/Make/files @@ -1,3 +1,4 @@ +common/fileFormats.C common/manifoldCellsMeshObject.C colours/colourTable.C diff --git a/src/fileFormats/common/fileFormats.C b/src/fileFormats/common/fileFormats.C new file mode 100644 index 0000000000..d5a55e834f --- /dev/null +++ b/src/fileFormats/common/fileFormats.C @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 "fileFormats.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Extract and merge 'default' + formatName from list of dictionaries +// +// \returns dictionary of merged options +static dictionary combineFormatOptions +( + const word& formatName, + std::initializer_list dicts +) +{ + dictionary options; + + // Default specification. Merge from all levels + // - literal search only + for (const dictionary* dict : dicts) + { + if + ( + dict + && (dict = dict->findDict("default", keyType::LITERAL)) != nullptr + ) + { + options.merge(*dict); + } + } + + // Format specification. Merge from all levels + // - allow REGEX search + if (!formatName.empty()) + { + for (const dictionary* dict : dicts) + { + if + ( + dict + && (dict = dict->findDict(formatName)) != nullptr + ) + { + options.merge(*dict); + } + } + } + + return options; +} + +} // End namespace Foam + + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +Foam::dictionary Foam::fileFormats::getFormatOptions +( + const dictionary& dict, + const word& formatName, + const word& entryName +) +{ + return combineFormatOptions + ( + formatName, + { + dict.findDict(entryName, keyType::LITERAL) + } + ); +} + + +Foam::dictionary Foam::fileFormats::getFormatOptions +( + const dictionary& dict, + const dictionary& altDict, + const word& formatName, + const word& entryName +) +{ + return combineFormatOptions + ( + formatName, + { + dict.findDict(entryName, keyType::LITERAL), + altDict.findDict(entryName, keyType::LITERAL) + } + ); +} + + +// ************************************************************************* // diff --git a/src/fileFormats/common/fileFormats.H b/src/fileFormats/common/fileFormats.H new file mode 100644 index 0000000000..ec1f4ed9f4 --- /dev/null +++ b/src/fileFormats/common/fileFormats.H @@ -0,0 +1,102 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2022 OpenCFD Ltd. +------------------------------------------------------------------------------- +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 . + +Namespace + Foam::fileFormats + +Description + Namespace to isolate specifics for file formats, + and some common utilities. + +SourceFiles + fileFormats.C + +\*---------------------------------------------------------------------------*/ + +#ifndef Foam_fileFormats_H +#define Foam_fileFormats_H + +#include "word.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward Declarations +class dictionary; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fileFormats +{ + +//- Find "formatOptions" in a top-level dictionary. +//- Extract and merge 'default' + formatName values. +// +// \returns dictionary of merged formatOptions +dictionary getFormatOptions +( + //! The top-level dictionary to search + const dictionary& dict, + + //! The format name. Eg, \c ensight + const word& formatName, + + //! Dictionary sub-entry to search for + const word& entryName = "formatOptions" +); + +//- Find "formatOptions" in a top-level dictionary, +//- and optional override dictionary. +//- Extract and merge 'default' + formatName values. +// +// \returns dictionary of merged formatOptions +dictionary getFormatOptions +( + //! The top-level dictionary to search + const dictionary& dict, + + //! Additional dictionary to search + const dictionary& altDict, + + //! The format name. Eg, \c ensight + const word& formatName, + + //! Dictionary sub-entry to search for + const word& entryName = "formatOptions" +); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fileFormats +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fileFormats/ensight/read/ensightReadFile.C b/src/fileFormats/ensight/read/ensightReadFile.C index 07064ce263..3dcf09e4a1 100644 --- a/src/fileFormats/ensight/read/ensightReadFile.C +++ b/src/fileFormats/ensight/read/ensightReadFile.C @@ -180,7 +180,27 @@ Foam::Istream& Foam::ensightReadFile::read(label& value) } -Foam::Istream& Foam::ensightReadFile::read(scalar& value) +Foam::Istream& Foam::ensightReadFile::read(float& value) +{ + if (format() == IOstreamOption::BINARY) + { + read + ( + reinterpret_cast(&value), + sizeof(value) + ); + } + else + { + stdStream() >> value; + syncState(); + } + + return *this; +} + + +Foam::Istream& Foam::ensightReadFile::read(double& value) { float fvalue; @@ -191,15 +211,14 @@ Foam::Istream& Foam::ensightReadFile::read(scalar& value) reinterpret_cast(&fvalue), sizeof(fvalue) ); - - value = fvalue; } else { - stdStream() >> value; + stdStream() >> fvalue; syncState(); } + value = fvalue; return *this; } diff --git a/src/fileFormats/ensight/read/ensightReadFile.H b/src/fileFormats/ensight/read/ensightReadFile.H index 4f8ff48529..6982ae9072 100644 --- a/src/fileFormats/ensight/read/ensightReadFile.H +++ b/src/fileFormats/ensight/read/ensightReadFile.H @@ -27,7 +27,8 @@ Class Foam::ensightReadFile Description - Ensight output with specialized read() for strings, integers and floats. + A variant of IFstream with specialised read() for + strings, integers and floats. Correctly handles binary read as well. \*---------------------------------------------------------------------------*/ @@ -98,13 +99,16 @@ public: virtual Istream& read(char* buf, std::streamsize count); //- Read string as "%80s" or as binary - Istream& read(string& value); + virtual Istream& read(string& value); //- Read integer as "%10d" or as binary - Istream& read(label& value); + virtual Istream& read(label& value); - //- Read float as "%12.5e" or as binary - Istream& read(scalar& value); + //- Read floating-point as "%12.5e" or as binary + virtual Istream& read(float& value); + + //- Read floating-point as "%12.5e" or as a binary (narrowed) float + virtual Istream& read(double& value); //- Read element keyword virtual Istream& readKeyword(string& key); diff --git a/src/finiteArea/fields/areaFields/areaFields.C b/src/finiteArea/fields/areaFields/areaFields.C index 08412b1a69..2120369959 100644 --- a/src/finiteArea/fields/areaFields/areaFields.C +++ b/src/finiteArea/fields/areaFields/areaFields.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2016-2017 Wikki Ltd - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -92,5 +92,14 @@ const Foam::wordList Foam::fieldTypes::area "areaTensorField" }); +const Foam::wordList Foam::fieldTypes::area_internal +({ + "areaScalarField::Internal", + "areaVectorField::Internal", + "areaSphericalTensorField::Internal", + "areaSymmTensorField::Internal", + "areaTensorField::Internal" +}); + // ************************************************************************* // diff --git a/src/finiteArea/fields/areaFields/areaFieldsFwd.H b/src/finiteArea/fields/areaFields/areaFieldsFwd.H index 621222c69b..202298c2d3 100644 --- a/src/finiteArea/fields/areaFields/areaFieldsFwd.H +++ b/src/finiteArea/fields/areaFields/areaFieldsFwd.H @@ -92,6 +92,9 @@ namespace fieldTypes //- Standard area field types (scalar, vector, tensor, etc) extern const wordList area; + //- Standard dimensioned field types (scalar, vector, tensor, etc) + extern const wordList area_internal; + } // End namespace fieldTypes diff --git a/src/functionObjects/utilities/areaWrite/areaWrite.C b/src/functionObjects/utilities/areaWrite/areaWrite.C index 6ef6ee820a..8a6e7b898e 100644 --- a/src/functionObjects/utilities/areaWrite/areaWrite.C +++ b/src/functionObjects/utilities/areaWrite/areaWrite.C @@ -53,6 +53,10 @@ namespace Foam Foam::scalar Foam::areaWrite::mergeTol_ = 1e-10; + +// Implementation +#include "areaWriteImpl.C" + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::areaWrite::areaWrite @@ -110,7 +114,7 @@ Foam::areaWrite::areaWrite // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::areaWrite::verbose(const bool on) +bool Foam::areaWrite::verbose(const bool on) noexcept { bool old(verbose_); verbose_ = on; @@ -137,7 +141,7 @@ bool Foam::areaWrite::read(const dictionary& dict) obr_, IOobject::NO_READ, IOobject::NO_WRITE, - false + IOobject::NO_REGISTER ) ) ); @@ -299,7 +303,11 @@ bool Foam::areaWrite::write() const word& clsName = iter.key(); const label n = iter.val().size(); - if (fieldTypes::area.found(clsName)) + if + ( + fieldTypes::area.found(clsName) + || fieldTypes::area_internal.found(clsName) + ) { nAreaFields += n; } @@ -318,11 +326,43 @@ bool Foam::areaWrite::write() // Write fields - performAction(outWriter, areaMesh, objects); - performAction(outWriter, areaMesh, objects); - performAction(outWriter, areaMesh, objects); - performAction(outWriter, areaMesh, objects); - performAction(outWriter, areaMesh, objects); + { + // Area fields + #undef doLocalCode + #define doLocalCode(Type) \ + performAction \ + < \ + GeometricField \ + > \ + ( \ + outWriter, areaMesh, objects \ + ); \ + + doLocalCode(scalar); + doLocalCode(vector); + doLocalCode(sphericalTensor); + doLocalCode(symmTensor); + doLocalCode(tensor); + + // Area internal fields + #undef doLocalCode + #define doLocalCode(Type) \ + performAction \ + < \ + DimensionedField \ + > \ + ( \ + outWriter, areaMesh, objects \ + ); + + doLocalCode(scalar); + doLocalCode(vector); + doLocalCode(sphericalTensor); + doLocalCode(symmTensor); + doLocalCode(tensor); + + #undef doLocalCode + } // Finish this time step @@ -384,17 +424,17 @@ void Foam::areaWrite::readUpdate(const polyMesh::readUpdateState state) } -Foam::scalar Foam::areaWrite::mergeTol() +Foam::scalar Foam::areaWrite::mergeTol() noexcept { return mergeTol_; } -Foam::scalar Foam::areaWrite::mergeTol(const scalar tol) +Foam::scalar Foam::areaWrite::mergeTol(const scalar tol) noexcept { - const scalar prev(mergeTol_); + scalar old(mergeTol_); mergeTol_ = tol; - return prev; + return old; } diff --git a/src/functionObjects/utilities/areaWrite/areaWrite.H b/src/functionObjects/utilities/areaWrite/areaWrite.H index fdcec555c3..bca7c2a36d 100644 --- a/src/functionObjects/utilities/areaWrite/areaWrite.H +++ b/src/functionObjects/utilities/areaWrite/areaWrite.H @@ -210,7 +210,7 @@ public: //- Enable/disable verbose output // \return old value - bool verbose(const bool on); + bool verbose(const bool on) noexcept; //- Read the areaWrite dictionary virtual bool read(const dictionary& dict); @@ -231,10 +231,10 @@ public: virtual void readUpdate(const polyMesh::readUpdateState state); //- Get merge tolerance - static scalar mergeTol(); + static scalar mergeTol() noexcept; //- Set merge tolerance and return old value - static scalar mergeTol(const scalar tol); + static scalar mergeTol(const scalar tol) noexcept; }; @@ -244,12 +244,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository - #include "areaWriteTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/functionObjects/utilities/areaWrite/areaWriteTemplates.C b/src/functionObjects/utilities/areaWrite/areaWriteImpl.C similarity index 100% rename from src/functionObjects/utilities/areaWrite/areaWriteTemplates.C rename to src/functionObjects/utilities/areaWrite/areaWriteImpl.C diff --git a/src/meshTools/PatchFunction1/MappedFile/MappedFile.C b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C index 270ceaeaf1..6d6138017a 100644 --- a/src/meshTools/PatchFunction1/MappedFile/MappedFile.C +++ b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C @@ -27,93 +27,14 @@ License #include "polyMesh.H" #include "rawIOField.H" +#include "clockTime.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::PatchFunction1Types::MappedFile::MappedFile ( - const polyPatch& pp, - const word& redirectType, - const word& entryName, - const dictionary& dict, - const bool faceValues -) -: - PatchFunction1(pp, entryName, dict, faceValues), - dictConstructed_(true), - setAverage_(dict.getOrDefault("setAverage", false)), - perturb_(dict.getOrDefault("perturb", 1e-5)), - fieldTableName_(dict.getOrDefault("fieldTable", entryName)), - pointsName_(dict.getOrDefault("points", "points")), - mapMethod_(), - filterRadius_(dict.getOrDefault("filterRadius", 0)), - filterSweeps_(dict.getOrDefault