mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: reference FO - position entry is now optional
This commit is contained in:
@ -75,6 +75,7 @@ Foam::functionObjects::reference::reference
|
|||||||
fieldExpression(name, runTime, dict),
|
fieldExpression(name, runTime, dict),
|
||||||
localDict_(dict),
|
localDict_(dict),
|
||||||
position_(point::zero),
|
position_(point::zero),
|
||||||
|
positionIsSet_(false),
|
||||||
celli_(-1),
|
celli_(-1),
|
||||||
interpolationScheme_("cell"),
|
interpolationScheme_("cell"),
|
||||||
scale_(1)
|
scale_(1)
|
||||||
@ -98,24 +99,28 @@ bool Foam::functionObjects::reference::read(const dictionary& dict)
|
|||||||
{
|
{
|
||||||
localDict_ = dict;
|
localDict_ = dict;
|
||||||
|
|
||||||
dict.lookup("position") >> position_;
|
if (dict.readIfPresent("position", position_))
|
||||||
|
{
|
||||||
|
positionIsSet_ = true;
|
||||||
|
|
||||||
interpolationScheme_ =
|
celli_ = mesh_.findCell(position_);
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
interpolationScheme_ =
|
||||||
|
dict.lookupOrDefault<word>("interpolationScheme", "cell");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
dict.readIfPresent("scale", scale_);
|
dict.readIfPresent("scale", scale_);
|
||||||
|
|
||||||
celli_ = mesh_.findCell(position_);
|
|
||||||
|
|
||||||
label celli = returnReduce(celli_, maxOp<label>());
|
|
||||||
|
|
||||||
if (celli == -1)
|
|
||||||
{
|
|
||||||
FatalErrorInFunction
|
|
||||||
<< "Sample cell could not be found at position " << position_
|
|
||||||
<< exit(FatalError);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log << type() << " " << name() << nl
|
Log << type() << " " << name() << nl
|
||||||
<< " field: " << fieldName_ << nl
|
<< " field: " << fieldName_ << nl
|
||||||
|
|||||||
@ -34,16 +34,16 @@ Description
|
|||||||
The field values are calculated using:
|
The field values are calculated using:
|
||||||
|
|
||||||
\f[
|
\f[
|
||||||
f_c = s(f_{c,t} - f_p + f_{off})
|
ref_c = s(f_{c}(t) - f_p + f_{off})
|
||||||
\f]
|
\f]
|
||||||
|
|
||||||
where
|
where
|
||||||
\vartable
|
\vartable
|
||||||
f_c | field values at cell
|
ref_c | field values at cell
|
||||||
s | optional scale factor (default = 1)
|
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_p | field value at position
|
||||||
f_{off} | offset field value (default = 0)
|
f_{off} | offset field value (default = 0)
|
||||||
\endvartable
|
\endvartable
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
@ -66,12 +66,11 @@ Usage
|
|||||||
\table
|
\table
|
||||||
Property | Description | Required | Default value
|
Property | Description | Required | Default value
|
||||||
type | Type name: reference | yes |
|
type | Type name: reference | yes |
|
||||||
position | Position to sample | yes |
|
|
||||||
field | Name of field | 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
|
scale | Scale value | no | 1
|
||||||
offset | Offset value | no | zero
|
offset | Offset value | no | zero
|
||||||
result | Name of result field | no | <function name>
|
|
||||||
log | Log to standard output | no | yes
|
log | Log to standard output | no | yes
|
||||||
\endtable
|
\endtable
|
||||||
|
|
||||||
@ -114,6 +113,9 @@ class reference
|
|||||||
//- Sample location
|
//- Sample location
|
||||||
point position_;
|
point position_;
|
||||||
|
|
||||||
|
//- Flag to indicate that the position is set
|
||||||
|
bool positionIsSet_;
|
||||||
|
|
||||||
//- Sample cell
|
//- Sample cell
|
||||||
label celli_;
|
label celli_;
|
||||||
|
|
||||||
|
|||||||
@ -32,22 +32,10 @@ bool Foam::functionObjects::reference::calcType()
|
|||||||
|
|
||||||
const VolFieldType* vfPtr = lookupObjectPtr<VolFieldType>(fieldName_);
|
const VolFieldType* vfPtr = lookupObjectPtr<VolFieldType>(fieldName_);
|
||||||
|
|
||||||
if (vfPtr && celli_ != -1)
|
if (vfPtr)
|
||||||
{
|
{
|
||||||
const VolFieldType& vf = *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> offset
|
||||||
(
|
(
|
||||||
dimensioned<Type>::lookupOrDefault
|
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
|
return store
|
||||||
(
|
(
|
||||||
resultName_,
|
resultName_,
|
||||||
scale_*(vf - value + offset)
|
scale_*(vf - cellValue + offset)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user