BUG: sampledTriSurfaceMesh: sampling outside of mesh. Fixes #575.

There are a few issues:
- error would only throw exceptions if not parallel
- if we change this we also need to make sure the functionObjectList
  construction is synchronised
- bounding box overlap was not returning the correct status so the code
  to avoid the issue of 'badly formed bounding box' was not triggered.
This commit is contained in:
mattijs
2017-08-29 14:41:22 +01:00
parent bd762c94d0
commit 0e7954c22b
4 changed files with 64 additions and 45 deletions

View File

@ -3,7 +3,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-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -182,7 +182,17 @@ void Foam::error::exit(const int errNo)
abort(); abort();
} }
if (Pstream::parRun()) if (throwExceptions_)
{
// Make a copy of the error to throw
error errorException(*this);
// Reset the message buffer for the next error message
messageStreamPtr_->reset();
throw errorException;
}
else if (Pstream::parRun())
{ {
Perr<< endl << *this << endl Perr<< endl << *this << endl
<< "\nFOAM parallel run exiting\n" << endl; << "\nFOAM parallel run exiting\n" << endl;
@ -190,22 +200,9 @@ void Foam::error::exit(const int errNo)
} }
else else
{ {
if (throwExceptions_) Perr<< endl << *this << endl
{ << "\nFOAM exiting\n" << endl;
// Make a copy of the error to throw ::exit(1);
error errorException(*this);
// Reset the message buffer for the next error message
messageStreamPtr_->reset();
throw errorException;
}
else
{
Perr<< endl << *this << endl
<< "\nFOAM exiting\n" << endl;
::exit(1);
}
} }
} }
@ -226,7 +223,17 @@ void Foam::error::abort()
::abort(); ::abort();
} }
if (Pstream::parRun()) if (throwExceptions_)
{
// Make a copy of the error to throw
error errorException(*this);
// Reset the message buffer for the next error message
messageStreamPtr_->reset();
throw errorException;
}
else if (Pstream::parRun())
{ {
Perr<< endl << *this << endl Perr<< endl << *this << endl
<< "\nFOAM parallel run aborting\n" << endl; << "\nFOAM parallel run aborting\n" << endl;
@ -235,23 +242,10 @@ void Foam::error::abort()
} }
else else
{ {
if (throwExceptions_) Perr<< endl << *this << endl
{ << "\nFOAM aborting\n" << endl;
// Make a copy of the error to throw printStack(Perr);
error errorException(*this); ::abort();
// Reset the message buffer for the next error message
messageStreamPtr_->reset();
throw errorException;
}
else
{
Perr<< endl << *this << endl
<< "\nFOAM aborting\n" << endl;
printStack(Perr);
::abort();
}
} }
} }

View File

@ -791,7 +791,9 @@ bool Foam::functionObjectList::read()
FatalError.throwExceptions(throwingError); FatalError.throwExceptions(throwingError);
FatalIOError.throwExceptions(throwingIOerr); FatalIOError.throwExceptions(throwingIOerr);
if (foPtr.valid()) // If one processor only has thrown an exception (so exited the
// constructor) invalidate the whole functionObject
if (returnReduce(foPtr.valid(), andOp<bool>()))
{ {
objPtr = foPtr.ptr(); objPtr = foPtr.ptr();
} }

View File

@ -59,7 +59,16 @@ inline Foam::boundBox::boundBox(Istream& is)
inline bool Foam::boundBox::empty() const inline bool Foam::boundBox::empty() const
{ {
return (min_ > max_); // Note: cannot use min_ > max_ here since that tests for -all- components
// of min_ being larger than max_.
for (direction dir = 0; dir < vector::nComponents; ++dir)
{
if (min_[dir] > max_[dir])
{
return true;
}
}
return false;
} }

View File

@ -683,7 +683,8 @@ Foam::sampledTriSurfaceMesh::sampledTriSurfaceMesh
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
) ),
dict
), ),
sampleSource_(samplingSourceNames_.lookup("source", dict)), sampleSource_(samplingSourceNames_.lookup("source", dict)),
needsUpdate_(true), needsUpdate_(true),
@ -779,15 +780,28 @@ bool Foam::sampledTriSurfaceMesh::update()
surface_.triSurface::meshPoints() surface_.triSurface::meshPoints()
); );
bb.intersect(mesh().bounds()); // Check for overlap with (global!) mesh bb
const bool intersect = bb.intersect(mesh().bounds());
// Extend a bit if (!intersect)
const vector span(bb.span()); {
// Surface and mesh do not overlap at all. Guarantee a valid
// bounding box so we don't get any 'invalid bounding box' errors.
bb = treeBoundBox(mesh().bounds());
const vector span(bb.span());
bb.min() -= 0.5*span; bb.min() += (0.5-1e-6)*span;
bb.max() += 0.5*span; bb.max() -= (0.5-1e-6)*span;
}
else
{
// Extend a bit
const vector span(bb.span());
bb.min() -= 0.5*span;
bb.max() += 0.5*span;
bb.inflate(1e-6); bb.inflate(1e-6);
}
// Mesh search engine, no triangulation of faces. // Mesh search engine, no triangulation of faces.
meshSearch meshSearcher(mesh(), bb, polyMesh::FACE_PLANES); meshSearch meshSearcher(mesh(), bb, polyMesh::FACE_PLANES);