Compare commits

..

4 Commits

Author SHA1 Message Date
b050cd9480 BUG: missed removal of pointMesh/boundaryProcAddressing (fixes #3412) 2025-08-14 11:00:09 +02:00
e73c13466b ENH: pointConstraint: work in binary mode 2025-07-31 14:55:39 +01:00
d2c145d7a4 COMP: resolve label 64 compilation ambiguity for Mingw (fixes #3390)
COMP: restrict HashTable maxTableSize to int32 range

- avoids compiler warning about possible overflow (left-shift
  operation) for label 64 compilations and we don't need anything
  larger than int32 HashTable capacity anyhow.

ENH: make nearest power-of-two non-branching (previously brute-force)
2025-07-31 11:36:50 +02:00
95a5dfacc7 BUG: AMIInterpolation: keep old geomComm. See #3372
Correcting bug introduced when trying to keep the old communicator.
We do not need local communicator if all ranks of comm have
some faces. Not all ranks of the already local communicator.
2025-07-15 13:53:54 +01:00
1072 changed files with 11638 additions and 23907 deletions

3
.gitignore vendored
View File

@ -11,7 +11,6 @@
# File-browser settings - anywhere # File-browser settings - anywhere
.directory .directory
.DS_Store # OSX app store
# Backup/recovery versions - anywhere # Backup/recovery versions - anywhere
.#* .#*
@ -39,8 +38,6 @@ linux*Gcc*/
linux*Icc*/ linux*Icc*/
solaris*Gcc*/ solaris*Gcc*/
SunOS*Gcc*/ SunOS*Gcc*/
darwin*Clang*/
darwin*Gcc*/
platforms/ platforms/
# Top-level build directories # Top-level build directories

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
cd "${0%/*}" || exit # Run from this directory cd "${0%/*}" || exit # Run from this directory
set -- -all="${0##*/}" "$@" # Execute this instead of ./Allwmake set -- -no-recursion "$@" # Parse arguments only
# Run from OPENFOAM top-level directory only # Run from OPENFOAM top-level directory only
wmake -check-dir "$WM_PROJECT_DIR" 2>/dev/null || { wmake -check-dir "$WM_PROJECT_DIR" 2>/dev/null || {
@ -33,7 +33,7 @@ case "$FOAM_MODULE_PREFIX" in
;; ;;
(*) (*)
# Use wmake -all instead of Allwmake to allow for overrides # Use wmake -all instead of Allwmake to allow for overrides
( cd "$WM_PROJECT_DIR/modules" 2>/dev/null && wmake -all $* ) ( cd "$WM_PROJECT_DIR/modules" 2>/dev/null && wmake -all )
esac esac
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
cd "${0%/*}" || exit # Run from this directory cd "${0%/*}" || exit # Run from this directory
set -- -all="${0##*/}" "$@" # Execute this instead of ./Allwmake set -- -no-recursion "$@" # Parse arguments only
# Run from OPENFOAM top-level directory only # Run from OPENFOAM top-level directory only
wmake -check-dir "$WM_PROJECT_DIR" 2>/dev/null || { wmake -check-dir "$WM_PROJECT_DIR" 2>/dev/null || {
@ -33,7 +33,7 @@ case "$FOAM_MODULE_PREFIX" in
;; ;;
(*) (*)
# Use wmake -all instead of Allwmake to allow for overrides # Use wmake -all instead of Allwmake to allow for overrides
( cd "$WM_PROJECT_DIR/plugins" 2>/dev/null && wmake -all $* ) ( cd "$WM_PROJECT_DIR/plugins" 2>/dev/null && wmake -all )
esac esac
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -1,2 +1,2 @@
api=2507 api=2506
patch=0 patch=0

View File

@ -15,10 +15,11 @@ volVectorField U
// Initialise the velocity internal field to zero // Initialise the velocity internal field to zero
// Note: explicitly bypass evaluation of contraint patch overrides // Note: explicitly bypass evaluation of contraint patch overrides
// (e.g. swirlFanVelocity might lookup phi,rho) // (e.g. swirlFanVelocity might lookup phi,rho)
//U = Zero; //U = dimensionedVector(U.dimensions(), Zero);
{ {
U.internalFieldRef() = Zero; const dimensionedVector dt(U.dimensions(), Zero);
U.boundaryFieldRef() = Zero; U.internalFieldRef() = dt;
U.boundaryFieldRef() = dt.value();
} }
surfaceScalarField phi surfaceScalarField phi

View File

@ -6,7 +6,7 @@
+ MRF.DDt(U) + MRF.DDt(U)
+ turbulence->divDevReff(U) + turbulence->divDevReff(U)
== ==
invRhoInf*parcels.SU(U) parcels.SU(U, true)
+ fvOptions(U) + fvOptions(U)
); );

View File

@ -39,11 +39,6 @@ dimensionedScalar rhoInfValue
laminarTransport laminarTransport
); );
const dimensionedScalar invRhoInf
(
dimless/dimDensity, scalar(1)/rhoInfValue.value()
);
volScalarField rhoInf volScalarField rhoInf
( (
IOobject IOobject

View File

@ -1086,7 +1086,7 @@ void Foam::multiphaseMixtureThermo::solveAlphas
MULES::limitSum(alphaPhiCorrs); MULES::limitSum(alphaPhiCorrs);
rhoPhi_ = Zero; rhoPhi_ = dimensionedScalar(dimensionSet(1, 0, -1, 0, 0), Zero);
volScalarField sumAlpha volScalarField sumAlpha
( (

View File

@ -63,11 +63,23 @@ Foam::DTRMParticle::DTRMParticle
{ {
is >> p0_ >> p1_ >> I0_ >> I_ >> dA_ >> transmissiveId_; is >> p0_ >> p1_ >> I0_ >> I_ >> dA_ >> transmissiveId_;
} }
else if (!is.checkLabelSize<>() || !is.checkScalarSize<>())
{
// Non-native label or scalar size
is.beginRawRead();
readRawScalar(is, p0_.data(), vector::nComponents);
readRawScalar(is, p1_.data(), vector::nComponents);
readRawScalar(is, &I0_);
readRawScalar(is, &I_);
readRawScalar(is, &dA_);
readRawLabel(is, &transmissiveId_);
is.endRawRead();
}
else else
{ {
// No non-native streaming
is.fatalCheckNativeSizes(FUNCTION_NAME);
is.read(reinterpret_cast<char*>(&p0_), sizeofFields_); is.read(reinterpret_cast<char*>(&p0_), sizeofFields_);
} }
} }

View File

@ -557,7 +557,7 @@ void Foam::radiation::laserDTRM::calculate()
// Reset the field // Reset the field
Q_ == Zero; Q_ == dimensionedScalar(Q_.dimensions(), Zero);
a_ = absorptionEmission_->a(); a_ = absorptionEmission_->a();
e_ = absorptionEmission_->e(); e_ = absorptionEmission_->e();

View File

@ -232,7 +232,7 @@
surfaceScalarField mSfGradp("mSfGradp", pEqnIncomp.flux()/rAUf); surfaceScalarField mSfGradp("mSfGradp", pEqnIncomp.flux()/rAUf);
phasei = 0; phasei = 0;
phi = Zero; phi = dimensionedScalar("phi", phi.dimensions(), Zero);
for (phaseModel& phase : fluid.phases()) for (phaseModel& phase : fluid.phases())
{ {
@ -261,7 +261,7 @@
mSfGradp = pEqnIncomp.flux()/rAUf; mSfGradp = pEqnIncomp.flux()/rAUf;
U = Zero; U = dimensionedVector("U", dimVelocity, Zero);
phasei = 0; phasei = 0;
for (phaseModel& phase : fluid.phases()) for (phaseModel& phase : fluid.phases())

View File

@ -626,7 +626,7 @@ void Foam::multiphaseMixture::solveAlphas
MULES::limitSum(alphaPhiCorrs); MULES::limitSum(alphaPhiCorrs);
rhoPhi_ = Zero; rhoPhi_ = dimensionedScalar(dimMass/dimTime, Zero);
volScalarField sumAlpha volScalarField sumAlpha
( (

View File

@ -14,6 +14,6 @@ if (!(runTime.timeIndex() % 5))
if (smi < -SMALL) if (smi < -SMALL)
{ {
Info<< "Resetting Dcorr to 0" << endl; Info<< "Resetting Dcorr to 0" << endl;
Dcorr == Zero; Dcorr == dimensionedVector(Dcorr.dimensions(), Zero);
} }
} }

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
cd "${0%/*}" || exit # Run from this directory cd "${0%/*}" || exit # Run from this directory
. "${WM_PROJECT_DIR:?}"/wmake/scripts/wmakeFunctions # Need wmake functions . ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions # Require wmake functions
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -1,9 +1,8 @@
#!/bin/sh #!/bin/sh
cd "${0%/*}" || exit # Run from this directory cd "${0%/*}" || exit # Run from this directory
set -- -all="${0##*/}" "$@" # Execute this instead of ./Allwmake set -- -no-recursion "$@" # Parse arguments only
. ${WM_PROJECT_DIR:?}/wmake/scripts/AllwmakeParseArguments
. "${WM_PROJECT_DIR:?}"/wmake/scripts/AllwmakeParseArguments . ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions # Require wmake functions
. "${WM_PROJECT_DIR:?}"/wmake/scripts/wmakeFunctions # Need wmake functions
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Environment # Environment

View File

@ -1,3 +1,3 @@
Test-CompactIOList.cxx Test-CompactIOList.C
EXE = $(FOAM_USER_APPBIN)/Test-CompactIOList EXE = $(FOAM_USER_APPBIN)/Test-CompactIOList

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2020-2025 OpenCFD Ltd. Copyright (C) 2020-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application Application
Test-CompactIOList testCompactIOList
Description Description
Simple demonstration and test application for the CompactIOList container Simple demonstration and test application for the CompactIOList container
@ -46,20 +46,13 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
argList::addBoolOption("ascii", "use ascii format");
argList::addOption("count", "number of faces");
#include "setRootCase.H" #include "setRootCase.H"
#include "createTime.H" #include "createTime.H"
IOstreamOption streamOpt(IOstreamOption::BINARY); IOstreamOption streamOpt(IOstreamOption::BINARY);
// IOstreamOption streamOpt(IOstreamOption::ASCII);
if (args.found("ascii")) const label size = 20000000;
{
streamOpt.format(IOstreamOption::ASCII);
}
const label size = args.getOrDefault<label>("count", 20000000);
// Old format // Old format
// ~~~~~~~~~~ // ~~~~~~~~~~
@ -70,50 +63,39 @@ int main(int argc, char *argv[])
( (
IOobject IOobject
( (
"faces2-plain", "faces2",
runTime.constant(), runTime.constant(),
polyMesh::meshSubDir, polyMesh::meshSubDir,
runTime, runTime,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
IOobject::NO_REGISTER IOobject::NO_REGISTER
) ),
size
); );
faces2.resize(size, face(identity(4))); const face f(identity(4));
Info<< "Plain format faceList " << faces2.objectRelPath() << nl; forAll(faces2, i)
Info<< " constructed in = " << runTime.cpuTimeIncrement() {
<< " s" << endl; faces2[i] = f;
}
Info<< "Constructed faceList in = "
<< runTime.cpuTimeIncrement() << " s" << nl << endl;
faces2.writeObject(streamOpt, true); faces2.writeObject(streamOpt, true);
Info<< " wrote in = " Info<< "Written old format faceList in = "
<< runTime.cpuTimeIncrement() << " s" << endl; << runTime.cpuTimeIncrement() << " s" << nl << endl;
// Read (size only)
label count = faceIOList::readContentsSize
(
IOobject
(
"faces2-plain",
runTime.constant(),
polyMesh::meshSubDir,
runTime,
IOobject::MUST_READ
)
);
Info<< " counted " << count << " faces on disk in = "
<< runTime.cpuTimeIncrement() << " s" << endl;
// Read // Read
faceIOList faces2b faceIOList faces3
( (
IOobject IOobject
( (
"faces2-plain", "faces2",
runTime.constant(), runTime.constant(),
polyMesh::meshSubDir, polyMesh::meshSubDir,
runTime, runTime,
@ -123,7 +105,7 @@ int main(int argc, char *argv[])
) )
); );
Info<< " read " << faces2b.size() << " faces in = " Info<< "Read old format " << faces3.size() << " faceList in = "
<< runTime.cpuTimeIncrement() << " s" << nl << endl; << runTime.cpuTimeIncrement() << " s" << nl << endl;
} }
@ -132,54 +114,44 @@ int main(int argc, char *argv[])
// ~~~~~~~~~~ // ~~~~~~~~~~
{ {
// Construct big faceList in compact format // Construct big faceList in new format
faceCompactIOList faces2 faceCompactIOList faces2
( (
IOobject IOobject
( (
"faces2-compact", "faces2",
runTime.constant(), runTime.constant(),
polyMesh::meshSubDir, polyMesh::meshSubDir,
runTime, runTime,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
IOobject::NO_REGISTER IOobject::NO_REGISTER
) ),
size
); );
faces2.resize(size, face(identity(4))); const face f(identity(4));
Info<< "Compact format faceList" << faces2.objectRelPath() << nl; forAll(faces2, i)
Info<< " constructed in = " {
<< runTime.cpuTimeIncrement() << " s" << endl; faces2[i] = f;
}
Info<< "Constructed new format faceList in = "
<< runTime.cpuTimeIncrement() << " s" << nl << endl;
faces2.writeObject(streamOpt, true); faces2.writeObject(streamOpt, true);
Info<< " wrote in = " Info<< "Written new format faceList in = "
<< runTime.cpuTimeIncrement() << " s" << endl; << runTime.cpuTimeIncrement() << " s" << nl << endl;
// Read (size only)
label count = faceCompactIOList::readContentsSize
(
IOobject
(
"faces2-compact",
runTime.constant(),
polyMesh::meshSubDir,
runTime,
IOobject::MUST_READ
)
);
Info<< " counted " << count << " faces on disk in = "
<< runTime.cpuTimeIncrement() << " s" << endl;
// Read // Read
faceCompactIOList faces2b faceCompactIOList faces3
( (
IOobject IOobject
( (
"faces2-compact", "faces2",
runTime.constant(), runTime.constant(),
polyMesh::meshSubDir, polyMesh::meshSubDir,
runTime, runTime,
@ -189,7 +161,7 @@ int main(int argc, char *argv[])
) )
); );
Info<< " read " << faces2b.size() << " faces in = " Info<< "Read new format " << faces3.size() << " faceList in = "
<< runTime.cpuTimeIncrement() << " s" << nl << endl; << runTime.cpuTimeIncrement() << " s" << nl << endl;
} }

View File

@ -1,3 +1,3 @@
Test-HashPtrTable.cxx Test-HashPtrTable.C
EXE = $(FOAM_USER_APPBIN)/Test-HashPtrTable EXE = $(FOAM_USER_APPBIN)/Test-HashPtrTable

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2025 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -42,55 +42,33 @@ Description
using namespace Foam; using namespace Foam;
bool verbosity = true; class Scalar
// Gratuitous class inheritance
template<class T>
class BoxedType
{ {
T data_; scalar data_;
public: public:
static bool verbose; static bool verbose;
constexpr BoxedType() noexcept : data_(0) {} constexpr Scalar() noexcept : data_(0) {}
BoxedType(T val) noexcept : data_(val) {} Scalar(scalar val) noexcept : data_(val) {}
~BoxedType()
{
if (verbosity) Info<< " [delete BoxedType: " << value() << ']' << nl;
}
T value() const noexcept { return data_; }
T& value() noexcept { return data_; }
auto clone() const { return autoPtr<BoxedType<T>>::New(*this); }
};
template<class T> Ostream& operator<<(Ostream& os, const BoxedType<T>& item)
{
return (os << " -> " << item.value());
}
class Scalar : public BoxedType<scalar>
{
public:
using BoxedType<scalar>::BoxedType;
~Scalar() ~Scalar()
{ {
if (verbosity) Info<< "delete Scalar: " << value() << nl; if (verbose) Info<< "delete Scalar: " << data_ << endl;
}
const scalar& value() const noexcept { return data_; }
scalar& value() noexcept { return data_; }
friend Ostream& operator<<(Ostream& os, const Scalar& item)
{
os << item.value();
return os;
} }
auto clone() const { return autoPtr<Scalar>::New(*this); }
}; };
Ostream& operator<<(Ostream& os, const Scalar& item) bool Scalar::verbose = true;
{
return (os << item.value());
}
template<class T> template<class T>

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd. Copyright (C) 2017-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,11 +37,30 @@ License
using namespace Foam; using namespace Foam;
void checkCanonicalSize(label size)
{
const auto n = HashTableCore::canonicalSize(size);
std::ostringstream buf;
buf.setf(std::ios_base::hex, std::ios_base::basefield);
buf << n;
Info<< "hash-table size of " << size
<< " = " << n << " (0x" << buf.str().c_str() << ')' << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:
int main() int main()
{ {
for (label size : { -1, 0, 1, 7, 500, 1024, 1025, 10000, (labelMax-1)} )
{
checkCanonicalSize(size);
}
Info<< nl;
HashTable<scalar> table1 HashTable<scalar> table1
{ {
{"aaa", 1.0}, {"aaa", 1.0},

View File

@ -1,3 +1,3 @@
Test-HashTable2.cxx Test-HashTable2.C
EXE = $(FOAM_USER_APPBIN)/Test-HashTable2 EXE = $(FOAM_USER_APPBIN)/Test-HashTable2

View File

@ -1,3 +1,3 @@
Test-HashTable3.cxx Test-HashTable3.C
EXE = $(FOAM_USER_APPBIN)/Test-HashTable3 EXE = $(FOAM_USER_APPBIN)/Test-HashTable3

View File

@ -89,6 +89,12 @@ Ostream& printView(Ostream& os, std::string_view s)
} }
Ostream& printView(Ostream& os, stdFoam::span<char> s)
{
return printView(os, s.begin(), s.end());
}
Ostream& printView(Ostream& os, const UList<char>& list) Ostream& printView(Ostream& os, const UList<char>& list)
{ {
return printView(os, list.begin(), list.end()); return printView(os, list.begin(), list.end());

View File

@ -1,3 +1,3 @@
Test-IOobjectList.cxx Test-IOobjectList.C
EXE = $(FOAM_USER_APPBIN)/Test-IOobjectList EXE = $(FOAM_USER_APPBIN)/Test-IOobjectList

View File

@ -1,3 +1,3 @@
Test-ISLList.cxx Test-ISLList.C
EXE = $(FOAM_USER_APPBIN)/Test-ISLList EXE = $(FOAM_USER_APPBIN)/Test-ISLList

View File

@ -1,3 +1,3 @@
Test-IStringStream.cxx Test-IStringStream.C
EXE = $(FOAM_USER_APPBIN)/Test-IStringStream EXE = $(FOAM_USER_APPBIN)/Test-IStringStream

View File

@ -106,7 +106,7 @@ void printMyString(const UList<string>& lst)
{ {
MyStrings slist2(lst); MyStrings slist2(lst);
Info<< slist2 << nl; Info<<slist2 << nl;
} }
@ -204,6 +204,16 @@ int main(int argc, char *argv[])
Info<<" " << *iter; Info<<" " << *iter;
} }
Info<< nl; Info<< nl;
Info<< "data:" << Foam::name(ident.cdata())
<< " size:" << ident.size() << nl;
Info<< "resize_unsafe(10)" << nl;
ident.resize_unsafe(10);
Info<< "data:" << Foam::name(ident.cdata())
<< " size:" << ident.size() << nl;
} }
if (false) if (false)
@ -360,7 +370,7 @@ int main(int argc, char *argv[])
auto shrtList = ListOps::create<short> auto shrtList = ListOps::create<short>
( (
longLabelList, longLabelList,
[](label val){ return val; } [](const label& val){ return val; }
); );
printListOutputType<short>("short") << nl; printListOutputType<short>("short") << nl;
@ -557,7 +567,7 @@ int main(int argc, char *argv[])
auto scalars = ListOps::create<scalar> auto scalars = ListOps::create<scalar>
( (
labels, labels,
[](label val){ return scalar(1.5*val); } [](const label& val){ return scalar(1.5*val); }
); );
Info<< "scalars: " << flatOutput(scalars) << endl; Info<< "scalars: " << flatOutput(scalars) << endl;
} }
@ -566,7 +576,7 @@ int main(int argc, char *argv[])
auto vectors = ListOps::create<vector> auto vectors = ListOps::create<vector>
( (
labels, labels,
[](label val){ return vector(1.2*val, -1.2*val, 0); } [](const label& val){ return vector(1.2*val, -1.2*val, 0); }
); );
Info<< "vectors: " << flatOutput(vectors) << endl; Info<< "vectors: " << flatOutput(vectors) << endl;
} }
@ -575,7 +585,7 @@ int main(int argc, char *argv[])
auto longs = ListOps::create<long> auto longs = ListOps::create<long>
( (
labels, labels,
[](label val){ return val; } [](const label& val){ return val; }
); );
Info<< "longs: " << flatOutput(longs) << endl; Info<< "longs: " << flatOutput(longs) << endl;
} }
@ -593,7 +603,7 @@ int main(int argc, char *argv[])
( (
labelRange().cbegin(), labelRange().cbegin(),
labelRange(15).cend(), labelRange(15).cend(),
[](label val){ return scalar(-1.125*val); } [](const label& val){ return scalar(-1.125*val); }
); );
Info<< "scalars: " << flatOutput(scalars) << endl; Info<< "scalars: " << flatOutput(scalars) << endl;
} }

