CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Programming phase dependant velocity boundary condition

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 21, 2014, 10:10
Default Programming phase dependant velocity boundary condition
  #1
New Member
 
Peter
Join Date: Apr 2014
Posts: 21
Rep Power: 12
John Degenkolb is on a distinguished road
Hi foamers,

I am running a filling simulation of a porous medium using the porousInterFoam solver.
My 2D-rectangular computational domain is filled initially with air. Starting from an inlet, it is filled up with a liquid.
I like to have a routine that switches the U boundary condition of one of the walls from "fixed value = 0" to "zeroGradient", depending on the phase that it is in contact with.

I want to simulate a special kind of infusion of resin into fibres.
The special thing is that one side of the mould is covered with a membrane, which is so densely woven that air can pass though but not the resin.

I think I can model this behavior by switch the velocity BC from impermeable wall (fixed value =0) to outlet (zeroGradient) while the vacuum pressure which drives the flow stays constant for both conditions.

So far I tried a codedFixedValue boundary condition. (Accidentally I did it in the p_rgh file, but it sould be similar in the U file) The problem is that I wasn't able to implement a zeroGradient BC this way.

Now, I'm implementing a #codeStream in the U file.
I want it to access the alpha values on the boundary and do an if look for every cell. If alpha is > 0.5, it sould see the cell as filled and define the BC as fixedValue=0.
But I'm not even able to access the alpha data, not to mention taking influence on the actual boundaries.

Please find attached a sketch of the problem and my input files containing my poor programming essays in the U and p_rgh files.

Thank you very much for your time and effort.
Kind regards,

Peter

My U file:
Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       volVectorField;
    location    "0";
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

internalField   uniform (0 0 0);

boundaryField
{
    leftWall
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }
    rightWall
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }
    lowerWall
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }

    upperWall
    // the following code is derived from the one in the p_rgh file. There it is a codedFixedValue BD, rather than a #codeStream
    #codeStream
     {
        code
        #{
            // save values of alpha.matrix to scalar field alpha1
            // gives error: ‘volScalarField’ was not declared in this scope
            volScalarField& alpha1 = const_cast<volScalarField&>(db().lookupObject<volScalarField>("alpha.matrix")); 

            // check: prints alphas for Cells specified by the number in []    
            Info << "alpha1: " << alpha1[300] << endl;     
            
            // what's written in the input file for alpha? gives: type  zeroGradient
            fvPatchField& alphasOnBoundary = const_cast<fvPatchField&>(alpha1.boundaryField()[IDupperWall]);  
            Info << "alphasOnBoundary: " << alphasOnBoundary << endl;
            
                forAll(patch(), facei)  // facei: cell faces
                {
                    label celli = patch().faceCells()[facei];  // get global cell indices for cells adjacent to patch
                    if (alpha1[celli] < 0.5)    // if cell is "not" filled with resin
                    {
                        // I want U to be zeroGradient
                        Info << "alpha 1 is LOWER than 0.5" << endl;
                    }
                    else  // if cell is filled with resin
                    {
                        // I want U to be fixedValue; uniform (0 0 0)
                        Info << "alpha 1 is HIGHER than 0.5" << endl;
                    }
                }
        #};
        
        codeInclude
        // try to make volScalarField available. New Error: problem while reading string "#include "volFields.H" ...
        #{
            #include "volFields.H"
        }#;

        codeOptions
        // try to make volScalarField available. Same error as with codeInclude
        #{
            -I$(LIB_SRC)/finiteVolume/lnInclude
        }#

    };

/*
    upperWall  // default values
    {
 ..."

        #{
            #include "volFields.H"
        }#
    };

/*
    upperWall  // default values
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }
*/
    inlet
    {
       type            pressureInletOutletVelocity;
       value           uniform (0 0 0);
    }
    
    outlet
    {
    type        zeroGradient;
    }
    
    defaultFaces
    {
        type            empty;
    }
}
My p_rgh file:
Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      p_rgh;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

internalField   uniform 0;

boundaryField
{
    Porosity
    {
        type            fixedFluxPressure;
        value           uniform 0;
    }
    lowerWall
    {
        type            fixedFluxPressure;
        value           uniform 0;
    }
/*
    upperWall
    {
        type            fixedFluxPressure;
        value           uniform 0;
    }
*/

    upperWall
    {
    type            codedFixedValue;
    value        uniform 0;
    redirectType     ramp;
    code
    // this is only a test on how to access data (alpha.matrix). My aim is to get the code in the U file running and use the same p_rgh BC for upperWall as for outlet
    #{
        // save values of alpha.matrix to scalar field alpha1, that works
        volScalarField& alpha1 = const_cast<volScalarField&>(db().lookupObject<volScalarField>("alpha.matrix")); // works
    
        // to check: print alpha value for Cells specified by the number in []
        Info << "alpha1: " << alpha1[300] << endl;     
    
        // find the patch ID of the BC patch upperWall
        const int IDupperWall = patch().boundaryMesh().findPatchID("upperWall"); 

        // print the patch ID of the boundary patch upperWall
        Info << "IDupperWall: " << IDupperWall << endl;     
/*    
        // see what's written in the initial file output: type zeroGrandient;
        fvPatchField& inputAlpha = alpha1.boundaryField()[IDupperWall];
      
        // print type zeroGrandient; what's written in the initial file
        Info << "inputAlpha: " << inputAlpha << endl;     
    
        // see what's written in the initial file output: type zeroGrandient;
        fvPatchField& alphasOnBoundary = const_cast<fvPatchField&>(alpha1.boundaryField()[IDupperWall]);  
    
        // print type zeroGrandient; what's written in the initial file
        Info << "alphasOnBoundary: " << alphasOnBoundary << endl;     
*/

        forAll(patch(), facei)  // facei: cell faces
        {
            // get global cell indices for cells adjacent to patch
            label celli = patch().faceCells()[facei];  

        //     Info << "cell labels: " << celli << endl;
        //    Info << "facei: " << facei << endl;
            Info << "alpha values on upperWall: " << alpha1[celli] << endl;

            if (alpha1[celli] < 0.5)    // if cell is "not" filled
            {
                Info << "alpha in cell IS 0 " << endl;
                // I want U to be zeroGradient
            }
            else
            {
                Info << "alpha in cell is NOT 0 " << endl;
                // I want U to be fixedValue; uniform (0 0 0)
            }
        }
    #}; 
}; 

   inlet
    {
    type        fixedValue;    // from Hanniel
    value        uniform 3.5e4;
  
    }

   outlet
    {
    type        fixedValue;    // from Hanniel
    value        uniform 0;    // from Hanniel

    }

    defaultFaces
    {
        type            empty;
    }
}
Attached Files
File Type: pdf problem setup.pdf (65.8 KB, 26 views)
File Type: gz Forum_BC_progamming.tar.gz (5.8 KB, 10 views)
John Degenkolb is offline   Reply With Quote

Old   May 22, 2014, 10:14
Default Suggestion from a newbie
  #2
bou
New Member
 
bou
Join Date: May 2014
Posts: 10
Rep Power: 12
bou is on a distinguished road
Hello,

I am a newbie but in case this can help you...

I am using groovyBc for time/field/space dependent Bc and it works fine. Is groovyBc not applicable for your case? (http://openfoamwiki.net/index.php/Contrib/swak4Foam)


Regards,

Bou
bou is offline   Reply With Quote

Old   May 22, 2014, 10:46
Default
  #3
New Member
 
Peter
Join Date: Apr 2014
Posts: 21
Rep Power: 12
John Degenkolb is on a distinguished road
Hi Bou,

thank you for your reply.

I don't know about the capabilities of groovyBCs. Is it capable to switch from one type of BC to another? Or is it just able to adapt the values of one type, like for example fixedValue?

However, they way I tried it is probably completely wrong. At the moment I’m trying to create a user defined boundary.

Kind Regards,
Peter
John Degenkolb is offline   Reply With Quote

Old   May 22, 2014, 12:18
Default groovyBc
  #4
bou
New Member
 
bou
Join Date: May 2014
Posts: 10
Rep Power: 12
bou is on a distinguished road
Absolutly,

Check this link (note groovyBc is a part of swak4foam); http://openfoamwiki.net/index.php/Contrib_groovyBC

You have a lot of examples. As you can see you can switch between
valueExpression and gradientExpression using fractionExpression.

Bou
bou is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with assigned inlet velocity profile as a boundary condition Ozgur_ FLUENT 5 August 25, 2015 05:58
Boundary condition programming Andrea_Fen STAR-CCM+ 1 July 9, 2013 09:49
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 07:28
inlet velocity boundary condition murali CFX 5 August 3, 2012 09:56
Boundary condition for each phase dungsidietquy FLUENT 0 November 5, 2009 09:44


All times are GMT -4. The time now is 07:02.