Commit a623ab42 authored by Henry Weller's avatar Henry Weller
Browse files

timeVaryingMappedFixedValue: Reinstated support for AverageField

parent 08e941dc
......@@ -123,6 +123,23 @@ void Foam::pointPatchField<Type>::write(Ostream& os) const
}
template<class Type>
template<class EntryType>
void Foam::pointPatchField<Type>::writeEntryIfDifferent
(
Ostream& os,
const word& entryName,
const EntryType& value1,
const EntryType& value2
) const
{
if (value1 != value2)
{
os.writeKeyword(entryName) << value2 << token::END_STATEMENT << nl;
}
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::pointPatchField<Type>::patchInternalField() const
......
......@@ -429,8 +429,21 @@ public:
);
//- Write
virtual void write(Ostream&) const;
// I-O
//- Write
virtual void write(Ostream&) const;
//- Helper function to write the keyword and entry only if the
// values are not equal. The value is then output as value2
template<class EntryType>
void writeEntryIfDifferent
(
Ostream& os,
const word& entryName,
const EntryType& value1,
const EntryType& value2
) const;
// Member operators
......
......@@ -27,6 +27,18 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::Function1Types::Constant<Type>::Constant
(
const word& entryName,
const Type& val
)
:
Function1<Type>(entryName),
value_(val)
{}
template<class Type>
Foam::Function1Types::Constant<Type>::Constant
(
......
......@@ -78,6 +78,9 @@ public:
// Constructors
//- Construct from entry name and value
Constant(const word& entryName, const Type& val);
//- Construct from entry name and dictionary
Constant(const word& entryName, const dictionary& dict);
......
......@@ -180,7 +180,6 @@ $(derivedFvPatchFields)/supersonicFreestream/supersonicFreestreamFvPatchVectorFi
$(derivedFvPatchFields)/surfaceNormalFixedValue/surfaceNormalFixedValueFvPatchVectorField.C
$(derivedFvPatchFields)/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvPatchVectorField.C
$(derivedFvPatchFields)/syringePressure/syringePressureFvPatchScalarField.C
$(derivedFvPatchFields)/timeVaryingMappedFixedValue/AverageIOFields.C
$(derivedFvPatchFields)/timeVaryingMappedFixedValue/timeVaryingMappedFixedValueFvPatchFields.C
$(derivedFvPatchFields)/totalPressure/totalPressureFvPatchScalarField.C
$(derivedFvPatchFields)/totalTemperature/totalTemperatureFvPatchScalarField.C
......
......@@ -23,65 +23,60 @@ License
\*---------------------------------------------------------------------------*/
#include "AverageIOField.H"
#include "AverageField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::AverageIOField<Type>::AverageIOField
(
const IOobject& io
)
Foam::AverageField<Type>::AverageField(const label size)
:
regIOobject(io)
{
readStream(typeName) >> average_;
readStream(typeName) >> static_cast<Field<Type>&>(*this);
close();
}
template<class Type>
Foam::AverageIOField<Type>::AverageIOField
(
const IOobject& io,
const label size
)
:
regIOobject(io),
Field<Type>(size),
average_(Zero)
{}
template<class Type>
Foam::AverageIOField<Type>::AverageIOField
Foam::AverageField<Type>::AverageField
(
const IOobject& io,
const Type& average,
const Field<Type>& f
const Field<Type>& f,
const Type& average
)
:
regIOobject(io),
Field<Type>(f),
average_(average)
{}
template<class Type>
Foam::AverageField<Type>::AverageField(Istream& is)
:
Field<Type>(is),
average_(pTraits<Type>(is))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
const Type& Foam::AverageField<Type>::average() const
{
return average_;
}
template<class Type>
Type&Foam::AverageField<Type>::average()
{
if (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
{
readStream(typeName)
>> average_
>> static_cast<Field<Type>&>(*this);
close();
}
return average_;
}
template<class Type>
bool Foam::AverageIOField<Type>::writeData(Ostream& os) const
bool Foam::AverageField<Type>::writeData(Ostream& os) const
{
os << average_
os << static_cast<const Field<Type>&>(*this)
<< token::NL
<< static_cast<const Field<Type>&>(*this);
<< average_;
return os.good();
}
......
......@@ -22,20 +22,19 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::AverageIOField
Foam::AverageField
Description
A primitive field + average with IO.
A primitive field with a separate average value.
SourceFiles
AverageIOField.C
AverageField.C
\*---------------------------------------------------------------------------*/
#ifndef AverageIOField_H
#define AverageIOField_H
#ifndef AverageField_H
#define AverageField_H
#include "regIOobject.H"
#include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -44,13 +43,12 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class AverageIOField Declaration
Class AverageField Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class AverageIOField
class AverageField
:
public regIOobject,
public Field<Type>
{
// Private data
......@@ -61,44 +59,23 @@ class AverageIOField
public:
TypeName("AverageField");
// Constructors
//- Construct from IOobject
AverageIOField
(
const IOobject&
);
//- Construct from IOobject and size (does not set values)
AverageIOField
(
const IOobject&,
const label size
);
//- Construct from size (does not set values)
AverageField(const label size);
//- Construct from components
AverageIOField
(
const IOobject&,
const Type& average,
const Field<Type>&
);
AverageField(const Field<Type>&, const Type& average);
//- Construct from Istream
AverageField(Istream&);
// Member functions
const Type& average() const
{
return average_;
}
const Type& average() const;
Type& average()
{
return average_;
}
Type& average();
bool writeData(Ostream& os) const;
};
......@@ -111,7 +88,7 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "AverageIOField.C"
#include "AverageField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "AverageIOField.H"
#include "fieldTypes.H"
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
typedef AverageIOField<scalar> scalarAverageIOField;
typedef AverageIOField<vector> vectorAverageIOField;
typedef AverageIOField<sphericalTensor> sphericalTensorAverageIOField;
typedef AverageIOField<symmTensor> symmTensorAverageIOField;
typedef AverageIOField<tensor> tensorAverageIOField;
defineTemplateTypeNameAndDebugWithName
(
scalarAverageIOField,
"scalarAverageField",
0
);
defineTemplateTypeNameAndDebugWithName
(
vectorAverageIOField,
"vectorAverageField",
0
);
defineTemplateTypeNameAndDebugWithName
(
sphericalTensorAverageIOField,
"sphericalTensorAverageField",
0
);
defineTemplateTypeNameAndDebugWithName
(
symmTensorAverageIOField,
"symmTensorAverageField",
0
);
defineTemplateTypeNameAndDebugWithName
(
tensorAverageIOField,
"tensorAverageField",
0
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -25,6 +25,7 @@ License
#include "timeVaryingMappedFixedValueFvPatchField.H"
#include "Time.H"
#include "AverageField.H"
#include "IFstream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -64,7 +65,7 @@ timeVaryingMappedFixedValueFvPatchField
:
fixedValueFvPatchField<Type>(p, iF),
fieldTableName_(iF.name()),
setAverage_(readBool(dict.lookup("setAverage"))),
setAverage_(dict.lookupOrDefault("setAverage", false)),
perturb_(dict.lookupOrDefault("perturb", 1e-5)),
mapMethod_
(
......@@ -82,8 +83,13 @@ timeVaryingMappedFixedValueFvPatchField
endSampleTime_(-1),
endSampledValues_(0),
endAverage_(Zero),
offset_(Function1<Type>::New("offset", dict))
offset_()
{
if (dict.found("offset"))
{
offset_ = Function1<Type>::New("offset", dict);
}
if
(
mapMethod_ != "planarInterpolation"
......@@ -97,7 +103,6 @@ timeVaryingMappedFixedValueFvPatchField
<< ", 'nearest'" << exit(FatalIOError);
}
dict.readIfPresent("fieldTable", fieldTableName_);
if (dict.found("value"))
......@@ -251,20 +256,6 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::checkTable()
pointField samplePoints((IFstream(samplePointsFile)()));
// pointIOField samplePoints
// (
// IOobject
// (
// "points",
// this->db().time().constant(),
// "boundaryData"/this->patch().name(),
// this->db(),
// IOobject::MUST_READ,
// IOobject::AUTO_WRITE,
// false
// )
// );
if (debug)
{
Info<< "timeVaryingMappedFixedValueFvPatchField :"
......@@ -376,22 +367,18 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::checkTable()
/fieldTableName_
);
Field<Type> vals((IFstream(valsFile)()));
// IOField<Type> vals
// (
// IOobject
// (
// fieldTableName_,
// this->db().time().constant(),
// "boundaryData"
// /this->patch().name()
// /sampleTimes_[startSampleTime_].name(),
// this->db(),
// IOobject::MUST_READ,
// IOobject::AUTO_WRITE,
// false
// )
// );
Field<Type> vals;
if (setAverage_)
{
AverageField<Type> avals((IFstream(valsFile)()));
vals = avals;
startAverage_ = avals.average();
}
else
{
IFstream(valsFile)() >> vals;
}
if (vals.size() != mapperPtr_().sourceSize())
{
......@@ -402,7 +389,6 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::checkTable()
<< ") in file " << valsFile << exit(FatalError);
}
//startAverage_ = vals.average();
startSampledValues_ = mapperPtr_().interpolate(vals);
}
}
......@@ -432,32 +418,37 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::checkTable()
}
// Reread values and interpolate
IOField<Type> vals
fileName valsFile
(
IOobject
(
fieldTableName_,
this->db().time().constant(),
"boundaryData"
/this->patch().name()
/sampleTimes_[endSampleTime_].name(),
this->db(),
IOobject::MUST_READ,
IOobject::AUTO_WRITE,
false
)
this->db().time().constant()
/"boundaryData"
/this->patch().name()
/sampleTimes_[endSampleTime_].name()
/fieldTableName_
);
Field<Type> vals;
if (setAverage_)
{
AverageField<Type> avals((IFstream(valsFile)()));
vals = avals;
endAverage_ = avals.average();
}
else
{
IFstream(valsFile)() >> vals;
}
if (vals.size() != mapperPtr_().sourceSize())
{
FatalErrorInFunction
<< "Number of values (" << vals.size()
<< ") differs from the number of points ("
<< mapperPtr_().sourceSize()
<< ") in file " << vals.objectPath() << exit(FatalError);
<< ") in file " << valsFile << exit(FatalError);
}
//endAverage_ = vals.average();
endSampledValues_ = mapperPtr_().interpolate(vals);
}
}
......@@ -481,7 +472,7 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::updateCoeffs()
if (endSampleTime_ == -1)
{
// only start value
// Only start value
if (debug)
{
Pout<< "updateCoeffs : Sampled, non-interpolated values"
......@@ -554,9 +545,12 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::updateCoeffs()
}
}
// apply offset to mapped values
const scalar t = this->db().time().timeOutputValue();
this->operator==(*this + offset_->value(t));
// Apply offset to mapped values
if (offset_.valid())
{
const scalar t = this->db().time().timeOutputValue();
this->operator==(*this + offset_->value(t));
}
if (debug)
{
......@@ -576,32 +570,32 @@ void Foam::timeVaryingMappedFixedValueFvPatchField<Type>::write
) const
{
fvPatchField<Type>::write(os);
os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
if (perturb_ != 1e-5)
{
os.writeKeyword("perturb") << perturb_ << token::END_STATEMENT << nl;
}
if (fieldTableName_ != this->internalField().name())
{
os.writeKeyword("fieldTable") << fieldTableName_
<< token::END_STATEMENT << nl;
}
this->writeEntryIfDifferent(os, "setAverage", Switch(false), setAverage_);
if
this->writeEntryIfDifferent(os, "perturb", 1e-5, perturb_);
this->writeEntryIfDifferent
(
(
!mapMethod_.empty()
&& mapMethod_ != "planarInterpolation"
)
)
os,
"fieldTable",
this->internalField().name(),
fieldTableName_
);
this->writeEntryIfDifferent
(
os,
"mapMethod",