View File

@ -89,6 +89,12 @@ Ostream& printView(Ostream& os, std::string_view s)
} }
Ostream& printView(Ostream& os, stdFoam::span<char> s)
{
return printView(os, s.begin(), s.end());
}
Ostream& printView(Ostream& os, const UList<char>& list) Ostream& printView(Ostream& os, const UList<char>& list)
{ {
return printView(os, list.begin(), list.end()); return printView(os, list.begin(), list.end());
@ -183,25 +189,12 @@ int main(int argc, char *argv[])
printInfo(obuf); printInfo(obuf);
// Overwrite at some position // Overwrite at some position
if (auto i = obuf.view().find("item5"); i != std::string::npos) obuf.stdStream().rdbuf()->pubseekpos(0.60 * obuf.size());
{ obuf << "<" << nl << "OVERWRITE" << nl;
// obuf.seek(0.60 * obuf.size());
obuf.seek(i);
obuf << "<OVERWRITE>" << nl;
}
Info<<"after overwrite" << nl; Info<<"after overwrite" << nl;
printInfo(obuf); printInfo(obuf);
// Truncate
{
constexpr float fraction = 0.90;
Info<<"truncated at " << (100*fraction) << "% ["
<< int(fraction*obuf.size()) << " chars]" << nl;
obuf.seek(fraction*obuf.size());
printInfo(obuf);
}
Info<< "transfer contents to a List or ICharStream" << nl; Info<< "transfer contents to a List or ICharStream" << nl;
// Reclaim data storage from OCharStream -> ICharStream // Reclaim data storage from OCharStream -> ICharStream

View File

@ -1,3 +0,0 @@
Test-OCharStream2.cxx
EXE = $(FOAM_USER_APPBIN)/Test-OCharStream2

View File

@ -1,2 +0,0 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -1,473 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2025 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/>.
Description
\*---------------------------------------------------------------------------*/
#include "SpanStream.H"
#include "wordList.H"
#include "IOstreams.H"
#include "argList.H"
#include <charconv>
#include <cctype>
#include <cstdio>
#include <limits>
#include <iomanip>
using namespace Foam;
Ostream& printString(Ostream& os, const char* first, const char* last)
{
os << '"';
for (; first != last; (void)++first)
{
os << *first;
}
os << '"';
return os;
}
Ostream& printView(Ostream& os, const char* first, const char* last)
{
char buf[4];
os << label(last-first) << '(';
for (; first != last; (void)++first)
{
const char c = *first;
if (isprint(c))
{
os << c;
}
else if (c == '\t')
{
os << "\\t";
}
else if (c == '\n')
{
os << "\\n";
}
else
{
::snprintf(buf, 4, "%02X", c);
os << "\\x" << buf;
}
}
os << ')';
return os;
}
Ostream& printView(Ostream& os, std::string_view s)
{
return printView(os, s.begin(), s.end());
}
Ostream& printView(Ostream& os, const UList<char>& list)
{
return printView(os, list.begin(), list.end());
}
Ostream& writeList(Ostream& os, const UList<char>& list)
{
return printView(os, list);
}
Ostream& toString(Ostream& os, const UList<char>& list)
{
return printString(os, list.begin(), list.end());
}
Ostream& toString(Ostream& os, std::string_view s)
{
return printString(os, s.begin(), s.end());
}
template<class BufType>
void printInfo(const BufType& buf)
{
Info<< nl << "=========================" << endl;
buf.print(Info);
Info<< "addr: " << Foam::name(buf.view().data()) << nl;
toString(Info, buf.view());
Info<< nl << "=========================" << endl;
}
// Return a left-padded integer as "word"
template<class IntType>
std::string leftpadded(IntType val, char fillch = ' ')
{
std::string buf;
buf.resize((std::numeric_limits<IntType>::digits10+1), fillch);
auto first = (buf.data());
auto last = (buf.data() + buf.size());
auto result = std::to_chars(first, last, val);
if (result.ec == std::errc{})
{
auto* iter = result.ptr;
int count = std::distance(iter, last);
std::cout << "did not fill: " << count << " chars\n";
// With two spaces before comments
if (count > 0) { *iter++ = ' '; --count; }
if (count > 0) { *iter++ = ' '; --count; }
for (char c = (count >= 2 ? '/' : ' '); count > 0; --count)
{
*iter++ = c;
}
}
return buf;
}
template<class IntType>
void leftpad(std::ostream& os, IntType val, char fillch = ' ')
{
// set fill char and width
os.setf(std::ios_base::left, std::ios_base::adjustfield);
fillch = os.fill(fillch);
os.width(std::numeric_limits<IntType>::digits10+1);
os << val;
// restore fill char
os.fill(fillch);
}
template<class IntType>
void rightpad(std::ostream& os, IntType val, char fillch = ' ')
{
// set fill char and width
os.setf(std::ios_base::right, std::ios_base::adjustfield);
fillch = os.fill(fillch);
os.width(std::numeric_limits<IntType>::digits10+1);
os << val;
// restore fill char
os.fill(fillch);
}
// Left-padded value with trailing comment slashes
template<class IntType>
void leftpad(ocharstream& os, IntType val)
{
const auto beg = os.tellp();
os << val;
int count = (std::numeric_limits<IntType>::digits10+1) - (os.tellp() - beg);
// With two spaces before comments
if (count > 0) { os << ' '; --count; }
if (count > 0) { os << ' '; --count; }
for (const char c = (count >= 2 ? '/' : ' '); count > 0; --count)
{
os << c;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noBanner();
argList::noParallel();
argList::addBoolOption("fake-zerosize", "Fake overwriting with zero data");
argList::addBoolOption("dict-format", "Format as dictionary entry");
#include "setRootCase.H"
const bool optFakeZerosize = args.found("fake-zerosize");
const bool isDictFormat = args.found("dict-format");
// const constexpr int width = (std::numeric_limits<label>::digits10+1);
// experiment with to_chars instead of streaming
{
// Some value
label val(1234);
auto fixed = leftpadded(val);
Info<< "leftpadded " << val << " : " << fixed << nl;
}
ocharstream labelbuf;
labelbuf.reserve_exact(32);
// Some value
labelbuf.rewind();
rightpad(labelbuf, label(10));
printInfo(labelbuf);
OCharStream obuf;
obuf.reserve_exact(48);
printInfo(obuf);
obuf.push_back('>');
obuf.append(" string_view ");
obuf.push_back('<');
printInfo(obuf);
obuf.pop_back(8);
printInfo(obuf);
obuf.pop_back(100);
printInfo(obuf);
// Fill with some content
for (int i = 0; i < 26; ++i)
{
obuf<< char('A' + i);
}
// Change letter 'O' to '_'
if (auto i = obuf.view().find('O'); i != std::string::npos)
{
obuf.overwrite(i, '_');
}
// append and push_back some content
obuf.append(5, '<');
obuf.push_back('#');
obuf.append(5, '>');
printInfo(obuf);
obuf.pop_back(8);
printInfo(obuf);
// Slightly silly test
{
const auto list = obuf.list();
Info<< "list content:" << list << nl;
Info<< "view content:" << nl << list.view() << nl;
}
obuf.overwrite(4, labelbuf.view());
printInfo(obuf);
obuf.overwrite(20, "####");
printInfo(obuf);
Info<< "operation Ignored..." << nl;
obuf.overwrite(45, "????");
printInfo(obuf);
// Update with new value
{
labelbuf.rewind();
rightpad(labelbuf, label(200), '.');
obuf.overwrite(4, labelbuf.view());
printInfo(obuf);
}
// With yet another value (non-fixed width)
{
labelbuf.rewind();
labelbuf << label(15);
obuf.overwrite(4, labelbuf.view());
printInfo(obuf);
}
// Slightly harder test
{
std::string chars(26, '?');
for (int i = 0; i < 26; ++i)
{
chars[i] = char('A' + i);
}
auto& os = obuf;
os.rewind();
const word procName("processor0");
// Write as primitiveEntry or commented content
// // constexpr bool isDictFormat = true;
// if constexpr (isDictFormat)
if (isDictFormat)
{
// Like writeKeyword() with compoundToken
os << nl << procName << ' ' << word("List<char>") << nl;
}
else
{
// Human-readable comments
os << nl << "// " << procName << nl;
}
// This is the code we want to have, but assume we don't know
// the size or data beforehand.
//
// if (str && len > 0)
// {
// // Special treatment for char data (binary I/O only)
// const auto oldFmt = os.format(IOstreamOption::BINARY);
//
// os << label(len) << nl;
// os.write(str, len);
// os << nl;
//
// os.format(oldFmt);
// }
// else
// {
// os << label(0) << nl;
// }
// Position before writing the label
const auto labelBegin = os.tellp();
// Replace: os << label(len) << nl;
// with a fixed-length version
{
labelbuf.rewind();
rightpad(labelbuf, 0);
os.append(labelbuf.view());
os << nl;
}
constexpr bool testUnknown = true;
label dataCount = 0;
if constexpr (testUnknown)
{
// Pretend we don't know the number of characters a priori
const auto oldFmt = os.format(IOstreamOption::BINARY);
const auto lineNumber = os.lineNumber();
// count is unknown but irrelevant for serial
os.beginRawWrite(0);
// Position before raw binary data
const auto dataBegin = os.tellp();
// Some type of output, streaming etc
os.writeRaw(chars.data(), chars.size());
// How many chars of binary data written?
dataCount = (os.tellp() - dataBegin);
os.endRawWrite();
os.lineNumber() = lineNumber;
os << nl;
os.format(oldFmt);
}
else
{
// If we had all data collected a priori
dataCount = chars.size();
const auto oldFmt = os.format(IOstreamOption::BINARY);
if (dataCount > 0)
{
os.write(chars.data(), chars.size());
os << nl;
}
os.format(oldFmt);
}
if (optFakeZerosize)
{
dataCount = 0; // fake zero-size
}
printInfo(os);
// Update the data count with the correct value
if (dataCount > 0)
{
labelbuf.rewind();
leftpad(labelbuf, label(dataCount));
os.overwrite(labelBegin, labelbuf.view());
}
else
{
os.seek(int64_t(labelBegin)-1);
// if constexpr (isDictFormat)
if (isDictFormat)
{
os << ' ' << label(0);
}
else
{
os << nl << label(0) << nl;
}
}
// if constexpr (isDictFormat)
if (isDictFormat)
{
os.endEntry();
}
printInfo(os);
Info<< "view: " << os.view(4, 8) << nl;
Info<< "view: " << os.view(32) << nl;
// Ignores out-of-range
Info<< "view: " << os.view(1000) << nl;
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2025 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -65,6 +65,7 @@ int main(int argc, char *argv[])
OCountStream cnt; OCountStream cnt;
OCharStream cstr; OCharStream cstr;
OStringStream sstr;
ocountstream plain; ocountstream plain;
generateOutput(cstr); generateOutput(cstr);
@ -76,6 +77,7 @@ int main(int argc, char *argv[])
Info<< "counter state: " << (cnt.stdStream().rdstate()) << nl Info<< "counter state: " << (cnt.stdStream().rdstate()) << nl
<< "via char-stream: " << label(cstr.view().size()) << " chars" << nl << "via char-stream: " << label(cstr.view().size()) << " chars" << nl
<< "via string-stream: " << label(sstr.count()) << " chars" << nl
<< "via ocountstream: " << plain.count() << " chars" << endl; << "via ocountstream: " << plain.count() << " chars" << endl;
fileName outputName; fileName outputName;

View File

@ -1,3 +1,3 @@
Test-OStringStream.cxx Test-OStringStream.C
EXE = $(FOAM_USER_APPBIN)/Test-OStringStream EXE = $(FOAM_USER_APPBIN)/Test-OStringStream

View File

@ -1,3 +1,3 @@
Test-PackedList.cxx Test-PackedList.C
EXE = $(FOAM_USER_APPBIN)/Test-PackedList EXE = $(FOAM_USER_APPBIN)/Test-PackedList

View File

@ -1,3 +1,3 @@
Test-PtrDictionary1.cxx Test-PtrDictionary1.C
EXE = $(FOAM_USER_APPBIN)/Test-PtrDictionary1 EXE = $(FOAM_USER_APPBIN)/Test-PtrDictionary1

View File

@ -42,8 +42,6 @@ Description
using namespace Foam; using namespace Foam;
bool verbosity = true;
class ent class ent
: :
public Dictionary<ent>::link public Dictionary<ent>::link
@ -75,12 +73,14 @@ class Scalar
public: public:
static bool verbose;
constexpr Scalar() noexcept : data_(0) {} constexpr Scalar() noexcept : data_(0) {}
Scalar(scalar val) noexcept : data_(val) {} Scalar(scalar val) noexcept : data_(val) {}
~Scalar() ~Scalar()
{ {
if (verbosity) Info<< "delete Scalar: " << data_ << endl; if (verbose) Info<< "delete Scalar: " << data_ << endl;
} }
scalar value() const noexcept { return data_; } scalar value() const noexcept { return data_; }
@ -93,6 +93,8 @@ public:
} }
}; };
bool Scalar::verbose = true;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:

View File

@ -1,3 +1,3 @@
Test-PtrList.cxx Test-PtrList.C
EXE = $(FOAM_USER_APPBIN)/Test-PtrList EXE = $(FOAM_USER_APPBIN)/Test-PtrList

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018-2025 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -41,85 +41,35 @@ Description
using namespace Foam; using namespace Foam;
bool verbosity = true; class Scalar
// Gratuitous class inheritance
template<class T>
class BoxedType
{ {
T data_; scalar data_;
public: public:
static bool verbose; static bool verbose;
constexpr BoxedType() noexcept : data_(0) {} constexpr Scalar() noexcept : data_(0) {}
BoxedType(T val) noexcept : data_(val) {} Scalar(scalar val) noexcept : data_(val) {}
~BoxedType()
{
if (verbosity) Info<< " [delete BoxedType: " << value() << ']' << nl;
}
T value() const noexcept { return data_; }
T& value() noexcept { return data_; }
auto clone() const { return autoPtr<BoxedType<T>>::New(*this); }
};
template<class T> Ostream& operator<<(Ostream& os, const BoxedType<T>& item)
{
return (os << " -> " << item.value());
}
class Scalar : public BoxedType<scalar>
{
public:
using BoxedType<scalar>::BoxedType;
~Scalar() ~Scalar()
{ {
if (verbosity) Info<< "delete Scalar: " << value() << nl; if (verbose) Info<< "delete Scalar: " << data_ << endl;
} }
auto clone() const { return autoPtr<Scalar>::New(*this); }
};
Ostream& operator<<(Ostream& os, const Scalar& item) scalar value() const noexcept { return data_; }
{ scalar& value() noexcept { return data_; }
return (os << item.value());
}
autoPtr<Scalar> clone() const { return autoPtr<Scalar>::New(data_); }
class Integer : public BoxedType<label> friend Ostream& operator<<(Ostream& os, const Scalar& item)
{
public:
using BoxedType<label>::BoxedType;
~Integer()
{ {
if (verbosity) Info<< "delete Integer: " << value() << nl; os << item.value();
return os;
} }
auto clone() const { return autoPtr<Integer>::New(*this); }
}; };
Ostream& operator<<(Ostream& os, const Integer& item) bool Scalar::verbose = true;
{
return (os << item.value());
}
//- Permit up-casting to the base class (eg, fvMesh to polyMesh).
// Usually only for holding (const) references.
// Exercise caution with the
template<class Base, class Derived>
std::enable_if_t<std::is_base_of_v<Base, Derived>, const UPtrList<Base>&>
upcast(const UPtrList<Derived>& This)
{
return *reinterpret_cast<const UPtrList<Base>*>(&This);
}
// As per // As per
@ -136,7 +86,20 @@ Ostream& printAddr
const UPtrList<T>& list const UPtrList<T>& list
) )
{ {
return list.printAddresses(os); const label len = list.size();
// Size and start delimiter
os << nl << indent << len << nl
<< indent << token::BEGIN_LIST << incrIndent << nl;
for (label i=0; i < len; ++i)
{
os << "addr=" << Foam::name(list.get(i)) << nl;
}
// End delimiter
os << decrIndent << indent << token::END_LIST << nl;
return os;
} }
@ -213,11 +176,11 @@ Ostream& print
{ {
const label cap = list.capacity(); const label cap = list.capacity();
for (label i = len; i < cap; ++i) for (label i=len; i < cap; ++i)
{ {
const T* ptr = list.get(i); const T* ptr = list.get(i);
os << "unused " << Foam::name(ptr) << nl; os << "unused " << name(ptr) << nl;
} }
} }
@ -301,9 +264,9 @@ int main(int argc, char *argv[])
Info<< "DLPtrList: " << llist1 << endl; Info<< "DLPtrList: " << llist1 << endl;
verbosity = false; Scalar::verbose = false;
llist1.clear(); llist1.clear();
verbosity = true; Scalar::verbose = true;
} }
#endif #endif
@ -381,44 +344,6 @@ int main(int argc, char *argv[])
} }
// Test upcasting - dangerous
{
const auto& base =
*reinterpret_cast<UPtrList<BoxedType<scalar>>*>(&list1);
Info<< "list :" << list1 << nl;
Info<< "base :" << base << nl;
}
// Expect bad things to happen!!
{
const auto& base =
*reinterpret_cast<UPtrList<BoxedType<label>>*>(&list1);
Info<< "list :" << list1 << nl;
Info<< "base :" << base << nl;
}
// Test upcasting - compile safer (make as member function?)
{
// const auto& base = list1.upcast<BoxedType<scalar>>();
const auto& base = upcast<BoxedType<scalar>>(list1);
Info<< "list :" << list1 << nl;
Info<< "base :" << base << nl;
}
// Refuse to compile (good!)
#if 0
{
// const auto& base = list1.upcast<BoxedType<label>>();
const auto& base = upcast<BoxedType<label>>(list1);
Info<< "list :" << list1 << nl;
Info<< "base :" << base << nl;
}
#endif
PtrList<Scalar> list2(15); PtrList<Scalar> list2(15);
Info<< "Emplace set " << list2.size() << " values" << nl; Info<< "Emplace set " << list2.size() << " values" << nl;
forAll(list2, i) forAll(list2, i)
@ -593,7 +518,6 @@ int main(int argc, char *argv[])
print(Info, dynlist1d); print(Info, dynlist1d);
Info<< "addresses:" << nl; Info<< "addresses:" << nl;
dynlist1d.printAddresses(Info, true);
printAddr(Info, dynlist1d); printAddr(Info, dynlist1d);
PtrList<Scalar> list1d; PtrList<Scalar> list1d;

