ENH: reference FO - position entry is now optional

This commit is contained in:
Andrew Heather
2018-05-09 12:15:43 +01:00
parent 050628c7b1
commit 16f3eac7d6
3 changed files with 52 additions and 37 deletions

View File

@ -75,6 +75,7 @@ Foam::functionObjects::reference::reference
fieldExpression(name, runTime, dict),
localDict_(dict),
position_(point::zero),
positionIsSet_(false),
celli_(-1),
interpolationScheme_("cell"),
scale_(1)
@ -98,13 +99,9 @@ bool Foam::functionObjects::reference::read(const dictionary& dict)
{
localDict_ = dict;
dict.lookup("position") >> position_;
interpolationScheme_ =
dict.lookupOrDefault<word>("interpolationScheme", "cell");
dict.readIfPresent("scale", scale_);
if (dict.readIfPresent("position", position_))
{
positionIsSet_ = true;
celli_ = mesh_.findCell(position_);
@ -117,6 +114,14 @@ bool Foam::functionObjects::reference::read(const dictionary& dict)
<< exit(FatalError);
}
interpolationScheme_ =
dict.lookupOrDefault<word>("interpolationScheme", "cell");
}
dict.readIfPresent("scale", scale_);
Log << type() << " " << name() << nl
<< " field: " << fieldName_ << nl
<< " sample position: " << position_ << nl

View File

@ -34,14 +34,14 @@ Description
The field values are calculated using:
\f[
f_c = s(f_{c,t} - f_p + f_{off})
ref_c = s(f_{c}(t) - f_p + f_{off})
\f]
where
\vartable
f_c | field values at cell
ref_c | field values at cell
s | optional scale factor (default = 1)
f_{c,t} | current field values at cell at this time
f_{c}(t) | current field values at cell at this time
f_p | field value at position
f_{off} | offset field value (default = 0)
\endvartable
@ -66,12 +66,11 @@ Usage
\table
Property | Description | Required | Default value
type | Type name: reference | yes |
position | Position to sample | yes |
field | Name of field | yes |
reult | Name of result field | no | reference(<field>)
result | Name of result field | no | reference(<field>)
position | Position to sample | no | <not used>
scale | Scale value | no | 1
offset | Offset value | no | zero
result | Name of result field | no | <function name>
log | Log to standard output | no | yes
\endtable
@ -114,6 +113,9 @@ class reference
//- Sample location
point position_;
//- Flag to indicate that the position is set
bool positionIsSet_;
//- Sample cell
label celli_;

View File

@ -32,22 +32,10 @@ bool Foam::functionObjects::reference::calcType()
const VolFieldType* vfPtr = lookupObjectPtr<VolFieldType>(fieldName_);
if (vfPtr && celli_ != -1)
if (vfPtr)
{
const VolFieldType& vf = *vfPtr;
autoPtr<interpolation<Type>> interpolator
(
interpolation<Type>::New(interpolationScheme_, vf)
);
const dimensioned<Type> value
(
"value",
vf.dimensions(),
interpolator().interpolate(position_, celli_, -1)
);
dimensioned<Type> offset
(
dimensioned<Type>::lookupOrDefault
@ -59,12 +47,32 @@ bool Foam::functionObjects::reference::calcType()
)
);
Log << " sampled value: " << value.value() << endl;
dimensioned<Type> cellValue("value", vf.dimensions(), Zero);
if (positionIsSet_)
{
cellValue.value() = -pTraits<Type>::one*GREAT;
if (celli_ != -1)
{
autoPtr<interpolation<Type>> interpolator
(
interpolation<Type>::New(interpolationScheme_, vf)
);
cellValue.value() =
interpolator().interpolate(position_, celli_, -1);
}
reduce(cellValue.value(), maxOp<Type>());
Log << " sampled value: " << cellValue.value() << endl;
}
return store
(
resultName_,
scale_*(vf - value + offset)
scale_*(vf - cellValue + offset)
);
}