ENH: add test application for fileHander writing

COMP: update applications/test
This commit is contained in:
Mark Olesen 2023-09-29 19:43:28 +02:00 committed by Andrew Heather
parent 1af40e7dfe
commit 1d43e45fdd
9 changed files with 200 additions and 29 deletions

View File

@ -76,10 +76,10 @@ Foam::List<StringType> Foam::DirLister::csorted
const bool prune
) const
{
List<StringType> list(list<StringType>(pred, prune));
Foam::sort(list, stringOps::natural_sort());
List<StringType> result(list<StringType>(pred, prune));
Foam::sort(result, stringOps::natural_sort());
return list;
return result;
}

View File

@ -248,7 +248,7 @@ int main(int argc, char *argv[])
addr.emplace_back(2);
// Can also use the return value
Info<< "adding " << addr.emplace_back(4) << endl;
Info<< "adding " << addr.emplace_back(4) << nl;
forAll(dlE2, i)
{
@ -325,7 +325,7 @@ int main(int argc, char *argv[])
input1 = list2;
Info<< nl << "test subset/remove with "
Info<< nl << "test remove with "
<< flatOutput(input1) << endl;
for
@ -344,11 +344,9 @@ int main(int argc, char *argv[])
list2 = input1;
list1.remove(range);
list2.subset(range);
Info<< "input = " << flatOutput(input1) << nl
<< "remove " << range << " = " << flatOutput(list1) << nl
<< "subset " << range << " = " << flatOutput(list2) << nl;
<< "remove " << range << " = " << flatOutput(list1) << nl;
}
}

View File

@ -211,22 +211,6 @@ int main(int argc, char *argv[])
<< " hash:" << Hash<FixedList<label, 4>>()(list2) << nl;
// Test deprecated form
SLList<label> sllist3;
{
sllist3.push_back(0);
sllist3.push_back(1);
sllist3.push_back(2);
sllist3.push_back(3);
}
FixedList<label, 4> list3(sllist3);
Info<< "list3:" << list3 << nl;
// Test deprecated forms
list3 = array2;
list2 = sllist3;
// Using FixedList for content too
{
List<FixedList<label, 4>> twolists{list1, list2};

View File

@ -121,7 +121,7 @@ int main()
{
OStringStream os;
os << table1;
HashTable<scalar> readTable(IStringStream(os.str())(), 100);
HashTable<scalar> readTable(IStringStream(os.str())());
Info<< "Istream constructor:" << readTable << endl;
}

View File

@ -194,12 +194,12 @@ int main(int argc, char *argv[])
printInfo(newvalues);
{
iliststream is(std::move(newvalues));
icharstream is(std::move(newvalues));
char c = 0;
Info<< nl
<< "getting values from iliststream of "
<< "getting values from icharstream of "
<< is.list() << endl;
// Info<< " (" << is.tellg() << " " << is.remaining() << ")";

View File

@ -0,0 +1,3 @@
Test-fileHandler-writing.C
EXE = $(FOAM_USER_APPBIN)/Test-fileHandler-writing

View File

@ -0,0 +1,18 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
-I$(LIB_SRC)/transportModels \
-I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel
EXE_LIBS = \
-lfiniteVolume \
-lfvOptions \
-lmeshTools \
-lsampling \
-lturbulenceModels \
-lincompressibleTurbulenceModels \
-lincompressibleTransportModels \
-latmosphericModels

View File

@ -0,0 +1,169 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2023 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 <http://www.gnu.org/licenses/>.
Application
Test-fileHandler-writing
Description
Simple test of file writing, including timings
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "profiling.H"
#include "clockTime.H"
#include "fileName.H"
#include "fileOperation.H"
#include "IOstreams.H"
#include "OSspecific.H"
#include "ReadFields.H"
#include "volFields.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::addNote
(
"Loads mesh and fields from latest time and writes multiple times"
);
argList::noFunctionObjects(); // Disallow function objects
argList::addVerboseOption("additional verbosity");
argList::addOption("output", "Begin output iteration (default: 10000)");
argList::addOption("count", "Number of writes (default: 1)");
#include "setRootCase.H"
#include "createTime.H"
const label firstOutput = args.getOrDefault("output", 10000);
const label nOutput = args.getOrDefault("count", 1);
const int verbose = args.verbose();
// Select latestTime, including 0 and constant
{
const auto& times = runTime.times();
const label timeIndex = (times.size()-1);
if (timeIndex < 0)
{
FatalErrorInFunction
<< "No times!"
<< exit(FatalError);
}
runTime.setTime(times[timeIndex], timeIndex);
}
// #include "createMesh.H"
Info << "Create mesh time = " << runTime.timeName() << nl;
fvMesh mesh
(
IOobject
(
polyMesh::defaultRegion,
runTime.timeName(),
runTime,
Foam::IOobject::MUST_READ
),
false
);
mesh.init(true); // initialise all (lower levels and current)
Info<< endl;
// Read objects in time directory
IOobjectList objects(mesh, runTime.timeName());
// List of stored objects to clear after (as required)
DynamicList<regIOobject*> storedObjects;
// Read GeometricFields
Info<< nl << "Load fields" << nl;
#undef ReadFields
#define ReadFields(FieldType) \
readFields<FieldType>(mesh, objects, predicates::always{}, storedObjects);
// Read volFields
ReadFields(volScalarField);
ReadFields(volVectorField);
ReadFields(volSphericalTensorField);
ReadFields(volSymmTensorField);
ReadFields(volTensorField);
// Set fields to AUTO_WRITE
for (regIOobject* io : storedObjects)
{
io->writeOpt(IOobjectOption::AUTO_WRITE);
}
Info<< nl
<< "Writing " << nOutput << " times starting at "
<< firstOutput << nl;
clockTime timing;
if (verbose) Info<< "Time:";
for
(
label timeIndex = firstOutput, count = 0;
count < nOutput;
++timeIndex, ++count
)
{
runTime.setTime(timeIndex, timeIndex);
if (verbose) Info<< ' ' << runTime.timeName() << flush;
runTime.writeNow();
}
if (verbose) Info<< nl;
Info<< nl << "Writing took "
<< timing.timeIncrement() << "s" << endl;
Info<< nl
<< "Cleanup newly generated files with" << nl << nl
<< " foamListTimes -rm -time "
<< firstOutput << ":" << nl
<< " foamListTimes -processor -rm -time "
<< firstOutput << ":" << nl;
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -117,8 +117,7 @@ void cell_labels
nVerts += meshFaces[facei].size();
}
// pointLabels.clear();
pointLabels.expandStorage();
pointLabels.resize(pointLabels.capacity()); // Use full storage
// The first face has no duplicates, can copy in values
const labelList& firstFace = meshFaces[cFaces[0]];