mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
timeVaryingMappedFixedValue: Reinstated support for AverageField
This commit is contained in:
@ -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
|
||||
{
|
||||
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
|
||||
Type&Foam::AverageField<Type>::average()
|
||||
{
|
||||
os << average_
|
||||
return average_;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::AverageField<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
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
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -1,78 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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,31 +570,31 @@ 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.writeKeyword("mapMethod") << mapMethod_
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
os,
|
||||
"fieldTable",
|
||||
this->internalField().name(),
|
||||
fieldTableName_
|
||||
);
|
||||
|
||||
offset_->writeData(os);
|
||||
this->writeEntryIfDifferent
|
||||
(
|
||||
os,
|
||||
"mapMethod",
|
||||
word("planarInterpolation"),
|
||||
mapMethod_
|
||||
);
|
||||
|
||||
if (offset_.valid())
|
||||
{
|
||||
offset_->writeData(os);
|
||||
}
|
||||
|
||||
this->writeEntry("value", os);
|
||||
}
|
||||
|
||||
@ -29,38 +29,36 @@ Group
|
||||
|
||||
Description
|
||||
This boundary conditions interpolates the values from a set of supplied
|
||||
points in space and time. Supplied data should be specified in
|
||||
constant/boundaryData/\<patchname\> where:
|
||||
- points : pointField with locations
|
||||
- ddd : supplied values at time ddd
|
||||
The default mode of operation (mapMethod planarInterpolation) is
|
||||
to project the points onto a plane (constructed from the first threee
|
||||
points) and construct a 2D triangulation and finds for the face centres
|
||||
the triangle it is in and the weights to the 3 vertices.
|
||||
points in space and time.
|
||||
|
||||
The optional mapMethod nearest will avoid all projection and
|
||||
triangulation and just use the value at the nearest vertex.
|
||||
Supplied data should be specified in constant/boundaryData/\<patchname\>/
|
||||
- points : pointField of locations
|
||||
- \<time\>/\<field\> : field of values at time \<time\>
|
||||
|
||||
The default mode of operation (mapMethod planarInterpolation) is to project
|
||||
the points onto a plane (constructed from the first threee points) and
|
||||
construct a 2D triangulation and finds for the face centres the triangle it
|
||||
is in and the weights to the 3 vertices.
|
||||
|
||||
The optional mapMethod nearest will avoid all projection and triangulation
|
||||
and just use the value at the nearest vertex.
|
||||
|
||||
Values are interpolated linearly between times.
|
||||
|
||||
Usage
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
setAverage | flag to activate setting of average value | yes |
|
||||
perturb | perturb points for regular geometries | no | 1e-5
|
||||
fieldTableName | alternative field name to sample | no| this field name
|
||||
mapMethod | type of mapping | no | planarInterpolation
|
||||
offset | for applying offset to mapped values | no | constant 0.0
|
||||
Property | Description | Required | Default value
|
||||
setAverage | Switch to activate setting of average value | no | false
|
||||
perturb | Perturb points for regular geometries | no | 1e-5
|
||||
fieldTableName | Alternative field name to sample | no| this field name
|
||||
mapMethod | Type of mapping | no | planarInterpolation
|
||||
offset | Offset to mapped values | no | Zero
|
||||
\endtable
|
||||
|
||||
\verbatim
|
||||
<patchName>
|
||||
{
|
||||
type timeVaryingMappedFixedValue;
|
||||
setAverage false;
|
||||
//perturb 0.0;
|
||||
//fieldTableName samples;
|
||||
//offset constant 0.2;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
@ -102,7 +100,7 @@ class timeVaryingMappedFixedValueFvPatchField
|
||||
word fieldTableName_;
|
||||
|
||||
//- If true adjust the mapped field to maintain average value
|
||||
bool setAverage_;
|
||||
Switch setAverage_;
|
||||
|
||||
//- Fraction of perturbation (fraction of bounding box) to add
|
||||
scalar perturb_;
|
||||
|
||||
@ -25,13 +25,13 @@ License
|
||||
|
||||
#include "timeVaryingMappedFixedValuePointPatchField.H"
|
||||
#include "Time.H"
|
||||
#include "AverageIOField.H"
|
||||
#include "AverageField.H"
|
||||
#include "IFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::
|
||||
timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
Foam::timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
timeVaryingMappedFixedValuePointPatchField
|
||||
(
|
||||
const pointPatch& p,
|
||||
@ -55,41 +55,7 @@ timeVaryingMappedFixedValuePointPatchField
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::
|
||||
timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
timeVaryingMappedFixedValuePointPatchField
|
||||
(
|
||||
const timeVaryingMappedFixedValuePointPatchField<Type>& ptf,
|
||||
const pointPatch& p,
|
||||
const DimensionedField<Type, pointMesh>& iF,
|
||||
const pointPatchFieldMapper& mapper
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
|
||||
fieldTableName_(ptf.fieldTableName_),
|
||||
setAverage_(ptf.setAverage_),
|
||||
perturb_(ptf.perturb_),
|
||||
mapMethod_(ptf.mapMethod_),
|
||||
mapperPtr_(NULL),
|
||||
sampleTimes_(0),
|
||||
startSampleTime_(-1),
|
||||
startSampledValues_(0),
|
||||
startAverage_(Zero),
|
||||
endSampleTime_(-1),
|
||||
endSampledValues_(0),
|
||||
endAverage_(Zero),
|
||||
offset_
|
||||
(
|
||||
ptf.offset_.valid()
|
||||
? ptf.offset_().clone().ptr()
|
||||
: NULL
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::
|
||||
timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
Foam::timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
timeVaryingMappedFixedValuePointPatchField
|
||||
(
|
||||
const pointPatch& p,
|
||||
@ -99,7 +65,7 @@ timeVaryingMappedFixedValuePointPatchField
|
||||
:
|
||||
fixedValuePointPatchField<Type>(p, iF),
|
||||
fieldTableName_(iF.name()),
|
||||
setAverage_(readBool(dict.lookup("setAverage"))),
|
||||
setAverage_(dict.lookupOrDefault("setAverage", false)),
|
||||
perturb_(dict.lookupOrDefault("perturb", 1e-5)),
|
||||
mapMethod_
|
||||
(
|
||||
@ -124,6 +90,19 @@ timeVaryingMappedFixedValuePointPatchField
|
||||
offset_ = Function1<Type>::New("offset", dict);
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
mapMethod_ != "planarInterpolation"
|
||||
&& mapMethod_ != "nearest"
|
||||
)
|
||||
{
|
||||
FatalIOErrorInFunction
|
||||
(
|
||||
dict
|
||||
) << "mapMethod should be one of 'planarInterpolation'"
|
||||
<< ", 'nearest'" << exit(FatalIOError);
|
||||
}
|
||||
|
||||
dict.readIfPresent("fieldTableName", fieldTableName_);
|
||||
|
||||
if (dict.found("value"))
|
||||
@ -145,8 +124,34 @@ timeVaryingMappedFixedValuePointPatchField
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::
|
||||
timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
Foam::timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
timeVaryingMappedFixedValuePointPatchField
|
||||
(
|
||||
const timeVaryingMappedFixedValuePointPatchField<Type>& ptf,
|
||||
const pointPatch& p,
|
||||
const DimensionedField<Type, pointMesh>& iF,
|
||||
const pointPatchFieldMapper& mapper
|
||||
)
|
||||
:
|
||||
fixedValuePointPatchField<Type>(ptf, p, iF, mapper),
|
||||
fieldTableName_(ptf.fieldTableName_),
|
||||
setAverage_(ptf.setAverage_),
|
||||
perturb_(ptf.perturb_),
|
||||
mapMethod_(ptf.mapMethod_),
|
||||
mapperPtr_(NULL),
|
||||
sampleTimes_(0),
|
||||
startSampleTime_(-1),
|
||||
startSampledValues_(0),
|
||||
startAverage_(Zero),
|
||||
endSampleTime_(-1),
|
||||
endSampledValues_(0),
|
||||
endAverage_(Zero),
|
||||
offset_(ptf.offset_, false)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
timeVaryingMappedFixedValuePointPatchField
|
||||
(
|
||||
const timeVaryingMappedFixedValuePointPatchField<Type>& ptf
|
||||
@ -165,18 +170,12 @@ timeVaryingMappedFixedValuePointPatchField
|
||||
endSampleTime_(ptf.endSampleTime_),
|
||||
endSampledValues_(ptf.endSampledValues_),
|
||||
endAverage_(ptf.endAverage_),
|
||||
offset_
|
||||
(
|
||||
ptf.offset_.valid()
|
||||
? ptf.offset_().clone().ptr()
|
||||
: NULL
|
||||
)
|
||||
offset_(ptf.offset_, false)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::
|
||||
timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
Foam::timeVaryingMappedFixedValuePointPatchField<Type>::
|
||||
timeVaryingMappedFixedValuePointPatchField
|
||||
(
|
||||
const timeVaryingMappedFixedValuePointPatchField<Type>& ptf,
|
||||
@ -196,12 +195,7 @@ timeVaryingMappedFixedValuePointPatchField
|
||||
endSampleTime_(ptf.endSampleTime_),
|
||||
endSampledValues_(ptf.endSampledValues_),
|
||||
endAverage_(ptf.endAverage_),
|
||||
offset_
|
||||
(
|
||||
ptf.offset_.valid()
|
||||
? ptf.offset_().clone().ptr()
|
||||
: NULL
|
||||
)
|
||||
offset_(ptf.offset_, false)
|
||||
{}
|
||||
|
||||
|
||||
@ -288,20 +282,17 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::checkTable()
|
||||
meshPts = pointField(points0, this->patch().meshPoints());
|
||||
}
|
||||
|
||||
pointIOField samplePoints
|
||||
// Reread values and interpolate
|
||||
fileName samplePointsFile
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"points",
|
||||
this->db().time().constant(),
|
||||
"boundaryData"/this->patch().name(),
|
||||
this->db(),
|
||||
IOobject::MUST_READ,
|
||||
IOobject::AUTO_WRITE,
|
||||
false
|
||||
)
|
||||
this->db().time().constant()
|
||||
/"boundaryData"
|
||||
/this->patch().name()
|
||||
/"points"
|
||||
);
|
||||
|
||||
pointField samplePoints((IFstream(samplePointsFile)()));
|
||||
|
||||
// tbd: run-time selection
|
||||
bool nearestOnly =
|
||||
(
|
||||
@ -323,7 +314,6 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::checkTable()
|
||||
|
||||
// Read the times for which data is available
|
||||
|
||||
const fileName samplePointsFile = samplePoints.filePath();
|
||||
const fileName samplePointsDir = samplePointsFile.path();
|
||||
sampleTimes_ = Time::findTimes(samplePointsDir);
|
||||
|
||||
@ -396,32 +386,37 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::checkTable()
|
||||
}
|
||||
|
||||
// Reread values and interpolate
|
||||
AverageIOField<Type> vals
|
||||
fileName valsFile
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
fieldTableName_,
|
||||
this->db().time().constant(),
|
||||
"boundaryData"
|
||||
/this->patch().name()
|
||||
/sampleTimes_[startSampleTime_].name(),
|
||||
this->db(),
|
||||
IOobject::MUST_READ,
|
||||
IOobject::AUTO_WRITE,
|
||||
false
|
||||
)
|
||||
this->db().time().constant()
|
||||
/"boundaryData"
|
||||
/this->patch().name()
|
||||
/sampleTimes_[startSampleTime_].name()
|
||||
/fieldTableName_
|
||||
);
|
||||
|
||||
Field<Type> vals;
|
||||
|
||||
if (setAverage_)
|
||||
{
|
||||
AverageField<Type> avals((IFstream(valsFile)()));
|
||||
vals = avals;
|
||||
startAverage_ = 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);
|
||||
}
|
||||
|
||||
startAverage_ = vals.average();
|
||||
startSampledValues_ = mapperPtr_().interpolate(vals);
|
||||
}
|
||||
}
|
||||
@ -449,33 +444,39 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::checkTable()
|
||||
/sampleTimes_[endSampleTime_].name()
|
||||
<< endl;
|
||||
}
|
||||
|
||||
// Reread values and interpolate
|
||||
AverageIOField<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);
|
||||
}
|
||||
}
|
||||
@ -569,7 +570,7 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::updateCoeffs()
|
||||
}
|
||||
}
|
||||
|
||||
// apply offset to mapped values
|
||||
// Apply offset to mapped values
|
||||
if (offset_.valid())
|
||||
{
|
||||
const scalar t = this->db().time().timeOutputValue();
|
||||
@ -594,29 +595,26 @@ void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::write
|
||||
) const
|
||||
{
|
||||
fixedValuePointPatchField<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("fieldTableName") << 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.writeKeyword("mapMethod") << mapMethod_
|
||||
<< token::END_STATEMENT << nl;
|
||||
}
|
||||
os,
|
||||
"fieldTable",
|
||||
this->internalField().name(),
|
||||
fieldTableName_
|
||||
);
|
||||
|
||||
this->writeEntryIfDifferent
|
||||
(
|
||||
os,
|
||||
"mapMethod",
|
||||
word("planarInterpolation"),
|
||||
mapMethod_
|
||||
);
|
||||
|
||||
if (offset_.valid())
|
||||
{
|
||||
|
||||
@ -63,7 +63,7 @@ class timeVaryingMappedFixedValuePointPatchField
|
||||
word fieldTableName_;
|
||||
|
||||
//- If true adjust the mapped field to maintain average value
|
||||
bool setAverage_;
|
||||
Switch setAverage_;
|
||||
|
||||
//- Fraction of perturbation (fraction of bounding box) to add
|
||||
scalar perturb_;
|
||||
|
||||
@ -25,7 +25,8 @@ Class
|
||||
Foam::sampledCuttingPlane
|
||||
|
||||
Description
|
||||
A sampledSurface defined by a plane
|
||||
A sampledSurface defined by a plane using the iso-surface algorithm
|
||||
to 'cut' the mesh.
|
||||
|
||||
SourceFiles
|
||||
sampledCuttingPlane.C
|
||||
|
||||
@ -25,7 +25,8 @@ Class
|
||||
Foam::sampledPlane
|
||||
|
||||
Description
|
||||
A sampledSurface defined by a cuttingPlane. Triangulated by default.
|
||||
A sampledSurface defined by a plane which 'cuts' the mesh using the
|
||||
cuttingPlane alorithm. The plane is triangulated by default.
|
||||
|
||||
Note
|
||||
Does not actually cut until update() called.
|
||||
|
||||
Reference in New Issue
Block a user