time-varying UniformFixedValue and MassFlowRate boundary conditions using new timeSeries template

This commit is contained in:
Mark Olesen
2008-05-08 14:50:05 +02:00
parent 73cf0583d5
commit 86c5794294
4 changed files with 463 additions and 91 deletions

View File

@ -0,0 +1,191 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2006-07 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 "timeVaryingMassFlowRateInletVelocityFvPatchVectorField.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "surfaceFields.H"
#include "Time.H"
#include "IFstream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF
)
:
massFlowRateInletVelocityFvPatchVectorField(p, iF)
{}
Foam::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const timeVaryingMassFlowRateInletVelocityFvPatchVectorField& ptf,
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
massFlowRateInletVelocityFvPatchVectorField(ptf, p, iF, mapper),
timeDataFile_(ptf.timeDataFile_),
timeSeries_(ptf.timeBounding())
{}
Foam::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const fvPatch& p,
const DimensionedField<vector, volMesh>& iF,
const dictionary& dict
)
:
massFlowRateInletVelocityFvPatchVectorField(p, iF, dict),
timeDataFile_(fileName(dict.lookup("timeDataFile")).expand()),
timeSeries_(word(dict.lookup("timeBounding")))
{}
Foam::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const timeVaryingMassFlowRateInletVelocityFvPatchVectorField& ptf
)
:
massFlowRateInletVelocityFvPatchVectorField(ptf),
timeDataFile_(ptf.timeDataFile_),
timeSeries_(ptf.timeBounding())
{}
Foam::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const timeVaryingMassFlowRateInletVelocityFvPatchVectorField& ptf,
const DimensionedField<vector, volMesh>& iF
)
:
massFlowRateInletVelocityFvPatchVectorField(ptf, iF),
timeDataFile_(ptf.timeDataFile_),
timeSeries_(ptf.timeBounding())
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar
Foam::timeVaryingMassFlowRateInletVelocityFvPatchVectorField::
currentValue()
{
if (timeSeries_.size() == 0)
{
if (timeDataFile_.size() == 0)
{
FatalErrorIn
(
"timeVaryingMassFlowRateInletVelocity"
"::currentValue()"
) << "timeDataFile not specified for Patch "
<< this->patch().name()
<< exit(FatalError);
}
else
{
// just in case we change the interface to timeSeries
word boundType = timeBounding();
IFstream(timeDataFile_)() >> timeSeries_;
timeSeries_.bounding(boundType);
// be a bit paranoid and check that the list is okay
timeSeries_.check();
}
if (timeSeries_.size() == 0)
{
FatalErrorIn
(
"timeVaryingMassFlowRateInletVelocity"
"::currentValue()"
) << "empty time series for Patch "
<< this->patch().name()
<< exit(FatalError);
}
}
return timeSeries_(this->db().time().timeOutputValue());
}
void Foam::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField::
updateCoeffs()
{
if (updated())
{
return;
}
massFlowRate() = currentValue();
massFlowRateInletVelocityFvPatchVectorField::updateCoeffs();
}
void Foam::
timeVaryingMassFlowRateInletVelocityFvPatchVectorField::
write(Ostream& os) const
{
massFlowRateInletVelocityFvPatchVectorField::write(os);
os.writeKeyword("timeDataFile")
<< timeDataFile_ << token::END_STATEMENT << nl;
os.writeKeyword("timeBounding")
<< timeBounding() << token::END_STATEMENT << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchVectorField,
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
);
}
// ************************************************************************* //

View File

