CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM

How to write a boundary condition which depends on a seperate patch

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   June 29, 2010, 21:15
Default How to write a boundary condition which depends on a seperate patch
  #1
Member
 
Ning Yang
Join Date: Mar 2009
Location: University Park, PA, USA
Posts: 85
Rep Power: 7
nzy102 is on a distinguished road
I am trying to write a new BC (for species A on wall 1) in OpenFOAM which is dependent on the data from a different patch (species B on wall 2), simply expressed as:

A_species_concentration_gradient_at_wall_1 = B_species_concentration_gradient_at_wall_2

Is there any way to obtain B_species concentration at wall 2 while writing a BC for A species on wall 1?

Thank you.
nzy102 is offline   Reply With Quote

Old   June 30, 2010, 04:39
Default
  #2
Senior Member
 
Stefan Herbert
Join Date: Dec 2009
Location: Darmstadt, Germany
Posts: 129
Rep Power: 7
herbert is on a distinguished road
Hi,

did you take a look at the directMappedFixedValue-BC in Foam? There are also data from another patch needed. For getting access to the other field you should be able to use db().lookupObject<volScalarField>("B_species").

Regards,
Stefan
herbert is offline   Reply With Quote

Old   June 30, 2010, 10:46
Default
  #3
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 9
braennstroem is on a distinguished road
Hi,

groovyBC should be able to do this.

Fabian
braennstroem is offline   Reply With Quote

Old   June 30, 2010, 19:57
Default
  #4
Member
 
Ning Yang
Join Date: Mar 2009
Location: University Park, PA, USA
Posts: 85
Rep Power: 7
nzy102 is on a distinguished road
Fabian:

I looked through the groovyBC demo and here is one example I found from average-t-junction:

outlet1
{
type groovyBC;
valueExpression "0.5*(pInlet+pOutlet2)";
variables "pInlet@inlet=sum(p*mag(Sf()))/sum(mag(Sf())); pOutlet2@outlet2=p;";
value uniform 100010;
}
here what does @ work? for example, @outlet2 means p value taken from patch outlet2? I tested it and found it is not the case. Do u have any idea how to get data from a different patch? Thank you.

Ning
nzy102 is offline   Reply With Quote

Old   July 1, 2010, 08:02
Default
  #5
Senior Member
 
Philippose Rajan
Join Date: Mar 2009
Location: Germany
Posts: 522
Rep Power: 15
philippose will become famous soon enough
Hello Ning,

A Good Day to you!!

As Fabian correctly pointed out, the best and easiest solution for you is to use the groovyBC library.

I use it routinely, and it fulfills the requirement of making one patch dependent on another beautifully :-)!

The dictionary that you found in the example is what you are looking for, and it works fine....

Code:
outlet1     
    {
    type            groovyBC;
    valueExpression "0.5*(pInlet+pOutlet2)";
            variables       "pInlet@inlet=sum(p*mag(Sf()))/sum(mag(Sf()));   
    pOutlet2@outlet2=p;";
    value           uniform 100010;
    }
Here, the entry variables basically defines variables which you will then use inside the valueExpression entry when you actually specify the expression you want to calculate.

Now... in the example above, the variables entry can be explained up as:

"Create a variable called pInlet on the patch with the name inlet whose value is calculated as the area weighted average of the pressure (p) on that patch"

This variable pInlet is then later used in the valueExpression entry to actually define how the pressure on the current patch outlet1 depends on the patch inlet and any other patches (In this case, also the pressure on patch outlet2 via the variable pOutlet2)

This method works fine.... an example from me which works looks like this:

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  1.4.1                                 |
|   \\  /    A nd           | Web:      http://www.openfoam.org               |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/

FoamFile
{
    version 2.0;
    format ascii;

    root "/home/cfduser/OpenFOAM/cfduser-1.4.1/run";
    case "";
    instance "0";
    local "";

    class volScalarField;
    object p;
}

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

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

internalField   uniform 2352.9411;  // 20 bar

boundaryField
{
    fixedWalls
    {
        type            zeroGradient;
    }
    inlet
    {
        type            groovyBC;
        variables       "pLS@outletLS=sum(p*mag(Sf()))/sum(mag(Sf()));";
        valueExpression "pLS + (9.5*100000/850)";
        value           uniform 2352.9411;
    }
    outlet
    {
        type            fixedValue;
        value           $internalField;
    }
    outletLS
    {
        type            zeroGradient;
    }
}


// ************************************************************************* //
In the example above, the pressure at the patch "inlet" will always have an offset of 9.5 bar higher than the area weighted average pressure at the patch "outletLS"

Hope this helps!

Have a great day ahead!

Philippose
philippose is offline   Reply With Quote

Old   July 1, 2010, 13:22
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,776
Rep Power: 37
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by philippose View Post
Hello Ning,

A Good Day to you!!

As Fabian correctly pointed out, the best and easiest solution for you is to use the groovyBC library.

--explanation snipped --
Could someone please add this explanation to the Wiki-page of GroovyBC. That way it would be easier to find for future generations

Thanks
Bernhard
gschaider is offline   Reply With Quote

Old   July 6, 2010, 18:46
Default groovyBC bug???
  #7
Member
 
Ning Yang
Join Date: Mar 2009
Location: University Park, PA, USA
Posts: 85
Rep Power: 7
nzy102 is on a distinguished road
Hi Philippose:

I used the groovyBC to apply a constant gradient bc, to test the accuracy of the code.

Here is the bc setup:

working
{
type groovyBC;
value uniform 0;
valueExpression "0";
gradientExpression "100"; //"-Deff1*grad";
fractionExpression "0";
// variables "grad=snGrad(C_peroxide);Deff1=0.3827;";
}

Then I used wallMassFlux (modified from wallHeatFlux utility) to calculate the species gradient on the wall and found that the gradient is a lot higher than 100. The type of error has been reported by elcovv (wallHeatFlux BC not constant after restart) previously. I tried to rename groovyBC as a random name according to elcovv's suggestion but it does not help.

I am 100% sure that my wallMassFlux utility works properly because I tested it using a fixedGradient bc instead. The results has been consistent.

Have u ever met similar problems? Thank you.

Ning
nzy102 is offline   Reply With Quote

Old   July 6, 2010, 18:50
Default
  #8
Member
 
Ning Yang
Join Date: Mar 2009
Location: University Park, PA, USA
Posts: 85
Rep Power: 7
nzy102 is on a distinguished road
BTW, I am using OpenFOAM 1.6.

Ning
nzy102 is offline   Reply With Quote

Old   August 5, 2010, 11:25
Default
  #9
Senior Member
 
Ben K
Join Date: Feb 2010
Location: Ottawa, Canada
Posts: 140
Rep Power: 9
benk is on a distinguished road
If you don't want to use groovyBC, I'm pretty sure something like this would work:

Code:
label wall1 = mesh.boundaryMesh().findPatchID("wall1");
fixedGradientFvPatchScalarField& buffer_speciesA = refCast<fixedGradientFvPatchScalarField>(speciesA.boundaryField()[wall1]);
scalarField& grad_speciesA = buffer_speciesA.gradient();

label wall2 = mesh.boundaryMesh().findPatchID("wall2");
fixedGradientFvPatchScalarField& buffer_speciesB =  refCast<fixedGradientFvPatchScalarField>(speciesB.boundaryField()[wall2]);
scalarField& grad_speciesB = buffer_speciesB.gradient();

forAll(grad_speciesA,i) {
grad_speciesA[i] = grad_speciesB[i]
}
benk is offline   Reply With Quote

Old   August 8, 2010, 12:55
Default
  #10
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 9
braennstroem is on a distinguished road
There is outletMappedUniformInlet in 1.7.x, which could be a good base as well...
braennstroem is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mixed/Robin boundary condition aaev OpenFOAM Bugs 2 December 15, 2011 14:03
CheckMeshbs errors ivanyao OpenFOAM Running, Solving & CFD 2 March 11, 2009 03:34
Airfoil boundary condition Frank Main CFD Forum 1 April 21, 2008 18:36
Slip boundary condition what is inside normunds OpenFOAM Running, Solving & CFD 2 June 4, 2007 06:45
How to write the boundary condition for round free jet Jason Main CFD Forum 8 July 26, 1999 16:15


All times are GMT -4. The time now is 21:42.