Skip to content

Commit

Permalink
triSurfaceMesh: Added support for specifying the tri-surface file name:
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Henry Weller committed Jan 7, 2017
1 parent 695466a commit 80e2278
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 130 deletions.
186 changes: 72 additions & 114 deletions src/meshTools/searchableSurface/triSurfaceMesh.C
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -247,40 +224,21 @@ 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(),
io.writeOpt(),
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)
Expand All @@ -298,47 +256,31 @@ 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(),
io.writeOpt(),
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)
{
Expand Down Expand Up @@ -470,7 +412,7 @@ Foam::triSurfaceMesh::edgeTree() const
label nPoints;
PatchTools::calcBounds
(
static_cast<const triSurface&>(*this),
*this,
bb,
nPoints
);
Expand Down Expand Up @@ -501,7 +443,7 @@ Foam::triSurfaceMesh::edgeTree() const
bEdges // selected edges
),
bb, // bb
maxTreeDepth(), // maxLevel
maxTreeDepth(), // maxLevel
10, // leafsize
3.0 // duplicity
)
Expand All @@ -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)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()))
{
Expand Down
24 changes: 8 additions & 16 deletions src/meshTools/searchableSurface/triSurfaceMesh.H
Expand Up @@ -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
Expand Down Expand Up @@ -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_;
Expand All @@ -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
Expand Down

0 comments on commit 80e2278

Please sign in to comment.