CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Polynomial velocity boundary condition (https://www.cfd-online.com/Forums/openfoam-programming-development/239543-polynomial-velocity-boundary-condition.html)

Erikaaa November 11, 2021 03:45

Polynomial velocity boundary condition
 
Hello FOAMers,

I'm trying to set a polynomial velocity Ux boundary condition in y-z inlet.
Initial values: Ux relationship with Z coordinates into a polynomial.

what should I do to create such polynomial velocity boundary condition. Is there a funtion that can implement it? or I need to program it.

I heard the functionality in swak4Foam can fix it. Has anyone tried that?

I would be grateful if someone could answer me.

Tobermory November 14, 2021 06:31

Swak4Foam is great, and very easy to use. But what version of OpenFOAM are you using - ESI or foundation? Swak4Foam cannot currently be used with v9 of the foundation flavour of OpenFOAM, but you could instead use a codedFixedValue BC.

Erikaaa November 14, 2021 20:19

Quote:

Originally Posted by Tobermory (Post 816499)
Swak4Foam is great, and very easy to use. But what version of OpenFOAM are you using - ESI or foundation? Swak4Foam cannot currently be used with v9 of the foundation flavour of OpenFOAM, but you could instead use a codedFixedValue BC.

I'm using openFOAM v8.

MattiaBressanelli November 15, 2021 05:57

The video linked below explains how to set up a codedFixedValue boundary condition for a parabolic inlet velocity profile:
https://www.youtube.com/watch?v=3zcT...el=HyperLyceum


Alternatively, you can use a .csv file as input for a fixedValue boundary condition.
https://www.youtube.com/watch?v=rfNY...nicalModelling

This explains more broadly the use of codedFixedValue:
https://www.youtube.com/watch?v=cvWa...el=HolzmannCFD


If I understand correctly, the following should be the end result (change the equation to the one you want to relate u(z) "field[i]" to z "Cf[i].z()"):

Code:

/*--------------------------------*- C++ -*----------------------------------*\
  =========                |
  \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox
  \\    /  O peration    | Website:  https://openfoam.org
    \\  /    A nd          | Version:  9
    \\/    M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class      volVectorField;
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -1 0 0 0 0];

internalField  uniform (5.0 0 0);

boundaryField
{
    inlet
    {
        type            codedFixedValue;
        value          $internalField;
        name            customVelocityInlet;
       
        code
        #{ 
            // input values
            scalar U_ave = 5.0; // [m/s]
            scalar h_ref = 0.001; // [m]

            // get the patch
            const fvPatch& boundaryPatch = this->patch();

            // get face centers "Cf"
            const vectorField& Cf = boundaryPatch.Cf();
            vectorField& field = *this;

            forAll(boundaryPatch, i)
            {
                // u(z) = 1.5 * U_ave * (1 - (z/h_ref)^2)           
                field[i] =  vector(1.5 * U_ave * ( 1 - Foam::pow( Cf[i].z() / h_ref, 2 ) ), 0, 0);
            }

            // operator==();
        #};

        codeInclude
        #{
            #include "fvCFD.H"
            #include <cmath>
            #include <iostream>
        #};

        codeOptions
        #{
            -I$(LIB_SRC)/finiteVolume/lnInclude \
            -I$(LIB_SRC)/meshTools/lnInclude
        #};
    }

    outlet
    {
        type            pressureInletOutletVelocity;
        value          uniform (0 0 0);
    }

    ground
    {
        type            noSlip;
    }

    #includeEtc "caseDicts/setConstraintTypes"
}

// ************************************************************************* //



All times are GMT -4. The time now is 15:52.