Implement A rampedFixedValue Boundary Condition
Implement A rampedFixedValue Boundary Condition
• You have figured out that there is already a boundary condition that oscillates the value
of a variable at a boundary, so you only need to change the time function of that boundary
condition to get what you want:
$FOAM_SRC/finiteVolume/fields/fvPatchFields/derived/oscillatingFixedValue
• You copy that to create a dynamic library according to what you have learnt in an excel-
lent course...
Field<Type> refValue_
autoPtr<DataEntry<scalar> > amplitude_
autoPtr<DataEntry<scalar> > frequency_
label curTimeIndex_
Field<Type> refValueLow_
Field<Type> refValueHigh_
autoPtr<DataEntry<scalar> > startRamp_
autoPtr<DataEntry<scalar> > endRamp_
label curTimeIndex_
You make a note of which of your new private data are objects of the same class as the
original private data. You realize that the original files have only one private data of
type Field<Type>, while you need two.
The function currentScale() is the ramp fraction at time t, which also needs to be
modified...
• You change the currentScale() function to:
return
min
( 1.0, max (
(this->db().time().value() - a)/
(f - a), 0.0));
• In function updateCoeffs(), you change the evaluation of the patchField to:
patchField = refValueLow_
+ (refValueHigh_ - refValueLow_)*currentScale();
• You clean an compile, and you are done!
A few comments
• The write function should now look like this:
template<class Type>
void rampedFixedValueFvPatchField<Type>::write(Ostream& os) const
{
fixedValueFvPatchField<Type>::write(os);
refValueLow_.writeEntry("refValueLow", os);
refValueHigh_.writeEntry("refValueHigh", os);
os.writeKeyword("offset") << offset_ << token::END_STATEMENT << nl;
startRamp_->writeData(os);
endRamp_->writeData(os);
}
This function makes sure that all the information of the boundary condition is written
in the output time directories. This useful when the simulation is restarted from the
latest time.
A few comments
• The generic rampedFixedValueFvPatchField<Type> class becomes specific for scalar,
vector, tensor, ... by using the command (see the *Fwd* file):
makePatchTypeFieldTypedefs(rampedFixedValue)
• This function is defined in $FOAM_SRC/finiteVolume/fvPatchField.H and it uses
typedef for this purpose:
typedef rampedFixedValueFvPatchField<scalar> rampedFixedValueFvPatchScalarField;
typedef rampedFixedValueFvPatchField<vector> rampedFixedValueFvPatchVectorField;
typedef rampedFixedValueFvPatchField<tensor> rampedFixedValueFvPatchTensorField;
A few comments
• It adds to the runTimeSelectionTable the new boundary conditions created in
rampedFixedValueFvPatchFields.H, by calling the function:
makePatchTypeFieldTypedefs(rampedFixedValue);
• In this way, the new boundary condition can be used for volScalarField, volVectorField,
volTensorField, ... just typing in the field file:
boundaryField
{
inlet
{
type rampedFixedValue;
refValueLow uniform 10; // example for a volScalarField
refValueHigh uniform 20; // example for a volScalarField
startRamp 20;
endRamp 50;
value uniform (0 0 0); //Dummy for paraFoam
}
}
• So, you can now easily use the rampedFixedvalue boundary condition for the cavity
case, with the original icoFoam solver.