mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
triSurfaceMesh: Added support for specifying the tri-surface file name:
e.g.
motorBike
{
type triSurfaceMesh;
file "motorBike.obj";
}
Based on patch provided by Mattijs Janssens
Resolves part of bug-report https://bugs.openfoam.org/view.php?id=2396
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -35,81 +35,58 @@ License
|
|||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
{
|
{
|
||||||
|
defineTypeNameAndDebug(triSurfaceMesh, 0);
|
||||||
defineTypeNameAndDebug(triSurfaceMesh, 0);
|
addToRunTimeSelectionTable(searchableSurface, triSurfaceMesh, dict);
|
||||||
addToRunTimeSelectionTable(searchableSurface, triSurfaceMesh, dict);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
//// Special version of Time::findInstance that does not check headerOk
|
Foam::fileName Foam::triSurfaceMesh::checkFile(const IOobject& io)
|
||||||
//// to search for instances of raw files
|
|
||||||
//Foam::word Foam::triSurfaceMesh::findRawInstance
|
|
||||||
//(
|
|
||||||
// const Time& runTime,
|
|
||||||
// const fileName& dir,
|
|
||||||
// const word& name
|
|
||||||
//)
|
|
||||||
//{
|
|
||||||
// // Check current time first
|
|
||||||
// if (isFile(runTime.path()/runTime.timeName()/dir/name))
|
|
||||||
// {
|
|
||||||
// return runTime.timeName();
|
|
||||||
// }
|
|
||||||
// instantList ts = runTime.times();
|
|
||||||
// label instanceI;
|
|
||||||
//
|
|
||||||
// for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
|
|
||||||
// {
|
|
||||||
// if (ts[instanceI].value() <= runTime.timeOutputValue())
|
|
||||||
// {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // continue searching from here
|
|
||||||
// for (; instanceI >= 0; --instanceI)
|
|
||||||
// {
|
|
||||||
// if (isFile(runTime.path()/ts[instanceI].name()/dir/name))
|
|
||||||
// {
|
|
||||||
// return ts[instanceI].name();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// // not in any of the time directories, try constant
|
|
||||||
//
|
|
||||||
// // Note. This needs to be a hard-coded constant, rather than the
|
|
||||||
// // constant function of the time, because the latter points to
|
|
||||||
// // the case constant directory in parallel cases
|
|
||||||
//
|
|
||||||
// if (isFile(runTime.path()/runTime.constant()/dir/name))
|
|
||||||
// {
|
|
||||||
// return runTime.constant();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// FatalErrorInFunction
|
|
||||||
// << "Cannot find file \"" << name << "\" in directory "
|
|
||||||
// << runTime.constant()/dir
|
|
||||||
// << exit(FatalError);
|
|
||||||
//
|
|
||||||
// return runTime.constant();
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
const Foam::fileName& Foam::triSurfaceMesh::checkFile
|
|
||||||
(
|
|
||||||
const fileName& fName,
|
|
||||||
const fileName& objectName
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
|
const fileName fName(io.filePath());
|
||||||
if (fName.empty())
|
if (fName.empty())
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Cannot find triSurfaceMesh starting from "
|
<< "Cannot find triSurfaceMesh starting from "
|
||||||
<< objectName << exit(FatalError);
|
<< io.objectPath() << exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::fileName Foam::triSurfaceMesh::checkFile
|
||||||
|
(
|
||||||
|
const IOobject& io,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
{
|
||||||
|
fileName fName;
|
||||||
|
if (dict.readIfPresent("file", fName, false, false))
|
||||||
|
{
|
||||||
|
fName.expand();
|
||||||
|
if (!fName.isAbsolute())
|
||||||
|
{
|
||||||
|
fName = io.objectPath().path()/fName;
|
||||||
|
}
|
||||||
|
if (!exists(fName))
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Cannot find triSurfaceMesh at " << fName
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fName = io.filePath();
|
||||||
|
if (!exists(fName))
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Cannot find triSurfaceMesh starting from "
|
||||||
|
<< io.objectPath() << exit(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return fName;
|
return fName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,25 +224,13 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io)
|
|||||||
:
|
:
|
||||||
// Find instance for triSurfaceMesh
|
// Find instance for triSurfaceMesh
|
||||||
searchableSurface(io),
|
searchableSurface(io),
|
||||||
//(
|
|
||||||
// IOobject
|
|
||||||
// (
|
|
||||||
// io.name(),
|
|
||||||
// io.time().findInstance(io.local(), word::null),
|
|
||||||
// io.local(),
|
|
||||||
// io.db(),
|
|
||||||
// io.readOpt(),
|
|
||||||
// io.writeOpt(),
|
|
||||||
// io.registerObject()
|
|
||||||
// )
|
|
||||||
//),
|
|
||||||
// Reused found instance in objectRegistry
|
// Reused found instance in objectRegistry
|
||||||
objectRegistry
|
objectRegistry
|
||||||
(
|
(
|
||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
io.name(),
|
io.name(),
|
||||||
static_cast<const searchableSurface&>(*this).instance(),
|
searchableSurface::instance(),
|
||||||
io.local(),
|
io.local(),
|
||||||
io.db(),
|
io.db(),
|
||||||
io.readOpt(),
|
io.readOpt(),
|
||||||
@ -273,14 +238,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io)
|
|||||||
false // searchableSurface already registered under name
|
false // searchableSurface already registered under name
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
triSurface
|
triSurface(checkFile(static_cast<const searchableSurface&>(*this))),
|
||||||
(
|
|
||||||
checkFile
|
|
||||||
(
|
|
||||||
searchableSurface::filePath(),
|
|
||||||
searchableSurface::objectPath()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
triSurfaceRegionSearch(static_cast<const triSurface&>(*this)),
|
triSurfaceRegionSearch(static_cast<const triSurface&>(*this)),
|
||||||
minQuality_(-1),
|
minQuality_(-1),
|
||||||
surfaceClosed_(-1)
|
surfaceClosed_(-1)
|
||||||
@ -298,25 +256,13 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
|||||||
)
|
)
|
||||||
:
|
:
|
||||||
searchableSurface(io),
|
searchableSurface(io),
|
||||||
//(
|
|
||||||
// IOobject
|
|
||||||
// (
|
|
||||||
// io.name(),
|
|
||||||
// io.time().findInstance(io.local(), word::null),
|
|
||||||
// io.local(),
|
|
||||||
// io.db(),
|
|
||||||
// io.readOpt(),
|
|
||||||
// io.writeOpt(),
|
|
||||||
// io.registerObject()
|
|
||||||
// )
|
|
||||||
//),
|
|
||||||
// Reused found instance in objectRegistry
|
// Reused found instance in objectRegistry
|
||||||
objectRegistry
|
objectRegistry
|
||||||
(
|
(
|
||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
io.name(),
|
io.name(),
|
||||||
static_cast<const searchableSurface&>(*this).instance(),
|
searchableSurface::instance(),
|
||||||
io.local(),
|
io.local(),
|
||||||
io.db(),
|
io.db(),
|
||||||
io.readOpt(),
|
io.readOpt(),
|
||||||
@ -324,21 +270,17 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
|||||||
false // searchableSurface already registered under name
|
false // searchableSurface already registered under name
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
triSurface
|
triSurface(checkFile(static_cast<const searchableSurface&>(*this), dict)),
|
||||||
(
|
|
||||||
checkFile
|
|
||||||
(
|
|
||||||
searchableSurface::filePath(),
|
|
||||||
searchableSurface::objectPath()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
triSurfaceRegionSearch(static_cast<const triSurface&>(*this), dict),
|
triSurfaceRegionSearch(static_cast<const triSurface&>(*this), dict),
|
||||||
minQuality_(-1),
|
minQuality_(-1),
|
||||||
surfaceClosed_(-1)
|
surfaceClosed_(-1)
|
||||||
{
|
{
|
||||||
|
// Reading from supplied file name instead of objectPath/filePath
|
||||||
|
dict.readIfPresent("file", fName_, false, false);
|
||||||
|
|
||||||
scalar scaleFactor = 0;
|
scalar scaleFactor = 0;
|
||||||
|
|
||||||
// allow rescaling of the surface points
|
// Allow rescaling of the surface points
|
||||||
// eg, CAD geometries are often done in millimeters
|
// eg, CAD geometries are often done in millimeters
|
||||||
if (dict.readIfPresent("scale", scaleFactor) && scaleFactor > 0)
|
if (dict.readIfPresent("scale", scaleFactor) && scaleFactor > 0)
|
||||||
{
|
{
|
||||||
@ -470,7 +412,7 @@ Foam::triSurfaceMesh::edgeTree() const
|
|||||||
label nPoints;
|
label nPoints;
|
||||||
PatchTools::calcBounds
|
PatchTools::calcBounds
|
||||||
(
|
(
|
||||||
static_cast<const triSurface&>(*this),
|
*this,
|
||||||
bb,
|
bb,
|
||||||
nPoints
|
nPoints
|
||||||
);
|
);
|
||||||
@ -501,7 +443,7 @@ Foam::triSurfaceMesh::edgeTree() const
|
|||||||
bEdges // selected edges
|
bEdges // selected edges
|
||||||
),
|
),
|
||||||
bb, // bb
|
bb, // bb
|
||||||
maxTreeDepth(), // maxLevel
|
maxTreeDepth(), // maxLevel
|
||||||
10, // leafsize
|
10, // leafsize
|
||||||
3.0 // duplicity
|
3.0 // duplicity
|
||||||
)
|
)
|
||||||
@ -527,7 +469,6 @@ const Foam::wordList& Foam::triSurfaceMesh::regions() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Find out if surface is closed.
|
|
||||||
bool Foam::triSurfaceMesh::hasVolumeType() const
|
bool Foam::triSurfaceMesh::hasVolumeType() const
|
||||||
{
|
{
|
||||||
if (surfaceClosed_ == -1)
|
if (surfaceClosed_ == -1)
|
||||||
@ -635,7 +576,7 @@ void Foam::triSurfaceMesh::getNormal
|
|||||||
vectorField& normal
|
vectorField& normal
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
const triSurface& s = static_cast<const triSurface&>(*this);
|
const triSurface& s = *this;
|
||||||
const pointField& pts = s.points();
|
const pointField& pts = s.points();
|
||||||
|
|
||||||
normal.setSize(info.size());
|
normal.setSize(info.size());
|
||||||
@ -796,7 +737,24 @@ bool Foam::triSurfaceMesh::writeObject
|
|||||||
IOstream::compressionType cmp
|
IOstream::compressionType cmp
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
fileName fullPath(searchableSurface::objectPath());
|
fileName fullPath;
|
||||||
|
if (fName_.size())
|
||||||
|
{
|
||||||
|
// Override file name
|
||||||
|
|
||||||
|
fullPath = fName_;
|
||||||
|
|
||||||
|
fullPath.expand();
|
||||||
|
if (!fullPath.isAbsolute())
|
||||||
|
{
|
||||||
|
// Add directory from regIOobject
|
||||||
|
fullPath = searchableSurface::objectPath().path()/fullPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fullPath = searchableSurface::objectPath();
|
||||||
|
}
|
||||||
|
|
||||||
if (!mkDir(fullPath.path()))
|
if (!mkDir(fullPath.path()))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -68,10 +68,11 @@ class triSurfaceMesh
|
|||||||
public triSurface,
|
public triSurface,
|
||||||
public triSurfaceRegionSearch
|
public triSurfaceRegionSearch
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
|
|
||||||
// Private member data
|
// Private member data
|
||||||
|
|
||||||
|
//- Supplied fileName override
|
||||||
|
fileName fName_;
|
||||||
|
|
||||||
//- Optional min triangle quality. Triangles below this get
|
//- Optional min triangle quality. Triangles below this get
|
||||||
// ignored for normal calculation
|
// ignored for normal calculation
|
||||||
scalar minQuality_;
|
scalar minQuality_;
|
||||||
@ -88,20 +89,11 @@ private:
|
|||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
////- Helper: find instance of files without header
|
//- Return fileName to load IOobject from
|
||||||
//static word findRawInstance
|
static fileName checkFile(const IOobject& io);
|
||||||
//(
|
|
||||||
// const Time&,
|
|
||||||
// const fileName&,
|
|
||||||
// const word&
|
|
||||||
//);
|
|
||||||
|
|
||||||
//- Check file existence
|
//- Return fileName to load IOobject from. Optional override of fileName
|
||||||
static const fileName& checkFile
|
static fileName checkFile(const IOobject&, const dictionary&);
|
||||||
(
|
|
||||||
const fileName& fName,
|
|
||||||
const fileName& objectName
|
|
||||||
);
|
|
||||||
|
|
||||||
//- Helper function for isSurfaceClosed
|
//- Helper function for isSurfaceClosed
|
||||||
static bool addFaceToEdge
|
static bool addFaceToEdge
|
||||||
|
|||||||
Reference in New Issue
Block a user