mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
general update + enabled absolute/specific option
This commit is contained in:
@ -27,15 +27,55 @@ License
|
|||||||
#include "timeActivatedExplicitSource.H"
|
#include "timeActivatedExplicitSource.H"
|
||||||
#include "volFields.H"
|
#include "volFields.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
template<>
|
||||||
|
const char* Foam::NamedEnum
|
||||||
|
<
|
||||||
|
Foam::timeActivatedExplicitSource::volumeType,
|
||||||
|
2
|
||||||
|
>::names[] =
|
||||||
|
{
|
||||||
|
"specific",
|
||||||
|
"absolute"
|
||||||
|
};
|
||||||
|
|
||||||
|
const Foam::NamedEnum<Foam::timeActivatedExplicitSource::volumeType, 2>
|
||||||
|
Foam::timeActivatedExplicitSource::volumeTypeNames_;
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::timeActivatedExplicitSource::updateCellSet()
|
||||||
|
{
|
||||||
|
cellSelector_->applyToSet(topoSetSource::NEW, selectedCellSet_);
|
||||||
|
|
||||||
|
Info<< " " << sourceName_ << ": selected "
|
||||||
|
<< returnReduce(selectedCellSet_.size(), sumOp<label>())
|
||||||
|
<< " cells" << nl << endl;
|
||||||
|
|
||||||
|
V_ = scalarField(selectedCellSet_.size(), 1.0);
|
||||||
|
if (volumeType_ == vtAbsolute)
|
||||||
|
{
|
||||||
|
label i = 0;
|
||||||
|
forAllConstIter(cellSet, selectedCellSet_, iter)
|
||||||
|
{
|
||||||
|
V_[i++] = mesh_.V()[iter.key()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::timeActivatedExplicitSource::timeActivatedExplicitSource
|
Foam::timeActivatedExplicitSource::timeActivatedExplicitSource
|
||||||
(
|
(
|
||||||
const word& sourceName,
|
const word& sourceName,
|
||||||
const fvMesh& mesh
|
const fvMesh& mesh,
|
||||||
|
const dimensionSet& dims
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
dict_
|
IOdictionary
|
||||||
(
|
(
|
||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
@ -46,52 +86,36 @@ Foam::timeActivatedExplicitSource::timeActivatedExplicitSource
|
|||||||
IOobject::NO_WRITE
|
IOobject::NO_WRITE
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
sourceName_(sourceName),
|
||||||
mesh_(mesh),
|
mesh_(mesh),
|
||||||
runTime_(mesh.time()),
|
runTime_(mesh.time()),
|
||||||
cellSource_(dict_.lookup("cellSource")),
|
dimensions_(dims),
|
||||||
timeStart_(dimensionedScalar(dict_.lookup("timeStart")).value()),
|
volumeType_(volumeTypeNames_.read(lookup("volumeType"))),
|
||||||
duration_(dimensionedScalar(dict_.lookup("duration")).value()),
|
timeStart_(readScalar(lookup("timeStart"))),
|
||||||
onValue_(dict_.lookup("onValue")),
|
duration_(readScalar(lookup("duration"))),
|
||||||
offValue_(dict_.lookup("offValue")),
|
onValue_(readScalar(lookup("onValue"))),
|
||||||
currentValue_(dimensionedScalar("zero", onValue_.dimensions(), 0.0)),
|
offValue_(readScalar(lookup("offValue"))),
|
||||||
|
currentValue_(0.0),
|
||||||
|
V_(0),
|
||||||
|
cellSource_(lookup("cellSource")),
|
||||||
cellSelector_
|
cellSelector_
|
||||||
(
|
(
|
||||||
topoSetSource::New
|
topoSetSource::New
|
||||||
(
|
(
|
||||||
cellSource_,
|
cellSource_,
|
||||||
mesh,
|
mesh,
|
||||||
dict_.subDict(cellSource_ + "Coeffs")
|
subDict(cellSource_ + "Coeffs")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
selectedCellSet_
|
selectedCellSet_
|
||||||
(
|
(
|
||||||
mesh,
|
mesh,
|
||||||
"timeActivatedExplicitSourceCellSet",
|
sourceName + "SourceCellSet",
|
||||||
mesh.nCells()/10 + 1 // Reasonable size estimate.
|
mesh.nCells()/10 + 1 // Reasonable size estimate.
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Check dimensions of on/off values are consistent
|
|
||||||
if (onValue_.dimensions() != offValue_.dimensions())
|
|
||||||
{
|
|
||||||
FatalErrorIn
|
|
||||||
(
|
|
||||||
"Foam::timeActivatedExplicitSource::timeActivatedExplicitSource"
|
|
||||||
)<< "Dimensions of on and off values must be equal" << nl
|
|
||||||
<< "onValue = " << onValue_ << nl
|
|
||||||
<< "offValue = " << offValue_ << exit(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the cell set
|
// Create the cell set
|
||||||
cellSelector_->applyToSet
|
updateCellSet();
|
||||||
(
|
|
||||||
topoSetSource::NEW,
|
|
||||||
selectedCellSet_
|
|
||||||
);
|
|
||||||
|
|
||||||
// Give some feedback
|
|
||||||
Info<< "timeVaryingExplitSource(" << sourceName << ")" << nl
|
|
||||||
<< "Selected " << returnReduce(selectedCellSet_.size(), sumOp<label>())
|
|
||||||
<< " cells." << endl;
|
|
||||||
|
|
||||||
// Initialise the value
|
// Initialise the value
|
||||||
update();
|
update();
|
||||||
@ -112,10 +136,15 @@ Foam::scalar Foam::timeActivatedExplicitSource::duration() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Foam::dimensionedScalar&
|
const Foam::dimensionedScalar
|
||||||
Foam::timeActivatedExplicitSource::currentValue() const
|
Foam::timeActivatedExplicitSource::currentValue() const
|
||||||
{
|
{
|
||||||
return currentValue_;
|
return dimensionedScalar
|
||||||
|
(
|
||||||
|
sourceName_,
|
||||||
|
dimensions_,
|
||||||
|
currentValue_
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -128,30 +157,60 @@ Foam::timeActivatedExplicitSource::Su() const
|
|||||||
(
|
(
|
||||||
IOobject
|
IOobject
|
||||||
(
|
(
|
||||||
"timeActivatedExplicitSource",
|
sourceName_ + "Su",
|
||||||
runTime_.timeName(),
|
runTime_.timeName(),
|
||||||
mesh_,
|
mesh_,
|
||||||
IOobject::NO_READ,
|
IOobject::NO_READ,
|
||||||
IOobject::NO_WRITE
|
IOobject::NO_WRITE
|
||||||
),
|
),
|
||||||
mesh_,
|
mesh_,
|
||||||
dimensionedScalar("zero", onValue_.dimensions(), 0.0)
|
dimensionedScalar("zero", dimensions_, 0.0)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
DimensionedField<scalar, volMesh>& sourceField = tSource();
|
DimensionedField<scalar, volMesh>& sourceField = tSource();
|
||||||
|
|
||||||
|
label i = 0;
|
||||||
forAllConstIter(cellSet, selectedCellSet_, iter)
|
forAllConstIter(cellSet, selectedCellSet_, iter)
|
||||||
{
|
{
|
||||||
sourceField[iter.key()] = currentValue_.value();
|
sourceField[iter.key()] = currentValue_/V_[i++];
|
||||||
}
|
}
|
||||||
|
|
||||||
return tSource;
|
return tSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Foam::timeActivatedExplicitSource::read()
|
||||||
|
{
|
||||||
|
if (regIOobject::read())
|
||||||
|
{
|
||||||
|
volumeType_ = volumeTypeNames_.read(lookup("volumeType"));
|
||||||
|
lookup("timeStart") >> duration_;
|
||||||
|
lookup("duration") >> duration_;
|
||||||
|
lookup("onValue") >> onValue_;
|
||||||
|
lookup("offValue") >> offValue_;
|
||||||
|
lookup("cellSource") >> cellSource_;
|
||||||
|
cellSelector_ =
|
||||||
|
topoSetSource::New
|
||||||
|
(
|
||||||
|
cellSource_,
|
||||||
|
mesh_,
|
||||||
|
subDict(cellSource_ + "Coeffs")
|
||||||
|
);
|
||||||
|
updateCellSet();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::timeActivatedExplicitSource::update()
|
void Foam::timeActivatedExplicitSource::update()
|
||||||
{
|
{
|
||||||
|
// Set the source value
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
(runTime_.time().value() >= timeStart_)
|
(runTime_.time().value() >= timeStart_)
|
||||||
@ -164,6 +223,12 @@ void Foam::timeActivatedExplicitSource::update()
|
|||||||
{
|
{
|
||||||
currentValue_ = offValue_;
|
currentValue_ = offValue_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the cell set if the mesh is changing
|
||||||
|
if (mesh_.changing())
|
||||||
|
{
|
||||||
|
updateCellSet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,24 +23,28 @@ License
|
|||||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
Class
|
Class
|
||||||
Foam::timeActivatedExplicitSource
|
Foam::timeActivatedExplicitSourceNew
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Creates a cell set source that is activated at timeStart_ for duration_
|
Creates a cell set source that is activated at a given time, and remains
|
||||||
|
active for a specified duration. The source value is either in specific
|
||||||
|
(XX/m3) or absolute (XX) units.
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
timeActivatedExplicitSource.C
|
timeActivatedExplicitSourceNew.C
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef timeActivatedExplicitSource_H
|
#ifndef timeActivatedExplicitSource_H
|
||||||
#define timeActivatedExplicitSource_H
|
#define timeActivatedExplicitSource_H
|
||||||
|
|
||||||
|
#include "IOdictionary.H"
|
||||||
#include "autoPtr.H"
|
#include "autoPtr.H"
|
||||||
#include "topoSetSource.H"
|
#include "topoSetSource.H"
|
||||||
#include "cellSet.H"
|
#include "cellSet.H"
|
||||||
#include "fvMesh.H"
|
#include "fvMesh.H"
|
||||||
#include "Time.H"
|
#include "Time.H"
|
||||||
|
#include "NamedEnum.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -52,11 +56,34 @@ namespace Foam
|
|||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
class timeActivatedExplicitSource
|
class timeActivatedExplicitSource
|
||||||
|
:
|
||||||
|
public IOdictionary
|
||||||
{
|
{
|
||||||
// Private data
|
public:
|
||||||
|
|
||||||
//- Properties dictionary
|
enum volumeType
|
||||||
IOdictionary dict_;
|
{
|
||||||
|
vtSpecific,
|
||||||
|
vtAbsolute
|
||||||
|
};
|
||||||
|
|
||||||
|
static const NamedEnum<volumeType, 2> volumeTypeNames_;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// Private member functions
|
||||||
|
|
||||||
|
//- Update the cell set that the source is acting on
|
||||||
|
void updateCellSet();
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected data
|
||||||
|
|
||||||
|
//- Name of the source
|
||||||
|
word sourceName_;
|
||||||
|
|
||||||
//- Reference to the mesh
|
//- Reference to the mesh
|
||||||
const fvMesh& mesh_;
|
const fvMesh& mesh_;
|
||||||
@ -64,8 +91,14 @@ class timeActivatedExplicitSource
|
|||||||
//- Reference to time database
|
//- Reference to time database
|
||||||
const Time& runTime_;
|
const Time& runTime_;
|
||||||
|
|
||||||
//- Name of cell source
|
|
||||||
word cellSource_;
|
// Source properties
|
||||||
|
|
||||||
|
//- Dimensions
|
||||||
|
const dimensionSet dimensions_;
|
||||||
|
|
||||||
|
//- Volume type
|
||||||
|
volumeType volumeType_;
|
||||||
|
|
||||||
//- Time start [s]
|
//- Time start [s]
|
||||||
scalar timeStart_;
|
scalar timeStart_;
|
||||||
@ -74,22 +107,31 @@ class timeActivatedExplicitSource
|
|||||||
scalar duration_;
|
scalar duration_;
|
||||||
|
|
||||||
//- Value when "on"
|
//- Value when "on"
|
||||||
dimensionedScalar onValue_;
|
scalar onValue_;
|
||||||
|
|
||||||
//- Value when "off"
|
//- Value when "off"
|
||||||
dimensionedScalar offValue_;
|
scalar offValue_;
|
||||||
|
|
||||||
//- Current source value
|
//- Current source value
|
||||||
dimensionedScalar currentValue_;
|
scalar currentValue_;
|
||||||
|
|
||||||
//- The method by which the cells will be selecetd
|
|
||||||
|
// Cell set
|
||||||
|
|
||||||
|
//- Cell volumes
|
||||||
|
scalarList V_;
|
||||||
|
|
||||||
|
//- Name of cell source (XXXToCell)
|
||||||
|
word cellSource_;
|
||||||
|
|
||||||
|
//- Method by which the cells will be selected
|
||||||
autoPtr<topoSetSource> cellSelector_;
|
autoPtr<topoSetSource> cellSelector_;
|
||||||
|
|
||||||
//- The set of selected cells
|
//- Set of selected cells
|
||||||
cellSet selectedCellSet_;
|
cellSet selectedCellSet_;
|
||||||
|
|
||||||
|
|
||||||
// Private Member Functions
|
// Protected Member Functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
timeActivatedExplicitSource(const timeActivatedExplicitSource&);
|
timeActivatedExplicitSource(const timeActivatedExplicitSource&);
|
||||||
@ -103,7 +145,12 @@ public:
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Construct from explicit source name and mesh
|
//- Construct from explicit source name and mesh
|
||||||
timeActivatedExplicitSource(const word&, const fvMesh&);
|
timeActivatedExplicitSource
|
||||||
|
(
|
||||||
|
const word&,
|
||||||
|
const fvMesh&,
|
||||||
|
const dimensionSet&
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// Member Functions
|
// Member Functions
|
||||||
@ -117,14 +164,17 @@ public:
|
|||||||
scalar duration() const;
|
scalar duration() const;
|
||||||
|
|
||||||
//- Return the current value of the source
|
//- Return the current value of the source
|
||||||
const dimensionedScalar& currentValue() const;
|
const dimensionedScalar currentValue() const;
|
||||||
|
|
||||||
//- Return a tmp field of the source
|
//- Return a tmp field of the source
|
||||||
tmp<DimensionedField<scalar, volMesh> > Su() const;
|
virtual tmp<DimensionedField<scalar, volMesh> > Su() const;
|
||||||
|
|
||||||
|
|
||||||
|
//- Read properties dictionary
|
||||||
|
virtual bool read();
|
||||||
|
|
||||||
//- Update
|
//- Update
|
||||||
void update();
|
virtual void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user