CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Check boundary type in solver (http://www.cfd-online.com/Forums/openfoam-programming-development/120833-check-boundary-type-solver.html)

ChrisA July 15, 2013 19:12

Check boundary type in solver
 
I'm attempting to implement a thermal diffusion model in the species equation (mass diffusion due to temperature gradient) but I'm having issues with my boundary conditions. Because the temperature gradient isn't necessarily zero at the wall for some cases mass transports through the wall and leaves the domain. Essentially I'm losing mass through walls when I obviously shouldn't be.

My current solution* has been to set the thermal diffusion coefficient to zero at all boundaries:

Code:

forAll(DT.boundaryField(),patchi)
{
    DT.boundaryField()[patchi] == 0;
}

This proves to be true for my current case, but for other cases this wouldn't be true. Is there any way to check what type a boundary is? So I could do something like:

Code:

forAll(DT.boundaryField(),patchi)
{
check if patchi is a wall
if(patchi is a wall)
{
    DT.boundaryField()[patchi] == 0;
}
}

I've looked around the boundary functions but no luck yet, has anyone else done something similar?

*I should note that I'm assuming this is the issue with my simulations and that my fix is appropriate, the corrected code is running as I type this and I wont know if this is true for a day or so.

fportela July 16, 2013 05:54

Hi Chris,

Not sure is this will work, but I believe you can get the type of the patch as follows:

Code:

const volScalarField::GeometricBoundaryField& pbf = p.boundaryField();
wordList pBoundaryTypes = pbf.types();

Then probably pBoundaryTypes[patchi] will give you the name type of patchi.


Cheers,
Felipe

KlasJ July 16, 2013 10:46

Hi Chris,

I would recommend having a look at for example (in OpenFOAM 2.2): $FOAM_SRC/postProcessing/functionObjects/field/streamLine/streamLine.C You will find the statement:

Code:

...
forAll(patches, patchI)
{
    if (isA<wallPolyPatch>(patches[patchI]))
    {
...

In this case we are looking at the patch itself to see if it is a wall. More examples could be found by searching in terminal using:

Code:

foam; grep "isA<wall" `find -iname *.C`
This way seems simple and fairly easy to read to me, but for sure there are other ways to do it.

Best regards,

Klas

ChrisA July 16, 2013 18:36

Felipe,

Thanks for your reply, it looks like your suggestion is returning the boundary condition type (which could be useful for other things) here's the output of pBoundaryTypes from your code:

Code:

7
(
fixedValue
zeroGradient
fixedValue
zeroGradient
zeroGradient
zeroGradient
empty
)

I'll dig through the boundary functions a bit more and see if theres anything similar but for the type I'm looking for.

Klas,

Thank you for that, it looks like it will do exactly what I need... when I finish updating my code to be 2.2.0 compatible :p (it's not in previous versions). Guess that's yet another reason to get off my butt and update my code.


Edit:

I've done a bit of digging into 2.1.1 and thought I'd share what I found. It looks like the polymesh libraries have a function physicalTypes() contained in polyBoundaryMesh.C which should return the physical definitions (wall, patch etc.) but it looks like this isn't easy to access at the solver level (although to be fair I'm absolutely horrible at figuring out how to properly access things like that, if there's an easy way to get access to these functions I'm all for it). This function appears to only be used in blockMesh, or rather was used in block mesh, it seems to be commented out now.

That said I think I'll stick with what I have and put in the wall check in my 2.2.0 code as thats the code that will be solving all my future cases. Thank you both for your assistance!

KlasJ July 17, 2013 11:42

Hi again,

The functions that I am referring to (isA<>) exists also in earlier versions of the code. You will find this in 2.1.x as well. (I was only referring to 2.2 to give an example.)

Good luck!

// Klas

ChrisA July 17, 2013 18:57

Ah, you're right it seems I just fail at writing grep statments. Anyway, to bring some conclusion to this thread, the problem was solved (and probably can be solved in other ways) by the following:

including "wallFvPatch.H" in the solver

and the thermal diffusion coefficient (DT) was given the proper boundary conditions via:

Code:

forAll(DT.boundaryField(),patchi)
{
    if (isA<wallFvPatch>(mesh.boundary()[patchi]))
    {
        DT.boundaryField()[patchi] == 0;
    }
    else
    {
        DT.boundaryField()[patchi] == DT.boundaryField()[patchi].patchInternalField();
    }
}


ARTem July 22, 2013 04:42

Or, alternatively, you can use

Code:

if(mesh.boundary()[patchi].type() == "wall")
without including "wallFvPatch.H".


All times are GMT -4. The time now is 16:44.