Commit 2bb9a4dd authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: Overhaul of time activated explicit sources

- deprecated:
  - timeActivatedExplicitSource (old base type)
  - timeActivatedExplicitCellSource
  - timeActivatedExplicitMulticomponentPointSource

- introduced timeActivatedExplicitSource
  - templated on primitive type - scalar, vector, tensor...
  - takes as input, either a cell set or list of points
parent 82dab7d6
......@@ -341,10 +341,5 @@ $(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
$(fieldSources)/timeActivatedExplicitMulticomponentPointSource/pointSourceProperties/pointSourcePropertiesIO.C
LIB = $(FOAM_LIBBIN)/libfiniteVolume
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "pointSourceProperties.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pointSourceProperties::pointSourceProperties()
:
name_("unknownPointSourceName"),
timeStart_(0.0),
duration_(0.0),
location_(point::zero),
fieldData_()
{}
Foam::pointSourceProperties::pointSourceProperties(const dictionary& dict)
:
name_(dict.name().name()),
timeStart_(readScalar(dict.lookup("timeStart"))),
duration_(readScalar(dict.lookup("duration"))),
location_(dict.lookup("location")),
fieldData_(dict.lookup("fieldData"))
{}
Foam::pointSourceProperties::pointSourceProperties
(
const pointSourceProperties& psp
)
:
name_(psp.name_),
timeStart_(psp.timeStart_),
duration_(psp.duration_),
location_(psp.location_),
fieldData_(psp.fieldData_)
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::pointSourceProperties::operator=(const pointSourceProperties& rhs)
{
// Check for assignment to self
if (this == &rhs)
{
FatalErrorIn
(
"pointSourceProperties::operator=(const pointSourceProperties&)"
) << "Attempted assignment to self" << nl
<< abort(FatalError);
}
// Set updated values
name_ = rhs.name_;
timeStart_ = rhs.timeStart_;
duration_ = rhs.duration_;
location_ = rhs.location_;
fieldData_ = rhs.fieldData_;}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::pointSourceProperties
Description
Helper class to describe point source properties
SourceFiles
pointSourceProperties.C
\*---------------------------------------------------------------------------*/
#ifndef pointSourceProperties_H
#define pointSourceProperties_H
#include "IOdictionary.H"
#include "fvMesh.H"
#include "Time.H"
#include "Tuple2.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class pointSourceProperties Declaration
\*---------------------------------------------------------------------------*/
class pointSourceProperties
{
protected:
// Protected data
typedef Tuple2<word, scalar> fieldNameValuePair;
//- Source name
word name_;
//- Time start
scalar timeStart_;
//- Duration
scalar duration_;
//- Point location
point location_;
//- List of source field name vs value pairs
List<fieldNameValuePair> fieldData_;
public:
// Constructors
//- Construct null
pointSourceProperties();
//- Construct from dictionary
pointSourceProperties(const dictionary& dict);
//- Construct from Istream
pointSourceProperties(Istream& is);
//- Copy constructor
pointSourceProperties(const pointSourceProperties&);
// Member Functions
// Access
//- Return const access to the source name
inline const word& name() const;
//- Return const access to the time start
inline scalar timeStart() const;
//- Return const access to the time end
inline scalar timeEnd() const;
//- Return const access to the duration
inline scalar duration() const;
//- Return const access to the point location
inline const point& location() const;
//- Return const access to the source field name vs value pairs
inline const List<fieldNameValuePair>& fieldData() const;
// Edit
//- Return access to the source name
inline word& name();
//- Return access to the time start
inline scalar& timeStart();
//- Return access to the duration
inline scalar& duration();
//- Return access to the point location
inline point& location();
//- Return access to the source field name vs value pairs
inline List<fieldNameValuePair>& fieldData();
// Member Operators
void operator=(const pointSourceProperties&);
// IOstream operators
friend Istream& operator>>(Istream&, pointSourceProperties&);
friend Ostream& operator<<(Ostream&, const pointSourceProperties&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "pointSourcePropertiesI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "timeActivatedExplicitMulticomponentPointSource.H"
#include "volFields.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::label
Foam::timeActivatedExplicitMulticomponentPointSource::carrierFieldId
(
const word& fieldName
)
{
forAll(carrierFields_, fieldI)
{
if (carrierFields_[fieldI].name() == fieldName)
{
return fieldI;
}
}
return -1;
}
void Foam::timeActivatedExplicitMulticomponentPointSource::updateAddressing()
{
forAll(pointSources_, sourceI)
{
const pointSourceProperties& psp = pointSources_[sourceI];
bool foundCell = false;
label cid = mesh_.findCell(psp.location());
if (cid >= 0)
{
foundCell = mesh_.pointInCell(psp.location(), cid);
}
reduce(foundCell, orOp<bool>());
if (!foundCell)
{
label cid = mesh_.findNearestCell(psp.location());
if (cid >= 0)
{
foundCell = mesh_.pointInCell(psp.location(), cid);
}
}
reduce(foundCell, orOp<bool>());
if (!foundCell)
{
FatalErrorIn
(
"timeActivatedExplicitMulticomponentPointSource::"
"updateAddressing()"
) << "Unable to find location " << psp.location() << " in mesh "
<< "for source " << psp.name() << nl
<< exit(FatalError);
}
else
{
cellOwners_[sourceI] = cid;
}
fieldIds_[sourceI].setSize(psp.fieldData().size());
forAll(psp.fieldData(), fieldI)
{
const word& fieldName = psp.fieldData()[fieldI].first();
label cfid = carrierFieldId(fieldName);
if (cfid < 0)
{
FatalErrorIn
(
"timeActivatedExplicitMulticomponentPointSource::"
"updateAddressing()"
) << "Unable to find field " << fieldName << " in carrier "
<< "fields for source " << psp.name() << nl
<< exit(FatalError);
}
else
{
fieldIds_[sourceI][fieldI] = cfid;
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::timeActivatedExplicitMulticomponentPointSource::
timeActivatedExplicitMulticomponentPointSource
(
const word& name,
const fvMesh& mesh,
const PtrList<volScalarField>& carrierFields,
const dimensionSet& dims