Commit 16f3eac7 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: reference FO - position entry is now optional

parent 050628c7
......@@ -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,24 +99,28 @@ bool Foam::functionObjects::reference::read(const dictionary& dict)
{
localDict_ = dict;
dict.lookup("position") >> position_;
if (dict.readIfPresent("position", position_))
{
positionIsSet_ = true;
interpolationScheme_ =
dict.lookupOrDefault<word>("interpolationScheme", "cell");
celli_ = mesh_.findCell(position_);
label celli = returnReduce(celli_, maxOp<label>());
dict.readIfPresent("scale", scale_);
if (celli == -1)
{
FatalErrorInFunction
<< "Sample cell could not be found at position " << position_
<< exit(FatalError);
}
celli_ = mesh_.findCell(position_);
interpolationScheme_ =
dict.lookupOrDefault<word>("interpolationScheme", "cell");
}
label celli = returnReduce(celli_, maxOp<label>());
if (celli == -1)
{
FatalErrorInFunction
<< "Sample cell could not be found at position " << position_
<< exit(FatalError);
}
dict.readIfPresent("scale", scale_);
Log << type() << " " << name() << nl
<< " field: " << fieldName_ << nl
......
......@@ -34,16 +34,16 @@ 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
s | optional scale factor (default = 1)
f_{c,t} | current field values at cell at this time
f_p | field value at position
f_{off} | offset field value (default = 0)
ref_c | field values at cell
s | optional scale factor (default = 1)
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
Usage
......@@ -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_;
......
......@@ -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)
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment