ENH: Switchable ability to check and ignore out of bounds positions

from ManualInjection.

Doubles time taken to inject when used, as cells being found twice.
This commit is contained in:
graham
2010-05-19 12:36:01 +01:00
parent 61b5633dd4
commit e3a0ed2585
4 changed files with 67 additions and 16 deletions

View File

@ -1,4 +1,4 @@
Info<< "Reading transportProperties\n" << endl; Info<< "\nReading transportProperties\n" << endl;
IOdictionary transportProperties IOdictionary transportProperties
( (
@ -31,7 +31,7 @@
rhoInfValue rhoInfValue
); );
Info<< "\nReading field U\n" << endl; Info<< "Reading field U\n" << endl;
volVectorField U volVectorField U
( (
IOobject IOobject
@ -127,7 +127,7 @@
if (HdotGradHheader.headerOk()) if (HdotGradHheader.headerOk())
{ {
Info<< "\nReading field HdotGradH\n" << endl; Info<< "Reading field HdotGradH" << endl;
HdotGradHPtr_.reset HdotGradHPtr_.reset
( (

View File

@ -129,10 +129,11 @@ void Foam::InjectionModel<CloudType>::prepareForNextTimeStep
template<class CloudType> template<class CloudType>
void Foam::InjectionModel<CloudType>::findCellAtPosition bool Foam::InjectionModel<CloudType>::findCellAtPosition
( (
label& cellI, label& cellI,
vector& position vector& position,
bool errorOnNotFound
) )
{ {
const volVectorField& cellCentres = owner_.mesh().C(); const volVectorField& cellCentres = owner_.mesh().C();
@ -176,17 +177,26 @@ void Foam::InjectionModel<CloudType>::findCellAtPosition
if (procI == -1) if (procI == -1)
{ {
FatalErrorIn if (errorOnNotFound)
( {
"Foam::InjectionModel<CloudType>::findCellAtPosition" FatalErrorIn
"(" (
"label&, " "Foam::InjectionModel<CloudType>::findCellAtPosition"
"vector&" "("
")" "label&, "
)<< "Cannot find parcel injection cell. " "vector&"
<< "Parcel position = " << p0 << nl ")"
<< abort(FatalError); ) << "Cannot find parcel injection cell. "
<< "Parcel position = " << p0 << nl
<< abort(FatalError);
}
else
{
return false;
}
} }
return true;
} }

View File

@ -180,7 +180,12 @@ protected:
//- Find the cell that contains the supplied position //- Find the cell that contains the supplied position
// Will modify position slightly towards the owner cell centroid to // Will modify position slightly towards the owner cell centroid to
// ensure that it lies in a cell and not edge/face // ensure that it lies in a cell and not edge/face
virtual void findCellAtPosition(label& cellI, vector& position); virtual bool findCellAtPosition
(
label& cellI,
vector& position,
bool errorOnNotFound = true
);
//- Set number of particles to inject given parcel properties //- Set number of particles to inject given parcel properties
virtual scalar setNumberOfParticles virtual scalar setNumberOfParticles

View File

@ -25,6 +25,8 @@ License
#include "ManualInjection.H" #include "ManualInjection.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
#include "PackedBoolList.H"
#include "Switch.H"
using namespace Foam::constant::mathematical; using namespace Foam::constant::mathematical;
@ -100,6 +102,40 @@ Foam::ManualInjection<CloudType>::ManualInjection
) )
) )
{ {
Switch checkAndIgnoreOutOfBounds
(
this->coeffDict().lookupOrDefault("checkAndIgnoreOutOfBounds", false)
);
label nRejected = 0;
if (checkAndIgnoreOutOfBounds)
{
// Dummy cell
label cellI = -1;
PackedBoolList keep(positions_.size(), true);
forAll(positions_, pI)
{
if (!this->findCellAtPosition(cellI, positions_[pI], false))
{
keep[pI] = false;
nRejected++;
}
}
if (nRejected > 0)
{
inplaceSubset(keep, positions_);
inplaceSubset(keep, diameters_);
Info<< " " << nRejected
<< " particles ignored, out of bounds." << endl;
}
}
// Construct parcel diameters // Construct parcel diameters
forAll(diameters_, i) forAll(diameters_, i)
{ {