View File

@ -1,3 +1,3 @@
Test-PtrListDictionary.cxx Test-PtrListDictionary.C
EXE = $(FOAM_USER_APPBIN)/Test-PtrListDictionary EXE = $(FOAM_USER_APPBIN)/Test-PtrListDictionary

View File

@ -39,26 +39,26 @@ Description
using namespace Foam; using namespace Foam;
bool verbosity = true;
class Scalar class Scalar
{ {
scalar data_; scalar data_;
public: public:
static bool verbose;
constexpr Scalar() noexcept : data_(0) {} constexpr Scalar() noexcept : data_(0) {}
Scalar(scalar val) noexcept : data_(val) {} Scalar(scalar val) noexcept : data_(val) {}
~Scalar() ~Scalar()
{ {
if (verbosity) Info<< "delete Scalar: " << value() << nl; if (verbose) Info<< "delete Scalar: " << data_ << endl;
} }
scalar value() const noexcept { return data_; } const scalar& value() const noexcept { return data_; }
scalar& value() noexcept { return data_; } scalar& value() noexcept { return data_; }
auto clone() const { return autoPtr<Scalar>::New(*this); } autoPtr<Scalar> clone() const { return autoPtr<Scalar>::New(data_); }
friend Ostream& operator<<(Ostream& os, const Scalar& item) friend Ostream& operator<<(Ostream& os, const Scalar& item)
{ {
@ -67,6 +67,8 @@ public:
} }
}; };
bool Scalar::verbose = true;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:

View File

@ -91,6 +91,12 @@ Ostream& printView(Ostream& os, std::string_view s)
} }
Ostream& printView(Ostream& os, stdFoam::span<char> s)
{
return printView(os, s.begin(), s.end());
}
Ostream& printView(Ostream& os, const UList<char>& list) Ostream& printView(Ostream& os, const UList<char>& list)
{ {
return printView(os, list.begin(), list.end()); return printView(os, list.begin(), list.end());

View File

@ -200,7 +200,7 @@ void printTypeName()
template<class Type, bool UseTypeName = true> template<class Type, bool UseTypeName = true>
void printPstreamTraits(std::string_view name = std::string_view()) void printPstreamTraits(const std::string_view name = std::string_view())
{ {
Info<< "========" << nl; Info<< "========" << nl;
Info<< "type: "; Info<< "type: ";
@ -299,9 +299,6 @@ void printPstreamTraits(std::string_view name = std::string_view())
// Use element or component type (or byte-wise) for data type // Use element or component type (or byte-wise) for data type
using base = typename UPstream_dataType<Type>::base; using base = typename UPstream_dataType<Type>::base;
// The sizing factor is constexpr
constexpr std::streamsize count = UPstream_dataType<Type>::size(1);
Info<< " : "; Info<< " : ";
if constexpr (UseTypeName) if constexpr (UseTypeName)
{ {
@ -314,7 +311,8 @@ void printPstreamTraits(std::string_view name = std::string_view())
Info<< " cmpt-type="; Info<< " cmpt-type=";
printDataTypeId(UPstream_dataType<Type>::datatype_id); printDataTypeId(UPstream_dataType<Type>::datatype_id);
Info<< " count=" << count << nl; Info<< " count=" << UPstream_dataType<Type>::size(1);
Info<< nl;
} }
} }
@ -364,24 +362,6 @@ void print_data_opType(BinaryOp bop, std::string_view name)
} }
template<class Type>
int check_simple(std::string_view name = std::string_view())
{
// The sizing factor is constexpr
constexpr std::streamsize count = UPstream_dataType<Type>::size(1);
static_assert
(
(count == 1),
"Code does not (yet) work with aggregate types"
);
Info<< "check_simple: " << name << ": " << count << nl;
return count;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:
@ -409,8 +389,6 @@ int main()
printPstreamTraits<const float>(); printPstreamTraits<const float>();
printPstreamTraits<floatVector>(); printPstreamTraits<floatVector>();
check_simple<floatVector>("vector<float>");
printPstreamTraits<scalar>(); printPstreamTraits<scalar>();
printPstreamTraits<double>(); printPstreamTraits<double>();
printPstreamTraits<doubleVector>(); printPstreamTraits<doubleVector>();

View File

@ -1,3 +1,3 @@
Test-base64Encoding.cxx Test-base64Encoding.C
EXE = $(FOAM_USER_APPBIN)/Test-base64Encoding EXE = $(FOAM_USER_APPBIN)/Test-base64Encoding

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2025 OpenCFD Ltd. Copyright (C) 2016 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,31 +35,25 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "base64Layer.H" #include "base64Layer.H"
#include "SpanStream.H"
#include "List.H" #include "List.H"
#include "Pair.H" #include "Pair.H"
#include <sstream>
using namespace Foam; using namespace Foam;
bool test(const Pair<string>& unit) bool test(const Pair<string>& unit)
{ {
const auto& input = unit.first(); const string& input = unit.first();
const auto& expected = unit.second(); const string& expected = unit.second();
Foam::ocharstream os; std::ostringstream os;
{ base64Layer b64(os);
base64Layer b64(os); b64.write(input.data(), input.size());
b64.write(input.data(), input.size()); b64.close();
if (b64.close()) const string encoded = os.str();
{
// Extra information
// std::cerr<< "closed with pending data" << nl;
}
}
const auto encoded = os.view();
Info<< input << nl; Info<< input << nl;
@ -84,7 +78,7 @@ bool test(std::initializer_list<Pair<string>> list)
{ {
bool good = true; bool good = true;
for (const auto& t : list) for (const Pair<string>& t : list)
{ {
good = test(t) && good; good = test(t) && good;
} }
@ -97,7 +91,7 @@ bool test(const UList<Pair<string>>& list)
{ {
bool good = true; bool good = true;
for (const auto& t : list) for (const Pair<string>& t : list)
{ {
good = test(t) && good; good = test(t) && good;
} }
@ -113,7 +107,7 @@ void testMixed(std::ostream& os, const UList<Pair<string>>& list)
os << "<test-mixed>" << nl; os << "<test-mixed>" << nl;
int i=0; int i=0;
for (const auto& t : list) for (const Pair<string>& t : list)
{ {
const string& input = t.first(); const string& input = t.first();

View File

@ -1,3 +1,3 @@
Test-bitSet1.cxx Test-bitSet1.C
EXE = $(FOAM_USER_APPBIN)/Test-bitSet1 EXE = $(FOAM_USER_APPBIN)/Test-bitSet1

View File

@ -142,9 +142,6 @@ int main(int argc, char *argv[])
Info<< "got: " << bset1 << nl Info<< "got: " << bset1 << nl
<< "and: " << bset2 << nl << "and: " << bset2 << nl
<< "and: " << bset3 << nl; << "and: " << bset3 << nl;
Info<< "==";
bset3.writeList(Info, 10) << nl; // matrix-like output
} }
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2025 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -75,9 +75,9 @@ inline Ostream& info(const UList<bool>& bools)
Info<< "size=" << bools.size() Info<< "size=" << bools.size()
<< " count=" << BitOps::count(bools) << " count=" << BitOps::count(bools)
<< " !count=" << BitOps::count(bools, false) << " !count=" << BitOps::count(bools, false)
<< " all:" << bools.all() << " all:" << BitOps::all(bools)
<< " any:" << bools.any() << " any:" << BitOps::any(bools)
<< " none:" << bools.none() << nl; << " none:" << BitOps::none(bools) << nl;
return Info; return Info;
} }
@ -137,11 +137,11 @@ inline bool compare
const std::string& expected const std::string& expected
) )
{ {
const auto& store = bitset.storage(); const List<unsigned int>& store = bitset.storage();
std::string has; std::string has;
for (label blocki=0; blocki < bitset.num_blocks(); ++blocki) for (label blocki=0; blocki < bitset.nBlocks(); ++blocki)
{ {
has += toString(store[blocki]); has += toString(store[blocki]);
} }
@ -194,10 +194,8 @@ int main(int argc, char *argv[])
{ {
boolList bools = list1.values(); boolList bools = list1.values();
Info<< "===============" << nl; Info<<"===============" << nl;
Info<< "bools: " << flatOutput(bools) << nl; Info<<"bools: " << flatOutput(bools) << nl;
Info<< " ";
info(bools);
for (int i : { -10, 0, 8, 15, 32}) for (int i : { -10, 0, 8, 15, 32})
{ {
@ -240,18 +238,17 @@ int main(int argc, char *argv[])
} }
#ifdef TEST_SFINAE #ifdef TEST_SFINAE
// This should fail to compile:
{ {
labelList labels = list1.toc(); labelList labels = list1.toc();
if (labels.test(0)) if (labels.test(0))
{ {
Info<< "no" << endl; Info<<"no" << endl;
} }
List<double*> ptrs(10, nullptr); List<double*> ptrs(10, nullptr);
if (ptrs.get(0)) if (ptrs.get(0))
{ {
Info<< "no" << endl; Info<<"no" << endl;
} }
} }
#endif #endif

View File

@ -1,3 +1,3 @@
Test-boolList.cxx Test-boolList.C
EXE = $(FOAM_USER_APPBIN)/Test-boolList EXE = $(FOAM_USER_APPBIN)/Test-boolList

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020-2025 OpenCFD Ltd. Copyright (C) 2020-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -71,9 +71,9 @@ inline Ostream& info(const UList<bool>& bools)
Info<< "size=" << bools.size() Info<< "size=" << bools.size()
<< " count=" << BitOps::count(bools) << " count=" << BitOps::count(bools)
<< " !count=" << BitOps::count(bools, false) << " !count=" << BitOps::count(bools, false)
<< " all:" << bools.all() << " all:" << BitOps::all(bools)
<< " any:" << bools.any() << " any:" << BitOps::any(bools)
<< " none:" << bools.none() << nl; << " none:" << BitOps::none(bools) << nl;
return Info; return Info;
} }

View File

@ -1,3 +1,3 @@
Test-compoundToken1.cxx Test-compoundToken1.C
EXE = $(FOAM_USER_APPBIN)/Test-compoundToken1 EXE = $(FOAM_USER_APPBIN)/Test-compoundToken1

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2023-2025 OpenCFD Ltd. Copyright (C) 2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -158,8 +158,7 @@ void populateCompound(token::compound& ct, const dictionary& dict)
} }
break; break;
case token::tokenType::INTEGER_32 : case token::tokenType::LABEL :
case token::tokenType::INTEGER_64 :
{ {
fillComponents(label, cmpts, 123); fillComponents(label, cmpts, 123);
} }

View File

@ -1,3 +1,3 @@
Test-dictionary.cxx Test-dictionary.C
EXE = $(FOAM_USER_APPBIN)/Test-dictionary EXE = $(FOAM_USER_APPBIN)/Test-dictionary

View File

@ -1,3 +1,3 @@
Test-dictionary2.cxx Test-dictionary2.C
EXE = $(FOAM_USER_APPBIN)/Test-dictionary2 EXE = $(FOAM_USER_APPBIN)/Test-dictionary2

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2025 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -47,18 +47,8 @@ void entryInfo(entry* e)
{ {
if (e) if (e)
{ {
Info<< "added " Info<<"added "
<< e->keyword() << ": " << typeid(e).name(); << e->keyword() << ": " << typeid(e).name() << nl;
if (auto* stream = e->streamPtr())
{
Info<< " tokens: "; stream->tokens().writeList(Info);
}
if (auto* dict = e->dictPtr())
{
Info<< " dictionary:";
}
Info<< nl;
} }
} }
@ -210,31 +200,12 @@ int main(int argc, char *argv[])
{ {
dictionary tmpdict; dictionary tmpdict;
// Add an empty entry and populate afterwards
if (entry* e = dict1.set(word::printf("entry%d", i), nullptr))
{ {
auto& toks = e->stream(); entry* e = dict1.add
toks.resize(2); (
word::printf("entry%d", i),
toks[0] = word("value" + Foam::name(i)); string("entry" + Foam::name(i))
toks[1] = 10*i; );
entryInfo(e);
}
// Add an entry from given list of tokens
{
tokenList toks(2);
toks[0] = word("value" + Foam::name(i));
toks[1] = 10*i;
Info<< "set token0: " << Foam::name(&(toks[0])) << nl;
entry* e = dict1.set(word::printf("_entry%d", i), std::move(toks));
// verify that the address is identical (ie, move semantics worked)
auto& newToks = e->stream();
Info<< "get token0: " << Foam::name(&(newToks[0])) << nl;
entryInfo(e); entryInfo(e);
} }

View File

@ -1,3 +1,3 @@
Test-dictionaryCopy.cxx Test-dictionaryCopy.C
EXE = $(FOAM_USER_APPBIN)/Test-dictionaryCopy EXE = $(FOAM_USER_APPBIN)/Test-dictionaryCopy

View File

@ -1,3 +1,3 @@
Test-fileOperation1.cxx Test-fileOperation1.C
EXE = $(FOAM_USER_APPBIN)/Test-fileOperation1 EXE = $(FOAM_USER_APPBIN)/Test-fileOperation1

View File

@ -27,7 +27,7 @@ Application
Test-fileOperation1 Test-fileOperation1
Description Description
Test string parsing and other bits for fileOperation Test string parsing and other bits for fileOperation
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -42,8 +42,7 @@ Description
using namespace Foam; using namespace Foam;
template<class IntType> word toString(const fileOperation::procRangeType& group)
word toString(const IntRange<IntType>& group)
{ {
if (group.empty()) if (group.empty())
{ {

View File

@ -1,3 +1,3 @@
Test-instant.cxx Test-instant.C
EXE = $(FOAM_USER_APPBIN)/Test-instant EXE = $(FOAM_USER_APPBIN)/Test-instant

View File

@ -79,11 +79,8 @@ int main(int argc, char *argv[])
} }
Info<< nl << "times:" << times << nl; Info<< nl << "times:" << times << nl;
sort(times);
labelList order(Foam::sortedOrder(times));
Foam::sort(times);
Info<< "Sorted:" << times << nl; Info<< "Sorted:" << times << nl;
Info<< "order:" << flatOutput(order) << nl;
for (const scalar val : { -0.5, 5.0, 18.0, 25.0, 450.0, 480.0 }) for (const scalar val : { -0.5, 5.0, 18.0, 25.0, 450.0, 480.0 })
{ {
@ -108,29 +105,10 @@ int main(int argc, char *argv[])
files.emplace_back(10, "ten"); files.emplace_back(10, "ten");
Info<< nl << "files:" << files << nl; Info<< nl << "files:" << files << nl;
Foam::sort(files); sort(files);
Info<< "Sorted:" << files << nl; Info<< "Sorted:" << files << nl;
{
const auto& a = times[3];
scalar b = 10;
Info<< "compare (" << a << ") <= (" << b << ") => "
<< a.less_equal(10) << nl;
Info<< "compare (" << a << ") >= (" << b << ") => "
<< a.greater_equal(10) << nl;
}
{
const auto& a = times[3];
const auto& b = files[4];
Info<< "compare (" << a << ") <= (" << b << ") => "
<< (a <= b) << nl;
Info<< "compare (" << a << ") >= (" << b << ") => "
<< (a >= b) << nl;
}
Info<< "\nEnd\n" << endl; Info<< "\nEnd\n" << endl;
return 0; return 0;

View File

@ -6,7 +6,6 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,10 +24,8 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application Application
Test-memInfo
Description Description
Very basic test for memInfo values
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -36,7 +33,6 @@ Description
#include "IOstreams.H" #include "IOstreams.H"
#include "List.H" #include "List.H"
#include "vector.H" #include "vector.H"
#include "Switch.H"
using namespace Foam; using namespace Foam;
@ -45,13 +41,9 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
constexpr int n = 10000000; const int n = 10000000;
const char* const memTags = "peak/size/rss/free mem: "; const char* const memTags = "peak/size/rss/free mem: ";
Info<< nl
<< "memInfo::supported() = " << Switch(memInfo::supported()) << nl
<< nl;
memInfo mem; memInfo mem;
Info<< memTags << mem << endl; Info<< memTags << mem << endl;

View File

@ -54,12 +54,9 @@ int main(int argc, char *argv[])
"int", "int",
"Num of cores to simulate (default: 4)" "Num of cores to simulate (default: 4)"
); );
argList::addBoolOption("scatter", "Use scatter arrows");
#include "setRootCase.H" #include "setRootCase.H"
const bool optScatterGraph = args.found("scatter");
label nProcs = UPstream::nProcs(UPstream::worldComm); label nProcs = UPstream::nProcs(UPstream::worldComm);
DynamicList<int> fake_interNode_offsets; DynamicList<int> fake_interNode_offsets;
@ -131,50 +128,25 @@ int main(int argc, char *argv[])
auto& os = Info.stream(); auto& os = Info.stream();
os << "// node topology graph:" << nl; os << "// node topology graph:" << nl;
os.beginBlock("graph");
std::string arrow;
if (optScatterGraph)
{
arrow = " -> ";
os.beginBlock("digraph");
}
else
{
arrow = " -- ";
os.beginBlock("graph");
}
// Prefer left-to-right layout for large graphs // Prefer left-to-right layout for large graphs
os << indent << "rankdir=LR" << nl << nl; os << indent << "rankdir=LR" << nl;
const label numNodes = interNodeOffsets.size()-1; const label numNodes = interNodeOffsets.size()-1;
// The master
os << indent
<< "0 [label=\"master\", style=filled, fillcolor=lightgray];"
<< nl << nl;
// First level are the inter-node connections // First level are the inter-node connections
{ {
os << indent os << indent << 0 << " -- " << token::LBRACE;
<< "// inter-node: " << flatOutput(interNodeOffsets) << nl;
os << indent for (label nodei = 1; nodei < numNodes; ++nodei)
<< 0 << arrow.data() << nl;
os.beginBlock();
os << indent << "rank=same; node [shape=box];" << nl << nl;
os << indent;
for (label nodei = 0; nodei < numNodes; ++nodei)
{ {
if (nodei) os << ' '; os << ' ' << interNodeOffsets[nodei];
os << "node" << nodei;
} }
os << nl; os << token::SPACE << token::RBRACE
os.endBlock() << nl; << " // inter-node: " << flatOutput(interNodeOffsets)
<< nl;
} }
// Next level are the local-node connections // Next level are the local-node connections
@ -183,9 +155,8 @@ int main(int argc, char *argv[])
const auto firstProc = interNodeOffsets[nodei]; const auto firstProc = interNodeOffsets[nodei];
const auto lastProc = interNodeOffsets[nodei+1]; const auto lastProc = interNodeOffsets[nodei+1];
os << indent << "node" << nodei << arrow.data() os << indent << firstProc << " -- " << token::DQUOTE
<< token::DQUOTE << (firstProc+1) << ".." << (lastProc-1)
<< firstProc << ".." << (lastProc-1)
<< token::DQUOTE << nl; << token::DQUOTE << nl;
} }

View File

@ -38,7 +38,6 @@ Description
#include "SubField.H" #include "SubField.H"
#include "vector.H" #include "vector.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "UPstreamWindow.H"
using namespace Foam; using namespace Foam;

View File

@ -186,9 +186,9 @@ int main()
Info<< nl << "some interesting label limits:" << nl; Info<< nl << "some interesting label limits:" << nl;
std::cout<< "sizeof = " << sizeof(label) << nl; std::cout<< "sizeof = " << sizeof(label) << nl;
std::cout<< "min = " << pTraits<label>::min_ << nl; std::cout<< "min = " << pTraits<label>::min << nl;
std::cout<< "max = " << pTraits<label>::max_ << nl; std::cout<< "max = " << pTraits<label>::max << nl;
std::cout<< "umax = " << pTraits<uLabel>::max_ << nl; std::cout<< "umax = " << pTraits<uLabel>::max << nl;
std::cout<< "max_2 = " << pTraits<label>::max/2 << " <=> " std::cout<< "max_2 = " << pTraits<label>::max/2 << " <=> "
<< (1L << (sizeof(label)*8-2)) << nl; << (1L << (sizeof(label)*8-2)) << nl;

View File

@ -185,9 +185,9 @@ int main(int argc, char *argv[])
} }
broadcast_chunks<labelList, label>(input1); broadcast_chunks<labelList, label>(input1);
UPstream::maxCommsSize = 33; Pstream::maxCommsSize = 33;
args.readIfPresent("comms-size", UPstream::maxCommsSize); args.readIfPresent("comms-size", Pstream::maxCommsSize);
broadcast_chunks<labelList, label>(input1); broadcast_chunks<labelList, label>(input1);
@ -197,11 +197,11 @@ int main(int argc, char *argv[])
PstreamBuffers pBufs; PstreamBuffers pBufs;
labelList sendData; labelList sendData;
if (UPstream::master()) if (Pstream::master())
{ {
sendData = identity(500); sendData = identity(500);
for (const int proci : UPstream::subProcs()) for (const int proci : Pstream::subProcs())
{ {
UOPstream os(proci, pBufs); UOPstream os(proci, pBufs);
os << sendData; os << sendData;
@ -211,7 +211,7 @@ int main(int argc, char *argv[])
Info<< "call finishedSends()" << endl; Info<< "call finishedSends()" << endl;
pBufs.finishedScatters(); pBufs.finishedScatters();
if (UPstream::is_subrank()) if (!Pstream::master())
{ {
UIPstream is(UPstream::masterNo(), pBufs); UIPstream is(UPstream::masterNo(), pBufs);
is >> sendData; is >> sendData;
@ -225,11 +225,11 @@ int main(int argc, char *argv[])
labelListList recvBufs(UPstream::nProcs()); labelListList recvBufs(UPstream::nProcs());
labelList recvSizes; labelList recvSizes;
if (UPstream::master()) if (Pstream::master())
{ {
for (const int proci : UPstream::allProcs()) for (const int proci : Pstream::allProcs())
{ {
if (proci != UPstream::myProcNo()) if (proci != Pstream::myProcNo())
{ {
sendBufs[proci] = identity(500); sendBufs[proci] = identity(500);
} }
@ -253,11 +253,11 @@ int main(int argc, char *argv[])
Map<labelList> recvBufs; Map<labelList> recvBufs;
Map<label> recvSizes; Map<label> recvSizes;
if (UPstream::master()) if (Pstream::master())
{ {
for (const int proci : UPstream::allProcs()) for (const int proci : Pstream::allProcs())
{ {
if (proci != UPstream::myProcNo()) if (proci != Pstream::myProcNo())
{ {
sendBufs(proci) = identity(500); sendBufs(proci) = identity(500);
} }

View File

@ -110,25 +110,21 @@ int main(int argc, char *argv[])
<< " (self) reduced " << selfVal << nl; << " (self) reduced " << selfVal << nl;
// Identical size on all procs // Identical size on all procs
{ bitSet procUsed(nProcs);
bitSet localUsed(nProcs);
localUsed.set(myRank, ((myRank % 4) == 0));
Pout<< "local procUsed " << localUsed << nl; if ((myRank % 4) == 0)
localUsed.reduceOr(UPstream::worldComm, false); {
Pout<< "reduce procUsed " << localUsed << nl; procUsed.set(myRank);
}
// With allGather
{
bitSet procUsed
(
bitSet::allGather((myRank % 4) == 0)
);
Pout<< "allGather: " << procUsed << nl;
} }
Pout<< "local procUsed " << procUsed << nl;
reduce
(
procUsed.data(),
procUsed.size_data(),
bitOrOp<unsigned int>()
);
Pout<< "reduce procUsed " << procUsed << nl;
// Identical size on all procs // Identical size on all procs
// encode as 0:empty, 1:uniform, 2:nonuniform, 3:mixed // encode as 0:empty, 1:uniform, 2:nonuniform, 3:mixed
@ -151,26 +147,12 @@ int main(int argc, char *argv[])
} }
Pout<< "local uniform " << uniformity << nl; Pout<< "local uniform " << uniformity << nl;
// reduce with op<..>() reduce
#if 1
Foam::reduce
( (
uniformity.data(), uniformity.data(),
uniformity.num_blocks(), uniformity.size_data(),
bitOrOp<unsigned int>(), bitOrOp<unsigned int>()
UPstream::msgType(), // ignored
UPstream::worldComm
); );
#else
// Direct call to MPI_Allreduce
UPstream::mpiAllReduce
(
uniformity.data(),
uniformity.num_blocks(),
UPstream::opCodes::op_bit_or,
UPstream::worldComm
);
#endif
Pout<< "reduce uniform " << uniformity << nl; Pout<< "reduce uniform " << uniformity << nl;
} }
@ -178,8 +160,8 @@ int main(int argc, char *argv[])
{ {
Pair<label> val Pair<label> val
( (
UPstream::myProcNo(UPstream::commWorld()), Pstream::myProcNo(UPstream::commWorld()),
UPstream::myProcNo(UPstream::commWorld()) Pstream::myProcNo(UPstream::commWorld())
); );
Pair<label> worldVal = val; Pair<label> worldVal = val;

View File

@ -79,7 +79,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
if (!UPstream::parRun()) if (!Pstream::parRun())
{ {
Info<< "\nWarning: not parallel - skipping further tests\n" << endl; Info<< "\nWarning: not parallel - skipping further tests\n" << endl;
return 0; return 0;
@ -97,7 +97,7 @@ int main(int argc, char *argv[])
DynamicList<MPI_Request> recvRequests(10); DynamicList<MPI_Request> recvRequests(10);
if (UPstream::is_subrank()) if (!Pstream::master())
{ {
// Send some random length to master // Send some random length to master

View File

@ -76,7 +76,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
if (!UPstream::parRun()) if (!Pstream::parRun())
{ {
Info<< "\nWarning: not parallel - skipping further tests\n" << endl; Info<< "\nWarning: not parallel - skipping further tests\n" << endl;
return 0; return 0;
@ -96,7 +96,7 @@ int main(int argc, char *argv[])
// Map request indices to procs // Map request indices to procs
Map<label> recvFromProc(20); Map<label> recvFromProc(20);
if (UPstream::is_subrank()) if (!Pstream::master())
{ {
// Send some random length to master // Send some random length to master

View File

@ -1,3 +0,0 @@
Test-parallel-file-write1.cxx
EXE = $(FOAM_USER_APPBIN)/Test-parallel-file-write1

View File

@ -1,2 +0,0 @@
/* EXE_INC = */
/* EXE_LIBS = */

View File

@ -1,260 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2025 Mark Olesen
-------------------------------------------------------------------------------
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-parallel-file-write1
Description
Simple test of writing with MPI/IO
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "Switch.H"
#include "UPstreamFile.H"
#include "SpanStream.H"
using namespace Foam;
template<class IntType>
void zeropadded(std::ostream& os, IntType val, char fillch = '0')
{
// set fill char and width
os.setf(std::ios_base::right, std::ios_base::adjustfield);
fillch = os.fill(fillch);
os.width(std::numeric_limits<IntType>::digits10+1);
os << val;
// restore fill char
os.fill(fillch);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::noCheckProcessorDirectories();
argList::addVerboseOption();
argList::addBoolOption("master-footer", "Write footer from master");
#include "setRootCase.H"
if (!UPstream::parRun())
{
Info<< "###############" << nl
<< "Not running in parallel. Stopping now" << nl
<< "###############" << endl;
return 1;
}
const bool optMasterFooter = args.found("master-footer");
Info<< nl << "Write master-footer: " << Switch::name(optMasterFooter)
<< nl << nl;
Info<< "Create time (without controlDict)\n" << endl;
auto runTimePtr = Time::New();
auto& runTime = runTimePtr();
const auto myProc = UPstream::myProcNo();
const auto nProcs = UPstream::nProcs();
// Some content
OCharStream charset;
for (int i = 0; i < 10; ++i)
{
charset<< char('A' + i);
}
// Header/footer buffers - these can be separate or bundled into
// the first/last blocks
OCharStream header;
OCharStream footer;
// Content buffer
OCharStream os(IOstream::BINARY);
{
const auto v = charset.view();
os << nl;
os.beginBlock(word("rank" + Foam::name(myProc)));
for (int repeat = 0; repeat <= myProc; ++repeat)
{
os << indent << word("entry" + Foam::name(repeat))
<< ' ' << word("List<char>");
// os << nl;
os << ' ';
os << label(v.size());
os.write(v.data(), v.size());
// os << nl;
os.endEntry();
}
os.endBlock();
}
// Bundle the footer into the last block
if (!optMasterFooter && (myProc == nProcs-1))
{
IOobject::writeEndDivider(os);
}
// All content now exists - commit to disk
const std::string_view blockData(os.view());
const int64_t blockSize(blockData.size());
// Collect sizes
const List<int64_t> sizes
(
UPstream::allGatherValues(blockSize, UPstream::worldComm)
);
// Format header with size information
if (UPstream::master())
{
header
<< "Simple MPI/IO test with " << nProcs << " ranks" << nl << nl;
ocharstream labelbuf;
labelbuf.reserve_exact(32);
// Position before writing a label
auto labelBegin = header.tellp();
header.beginBlock("meta");
{
header << indent << word("data.start") << ' ';
labelBegin = header.tellp();
// Add the start value (placeholder)
{
labelbuf.rewind();
zeropadded(labelbuf, label(0));
header.append(labelbuf.view());
}
header.endEntry();
header << indent << word("data.sizes") << nl;
sizes.writeList(header); // flatOutput
header.endEntry();
}
header.endBlock();
header << nl;
IOobject::writeDivider(header);
// Now update with the correct size
{
labelbuf.rewind();
zeropadded(labelbuf, label(header.view().size()));
header.overwrite(labelBegin, labelbuf.view());
}
// Bundled the footer into the last block or from master?
if (optMasterFooter)
{
IOobject::writeEndDivider(footer);
}
}
// With additional header/footer
int64_t headerSize(header.view().size());
int64_t footerSize(footer.view().size());
Pstream::broadcast(headerSize);
if (optMasterFooter)
{
Pstream::broadcast(footerSize);
}
int64_t totalSize(headerSize);
for (int i = 0; i < myProc; ++i)
{
totalSize += sizes[i];
}
const int64_t blockOffset(totalSize);
for (int i = myProc; i < nProcs; ++i)
{
totalSize += sizes[i];
}
const int64_t footerOffset(totalSize);
totalSize += footerSize;
Pout<< "write size=" << label(blockSize)
<< " at=" << label(blockOffset) << " total=" << label(totalSize) << nl;
{
UPstream::File file;
bool ok = file.open_write
(
UPstream::worldComm,
runTime.globalPath()/"mpiio-test1.txt",
IOstreamOption::ATOMIC
);
if (ok)
{
Info<< "writing: " << file.name() << nl;
if (UPstream::master())
{
// A no-op for empty buffer
ok = file.write_at(0, header.view());
}
ok = file.write_at_all(blockOffset, blockData);
if (UPstream::master())
{
// A no-op for empty buffer
ok = file.write_at(footerOffset, footer.view());
}
}
file.set_size(totalSize);
file.close();
}
Info<< "\nEnd\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -52,7 +52,7 @@ int main(int argc, char *argv[])
const bool optNonBlocking = args.found("non-blocking"); const bool optNonBlocking = args.found("non-blocking");
if (!UPstream::parRun()) if (!Pstream::parRun())
{ {
Info<< "\nWarning: not parallel - skipping further tests\n" << endl; Info<< "\nWarning: not parallel - skipping further tests\n" << endl;
return 0; return 0;
@ -73,7 +73,7 @@ int main(int argc, char *argv[])
DynamicList<UPstream::Request> sendRequests(10); DynamicList<UPstream::Request> sendRequests(10);
DynamicList<UPstream::Request> recvRequests(10); DynamicList<UPstream::Request> recvRequests(10);
if (UPstream::is_subrank()) if (!Pstream::master())
{ {
// Send some random length to master // Send some random length to master

View File

@ -1,3 +1,3 @@
Test-SHA1.cxx Test-SHA1.C
EXE = $(FOAM_USER_APPBIN)/Test-SHA1 EXE = $(FOAM_USER_APPBIN)/Test-SHA1

View File

@ -64,10 +64,6 @@ int main(int argc, char * argv[])
osha<< str; osha<< str;
Info<< osha.digest() << " : output << to empty" << nl; Info<< osha.digest() << " : output << to empty" << nl;
osha.reset();
osha<< std::string_view(str);
Info<< osha.digest() << " : << string_view [ not quite right !]" << nl;
sha.clear(); sha.clear();
sha.append(str); sha.append(str);
shaDig = sha; shaDig = sha;

View File

@ -296,7 +296,7 @@ int main(int argc, char *argv[])
( (
strings, strings,
order, order,
stringOps::natural_sort::list_less(strings) stringOps::natural_sort::less<string>(strings)
); );
Info<< "natural sortedOrder: " << flatOutput(order) << endl; Info<< "natural sortedOrder: " << flatOutput(order) << endl;
} }
@ -321,7 +321,7 @@ int main(int argc, char *argv[])
/// sortable = hashed.toc(); /// sortable = hashed.toc();
/// sortable.sort /// sortable.sort
/// ( /// (
/// stringOps::natural_sort::list_less(sortable) /// stringOps::natural_sort::less<string>(sortable)
/// ); /// );
/// Info<< nl << "natural:" << sortable << endl; /// Info<< nl << "natural:" << sortable << endl;
@ -329,7 +329,7 @@ int main(int argc, char *argv[])
/// sortable = hashed.toc(); /// sortable = hashed.toc();
/// sortable.sort /// sortable.sort
/// ( /// (
/// stringOps::natural_sort::list_greater(sortable) /// stringOps::natural_sort::greater<string>(sortable)
/// ); /// );
/// Info<< nl << "natural:" << sortable << endl; /// Info<< nl << "natural:" << sortable << endl;
} }

View File

@ -42,7 +42,7 @@ using namespace Foam;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
stringList strings stringList strings
({ {
"hello", "hello",
"heello", "heello",
"heeello", "heeello",
@ -52,7 +52,7 @@ int main(int argc, char *argv[])
"okey", "okey",
"okkey", "okkey",
"okkkey", "okkkey",
}); };
labelList matches; labelList matches;
wordRes matcher1(ICharStream("( okey \"[hy]e+.*\" )")()); wordRes matcher1(ICharStream("( okey \"[hy]e+.*\" )")());
@ -72,14 +72,12 @@ int main(int argc, char *argv[])
} }
} }
{ Info<< "Match found using ListOps = "
regExp matcher(".*ee.*"); << ListOps::found(strings, regExp(".*ee.*")) << nl;
Info<< "First index = "
<< ListOps::find(strings, regExp(".*ee.*")) << nl;
Info<< "Match found using ListOps = "
<< ListOps::found_if(strings, matcher) << nl
<< "First index = "
<< ListOps::find_if(strings, matcher) << nl;
}
Info<< endl; Info<< endl;
matches = findMatchingStrings(matcher1, strings); matches = findMatchingStrings(matcher1, strings);

View File

@ -59,6 +59,11 @@ int main(int argc, char *argv[])
<< " type: " << typeid(cstr).name() << " len:" << len << nl; << " type: " << typeid(cstr).name() << " len:" << len << nl;
Info<< " view: " << std::string_view(cstr) << nl; Info<< " view: " << std::string_view(cstr) << nl;
Info<< " span: "
<< stdFoam::span<const char>(cstr, len) << nl;
Info<< " span: "
<< stdFoam::span<char>(const_cast<char*>(cstr), len) << nl;
} }
} }

View File

@ -1,4 +1,4 @@
mydebugSurfaceWriter.cxx mydebugSurfaceWriter.C
Test-surface-sampling.cxx Test-surface-sampling.C
EXE = $(FOAM_USER_APPBIN)/Test-surface-sampling EXE = $(FOAM_USER_APPBIN)/Test-surface-sampling

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2022-2025 OpenCFD Ltd. Copyright (C) 2022-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -83,10 +83,12 @@ template<> struct narrowType<SymmTensor<double>>
typedef SymmTensor<float> type; typedef SymmTensor<float> type;
}; };
template<> struct narrowType<Tensor<double>> // FIXME: Not sure why this one seems to be broken...
{ //
typedef Tensor<float> type; // template<> struct narrowType<Tensor<double>>
}; // {
// typedef Tensor<float> type;
// };
} // End namespace Foam } // End namespace Foam
@ -102,18 +104,12 @@ Foam::surfaceWriters::mydebugWriter::mergeField
{ {
addProfiling(merge, "debugWriter::merge-field"); addProfiling(merge, "debugWriter::merge-field");
// Identical to surfaceWriter::mergeField() // This is largely identical to surfaceWriter::mergeField()
// but with narrowing for communication // but with narrowing for communication
if (narrowTransfer_ && parallel_ && UPstream::parRun())
if constexpr (std::is_same_v<Tensor<double>, Type>)
{
// Cannot narrow tensor. Does not compile since MatrixSpace
// does not (yet) allow assigments from different Cmpt types.
}
else if (narrowTransfer_ && parallel_ && UPstream::parRun())
{ {
// The narrowed type // The narrowed type
using narrowedType = typename narrowType<Type>::type; typedef typename narrowType<Type>::type narrowedType;
// Ensure geometry is also merged // Ensure geometry is also merged
merge(); merge();
@ -134,29 +130,14 @@ Foam::surfaceWriters::mydebugWriter::mergeField
ConstPrecisionAdaptor<narrowedType, Type> input(fld); ConstPrecisionAdaptor<narrowedType, Type> input(fld);
PrecisionAdaptor<narrowedType, Type> output(allFld); PrecisionAdaptor<narrowedType, Type> output(allFld);
if (gatherv_) globIndex.gather
{ (
globIndex.mpiGather input.cref(), // fld,
( output.ref(), // allFld,
input.cref(), // fld UPstream::msgType(),
output.ref(), // allFld commType_,
UPstream::worldComm, UPstream::worldComm
// For fallback: );
commType_,
UPstream::msgType()
);
}
else
{
globIndex.gather
(
input.cref(), // fld
output.ref(), // allFld
UPstream::msgType(),
commType_,
UPstream::worldComm
);
}
// Commit adapted content changes // Commit adapted content changes
input.commit(); input.commit();
@ -212,19 +193,8 @@ Foam::surfaceWriters::mydebugWriter::mydebugWriter
{ {
Info<< "Using debug surface writer (" Info<< "Using debug surface writer ("
<< (this->isPointData() ? "point" : "face") << " data):" << (this->isPointData() ? "point" : "face") << " data):"
<< " commsType="; << " commsType=" << UPstream::commsTypeNames[commType_]
<< " merge=" << Switch::name(enableMerge_)
if (UPstream::parRun())
{
if (gatherv_) Info<< "gatherv+";
Info<< UPstream::commsTypeNames[commType_];
}
else
{
Info<< "serial";
}
Info<< " merge=" << Switch::name(enableMerge_)
<< " write=" << Switch::name(enableWrite_) << " write=" << Switch::name(enableWrite_)
<< " narrow=" << Switch::name(narrowTransfer_) << " narrow=" << Switch::name(narrowTransfer_)
<< endl; << endl;

View File

@ -43,29 +43,6 @@ Description
using namespace Foam; using namespace Foam;
const char yesno[2] = { 'n', 'y' };
void printIntegralTest(const token& tok)
{
Info<< "Test: " << tok.info() << nl
<< " is int32 = " << yesno[tok.is_int32()]
<< ", int64 = " << yesno[tok.is_int64()]
<< ", uint32 = " << yesno[tok.is_uint32()]
<< ", uint64 = " << yesno[tok.is_uint64()]
<< nl;
}
void printFloatTest(const token& tok)
{
Info<< "Test: " << tok.info() << nl
<< " is float = " << yesno[tok.isFloat()]
<< ", double = " << yesno[tok.isDouble()]
<< ", number = " << yesno[tok.isNumber()]
<< nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:
@ -79,23 +56,6 @@ int main(int argc, char *argv[])
token tok1; token tok1;
Info<< "default construct: " << tok1.info() << endl; Info<< "default construct: " << tok1.info() << endl;
tok1 = label(100);
Info<< "assign label: " << tok1.info() << endl;
tok1 = int64_t(100);
Info<< "assign int64: " << tok1.info() << endl;
tok1 = int32_t(100);
Info<< "assign int32: " << tok1.info() << endl;
{
tok1.int64Token(int64_t(INT32_MIN)-1);
Info<< "set int64Token: " << tok1.info() << endl;
printIntegralTest(tok1);
printFloatTest(tok1);
}
tok1 = double(3.14159); tok1 = double(3.14159);
Info<< "assign double: " << tok1.info() << endl; Info<< "assign double: " << tok1.info() << endl;

View File

@ -33,7 +33,6 @@ Description
#include "vectorField.H" #include "vectorField.H"
#include "boolVector.H" #include "boolVector.H"
#include "complexVector.H"
#include "labelVector.H" #include "labelVector.H"
#include "IOstreams.H" #include "IOstreams.H"
#include "FixedList.H" #include "FixedList.H"
@ -165,30 +164,6 @@ void testTranscribe(Type& input)
} }
// Test of adding to vectors, possible of dissimilar types
template<class Target, class Source>
void testAdding(const Target& a, const Source& b)
{
typedef typename Target::cmptType cmptType1;
typedef typename Source::cmptType cmptType2;
Info<< " "
<< pTraits<Target>::typeName << " += "
<< pTraits<Source>::typeName << " : ";
if constexpr (std::is_convertible_v<cmptType2, cmptType1>)
{
Target res(a);
res += b;
Info<< a << " += " << b << " == " << res << nl;
}
else
{
Info<< "unsupported" << nl;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program: // Main program:
@ -198,37 +173,6 @@ int main(int argc, char *argv[])
Info<<"normalised: " << vector::uniform(VSMALL).normalise() << nl; Info<<"normalised: " << vector::uniform(VSMALL).normalise() << nl;
Info<<"normalised: " << vector::uniform(ROOTVSMALL).normalise() << nl; Info<<"normalised: " << vector::uniform(ROOTVSMALL).normalise() << nl;
{
complexVector cvec(complex(1), complex(0), complex(0));
doubleVector dvec(1, 0, 0);
floatVector fvec(1, 0, 0);
labelVector lvec(1, 0, 0);
Info<< nl << "additions:" << nl;
testAdding(cvec, cvec);
testAdding(cvec, dvec);
testAdding(cvec, fvec);
testAdding(cvec, lvec);
testAdding(dvec, cvec);
testAdding(dvec, dvec);
testAdding(dvec, fvec);
testAdding(dvec, lvec);
testAdding(fvec, cvec);
testAdding(fvec, dvec);
testAdding(fvec, fvec);
testAdding(fvec, lvec);
testAdding(lvec, cvec);
testAdding(lvec, dvec);
testAdding(lvec, fvec);
testAdding(lvec, lvec);
Info<< nl;
}
{ {
vector vec1(0.5, 0.5, 0.5); vector vec1(0.5, 0.5, 0.5);
vector vec2(0.5, 0.51, -0.5); vector vec2(0.5, 0.51, -0.5);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2025 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -857,8 +857,16 @@ int main(int argc, char *argv[])
if if
( (
Foam::fieldTypes::is_volume(obj.headerClassName()) obj.isHeaderClass<volScalarField>()
|| Foam::fieldTypes::is_surface(obj.headerClassName()) || obj.isHeaderClass<volVectorField>()
|| obj.isHeaderClass<volSphericalTensorField>()
|| obj.isHeaderClass<volTensorField>()
|| obj.isHeaderClass<volSymmTensorField>()
|| obj.isHeaderClass<surfaceScalarField>()
|| obj.isHeaderClass<surfaceVectorField>()
|| obj.isHeaderClass<surfaceSphericalTensorField>()
|| obj.isHeaderClass<surfaceSymmTensorField>()
|| obj.isHeaderClass<surfaceTensorField>()
) )
{ {
objects.add(objPtr); objects.add(objPtr);

View File

@ -86,7 +86,7 @@ void constructVolFields(fvMesh& mesh, const vtkUnstructuredReader& reader)
); );
auto& fld = tfld.ref(); auto& fld = tfld.ref();
fld.instance() = mesh.time().timeName(); fld.instance() = mesh.time().timeName();
fld.writeOpt(IOobject::AUTO_WRITE); fld.writeOpt() = IOobject::AUTO_WRITE;
// Fill cell values // Fill cell values
fld.internalFieldRef().field() = fld.internalFieldRef().field() =

View File

@ -152,7 +152,7 @@ Description
if if
( (
!cleanupPatches.contains(patchName) !cleanupPatches.found(patchName)
|| returnReduceOr(oldPatches[patchi].size()) || returnReduceOr(oldPatches[patchi].size())
) )
{ {
@ -188,9 +188,8 @@ Description
// Cleanup empty merged point zones // Cleanup empty merged point zones
{ {
auto& zmesh = mesh.pointZones(); PtrList<pointZone>& zones = mesh.pointZones();
zmesh.clearAddressing(); mesh.pointZones().clearAddressing();
PtrList<pointZone>& zones = zmesh;
wordHashSet removedZones(2*zones.size()); wordHashSet removedZones(2*zones.size());
@ -199,11 +198,12 @@ Description
{ {
if if
( (
!cleanupPointZones.contains(zones[zonei].name()) !cleanupPointZones.found(zones[zonei].name())
|| returnReduceOr(zones[zonei].size()) || returnReduceOr(zones[zonei].size())
) )
{ {
zones.set(nZones, zones.release(zonei)); zones.set(nZones, zones.release(zonei));
zones[nZones].index() = nZones; // re-index
++nZones; ++nZones;
} }
else else
@ -212,7 +212,6 @@ Description
} }
} }
zones.resize(nZones); zones.resize(nZones);
zmesh.reindex();
if (removedZones.size()) if (removedZones.size())
{ {
@ -224,9 +223,8 @@ Description
// Cleanup empty merged face zones // Cleanup empty merged face zones
{ {
auto& zmesh = mesh.faceZones(); PtrList<faceZone>& zones = mesh.faceZones();
zmesh.clearAddressing(); mesh.faceZones().clearAddressing();
PtrList<faceZone>& zones = zmesh;
wordHashSet removedZones(2*zones.size()); wordHashSet removedZones(2*zones.size());
@ -235,11 +233,12 @@ Description
{ {
if if
( (
!cleanupFaceZones.contains(zones[zonei].name()) !cleanupFaceZones.found(zones[zonei].name())
|| returnReduceOr(zones[zonei].size()) || returnReduceOr(zones[zonei].size())
) )
{ {
zones.set(nZones, zones.release(zonei)); zones.set(nZones, zones.release(zonei));
zones[nZones].index() = nZones; // re-index
++nZones; ++nZones;
} }
else else
@ -248,7 +247,6 @@ Description
} }
} }
zones.resize(nZones); zones.resize(nZones);
zmesh.reindex();
if (removedZones.size()) if (removedZones.size())
{ {

View File

@ -473,6 +473,16 @@ int main(int argc, char *argv[])
); );
// Precalculate mesh edges for pp.edges.
const labelList meshEdges
(
extrudePatch.meshEdges
(
mesh.edges(),
mesh.pointEdges()
)
);
// Global face indices engine // Global face indices engine
const globalIndex globalFaces(mesh.nFaces()); const globalIndex globalFaces(mesh.nFaces());

View File

@ -13,40 +13,28 @@ const Enum<writeChecksFormatType> writeChecksFormatTypeNames
writeChecksFormatType writeChecksFormat(writeChecksFormatType::none); writeChecksFormatType writeChecksFormat(writeChecksFormatType::none);
auto writeMeshChecks = [&](const fvMesh& mesh, const writeChecksFormatType fmt) auto writeMeshChecks = [](const fvMesh& mesh, const writeChecksFormatType fmt)
{ {
// Early exit if 'none' option is set
if (fmt == writeChecksFormatType::none)
{
return;
}
if (UPstream::master()) if (UPstream::master())
{ {
fileName path(mesh.time().globalPath()/"checkMesh");
if (mesh.name() != polyMesh::defaultRegion)
{
path += "_" + mesh.name();
}
OFstream os(path.ext(writeChecksFormatTypeNames[fmt]));
Info<< "Writing mesh data to " << os.name() << nl << endl;
switch (fmt) switch (fmt)
{ {
case writeChecksFormatType::dictionary: case writeChecksFormatType::dictionary:
{ {
OFstream os(mesh.time().globalPath()/"checkMesh.dict");
IOdictionary data IOdictionary data
( (
IOobject IOobject
( (
os.name(), mesh.time().globalPath()/"checkMesh.dict",
mesh, mesh,
IOobject::NO_READ IOobject::NO_READ
) )
); );
Info<< "Writing mesh data to " << os.name() << nl << endl;
data.writeHeader(os); data.writeHeader(os);
mesh.data().meshDict().write(os, false); mesh.data().meshDict().write(os, false);
@ -57,9 +45,13 @@ auto writeMeshChecks = [&](const fvMesh& mesh, const writeChecksFormatType fmt)
} }
case writeChecksFormatType::JSON: case writeChecksFormatType::JSON:
{ {
JSONformatter json(os); OFstream os(mesh.time().globalPath()/"checkMesh.json");
json.writeDict(mesh.data().meshDict());
Info<< "Writing mesh data to " << os.name() << nl << endl;
JSONformatter json(os);
json.writeDict(mesh.data().meshDict());
break; break;
} }
default: default:

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2025 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -42,14 +42,14 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "cyclicPolyPatch.H"
#include "syncTools.H"
#include "argList.H" #include "argList.H"
#include "Time.H" #include "Time.H"
#include "OFstream.H" #include "OFstream.H"
#include "meshTools.H" #include "meshTools.H"
#include "faceSet.H" #include "faceSet.H"
#include "IOPtrList.H" #include "IOPtrList.H"
#include "cyclicPolyPatch.H"
#include "syncTools.H"
#include "polyTopoChange.H" #include "polyTopoChange.H"
#include "polyModifyFace.H" #include "polyModifyFace.H"
#include "polyAddFace.H" #include "polyAddFace.H"
@ -942,9 +942,6 @@ int main(int argc, char *argv[])
} }
// Maintain list of added patches so we exclude them from filtering
// later on
List<DynamicList<word>> allAddedPatches(meshes.size());
// Loop over all regions // Loop over all regions
@ -1039,7 +1036,6 @@ int main(int argc, char *argv[])
fvPatchFieldBase::calculatedType(), fvPatchFieldBase::calculatedType(),
true true
); );
allAddedPatches[meshi].append(ppPtr->name());
} }
} }
} }
@ -1091,7 +1087,6 @@ int main(int argc, char *argv[])
fvPatchFieldBase::calculatedType(), fvPatchFieldBase::calculatedType(),
true true
); );
allAddedPatches[meshi].append(ppPtr->name());
} }
} }
} }
@ -1121,7 +1116,6 @@ int main(int argc, char *argv[])
fvPatchFieldBase::calculatedType(), fvPatchFieldBase::calculatedType(),
true true
); );
allAddedPatches[meshi].append(ppPtr->name());
} }
} }
} }
@ -1459,7 +1453,7 @@ int main(int argc, char *argv[])
Info<< "Removing patches with no faces in them." << nl << endl; Info<< "Removing patches with no faces in them." << nl << endl;
const wordList oldPatchNames(mesh.boundaryMesh().names()); const wordList oldPatchNames(mesh.boundaryMesh().names());
const wordList oldPatchTypes(mesh.boundaryMesh().types()); const wordList oldPatchTypes(mesh.boundaryMesh().types());
fvMeshTools::removeEmptyPatches(mesh, allAddedPatches[meshi], true); fvMeshTools::removeEmptyPatches(mesh, true);
forAll(oldPatchNames, patchi) forAll(oldPatchNames, patchi)
{ {
const word& pName = oldPatchNames[patchi]; const word& pName = oldPatchNames[patchi];
@ -1482,11 +1476,14 @@ int main(int argc, char *argv[])
{ {
++runTime; ++runTime;
} }
else
forAll(meshes, meshi)
{ {
fvMesh& mesh = meshes[meshi]; forAll(meshes, meshi)
mesh.setInstance(overwrite ? oldInstances[meshi] : runTime.timeName()); {
fvMesh& mesh = meshes[meshi];
mesh.setInstance(oldInstances[meshi]);
}
} }
// More precision (for points data) // More precision (for points data)
@ -1496,21 +1493,6 @@ int main(int argc, char *argv[])
forAll(meshes, meshi) forAll(meshes, meshi)
{ {
fvMesh& mesh = meshes[meshi]; fvMesh& mesh = meshes[meshi];
// Override bcs with explicitly provided info. Done late so there
// are already patch faces
forAll(patchInfoDicts[meshi], sourcei)
{
const dictionary& patchDict = patchInfoDicts[meshi][sourcei];
const word& patchName = patchNames[meshi][sourcei];
const label patchID = mesh.boundary().findPatchID(patchName);
if (patchID != -1 && patchDict.found("patchFields"))
{
const dictionary& pfd = patchDict.subDict("patchFields");
fvMeshTools::setPatchFields(mesh, patchID, pfd);
}
}
Info<< "\n\nWriting repatched mesh " << mesh.name() Info<< "\n\nWriting repatched mesh " << mesh.name()
<< " to " << runTime.timeName() << nl << endl; << " to " << runTime.timeName() << nl << endl;
mesh.clearOut(); // remove meshPhi mesh.clearOut(); // remove meshPhi

View File

@ -251,31 +251,18 @@ const dictionary& lookupScopedDict
return dict; return dict;
} }
const auto finder = dict.csearchScoped(subDictName, keyType::LITERAL); const entry* eptr = dict.findScoped(subDictName, keyType::LITERAL);
if (!finder.good() || !finder.isDict()) if (!eptr || !eptr->isDict())
{ {
// Not found or not a dictionary
FatalIOErrorInFunction(dict) FatalIOErrorInFunction(dict)
<< '"' << subDictName << '"' << nl; << "'" << subDictName << "' not found in dictionary "
<< dict.name() << " or is not a dictionary" << nl
if (!finder.good()) << "Known entries are " << dict.keys()
{
FatalIOError << "Not found in dictionary";
}
else
{
FatalIOError << "Not a dictionary entry";
}
FatalIOError
<< nl << nl
<< "Known entries of " << finder.context().name() << " : " << nl
<< finder.context().keys()
<< exit(FatalIOError); << exit(FatalIOError);
} }
return finder.dict(); return eptr->dict();
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2025 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -383,10 +383,29 @@ int main(int argc, char *argv[])
if if
( (
Foam::fieldTypes::is_volume(io.headerClassName()) io.isHeaderClass<volScalarField>()
|| Foam::fieldTypes::is_internal(io.headerClassName()) || io.isHeaderClass<volVectorField>()
|| Foam::fieldTypes::is_surface(io.headerClassName()) || io.isHeaderClass<volSphericalTensorField>()
|| Foam::fieldTypes::is_point(io.headerClassName()) || io.isHeaderClass<volSymmTensorField>()
|| io.isHeaderClass<volTensorField>()
|| io.isHeaderClass<surfaceScalarField>()
|| io.isHeaderClass<surfaceVectorField>()
|| io.isHeaderClass<surfaceSphericalTensorField>()
|| io.isHeaderClass<surfaceSymmTensorField>()
|| io.isHeaderClass<surfaceTensorField>()
|| io.isHeaderClass<pointScalarField>()
|| io.isHeaderClass<pointVectorField>()
|| io.isHeaderClass<pointSphericalTensorField>()
|| io.isHeaderClass<pointSymmTensorField>()
|| io.isHeaderClass<pointTensorField>()
|| io.isHeaderClass<volScalarField::Internal>()
|| io.isHeaderClass<volVectorField::Internal>()
|| io.isHeaderClass<volSphericalTensorField::Internal>()
|| io.isHeaderClass<volSymmTensorField::Internal>()
|| io.isHeaderClass<volTensorField::Internal>()
) )
{ {
Info<< " Reading " << io.headerClassName() Info<< " Reading " << io.headerClassName()

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2025 OpenCFD Ltd. Copyright (C) 2017-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,8 +30,7 @@ Group
grpPostProcessingUtilities grpPostProcessingUtilities
Description Description
List volume regions from constant/regionProperties List regions from constant/regionProperties.
or area regions from constant/finite-area/regionProperties
Usage Usage
\b foamListRegions [OPTION] \b foamListRegions [OPTION]
@ -46,9 +45,6 @@ Note
#include "Time.H" #include "Time.H"
#include "regionProperties.H" #include "regionProperties.H"
// Same as faMesh::prefix() but without additional linkage
constexpr const char* const faMeshPrefix = "finite-area";
using namespace Foam; using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -57,8 +53,7 @@ int main(int argc, char *argv[])
{ {
argList::addNote argList::addNote
( (
"List volume regions from constant/regionProperties,\n" "List regions from constant/regionProperties"
"or area regions from constant/finite-area/regionProperties"
); );
argList::noBanner(); argList::noBanner();
@ -67,55 +62,12 @@ int main(int argc, char *argv[])
argList::noFunctionObjects(); // Never use function objects argList::noFunctionObjects(); // Never use function objects
// No profiling since there is no time loop // No profiling since there is no time loop
argList::addBoolOption
(
"finite-area",
"List constant/finite-area/regionProperties (if available)"
);
argList::addBoolOption
(
"optional",
"A missing regionProperties is not treated as an error"
);
argList::addDryRunOption
(
"Make reading optional and add verbosity"
);
argList::addVerboseOption("Additional verbosity");
// Arguments are optional (non-mandatory) // Arguments are optional (non-mandatory)
argList::noMandatoryArgs(); argList::noMandatoryArgs();
argList::addArgument("regionType ... regionType"); argList::addArgument("regionType ... regionType");
#include "setRootCase.H" #include "setRootCase.H"
const bool dryRun = args.dryRun();
int optVerbose = args.verbose();
if (dryRun && !optVerbose)
{
++optVerbose;
}
// File is optional, not an error
const bool isOptional = args.found("optional");
// Use finite-area regions
const bool doFiniteArea = args.found("finite-area");
// The number of optional region filters to apply
const label nFilters = (args.size()-1);
IOobjectOption::readOption readOpt(IOobjectOption::MUST_READ);
if (dryRun || isOptional || doFiniteArea)
{
// The finite-area regionProperties are also considered optional
readOpt = IOobjectOption::READ_IF_PRESENT;
}
// Silent version of "createTime.H", without libraries // Silent version of "createTime.H", without libraries
Time runTime Time runTime
( (
@ -125,74 +77,30 @@ int main(int argc, char *argv[])
false // no enableLibs false // no enableLibs
); );
regionProperties regionProps; regionProperties rp(runTime);
if (doFiniteArea)
{
regionProps = regionProperties(runTime, faMeshPrefix, readOpt);
}
else
{
regionProps = regionProperties(runTime, readOpt);
}
// Some reporting...
if (regionProps.empty())
{
if (doFiniteArea)
{
InfoErr<< "No finite-area region types" << nl;
}
else if (isOptional)
{
InfoErr<< "No region types" << nl;
}
}
else if (optVerbose)
{
InfoErr << "Have " << regionProps.size();
if (doFiniteArea)
{
InfoErr<< " finite-area";
}
InfoErr
<< " region types, "
<< regionProps.count() << " regions" << nl << nl;
}
// We now handle checking args and general sanity etc. // We now handle checking args and general sanity etc.
wordList regionTypes;
DynamicList<word> regionTypes; if (args.size() > 1)
if (isOptional && regionProps.empty())
{ {
// Nothing to do... regionTypes.resize(args.size()-1);
}
else if (nFilters > 0)
{
// Apply region filters
regionTypes.reserve_exact // No duplicates
(
Foam::min(nFilters, regionProps.size())
);
// No duplicates, and no duplicate warnings
wordHashSet uniq; wordHashSet uniq;
label nTypes = 0;
for (label argi = 1; argi < args.size(); ++argi) for (label argi = 1; argi < args.size(); ++argi)
{ {
word regType(args[argi]); regionTypes[nTypes] = args[argi];
const word& regType = regionTypes[nTypes];
if (uniq.insert(regType)) if (uniq.insert(regType))
{ {
if (regionProps.contains(regType)) if (rp.found(regType))
{ {
if (!regionTypes.contains(regType)) ++nTypes;
{
regionTypes.push_back(std::move(regType));
}
} }
else else
{ {
@ -200,22 +108,22 @@ int main(int argc, char *argv[])
} }
} }
} }
regionTypes.resize(nTypes);
} }
else else
{ {
// Take all regions regionTypes = rp.sortedToc();
regionTypes = regionProps.sortedToc();
} }
for (const word& regionType : regionTypes) for (const word& regionType : regionTypes)
{ {
if (const auto iter = regionProps.cfind(regionType); iter.good()) const wordList& regionNames = rp[regionType];
for (const word& regionName : regionNames)
{ {
for (const word& regionName : iter.val()) Info<< regionName << nl;
{
Info<< regionName << nl;
}
} }
} }

View File

@ -418,14 +418,8 @@ int main(int argc, char *argv[])
// Allow explicit -constant, have zero from time range // Allow explicit -constant, have zero from time range
timeSelector::addOptions(true, false); // constant(true), zero(false) timeSelector::addOptions(true, false); // constant(true), zero(false)
// Prevent volume BCs from triggering finite-area
regionModels::allowFaModels(false);
#include "setRootCase.H" #include "setRootCase.H"
// ------------------------------------------------------------------------
// Configuration
const bool writeCellDist = args.found("cellDist"); const bool writeCellDist = args.found("cellDist");
// Most of these are ignored for dry-run (not triggered anywhere) // Most of these are ignored for dry-run (not triggered anywhere)

Some files were not shown because too many files have changed in this diff Show More