updates to sources

This commit is contained in:
andy
2009-06-03 19:40:16 +01:00
parent d4da7d823a
commit 2bb2266872
8 changed files with 509 additions and 218 deletions

View File

@ -4,5 +4,5 @@ timeActivatedExplicitMulticomponentPointSource pointMassSources
"pointMassSources",
mesh,
Y,
dimMass/dimTime/dimVolume
dimMass/dimVolume/dimTime
);

View File

@ -319,6 +319,7 @@ $(SRF)/derivedFvPatchFields/SRFVelocityFvPatchVectorField/SRFVelocityFvPatchVect
fieldSources = $(general)/fieldSources
$(fieldSources)/pressureGradientExplicitSource/pressureGradientExplicitSource.C
$(fieldSources)/timeActivatedExplicitSource/timeActivatedExplicitSource.C
$(fieldSources)/timeActivatedExplicitCellSource/timeActivatedExplicitCellSource.C
$(fieldSources)/timeActivatedExplicitMulticomponentPointSource/timeActivatedExplicitMulticomponentPointSource.C
$(fieldSources)/timeActivatedExplicitMulticomponentPointSource/pointSourceProperties/pointSourceProperties.C

View File

@ -0,0 +1,175 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "timeActivatedExplicitCellSource.H"
#include "volFields.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::timeActivatedExplicitCellSource::updateCellSet()
{
cellSelector_->applyToSet(topoSetSource::NEW, selectedCellSet_);
Info<< " " << name_ << ": 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::timeActivatedExplicitCellSource::timeActivatedExplicitCellSource
(
const word& name,
const fvMesh& mesh,
const dimensionSet& dims
)
:
timeActivatedExplicitSource(name, mesh, dims),
onValue_(readScalar(lookup("onValue"))),
offValue_(readScalar(lookup("offValue"))),
V_(0),
cellSource_(lookup("cellSource")),
cellSelector_
(
topoSetSource::New
(
cellSource_,
mesh,
subDict(cellSource_ + "Coeffs")
)
),
selectedCellSet_
(
mesh,
name + "SourceCellSet",
mesh.nCells()/10 + 1 // Reasonable size estimate.
)
{
// Create the cell set
updateCellSet();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::timeActivatedExplicitCellSource::onValue() const
{
return onValue_;
}
Foam::scalar Foam::timeActivatedExplicitCellSource::offValue() const
{
return offValue_;
}
Foam::tmp<Foam::DimensionedField<Foam::scalar, Foam::volMesh> >
Foam::timeActivatedExplicitCellSource::Su()
{
tmp<DimensionedField<scalar, volMesh> > tSource
(
new DimensionedField<scalar, volMesh>
(
IOobject
(
name_ + "Su",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("zero", dimensions_, 0.0)
)
);
scalar value = offValue_;
if
(
active_
&& (runTime_.time().value() >= timeStart_)
&& (runTime_.time().value() <= timeStart_ + duration_)
)
{
// Update the cell set if the mesh is changing
if (mesh_.changing())
{
updateCellSet();
}
value = onValue_;
}
DimensionedField<scalar, volMesh>& sourceField = tSource();
label i = 0;
forAllConstIter(cellSet, selectedCellSet_, iter)
{
sourceField[iter.key()] = value/V_[i++];
}
return tSource;
}
bool Foam::timeActivatedExplicitCellSource::read()
{
if (timeActivatedExplicitSource::read())
{
lookup("onValue") >> onValue_;
lookup("offValue") >> offValue_;
lookup("cellSource") >> cellSource_;
cellSelector_ =
topoSetSource::New
(
cellSource_,
mesh_,
subDict(cellSource_ + "Coeffs")
);
updateCellSet();
return true;
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,143 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::timeActivatedExplicitSourceNew
Description
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
timeActivatedExplicitCellSource.C
\*---------------------------------------------------------------------------*/
#ifndef timeActivatedExplicitCellSource_H
#define timeActivatedExplicitCellSource_H
#include "timeActivatedExplicitSource.H"
#include "topoSetSource.H"
#include "cellSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class timeActivatedExplicitCellSource Declaration
\*---------------------------------------------------------------------------*/
class timeActivatedExplicitCellSource
:
public timeActivatedExplicitSource
{
private:
// Private member functions
//- Update the cell set that the source is acting on
void updateCellSet();
// Private Member Functions
//- Disallow default bitwise copy construct
timeActivatedExplicitCellSource(const timeActivatedExplicitCellSource&);
//- Disallow default bitwise assignment
void operator=(const timeActivatedExplicitCellSource&);
protected:
// Protected data
// Source properties
//- Value when "on"
scalar onValue_;
//- Value when "off"
scalar offValue_;
// Cell set
//- Cell volumes
scalarList V_;
//- Name of cell source (XXXToCell)
word cellSource_;
//- Method by which the cells will be selected
autoPtr<topoSetSource> cellSelector_;
//- Set of selected cells
cellSet selectedCellSet_;
public:
// Constructors
//- Construct from explicit source name and mesh
timeActivatedExplicitCellSource
(
const word&,
const fvMesh&,
const dimensionSet&
);
// Member Functions
// Access
//- Return the "on" value
virtual scalar onValue() const;
//- Return the "off" value
virtual scalar offValue() const;
//- Return a tmp field of the source
virtual tmp<DimensionedField<scalar, volMesh> > Su();
//- Read properties dictionary
virtual bool read();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -97,7 +97,7 @@ void Foam::timeActivatedExplicitMulticomponentPointSource::updateAddressing()
Foam::timeActivatedExplicitMulticomponentPointSource::
timeActivatedExplicitMulticomponentPointSource
(
const word& sourceName,
const word& name,
const fvMesh& mesh,
const PtrList<volScalarField>& carrierFields,
const dimensionSet& dims
@ -107,14 +107,14 @@ timeActivatedExplicitMulticomponentPointSource
(
IOobject
(
sourceName + "Properties",
name + "Properties",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
),
sourceName_(sourceName),
name_(name),
mesh_(mesh),
runTime_(mesh.time()),
dimensions_(dims),
@ -148,7 +148,7 @@ Foam::timeActivatedExplicitMulticomponentPointSource::Su
(
IOobject
(
sourceName_ + carrierFields_[fieldI].name() + "Su",
name_ + carrierFields_[fieldI].name() + "Su",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
@ -159,23 +159,84 @@ Foam::timeActivatedExplicitMulticomponentPointSource::Su
)
);
DimensionedField<scalar, volMesh>& sourceField = tSource();
forAll(pointSources_, sourceI)
if (active_)
{
const pointSourceProperties& psp = pointSources_[sourceI];
DimensionedField<scalar, volMesh>& sourceField = tSource();
forAll(fieldIds_[sourceI], i)
const scalarField& V = mesh_.V();
const scalar dt = runTime_.deltaT().value();
forAll(pointSources_, sourceI)
{
if
(
fieldIds_[sourceI][i] == fieldI
&& (runTime_.time().value() >= psp.timeStart())
&& (runTime_.time().value() <= psp.timeEnd())
)
const pointSourceProperties& psp = pointSources_[sourceI];
forAll(fieldIds_[sourceI], i)
{
const label cid = cellOwners_[sourceI];
sourceField[cid] += psp.fieldData()[i].second();
if
(
fieldIds_[sourceI][i] == fieldI
&& (runTime_.time().value() >= psp.timeStart())
&& (runTime_.time().value() <= psp.timeEnd())
)
{
const label cid = cellOwners_[sourceI];
sourceField[cid] += dt*psp.fieldData()[i].second()/V[cid];
}
}
}
}
return tSource;
}
Foam::tmp<Foam::DimensionedField<Foam::scalar, Foam::volMesh> >
Foam::timeActivatedExplicitMulticomponentPointSource::Su()
{
if (mesh_.changing())
{
updateAddressing();
}
tmp<DimensionedField<scalar, volMesh> > tSource
(
new DimensionedField<scalar, volMesh>
(
IOobject
(
name_ + "TotalSu",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("zero", dimensions_, 0.0)
)
);
if (active_)
{
DimensionedField<scalar, volMesh>& sourceField = tSource();
const scalarField& V = mesh_.V();
const scalar dt = runTime_.deltaT().value();
forAll(pointSources_, sourceI)
{
const pointSourceProperties& psp = pointSources_[sourceI];
forAll(fieldIds_[sourceI], i)
{
if
(
(runTime_.time().value() >= psp.timeStart())
&& (runTime_.time().value() <= psp.timeEnd())
)
{
const label cid = cellOwners_[sourceI];
sourceField[cid] += dt*psp.fieldData()[i].second()/V[cid];
}
}
}
}

View File

@ -30,7 +30,10 @@ Description
Carrier fields are supplied on consruction, and interrogated to provide the
field indices of the sources.
Properties are described in a <sourceName>Properties dictionary, e.g.:
Source values are assumed to be in <quantity>/s, and divided through by the
cell volumes before being returned, e.g. for a kg/s source
Properties are described in a <name>Properties dictionary
active true; // are sources active (true/false)
@ -43,8 +46,8 @@ Description
location (0 0 0);
fieldData
(
(H2O 0.1)
(O2 0.05)
(H2O 0.1) // kg/s
(O2 0.05) // kg/s
);
}
source2 // source name
@ -54,9 +57,9 @@ Description
location (1 1 1);
fieldData
(
(NO 0.1)
(CO2 0.05)
(H2 0.001)
(NO 0.1) // kg/s
(CO2 0.05) // kg/s
(H2 0.001) // kg/s
);
}
);
@ -93,7 +96,7 @@ protected:
// Protected data
//- Name of the source
word sourceName_;
word name_;
//- Reference to the mesh
const fvMesh& mesh_;
@ -156,12 +159,15 @@ public:
// Access
//- Return a tmp field of the source
//- Return a tmp field of the source for field fieldI
virtual tmp<DimensionedField<scalar, volMesh> > Su
(
const label fieldI
);
//- Return a tmp field of the total source
virtual tmp<DimensionedField<scalar, volMesh> > Su();
//- Read properties dictionary
virtual bool read();

View File

@ -44,33 +44,11 @@ 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 word& name,
const fvMesh& mesh,
const dimensionSet& dims
)
@ -79,51 +57,63 @@ Foam::timeActivatedExplicitSource::timeActivatedExplicitSource
(
IOobject
(
sourceName + "Properties",
name + "Properties",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
),
sourceName_(sourceName),
mesh_(mesh),
runTime_(mesh.time()),
name_(name),
active_(lookup("active")),
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,
subDict(cellSource_ + "Coeffs")
)
),
selectedCellSet_
(
mesh,
sourceName + "SourceCellSet",
mesh.nCells()/10 + 1 // Reasonable size estimate.
)
{
// Create the cell set
updateCellSet();
// Initialise the value
update();
}
duration_(readScalar(lookup("duration")))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::fvMesh& Foam::timeActivatedExplicitSource::mesh() const
{
return mesh_;
}
const Foam::Time& Foam::timeActivatedExplicitSource::runTime() const
{
return runTime_;
}
const Foam::word& Foam::timeActivatedExplicitSource::name() const
{
return name_;
}
const Foam::Switch& Foam::timeActivatedExplicitSource::active() const
{
return active_;
}
const Foam::dimensionSet& Foam::timeActivatedExplicitSource::dimensions() const
{
return dimensions_;
}
const Foam::timeActivatedExplicitSource::volumeType&
Foam::timeActivatedExplicitSource::volume() const
{
return volumeType_;
}
Foam::scalar Foam::timeActivatedExplicitSource::timeStart() const
{
return timeStart_;
@ -136,70 +126,22 @@ Foam::scalar Foam::timeActivatedExplicitSource::duration() const
}
const Foam::dimensionedScalar
Foam::timeActivatedExplicitSource::currentValue() const
{
return dimensionedScalar
(
sourceName_,
dimensions_,
currentValue_
);
}
Foam::tmp<Foam::DimensionedField<Foam::scalar, Foam::volMesh> >
Foam::timeActivatedExplicitSource::Su() const
{
tmp<DimensionedField<scalar, volMesh> > tSource
(
new DimensionedField<scalar, volMesh>
(
IOobject
(
sourceName_ + "Su",
runTime_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("zero", dimensions_, 0.0)
)
);
DimensionedField<scalar, volMesh>& sourceField = tSource();
label i = 0;
forAllConstIter(cellSet, selectedCellSet_, iter)
{
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;
lookup("active") >> active_;
if (active_)
{
volumeType_ = volumeTypeNames_.read(lookup("volumeType"));
lookup("timeStart") >> duration_;
lookup("duration") >> duration_;
return true;
}
else
{
return false;
}
}
else
{
@ -208,28 +150,6 @@ bool Foam::timeActivatedExplicitSource::read()
}
void Foam::timeActivatedExplicitSource::update()
{
// Set the source value
if
(
(runTime_.time().value() >= timeStart_)
&& (runTime_.time().value() <= timeStart_ + duration_)
)
{
currentValue_ = onValue_;
}
else
{
currentValue_ = offValue_;
}
// Update the cell set if the mesh is changing
if (mesh_.changing())
{
updateCellSet();
}
}
// ************************************************************************* //

View File

@ -23,15 +23,20 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::timeActivatedExplicitSourceNew
Foam::timeActivatedExplicitSource
Description
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.
Base class for field sources. Provides:
- name
- references to mesh and time
- dimensions
- volume type
- startTime
- duration
- read (from <sourceName>Properties dictionary)
SourceFiles
timeActivatedExplicitSourceNew.C
timeActivatedExplicitSource.C
\*---------------------------------------------------------------------------*/
@ -40,8 +45,6 @@ SourceFiles
#include "IOdictionary.H"
#include "autoPtr.H"
#include "topoSetSource.H"
#include "cellSet.H"
#include "fvMesh.H"
#include "Time.H"
#include "NamedEnum.H"
@ -72,19 +75,19 @@ public:
private:
// Private member functions
// Private Member Functions
//- Update the cell set that the source is acting on
void updateCellSet();
//- Disallow default bitwise copy construct
timeActivatedExplicitSource(const timeActivatedExplicitSource&);
//- Disallow default bitwise assignment
void operator=(const timeActivatedExplicitSource&);
protected:
// Protected data
//- Name of the source
word sourceName_;
//- Reference to the mesh
const fvMesh& mesh_;
@ -94,6 +97,12 @@ protected:
// Source properties
//- Name of the source
word name_;
//- Active flag
Switch active_;
//- Dimensions
const dimensionSet dimensions_;
@ -106,39 +115,6 @@ protected:
//- Duration [s]
scalar duration_;
//- Value when "on"
scalar onValue_;
//- Value when "off"
scalar offValue_;
//- Current source value
scalar currentValue_;
// Cell set
//- Cell volumes
scalarList V_;
//- Name of cell source (XXXToCell)
word cellSource_;
//- 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&);
//- Disallow default bitwise assignment
void operator=(const timeActivatedExplicitSource&);
public:
@ -157,24 +133,33 @@ public:
// Access
//- Return the reference to the mesh
virtual const fvMesh& mesh() const;
//- Return the reference to the time database
virtual const Time& runTime() const;
//- Return the source name
virtual const word& name() const;
//- Return the active flag
virtual const Switch& active() const;
//- Return the dimensions
virtual const dimensionSet& dimensions() const;
//- Return the volume type
virtual const volumeType& volume() const;
//- Return the start time
scalar timeStart() const;
virtual scalar timeStart() const;
//- Return the duration
scalar duration() const;
//- Return the current value of the source
const dimensionedScalar currentValue() const;
//- Return a tmp field of the source
virtual tmp<DimensionedField<scalar, volMesh> > Su() const;
virtual scalar duration() const;
//- Read properties dictionary
virtual bool read();
//- Update
virtual void update();
};