Compare commits
10 Commits
wip-meson-
...
feature-st
| Author | SHA1 | Date | |
|---|---|---|---|
| 798a9dd9b1 | |||
| fe1e056196 | |||
| 9d291ab4cc | |||
| 0e11f47f74 | |||
| 698e05eeb3 | |||
| 2395e493d1 | |||
| 12916cd7a3 | |||
| b66369fb37 | |||
| b236e1493c | |||
| a6744d0814 |
@ -183,9 +183,7 @@ int main(int argc, char *argv[])
|
||||
Pout<<"recv: " << flatOutput(recv) << endl;
|
||||
}
|
||||
|
||||
// MPI barrier
|
||||
bool barrier = true;
|
||||
Pstream::broadcast(barrier);
|
||||
UPstream::barrier(UPstream::worldComm);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -204,7 +204,7 @@ int main(int argc, char *argv[])
|
||||
labelPair inOut;
|
||||
pointField allCcs(globalNumbering.gather(mesh.cellCentres()));
|
||||
inOut[0] = allCcs.size();
|
||||
Pstream::broadcast(allCcs);
|
||||
Pstream::broadcastList(allCcs);
|
||||
inOut[1] = allCcs.size();
|
||||
Pout<< " " << inOut << endl;
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -47,7 +47,7 @@ Description
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "cellSet.H"
|
||||
#include "SortableList.H"
|
||||
#include "SortList.H"
|
||||
#include "labelIOList.H"
|
||||
#include "fvMesh.H"
|
||||
#include "volFields.H"
|
||||
@ -128,71 +128,54 @@ int main(int argc, char *argv[])
|
||||
|
||||
const scalarField& vols = mesh.cellVolumes();
|
||||
|
||||
SortableList<scalar> sortedVols(vols);
|
||||
SortList<scalar> sortedVols(vols);
|
||||
|
||||
// All cell labels, sorted per bin.
|
||||
DynamicList<DynamicList<label>> bins;
|
||||
|
||||
// Lower/upper limits
|
||||
DynamicList<scalar> lowerLimits;
|
||||
DynamicList<scalar> upperLimits;
|
||||
DynamicList<scalarMinMax> limits;
|
||||
|
||||
// Create bin0. Have upperlimit as factor times lowerlimit.
|
||||
bins.append(DynamicList<label>());
|
||||
lowerLimits.append(sortedVols[0]);
|
||||
upperLimits.append(1.1 * lowerLimits.last());
|
||||
bins.emplace_back();
|
||||
limits.emplace_back(sortedVols[0], 1.1*sortedVols[0]);
|
||||
|
||||
forAll(sortedVols, i)
|
||||
{
|
||||
if (sortedVols[i] > upperLimits.last())
|
||||
if (sortedVols[i] > limits.back().max())
|
||||
{
|
||||
// New value outside of current bin
|
||||
|
||||
// Shrink old bin.
|
||||
DynamicList<label>& bin = bins.last();
|
||||
|
||||
bin.shrink();
|
||||
|
||||
Info<< "Collected " << bin.size() << " elements in bin "
|
||||
<< lowerLimits.last() << " .. "
|
||||
<< upperLimits.last() << endl;
|
||||
Info<< "Collected " << bins.back() << " elements in bin "
|
||||
<< limits.back().min() << " .. "
|
||||
<< limits.back().max() << endl;
|
||||
|
||||
// Create new bin.
|
||||
bins.append(DynamicList<label>());
|
||||
lowerLimits.append(sortedVols[i]);
|
||||
upperLimits.append(1.1 * lowerLimits.last());
|
||||
bins.emplace_back();
|
||||
limits.emplace_back(sortedVols[i], 1.1 * sortedVols[i]);
|
||||
|
||||
Info<< "Creating new bin " << lowerLimits.last()
|
||||
<< " .. " << upperLimits.last()
|
||||
<< endl;
|
||||
Info<< "Creating new bin "
|
||||
<< limits.back().min() << " .. "
|
||||
<< limits.back().max() << endl;
|
||||
}
|
||||
|
||||
// Append to current bin.
|
||||
DynamicList<label>& bin = bins.last();
|
||||
|
||||
bin.append(sortedVols.indices()[i]);
|
||||
// Add to current bin.
|
||||
bins.back().push_back(sortedVols.indices()[i]);
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
bins.last().shrink();
|
||||
bins.shrink();
|
||||
lowerLimits.shrink();
|
||||
upperLimits.shrink();
|
||||
|
||||
|
||||
//
|
||||
// Write to cellSets.
|
||||
//
|
||||
|
||||
Info<< "Volume bins:" << nl;
|
||||
forAll(bins, binI)
|
||||
forAll(bins, bini)
|
||||
{
|
||||
const DynamicList<label>& bin = bins[binI];
|
||||
const auto& bin = bins[bini];
|
||||
|
||||
cellSet cells(mesh, "vol" + name(binI), bin.size());
|
||||
cellSet cells(mesh, "vol" + Foam::name(bini), bin.size());
|
||||
cells.insert(bin);
|
||||
|
||||
Info<< " " << lowerLimits[binI] << " .. " << upperLimits[binI]
|
||||
Info<< " " << limits[bini].min() << " .. " << limits[bini].max()
|
||||
<< " : writing " << bin.size() << " cells to cellSet "
|
||||
<< cells.name() << endl;
|
||||
|
||||
@ -294,13 +277,13 @@ int main(int argc, char *argv[])
|
||||
);
|
||||
|
||||
// Set cell values
|
||||
forAll(bins, binI)
|
||||
forAll(bins, bini)
|
||||
{
|
||||
const DynamicList<label>& bin = bins[binI];
|
||||
const auto& bin = bins[bini];
|
||||
|
||||
forAll(bin, i)
|
||||
{
|
||||
refLevel[bin[i]] = bins.size() - binI - 1;
|
||||
refLevel[bin[i]] = bins.size() - bini - 1;
|
||||
postRefLevel[bin[i]] = refLevel[bin[i]];
|
||||
}
|
||||
}
|
||||
|
||||
@ -468,8 +468,8 @@ inline Foam::List<Foam::label> Foam::conformalVoronoiMesh::processorsAttached
|
||||
|
||||
forAll(c1Procs, aPI)
|
||||
{
|
||||
procsAttached.appendUniq(c1Procs[aPI]);
|
||||
procsAttached.appendUniq(c2Procs[aPI]);
|
||||
procsAttached.push_uniq(c1Procs[aPI]);
|
||||
procsAttached.push_uniq(c2Procs[aPI]);
|
||||
}
|
||||
|
||||
return List<label>(procsAttached);
|
||||
|
||||
@ -46,8 +46,8 @@ void Foam::shortEdgeFilter2D::assignBoundaryPointRegions
|
||||
const edge& e = iter.key();
|
||||
const label regi = iter.val();
|
||||
|
||||
boundaryPointRegions[e.start()].appendUniq(regi);
|
||||
boundaryPointRegions[e.end()].appendUniq(regi);
|
||||
boundaryPointRegions[e.first()].push_uniq(regi);
|
||||
boundaryPointRegions[e.second()].push_uniq(regi);
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ void Foam::shortEdgeFilter2D::updateEdgeRegionMap
|
||||
const edgeList& edges = surfMesh.edges();
|
||||
const labelList& meshPoints = surfMesh.meshPoints();
|
||||
|
||||
patchSizes.setSize(patchNames_.size(), 0);
|
||||
patchSizes.resize_nocopy(patchNames_.size());
|
||||
patchSizes = 0;
|
||||
|
||||
forAll(edges, edgeI)
|
||||
@ -78,15 +78,13 @@ void Foam::shortEdgeFilter2D::updateEdgeRegionMap
|
||||
|
||||
const edge& e = edges[edgeI];
|
||||
|
||||
const label startI = meshPoints[e[0]];
|
||||
const label endI = meshPoints[e[1]];
|
||||
|
||||
label region = -1;
|
||||
|
||||
const DynamicList<label> startPtRegions =
|
||||
boundaryPtRegions[surfPtToBoundaryPt[startI]];
|
||||
const DynamicList<label> endPtRegions =
|
||||
boundaryPtRegions[surfPtToBoundaryPt[endI]];
|
||||
const DynamicList<label>& startPtRegions =
|
||||
boundaryPtRegions[surfPtToBoundaryPt[meshPoints[e.first()]]];
|
||||
|
||||
const DynamicList<label>& endPtRegions =
|
||||
boundaryPtRegions[surfPtToBoundaryPt[meshPoints[e.second()]]];
|
||||
|
||||
if (startPtRegions.size() > 1 && endPtRegions.size() > 1)
|
||||
{
|
||||
|
||||
@ -87,11 +87,7 @@ label addPatch
|
||||
)
|
||||
);
|
||||
auto& pp = *ppPtr;
|
||||
|
||||
if (!groupName.empty())
|
||||
{
|
||||
pp.inGroups().appendUniq(groupName);
|
||||
}
|
||||
pp.addGroup(groupName);
|
||||
|
||||
|
||||
// Add patch, create calculated everywhere
|
||||
|
||||
@ -148,21 +148,15 @@ void matchPatchFaces
|
||||
// Mesh 0
|
||||
//~~~~~~~
|
||||
|
||||
interfaceMesh0.append(labelList());
|
||||
auto& intMesh0 = interfaceMesh0.last();
|
||||
intMesh0.setSize(nSourcei, -1);
|
||||
auto& intMesh0 = interfaceMesh0.emplace_back(nSourcei, -1);
|
||||
intMesh0[sourcei] = meshi;
|
||||
|
||||
interfaceSource0.append(sourcei);
|
||||
interfaceSource0.push_back(sourcei);
|
||||
|
||||
interfacePatch0.append(labelList());
|
||||
auto& intPatch0 = interfacePatch0.last();
|
||||
intPatch0.setSize(nSourcei, -1);
|
||||
auto& intPatch0 = interfacePatch0.emplace_back(nSourcei, -1);
|
||||
intPatch0[sourcei] = ppi.index();
|
||||
|
||||
interfaceNames0.append(wordList());
|
||||
auto& intNames0 = interfaceNames0.last();
|
||||
intNames0.setSize(nSourcei);
|
||||
auto& intNames0 = interfaceNames0.emplace_back(nSourcei);
|
||||
intNames0[sourcei] =
|
||||
patchName(entryName, meshes[meshi], meshes[meshj]);
|
||||
|
||||
@ -170,33 +164,23 @@ void matchPatchFaces
|
||||
// Mesh 1
|
||||
//~~~~~~~
|
||||
|
||||
interfaceMesh1.append(labelList());
|
||||
auto& intMesh1 = interfaceMesh1.last();
|
||||
intMesh1.setSize(nSourcej, -1);
|
||||
auto& intMesh1 = interfaceMesh1.emplace_back(nSourcej, -1);
|
||||
intMesh1[sourcej] = meshj;
|
||||
|
||||
interfaceSource1.append(sourcej);
|
||||
interfaceSource1.push_back(sourcej);
|
||||
|
||||
interfacePatch1.append(labelList());
|
||||
auto& intPatch1 = interfacePatch1.last();
|
||||
intPatch1.setSize(nSourcej, -1);
|
||||
auto& intPatch1 = interfacePatch1.emplace_back(nSourcej, -1);
|
||||
intPatch1[sourcej] = ppj.index();
|
||||
|
||||
interfaceNames1.append(wordList());
|
||||
auto& intNames1 = interfaceNames1.last();
|
||||
intNames1.setSize(nSourcej);
|
||||
auto& intNames1 = interfaceNames1.emplace_back(nSourcej);
|
||||
intNames1[sourcej] =
|
||||
patchName(entryName, meshes[meshj], meshes[meshi]);
|
||||
|
||||
interfaceFaces0.append(List<DynamicList<label>>());
|
||||
auto& intFaces0 = interfaceFaces0.last();
|
||||
intFaces0.setSize(nSourcei);
|
||||
auto& intFaces0 = interfaceFaces0.emplace_back(nSourcei);
|
||||
DynamicList<label>& faces0 = intFaces0[sourcei];
|
||||
faces0.setCapacity(ppi.size());
|
||||
|
||||
interfaceFaces1.append(List<DynamicList<label>>());
|
||||
auto& intFaces1 = interfaceFaces1.last();
|
||||
intFaces1.setSize(nSourcej);
|
||||
auto& intFaces1 = interfaceFaces1.emplace_back(nSourcej);
|
||||
DynamicList<label>& faces1 = intFaces1[sourcej];
|
||||
faces1.setCapacity(ppj.size());
|
||||
|
||||
@ -249,7 +233,7 @@ void matchPatchFaces
|
||||
{
|
||||
if (weights[facei] > 0.5 || sourceMask[facei] > SMALL)
|
||||
{
|
||||
faces0.append(ppi.start()+facei);
|
||||
faces0.push_back(ppi.start()+facei);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -259,7 +243,7 @@ void matchPatchFaces
|
||||
{
|
||||
if (weights[facei] > 0.5 || targetMask[facei] > SMALL)
|
||||
{
|
||||
faces1.append(ppj.start()+facei);
|
||||
faces1.push_back(ppj.start()+facei);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -825,7 +809,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (pDict.get<word>("constructFrom") == "autoPatch")
|
||||
{
|
||||
interRegionSources[meshi].append(sourcei);
|
||||
interRegionSources[meshi].push_back(sourcei);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -518,7 +518,7 @@ void Foam::meshDualiser::createFacesAroundEdge
|
||||
|
||||
if (startDual != -1)
|
||||
{
|
||||
verts.appendUniq(startDual);
|
||||
verts.push_uniq(startDual);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Submodule modules/visualization updated: 8c0c81f563...87886a1c8a
@ -497,7 +497,7 @@ bool Foam::fileMonitor::removeWatch(const label watchFd)
|
||||
<< watchFile_[watchFd] << endl;
|
||||
}
|
||||
|
||||
freeWatchFds_.appendUniq(watchFd);
|
||||
freeWatchFds_.push_uniq(watchFd);
|
||||
|
||||
return watcher_->removeWatch(watchFd);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2011 Symscape
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -36,6 +36,7 @@ License
|
||||
#include "Switch.H"
|
||||
|
||||
#include <float.h> // For *fp functions
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
// File-local functions
|
||||
@ -98,18 +99,7 @@ void Foam::sigFpe::sigHandler(int)
|
||||
|
||||
Foam::sigFpe::sigFpe()
|
||||
{
|
||||
set(false);
|
||||
}
|
||||
|
||||
|
||||
Foam::sigFpe::ignore::ignore()
|
||||
:
|
||||
wasActive_(sigFpe::active())
|
||||
{
|
||||
if (wasActive_)
|
||||
{
|
||||
sigFpe::unset();
|
||||
}
|
||||
set(false); // false = non-verbose
|
||||
}
|
||||
|
||||
|
||||
@ -117,28 +107,12 @@ Foam::sigFpe::ignore::ignore()
|
||||
|
||||
Foam::sigFpe::~sigFpe()
|
||||
{
|
||||
unset(false);
|
||||
}
|
||||
|
||||
|
||||
Foam::sigFpe::ignore::~ignore()
|
||||
{
|
||||
restore();
|
||||
unset(false); // false = non-verbose
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::sigFpe::ignore::restore()
|
||||
{
|
||||
if (wasActive_)
|
||||
{
|
||||
sigFpe::set();
|
||||
}
|
||||
wasActive_ = false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::sigFpe::requested()
|
||||
{
|
||||
return isTrue("FOAM_SIGFPE", switchFpe_);
|
||||
@ -153,8 +127,8 @@ void Foam::sigFpe::set(bool verbose)
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
Info<< "trapFpe: Floating point exception trapping ";
|
||||
Info<< "- disabled on this platform" << endl;
|
||||
Info<< "trapFpe: Floating point exception trapping "
|
||||
<< "- disabled on this platform" << endl;
|
||||
}
|
||||
|
||||
#else
|
||||
@ -194,7 +168,7 @@ void Foam::sigFpe::set(bool verbose)
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
Info<< "setNaN : Initialise allocated memory to NaN "
|
||||
Info<< "setNaN : Fill allocated memory with NaN "
|
||||
<< "- not supported on this platform" << endl;
|
||||
}
|
||||
}
|
||||
@ -222,9 +196,37 @@ void Foam::sigFpe::unset(bool verbose)
|
||||
}
|
||||
|
||||
|
||||
void Foam::sigFpe::fillNan(char* buf, size_t count)
|
||||
{
|
||||
if (!buf || !count) return;
|
||||
|
||||
// Fill with signaling_NaN
|
||||
const scalar val = std::numeric_limits<scalar>::signaling_NaN();
|
||||
|
||||
// Can dispatch with
|
||||
// - std::execution::parallel_unsequenced_policy
|
||||
// - std::execution::unsequenced_policy
|
||||
std::fill_n
|
||||
(
|
||||
reinterpret_cast<scalar*>(buf), (count/sizeof(scalar)), val
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void Foam::sigFpe::fillNan(UList<scalar>& list)
|
||||
{
|
||||
list = std::numeric_limits<scalar>::signaling_NaN();
|
||||
if (list.empty()) return;
|
||||
|
||||
// Fill with signaling_NaN
|
||||
const scalar val = std::numeric_limits<scalar>::signaling_NaN();
|
||||
|
||||
// Can dispatch with
|
||||
// - std::execution::parallel_unsequenced_policy
|
||||
// - std::execution::unsequenced_policy
|
||||
std::fill_n
|
||||
(
|
||||
list.data(), list.size(), val
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -57,7 +57,7 @@ SourceFiles
|
||||
#ifndef Foam_sigFpe_H
|
||||
#define Foam_sigFpe_H
|
||||
|
||||
#include <cstddef> // for std::size_t
|
||||
#include <cstddef> // For std::size_t
|
||||
#include "scalarFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -87,7 +87,7 @@ class sigFpe
|
||||
//- Floating point trapping currently active?
|
||||
static bool sigActive_;
|
||||
|
||||
//- Flag to indicate mallocNan is currently active
|
||||
//- Is NaN memory initialisation currently active?
|
||||
static bool nanActive_;
|
||||
|
||||
|
||||
@ -124,18 +124,21 @@ public:
|
||||
//- True if NaN memory initialisation is currently active.
|
||||
static bool nanActive() noexcept { return nanActive_; }
|
||||
|
||||
//- Activate SIGFPE signal handler when FOAM_SIGFPE is %set
|
||||
// Fill memory with NaN when FOAM_SETNAN is %set
|
||||
//- Activate SIGFPE handler when FOAM_SIGFPE is enabled.
|
||||
//- Activate fill memory with signaling_NaN when FOAM_SETNAN is enabled
|
||||
static void set(bool verbose=false);
|
||||
|
||||
//- Deactivate SIGFPE signal handler and NaN memory initialisation
|
||||
//- Deactivate SIGFPE handler and NaN memory initialisation
|
||||
static void unset(bool verbose=false);
|
||||
|
||||
//- Fill data block with NaN values
|
||||
//- Fill data block with signaling_NaN values
|
||||
static void fillNan(char* buf, size_t count);
|
||||
|
||||
//- Fill data block with signaling_NaN values
|
||||
static void fillNan(UList<scalar>& list);
|
||||
|
||||
|
||||
// Helper classes
|
||||
// Helpers
|
||||
|
||||
//- Helper to locally ignore SIGFPE handling.
|
||||
// Restores the original state of the SIGFPE handler on destruction.
|
||||
@ -144,29 +147,46 @@ public:
|
||||
//- The signal handler state when entering
|
||||
bool wasActive_;
|
||||
|
||||
public:
|
||||
|
||||
//- No copy construct
|
||||
ignore(const ignore&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const ignore&) = delete;
|
||||
|
||||
//- No move construct
|
||||
ignore(ignore&&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const ignore&) = delete;
|
||||
|
||||
//- No move assignment
|
||||
void operator=(ignore&&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Constructor deactivates any previously active SIGFPE handler
|
||||
ignore();
|
||||
ignore()
|
||||
:
|
||||
wasActive_(Foam::sigFpe::active())
|
||||
{
|
||||
if (wasActive_)
|
||||
{
|
||||
Foam::sigFpe::unset();
|
||||
}
|
||||
}
|
||||
|
||||
//- Destructor restores the original state of SIGFPE handler
|
||||
~ignore();
|
||||
~ignore() { reset(); }
|
||||
|
||||
//- Restore the original state of SIGFPE handler
|
||||
void restore();
|
||||
void reset()
|
||||
{
|
||||
if (wasActive_)
|
||||
{
|
||||
wasActive_ = false;
|
||||
Foam::sigFpe::set();
|
||||
}
|
||||
}
|
||||
|
||||
//- Same as reset()
|
||||
void restore() { reset(); }
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -77,7 +77,7 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Default construct
|
||||
sigStopAtWriteNow();
|
||||
sigStopAtWriteNow() noexcept = default;
|
||||
|
||||
//- Construct with Time reference
|
||||
explicit sigStopAtWriteNow(const Time& runTime, bool verbose=false);
|
||||
|
||||
@ -493,7 +493,7 @@ bool Foam::fileMonitor::removeWatch(const label watchFd)
|
||||
<< watchFile_[watchFd] << endl;
|
||||
}
|
||||
|
||||
freeWatchFds_.appendUniq(watchFd);
|
||||
freeWatchFds_.push_uniq(watchFd);
|
||||
|
||||
return watcher_->removeWatch(watchFd);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -33,12 +33,12 @@ License
|
||||
#include "IOstreams.H"
|
||||
#include "UList.H"
|
||||
#include "Switch.H"
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
// File-local functions
|
||||
#include "signalMacros.C"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#if defined(__linux__) && defined(__GNUC__)
|
||||
#ifndef __USE_GNU
|
||||
#define __USE_GNU // To use feenableexcept()
|
||||
@ -85,32 +85,32 @@ extern "C"
|
||||
{
|
||||
extern void* __libc_malloc(size_t size);
|
||||
|
||||
// Override the GLIBC malloc to support mallocNan
|
||||
// Override the GLIBC malloc to support filling with NaN
|
||||
void* malloc(size_t size)
|
||||
{
|
||||
// Call the low-level GLIBC malloc function
|
||||
void* ptr = __libc_malloc(size);
|
||||
|
||||
if (Foam::sigFpe::nanActive())
|
||||
{
|
||||
return Foam::sigFpe::mallocNan(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
return __libc_malloc(size);
|
||||
// Fill with signaling_NaN
|
||||
const auto val = std::numeric_limits<Foam::scalar>::signaling_NaN();
|
||||
|
||||
// Can dispatch with
|
||||
// - std::execution::parallel_unsequenced_policy
|
||||
// - std::execution::unsequenced_policy
|
||||
std::fill_n
|
||||
(
|
||||
reinterpret_cast<Foam::scalar*>(ptr),
|
||||
(size/sizeof(Foam::scalar)),
|
||||
val
|
||||
);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
} // End extern C
|
||||
|
||||
|
||||
void* Foam::sigFpe::mallocNan(size_t size)
|
||||
{
|
||||
// Call the low-level GLIBC malloc function
|
||||
void* result = __libc_malloc(size);
|
||||
|
||||
// Initialize to signalling NaN
|
||||
UList<scalar> list(reinterpret_cast<scalar*>(result), size/sizeof(scalar));
|
||||
sigFpe::fillNan(list);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif // __linux__
|
||||
|
||||
|
||||
@ -134,18 +134,7 @@ void Foam::sigFpe::sigHandler(int)
|
||||
|
||||
Foam::sigFpe::sigFpe()
|
||||
{
|
||||
set(false);
|
||||
}
|
||||
|
||||
|
||||
Foam::sigFpe::ignore::ignore()
|
||||
:
|
||||
wasActive_(sigFpe::active())
|
||||
{
|
||||
if (wasActive_)
|
||||
{
|
||||
sigFpe::unset();
|
||||
}
|
||||
set(false); // false = non-verbose
|
||||
}
|
||||
|
||||
|
||||
@ -153,28 +142,12 @@ Foam::sigFpe::ignore::ignore()
|
||||
|
||||
Foam::sigFpe::~sigFpe()
|
||||
{
|
||||
unset(false);
|
||||
}
|
||||
|
||||
|
||||
Foam::sigFpe::ignore::~ignore()
|
||||
{
|
||||
restore();
|
||||
unset(false); // false = non-verbose
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::sigFpe::ignore::restore()
|
||||
{
|
||||
if (wasActive_)
|
||||
{
|
||||
sigFpe::set();
|
||||
}
|
||||
wasActive_ = false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::sigFpe::requested()
|
||||
{
|
||||
return isTrue("FOAM_SIGFPE", switchFpe_);
|
||||
@ -224,7 +197,7 @@ void Foam::sigFpe::set(bool verbose)
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
Info<< "setNaN : Initialise allocated memory to NaN ";
|
||||
Info<< "setNaN : Fill allocated memory with NaN ";
|
||||
|
||||
if (nanActive_)
|
||||
{
|
||||
@ -275,9 +248,37 @@ void Foam::sigFpe::unset(bool verbose)
|
||||
}
|
||||
|
||||
|
||||
void Foam::sigFpe::fillNan(char* buf, size_t count)
|
||||
{
|
||||
if (!buf || !count) return;
|
||||
|
||||
// Fill with signaling_NaN
|
||||
const auto val = std::numeric_limits<scalar>::signaling_NaN();
|
||||
|
||||
// Can dispatch with
|
||||
// - std::execution::parallel_unsequenced_policy
|
||||
// - std::execution::unsequenced_policy
|
||||
std::fill_n
|
||||
(
|
||||
reinterpret_cast<scalar*>(buf), (count/sizeof(scalar)), val
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void Foam::sigFpe::fillNan(UList<scalar>& list)
|
||||
{
|
||||
list = std::numeric_limits<scalar>::signaling_NaN();
|
||||
if (list.empty()) return;
|
||||
|
||||
// Fill with signaling_NaN
|
||||
const auto val = std::numeric_limits<scalar>::signaling_NaN();
|
||||
|
||||
// Can dispatch with
|
||||
// - std::execution::parallel_unsequenced_policy
|
||||
// - std::execution::unsequenced_policy
|
||||
std::fill_n
|
||||
(
|
||||
list.data(), list.size(), val
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -57,7 +57,7 @@ SourceFiles
|
||||
#ifndef Foam_sigFpe_H
|
||||
#define Foam_sigFpe_H
|
||||
|
||||
#include <cstddef> // for std::size_t
|
||||
#include <cstddef> // For std::size_t
|
||||
#include "scalarFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -87,7 +87,7 @@ class sigFpe
|
||||
//- Floating point trapping currently active?
|
||||
static bool sigActive_;
|
||||
|
||||
//- Flag to indicate mallocNan is currently active
|
||||
//- Is NaN memory initialisation currently active?
|
||||
static bool nanActive_;
|
||||
|
||||
|
||||
@ -124,23 +124,21 @@ public:
|
||||
//- True if NaN memory initialisation is currently active.
|
||||
static bool nanActive() noexcept { return nanActive_; }
|
||||
|
||||
//- Activate SIGFPE signal handler when FOAM_SIGFPE is %set
|
||||
// Fill memory with NaN when FOAM_SETNAN is %set
|
||||
//- Activate SIGFPE handler when FOAM_SIGFPE is enabled.
|
||||
//- Activate fill memory with signaling_NaN when FOAM_SETNAN is enabled
|
||||
static void set(bool verbose=false);
|
||||
|
||||
//- Deactivate SIGFPE signal handler and NaN memory initialisation
|
||||
//- Deactivate SIGFPE handler and NaN memory initialisation
|
||||
static void unset(bool verbose=false);
|
||||
|
||||
#ifdef __linux__
|
||||
//- Malloc function which initializes to NaN
|
||||
static void* mallocNan(size_t size);
|
||||
#endif
|
||||
//- Fill data block with signaling_NaN values
|
||||
static void fillNan(char* buf, size_t count);
|
||||
|
||||
//- Fill data block with NaN values
|
||||
//- Fill data block with signaling_NaN values
|
||||
static void fillNan(UList<scalar>& list);
|
||||
|
||||
|
||||
// Helper classes
|
||||
// Helpers
|
||||
|
||||
//- Helper to locally ignore SIGFPE handling.
|
||||
// Restores the original state of the SIGFPE handler on destruction.
|
||||
@ -149,29 +147,46 @@ public:
|
||||
//- The signal handler state when entering
|
||||
bool wasActive_;
|
||||
|
||||
public:
|
||||
|
||||
//- No copy construct
|
||||
ignore(const ignore&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const ignore&) = delete;
|
||||
|
||||
//- No move construct
|
||||
ignore(ignore&&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const ignore&) = delete;
|
||||
|
||||
//- No move assignment
|
||||
void operator=(ignore&&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Constructor deactivates any previously active SIGFPE handler
|
||||
ignore();
|
||||
ignore()
|
||||
:
|
||||
wasActive_(Foam::sigFpe::active())
|
||||
{
|
||||
if (wasActive_)
|
||||
{
|
||||
Foam::sigFpe::unset();
|
||||
}
|
||||
}
|
||||
|
||||
//- Destructor restores the original state of SIGFPE handler
|
||||
~ignore();
|
||||
~ignore() { reset(); }
|
||||
|
||||
//- Restore the original state of SIGFPE handler
|
||||
void restore();
|
||||
void reset()
|
||||
{
|
||||
if (wasActive_)
|
||||
{
|
||||
wasActive_ = false;
|
||||
Foam::sigFpe::set();
|
||||
}
|
||||
}
|
||||
|
||||
//- Same as reset()
|
||||
void restore() { reset(); }
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ global/globals.C
|
||||
/* global/JobInfo/JobInfo.C in globals.C */
|
||||
global/argList/argList.C
|
||||
global/argList/argListHelp.C
|
||||
global/argList/argListRedirect.C
|
||||
global/clock/clock.C
|
||||
global/clockValue/clockValue.C
|
||||
global/cpuTime/cpuTimeCxx.C
|
||||
|
||||
@ -524,8 +524,8 @@ public:
|
||||
//FOAM_DEPRECATED_FOR(2022-10, "push_back()")
|
||||
void append(const UList<T>& list) { this->push_back(list); }
|
||||
|
||||
//- Append an element if not already in the buffer.
|
||||
//FOAM_DEPRECATED_FOR(2022-10, "push_uniq()")
|
||||
//- Same as push_uniq()
|
||||
FOAM_DEPRECATED_STRICT(2022-10, "push_uniq()")
|
||||
label appendUniq(const T& val) { return this->push_uniq(val); }
|
||||
};
|
||||
|
||||
|
||||
@ -443,8 +443,8 @@ public:
|
||||
this->push_back(std::move(list));
|
||||
}
|
||||
|
||||
//- Append an element if not already in the list.
|
||||
//FOAM_DEPRECATED_FOR(2022-10, "push_uniq()")
|
||||
//- Same as push_uniq()
|
||||
FOAM_DEPRECATED_STRICT(2022-10, "push_uniq()")
|
||||
label appendUniq(const T& val) { return this->push_uniq(val); }
|
||||
};
|
||||
|
||||
|
||||
@ -395,8 +395,8 @@ public:
|
||||
this->push_back(list);
|
||||
}
|
||||
|
||||
//- Append an element if not already in the list.
|
||||
//FOAM_DEPRECATED_FOR(2022-10, "push_uniq()")
|
||||
//- Same as push_uniq()
|
||||
FOAM_DEPRECATED_STRICT(2022-10, "push_uniq()")
|
||||
label appendUniq(const T& val) { return this->push_uniq(val); }
|
||||
|
||||
|
||||
|
||||
@ -1065,14 +1065,9 @@ void Foam::ListOps::appendEqOp<T>::operator()
|
||||
{
|
||||
if (y.size())
|
||||
{
|
||||
label len = x.size();
|
||||
if (len)
|
||||
if (x.size())
|
||||
{
|
||||
x.resize(len + y.size());
|
||||
for (const T& val : y)
|
||||
{
|
||||
x[len++] = val;
|
||||
}
|
||||
x.push_back(y);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1095,11 +1090,7 @@ void Foam::ListOps::uniqueEqOp<T>::operator()
|
||||
{
|
||||
for (const T& val : y)
|
||||
{
|
||||
// --> x.push_uniq(val)
|
||||
if (!x.contains(val))
|
||||
{
|
||||
x.push_back(val);
|
||||
}
|
||||
x.push_uniq(val);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -45,7 +45,7 @@ Foam::IFstream::IFstream
|
||||
IOstreamOption streamOpt
|
||||
)
|
||||
:
|
||||
Foam::ifstreamPointer(pathname),
|
||||
Foam::ifstreamPointer(pathname, streamOpt),
|
||||
ISstream(*(ifstreamPointer::get()), pathname, streamOpt)
|
||||
{
|
||||
IOstreamOption::compression(ifstreamPointer::whichCompression());
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -65,7 +65,7 @@ Foam::OFstream::OFstream
|
||||
Foam::ofstreamPointer
|
||||
(
|
||||
pathname,
|
||||
streamOpt.compression(),
|
||||
streamOpt,
|
||||
(IOstreamOption::appendType::APPEND == append),
|
||||
(IOstreamOption::atomicType::ATOMIC == atomic)
|
||||
),
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -74,7 +74,7 @@ class ifstreamPointer
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- The stream pointer (ifstream or igzstream)
|
||||
//- The stream pointer (ifstream | igzstream, ...)
|
||||
std::unique_ptr<std::istream> ptr_;
|
||||
|
||||
|
||||
@ -114,8 +114,20 @@ public:
|
||||
//- Construct from pathname.
|
||||
// Attempts to read the specified file.
|
||||
// If that fails, try as a compressed file (.gz ending).
|
||||
// \param pathname The file name to open for reading
|
||||
explicit ifstreamPointer(const fileName& pathname);
|
||||
|
||||
//- Construct from pathname, option.
|
||||
// Attempts to read the specified file.
|
||||
// If that fails, try as a compressed file (.gz ending).
|
||||
// \param pathname The file name to open for reading
|
||||
// \param streamOpt Currently unused
|
||||
ifstreamPointer
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption streamOpt
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -125,6 +137,9 @@ public:
|
||||
|
||||
// Access
|
||||
|
||||
//- True if it holds a valid pointer
|
||||
explicit operator bool() const noexcept { return bool(ptr_); }
|
||||
|
||||
//- The stream pointer (ifstream or igzstream)
|
||||
std::istream* get() noexcept { return ptr_.get(); }
|
||||
|
||||
@ -135,6 +150,19 @@ public:
|
||||
IOstreamOption::compressionType whichCompression() const;
|
||||
|
||||
|
||||
// Wrapped Methods
|
||||
|
||||
//- Attempts to open the specified file for reading.
|
||||
// If that fails, try as a compressed file (.gz ending).
|
||||
// \param pathname The file name to open for reading
|
||||
// \param streamOpt Currently unused
|
||||
void open
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption streamOpt = IOstreamOption()
|
||||
);
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Return managed pointer and release ownership
|
||||
@ -168,7 +196,7 @@ class ofstreamPointer
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- The stream pointer (ofstream | ogzstream | ocountstream)
|
||||
//- The stream pointer (ofstream | ogzstream | ocountstream, ...)
|
||||
std::unique_ptr<std::ostream> ptr_;
|
||||
|
||||
//- Atomic file creation
|
||||
@ -211,9 +239,24 @@ public:
|
||||
//- Default construct (empty)
|
||||
ofstreamPointer() noexcept;
|
||||
|
||||
//- Construct as null output stream using Foam::ocountstream
|
||||
//- Construct as null output stream (Foam::ocountstream)
|
||||
explicit ofstreamPointer(std::nullptr_t);
|
||||
|
||||
//- Construct from pathname, option, append, file handling atomic
|
||||
// \param pathname The file name to open for writing
|
||||
// \param streamOpt Respects (UNCOMPRESSED | COMPRESSED)
|
||||
// \param append Open in append mode
|
||||
// \param atomic Write into temporary file (not target file).
|
||||
// This option should only be used with a stream wrapper
|
||||
// (eg, OFstream) that handles the final renaming.
|
||||
explicit ofstreamPointer
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption streamOpt = IOstreamOption(),
|
||||
const bool append = false,
|
||||
const bool atomic = false
|
||||
);
|
||||
|
||||
//- Construct from pathname, compression, append, file handling atomic
|
||||
// \param pathname The file name to open for writing
|
||||
// \param comp UNCOMPRESSED | COMPRESSED
|
||||
@ -221,10 +264,10 @@ public:
|
||||
// \param atomic Write into temporary file (not target file).
|
||||
// This option should only be used with a stream wrapper
|
||||
// (eg, OFstream) that handles the final renaming.
|
||||
explicit ofstreamPointer
|
||||
ofstreamPointer
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption::compressionType comp = IOstreamOption::UNCOMPRESSED,
|
||||
IOstreamOption::compressionType comp,
|
||||
const bool append = false,
|
||||
const bool atomic = false
|
||||
);
|
||||
@ -238,6 +281,9 @@ public:
|
||||
|
||||
// Access
|
||||
|
||||
//- True if it holds a valid pointer
|
||||
explicit operator bool() const noexcept { return bool(ptr_); }
|
||||
|
||||
//- The stream pointer (ofstream or ogzstream)
|
||||
std::ostream* get() noexcept { return ptr_.get(); }
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -60,8 +60,23 @@ bool Foam::ofstreamPointer::supports_gz()
|
||||
}
|
||||
|
||||
|
||||
// Future: List<char> slurpFile(....);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::ifstreamPointer::ifstreamPointer
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption streamOpt // Currently unused
|
||||
)
|
||||
:
|
||||
ptr_(nullptr)
|
||||
{
|
||||
open(pathname, streamOpt);
|
||||
}
|
||||
|
||||
|
||||
Foam::ifstreamPointer::ifstreamPointer
|
||||
(
|
||||
const fileName& pathname
|
||||
@ -69,6 +84,162 @@ Foam::ifstreamPointer::ifstreamPointer
|
||||
:
|
||||
ptr_(nullptr)
|
||||
{
|
||||
open(pathname);
|
||||
}
|
||||
|
||||
|
||||
Foam::ofstreamPointer::ofstreamPointer() noexcept
|
||||
:
|
||||
ptr_(),
|
||||
atomic_(false)
|
||||
{}
|
||||
|
||||
|
||||
Foam::ofstreamPointer::ofstreamPointer(std::nullptr_t)
|
||||
:
|
||||
ptr_(new Foam::ocountstream),
|
||||
atomic_(false)
|
||||
{}
|
||||
|
||||
|
||||
Foam::ofstreamPointer::ofstreamPointer
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption streamOpt,
|
||||
const bool append,
|
||||
const bool atomic
|
||||
)
|
||||
:
|
||||
ptr_(nullptr),
|
||||
atomic_(atomic)
|
||||
{
|
||||
std::ios_base::openmode mode
|
||||
(
|
||||
std::ios_base::out | std::ios_base::binary
|
||||
);
|
||||
|
||||
if (append)
|
||||
{
|
||||
mode |= std::ios_base::app;
|
||||
|
||||
// Cannot append to gzstream
|
||||
streamOpt.compression(IOstreamOption::UNCOMPRESSED);
|
||||
|
||||
// Cannot use append + atomic operation, without lots of extra work
|
||||
atomic_ = false;
|
||||
}
|
||||
|
||||
|
||||
// When opening new files, remove file variants out of the way.
|
||||
// Eg, opening "file1"
|
||||
// - remove old "file1.gz" (compressed)
|
||||
// - also remove old "file1" if it is a symlink and we are not appending
|
||||
//
|
||||
// Not writing into symlinked files avoids problems with symlinked
|
||||
// initial fields (eg, 0/U -> ../0.orig/U)
|
||||
|
||||
const fileName pathname_gz(pathname + ".gz");
|
||||
const fileName pathname_tmp(pathname + "~tmp~");
|
||||
|
||||
fileName::Type fType = fileName::Type::UNDEFINED;
|
||||
|
||||
if (IOstreamOption::COMPRESSED == streamOpt.compression())
|
||||
{
|
||||
// Output compression requested.
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
// TBD:
|
||||
// atomic_ = true; // Always treat COMPRESSED like an atomic
|
||||
|
||||
const fileName& target = (atomic_ ? pathname_tmp : pathname_gz);
|
||||
|
||||
// Remove old uncompressed version (if any)
|
||||
fType = Foam::type(pathname, false);
|
||||
if (fType == fileName::SYMLINK || fType == fileName::FILE)
|
||||
{
|
||||
Foam::rm(pathname);
|
||||
}
|
||||
|
||||
// Avoid writing into symlinked files (non-append mode)
|
||||
if (!append || atomic_)
|
||||
{
|
||||
fType = Foam::type(target, false);
|
||||
if (fType == fileName::SYMLINK)
|
||||
{
|
||||
Foam::rm(target);
|
||||
}
|
||||
}
|
||||
|
||||
ptr_.reset(new ogzstream(target, mode));
|
||||
|
||||
#else /* HAVE_LIBZ */
|
||||
|
||||
streamOpt.compression(IOstreamOption::UNCOMPRESSED);
|
||||
|
||||
Warning
|
||||
<< nl
|
||||
<< "No write support for gz compressed files (libz)"
|
||||
<< " : downgraded to UNCOMPRESSED" << nl
|
||||
<< "file: " << pathname_gz << endl;
|
||||
|
||||
#endif /* HAVE_LIBZ */
|
||||
}
|
||||
|
||||
if (IOstreamOption::COMPRESSED != streamOpt.compression())
|
||||
{
|
||||
const fileName& target = (atomic_ ? pathname_tmp : pathname);
|
||||
|
||||
// Remove old compressed version (if any)
|
||||
fType = Foam::type(pathname_gz, false);
|
||||
if (fType == fileName::SYMLINK || fType == fileName::FILE)
|
||||
{
|
||||
Foam::rm(pathname_gz);
|
||||
}
|
||||
|
||||
// Avoid writing into symlinked files (non-append mode)
|
||||
if (!append || atomic_)
|
||||
{
|
||||
fType = Foam::type(target, false);
|
||||
if (fType == fileName::SYMLINK)
|
||||
{
|
||||
Foam::rm(target);
|
||||
}
|
||||
}
|
||||
|
||||
ptr_.reset(new std::ofstream(target, mode));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::ofstreamPointer::ofstreamPointer
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption::compressionType comp,
|
||||
const bool append,
|
||||
const bool atomic
|
||||
)
|
||||
:
|
||||
ofstreamPointer
|
||||
(
|
||||
pathname,
|
||||
IOstreamOption(IOstreamOption::ASCII, comp),
|
||||
append,
|
||||
atomic
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::ifstreamPointer::open
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption streamOpt // Currently unused
|
||||
)
|
||||
{
|
||||
// Forcibly close old stream (if any)
|
||||
ptr_.reset(nullptr);
|
||||
|
||||
const std::ios_base::openmode mode
|
||||
(
|
||||
std::ios_base::in | std::ios_base::binary
|
||||
@ -110,131 +281,6 @@ Foam::ifstreamPointer::ifstreamPointer
|
||||
}
|
||||
|
||||
|
||||
Foam::ofstreamPointer::ofstreamPointer() noexcept
|
||||
:
|
||||
ptr_(),
|
||||
atomic_(false)
|
||||
{}
|
||||
|
||||
|
||||
Foam::ofstreamPointer::ofstreamPointer(std::nullptr_t)
|
||||
:
|
||||
ptr_(new Foam::ocountstream),
|
||||
atomic_(false)
|
||||
{}
|
||||
|
||||
|
||||
Foam::ofstreamPointer::ofstreamPointer
|
||||
(
|
||||
const fileName& pathname,
|
||||
IOstreamOption::compressionType comp,
|
||||
const bool append,
|
||||
const bool atomic
|
||||
)
|
||||
:
|
||||
ptr_(nullptr),
|
||||
atomic_(atomic)
|
||||
{
|
||||
std::ios_base::openmode mode
|
||||
(
|
||||
std::ios_base::out | std::ios_base::binary
|
||||
);
|
||||
|
||||
if (append)
|
||||
{
|
||||
mode |= std::ios_base::app;
|
||||
|
||||
// Cannot append to gzstream
|
||||
comp = IOstreamOption::UNCOMPRESSED;
|
||||
|
||||
// Cannot use append + atomic operation, without lots of extra work
|
||||
atomic_ = false;
|
||||
}
|
||||
|
||||
|
||||
// When opening new files, remove file variants out of the way.
|
||||
// Eg, opening "file1"
|
||||
// - remove old "file1.gz" (compressed)
|
||||
// - also remove old "file1" if it is a symlink and we are not appending
|
||||
//
|
||||
// Not writing into symlinked files avoids problems with symlinked
|
||||
// initial fields (eg, 0/U -> ../0.orig/U)
|
||||
|
||||
const fileName pathname_gz(pathname + ".gz");
|
||||
const fileName pathname_tmp(pathname + "~tmp~");
|
||||
|
||||
fileName::Type fType = fileName::Type::UNDEFINED;
|
||||
|
||||
if (IOstreamOption::COMPRESSED == comp)
|
||||
{
|
||||
// Output compression requested.
|
||||
|
||||
#ifdef HAVE_LIBZ
|
||||
// TBD:
|
||||
// atomic_ = true; // Always treat COMPRESSED like an atomic
|
||||
|
||||
const fileName& target = (atomic_ ? pathname_tmp : pathname_gz);
|
||||
|
||||
// Remove old uncompressed version (if any)
|
||||
fType = Foam::type(pathname, false);
|
||||
if (fType == fileName::SYMLINK || fType == fileName::FILE)
|
||||
{
|
||||
Foam::rm(pathname);
|
||||
}
|
||||
|
||||
// Avoid writing into symlinked files (non-append mode)
|
||||
if (!append || atomic_)
|
||||
{
|
||||
fType = Foam::type(target, false);
|
||||
if (fType == fileName::SYMLINK)
|
||||
{
|
||||
Foam::rm(target);
|
||||
}
|
||||
}
|
||||
|
||||
ptr_.reset(new ogzstream(target, mode));
|
||||
|
||||
#else /* HAVE_LIBZ */
|
||||
|
||||
comp = IOstreamOption::UNCOMPRESSED;
|
||||
|
||||
Warning
|
||||
<< nl
|
||||
<< "No write support for gz compressed files (libz)"
|
||||
<< " : downgraded to UNCOMPRESSED" << nl
|
||||
<< "file: " << pathname_gz << endl;
|
||||
|
||||
#endif /* HAVE_LIBZ */
|
||||
}
|
||||
|
||||
if (IOstreamOption::COMPRESSED != comp)
|
||||
{
|
||||
const fileName& target = (atomic_ ? pathname_tmp : pathname);
|
||||
|
||||
// Remove old compressed version (if any)
|
||||
fType = Foam::type(pathname_gz, false);
|
||||
if (fType == fileName::SYMLINK || fType == fileName::FILE)
|
||||
{
|
||||
Foam::rm(pathname_gz);
|
||||
}
|
||||
|
||||
// Avoid writing into symlinked files (non-append mode)
|
||||
if (!append || atomic_)
|
||||
{
|
||||
fType = Foam::type(target, false);
|
||||
if (fType == fileName::SYMLINK)
|
||||
{
|
||||
Foam::rm(target);
|
||||
}
|
||||
}
|
||||
|
||||
ptr_.reset(new std::ofstream(target, mode));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::ifstreamPointer::reopen_gz(const std::string& pathname)
|
||||
{
|
||||
#ifdef HAVE_LIBZ
|
||||
|
||||
@ -35,6 +35,27 @@ License
|
||||
Foam::fileName Foam::IOstream::staticName_("stream");
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::IOstream::attach(const std::ios& s)
|
||||
{
|
||||
labelByteSize_ = sizeof(label);
|
||||
scalarByteSize_ = sizeof(scalar);
|
||||
lineNumber_ = 0;
|
||||
|
||||
if (s.good())
|
||||
{
|
||||
setOpened();
|
||||
setGood();
|
||||
}
|
||||
else
|
||||
{
|
||||
setClosed();
|
||||
setState(s.rdstate());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::fileName& Foam::IOstream::name() const
|
||||
|
||||
@ -157,6 +157,9 @@ protected:
|
||||
ioState_ = std::ios_base::goodbit;
|
||||
}
|
||||
|
||||
//- Adjustments when attaching a new stream
|
||||
void attach(const std::ios& s);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@ -102,9 +102,8 @@ public:
|
||||
//- Broadcast buffer content to all processes in communicator.
|
||||
using UPstream::broadcast;
|
||||
|
||||
//- Broadcast content (contiguous or non-contiguous)
|
||||
//- to all processes in communicator.
|
||||
// For \b non-parallel : do nothing.
|
||||
//- Broadcast content (contiguous or non-contiguous) to all
|
||||
//- communicator ranks. Does nothing in \b non-parallel.
|
||||
template<class Type>
|
||||
static void broadcast
|
||||
(
|
||||
@ -112,11 +111,22 @@ public:
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
|
||||
//- Broadcast multiple items to all processes in communicator.
|
||||
// For \b non-parallel : do nothing.
|
||||
//- Broadcast multiple items to all communicator ranks.
|
||||
//- Does nothing in \b non-parallel.
|
||||
template<class Type, class... Args>
|
||||
static void broadcasts(const label comm, Type& arg1, Args&&... args);
|
||||
|
||||
//- Broadcast list content (contiguous or non-contiguous) to all
|
||||
//- communicator ranks. Does nothing in \b non-parallel.
|
||||
// For contiguous list data, this avoids serialization overhead,
|
||||
// but at the expense of an additional broadcast call.
|
||||
template<class ListType>
|
||||
static void broadcastList
|
||||
(
|
||||
ListType& list,
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
|
||||
|
||||
// Gather
|
||||
|
||||
|
||||
@ -80,4 +80,61 @@ void Foam::Pstream::broadcasts(const label comm, Type& arg1, Args&&... args)
|
||||
}
|
||||
|
||||
|
||||
template<class ListType>
|
||||
void Foam::Pstream::broadcastList(ListType& list, const label comm)
|
||||
{
|
||||
if (is_contiguous<typename ListType::value_type>::value)
|
||||
{
|
||||
// List data are contiguous
|
||||
// 1. broadcast the size
|
||||
// 2. resize for receiver list
|
||||
// 3. broadcast contiguous contents
|
||||
|
||||
if (UPstream::is_parallel(comm))
|
||||
{
|
||||
label len(list.size());
|
||||
|
||||
UPstream::broadcast
|
||||
(
|
||||
reinterpret_cast<char*>(&len),
|
||||
sizeof(label),
|
||||
comm,
|
||||
UPstream::masterNo()
|
||||
);
|
||||
|
||||
if (UPstream::is_subrank(comm))
|
||||
{
|
||||
list.resize_nocopy(len);
|
||||
}
|
||||
|
||||
if (len)
|
||||
{
|
||||
UPstream::broadcast
|
||||
(
|
||||
list.data_bytes(),
|
||||
list.size_bytes(),
|
||||
comm,
|
||||
UPstream::masterNo()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (UPstream::is_parallel(comm))
|
||||
{
|
||||
// List data are non-contiguous - serialize/de-serialize
|
||||
|
||||
if (UPstream::master(comm))
|
||||
{
|
||||
OPBstream os(UPstream::masterNo(), comm);
|
||||
os << list;
|
||||
}
|
||||
else // UPstream::is_subrank(comm)
|
||||
{
|
||||
IPBstream is(UPstream::masterNo(), comm);
|
||||
is >> list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -723,7 +723,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
||||
// readScalar determine the validity
|
||||
while
|
||||
(
|
||||
is_.get(c)
|
||||
is_->get(c)
|
||||
&& (
|
||||
isdigit(c)
|
||||
|| c == '+'
|
||||
@ -758,13 +758,13 @@ Foam::Istream& Foam::ISstream::read(token& t)
|
||||
|
||||
syncState();
|
||||
|
||||
if (is_.bad())
|
||||
if (is_->bad())
|
||||
{
|
||||
t.setBad();
|
||||
}
|
||||
else
|
||||
{
|
||||
is_.putback(c);
|
||||
is_->putback(c);
|
||||
|
||||
if (nChar == 1 && buf[0] == '-')
|
||||
{
|
||||
@ -1009,7 +1009,7 @@ Foam::Istream& Foam::ISstream::read(string& str)
|
||||
|
||||
Foam::Istream& Foam::ISstream::read(label& val)
|
||||
{
|
||||
is_ >> val;
|
||||
(*is_) >> val;
|
||||
syncState();
|
||||
return *this;
|
||||
}
|
||||
@ -1017,7 +1017,7 @@ Foam::Istream& Foam::ISstream::read(label& val)
|
||||
|
||||
Foam::Istream& Foam::ISstream::read(float& val)
|
||||
{
|
||||
is_ >> val;
|
||||
(*is_) >> val;
|
||||
syncState();
|
||||
return *this;
|
||||
}
|
||||
@ -1025,7 +1025,7 @@ Foam::Istream& Foam::ISstream::read(float& val)
|
||||
|
||||
Foam::Istream& Foam::ISstream::read(double& val)
|
||||
{
|
||||
is_ >> val;
|
||||
(*is_) >> val;
|
||||
syncState();
|
||||
return *this;
|
||||
}
|
||||
@ -1047,24 +1047,11 @@ Foam::Istream& Foam::ISstream::readRaw(char* data, std::streamsize count)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
is_.read(data, count);
|
||||
is_->read(data, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Forward seek
|
||||
// - use absolute positioning (see C++ notes about std::ifstream)
|
||||
is_.seekg(is_.tellg() + std::istream::pos_type(count));
|
||||
|
||||
// Not sure if this is needed (as per rewind)
|
||||
// some documentation indicates that ifstream needs
|
||||
// seekg with values from a tellg
|
||||
//
|
||||
// stdStream().rdbuf()->pubseekpos
|
||||
// (
|
||||
// count,
|
||||
// std::ios_base::seekdir::cur,
|
||||
// std::ios_base::in
|
||||
// );
|
||||
is_->ignore(count);
|
||||
}
|
||||
}
|
||||
syncState();
|
||||
@ -1083,7 +1070,7 @@ bool Foam::ISstream::beginRawRead()
|
||||
|
||||
readBegin("binaryBlock");
|
||||
syncState();
|
||||
return is_.good();
|
||||
return is_->good();
|
||||
}
|
||||
|
||||
|
||||
@ -1091,7 +1078,7 @@ bool Foam::ISstream::endRawRead()
|
||||
{
|
||||
readEnd("binaryBlock");
|
||||
syncState();
|
||||
return is_.good();
|
||||
return is_->good();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ class ISstream
|
||||
|
||||
fileName name_;
|
||||
|
||||
std::istream& is_;
|
||||
std::istream* is_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
@ -135,10 +135,10 @@ public:
|
||||
// STL stream
|
||||
|
||||
//- Const access to underlying std::istream
|
||||
virtual const std::istream& stdStream() const { return is_; }
|
||||
virtual const std::istream& stdStream() const { return *is_; }
|
||||
|
||||
//- Access to underlying std::istream
|
||||
virtual std::istream& stdStream() { return is_; }
|
||||
virtual std::istream& stdStream() { return *is_; }
|
||||
|
||||
|
||||
// Stream State
|
||||
@ -146,19 +146,19 @@ public:
|
||||
//- Return flags of output stream
|
||||
virtual ios_base::fmtflags flags() const
|
||||
{
|
||||
return is_.flags();
|
||||
return is_->flags();
|
||||
}
|
||||
|
||||
//- Set stream flags
|
||||
virtual ios_base::fmtflags flags(const ios_base::fmtflags f)
|
||||
{
|
||||
return is_.flags(f);
|
||||
return is_->flags(f);
|
||||
}
|
||||
|
||||
//- Set stream state to match that of the std::istream
|
||||
void syncState()
|
||||
{
|
||||
setState(is_.rdstate());
|
||||
setState(is_->rdstate());
|
||||
}
|
||||
|
||||
|
||||
@ -180,6 +180,10 @@ public:
|
||||
const bool stripComments = true
|
||||
);
|
||||
|
||||
//- Associate a different std::istream with the ISstream
|
||||
// \return the previously attached stream
|
||||
inline std::istream& attach(std::istream& is);
|
||||
|
||||
|
||||
// Read Functions
|
||||
|
||||
|
||||
@ -37,9 +37,9 @@ inline Foam::ISstream::ISstream
|
||||
:
|
||||
Istream(streamOpt),
|
||||
name_(streamName),
|
||||
is_(is)
|
||||
is_(&is)
|
||||
{
|
||||
if (is_.good())
|
||||
if (is_->good())
|
||||
{
|
||||
setOpened();
|
||||
setGood();
|
||||
@ -53,9 +53,20 @@ inline Foam::ISstream::ISstream
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
inline std::istream& Foam::ISstream::attach(std::istream& is)
|
||||
{
|
||||
std::istream* old = is_;
|
||||
|
||||
is_ = &is;
|
||||
IOstream::attach(*is_);
|
||||
|
||||
return *old;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::ISstream& Foam::ISstream::get(char& c)
|
||||
{
|
||||
is_.get(c);
|
||||
is_->get(c);
|
||||
syncState();
|
||||
|
||||
if (c == '\n' && good())
|
||||
@ -69,13 +80,13 @@ inline Foam::ISstream& Foam::ISstream::get(char& c)
|
||||
|
||||
inline int Foam::ISstream::peek()
|
||||
{
|
||||
return is_.peek();
|
||||
return is_->peek();
|
||||
}
|
||||
|
||||
|
||||
inline Foam::ISstream& Foam::ISstream::getLine(std::string& str, char delim)
|
||||
{
|
||||
std::getline(is_, str, delim);
|
||||
std::getline(*is_, str, delim);
|
||||
syncState();
|
||||
|
||||
if (delim == '\n')
|
||||
@ -89,10 +100,10 @@ inline Foam::ISstream& Foam::ISstream::getLine(std::string& str, char delim)
|
||||
|
||||
inline std::streamsize Foam::ISstream::getLine(std::nullptr_t, char delim)
|
||||
{
|
||||
is_.ignore(std::numeric_limits<std::streamsize>::max(), delim);
|
||||
is_->ignore(std::numeric_limits<std::streamsize>::max(), delim);
|
||||
syncState();
|
||||
|
||||
std::streamsize count = is_.gcount();
|
||||
std::streamsize count = is_->gcount();
|
||||
|
||||
if (delim == '\n' && count)
|
||||
{
|
||||
@ -110,7 +121,7 @@ inline Foam::ISstream& Foam::ISstream::putback(const char c)
|
||||
--lineNumber_;
|
||||
}
|
||||
|
||||
if (!is_.putback(c))
|
||||
if (!is_->putback(c))
|
||||
{
|
||||
setBad();
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ bool Foam::OSstream::write(const token& tok)
|
||||
|
||||
Foam::Ostream& Foam::OSstream::write(const char c)
|
||||
{
|
||||
os_ << c;
|
||||
(*os_) << c;
|
||||
if (c == token::NL)
|
||||
{
|
||||
++lineNumber_;
|
||||
@ -101,7 +101,7 @@ Foam::Ostream& Foam::OSstream::write(const char c)
|
||||
Foam::Ostream& Foam::OSstream::write(const char* str)
|
||||
{
|
||||
lineNumber_ += stringOps::count(str, token::NL);
|
||||
os_ << str;
|
||||
(*os_) << str;
|
||||
syncState();
|
||||
return *this;
|
||||
}
|
||||
@ -109,7 +109,7 @@ Foam::Ostream& Foam::OSstream::write(const char* str)
|
||||
|
||||
Foam::Ostream& Foam::OSstream::write(const word& str)
|
||||
{
|
||||
os_ << str;
|
||||
(*os_) << str;
|
||||
syncState();
|
||||
return *this;
|
||||
}
|
||||
@ -125,7 +125,7 @@ Foam::Ostream& Foam::OSstream::writeQuoted
|
||||
{
|
||||
// Output unquoted, only advance line number on newline
|
||||
lineNumber_ += stringOps::count(str, token::NL);
|
||||
os_ << str;
|
||||
(*os_) << str;
|
||||
|
||||
syncState();
|
||||
return *this;
|
||||
@ -133,7 +133,7 @@ Foam::Ostream& Foam::OSstream::writeQuoted
|
||||
|
||||
|
||||
// Output with surrounding quotes and backslash escaping
|
||||
os_ << token::DQUOTE;
|
||||
(*os_) << token::DQUOTE;
|
||||
|
||||
unsigned backslash = 0;
|
||||
for (auto iter = str.cbegin(); iter != str.cend(); ++iter)
|
||||
@ -158,16 +158,16 @@ Foam::Ostream& Foam::OSstream::writeQuoted
|
||||
// output all pending backslashes
|
||||
while (backslash)
|
||||
{
|
||||
os_ << '\\';
|
||||
(*os_) << '\\';
|
||||
--backslash;
|
||||
}
|
||||
|
||||
os_ << c;
|
||||
(*os_) << c;
|
||||
}
|
||||
|
||||
// silently drop any trailing backslashes
|
||||
// they would otherwise appear like an escaped end-quote
|
||||
os_ << token::DQUOTE;
|
||||
(*os_) << token::DQUOTE;
|
||||
|
||||
syncState();
|
||||
return *this;
|
||||
@ -182,7 +182,7 @@ Foam::Ostream& Foam::OSstream::write(const string& str)
|
||||
|
||||
Foam::Ostream& Foam::OSstream::write(const int32_t val)
|
||||
{
|
||||
os_ << val;
|
||||
(*os_) << val;
|
||||
syncState();
|
||||
return *this;
|
||||
}
|
||||
@ -190,7 +190,7 @@ Foam::Ostream& Foam::OSstream::write(const int32_t val)
|
||||
|
||||
Foam::Ostream& Foam::OSstream::write(const int64_t val)
|
||||
{
|
||||
os_ << val;
|
||||
(*os_) << val;
|
||||
syncState();
|
||||
return *this;
|
||||
}
|
||||
@ -198,7 +198,7 @@ Foam::Ostream& Foam::OSstream::write(const int64_t val)
|
||||
|
||||
Foam::Ostream& Foam::OSstream::write(const float val)
|
||||
{
|
||||
os_ << val;
|
||||
(*os_) << val;
|
||||
syncState();
|
||||
return *this;
|
||||
}
|
||||
@ -206,7 +206,7 @@ Foam::Ostream& Foam::OSstream::write(const float val)
|
||||
|
||||
Foam::Ostream& Foam::OSstream::write(const double val)
|
||||
{
|
||||
os_ << val;
|
||||
(*os_) << val;
|
||||
syncState();
|
||||
return *this;
|
||||
}
|
||||
@ -231,17 +231,18 @@ bool Foam::OSstream::beginRawWrite(std::streamsize count)
|
||||
<< abort(FatalIOError);
|
||||
}
|
||||
|
||||
os_ << token::BEGIN_LIST;
|
||||
(*os_) << token::BEGIN_LIST;
|
||||
syncState();
|
||||
return os_.good();
|
||||
|
||||
return os_->good();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::OSstream::endRawWrite()
|
||||
{
|
||||
os_ << token::END_LIST;
|
||||
(*os_) << token::END_LIST;
|
||||
syncState();
|
||||
return os_.good();
|
||||
return os_->good();
|
||||
}
|
||||
|
||||
|
||||
@ -254,8 +255,9 @@ Foam::Ostream& Foam::OSstream::writeRaw
|
||||
// No check for IOstreamOption::BINARY since this is either done in the
|
||||
// beginRawWrite() method, or the caller knows what they are doing.
|
||||
|
||||
os_.write(data, count);
|
||||
os_->write(data, count);
|
||||
syncState();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -264,7 +266,7 @@ void Foam::OSstream::indent()
|
||||
{
|
||||
for (unsigned short i = 0; i < indentLevel_*indentSize_; ++i)
|
||||
{
|
||||
os_ << ' ';
|
||||
(*os_) << ' ';
|
||||
}
|
||||
syncState();
|
||||
}
|
||||
@ -272,14 +274,14 @@ void Foam::OSstream::indent()
|
||||
|
||||
void Foam::OSstream::flush()
|
||||
{
|
||||
os_.flush();
|
||||
os_->flush();
|
||||
}
|
||||
|
||||
|
||||
void Foam::OSstream::endl()
|
||||
{
|
||||
write('\n');
|
||||
os_.flush();
|
||||
os_->flush();
|
||||
}
|
||||
|
||||
|
||||
@ -287,37 +289,37 @@ void Foam::OSstream::endl()
|
||||
|
||||
char Foam::OSstream::fill() const
|
||||
{
|
||||
return os_.fill();
|
||||
return os_->fill();
|
||||
}
|
||||
|
||||
|
||||
char Foam::OSstream::fill(const char fillch)
|
||||
{
|
||||
return os_.fill(fillch);
|
||||
return os_->fill(fillch);
|
||||
}
|
||||
|
||||
|
||||
int Foam::OSstream::width() const
|
||||
{
|
||||
return os_.width();
|
||||
return os_->width();
|
||||
}
|
||||
|
||||
|
||||
int Foam::OSstream::width(const int w)
|
||||
{
|
||||
return os_.width(w);
|
||||
return os_->width(w);
|
||||
}
|
||||
|
||||
|
||||
int Foam::OSstream::precision() const
|
||||
{
|
||||
return os_.precision();
|
||||
return os_->precision();
|
||||
}
|
||||
|
||||
|
||||
int Foam::OSstream::precision(const int p)
|
||||
{
|
||||
return os_.precision(p);
|
||||
return os_->precision(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ class OSstream
|
||||
|
||||
fileName name_;
|
||||
|
||||
std::ostream& os_;
|
||||
std::ostream* os_;
|
||||
|
||||
|
||||
public:
|
||||
@ -123,10 +123,10 @@ public:
|
||||
// STL stream
|
||||
|
||||
//- Const access to underlying std::ostream
|
||||
virtual const std::ostream& stdStream() const { return os_; }
|
||||
virtual const std::ostream& stdStream() const { return *os_; }
|
||||
|
||||
//- Access to underlying std::ostream
|
||||
virtual std::ostream& stdStream() { return os_; }
|
||||
virtual std::ostream& stdStream() { return *os_; }
|
||||
|
||||
|
||||
// Stream State
|
||||
@ -134,21 +134,25 @@ public:
|
||||
//- Get stream flags
|
||||
virtual ios_base::fmtflags flags() const
|
||||
{
|
||||
return os_.flags();
|
||||
return os_->flags();
|
||||
}
|
||||
|
||||
//- Set stream flags
|
||||
virtual ios_base::fmtflags flags(const ios_base::fmtflags f)
|
||||
{
|
||||
return os_.flags(f);
|
||||
return os_->flags(f);
|
||||
}
|
||||
|
||||
//- Set stream state to match that of the std::ostream
|
||||
void syncState()
|
||||
{
|
||||
setState(os_.rdstate());
|
||||
setState(os_->rdstate());
|
||||
}
|
||||
|
||||
//- Associate a different std::ostream with the OSstream
|
||||
// \return the previously attached stream
|
||||
inline std::ostream& attach(std::ostream& os);
|
||||
|
||||
|
||||
// Write Functions
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -39,13 +39,13 @@ inline Foam::OSstream::OSstream
|
||||
:
|
||||
Ostream(streamOpt),
|
||||
name_(streamName),
|
||||
os_(os)
|
||||
os_(&os)
|
||||
{
|
||||
if (os_.good())
|
||||
if (os_->good())
|
||||
{
|
||||
setOpened();
|
||||
setGood();
|
||||
os_.precision(precision_);
|
||||
os_->precision(precision_);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -54,4 +54,18 @@ inline Foam::OSstream::OSstream
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline std::ostream& Foam::OSstream::attach(std::ostream& os)
|
||||
{
|
||||
std::ostream* old = os_;
|
||||
|
||||
os_ = &os;
|
||||
IOstream::attach(*os_);
|
||||
// Leave precision untouched
|
||||
|
||||
return *old;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -38,7 +39,14 @@ void Foam::ISstream::print(Ostream& os) const
|
||||
os << "ISstream: " << name().c_str() << ' ';
|
||||
|
||||
IOstream::print(os);
|
||||
IOstream::print(os, is_.rdstate());
|
||||
if (is_)
|
||||
{
|
||||
IOstream::print(os, is_->rdstate());
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "std::stream not attached" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +55,14 @@ void Foam::OSstream::print(Ostream& os) const
|
||||
os << "OSstream: " << name().c_str() << ' ';
|
||||
|
||||
IOstream::print(os);
|
||||
IOstream::print(os, os_.rdstate());
|
||||
if (os_)
|
||||
{
|
||||
IOstream::print(os, os_->rdstate());
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "std::stream not attached" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "argListRedirect.H"
|
||||
#include "OSspecific.H"
|
||||
#include "Switch.H"
|
||||
#include "clock.H"
|
||||
@ -47,6 +48,7 @@ License
|
||||
#include "stringListOps.H"
|
||||
#include "fileOperation.H"
|
||||
#include "fileOperationInitialise.H"
|
||||
#include "fstreamPointer.H"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
@ -911,7 +913,9 @@ Foam::argList::argList
|
||||
runControl_(),
|
||||
args_(argc),
|
||||
options_(argc),
|
||||
libs_()
|
||||
libs_(),
|
||||
stdout_(nullptr),
|
||||
stderr_(nullptr)
|
||||
{
|
||||
// Pre-scan for some options needed for initial setup:
|
||||
// -fileHandler (takes an argument)
|
||||
@ -1018,6 +1022,53 @@ Foam::argList::argList
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Capture stdout/stderr redirection names. Filters argv
|
||||
Detail::redirectOutputs redirects(argc, argv);
|
||||
|
||||
// Perform output redirection
|
||||
if (redirects.active())
|
||||
{
|
||||
word suffix;
|
||||
|
||||
if (redirects.ranks_ && parRunControl_.parRun())
|
||||
{
|
||||
suffix = Foam::name(Pstream::myProcNo());
|
||||
}
|
||||
|
||||
if (!redirects.stdout_.empty())
|
||||
{
|
||||
fileName file(fileName::validate(redirects.stdout_));
|
||||
file.ext(suffix);
|
||||
|
||||
stdout_.reset(ofstreamPointer(file).release());
|
||||
}
|
||||
|
||||
if (!redirects.stderr_.empty())
|
||||
{
|
||||
fileName file(fileName::validate(redirects.stderr_));
|
||||
file.ext(suffix);
|
||||
|
||||
stderr_.reset(ofstreamPointer(file).release());
|
||||
}
|
||||
|
||||
if (stdout_)
|
||||
{
|
||||
Sout.attach(*stdout_);
|
||||
Pout.attach(*stdout_);
|
||||
}
|
||||
|
||||
if (stderr_)
|
||||
{
|
||||
Serr.attach(*stderr_);
|
||||
Perr.attach(*stderr_);
|
||||
}
|
||||
else if (redirects.join_)
|
||||
{
|
||||
Serr.attach(Sout.stdStream());
|
||||
Perr.attach(Sout.stdStream());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Convert argv -> args_ and capture ( ... ) lists
|
||||
regroupArgv(argc, argv);
|
||||
@ -1172,6 +1223,8 @@ Foam::argList::argList
|
||||
args_(args.args_),
|
||||
options_(options),
|
||||
libs_(),
|
||||
stdout_(nullptr),
|
||||
stderr_(nullptr),
|
||||
executable_(args.executable_),
|
||||
rootPath_(args.rootPath_),
|
||||
globalCase_(args.globalCase_),
|
||||
|
||||
@ -146,6 +146,12 @@ class argList
|
||||
//- Additional libraries
|
||||
mutable dlLibraryTable libs_;
|
||||
|
||||
//- File redirection for stdout (Sout, Pout)
|
||||
std::unique_ptr<std::ostream> stdout_;
|
||||
|
||||
//- File redirection for stderr (Serr, Perr)
|
||||
std::unique_ptr<std::ostream> stderr_;
|
||||
|
||||
word executable_;
|
||||
fileName rootPath_;
|
||||
fileName globalCase_;
|
||||
|
||||
@ -425,6 +425,16 @@ void Foam::argList::printUsage(bool full) const
|
||||
}
|
||||
|
||||
|
||||
// Redirections
|
||||
if (full)
|
||||
{
|
||||
printOption("stdout <file>", "Redirect stdout to file");
|
||||
printOption("stderr <file>", "Redirect stderr to file");
|
||||
printOption("join-stderr", "Join stderr to stdout");
|
||||
printOption("append-rank", "Append stdout/stderr files with MPI-rank");
|
||||
}
|
||||
|
||||
|
||||
// Place documentation/help options at the end
|
||||
|
||||
printOption("doc", "Display documentation in browser");
|
||||
|
||||
175
src/OpenFOAM/global/argList/argListRedirect.C
Normal file
175
src/OpenFOAM/global/argList/argListRedirect.C
Normal file
@ -0,0 +1,175 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argListRedirect.H"
|
||||
#include "IOstreams.H"
|
||||
#include "boolList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
inline bool opt_join(const char* optName)
|
||||
{
|
||||
return strcmp(optName, "join-stderr") == 0;
|
||||
}
|
||||
|
||||
inline bool opt_rank(const char* optName)
|
||||
{
|
||||
return strcmp(optName, "append-rank") == 0;
|
||||
}
|
||||
|
||||
inline bool opt_stderr(const char* optName)
|
||||
{
|
||||
return strcmp(optName, "stderr") == 0;
|
||||
}
|
||||
|
||||
inline bool opt_stdout(const char* optName)
|
||||
{
|
||||
return strcmp(optName, "stdout") == 0;
|
||||
}
|
||||
|
||||
} // End anonymous namespace
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Detail::redirectOutputs::redirectOutputs(int& argc, char**& argv)
|
||||
:
|
||||
stdout_(),
|
||||
stderr_(),
|
||||
join_(false),
|
||||
ranks_(false)
|
||||
{
|
||||
List<bool> skip(label(argc), false);
|
||||
bool filter = false;
|
||||
|
||||
for (int argi = 1; argi < argc-1; ++argi)
|
||||
{
|
||||
if (argv[argi][0] == '-')
|
||||
{
|
||||
const char *optName = &argv[argi][1];
|
||||
|
||||
if (opt_join(optName))
|
||||
{
|
||||
join_ = true;
|
||||
filter = true;
|
||||
skip[argi] = true;
|
||||
}
|
||||
else if (opt_rank(optName))
|
||||
{
|
||||
ranks_ = true;
|
||||
filter = true;
|
||||
skip[argi] = true;
|
||||
}
|
||||
else if (opt_stdout(optName))
|
||||
{
|
||||
stdout_ = argv[argi+1];
|
||||
filter = true;
|
||||
skip[argi] = true;
|
||||
skip[argi+1] = true;
|
||||
++argi;
|
||||
}
|
||||
else if (opt_stderr(optName))
|
||||
{
|
||||
stderr_ = argv[argi+1];
|
||||
filter = true;
|
||||
skip[argi] = true;
|
||||
skip[argi+1] = true;
|
||||
++argi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Test final arg separately
|
||||
{
|
||||
const int argi = argc-1;
|
||||
|
||||
if (argi > 0 && argv[argi][0] == '-')
|
||||
{
|
||||
const char *optName = &argv[argi][1];
|
||||
|
||||
if (opt_join(optName))
|
||||
{
|
||||
join_ = true;
|
||||
filter = true;
|
||||
skip[argi] = true;
|
||||
}
|
||||
else if (opt_rank(optName))
|
||||
{
|
||||
ranks_ = true;
|
||||
filter = true;
|
||||
skip[argi] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (filter)
|
||||
{
|
||||
int nArgs = 1;
|
||||
|
||||
for (int argi = 1; argi < argc; ++argi)
|
||||
{
|
||||
if (!skip[argi])
|
||||
{
|
||||
argv[nArgs] = argv[argi];
|
||||
++nArgs;
|
||||
}
|
||||
}
|
||||
argc = nArgs;
|
||||
}
|
||||
|
||||
|
||||
// Resolve potential conflicts
|
||||
|
||||
if (!stderr_.empty())
|
||||
{
|
||||
if (stdout_.empty())
|
||||
{
|
||||
join_ = false;
|
||||
}
|
||||
else if (stdout_ == stderr_)
|
||||
{
|
||||
join_ = true;
|
||||
stderr_.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::Detail::redirectOutputs::active() const
|
||||
{
|
||||
return join_ || !stdout_.empty() || !stderr_.empty();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
86
src/OpenFOAM/global/argList/argListRedirect.H
Normal file
86
src/OpenFOAM/global/argList/argListRedirect.H
Normal file
@ -0,0 +1,86 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 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/>.
|
||||
|
||||
Class
|
||||
Foam::Detail::redirectOutputs
|
||||
|
||||
Description
|
||||
Helper class for redirecting outputs from within argList.
|
||||
Handles the following options:
|
||||
|
||||
\verbatim
|
||||
-stdout <file>
|
||||
-stderr <file>
|
||||
-join-stderr
|
||||
-append-rank
|
||||
\endverbatim
|
||||
|
||||
Note
|
||||
Not intended for general use
|
||||
|
||||
SourceFiles
|
||||
argListRedirect.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef argListRedirect_H
|
||||
#define argListRedirect_H
|
||||
|
||||
#include "string.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace Detail
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class redirectOutputs Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
struct redirectOutputs
|
||||
{
|
||||
string stdout_;
|
||||
string stderr_;
|
||||
bool join_;
|
||||
bool ranks_;
|
||||
|
||||
redirectOutputs(int& argc, char**& argv);
|
||||
|
||||
bool active() const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Detail
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -93,6 +93,25 @@ Foam::patchIdentifier::patchIdentifier
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::patchIdentifier::removeGroup(const word& name)
|
||||
{
|
||||
label idx = name.empty() ? -1 : inGroups_.find(name);
|
||||
|
||||
if (idx >= 0)
|
||||
{
|
||||
for (label i = idx + 1; i < inGroups_.size(); ++i)
|
||||
{
|
||||
if (inGroups_[i] != name)
|
||||
{
|
||||
inGroups_[idx] = std::move(inGroups_[i]);
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
inGroups_.resize(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::patchIdentifier::write(Ostream& os) const
|
||||
{
|
||||
if (!physicalType_.empty())
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -36,8 +36,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef patchIdentifier_H
|
||||
#define patchIdentifier_H
|
||||
#ifndef Foam_patchIdentifier_H
|
||||
#define Foam_patchIdentifier_H
|
||||
|
||||
#include "wordList.H"
|
||||
|
||||
@ -133,59 +133,47 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- The patch name
|
||||
const word& name() const noexcept
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
const word& name() const noexcept { return name_; }
|
||||
|
||||
//- Modifiable patch name
|
||||
word& name() noexcept
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
word& name() noexcept { return name_; }
|
||||
|
||||
//- The index of this patch in the boundaryMesh
|
||||
label index() const noexcept
|
||||
{
|
||||
return index_;
|
||||
}
|
||||
label index() const noexcept { return index_; }
|
||||
|
||||
//- Modifiable index of this patch in the boundaryMesh
|
||||
label& index() noexcept
|
||||
{
|
||||
return index_;
|
||||
}
|
||||
label& index() noexcept { return index_; }
|
||||
|
||||
//- The (optional) physical type of the patch
|
||||
const word& physicalType() const noexcept
|
||||
{
|
||||
return physicalType_;
|
||||
}
|
||||
const word& physicalType() const noexcept { return physicalType_; }
|
||||
|
||||
//- Modifiable (optional) physical type of the patch
|
||||
word& physicalType() noexcept
|
||||
{
|
||||
return physicalType_;
|
||||
}
|
||||
word& physicalType() noexcept { return physicalType_; }
|
||||
|
||||
//- The (optional) groups that the patch belongs to
|
||||
const wordList& inGroups() const noexcept
|
||||
{
|
||||
return inGroups_;
|
||||
}
|
||||
const wordList& inGroups() const noexcept { return inGroups_; }
|
||||
|
||||
//- Modifiable (optional) groups that the patch belongs to
|
||||
wordList& inGroups() noexcept
|
||||
{
|
||||
return inGroups_;
|
||||
}
|
||||
wordList& inGroups() noexcept { return inGroups_; }
|
||||
|
||||
//- True if given name is in a group
|
||||
bool inGroup(const word& name) const
|
||||
{
|
||||
return inGroups_.found(name);
|
||||
return (!name.empty() && inGroups_.contains(name));
|
||||
}
|
||||
|
||||
//- Add (unique) group for the patch
|
||||
void addGroup(const word& name)
|
||||
{
|
||||
if (!name.empty() && !inGroups_.contains(name))
|
||||
{
|
||||
inGroups_.push_back(name);
|
||||
}
|
||||
}
|
||||
|
||||
//- Remove group for the patch
|
||||
void removeGroup(const word& name);
|
||||
|
||||
//- Write (physicalType, inGroups) dictionary entries
|
||||
//- (without surrounding braces)
|
||||
void write(Ostream& os) const;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -92,6 +92,25 @@ Foam::zoneIdentifier::zoneIdentifier
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::zoneIdentifier::removeGroup(const word& name)
|
||||
{
|
||||
label idx = name.empty() ? -1 : inGroups_.find(name);
|
||||
|
||||
if (idx >= 0)
|
||||
{
|
||||
for (label i = idx + 1; i < inGroups_.size(); ++i)
|
||||
{
|
||||
if (inGroups_[i] != name)
|
||||
{
|
||||
inGroups_[idx] = std::move(inGroups_[i]);
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
inGroups_.resize(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::zoneIdentifier::write(Ostream& os) const
|
||||
{
|
||||
if (!physicalType_.empty())
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -38,8 +38,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef zoneIdentifier_H
|
||||
#define zoneIdentifier_H
|
||||
#ifndef Foam_zoneIdentifier_H
|
||||
#define Foam_zoneIdentifier_H
|
||||
|
||||
#include "wordList.H"
|
||||
|
||||
@ -121,59 +121,47 @@ public:
|
||||
// Member Functions
|
||||
|
||||
//- The zone name
|
||||
const word& name() const noexcept
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
const word& name() const noexcept { return name_; }
|
||||
|
||||
//- Modifiable zone name
|
||||
word& name() noexcept
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
word& name() noexcept { return name_; }
|
||||
|
||||
//- The index of this zone in the zone list
|
||||
label index() const noexcept
|
||||
{
|
||||
return index_;
|
||||
}
|
||||
label index() const noexcept { return index_; }
|
||||
|
||||
//- Modifiable index of this zone in the zone list
|
||||
label& index() noexcept
|
||||
{
|
||||
return index_;
|
||||
}
|
||||
label& index() noexcept { return index_; }
|
||||
|
||||
//- The (optional) type of the zone
|
||||
const word& physicalType() const noexcept
|
||||
{
|
||||
return physicalType_;
|
||||
}
|
||||
const word& physicalType() const noexcept { return physicalType_; }
|
||||
|
||||
//- Modifiable (optional) type of the zone
|
||||
word& physicalType() noexcept
|
||||
{
|
||||
return physicalType_;
|
||||
}
|
||||
word& physicalType() noexcept { return physicalType_; }
|
||||
|
||||
//- The (optional) groups that the zone belongs to
|
||||
const wordList& inGroups() const noexcept
|
||||
{
|
||||
return inGroups_;
|
||||
}
|
||||
const wordList& inGroups() const noexcept { return inGroups_; }
|
||||
|
||||
//- Modifiable (optional) groups that the zone belongs to
|
||||
wordList& inGroups() noexcept
|
||||
{
|
||||
return inGroups_;
|
||||
}
|
||||
wordList& inGroups() noexcept { return inGroups_; }
|
||||
|
||||
//- True if given name is in a group
|
||||
bool inGroup(const word& name) const
|
||||
{
|
||||
return inGroups_.found(name);
|
||||
return (!name.empty() && inGroups_.contains(name));
|
||||
}
|
||||
|
||||
//- Add (unique) group for the zone
|
||||
void addGroup(const word& name)
|
||||
{
|
||||
if (!name.empty() && !inGroups_.contains(name))
|
||||
{
|
||||
inGroups_.push_back(name);
|
||||
}
|
||||
}
|
||||
|
||||
//- Remove group for the zone
|
||||
void removeGroup(const word& name);
|
||||
|
||||
//- Write (physicalType, inGroups) dictionary entries
|
||||
//- (without surrounding braces)
|
||||
void write(Ostream& os) const;
|
||||
|
||||
@ -239,7 +239,7 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
|
||||
|
||||
for (const labelPair& connection : nbrData)
|
||||
{
|
||||
allComms.appendUniq(connection);
|
||||
allComms.push_uniq(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,9 +84,7 @@ void Foam::polyBoundaryMesh::calcGroupIDs() const
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
const wordList& groups = patches[patchi].inGroups();
|
||||
|
||||
for (const word& groupName : groups)
|
||||
for (const word& groupName : patches[patchi].inGroups())
|
||||
{
|
||||
groupLookup(groupName).push_back(patchi);
|
||||
}
|
||||
@ -504,34 +502,24 @@ void Foam::polyBoundaryMesh::setGroup
|
||||
|
||||
polyPatchList& patches = *this;
|
||||
|
||||
boolList donePatch(patches.size(), false);
|
||||
boolList pending(patches.size(), true);
|
||||
|
||||
// Add to specified patches
|
||||
for (const label patchi : patchIDs)
|
||||
{
|
||||
patches[patchi].inGroups().push_uniq(groupName);
|
||||
donePatch[patchi] = true;
|
||||
if (pending.test(patchi))
|
||||
{
|
||||
pending.unset(patchi);
|
||||
patches[patchi].addGroup(groupName);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove from other patches
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (!donePatch[patchi])
|
||||
if (pending.test(patchi))
|
||||
{
|
||||
wordList& groups = patches[patchi].inGroups();
|
||||
|
||||
if (groups.found(groupName))
|
||||
{
|
||||
label newi = 0;
|
||||
forAll(groups, i)
|
||||
{
|
||||
if (groups[i] != groupName)
|
||||
{
|
||||
groups[newi++] = groups[i];
|
||||
}
|
||||
}
|
||||
groups.resize(newi);
|
||||
}
|
||||
patches[patchi].removeGroup(groupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -54,7 +54,7 @@ Foam::wallPolyPatch::wallPolyPatch
|
||||
polyPatch(name, size, start, index, bm, patchType)
|
||||
{
|
||||
// wall is not constraint type so add wall group explicitly
|
||||
inGroups().appendUniq(typeName);
|
||||
addGroup(typeName);
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ Foam::wallPolyPatch::wallPolyPatch
|
||||
polyPatch(name, dict, index, bm, patchType)
|
||||
{
|
||||
// wall is not constraint type so add wall group explicitly
|
||||
inGroups().appendUniq(typeName);
|
||||
addGroup(typeName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -102,7 +102,7 @@ Foam::polyPatch::polyPatch
|
||||
{
|
||||
if (constraintType(patchType))
|
||||
{
|
||||
inGroups().appendUniq(patchType);
|
||||
addGroup(patchType);
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ Foam::polyPatch::polyPatch
|
||||
{
|
||||
if (constraintType(patchType))
|
||||
{
|
||||
inGroups().appendUniq(patchType);
|
||||
addGroup(patchType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -129,9 +129,7 @@ void Foam::ZoneMesh<ZoneType, MeshType>::calcGroupIDs() const
|
||||
|
||||
forAll(zones, zonei)
|
||||
{
|
||||
const wordList& groups = zones[zonei].inGroups();
|
||||
|
||||
for (const word& groupName : groups)
|
||||
for (const word& groupName : zones[zonei].inGroups())
|
||||
{
|
||||
groupLookup(groupName).push_back(zonei);
|
||||
}
|
||||
@ -716,34 +714,24 @@ void Foam::ZoneMesh<ZoneType, MeshType>::setGroup
|
||||
|
||||
PtrList<ZoneType>& zones = *this;
|
||||
|
||||
boolList doneZone(zones.size(), false);
|
||||
boolList pending(zones.size(), true);
|
||||
|
||||
// Add to specified zones
|
||||
for (const label zonei : zoneIDs)
|
||||
{
|
||||
zones[zonei].inGroups().push_uniq(groupName);
|
||||
doneZone[zonei] = true;
|
||||
if (pending.test(zonei))
|
||||
{
|
||||
pending.unset(zonei);
|
||||
zones[zonei].addGroup(groupName);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove from other zones
|
||||
forAll(zones, zonei)
|
||||
{
|
||||
if (!doneZone[zonei])
|
||||
if (pending.test(zonei))
|
||||
{
|
||||
wordList& groups = zones[zonei].inGroups();
|
||||
|
||||
if (groups.found(groupName))
|
||||
{
|
||||
label newi = 0;
|
||||
forAll(groups, i)
|
||||
{
|
||||
if (groups[i] != groupName)
|
||||
{
|
||||
groups[newi++] = groups[i];
|
||||
}
|
||||
}
|
||||
groups.resize(newi);
|
||||
}
|
||||
zones[zonei].removeGroup(groupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,16 +184,16 @@ public:
|
||||
//- Same as contains(), searches the hash.
|
||||
bool found(const word& val) const { return this->contains(val); }
|
||||
|
||||
//- Append an element if not already in the list.
|
||||
//- Same as push_uniq()
|
||||
FOAM_DEPRECATED_FOR(2022-05, "push_uniq method")
|
||||
void append(const word& val) { this->push_uniq(val); }
|
||||
|
||||
//- Append an element if not already in the list.
|
||||
//- Same as push_uniq()
|
||||
FOAM_DEPRECATED_FOR(2022-10, "push_uniq method")
|
||||
void push_back(const word& val) { this->push_uniq(val); }
|
||||
|
||||
//- Append an element if not already in the list.
|
||||
//FOAM_DEPRECATED_FOR(2022-10, "push_uniq method")
|
||||
//- Same as push_uniq()
|
||||
FOAM_DEPRECATED_STRICT(2022-10, "push_uniq method")
|
||||
label appendUniq(const word& val) { return this->push_uniq(val); }
|
||||
};
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@ Description
|
||||
|
||||
#include "direction.H"
|
||||
#include <type_traits> // For std::integral_constant, std::void_t (C++17)
|
||||
#include <utility> // For declval
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -163,6 +164,31 @@ struct pTraits_has_zero
|
||||
{};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Container Traits
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- Test for containers with begin/end range iterators.
|
||||
template<class T, class = void>
|
||||
struct is_range : std::false_type {};
|
||||
|
||||
//- Test for list containers with begin/end range iterators.
|
||||
//- \attention May yield a false positive with HashTable, HashSet etc
|
||||
template<class T>
|
||||
struct is_range
|
||||
<
|
||||
T,
|
||||
stdFoam::void_t
|
||||
<
|
||||
decltype(std::declval<T>().begin()),
|
||||
decltype(std::declval<T>().end())
|
||||
>
|
||||
>
|
||||
:
|
||||
std::true_type
|
||||
{};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -613,19 +613,6 @@ void Foam::PstreamDetail::allToAllConsensus
|
||||
int flag = 0;
|
||||
MPI_Status status;
|
||||
|
||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||
MPI_Message message;
|
||||
MPI_Improbe
|
||||
(
|
||||
MPI_ANY_SOURCE,
|
||||
tag,
|
||||
PstreamGlobals::MPICommunicators_[comm],
|
||||
&flag,
|
||||
&message,
|
||||
&status
|
||||
);
|
||||
#else
|
||||
MPI_Iprobe
|
||||
(
|
||||
MPI_ANY_SOURCE,
|
||||
@ -634,7 +621,6 @@ void Foam::PstreamDetail::allToAllConsensus
|
||||
&flag,
|
||||
&status
|
||||
);
|
||||
#endif
|
||||
|
||||
if (flag)
|
||||
{
|
||||
@ -654,17 +640,6 @@ void Foam::PstreamDetail::allToAllConsensus
|
||||
|
||||
// Regular blocking receive [the data are small]
|
||||
|
||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||
MPI_Mrecv
|
||||
(
|
||||
&recvData[proci],
|
||||
count, // count=1 (see above)
|
||||
datatype,
|
||||
&message,
|
||||
MPI_STATUS_IGNORE
|
||||
);
|
||||
#else
|
||||
MPI_Recv
|
||||
(
|
||||
&recvData[proci],
|
||||
@ -675,7 +650,6 @@ void Foam::PstreamDetail::allToAllConsensus
|
||||
PstreamGlobals::MPICommunicators_[comm],
|
||||
MPI_STATUS_IGNORE
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (barrier_active)
|
||||
|
||||
@ -212,7 +212,7 @@ Foam::wordList Foam::fvMeshDistribute::mergeWordList(const wordList& procNames)
|
||||
{
|
||||
for (const word& name : names)
|
||||
{
|
||||
mergedNames.appendUniq(name);
|
||||
mergedNames.push_uniq(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -55,41 +55,37 @@ Foam::label Foam::polyMeshAdder::patchIndex
|
||||
const word& pType = p.type();
|
||||
const word& pName = p.name();
|
||||
|
||||
const label patchi = allPatchNames.find(pName);
|
||||
label patchi = allPatchNames.find(pName);
|
||||
|
||||
if (patchi == -1)
|
||||
if (patchi < 0)
|
||||
{
|
||||
// Patch not found. Append to the list
|
||||
allPatchNames.append(pName);
|
||||
allPatchTypes.append(pType);
|
||||
// Not found - add to the lists
|
||||
patchi = allPatchNames.size();
|
||||
|
||||
return allPatchNames.size() - 1;
|
||||
allPatchNames.push_back(pName);
|
||||
allPatchTypes.push_back(pType);
|
||||
}
|
||||
else if (allPatchTypes[patchi] == pType)
|
||||
{
|
||||
// Found name and types match
|
||||
return patchi;
|
||||
}
|
||||
else
|
||||
else if (allPatchTypes[patchi] != pType)
|
||||
{
|
||||
// Found the name, but type is different
|
||||
patchi = allPatchNames.size();
|
||||
|
||||
// Duplicate name is not allowed. Create a composite name from the
|
||||
// patch name and case name
|
||||
const word& caseName = p.boundaryMesh().mesh().time().caseName();
|
||||
|
||||
allPatchNames.append(pName + "_" + caseName);
|
||||
allPatchTypes.append(pType);
|
||||
allPatchNames.push_back(pName + "_" + caseName);
|
||||
allPatchTypes.push_back(pType);
|
||||
|
||||
Pout<< "label patchIndex(const polyPatch& p) : "
|
||||
<< "Patch " << p.index() << " named "
|
||||
<< pName << " in mesh " << caseName
|
||||
<< " already exists, but patch types"
|
||||
<< " do not match.\nCreating a composite name as "
|
||||
<< allPatchNames.last() << endl;
|
||||
|
||||
return allPatchNames.size() - 1;
|
||||
<< allPatchNames.back() << endl;
|
||||
}
|
||||
|
||||
return patchi;
|
||||
}
|
||||
|
||||
|
||||
@ -100,19 +96,17 @@ Foam::label Foam::polyMeshAdder::zoneIndex
|
||||
DynamicList<word>& names
|
||||
)
|
||||
{
|
||||
const label zoneI = names.find(curName);
|
||||
label zonei = names.find(curName);
|
||||
|
||||
if (zoneI != -1)
|
||||
if (zonei < 0)
|
||||
{
|
||||
return zoneI;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not found. Add new name to the list
|
||||
names.append(curName);
|
||||
// Not found - add to the list
|
||||
zonei = names.size();
|
||||
|
||||
return names.size() - 1;
|
||||
names.push_back(curName);
|
||||
}
|
||||
|
||||
return zonei;
|
||||
}
|
||||
|
||||
|
||||
@ -129,8 +123,8 @@ void Foam::polyMeshAdder::mergePatchNames
|
||||
)
|
||||
{
|
||||
// Insert the mesh0 patches and zones
|
||||
allPatchNames.append(patches0.names());
|
||||
allPatchTypes.append(patches0.types());
|
||||
allPatchNames.push_back(patches0.names());
|
||||
allPatchTypes.push_back(patches0.types());
|
||||
|
||||
|
||||
// Patches
|
||||
@ -165,34 +159,6 @@ void Foam::polyMeshAdder::mergePatchNames
|
||||
}
|
||||
|
||||
|
||||
Foam::labelList Foam::polyMeshAdder::getPatchStarts
|
||||
(
|
||||
const polyBoundaryMesh& patches
|
||||
)
|
||||
{
|
||||
labelList patchStarts(patches.size());
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
patchStarts[patchi] = patches[patchi].start();
|
||||
}
|
||||
return patchStarts;
|
||||
}
|
||||
|
||||
|
||||
Foam::labelList Foam::polyMeshAdder::getPatchSizes
|
||||
(
|
||||
const polyBoundaryMesh& patches
|
||||
)
|
||||
{
|
||||
labelList patchSizes(patches.size());
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
patchSizes[patchi] = patches[patchi].size();
|
||||
}
|
||||
return patchSizes;
|
||||
}
|
||||
|
||||
|
||||
Foam::List<Foam::polyPatch*> Foam::polyMeshAdder::combinePatches
|
||||
(
|
||||
const polyMesh& mesh0,
|
||||
@ -916,8 +882,7 @@ void Foam::polyMeshAdder::mergePointZones
|
||||
}
|
||||
else if (pointToZone[allPointi] != zoneI)
|
||||
{
|
||||
labelList& pZones = addPointToZones[allPointi];
|
||||
pZones.appendUniq(zoneI);
|
||||
addPointToZones[allPointi].push_uniq(zoneI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -939,8 +904,7 @@ void Foam::polyMeshAdder::mergePointZones
|
||||
}
|
||||
else if (pointToZone[allPointi] != allZoneI)
|
||||
{
|
||||
labelList& pZones = addPointToZones[allPointi];
|
||||
pZones.appendUniq(allZoneI);
|
||||
addPointToZones[allPointi].push_uniq(allZoneI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1066,12 +1030,9 @@ void Foam::polyMeshAdder::mergeFaceZones
|
||||
}
|
||||
else if (faceToZone[allFacei] != zoneI)
|
||||
{
|
||||
labelList& fZones = addFaceToZones[allFacei];
|
||||
boolList& flipZones = addFaceToFlips[allFacei];
|
||||
|
||||
if (fZones.appendUniq(zoneI))
|
||||
if (addFaceToZones[allFacei].push_uniq(zoneI))
|
||||
{
|
||||
flipZones.append(flip0);
|
||||
addFaceToFlips[allFacei].push_back(flip0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1108,12 +1069,9 @@ void Foam::polyMeshAdder::mergeFaceZones
|
||||
}
|
||||
else if (faceToZone[allFacei] != allZoneI)
|
||||
{
|
||||
labelList& fZones = addFaceToZones[allFacei];
|
||||
boolList& flipZones = addFaceToFlips[allFacei];
|
||||
|
||||
if (fZones.appendUniq(allZoneI))
|
||||
if (addFaceToZones[allFacei].push_uniq(allZoneI))
|
||||
{
|
||||
flipZones.append(flip1);
|
||||
addFaceToFlips[allFacei].push_back(flip1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1231,8 +1189,7 @@ void Foam::polyMeshAdder::mergeCellZones
|
||||
}
|
||||
else if (cellToZone[cell0] != zoneI)
|
||||
{
|
||||
labelList& cZones = addCellToZones[cell0];
|
||||
cZones.appendUniq(zoneI);
|
||||
addCellToZones[cell0].push_uniq(zoneI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1253,8 +1210,7 @@ void Foam::polyMeshAdder::mergeCellZones
|
||||
}
|
||||
else if (cellToZone[allCelli] != allZoneI)
|
||||
{
|
||||
labelList& cZones = addCellToZones[allCelli];
|
||||
cZones.appendUniq(allZoneI);
|
||||
addCellToZones[allCelli].push_uniq(allZoneI);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1625,8 +1581,8 @@ Foam::autoPtr<Foam::polyMesh> Foam::polyMeshAdder::add
|
||||
|
||||
from0ToAllPatches,
|
||||
from1ToAllPatches,
|
||||
getPatchSizes(patches0),
|
||||
getPatchStarts(patches0)
|
||||
patches0.patchSizes(),
|
||||
patches0.patchStarts()
|
||||
)
|
||||
);
|
||||
|
||||
@ -1793,8 +1749,8 @@ Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::polyMeshAdder::add
|
||||
|
||||
|
||||
// Store mesh0 patch info before modifying patches0.
|
||||
labelList mesh0PatchSizes(getPatchSizes(patches0));
|
||||
labelList mesh0PatchStarts(getPatchStarts(patches0));
|
||||
labelList mesh0PatchSizes(patches0.patchSizes());
|
||||
labelList mesh0PatchStarts(patches0.patchStarts());
|
||||
|
||||
// Map from 0 to all patches (since gets compacted)
|
||||
labelList from0ToAllPatches(patches0.size(), -1);
|
||||
|
||||
@ -86,11 +86,6 @@ class polyMeshAdder
|
||||
labelList& fromAllTo1Patches
|
||||
);
|
||||
|
||||
//- Get starts of patches
|
||||
static labelList getPatchStarts(const polyBoundaryMesh&);
|
||||
//- Get sizes of patches
|
||||
static labelList getPatchSizes(const polyBoundaryMesh&);
|
||||
|
||||
static List<polyPatch*> combinePatches
|
||||
(
|
||||
const polyMesh& mesh0,
|
||||
|
||||
@ -262,7 +262,7 @@ bool Foam::combineFaces::faceNeighboursValid
|
||||
}
|
||||
else
|
||||
{
|
||||
neighbourFaces.appendUniq(nbrI);
|
||||
neighbourFaces.push_uniq(nbrI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -1810,9 +1810,7 @@ bool Foam::hexRef8::matchHexShape
|
||||
{
|
||||
reverse(verts);
|
||||
}
|
||||
quads.append(face(0));
|
||||
labelList& quadVerts = quads.last();
|
||||
quadVerts.transfer(verts);
|
||||
quads.emplace_back(verts);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1837,26 +1835,11 @@ bool Foam::hexRef8::matchHexShape
|
||||
{
|
||||
// Add to pointFaces for any level+1 point (this might be
|
||||
// a midpoint of a split face)
|
||||
forAll(f, fp)
|
||||
for (const label pointi : f)
|
||||
{
|
||||
label pointi = f[fp];
|
||||
if (pointLevel_[pointi] == cellLevel+1)
|
||||
{
|
||||
auto iter = pointFaces.find(pointi);
|
||||
|
||||
if (iter.good())
|
||||
{
|
||||
labelList& pFaces = iter.val();
|
||||
pFaces.appendUniq(facei);
|
||||
}
|
||||
else
|
||||
{
|
||||
pointFaces.insert
|
||||
(
|
||||
pointi,
|
||||
labelList(one{}, facei)
|
||||
);
|
||||
}
|
||||
pointFaces(pointi).push_uniq(facei);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1906,9 +1889,7 @@ bool Foam::hexRef8::matchHexShape
|
||||
|
||||
if (verts.size() == 4)
|
||||
{
|
||||
quads.append(face(0));
|
||||
labelList& quadVerts = quads.last();
|
||||
quadVerts.transfer(verts);
|
||||
quads.emplace_back(verts);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2387,6 +2368,8 @@ Foam::labelList Foam::hexRef8::consistentSlowRefinement
|
||||
|
||||
const refinementData& ownData = allCellInfo[faceOwner[facei]];
|
||||
|
||||
label maxDataCount = ownData.count();
|
||||
|
||||
if (mesh_.isInternalFace(facei))
|
||||
{
|
||||
// Seed face if neighbouring cell (after possible refinement)
|
||||
@ -2394,46 +2377,18 @@ Foam::labelList Foam::hexRef8::consistentSlowRefinement
|
||||
|
||||
const refinementData& neiData = allCellInfo[faceNeighbour[facei]];
|
||||
|
||||
label faceCount;
|
||||
label faceRefineCount;
|
||||
if (neiData.count() > ownData.count())
|
||||
if (maxDataCount < neiData.count())
|
||||
{
|
||||
faceCount = neiData.count() + maxFaceDiff;
|
||||
faceRefineCount = faceCount + maxFaceDiff;
|
||||
maxDataCount = neiData.count();
|
||||
}
|
||||
else
|
||||
{
|
||||
faceCount = ownData.count() + maxFaceDiff;
|
||||
faceRefineCount = faceCount + maxFaceDiff;
|
||||
}
|
||||
|
||||
seedFaces.append(facei);
|
||||
seedFacesInfo.append
|
||||
(
|
||||
refinementData
|
||||
(
|
||||
faceRefineCount,
|
||||
faceCount
|
||||
)
|
||||
);
|
||||
allFaceInfo[facei] = seedFacesInfo.last();
|
||||
}
|
||||
else
|
||||
{
|
||||
label faceCount = ownData.count() + maxFaceDiff;
|
||||
label faceRefineCount = faceCount + maxFaceDiff;
|
||||
|
||||
seedFaces.append(facei);
|
||||
seedFacesInfo.append
|
||||
(
|
||||
refinementData
|
||||
(
|
||||
faceRefineCount,
|
||||
faceCount
|
||||
)
|
||||
);
|
||||
allFaceInfo[facei] = seedFacesInfo.last();
|
||||
}
|
||||
label faceCount = maxDataCount + maxFaceDiff;
|
||||
label faceRefineCount = faceCount + maxFaceDiff;
|
||||
|
||||
seedFaces.push_back(facei);
|
||||
allFaceInfo[facei] =
|
||||
seedFacesInfo.emplace_back(faceRefineCount, faceCount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -57,12 +57,10 @@ void Foam::enrichedPatch::calcPointPoints() const
|
||||
DynamicList<label>& curPp = pp[curFace[pointi]];
|
||||
|
||||
// Do next label
|
||||
const label next = curFace.nextLabel(pointi);
|
||||
curPp.appendUniq(next);
|
||||
curPp.push_uniq(curFace.nextLabel(pointi));
|
||||
|
||||
// Do previous label
|
||||
const label prev = curFace.prevLabel(pointi);
|
||||
curPp.appendUniq(prev);
|
||||
curPp.push_uniq(curFace.prevLabel(pointi));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -32,11 +32,11 @@ License
|
||||
template<class Type>
|
||||
Type& Foam::glTF::List<Type>::create(const word& name)
|
||||
{
|
||||
Type obj(name);
|
||||
obj.id() = data_.size();
|
||||
data_.append(obj);
|
||||
const label id = data_.size();
|
||||
Type& obj = data_.emplace_back(name);
|
||||
obj.id() = id;
|
||||
|
||||
return data_.last();
|
||||
return data_.back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -80,9 +80,7 @@ void Foam::faBoundaryMesh::calcGroupIDs() const
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
const wordList& groups = patches[patchi].inGroups();
|
||||
|
||||
for (const word& groupName : groups)
|
||||
for (const word& groupName : patches[patchi].inGroups())
|
||||
{
|
||||
groupLookup(groupName).push_back(patchi);
|
||||
}
|
||||
@ -366,34 +364,24 @@ void Foam::faBoundaryMesh::setGroup
|
||||
|
||||
faPatchList& patches = *this;
|
||||
|
||||
boolList donePatch(patches.size(), false);
|
||||
boolList pending(patches.size(), true);
|
||||
|
||||
// Add to specified patches
|
||||
for (const label patchi : patchIDs)
|
||||
{
|
||||
patches[patchi].inGroups().push_uniq(groupName);
|
||||
donePatch[patchi] = true;
|
||||
if (pending.test(patchi))
|
||||
{
|
||||
pending.unset(patchi);
|
||||
patches[patchi].addGroup(groupName);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove from other patches
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (!donePatch[patchi])
|
||||
if (pending.test(patchi))
|
||||
{
|
||||
wordList& groups = patches[patchi].inGroups();
|
||||
|
||||
if (groups.found(groupName))
|
||||
{
|
||||
label newi = 0;
|
||||
forAll(groups, i)
|
||||
{
|
||||
if (groups[i] != groupName)
|
||||
{
|
||||
groups[newi++] = groups[i];
|
||||
}
|
||||
}
|
||||
groups.resize(newi);
|
||||
}
|
||||
patches[patchi].removeGroup(groupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ Foam::faPatch::faPatch
|
||||
{
|
||||
if (constraintType(patchType))
|
||||
{
|
||||
inGroups().appendUniq(patchType);
|
||||
addGroup(patchType);
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ Foam::faPatch::faPatch
|
||||
{
|
||||
if (constraintType(patchType))
|
||||
{
|
||||
inGroups().appendUniq(patchType);
|
||||
addGroup(patchType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -176,7 +176,7 @@ void Foam::CFCFaceToCellStencil::calcCellStencil
|
||||
label nbrGlobali = globalNumbering().toGlobal(nbrFacei);
|
||||
|
||||
// Note:should use hashset?
|
||||
allGlobalFaces.appendUniq(nbrGlobali);
|
||||
allGlobalFaces.push_uniq(nbrGlobali);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,7 +188,7 @@ void Foam::CFCFaceToCellStencil::calcCellStencil
|
||||
for (const label nbrGlobali : nbrGlobalFaces)
|
||||
{
|
||||
// Note:should use hashset?
|
||||
allGlobalFaces.appendUniq(nbrGlobali);
|
||||
allGlobalFaces.push_uniq(nbrGlobali);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,12 +250,7 @@ Foam::CollisionRecordList<PairType, WallType>::matchPairRecord
|
||||
// member of the list. Setting the status of the record to be accessed
|
||||
// on construction.
|
||||
|
||||
pairRecords_.append
|
||||
(
|
||||
PairCollisionRecord<PairType>(true, origProcOfOther, origIdOfOther)
|
||||
);
|
||||
|
||||
return pairRecords_.last();
|
||||
return pairRecords_.emplace_back(true, origProcOfOther, origIdOfOther);
|
||||
}
|
||||
|
||||
|
||||
@ -307,9 +302,7 @@ Foam::CollisionRecordList<PairType, WallType>::matchWallRecord
|
||||
// member of the list. Setting the status of the record to be accessed
|
||||
// on construction.
|
||||
|
||||
wallRecords_.append(WallCollisionRecord<WallType>(true, pRel));
|
||||
|
||||
return wallRecords_.last();
|
||||
return wallRecords_.emplace_back(true, pRel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1967,16 +1967,8 @@ void Foam::snappyLayerDriver::getPatchDisplacement
|
||||
// const label patchFacei = pFaces[pFacei];
|
||||
// const label meshFacei = pp.addressing()[patchFacei];
|
||||
// const label celli = mesh.faceOwner()[meshFacei];
|
||||
// Map<labelList>::iterator faceFnd = cellToFaces.find(celli);
|
||||
// if (faceFnd.good())
|
||||
// {
|
||||
// labelList& faces = faceFnd();
|
||||
// faces.appendUniq(patchFacei);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cellToFaces.insert(celli, labelList(one{}, patchFacei));
|
||||
// }
|
||||
//
|
||||
// cellToFaces(celli).push_uniq(patchFacei);
|
||||
// }
|
||||
//
|
||||
// forAllConstIters(cellToFaces, iter)
|
||||
|
||||
@ -107,7 +107,7 @@ void Foam::cellDistFuncs::getPointNeighbours
|
||||
|
||||
for (const label nbr : faceNeighbours)
|
||||
{
|
||||
neighbours.appendUniq(nbr);
|
||||
neighbours.push_uniq(nbr);
|
||||
}
|
||||
|
||||
// Add all point-only neighbours by linear searching in edge neighbours.
|
||||
@ -125,7 +125,7 @@ void Foam::cellDistFuncs::getPointNeighbours
|
||||
for (const label facei : pointNbs)
|
||||
{
|
||||
// Check for facei in edge-neighbours part of neighbours
|
||||
neighbours.appendUniq(facei);
|
||||
neighbours.push_uniq(facei);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -56,7 +56,7 @@ Foam::mappedPolyPatch::mappedPolyPatch
|
||||
mappedPatchBase(static_cast<const polyPatch&>(*this))
|
||||
{
|
||||
// mapped is not constraint type so add mapped group explicitly
|
||||
inGroups().appendUniq(typeName);
|
||||
addGroup(typeName);
|
||||
}
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ Foam::mappedPolyPatch::mappedPolyPatch
|
||||
mappedPatchBase(*this, dict)
|
||||
{
|
||||
// mapped is not constraint type so add mapped group explicitly
|
||||
inGroups().appendUniq(typeName);
|
||||
addGroup(typeName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -62,7 +62,7 @@ Foam::mappedWallPolyPatch::mappedWallPolyPatch
|
||||
mappedPatchBase(static_cast<const polyPatch&>(*this))
|
||||
{
|
||||
// mapped is not constraint type so add mapped group explicitly
|
||||
inGroups().appendUniq(mappedPolyPatch::typeName);
|
||||
addGroup(mappedPolyPatch::typeName);
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +129,7 @@ Foam::mappedWallPolyPatch::mappedWallPolyPatch
|
||||
mappedPatchBase(*this, dict)
|
||||
{
|
||||
// mapped is not constraint type so add mapped group explicitly
|
||||
inGroups().appendUniq(mappedPolyPatch::typeName);
|
||||
addGroup(mappedPolyPatch::typeName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -56,7 +56,7 @@ Foam::oversetPolyPatch::oversetPolyPatch
|
||||
masterPatchID_(-1)
|
||||
{
|
||||
// 'overset' is not constraint type so add to group explicitly
|
||||
inGroups().appendUniq(typeName);
|
||||
addGroup(typeName);
|
||||
}
|
||||
|
||||
|
||||
@ -73,7 +73,7 @@ Foam::oversetPolyPatch::oversetPolyPatch
|
||||
masterPatchID_(-1)
|
||||
{
|
||||
// 'overset' is not constraint type so add to group explicitly
|
||||
inGroups().appendUniq(typeName);
|
||||
addGroup(typeName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -166,9 +166,9 @@ void Foam::meshToMeshMethod::appendNbrCells
|
||||
// filter out cells already visited from cell neighbours
|
||||
for (const label nbrCelli : nbrCells)
|
||||
{
|
||||
if (!visitedCells.found(nbrCelli))
|
||||
if (!visitedCells.contains(nbrCelli))
|
||||
{
|
||||
nbrCellIDs.appendUniq(nbrCelli);
|
||||
nbrCellIDs.push_uniq(nbrCelli);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -245,9 +245,9 @@ public:
|
||||
autoPtr<sampledSet> operator()(Istream& is) const
|
||||
{
|
||||
word name(is);
|
||||
capture_.append(dictionary(is));
|
||||
dictionary& dict = capture_.emplace_back(is);
|
||||
|
||||
return sampledSet::New(name, mesh_, search_, capture_.last());
|
||||
return sampledSet::New(name, mesh_, search_, dict);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -225,9 +225,9 @@ public:
|
||||
autoPtr<sampledSurface> operator()(Istream& is) const
|
||||
{
|
||||
word name(is);
|
||||
capture_.append(dictionary(is));
|
||||
dictionary& dict = capture_.emplace_back(is);
|
||||
|
||||
return sampledSurface::New(name, mesh_, capture_.last());
|
||||
return sampledSurface::New(name, mesh_, dict);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -801,8 +801,7 @@ void Foam::isoSurfaceTopo::triangulateOutside
|
||||
{
|
||||
if (loop.size() > 2)
|
||||
{
|
||||
compactFaces.append(face(loop.size()));
|
||||
face& f = compactFaces.last();
|
||||
face& f = compactFaces.emplace_back(loop.size());
|
||||
|
||||
label fpi = 0;
|
||||
forAll(f, i)
|
||||
@ -1072,7 +1071,7 @@ Foam::isoSurfaceTopo::isoSurfaceTopo
|
||||
);
|
||||
}
|
||||
}
|
||||
startTri.last() = tetCutAddr.nFaces();
|
||||
startTri.back() = tetCutAddr.nFaces();
|
||||
|
||||
// Information not needed anymore:
|
||||
tetBasePtIs.clear();
|
||||
@ -1080,7 +1079,7 @@ Foam::isoSurfaceTopo::isoSurfaceTopo
|
||||
|
||||
|
||||
// From list of vertices -> triangular faces
|
||||
faceList allTriFaces(startTri.last());
|
||||
faceList allTriFaces(startTri.back());
|
||||
{
|
||||
auto& verts = tetCutAddr.cutPoints();
|
||||
|
||||
@ -1097,7 +1096,7 @@ Foam::isoSurfaceTopo::isoSurfaceTopo
|
||||
|
||||
|
||||
// The cells cut by the triangular faces
|
||||
meshCells_.resize(startTri.last());
|
||||
meshCells_.resize(startTri.back());
|
||||
for (label celli = 0; celli < startTri.size()-1; ++celli)
|
||||
{
|
||||
// All triangles for the current cell
|
||||
|
||||
@ -93,7 +93,7 @@ Foam::solidReaction<ReactionThermo>::solidReaction
|
||||
speciesTable allSpecies(species);
|
||||
for (const word& gasName : pyrolisisGases_)
|
||||
{
|
||||
allSpecies.appendUniq(gasName);
|
||||
allSpecies.push_uniq(gasName);
|
||||
}
|
||||
List<specieCoeffs> dummyLhs;
|
||||
List<specieCoeffs> dummyRhs;
|
||||
|
||||
Reference in New Issue
Block a user