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
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -35,81 +35,58 @@ License
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
defineTypeNameAndDebug(triSurfaceMesh, 0);
|
||||
addToRunTimeSelectionTable(searchableSurface, triSurfaceMesh, dict);
|
||||
|
||||
defineTypeNameAndDebug(triSurfaceMesh, 0);
|
||||
addToRunTimeSelectionTable(searchableSurface, triSurfaceMesh, dict);
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
//// Special version of Time::findInstance that does not check headerOk
|
||||
//// 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
|
||||
)
|
||||
Foam::fileName Foam::triSurfaceMesh::checkFile(const IOobject& io)
|
||||
{
|
||||
const fileName fName(io.filePath());
|
||||
if (fName.empty())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "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;
|
||||
}
|
||||
|
||||
@ -247,25 +224,13 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io)
|
||||
:
|
||||
// Find instance for triSurfaceMesh
|
||||
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
|
||||
objectRegistry
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
io.name(),
|
||||
static_cast<const searchableSurface&>(*this).instance(),
|
||||
searchableSurface::instance(),
|
||||
io.local(),
|
||||
io.db(),
|
||||
io.readOpt(),
|
||||
@ -273,14 +238,7 @@ Foam::triSurfaceMesh::triSurfaceMesh(const IOobject& io)
|
||||
false // searchableSurface already registered under name
|
||||
)
|
||||
),
|
||||
triSurface
|
||||
(
|
||||
checkFile
|
||||
(
|
||||
searchableSurface::filePath(),
|
||||
searchableSurface::objectPath()
|
||||
)
|
||||
),
|
||||
triSurface(checkFile(static_cast<const searchableSurface&>(*this))),
|
||||
triSurfaceRegionSearch(static_cast<const triSurface&>(*this)),
|
||||
minQuality_(-1),
|
||||
surfaceClosed_(-1)
|
||||
@ -298,25 +256,13 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
||||
)
|
||||
:
|
||||
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
|
||||
objectRegistry
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
io.name(),
|
||||
static_cast<const searchableSurface&>(*this).instance(),
|
||||
searchableSurface::instance(),
|
||||
io.local(),
|
||||
io.db(),
|
||||
io.readOpt(),
|
||||
@ -324,21 +270,17 @@ Foam::triSurfaceMesh::triSurfaceMesh
|
||||
false // searchableSurface already registered under name
|
||||
)
|
||||
),
|
||||
triSurface
|
||||
(
|
||||
checkFile
|
||||
(
|
||||
searchableSurface::filePath(),
|
||||
searchableSurface::objectPath()
|
||||
)
|
||||
),
|
||||
triSurface(checkFile(static_cast<const searchableSurface&>(*this), dict)),
|
||||
triSurfaceRegionSearch(static_cast<const triSurface&>(*this), dict),
|
||||
minQuality_(-1),
|
||||
surfaceClosed_(-1)
|
||||
{
|
||||
// Reading from supplied file name instead of objectPath/filePath
|
||||
dict.readIfPresent("file", fName_, false, false);
|
||||
|
||||
scalar scaleFactor = 0;
|
||||
|
||||
// allow rescaling of the surface points
|
||||
// Allow rescaling of the surface points
|
||||
// eg, CAD geometries are often done in millimeters
|
||||
if (dict.readIfPresent("scale", scaleFactor) && scaleFactor > 0)
|
||||
{
|
||||
@ -470,7 +412,7 @@ Foam::triSurfaceMesh::edgeTree() const
|
||||
label nPoints;
|
||||
PatchTools::calcBounds
|
||||
(
|
||||
static_cast<const triSurface&>(*this),
|
||||
*this,
|
||||
bb,
|
||||
nPoints
|
||||
);
|
||||
@ -501,7 +443,7 @@ Foam::triSurfaceMesh::edgeTree() const
|
||||
bEdges // selected edges
|
||||
),
|
||||
bb, // bb
|
||||
maxTreeDepth(), // maxLevel
|
||||
maxTreeDepth(), // maxLevel
|
||||
10, // leafsize
|
||||
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
|
||||
{
|
||||
if (surfaceClosed_ == -1)
|
||||
@ -635,7 +576,7 @@ void Foam::triSurfaceMesh::getNormal
|
||||
vectorField& normal
|
||||
) const
|
||||
{
|
||||
const triSurface& s = static_cast<const triSurface&>(*this);
|
||||
const triSurface& s = *this;
|
||||
const pointField& pts = s.points();
|
||||
|
||||
normal.setSize(info.size());
|
||||
@ -796,7 +737,24 @@ bool Foam::triSurfaceMesh::writeObject
|
||||
IOstream::compressionType cmp
|
||||
) 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()))
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -68,10 +68,11 @@ class triSurfaceMesh
|
||||
public triSurface,
|
||||
public triSurfaceRegionSearch
|
||||
{
|
||||
private:
|
||||
|
||||
// Private member data
|
||||
|
||||
//- Supplied fileName override
|
||||
fileName fName_;
|
||||
|
||||
//- Optional min triangle quality. Triangles below this get
|
||||
// ignored for normal calculation
|
||||
scalar minQuality_;
|
||||
@ -88,20 +89,11 @@ private:
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
////- Helper: find instance of files without header
|
||||
//static word findRawInstance
|
||||
//(
|
||||
// const Time&,
|
||||
// const fileName&,
|
||||
// const word&
|
||||
//);
|
||||
//- Return fileName to load IOobject from
|
||||
static fileName checkFile(const IOobject& io);
|
||||
|
||||
//- Check file existence
|
||||
static const fileName& checkFile
|
||||
(
|
||||
const fileName& fName,
|
||||
const fileName& objectName
|
||||
);
|
||||
//- Return fileName to load IOobject from. Optional override of fileName
|
||||
static fileName checkFile(const IOobject&, const dictionary&);
|
||||
|
||||
//- Helper function for isSurfaceClosed
|
||||
static bool addFaceToEdge
|
||||
|
||||
Reference in New Issue
Block a user