Previous: codedFixedValue Up: Creating new boundary condition Next: Test case: longMixerVessel
This is an automatically generated documentation by LaTeX2HTML utility. In case of any issue, please, contact us at info@cfdsupport.com.
uniformFixedValue
- The uniformFixedValue boundary condition extends the fixedValue boundary condition
- It sets the field to the uniform value as a function of time
- It is applicable to all variables types (scalars, vectors, etc.)
- Look inside the source code:
# cat $FOAM_SRC/finiteVolume/fields/fvPatchFields/\
derived/uniformFixedValue/uniformFixedValueFvPatchField.HDescription This boundary condition provides a uniform fixed value condition. Usage \table Property | Description | Required | Default value uniformValue | uniform value | yes | \endtable Example of the boundary condition specification: \verbatim <patchName> { type uniformFixedValue; uniformValue constant 0.2; } \endverbatim Note The uniformValue entry is a Function1 type, able to describe time varying functions. The example above gives the usage for supplying a constant value.
- The uniformValue entry is a Function1 type.
- To implement () we have create new function.
- We need to find the place in OF structure where the Function1 is implemented:
# find $FOAM_SRC -name "Function1" - We can read the path and take a similar function to () using which we implement the new function.
- The function Sine seems to be a good choice.
- First, we start by copying the Sine into our working directory, e.g.,
# mkdir $FOAM_RUN/newFunction1
# cp -r $FOAM_SRC/OpenFOAM/primitives/functions/Function1/Sine $FOAM_RUN/newFunction1 - We have to rename it, e.g., to TrainingExp:
- Rename the directory Sine to TrainingExp
- Rename all files in TrainingExp directory to TrainingExp*
# rename "s/Sine/TrainingExp/g" Sine* - Rename all occurances of Sine to TrainingExp in all TrainingExp.* files # sed -i "s/Sine/TrainingExp/g" TrainingExp*
- Now we have to reimplement the Sine function to our TrainingExp
- We are going to implement a general version of ():
- Lets look inside the file TrainingExp.h:
namespace Foam { namespace Function1Types { /*---------------------------------------------------------------------------*\ Class TrainingExp Declaration \*---------------------------------------------------------------------------*/ template<class Type> class TrainingExp : public Function1<Type> { // Private data //- Start-time for the sin function scalar t0_; //- Scalar amplitude of the sin function autoPtr<Function1<scalar>> amplitude_; //- Frequency of the sin function autoPtr<Function1<scalar>> frequency_; //- Scaling factor of the sin function autoPtr<Function1<Type>> scale_; //- Level to which the sin function is added autoPtr<Function1<Type>> level_; // Private Member Functions //- Read the coefficients from the given dictionary void read(const dictionary& coeffs); //- Disallow default bitwise assignment void operator=(const TrainingExp<Type>&); public: // Runtime type information TypeName("trainingExp"); // Constructors //- Construct from entry name and dictionary TrainingExp ( const word& entryName, const dictionary& dict ); //- Copy constructor TrainingExp(const TrainingExp<Type>& se); //- Destructor virtual ~TrainingExp(); // Member Functions //- Return value for time t virtual inline Type value(const scalar t) const; //- Write in dictionary format virtual void writeData(Ostream& os) const; };
- First lines, which are not listed here, cotains a decription of the implemented function. We leave it to the user to change it by him or herself.
- This is a declaration of the templated class TrainingExp
- Line 126 defines the name which will be used to refer to this particular Function1 type, therefore it has to be renamed to “trainingExp”
- The private data holds the constants of the implemented functions
- We need to define new constant for the new boundary condition we rename it to trainingExp
- Lines 98-111 declare constants for the original Sine function, we are going to modify it in the following way:
- t0_ – is kept
- amplitude_ – is renamed to A_
- frequence_ – is renamed to B_
- scale_ – is deleted
- level_ – is renamed to x0_
- We cen read that A_ and B_ can be Function1 type of scalar, nevertheless we will use it as constants
- x0_ is a Function1 type of general Type, i.e. we will specify it later on as scalar, vector etc.
- In all files TrainingExp* we have to redefine the private members to the new names given above
- We can do it by a series of the following commands:
# sed -i "s/amplitude/A/g" TrainingExp*
# sed -i "s/frequency/B/g" TrainingExp*
# sed -i "s/level/x0/g" TrainingExp* - All entries containing scale_ variable have to be deleted.
- Finally we need to implement formula () in the file TrainingExpI.H:
#include "TrainingExp.H" #include "mathematicalConstants.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Type> inline Type Foam::Function1Types::TrainingExp<Type>::value(const scalar t) const { return (t < t0_) ? x0_->value(t) * ( 1.0 / ( 1.0 + exp(A_->value(t) * t/t0_ + B_->value(t)) ) ) : x0_->value(t);
- To compile this code we need to create the Make directory and provide explicit template class instantiation.
- We can get inspired in the source code:
# cat $FOAM_SRC/OpenFOAM/primitives/functions/Function1/makeFunction1.C - We need to do a similar file which is relevent for the TrainingExp function # cp $FOAM_SRC/OpenFOAM/primitives/functions/Function1/makeFunction1s.C \
$FOAM_RUN/newFunction1 - Therefore, we modify it to the following form:
#include "TrainingExp.H" #include "fieldTypes.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define makeFunction1s(Type) \ makeFunction1Type(TrainingExp, Type); \ namespace Foam { makeFunction1s(scalar); makeFunction1s(vector); }
- The last thing is to set the wmake routines, we have to create the Make directory with the files and options files.
# mkdir $FOAM_RUN/newFunction1/Make - We have to provide the file options – there is no need to explicitely link any header files or libraries
- The file files have to contain the source .C file which is going to be compiled and provide the name of the new library, i.e.,
/* Run-time selectable functions */ makeFunction1s.C LIB = $(FOAM_USER_LIBBIN)/libUserFunction1
- Now is time to compile the code:
# cd $FOAM_RUN/newFunction1
# wmake - When the compilation is done without any error, it is ready for a test.
- We are going to use the cavity case similarly as for codedFixedValue in previous secion.
- We modify the boundary condition at the movingWall patch for velocity as follows
movingWall { type uniformFixedValue; uniformValue { type trainingExp; t0 5; A -10; B 5; x0 (1 0 0); } }
- Additionally, we have to provide the user created library inside the controlDict:
libs ( "libUserFunction1.so" );
- Now we can test the new boundary condition:
# blockMesh
# pisoFoam - We can check the values at the movingWall in paraView or extract the patch values using the command:
# pisoFoam -postProcess -func "patchAverage(U,name=movingWall)" | grep "of U = \|Time ="
% increaseToFixedValue/increaseToFixedValueFvPatchFields.C % % LIB = $(FOAM_USER_LIBBIN)/libuserBCs
% EXE_INC = \ % -I$(LIB_SRC)/finiteVolume/lnInclude % % LIB_LIBS = \ % -lfiniteVolume
% template<class Type> % scalar increaseToFixedValueFvPatchField<Type>::currentScale() const % { % const scalar t = this->db().time().timeOutputValue(); % const scalar t0 = t0_->value(t); % return 1.0/(1.0 + exp(-10*t/t0 + 5)); % }
% timePrecision 6; % % runTimeModifiable yes; % % libs ("libuserBCs.so"); % % // ************************************************************************* //
% % libs ("libuserBCs.dll");
% boundaryField % { % movingWall % { % type increaseToFixedValue; % refValue uniform (1 0 0); % t0 constant 0.5; % value uniform (0 0 0); % }