From 9db3547bd31a535113edb06b3d7af5409bb8fdd3 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 28 Oct 2022 12:46:51 +0200 Subject: [PATCH] ENH: support optional average value when reading rawIOField ENH: simplify bookkeeping within MappedFile --- applications/test/rawIOField/Make/files | 3 + applications/test/rawIOField/Make/options | 9 + .../test/rawIOField/Test-rawIOField.C | 168 ++++++++++ .../IOobjects/GlobalIOField/GlobalIOField.C | 6 +- .../IOobjects/GlobalIOField/GlobalIOField.H | 21 +- .../db/IOobjects/GlobalIOList/GlobalIOList.H | 11 +- .../db/IOobjects/rawIOField/rawIOField.C | 125 +++++--- .../db/IOobjects/rawIOField/rawIOField.H | 61 +++- ...meVaryingMappedFixedValuePointPatchField.C | 289 ++++++++---------- ...meVaryingMappedFixedValuePointPatchField.H | 36 ++- .../PatchFunction1/MappedFile/MappedFile.C | 279 ++++++++--------- .../PatchFunction1/MappedFile/MappedFile.H | 35 ++- .../pointToPointPlanarInterpolation.H | 4 + ...pointToPointPlanarInterpolationTemplates.C | 15 + .../boundary/boundaryDataSurfaceWriter.C | 18 +- .../boundary/boundaryDataSurfaceWriter.H | 3 +- 16 files changed, 664 insertions(+), 419 deletions(-) create mode 100644 applications/test/rawIOField/Make/files create mode 100644 applications/test/rawIOField/Make/options create mode 100644 applications/test/rawIOField/Test-rawIOField.C diff --git a/applications/test/rawIOField/Make/files b/applications/test/rawIOField/Make/files new file mode 100644 index 0000000000..a37b434282 --- /dev/null +++ b/applications/test/rawIOField/Make/files @@ -0,0 +1,3 @@ +Test-rawIOField.C + +EXE = $(FOAM_USER_APPBIN)/Test-rawIOField diff --git a/applications/test/rawIOField/Make/options b/applications/test/rawIOField/Make/options new file mode 100644 index 0000000000..b6fa4bff16 --- /dev/null +++ b/applications/test/rawIOField/Make/options @@ -0,0 +1,9 @@ +EXE_INC = \ + -I$(LIB_SRC)/fileFormats/lnInclude \ + -I$(LIB_SRC)/surfMesh/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +EXE_LIBS = \ + -lfileFormats \ + -lsurfMesh \ + -lmeshTools diff --git a/applications/test/rawIOField/Test-rawIOField.C b/applications/test/rawIOField/Test-rawIOField.C new file mode 100644 index 0000000000..43bd4979ce --- /dev/null +++ b/applications/test/rawIOField/Test-rawIOField.C @@ -0,0 +1,168 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +Application + Test-rawIOField + +Description + Reading rawIOField from disk + +\*---------------------------------------------------------------------------*/ + +#include "argList.H" +#include "Time.H" +#include "Switch.H" +#include "primitiveFields.H" +#include "pointField.H" +#include "rawIOField.H" +#include "exprTraits.H" + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +using namespace Foam; + +#undef USE_ROOT_CASE +//#define USE_ROOT_CASE + + +template +tmp> readRawField +( + const IOobject& io, + IOobjectOption::readOption withAverage +) +{ + rawIOField raw(io, withAverage); + + Info<< "File: " << io.objectPath() << nl + << "Read: " << raw.size() + << ' ' << pTraits::typeName << " entries" << nl + << "Average: " << Switch::name(raw.hasAverage()) + << " = " << raw.average() << endl; + + return tmp>::New(std::move(static_cast&>(raw))); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char *argv[]) +{ + argList::addNote + ( + "Test behaviour of rawIOField reading (writing?)" + ); + + argList::noCheckProcessorDirectories(); + + argList::addBoolOption("scalar", "Read scalar field"); + argList::addBoolOption("vector", "Read vector field"); + argList::addBoolOption("point", "Read point field"); + argList::addBoolOption("average", "Require averaged value entry"); + argList::addBoolOption("try-average", "Optional averaged value entry"); + + argList::addArgument("fileName"); + + #ifdef USE_ROOT_CASE + #include "setRootCase.H" + #include "createTime.H" + #else + // Without root case, or time + argList args(argc, argv); + #endif + + fileName inputName = args.get(1); + + IOobjectOption::readOption withAverage = IOobjectOption::NO_READ; + + if (args.found("average")) + { + withAverage = IOobjectOption::MUST_READ; + } + else if (args.found("try-average")) + { + withAverage = IOobjectOption::READ_IF_PRESENT; + } + + Info<< "Using case: " << argList::envGlobalPath() << nl + << "Read file: " << inputName << nl + << "with average: " << int(withAverage) << nl + << endl; + + + refPtr