Commit c39c135b authored by Andrew Heather's avatar Andrew Heather
Browse files

general update + enabled absolute/specific option

parent 33caf9f6
......@@ -27,15 +27,55 @@ License
#include "timeActivatedExplicitSource.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 * * * * * * * * * * * * * * //
Foam::timeActivatedExplicitSource::timeActivatedExplicitSource
(
const word& sourceName,
const fvMesh& mesh
const fvMesh& mesh,
const dimensionSet& dims
)
:
dict_
IOdictionary
(
IOobject
(
......@@ -46,52 +86,36 @@ Foam::timeActivatedExplicitSource::timeActivatedExplicitSource
IOobject::NO_WRITE
)
),
sourceName_(sourceName),
mesh_(mesh),
runTime_(mesh.time()),
cellSource_(dict_.lookup("cellSource")),
timeStart_(dimensionedScalar(dict_.lookup("timeStart")).value()),
duration_(dimensionedScalar(dict_.lookup("duration")).value()),
onValue_(dict_.lookup("onValue")),
offValue_(dict_.lookup("offValue")),
currentValue_(dimensionedScalar("zero", onValue_.dimensions(), 0.0)),
dimensions_(dims),
volumeType_(volumeTypeNames_.read(lookup("volumeType"))),
timeStart_(readScalar(lookup("timeStart"))),
duration_(readScalar(lookup("duration"))),
onValue_(readScalar(lookup("onValue"))),
offValue_(readScalar(lookup("offValue"))),
currentValue_(0.0),
V_(0),
cellSource_(lookup("cellSource")),
cellSelector_
(
topoSetSource::New
(
cellSource_,
mesh,
dict_.subDict(cellSource_ + "Coeffs")
subDict(cellSource_ + "Coeffs")
)
),
selectedCellSet_
(
mesh,
"timeActivatedExplicitSourceCellSet",
sourceName + "SourceCellSet",
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
cellSelector_->applyToSet
(
topoSetSource::NEW,
selectedCellSet_
);
// Give some feedback
Info<< "timeVaryingExplitSource(" << sourceName << ")" << nl
<< "Selected " << returnReduce(selectedCellSet_.size(), sumOp<label>())
<< " cells." << endl;
updateCellSet();
// Initialise the value
update();
......@@ -112,10 +136,15 @@ Foam::scalar Foam::timeActivatedExplicitSource::duration() const
}
const Foam::dimensionedScalar&
const Foam::dimensionedScalar
Foam::timeActivatedExplicitSource::currentValue() const
{
return currentValue_;
return dimensionedScalar
(
sourceName_,
dimensions_,
currentValue_
);
}
......@@ -128,30 +157,60 @@ Foam::timeActivatedExplicitSource::Su() const
(
IOobject
(
"timeActivatedExplicitSource",
sourceName_ + "Su",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("zero", onValue_.dimensions(), 0.0)
dimensionedScalar("zero", dimensions_, 0.0)
)
);
DimensionedField<scalar, volMesh>& sourceField = tSource();
label i = 0;
forAllConstIter(cellSet, selectedCellSet_, iter)
{
sourceField[iter.key()] = currentValue_.value();
sourceField[iter.key()] = currentValue_/V_[i++];
}
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()
{
// Set the source value
if
(
(runTime_.time().value() >= timeStart_)
......@@ -164,6 +223,12 @@ void Foam::timeActivatedExplicitSource::update()
{
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
Class
Foam::timeActivatedExplicitSource
Foam::timeActivatedExplicitSourceNew
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
timeActivatedExplicitSource.C
timeActivatedExplicitSourceNew.C
\*---------------------------------------------------------------------------*/
#ifndef timeActivatedExplicitSource_H
#define timeActivatedExplicitSource_H
#include "IOdictionary.H"
#include "autoPtr.H"
#include "topoSetSource.H"
#include "cellSet.H"
#include "fvMesh.H"
#include "Time.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -48,15 +52,38 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class timeActivatedExplicitSource Declaration
Class timeActivatedExplicitSource Declaration
\*---------------------------------------------------------------------------*/
class timeActivatedExplicitSource
:
public IOdictionary
{
// Private data
public:
enum volumeType
{
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:
//- Properties dictionary
IOdictionary dict_;
// Protected data
//- Name of the source
word sourceName_;
//- Reference to the mesh
const fvMesh& mesh_;
......@@ -64,32 +91,47 @@ class timeActivatedExplicitSource
//- Reference to time database
const Time& runTime_;
//- Name of cell source
word cellSource_;
//- Time start [s]
scalar timeStart_;
// Source properties
//- Dimensions
const dimensionSet dimensions_;
//- Volume type
volumeType volumeType_;
//- Time start [s]
scalar timeStart_;
//- Duration [s]
scalar duration_;
//- Duration [s]
scalar duration_;
//- Value when "on"
scalar onValue_;
//- Value when "on"
dimensionedScalar onValue_;
//- Value when "off"
scalar offValue_;
//- Value when "off"
dimensionedScalar offValue_;
//- Current source value
scalar currentValue_;
//- Current source value
dimensionedScalar currentValue_;
//- The method by which the cells will be selecetd
autoPtr<topoSetSource> cellSelector_;
// Cell set
//- The set of selected cells
cellSet selectedCellSet_;
//- Cell volumes
scalarList V_;
//- Name of cell source (XXXToCell)
word cellSource_;
// Private Member Functions
//- Method by which the cells will be selected
autoPtr<topoSetSource> cellSelector_;
//- Set of selected cells
cellSet selectedCellSet_;
// Protected Member Functions
//- Disallow default bitwise copy construct
timeActivatedExplicitSource(const timeActivatedExplicitSource&);
......@@ -103,7 +145,12 @@ public:
// Constructors
//- Construct from explicit source name and mesh
timeActivatedExplicitSource(const word&, const fvMesh&);
timeActivatedExplicitSource
(
const word&,
const fvMesh&,
const dimensionSet&
);
// Member Functions
......@@ -117,14 +164,17 @@ public:
scalar duration() const;
//- Return the current value of the source
const dimensionedScalar& currentValue() const;
const dimensionedScalar currentValue() const;
//- 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
void update();
virtual void update();
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment