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

Accessing all cells that are next to a wall

Register Blogs Community New Posts Updated Threads Search

Like Tree11Likes
  • 1 Post By olesen
  • 1 Post By deepsterblue
  • 1 Post By holger_marschall
  • 1 Post By dohnie
  • 6 Post By olesen
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 9, 2010, 08:52
Default Accessing all cells that are next to a wall
  #1
Member
 
Florian Ettner
Join Date: Mar 2009
Location: Munich, Germany
Posts: 41
Rep Power: 17
dohnie is on a distinguished road
Hi,
I am stuck on a combustion model. I have implemented a source term (a volScalarField). I need to recalculate the source term in every timestep but force it to be zero in all cells that are next to a wall.
Can anybody help me how to get the information which cells are next to a wall?
dohnie is offline   Reply With Quote

Old   April 11, 2010, 12:44
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by dohnie View Post
Hi,
I am stuck on a combustion model. I have implemented a source term (a volScalarField). I need to recalculate the source term in every timestep but force it to be zero in all cells that are next to a wall.
Can anybody help me how to get the information which cells are next to a wall?
Just loop over the boundary patches and select the wall patches.
Then loop over those faces - the face owner() is the cell ID that you are looking for.
Mojtaba.a likes this.
olesen is offline   Reply With Quote

Old   April 11, 2010, 13:18
Default
  #3
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
Alternatively, you can specify:

mesh.boundaryMesh()[patchI].faceCells();

to obtain a list of cells adjacent to patchI.
Mojtaba.a likes this.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   April 11, 2010, 14:03
Default
  #4
Senior Member
 
Holger Marschall
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 126
Rep Power: 19
holger_marschall is on a distinguished road
Send a message via Skype™ to holger_marschall
Hi Florian,

I have implemented this, for switching off some force coefficients near to walls. Simply use (as already described):

Code:
const fvPatchList& patches = mesh.boundary();

    forAll(patches, patchi)
    {
        const fvPatch& curPatch = patches[patchi];
        if (isType<wallFvPatch>(curPatch))
        {
            forAll(curPatch, facei)
            {
                label faceCelli = curPatch.faceCells()[facei];
                //your stuff
            }
        }
    }
If needed you could add a word (or wordList) holding only the patch(es) under consideration and check for the right patch name in the if-statement. This could be accomplished most conveniently via dictionary lookup, in case you want to change the corresoponding patch names in a flexible way.

Hope that helps

best,
randolph likes this.
__________________
Holger Marschall
web: http://www.holger-marschall.info
mail: holgermarschall@yahoo.de
holger_marschall is offline   Reply With Quote

Old   April 12, 2010, 06:44
Default Thanks!
  #5
Member
 
Florian Ettner
Join Date: Mar 2009
Location: Munich, Germany
Posts: 41
Rep Power: 17
dohnie is on a distinguished road
Thanks to all of you, that really helped!

Based on Holger's suggestion I make a list of all cells at the beginning of a run

Code:
const fvPatchList& patches = mesh.boundary();
labelList wallList;
wallList.clear();

    forAll(patches, patchi)
    {
        const fvPatch& curPatch = patches[patchi];
        if (isType<wallFvPatch>(curPatch))
        {
            forAll(curPatch, facei)
            {
                label faceCelli = curPatch.faceCells()[facei];
                wallList.resize(wallList.size()+1);
                wallList[wallList.size()-1]=faceCelli;
            }
        }
    }
(You have to include wallFvPatch.H to make this work)

I'm not much of a C++ crack, but I suppose that the adding of elements to wallList could be done in a nicer way (append() only works for appending lists, not elements to a list).

Then I can refer to this list in every time step to set the source term to zero:

Code:
forAll(wallList,i)  omegaC[wallList[i]] = 0.0;
Mojtaba.a likes this.

Last edited by dohnie; April 12, 2010 at 07:54.
dohnie is offline   Reply With Quote

Old   April 12, 2010, 08:42
Default
  #6
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Just to add a little kibitzing ...
Your approach is OK, but it might be faster and more efficient to use a DynamicList of labels instead. This gives you an append() method and should be faster since it avoids too many small resizing operations.

For example,
Code:
const fvPatchList& patches = mesh.boundary();
DynamicList<label> dynWallList;

forAll(patches, patchI)
{
    const fvPatch& p = patches[patchI];
    if (isType<wallFvPatch>(p))
    {
        forAll(p, pFaceI)
        {
            dynWallList.append(p.faceCells()[pFaceI]);
        }
    }
}

// make invariant labelList, reusing allocated memory
const labelList wallList(dynWallList.xfer());
With either approach, you will get double entries for cells that have two wall faces (which shouldn't be an issue in your case).

Another alternative would be to first note which cells are addressed and then build the label list afterwards.
For example,

Code:
const fvPatchList& patches = mesh.boundary();
PackedBoolList isWallCell(mesh.nCells());

// stage 1: find the cells that are near a wall
forAll(patches, patchI)
{
    const fvPatch& p = patches[patchI];
    if (isType<wallFvPatch>(p))
    {
        forAll(p, pFaceI)
        {
            isWallCell.set(p.faceCells()[pFaceI]);
        }
    }
}

// stage 2: build labelList from list of bools
labelList wallList(isWallCell.count());
label nWallCells = 0;
forAll(isWallCell, celli)
{
    if (isWallCell.get(celli))
    {
        wallList[nWallCells++] = celli;
    }
}

// paranoid
wallList.setSize(nWallCells);
A third way would be similar to the first one, but slightly more efficient again.

Code:
const fvPatchList& patches = mesh.boundary();
 label nWallCells = 0;

// stage 1: get the max number of wall cells (including doubled entries)
forAll(patches, patchI)
{
    const fvPatch& p = patches[patchI];
    if (isType<wallFvPatch>(p))
    {
        nWallCells += p.size();
    }
}

// stage 2: build labelList

labelList wallList(nWallCells);
nWallCells = 0;
 
 forAll(patches, patchI)
 {
    const fvPatch& p = patches[patchI];
    if (isType<wallFvPatch>(p))
    {
        forAll(p, faceI)
        {
            wallList[nWallCells++] = p.faceCells()[faceI];
        }
    }
 }

// safety
wallList.setSize(nWallCells);
You could use similar trick with the xfer() method if you wanted your list to be invariant.
D.R., Mojtaba.a, codder and 3 others like this.
olesen is offline   Reply With Quote

Old   April 12, 2010, 12:38
Default
  #7
Senior Member
 
Holger Marschall
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 126
Rep Power: 19
holger_marschall is on a distinguished road
Send a message via Skype™ to holger_marschall
Quote:
Originally Posted by olesen View Post
Just to add a little kibitzing ...
why kibitzing...? These are nice adds. Thanks a lot, Mark.

best,
__________________
Holger Marschall
web: http://www.holger-marschall.info
mail: holgermarschall@yahoo.de
holger_marschall is offline   Reply With Quote

Old   April 13, 2010, 09:21
Default
  #8
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by holger_marschall View Post
why kibitzing...? These are nice adds. Thanks a lot, Mark.
Actually, for even better efficiency and more flexibility, it is probably better to avoid the faceCells() method and also to avoid storing any extra lists.

Initially it may appear somewhat less convenient to use the face owners directly, but you only need to add in the patch start as an offset.

Here is what I think would be a useful, and more general implementation:

Code:
#ifndef setWallCells_H
#define setWallCells_H

#include "wallFvPatch.H"

template<class Type>
void setWallCells
(
    GeometricField<Type, fvPatchField, volMesh>& field,
    const Type& value
)
{
    // the patches and the face owners
    const fvPatchList& patches = field.mesh().boundary();
    const labelList& own = field.mesh().owner();

    forAll(patches, patchI)
    {
        const fvPatch& p = patches[patchI];

        // only do walls
        if (isType<wallFvPatch>(p))
        {
            const polyPatch& pp = p.patch();
            forAll(pp, patchFaceI)
            {
                field[own[pp.start() + patchFaceI]] = value;
            }
        }
    }
}

#endif
Within the code you could then simply use it like this:
Code:
const scalar omegaWallValue = SMALL;

setWallCells(omegaC, omegaWallValue);

// should work with other volFields too:
setWallCells(U, vector::zero);
Mojtaba.a likes this.
olesen is offline   Reply With Quote

Old   May 19, 2010, 14:19
Default
  #9
Member
 
Niklas Winkler
Join Date: Mar 2009
Location: Stockholm, Stockholm, Sweden
Posts: 73
Rep Power: 17
nikwin is on a distinguished road
Hello,

Holger, you're writing that it's possible to change patch name in a convenient way via dictionary lookup. Could you please give an example since I can't get it? I would need it both for vol<type>fields and for the fvMesh.

Thanks
/NW
nikwin is offline   Reply With Quote

Old   May 19, 2010, 17:46
Default
  #10
Senior Member
 
Holger Marschall
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 126
Rep Power: 19
holger_marschall is on a distinguished road
Send a message via Skype™ to holger_marschall
Quote:
Originally Posted by nikwin View Post
Holger, you're writing that it's possible to change patch name in a convenient way via dictionary lookup. Could you please give an example since I can't get it? I would need it both for vol<type>fields and for the fvMesh.
/NW
Hi Niklas,

no, not to change. I was talking just about reading them in.
This simply might be accomplished by a word or wordlist (for multiple patches) and an dictionary lookup:

For example: Provide this in a dictionary (say in arbitraryNameDict)
Code:
wallPatches (wallName1 wallName2);
and some appropriate lines in createFields.H, for instance:
Code:
IOdictionary arbitraryNameDict
(
    IOobject
    (
        "arbitraryNameDict",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    )
);

wordList wallPatchNames
(
    arbitraryNameDict.lookup("wallPatches")
);
which makes the wallPatches declared in the dictionary file available in your top-level code.

Hope that helps.

best regards,
__________________
Holger Marschall
web: http://www.holger-marschall.info
mail: holgermarschall@yahoo.de
holger_marschall is offline   Reply With Quote

Old   May 24, 2010, 10:14
Default
  #11
Member
 
Niklas Winkler
Join Date: Mar 2009
Location: Stockholm, Stockholm, Sweden
Posts: 73
Rep Power: 17
nikwin is on a distinguished road
Ok, Thanks anyway! I realized however that it's possible via fvMeshSubset to write faces into a user supplied patch which solves my problem.

All the Best
/NW
nikwin is offline   Reply With Quote

Old   June 14, 2010, 13:38
Default
  #12
Senior Member
 
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18
gwierink is on a distinguished road
Dear all,

Neat stuff, thanks for that! I would like to do a routine over only internal cells. Is there a function to retrieve the internal cells only? Thank you in advance!
__________________
Regards, Gijs
gwierink 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 in IMPORT of ICEM input file in FLUENT csvirume FLUENT 2 September 9, 2009 02:08
Deal with wall boundary with moving mesh by FVM? aiya Main CFD Forum 6 May 10, 2007 12:33
Wall functions? Pr Main CFD Forum 7 April 8, 2004 07:15
Quick Question - Wall Function D.Tandra Main CFD Forum 2 March 16, 2004 05:29
Simple Wall Boundary Conditions for Turb. Flow Greg Perkins Main CFD Forum 4 May 29, 2002 00:10


All times are GMT -4. The time now is 00:14.