Merge branch 'feature-LagrangianPatchInterationInfo' into 'develop'

ENH: Adding optional output information ordered by injectorID to LocalInteraction.

See merge request Development/OpenFOAM-plus!187
This commit is contained in:
Andrew Heather
2018-01-24 08:30:27 +00:00
6 changed files with 269 additions and 75 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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -274,6 +274,9 @@ public:
//- Return mass of particles injected (cumulative) //- Return mass of particles injected (cumulative)
inline scalar massInjected() const; inline scalar massInjected() const;
//- Return injectorID
inline label injectorID() const;
//- Return the end-of-injection time //- Return the end-of-injection time
virtual scalar timeEnd() const = 0; virtual scalar timeEnd() const = 0;

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 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -55,6 +55,13 @@ Foam::scalar Foam::InjectionModel<CloudType>::massInjected() const
} }
template<class CloudType>
Foam::label Foam::InjectionModel<CloudType>::injectorID() const
{
return injectorID_;
}
template<class CloudType> template<class CloudType>
Foam::label Foam::InjectionModel<CloudType>::nInjections() const Foam::label Foam::InjectionModel<CloudType>::nInjections() const
{ {

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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,11 +36,13 @@ Foam::LocalInteraction<CloudType>::LocalInteraction
: :
PatchInteractionModel<CloudType>(dict, cloud, typeName), PatchInteractionModel<CloudType>(dict, cloud, typeName),
patchData_(cloud.mesh(), this->coeffDict()), patchData_(cloud.mesh(), this->coeffDict()),
nEscape_(patchData_.size(), 0), nEscape_(patchData_.size()),
massEscape_(patchData_.size(), 0.0), massEscape_(patchData_.size()),
nStick_(patchData_.size(), 0), nStick_(patchData_.size()),
massStick_(patchData_.size(), 0.0), massStick_(patchData_.size()),
writeFields_(this->coeffDict().lookupOrDefault("writeFields", false)), writeFields_(this->coeffDict().lookupOrDefault("writeFields", false)),
outputByInjectorId_(this->coeffDict().lookupOrDefault("outputByInjectorId", false)),
injIdToIndex_(cloud.injectors().size()),
massEscapePtr_(nullptr), massEscapePtr_(nullptr),
massStickPtr_(nullptr) massStickPtr_(nullptr)
{ {
@ -77,6 +79,21 @@ Foam::LocalInteraction<CloudType>::LocalInteraction
<< this->PatchInteractionModel<CloudType>::interactionTypeNames_ << this->PatchInteractionModel<CloudType>::interactionTypeNames_
<< nl << exit(FatalError); << nl << exit(FatalError);
} }
label nInjectors(1);
if (outputByInjectorId_)
{
nInjectors = cloud.injectors().size();
for (label i=0; i<nInjectors; i++)
{
injIdToIndex_.insert(cloud.injectors()[i].injectorID(), i);
}
}
nEscape_[patchi].setSize(nInjectors, 0);
massEscape_[patchi].setSize(nInjectors, 0.0);
nStick_[patchi].setSize(nInjectors, 0);
massStick_[patchi].setSize(nInjectors, 0.0);
} }
} }
@ -94,6 +111,8 @@ Foam::LocalInteraction<CloudType>::LocalInteraction
nStick_(pim.nStick_), nStick_(pim.nStick_),
massStick_(pim.massStick_), massStick_(pim.massStick_),
writeFields_(pim.writeFields_), writeFields_(pim.writeFields_),
outputByInjectorId_(pim.outputByInjectorId_),
injIdToIndex_(pim.injIdToIndex_),
massEscapePtr_(nullptr), massEscapePtr_(nullptr),
massStickPtr_(nullptr) massStickPtr_(nullptr)
{} {}
@ -199,8 +218,16 @@ bool Foam::LocalInteraction<CloudType>::correct
keepParticle = false; keepParticle = false;
p.active(false); p.active(false);
U = Zero; U = Zero;
nEscape_[patchi]++; if (outputByInjectorId_)
massEscape_[patchi] += dm; {
nEscape_[patchi][injIdToIndex_[p.typeId()]]++;
massEscape_[patchi][injIdToIndex_[p.typeId()]] += dm;
}
else
{
nEscape_[patchi][0]++;
massEscape_[patchi][0] += dm;
}
if (writeFields_) if (writeFields_)
{ {
label pI = pp.index(); label pI = pp.index();
@ -216,8 +243,16 @@ bool Foam::LocalInteraction<CloudType>::correct
keepParticle = true; keepParticle = true;
p.active(false); p.active(false);
U = Zero; U = Zero;
nStick_[patchi]++; if (outputByInjectorId_)
massStick_[patchi] += dm; {
nStick_[patchi][injIdToIndex_[p.typeId()]]++;
massStick_[patchi][injIdToIndex_[p.typeId()]] += dm;
}
else
{
nStick_[patchi][0]++;
massStick_[patchi][0] += dm;
}
if (writeFields_) if (writeFields_)
{ {
label pI = pp.index(); label pI = pp.index();
@ -279,59 +314,91 @@ void Foam::LocalInteraction<CloudType>::info(Ostream& os)
PatchInteractionModel<CloudType>::info(os); PatchInteractionModel<CloudType>::info(os);
// retrieve any stored data // retrieve any stored data
labelList npe0(patchData_.size(), 0); labelListList npe0(nEscape_);
this->getModelProperty("nEscape", npe0); this->getModelProperty("nEscape", npe0);
scalarList mpe0(patchData_.size(), 0.0); scalarListList mpe0(massEscape_);
this->getModelProperty("massEscape", mpe0); this->getModelProperty("massEscape", mpe0);
labelList nps0(patchData_.size(), 0); labelListList nps0(nStick_);
this->getModelProperty("nStick", nps0); this->getModelProperty("nStick", nps0);
scalarList mps0(patchData_.size(), 0.0); scalarListList mps0(massStick_);
this->getModelProperty("massStick", mps0); this->getModelProperty("massStick", mps0);
// accumulate current data // accumulate current data
labelList npe(nEscape_); labelListList npe(nEscape_);
Pstream::listCombineGather(npe, plusEqOp<label>()); forAll(npe, i)
npe = npe + npe0; {
Pstream::listCombineGather(npe[i], plusEqOp<label>());
npe[i] = npe[i] + npe0[i];
}
scalarList mpe(massEscape_); scalarListList mpe(massEscape_);
Pstream::listCombineGather(mpe, plusEqOp<scalar>()); forAll(mpe, i)
mpe = mpe + mpe0; {
Pstream::listCombineGather(mpe[i], plusEqOp<scalar>());
mpe[i] = mpe[i] + mpe0[i];
}
labelList nps(nStick_); labelListList nps(nStick_);
Pstream::listCombineGather(nps, plusEqOp<label>()); forAll(nps, i)
nps = nps + nps0; {
Pstream::listCombineGather(nps[i], plusEqOp<label>());
nps[i] = nps[i] + nps0[i];
}
scalarList mps(massStick_); scalarListList mps(massStick_);
Pstream::listCombineGather(mps, plusEqOp<scalar>()); forAll(nps, i)
mps = mps + mps0; {
Pstream::listCombineGather(mps[i], plusEqOp<scalar>());
mps[i] = mps[i] + mps0[i];
}
if (outputByInjectorId_)
{
forAll(patchData_, i)
{
forAll (mpe[i], injId)
{
os << " Parcel fate: patch " << patchData_[i].patchName()
<< " (number, mass)" << nl
<< " - escape (injector " << injIdToIndex_.toc()[injId]
<< " ) = " << npe[i][injId]
<< ", " << mpe[i][injId] << nl
<< " - stick (injector " << injIdToIndex_.toc()[injId]
<< " ) = " << nps[i][injId]
<< ", " << mps[i][injId] << nl;
}
}
}
else
{
forAll(patchData_, i) forAll(patchData_, i)
{ {
os << " Parcel fate: patch " << patchData_[i].patchName() os << " Parcel fate: patch " << patchData_[i].patchName()
<< " (number, mass)" << nl << " (number, mass)" << nl
<< " - escape = " << npe[i] << " - escape = " << npe[i][0]
<< ", " << mpe[i] << nl << ", " << mpe[i][0] << nl
<< " - stick = " << nps[i] << " - stick = " << nps[i][0]
<< ", " << mps[i] << nl; << ", " << mps[i][0] << nl;
}
} }
if (this->writeTime()) if (this->writeTime())
{ {
this->setModelProperty("nEscape", npe); this->setModelProperty("nEscape", npe);
nEscape_ = 0; nEscape_ = Zero;
this->setModelProperty("massEscape", mpe); this->setModelProperty("massEscape", mpe);
massEscape_ = 0.0; massEscape_ = Zero;
this->setModelProperty("nStick", nps); this->setModelProperty("nStick", nps);
nStick_ = 0; nStick_ = Zero;
this->setModelProperty("massStick", mps); this->setModelProperty("massStick", mps);
massStick_ = 0.0; massStick_ = Zero;
} }
} }

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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -61,21 +61,27 @@ class LocalInteraction
// Counters for particle fates // Counters for particle fates
//- Number of parcels escaped //- Number of parcels escaped
List<label> nEscape_; List<List<label>> nEscape_;
//- Mass of parcels escaped //- Mass of parcels escaped
List<scalar> massEscape_; List<List<scalar>> massEscape_;
//- Number of parcels stuck to patches //- Number of parcels stuck to patches
List<label> nStick_; List<List<label>> nStick_;
//- Mass of parcels stuck to patches //- Mass of parcels stuck to patches
List<scalar> massStick_; List<List<scalar>> massStick_;
//- Flag to output data as fields //- Flag to output data as fields
Switch writeFields_; Switch writeFields_;
//- Flag to output escaped/mass particles sorted by injectorID
Switch outputByInjectorId_;
//- InjectorId to index map
Map<label> injIdToIndex_;
//- Mass escape field //- Mass escape field
autoPtr<volScalarField> massEscapePtr_; autoPtr<volScalarField> massEscapePtr_;
@ -83,6 +89,7 @@ class LocalInteraction
autoPtr<volScalarField> massStickPtr_; autoPtr<volScalarField> massStickPtr_;
public: public:
//- Runtime type information //- Runtime type information

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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,16 +35,19 @@ Foam::StandardWallInteraction<CloudType>::StandardWallInteraction
) )
: :
PatchInteractionModel<CloudType>(dict, cloud, typeName), PatchInteractionModel<CloudType>(dict, cloud, typeName),
mesh_(cloud.mesh()),
interactionType_ interactionType_
( (
this->wordToInteractionType(this->coeffDict().lookup("type")) this->wordToInteractionType(this->coeffDict().lookup("type"))
), ),
e_(0.0), e_(0.0),
mu_(0.0), mu_(0.0),
nEscape_(0), nEscape_(cloud.mesh().boundary().size()),
massEscape_(0.0), massEscape_(nEscape_.size()),
nStick_(0), nStick_(nEscape_.size()),
massStick_(0.0) massStick_(nEscape_.size()),
outputByInjectorId_(this->coeffDict().lookupOrDefault("outputByInjectorId", false)),
injIdToIndex_(cloud.injectors().size())
{ {
switch (interactionType_) switch (interactionType_)
{ {
@ -69,6 +72,24 @@ Foam::StandardWallInteraction<CloudType>::StandardWallInteraction
default: default:
{} {}
} }
forAll(nEscape_, patchi)
{
label nInjectors(1);
if (outputByInjectorId_)
{
nInjectors = cloud.injectors().size();
for (label i=0; i<nInjectors; i++)
{
injIdToIndex_.insert(cloud.injectors()[i].injectorID(), i);
}
}
nEscape_[patchi].setSize(nInjectors, 0);
massEscape_[patchi].setSize(nInjectors, 0.0);
nStick_[patchi].setSize(nInjectors, 0);
massStick_[patchi].setSize(nInjectors, 0.0);
}
} }
@ -79,13 +100,16 @@ Foam::StandardWallInteraction<CloudType>::StandardWallInteraction
) )
: :
PatchInteractionModel<CloudType>(pim), PatchInteractionModel<CloudType>(pim),
mesh_(pim.mesh_),
interactionType_(pim.interactionType_), interactionType_(pim.interactionType_),
e_(pim.e_), e_(pim.e_),
mu_(pim.mu_), mu_(pim.mu_),
nEscape_(pim.nEscape_), nEscape_(pim.nEscape_),
massEscape_(pim.massEscape_), massEscape_(pim.massEscape_),
nStick_(pim.nStick_), nStick_(pim.nStick_),
massStick_(pim.massStick_) massStick_(pim.massStick_),
outputByInjectorId_(pim.outputByInjectorId_),
injIdToIndex_(pim.injIdToIndex_)
{} {}
@ -121,8 +145,17 @@ bool Foam::StandardWallInteraction<CloudType>::correct
keepParticle = false; keepParticle = false;
p.active(false); p.active(false);
U = Zero; U = Zero;
nEscape_++; const scalar dm = p.nParticle()*p.mass();
massEscape_ += p.nParticle()*p.mass(); if (outputByInjectorId_)
{
nEscape_[pp.index()][injIdToIndex_[p.typeId()]]++;
massEscape_[pp.index()][injIdToIndex_[p.typeId()]] += dm;
}
else
{
nEscape_[pp.index()][0]++;
massEscape_[pp.index()][0] += dm;
}
break; break;
} }
case PatchInteractionModel<CloudType>::itStick: case PatchInteractionModel<CloudType>::itStick:
@ -130,8 +163,17 @@ bool Foam::StandardWallInteraction<CloudType>::correct
keepParticle = true; keepParticle = true;
p.active(false); p.active(false);
U = Zero; U = Zero;
nStick_++; const scalar dm = p.nParticle()*p.mass();
massStick_ += p.nParticle()*p.mass(); if (outputByInjectorId_)
{
nStick_[pp.index()][injIdToIndex_[p.typeId()]]++;
massStick_[pp.index()][injIdToIndex_[p.typeId()]] += dm;
}
else
{
nStick_[pp.index()][0]++;
massStick_[pp.index()][0] += dm;
}
break; break;
} }
case PatchInteractionModel<CloudType>::itRebound: case PatchInteractionModel<CloudType>::itRebound:
@ -184,28 +226,87 @@ void Foam::StandardWallInteraction<CloudType>::info(Ostream& os)
{ {
PatchInteractionModel<CloudType>::info(os); PatchInteractionModel<CloudType>::info(os);
label npe0 = this->template getModelProperty<scalar>("nEscape"); labelListList npe0(nEscape_);
label npe = npe0 + returnReduce(nEscape_, sumOp<label>()); this->getModelProperty("nEscape", npe0);
scalar mpe0 = this->template getModelProperty<scalar>("massEscape"); scalarListList mpe0(massEscape_);
scalar mpe = mpe0 + returnReduce(massEscape_, sumOp<scalar>()); this->getModelProperty("massEscape", mpe0);
label nps0 = this->template getModelProperty<scalar>("nStick"); labelListList nps0(nStick_);
label nps = nps0 + returnReduce(nStick_, sumOp<label>()); this->getModelProperty("nStick", nps0);
scalar mps0 = this->template getModelProperty<scalar>("massStick"); scalarListList mps0(massStick_);
scalar mps = mps0 + returnReduce(massStick_, sumOp<scalar>()); this->getModelProperty("massStick", mps0);
os << " Parcel fate: walls (number, mass)" << nl // accumulate current data
<< " - escape = " << npe << ", " << mpe << nl labelListList npe(nEscape_);
<< " - stick = " << nps << ", " << mps << nl; forAll(npe, i)
{
Pstream::listCombineGather(npe[i], plusEqOp<label>());
npe[i] = npe[i] + npe0[i];
}
scalarListList mpe(massEscape_);
forAll(mpe, i)
{
Pstream::listCombineGather(mpe[i], plusEqOp<scalar>());
mpe[i] = mpe[i] + mpe0[i];
}
labelListList nps(nStick_);
forAll(nps, i)
{
Pstream::listCombineGather(nps[i], plusEqOp<label>());
nps[i] = nps[i] + nps0[i];
}
scalarListList mps(massStick_);
forAll(nps, i)
{
Pstream::listCombineGather(mps[i], plusEqOp<scalar>());
mps[i] = mps[i] + mps0[i];
}
if (outputByInjectorId_)
{
forAll(npe, i)
{
forAll (mpe[i], injId)
{
os << " Parcel fate: patch " << mesh_.boundary()[i].name()
<< " (number, mass)" << nl
<< " - escape (injector " << injIdToIndex_.toc()[injId]
<< " ) = " << npe[i][injId]
<< ", " << mpe[i][injId] << nl
<< " - stick (injector " << injIdToIndex_.toc()[injId]
<< " ) = " << nps[i][injId]
<< ", " << mps[i][injId] << nl;
}
}
}
else
{
forAll(npe, i)
{
os << " Parcel fate: walls (number, mass) "
<< mesh_.boundary()[i].name() << nl
<< " - escape = "
<< npe[i][0] << ", " << mpe[i][0] << nl
<< " - stick = "
<< nps[i][0] << ", " << mps[i][0] << nl;
}
}
if (this->writeTime()) if (this->writeTime())
{ {
this->setModelProperty("nEscape", npe); this->setModelProperty("nEscape", npe);
nEscape_ = Zero;
this->setModelProperty("massEscape", mpe); this->setModelProperty("massEscape", mpe);
massEscape_ = Zero;
this->setModelProperty("nStick", nps); this->setModelProperty("nStick", nps);
nStick_ = Zero;
this->setModelProperty("massStick", mps); this->setModelProperty("massStick", mps);
massStick_ = Zero;
} }
} }

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-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -69,6 +69,9 @@ protected:
// Protected data // Protected data
// Reference to mesh
const fvMesh& mesh_;
//- Interaction type //- Interaction type
typename PatchInteractionModel<CloudType>::interactionType typename PatchInteractionModel<CloudType>::interactionType
interactionType_; interactionType_;
@ -83,16 +86,22 @@ protected:
// Counters for particle fates // Counters for particle fates
//- Number of parcels escaped //- Number of parcels escaped
label nEscape_; List<List<label>> nEscape_;
//- Mass of parcels escaped //- Mass of parcels escaped
scalar massEscape_; List<List<scalar>> massEscape_;
//- Number of parcels stuck to patches //- Number of parcels stuck to patches
label nStick_; List<List<label>> nStick_;
//- Mass of parcels stuck to patches //- Mass of parcels stuck to patches
scalar massStick_; List<List<scalar>> massStick_;
//- Flag to output escaped/mass particles sorted by injectorID
Switch outputByInjectorId_;
//- InjectorId to index map
Map<label> injIdToIndex_;
public: public: