CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   How to write a boundary condition which depends on a seperate patch (http://www.cfd-online.com/Forums/openfoam/77653-how-write-boundary-condition-depends-seperate-patch.html)

nzy102 June 29, 2010 21:15

How to write a boundary condition which depends on a seperate patch
 
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.

herbert June 30, 2010 04:39

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

braennstroem June 30, 2010 10:46

Hi,

groovyBC should be able to do this.

Fabian

nzy102 June 30, 2010 19:57

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

philippose July 1, 2010 08:02

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

gschaider July 1, 2010 13:22

Quote:

Originally Posted by philippose (Post 265264)
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

nzy102 July 6, 2010 18:46

groovyBC bug???
 
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 (http://www.cfd-online.com/Forums/ope...r-restart.html) 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 July 6, 2010 18:50

BTW, I am using OpenFOAM 1.6.

Ning

benk August 5, 2010 11:25

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]
}


braennstroem August 8, 2010 12:55

There is outletMappedUniformInlet in 1.7.x, which could be a good base as well...


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