/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "edgeMesh.H"
#include "bitSet.H"
#include "edgeHashes.H"
#include "mergePoints.H"
#include "ListOps.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(edgeMesh, 0);
defineRunTimeSelectionTable(edgeMesh, fileExtension);
defineMemberFunctionSelectionTable(edgeMesh,write,fileExtension);
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::wordHashSet Foam::edgeMesh::readTypes()
{
return wordHashSet(*fileExtensionConstructorTablePtr_);
}
Foam::wordHashSet Foam::edgeMesh::writeTypes()
{
return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
}
bool Foam::edgeMesh::canReadType(const word& fileType, bool verbose)
{
return checkSupport
(
readTypes(),
fileType,
verbose,
"reading"
);
}
bool Foam::edgeMesh::canWriteType(const word& fileType, bool verbose)
{
return checkSupport
(
writeTypes(),
fileType,
verbose,
"writing"
);
}
bool Foam::edgeMesh::canRead(const fileName& name, bool verbose)
{
const word ext =
(
name.has_ext("gz")
? name.stem().ext()
: name.ext()
);
return canReadType(ext, verbose);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::edgeMesh::calcPointEdges() const
{
if (pointEdgesPtr_)
{
FatalErrorInFunction
<< "pointEdges already calculated."
<< abort(FatalError);
}
pointEdgesPtr_.reset(new labelListList(points_.size()));
auto& pointEdges = *pointEdgesPtr_;
invertManyToMany(pointEdges.size(), edges_, pointEdges);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::edgeMesh::clear()
{
points_.clear();
edges_.clear();
pointEdgesPtr_.reset(nullptr);
}
void Foam::edgeMesh::transfer(edgeMesh& mesh)
{
if (&mesh == this)
{
return; // Self-transfer is a no-op
}
points_.transfer(mesh.points_);
edges_.transfer(mesh.edges_);
pointEdgesPtr_ = std::move(mesh.pointEdgesPtr_);
}
Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
{
edgeRegion.setSize(edges_.size());
edgeRegion = -1;
label startEdgeI = 0;
label currentRegion = 0;
while (true)
{
while (startEdgeI < edges_.size() && edgeRegion[startEdgeI] != -1)
{
startEdgeI++;
}
if (startEdgeI == edges_.size())
{
break;
}
// Found edge that has not yet been assigned a region.
// Mark connected region with currentRegion starting at startEdgeI.
edgeRegion[startEdgeI] = currentRegion;
labelList edgesToVisit(1, startEdgeI);
while (edgesToVisit.size())
{
// neighbours of current edgesToVisit
DynamicList