|
[Sponsors] |
Accessing all cells that are next to a wall |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 9, 2010, 08:52 |
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 |
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? |
|
April 11, 2010, 12:44 |
|
#2 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
Then loop over those faces - the face owner() is the cell ID that you are looking for. |
||
April 11, 2010, 13:18 |
|
#3 |
Senior Member
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25 |
Alternatively, you can specify:
mesh.boundaryMesh()[patchI].faceCells(); to obtain a list of cells adjacent to patchI. |
|
April 11, 2010, 14:03 |
|
#4 |
Senior Member
|
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 } } } Hope that helps best,
__________________
Holger Marschall web: http://www.holger-marschall.info mail: holgermarschall@yahoo.de |
|
April 12, 2010, 06:44 |
Thanks!
|
#5 |
Member
Florian Ettner
Join Date: Mar 2009
Location: Munich, Germany
Posts: 41
Rep Power: 17 |
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; } } } 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; Last edited by dohnie; April 12, 2010 at 07:54. |
|
April 12, 2010, 08:42 |
|
#6 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
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()); 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); 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); |
|
April 12, 2010, 12:38 |
|
#7 |
Senior Member
|
why kibitzing...? These are nice adds. Thanks a lot, Mark.
best,
__________________
Holger Marschall web: http://www.holger-marschall.info mail: holgermarschall@yahoo.de |
|
April 13, 2010, 09:21 |
|
#8 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
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 Code:
const scalar omegaWallValue = SMALL; setWallCells(omegaC, omegaWallValue); // should work with other volFields too: setWallCells(U, vector::zero); |
||
May 19, 2010, 14:19 |
|
#9 |
Member
Niklas Winkler
Join Date: Mar 2009
Location: Stockholm, Stockholm, Sweden
Posts: 73
Rep Power: 17 |
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 |
|
May 19, 2010, 17:46 |
|
#10 | |
Senior Member
|
Quote:
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); Code:
IOdictionary arbitraryNameDict ( IOobject ( "arbitraryNameDict", runTime.constant(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ) ); wordList wallPatchNames ( arbitraryNameDict.lookup("wallPatches") ); Hope that helps. best regards,
__________________
Holger Marschall web: http://www.holger-marschall.info mail: holgermarschall@yahoo.de |
||
May 24, 2010, 10:14 |
|
#11 |
Member
Niklas Winkler
Join Date: Mar 2009
Location: Stockholm, Stockholm, Sweden
Posts: 73
Rep Power: 17 |
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 |
|
June 14, 2010, 13:38 |
|
#12 |
Senior Member
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18 |
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 |
|
|
|
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 |