Commit 431c9632 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add IOobject-based constructors for meshed surfaces (#1600)

- refactor logic from triSurfaceMesh for triSurface, MeshedSurface,
  UnsortedMeshedSurface.

  Makes it easier to locate and use surface files without the
  triSurfaceMesh (meshTools) infrastructure.

STYLE: remove unused sampledTriSurfaceMesh constructors
parent de4c728e
......@@ -47,97 +47,6 @@ Foam::word Foam::triSurfaceMesh::meshSubDir = "triSurface";
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::fileName Foam::triSurfaceMesh::checkFile
(
const IOobject& io,
const bool isGlobal
)
{
const fileName fName
(
isGlobal
? io.globalFilePath(typeName)
: io.localFilePath(typeName)
);
if (fName.empty())
{
FatalErrorInFunction
<< "Cannot find triSurfaceMesh starting from "
<< io.objectPath() << exit(FatalError);
}
return fName;
}
Foam::fileName Foam::triSurfaceMesh::relativeFilePath
(
const IOobject& io,
const fileName& f,
const bool isGlobal
)
{
fileName fName(f);
fName.expand();
if (!fName.isAbsolute())
{
// Is the specified file:
// - local to the cwd?
// - local to the case dir?
// - or just another name?
fName = fileHandler().filePath
(
isGlobal,
IOobject(io, fName),
word::null
);
}
return fName;
}
Foam::fileName Foam::triSurfaceMesh::checkFile
(
const IOobject& io,
const dictionary& dict,
const bool isGlobal
)
{
fileName fName;
if (dict.readIfPresent("file", fName, keyType::LITERAL))
{
const fileName rawFName(fName);
fName = relativeFilePath(io, rawFName, isGlobal);
if (!exists(fName))
{
FatalErrorInFunction
<< "Cannot find triSurfaceMesh " << rawFName
<< " starting from " << io.objectPath()
<< exit(FatalError);
}
}
else
{
fName =
(
isGlobal
? io.globalFilePath(typeName)
: io.localFilePath(typeName)
);
if (!exists(fName))
{
FatalErrorInFunction
<< "Cannot find triSurfaceMesh starting from "
<< io.objectPath() << exit(FatalError);
}
}
return fName;
}
bool Foam::triSurfaceMesh::addFaceToEdge
(
const edge& e,
......@@ -308,7 +217,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io)
false // searchableSurface already registered under name
)
),
triSurface(checkFile(static_cast<const searchableSurface&>(*this), true)),
triSurface(static_cast<const searchableSurface&>(*this), dictionary::null),
triSurfaceRegionSearch(static_cast<const triSurface&>(*this)),
minQuality_(-1),
surfaceClosed_(-1),
......@@ -341,19 +250,16 @@ Foam::triSurfaceMesh::triSurfaceMesh
false // searchableSurface already registered under name
)
),
triSurface
(
checkFile(static_cast<const searchableSurface&>(*this), dict, true)
),
triSurface(static_cast<const searchableSurface&>(*this), dict),
triSurfaceRegionSearch(static_cast<const triSurface&>(*this), dict),
minQuality_(-1),
surfaceClosed_(-1),
outsideVolType_(volumeType::UNKNOWN)
{
// Reading from supplied file name instead of objectPath/filePath
// Adjust to use supplied file name instead of objectPath/filePath
if (dict.readIfPresent("file", fName_, keyType::LITERAL))
{
fName_ = relativeFilePath
fName_ = triSurface::relativeFilePath
(
static_cast<const searchableSurface&>(*this),
fName_,
......@@ -404,7 +310,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io, const readAction r)
false // searchableSurface already registered under name
)
),
triSurface(), // construct null
triSurface(),
triSurfaceRegionSearch(static_cast<const triSurface&>(*this)),
minQuality_(-1),
surfaceClosed_(-1),
......@@ -502,7 +408,7 @@ Foam::triSurfaceMesh::triSurfaceMesh
false // searchableSurface already registered under name
)
),
triSurface(), // construct null
triSurface(),
triSurfaceRegionSearch(static_cast<const triSurface&>(*this), dict),
minQuality_(-1),
surfaceClosed_(-1),
......
......@@ -106,26 +106,6 @@ protected:
// Private Member Functions
//- Return fileName to load IOobject from
static fileName checkFile(const IOobject& io, const bool isGlobal);
//- Return fileName. If fileName is relative gets treated local to
// IOobject
static fileName relativeFilePath
(
const IOobject&,
const fileName&,
const bool isGlobal
);
//- Return fileName to load IOobject from. Optional override of fileName
static fileName checkFile
(
const IOobject&,
const dictionary&,
const bool isGlobal
);
//- Helper function for isSurfaceClosed
static bool addFaceToEdge
(
......
......@@ -2557,7 +2557,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(const IOobject& io)
bounds().reduce();
const fileName actualFile(checkFile(io, true));
const fileName actualFile(triSurfaceMesh::checkFile(io, true));
if
(
......@@ -2697,7 +2697,7 @@ Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh
bounds().reduce();
const fileName actualFile(checkFile(io, dict, true));
const fileName actualFile(triSurfaceMesh::checkFile(io, dict, true));
if
(
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -121,32 +122,34 @@ Foam::triSurfaceMeshPointSet::triSurfaceMeshPointSet
)
:
sampledSet(name, mesh, searchEngine, dict),
surface_(dict.get<word>("surface"))
surfaceName_(dict.get<word>("surface"))
{
// Load surface.
if (mesh.time().foundObject<triSurfaceMesh>(surface_))
// Get or load surface
const auto* surfPtr =
mesh.time().cfindObject<triSurfaceMesh>(surfaceName_);
if (surfPtr)
{
// Note: should use localPoints() instead of points() but assume
// trisurface is compact.
sampleCoords_ = mesh.time().lookupObject<triSurfaceMesh>
(
surface_
).points();
sampleCoords_ = surfPtr->points();
}
else
{
sampleCoords_ = triSurfaceMesh
sampleCoords_ = triSurface
(
IOobject
(
surface_,
surfaceName_,
mesh.time().constant(), // instance
"triSurface", // local
mesh.time(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
),
dictionary::null
).points();
}
......
......@@ -60,10 +60,10 @@ class triSurfaceMeshPointSet
:
public sampledSet
{
// Private data
// Private Data
//- Name of triSurfaceMesh
const word surface_;
//- The surface name
const word surfaceName_;
//- Sampling points
List<point> sampleCoords_;
......
......@@ -33,7 +33,6 @@ License
#include "treeDataCell.H"
#include "treeDataFace.H"
#include "meshTools.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -78,8 +77,32 @@ namespace Foam
}
}
};
} // End namespace Foam
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
// The IOobject for reading
inline static IOobject selectReadIO(const word& name, const Time& runTime)
{
return IOobject
(
name,
runTime.constant(), // instance
"triSurface", // local
runTime, // registry
IOobject::MUST_READ,
IOobject::NO_WRITE,
false // no register
);
}
} // End namespace Foam
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
......@@ -94,14 +117,14 @@ void Foam::sampledTriSurfaceMesh::setZoneMap
{
sz += zn.size();
}
zoneIds.resize(sz);
zoneIds.setSize(sz);
forAll(zoneLst, zonei)
{
const surfZone& zn = zoneLst[zonei];
// Assign sub-zone Ids
SubList<label>(zoneIds, zn.size(), zn.start()) = zonei;
SubList<label>(zoneIds, zn.range()) = zonei;
}
}
......@@ -224,8 +247,8 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher)
<< " keeping:" << nFound << endl;
}
// Now subset the surface. Do not use triSurface::subsetMesh since requires
// original surface to be in compact numbering.
// Now subset the surface.
// Done manually in case the original had non-compact point numbering
const triSurface& s = surface_;
......@@ -393,15 +416,10 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher)
forAll(faceMap, facei)
{
const labelledTri& origF = s[faceMap[facei]];
face& f = surfFaces[facei];
f = triFace
(
reversePointMap[origF[0]],
reversePointMap[origF[1]],
reversePointMap[origF[2]]
);
f = s[faceMap[facei]]; // Copy original face
inplaceRenumber(reversePointMap, f); // renumber point ids
for (const label labi : f)
{
......@@ -583,18 +601,11 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh
:
sampledSurface(name, mesh),
MeshStorage(),
surfaceName_(surfaceName),
surface_
(
IOobject
(
surfaceName,
mesh.time().constant(), // instance
"triSurface", // local
mesh.time(), // registry
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
selectReadIO(surfaceName, mesh.time()),
dictionary::null
),
sampleSource_(sampleSource),
needsUpdate_(true),
......@@ -615,57 +626,22 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh
:
sampledSurface(name, mesh, dict),
MeshStorage(),
surface_
surfaceName_
(
IOobject
triSurface::findFile
(
dict.get<word>("surface"),
mesh.time().constant(), // instance
"triSurface", // local
mesh.time(), // registry
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
),
dict
selectReadIO(dict.get<word>("surface"), mesh.time()),
dict
).name()
),
sampleSource_(samplingSourceNames_.get("source", dict)),
needsUpdate_(true),
keepIds_(dict.lookupOrDefault("keepIds", false)),
originalIds_(),
zoneIds_(),
sampleElements_(),
samplePoints_()
{}
Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh
(
const word& name,
const polyMesh& mesh,
const triSurface& surface,
const word& sampleSourceName
)
:
sampledSurface(name, mesh),
MeshStorage(),
surface_
(
IOobject
(
name,
mesh.time().constant(), // instance
"triSurface", // local
mesh.time(), // registry
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
surface
selectReadIO(dict.get<word>("surface"), mesh.time()),
dict
),
sampleSource_(samplingSourceNames_[sampleSourceName]),
sampleSource_(samplingSourceNames_.get("source", dict)),
needsUpdate_(true),
keepIds_(false),
keepIds_(dict.lookupOrDefault("keepIds", false)),
originalIds_(),
zoneIds_(),
sampleElements_(),
......@@ -673,12 +649,6 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::sampledTriSurfaceMesh::~sampledTriSurfaceMesh()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::sampledTriSurfaceMesh::needsUpdate() const
......@@ -700,7 +670,6 @@ bool Foam::sampledTriSurfaceMesh::expire()
zoneIds_.clear();
originalIds_.clear();
boundaryTreePtr_.clear();
sampleElements_.clear();
samplePoints_.clear();
......@@ -717,11 +686,7 @@ bool Foam::sampledTriSurfaceMesh::update()
}
// Calculate surface and mesh overlap bounding box
treeBoundBox bb
(
surface_.triSurface::points(),
surface_.triSurface::meshPoints()
);
treeBoundBox bb(surface_.points(), surface_.meshPoints());
// Check for overlap with (global!) mesh bb
const bool intersect = bb.intersect(mesh().bounds());
......@@ -732,7 +697,7 @@ bool Foam::sampledTriSurfaceMesh::update()
// bounding box so we don't get any 'invalid bounding box' errors.
WarningInFunction
<< "Surface " << surface_.searchableSurface::name()
<< "Surface " << surfaceName_
<< " does not overlap bounding box of mesh " << mesh().bounds()
<< endl;
......@@ -865,7 +830,7 @@ Foam::tmp<Foam::tensorField> Foam::sampledTriSurfaceMesh::interpolate
void Foam::sampledTriSurfaceMesh::print(Ostream& os) const
{
os << "sampledTriSurfaceMesh: " << name() << " :"
<< " surface:" << surface_.objectRegistry::name()
<< " surface:" << surfaceName_
<< " faces:" << faces().size()
<< " points:" << points().size()
<< " zoneids:" << zoneIds().size();
......
......@@ -28,8 +28,8 @@ Class
Foam::sampledTriSurfaceMesh
Description
A sampledSurface from a triSurfaceMesh. It samples on the points/triangles
of the triSurface.
A sampledSurface from a meshed surface.
It samples on the points/faces of the triSurface.
- it either samples cells or (non-coupled) boundary faces
......@@ -98,7 +98,7 @@ SourceFiles
#define sampledTriSurfaceMesh_H
#include "sampledSurface.H"
#include "triSurfaceMesh.H"
#include "triSurface.H"
#include "MeshedSurface.H"
#include "MeshedSurfacesFwd.H"
......@@ -120,7 +120,7 @@ class sampledTriSurfaceMesh
public meshedSurface
{
public:
//- Types of communications
//- Types of sampling regions
enum samplingSource
{
cells,
......@@ -130,7 +130,7 @@ public:
private:
//- Private typedefs for convenience
//- Private typedefs for convenience
typedef meshedSurface MeshStorage;
......@@ -138,8 +138,11 @@ private:
static const Enum<samplingSource> samplingSourceNames_;
//- The name of the input surface
word surfaceName_;
//- Surface to sample on
const triSurfaceMesh surface_;
const triSurface surface_;
//- Whether to sample internal cell values or boundary values
const samplingSource sampleSource_;
......@@ -151,12 +154,9 @@ private:
bool keepIds_;
//- List of element ids/order of the original surface,
// when keepIds is active.
//- when keepIds is active.
labelList originalIds_;
//- Search tree for all non-coupled boundary faces
mutable autoPtr<indexedOctree<treeDataFace>> boundaryTreePtr_;
//- For compatibility with the meshSurf interface
labelList zoneIds_;
......@@ -210,18 +210,9 @@ public:
const dictionary& dict
);
//- Construct from triSurface
sampledTriSurfaceMesh
(
const word& name,
const polyMesh& mesh,
const triSurface& surface,
const word& sampleSourceName
);
//- Destructor
virtual ~sampledTriSurfaceMesh();
virtual ~sampledTriSurfaceMesh() = default;
// Member Functions
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -67,18 +67,6 @@ Foam::sampledTriSurfaceMeshNormal::sampledTriSurfaceMeshNormal
{}
Foam::sampledTriSurfaceMeshNormal::sampledTriSurfaceMeshNormal
(
const word& name,
const polyMesh& mesh,
const triSurface& surface,
const word& sampleSourceName
)
:
sampledTriSurfaceMesh(name, mesh, surface, sampleSourceName)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::tmp<Foam::Field<Foam::vector>>
......
......@@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-2018 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.