diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMassFlowRateInletVelocity/timeVaryingMassFlowRateInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMassFlowRateInletVelocity/timeVaryingMassFlowRateInletVelocityFvPatchVectorField.C new file mode 100644 index 0000000000..c5bf659384 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMassFlowRateInletVelocity/timeVaryingMassFlowRateInletVelocityFvPatchVectorField.C @@ -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& iF +) +: + massFlowRateInletVelocityFvPatchVectorField(p, iF) +{} + + +Foam:: +timeVaryingMassFlowRateInletVelocityFvPatchVectorField:: +timeVaryingMassFlowRateInletVelocityFvPatchVectorField +( + const timeVaryingMassFlowRateInletVelocityFvPatchVectorField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + massFlowRateInletVelocityFvPatchVectorField(ptf, p, iF, mapper), + timeDataFile_(ptf.timeDataFile_), + timeSeries_(ptf.timeBounding()) +{} + + +Foam:: +timeVaryingMassFlowRateInletVelocityFvPatchVectorField:: +timeVaryingMassFlowRateInletVelocityFvPatchVectorField +( + const fvPatch& p, + const DimensionedField& 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& 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 + ); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMassFlowRateInletVelocity/timeVaryingMassFlowRateInletVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMassFlowRateInletVelocity/timeVaryingMassFlowRateInletVelocityFvPatchVectorField.H new file mode 100644 index 0000000000..a00472d4c1 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingMassFlowRateInletVelocity/timeVaryingMassFlowRateInletVelocityFvPatchVectorField.H @@ -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 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& + ); + + //- Construct from patch, internal field and dictionary + timeVaryingMassFlowRateInletVelocityFvPatchVectorField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given patch field onto a new patch + timeVaryingMassFlowRateInletVelocityFvPatchVectorField + ( + const timeVaryingMassFlowRateInletVelocityFvPatchVectorField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Construct as copy + timeVaryingMassFlowRateInletVelocityFvPatchVectorField + ( + const timeVaryingMassFlowRateInletVelocityFvPatchVectorField& + ); + + //- Construct and return a clone + virtual tmp clone() const + { + return tmp + ( + new timeVaryingMassFlowRateInletVelocityFvPatchVectorField(*this) + ); + } + + //- Construct as copy setting internal field reference + timeVaryingMassFlowRateInletVelocityFvPatchVectorField + ( + const timeVaryingMassFlowRateInletVelocityFvPatchVectorField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp clone + ( + const DimensionedField& iF + ) const + { + return tmp + ( + 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& 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 + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFvPatchField.C index a6a6529c44..173563c7db 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFvPatchField.C @@ -26,18 +26,14 @@ License #include "timeVaryingUniformFixedValueFvPatchField.H" #include "Time.H" -#include "Tuple2.H" #include "IFstream.H" -#include "interpolateXY.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam -{ - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template +Foam:: timeVaryingUniformFixedValueFvPatchField:: timeVaryingUniformFixedValueFvPatchField ( @@ -50,6 +46,7 @@ timeVaryingUniformFixedValueFvPatchField template +Foam:: timeVaryingUniformFixedValueFvPatchField:: timeVaryingUniformFixedValueFvPatchField ( @@ -60,11 +57,13 @@ timeVaryingUniformFixedValueFvPatchField ) : fixedValueFvPatchField(ptf, p, iF, mapper), - timeDataFileName_(ptf.timeDataFileName_) + timeDataFile_(ptf.timeDataFile_), + timeSeries_(ptf.timeBounding()) {} template +Foam:: timeVaryingUniformFixedValueFvPatchField:: timeVaryingUniformFixedValueFvPatchField ( @@ -74,20 +73,22 @@ timeVaryingUniformFixedValueFvPatchField ) : fixedValueFvPatchField(p, iF), - timeDataFileName_(fileName(dict.lookup("timeDataFileName")).expand()) + timeDataFile_(fileName(dict.lookup("timeDataFile")).expand()), + timeSeries_(word(dict.lookup("timeBounding"))) { - if (dict.found("value")) - { - fvPatchField::operator==(Field("value", dict, p.size())); - } - else - { - updateCoeffs(); - } + if (dict.found("value")) + { + fvPatchField::operator==(Field("value", dict, p.size())); + } + else + { + updateCoeffs(); + } } template +Foam:: timeVaryingUniformFixedValueFvPatchField:: timeVaryingUniformFixedValueFvPatchField ( @@ -95,11 +96,13 @@ timeVaryingUniformFixedValueFvPatchField ) : fixedValueFvPatchField(ptf), - timeDataFileName_(ptf.timeDataFileName_) + timeDataFile_(ptf.timeDataFile_), + timeSeries_(ptf.timeBounding()) {} template +Foam:: timeVaryingUniformFixedValueFvPatchField:: timeVaryingUniformFixedValueFvPatchField ( @@ -108,108 +111,83 @@ timeVaryingUniformFixedValueFvPatchField ) : fixedValueFvPatchField(ptf, iF), - timeDataFileName_(ptf.timeDataFileName_) + timeDataFile_(ptf.timeDataFile_), + timeSeries_(ptf.timeBounding()) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void timeVaryingUniformFixedValueFvPatchField::checkTable() +Type +Foam::timeVaryingUniformFixedValueFvPatchField:: +currentValue() { - const Time& tm = this->db().time(); - - if (times_.size() == 0) + if (timeSeries_.size() == 0) { - if (timeDataFileName_.size() == 0) + if (timeDataFile_.size() == 0) { FatalErrorIn ( - "timeVaryingUniformFixedValueFvPatchField" - "::checkTable()" - ) << "timeDataFileName not specified for Patch " + "timeVaryingUniformFixedValueFvPatchField" + "::currentValue()" + ) << "timeDataFile not specified for Patch " << this->patch().name() << exit(FatalError); } else { - IFstream str(timeDataFileName_); + // just in case we change the interface to timeSeries + word boundType = timeBounding(); - List > timeValues(str); + IFstream(timeDataFile_)() >> timeSeries_; + timeSeries_.bounding(boundType); - times_.setSize(timeValues.size()); - values_.setSize(timeValues.size()); + // be a bit paranoid and check that the list is okay + timeSeries_.check(); + } - forAll(timeValues, i) - { - times_[i] = timeValues[i].first(); - values_[i] = timeValues[i].second(); - } + if (timeSeries_.size() == 0) + { + FatalErrorIn + ( + "timeVaryingUniformFixedValueFvPatchField" + "::currentValue()" + ) << "empty time series for Patch " + << this->patch().name() + << exit(FatalError); } } - if (tm.value() < times_[0]) - { - WarningIn - ( - "timeVaryingUniformFixedValueFvPatchField::checkTable()" - ) << "current time (" << tm.value() - << ") is less than the minimum in the data table (" - << times_[0] << ')' << endl - << " Continuing with the value for the smallest time" - << endl; - } - - if (tm.value() > times_[times_.size()-1]) - { - WarningIn - ( - "timeVaryingUniformFixedValueFvPatchField::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; - } + return timeSeries_(this->db().time().timeOutputValue()); } template -void timeVaryingUniformFixedValueFvPatchField::updateCoeffs() +void Foam::timeVaryingUniformFixedValueFvPatchField::updateCoeffs() { if (this->updated()) { return; } - checkTable(); - - this->operator== - ( - interpolateXY - ( - this->db().time().value(), - times_, - values_ - ) - ); - + fvPatchField::operator==(currentValue()); fixedValueFvPatchField::updateCoeffs(); } template -void timeVaryingUniformFixedValueFvPatchField::write(Ostream& os) const +void Foam::timeVaryingUniformFixedValueFvPatchField::write(Ostream& os) const { fvPatchField::write(os); - os.writeKeyword("timeDataFileName") - << timeDataFileName_ << token::END_STATEMENT << nl; + os.writeKeyword("timeDataFile") + << timeDataFile_ << token::END_STATEMENT << nl; + os.writeKeyword("timeBounding") + << timeBounding() << token::END_STATEMENT << nl; this->writeEntry("value", os); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam - // ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFvPatchField.H index f0040b65fd..23850c7862 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformFixedValue/timeVaryingUniformFixedValueFvPatchField.H @@ -26,7 +26,24 @@ Class Foam::timeVaryingUniformFixedValueFvPatchField 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 timeVaryingUniformFixedValueFvPatchField.C @@ -36,7 +53,8 @@ SourceFiles #ifndef timeVaryingUniformFixedValueFvPatchField_H #define timeVaryingUniformFixedValueFvPatchField_H -#include "fixedValueFvPatchFields.H" +#include "fixedValueFvPatchField.H" +#include "timeSeries.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -44,7 +62,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class timeVaryingUniformFixedValueFvPatch Declaration + Class timeVaryingUniformFixedValueFvPatch Declaration \*---------------------------------------------------------------------------*/ template @@ -54,13 +72,14 @@ class timeVaryingUniformFixedValueFvPatchField { // Private data - fileName timeDataFileName_; + //- file containing time/uniformFixedValue + fileName timeDataFile_; - scalarField times_; - Field values_; - - void checkTable(); + //- the time series being used, including the bounding treatment + timeSeries timeSeries_; + //- interpolate the value at the current time + Type currentValue(); public: @@ -85,8 +104,7 @@ public: const dictionary& ); - //- Construct by mapping given timeVaryingUniformFixedValueFvPatchField - // onto a new patch + //- Construct by mapping given patch field onto a new patch timeVaryingUniformFixedValueFvPatchField ( const timeVaryingUniformFixedValueFvPatchField&, @@ -134,16 +152,16 @@ public: // Access - //- Return the list of times in the interpolation table - const scalarField& times() const + //- Return the out-of-bounds treatment as a word + word timeBounding() const { - return times_; + return timeSeries_.bounding(); } - //- Return the list of values in the interpolation table - const Field& values() + //- Return the time series used + const timeSeries& timeData() const { - return values_; + return timeSeries_; }