@ -0,0 +1,185 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2006-07 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::timeVaryingMassFlowRateInletVelocityFvPatchVectorField
Description
A time-varying form of a massflow normal vector boundary condition.
Example of the boundary condition specification:
@verbatim
inlet
{
type timeVaryingMassFlowRateInletVelocity;
massFlowRate 0.2; // Massflow rate [kg/s]
value uniform (0 0 0); // placeholder
timeDataFile "time-series";
timeBounding repeat; // (error|warn|clamp|repeat)
}
@endverbatim
Note
- The value is positive inwards
- may not work correctly for transonic inlets!
- strange behaviour with potentialFoam since the U equation is not solved
See Also
Foam::timeSeries and Foam::massFlowRateInletVelocityFvPatchVectorField
SourceFiles
timeVaryingMassFlowRateInletVelocityFvPatchVectorField.C
\*---------------------------------------------------------------------------*/
#ifndef timeVaryingMassFlowRateInletVelocityFvPatchVectorField_H
#define timeVaryingMassFlowRateInletVelocityFvPatchVectorField_H
#include "massFlowRateInletVelocityFvPatchVectorField.H"
#include "timeSeries.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class timeVaryingMassFlowRateInletVelocityFvPatch Declaration
\*---------------------------------------------------------------------------*/
class timeVaryingMassFlowRateInletVelocityFvPatchVectorField
:
public massFlowRateInletVelocityFvPatchVectorField
{
// Private data
//- file containing time/massFlowRate
fileName timeDataFile_;
//- the time series being used, including the bounding treatment
timeSeries<scalar> timeSeries_;
//- interpolate the value at the current time
scalar currentValue();
public:
//- Runtime type information
TypeName("timeVaryingMassFlowRateInletVelocity");
// Constructors
//- Construct from patch and internal field
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const fvPatch&,
const DimensionedField<vector, volMesh>&
);
//- Construct from patch, internal field and dictionary
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const fvPatch&,
const DimensionedField<vector, volMesh>&,
const dictionary&
);
//- Construct by mapping given patch field onto a new patch
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const timeVaryingMassFlowRateInletVelocityFvPatchVectorField&,
const fvPatch&,
const DimensionedField<vector, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const timeVaryingMassFlowRateInletVelocityFvPatchVectorField&
);
//- Construct and return a clone
virtual tmp<fvPatchVectorField> clone() const
{
return tmp<fvPatchVectorField>
(
new timeVaryingMassFlowRateInletVelocityFvPatchVectorField(*this)
);
}
//- Construct as copy setting internal field reference
timeVaryingMassFlowRateInletVelocityFvPatchVectorField
(
const timeVaryingMassFlowRateInletVelocityFvPatchVectorField&,
const DimensionedField<vector, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchVectorField> clone
(
const DimensionedField<vector, volMesh>& iF
) const
{
return tmp<fvPatchVectorField>
(
new timeVaryingMassFlowRateInletVelocityFvPatchVectorField(*this, iF)
);
}
// Member functions
// Access
//- Return the out-of-bounds treatment as a word
word timeBounding() const
{
return timeSeries_.bounding();
}
//- Return the time series used
const timeSeries<scalar>& timeData() const
{
return timeSeries_;
}
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -26,18 +26,14 @@ License
#include "timeVaryingUniformFixedValueFvPatchField.H" #include "timeVaryingUniformFixedValueFvPatchField.H"
#include "Time.H" #include "Time.H"
#include "Tuple2.H"
#include "IFstream.H" #include "IFstream.H"
#include "interpolateXY.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::
timeVaryingUniformFixedValueFvPatchField<Type>:: timeVaryingUniformFixedValueFvPatchField<Type>::
timeVaryingUniformFixedValueFvPatchField timeVaryingUniformFixedValueFvPatchField
( (
@ -50,6 +46,7 @@ timeVaryingUniformFixedValueFvPatchField
template<class Type> template<class Type>
Foam::
timeVaryingUniformFixedValueFvPatchField<Type>:: timeVaryingUniformFixedValueFvPatchField<Type>::
timeVaryingUniformFixedValueFvPatchField timeVaryingUniformFixedValueFvPatchField
( (
@ -60,11 +57,13 @@ timeVaryingUniformFixedValueFvPatchField
) )
: :
fixedValueFvPatchField<Type>(ptf, p, iF, mapper), fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
timeDataFileName_(ptf.timeDataFileName_) timeDataFile_(ptf.timeDataFile_),
timeSeries_(ptf.timeBounding())
{} {}
template<class Type> template<class Type>
Foam::
timeVaryingUniformFixedValueFvPatchField<Type>:: timeVaryingUniformFixedValueFvPatchField<Type>::
timeVaryingUniformFixedValueFvPatchField timeVaryingUniformFixedValueFvPatchField
( (
@ -74,7 +73,8 @@ timeVaryingUniformFixedValueFvPatchField
) )
: :
fixedValueFvPatchField<Type>(p, iF), fixedValueFvPatchField<Type>(p, iF),
timeDataFileName_(fileName(dict.lookup("timeDataFileName")).expand()) timeDataFile_(fileName(dict.lookup("timeDataFile")).expand()),
timeSeries_(word(dict.lookup("timeBounding")))
{ {
if (dict.found("value")) if (dict.found("value"))
{ {
@ -88,6 +88,7 @@ timeVaryingUniformFixedValueFvPatchField
template<class Type> template<class Type>
Foam::
timeVaryingUniformFixedValueFvPatchField<Type>:: timeVaryingUniformFixedValueFvPatchField<Type>::
timeVaryingUniformFixedValueFvPatchField timeVaryingUniformFixedValueFvPatchField
( (
@ -95,11 +96,13 @@ timeVaryingUniformFixedValueFvPatchField
) )
: :
fixedValueFvPatchField<Type>(ptf), fixedValueFvPatchField<Type>(ptf),
timeDataFileName_(ptf.timeDataFileName_) timeDataFile_(ptf.timeDataFile_),
timeSeries_(ptf.timeBounding())
{} {}
template<class Type> template<class Type>
Foam::
timeVaryingUniformFixedValueFvPatchField<Type>:: timeVaryingUniformFixedValueFvPatchField<Type>::
timeVaryingUniformFixedValueFvPatchField timeVaryingUniformFixedValueFvPatchField
( (
@ -108,108 +111,83 @@ timeVaryingUniformFixedValueFvPatchField
) )
: :
fixedValueFvPatchField<Type>(ptf, iF), fixedValueFvPatchField<Type>(ptf, iF),
timeDataFileName_(ptf.timeDataFileName_) timeDataFile_(ptf.timeDataFile_),
timeSeries_(ptf.timeBounding())
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
void timeVaryingUniformFixedValueFvPatchField<Type>::checkTable() Type
Foam::timeVaryingUniformFixedValueFvPatchField<Type>::
currentValue()
{ {
const Time& tm = this->db().time(); if (timeSeries_.size() == 0)
if (times_.size() == 0)
{ {
if (timeDataFileName_.size() == 0) if (timeDataFile_.size() == 0)
{ {
FatalErrorIn FatalErrorIn
( (
"timeVaryingUniformFixedValueFvPatchField<Type>" "timeVaryingUniformFixedValueFvPatchField"
"::checkTable()" "::currentValue()"
) << "timeDataFileName not specified for Patch " ) << "timeDataFile not specified for Patch "
<< this->patch().name() << this->patch().name()
<< exit(FatalError); << exit(FatalError);
} }
else else
{ {
IFstream str(timeDataFileName_); // just in case we change the interface to timeSeries
word boundType = timeBounding();
List<Tuple2<scalar, Type> > timeValues(str); IFstream(timeDataFile_)() >> timeSeries_;
timeSeries_.bounding(boundType);
times_.setSize(timeValues.size()); // be a bit paranoid and check that the list is okay
values_.setSize(timeValues.size()); timeSeries_.check();
}
forAll(timeValues, i) if (timeSeries_.size() == 0)
{ {
times_[i] = timeValues[i].first(); FatalErrorIn
values_[i] = timeValues[i].second();
}
}
}
if (tm.value() < times_[0])
{
WarningIn
( (
"timeVaryingUniformFixedValueFvPatchField<Type>::checkTable()" "timeVaryingUniformFixedValueFvPatchField"
) << "current time (" << tm.value() "::currentValue()"
<< ") is less than the minimum in the data table (" ) << "empty time series for Patch "
<< times_[0] << ')' << endl << this->patch().name()
<< " Continuing with the value for the smallest time" << exit(FatalError);
<< endl; }
} }
if (tm.value() > times_[times_.size()-1]) return timeSeries_(this->db().time().timeOutputValue());
{
WarningIn
(
"timeVaryingUniformFixedValueFvPatchField<Type>::checkTable()"
) << "current time (" << tm.value()
<< ") is greater than the maximum in the data table ("
<< times_[times_.size()-1] << ')' << endl
<< " Continuing with the value for the largest time"
<< endl;
}
} }
template<class Type> template<class Type>
void timeVaryingUniformFixedValueFvPatchField<Type>::updateCoeffs() void Foam::timeVaryingUniformFixedValueFvPatchField<Type>::updateCoeffs()
{ {
if (this->updated()) if (this->updated())
{ {
return; return;
} }
checkTable(); fvPatchField<Type>::operator==(currentValue());
this->operator==
(
interpolateXY
(
this->db().time().value(),
times_,
values_
)
);
fixedValueFvPatchField<Type>::updateCoeffs(); fixedValueFvPatchField<Type>::updateCoeffs();
} }
template<class Type> template<class Type>
void timeVaryingUniformFixedValueFvPatchField<Type>::write(Ostream& os) const void Foam::timeVaryingUniformFixedValueFvPatchField<Type>::write(Ostream& os) const
{ {
fvPatchField<Type>::write(os); fvPatchField<Type>::write(os);
os.writeKeyword("timeDataFileName") os.writeKeyword("timeDataFile")
<< timeDataFileName_ << token::END_STATEMENT << nl; << timeDataFile_ << token::END_STATEMENT << nl;
os.writeKeyword("timeBounding")
<< timeBounding() << token::END_STATEMENT << nl;
this->writeEntry("value", os); this->writeEntry("value", os);
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //

View File

@ -26,7 +26,24 @@ Class
Foam::timeVaryingUniformFixedValueFvPatchField Foam::timeVaryingUniformFixedValueFvPatchField
Description Description
Foam::timeVaryingUniformFixedValueFvPatchField A time-varying form of a uniform fixed value boundary condition.
Example of the boundary condition specification:
@verbatim
inlet
{
type timeVaryingUniformFixedValue;
timeDataFile "time-series";
timeBounding clamp; // (error|warn|clamp|repeat)
}
@endverbatim
Note
This class is derived directly from a fixedValue patch rather than from
a uniformFixedValue patch.
See Also
Foam::timeSeries and Foam::fixedValueFvPatchField
SourceFiles SourceFiles
timeVaryingUniformFixedValueFvPatchField.C timeVaryingUniformFixedValueFvPatchField.C
@ -36,7 +53,8 @@ SourceFiles
#ifndef timeVaryingUniformFixedValueFvPatchField_H #ifndef timeVaryingUniformFixedValueFvPatchField_H
#define timeVaryingUniformFixedValueFvPatchField_H #define timeVaryingUniformFixedValueFvPatchField_H
#include "fixedValueFvPatchFields.H" #include "fixedValueFvPatchField.H"
#include "timeSeries.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,13 +72,14 @@ class timeVaryingUniformFixedValueFvPatchField
{ {
// Private data // Private data
fileName timeDataFileName_; //- file containing time/uniformFixedValue
fileName timeDataFile_;
scalarField times_; //- the time series being used, including the bounding treatment
Field<Type> values_; timeSeries<Type> timeSeries_;
void checkTable();
//- interpolate the value at the current time
Type currentValue();
public: public:
@ -85,8 +104,7 @@ public:
const dictionary& const dictionary&
); );
//- Construct by mapping given timeVaryingUniformFixedValueFvPatchField //- Construct by mapping given patch field onto a new patch
// onto a new patch
timeVaryingUniformFixedValueFvPatchField timeVaryingUniformFixedValueFvPatchField
( (
const timeVaryingUniformFixedValueFvPatchField<Type>&, const timeVaryingUniformFixedValueFvPatchField<Type>&,
@ -134,16 +152,16 @@ public:
// Access // Access
//- Return the list of times in the interpolation table //- Return the out-of-bounds treatment as a word
const scalarField& times() const word timeBounding() const
{ {
return times_; return timeSeries_.bounding();
} }
//- Return the list of values in the interpolation table //- Return the time series used
const Field<Type>& values() const timeSeries<Type>& timeData() const
{ {
return values_; return timeSeries_;
} }