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

Number of particles inside Cell

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 5, 2022, 14:47
Default Number of particles inside Cell
  #1
Member
 
Jairo A. Gutiérrez S
Join Date: Nov 2014
Posts: 57
Rep Power: 11
jairoandres is on a distinguished road
Dear all

I am working on a solution for OpenFOAM issue #2289 (https://develop.openfoam.com/Develop.../-/issues/2289), which affects both versions of OpenFOAM. The bug occurs when a particle-containing cell of level > 1, belonging to a wall boundary is unrefined.

One approach would be protecting the boundary-cells from unrefinement, which is discussed here: dynamicRefineFvMesh - Protect cells from refinement (boundary). However, this approach is not convenient as it blocks refinement in wall cells, which very often need to be refined.

The other option would be protecting from refinement cell containing particles. My idea is modifying the dynamicRefineFvMesh file, including something like:

forAll(cells(), celli)
{
const cell& nParcels = cells()[celli];
if (nParcels.parcelNumberinCell > 0)
{
protectedCell_.set(celli);
}

I am aware that there is no such thing as "parcelNumberinCell". What would be the best approach?

I am aware that p.cell() would return the cell number containing the parcel, but then it would require a loop through all parcels. This would be the same for cellOccupancy, right?

Any ideas?

Best regard

J.A. Gutiérrez
jairoandres is offline   Reply With Quote

Old   February 16, 2022, 04:42
Default
  #2
Senior Member
 
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 112
Rep Power: 5
joshwilliams is on a distinguished road
Quote:
Originally Posted by jairoandres View Post
I am aware that p.cell() would return the cell number containing the parcel, but then it would require a loop through all parcels. This would be the same for cellOccupancy, right?

Hi,
Your point about cellOccupancy requiring a loop over all particles is incorrect, if I have understood your task correctly. You can simply do `cellOccupancy.size()', thus eliminating the need to loop over all particles. Here is a minimum example based on a time I have done something similar for cells containing no particles:
Code:
const polyMesh& pmesh = this->owner().mesh();
List<DynamicList<typename CloudType::parcelType*>>& cellOccupancy =
    this->owner().cellOccupancy();

// check all cells containing particles
forAll(pmesh.cells(), celli)
{
    if ( cellOccupancy[celli].size() == 0 )
    {
        // do something
    }
    else
    {
        // do something else
    }
}
Best,
Josh
joshwilliams is offline   Reply With Quote

Old   February 21, 2022, 08:48
Default
  #3
Member
 
Jairo A. Gutiérrez S
Join Date: Nov 2014
Posts: 57
Rep Power: 11
jairoandres is on a distinguished road
Thank you Josh.. I am going to test it this week and I will let you know what happens.

Jairo.
jairoandres is offline   Reply With Quote

Old   March 8, 2022, 09:59
Default
  #4
Senior Member
 
Josh Williams
Join Date: Feb 2021
Location: Scotland
Posts: 112
Rep Power: 5
joshwilliams is on a distinguished road
Any luck, Jairo?
joshwilliams is offline   Reply With Quote

Old   March 18, 2022, 17:14
Default
  #5
Member
 
Jairo A. Gutiérrez S
Join Date: Nov 2014
Posts: 57
Rep Power: 11
jairoandres is on a distinguished road
Hi Josh, no I have not had any luck yet. I think my OpenFOAM C++ skills are lacking for this task, please correct me if I am wrong.

I suppose the modification must be included in the dynamicRefineFvMesh, as the protected cells (particle-containing) must be evaluated each time the mesh refinement / unrefinement is going to occur. I added something like this:

Code:
const polyMesh& pmesh = this->owner().mesh();
List<DynamicList<typename CloudType::parcelType*>>& cellOccupancy = this->owner().cellOccupancy();
forAll(pmesh.cells(), celli)
{
    if ( cellOccupancy[celli].size() > 0 )
    {
       protectedCell_.set(celli);
    }
    
}
However, as far as I understand, the List<DynamicList<typename CloudType returns a list for each parcel and I don't think it can be called from dynamicRefineFvMesh. The compiling error is the following:

Code:
dynamicRefineFvMesh/dynamicRefineFvMesh.C: In member function ‘virtual bool Foam::dynamicRefineFvMesh::init(bool)’:
dynamicRefineFvMesh/dynamicRefineFvMesh.C:1174:46: error: ‘const labelUList {aka const class Foam::UList<int>}’ has no member named ‘mesh’; did you mean ‘test’?
        const polyMesh& pmesh = this->owner().mesh();
                                              ^~~~
                                              test
dynamicRefineFvMesh/dynamicRefineFvMesh.C:1175:49: error: template argument 1 is invalid
 List<DynamicList<typename CloudType::parcelType*>>& cellOccupancy =
                                                 ^~
dynamicRefineFvMesh/dynamicRefineFvMesh.C:1175:53: error: ‘cellOccupancy’ was not declared in this scope
 List<DynamicList<typename CloudType::parcelType*>>& cellOccupancy =
                                                     ^~~~~~~~~~~~~
dynamicRefineFvMesh/dynamicRefineFvMesh.C:1176:19: error: ‘const labelUList {aka const class Foam::UList<int>}’ has no member named ‘cellOccupancy’
     this->owner().cellOccupancy();
                   ^~~~~~~~~~~~~
dynamicRefineFvMesh/dynamicRefineFvMesh.C:1176:33: error: template argument 1 is invalid
     this->owner().cellOccupancy();
                                 ^

I've have included the intermediate library to "#include "kinematicCloud.H", where cellOccupancy is defined, but that specific error still persists.

Any help is completely welcomed
jairoandres is offline   Reply With Quote

Old   March 19, 2022, 08:51
Default
  #6
Member
 
Rishikesh
Join Date: Apr 2016
Posts: 63
Rep Power: 9
mrishi is on a distinguished road
It appears you are using 'this' from within the dynamicFvMesh file, but trying to access cloud members? Using 'this' will only work from within the cloud functions.
Are you able to access the mesh using something like
Code:
const polyMesh& mesh = cloud.pMesh();
mrishi is offline   Reply With Quote

Old   March 19, 2022, 18:10
Default
  #7
Member
 
Jairo A. Gutiérrez S
Join Date: Nov 2014
Posts: 57
Rep Power: 11
jairoandres is on a distinguished road
Quote:
Originally Posted by mrishi View Post
It appears you are using 'this' from within the dynamicFvMesh file, but trying to access cloud members? Using 'this' will only work from within the cloud functions.
Are you able to access the mesh using something like
Code:
const polyMesh& mesh = cloud.pMesh();
Thank you mrishi, cloud was not declared but I added #include "cloud.H" at the start and the error stopped appearing. Still, pMesh, cellOccupancy are still undefined. What is weird to me(or beyond my knowledge) is that pMesh is supposed to be defined in cloud.H.

Code:
 dynamicRefineFvMesh/dynamicRefineFvMesh.C:1176:36: error: expected primary-expression before ‘.’ token
        const polyMesh& mesh = cloud.pMesh();
                                    ^
dynamicRefineFvMesh/dynamicRefineFvMesh.C:1178:49: error: template argument 1 is invalid
 List<DynamicList<typename CloudType::parcelType*>>& cellOccupancy = cloud.pMesh().cellOccupancy();
                                                 ^~
dynamicRefineFvMesh/dynamicRefineFvMesh.C:1178:53: error: ‘cellOccupancy’ was not declared in this scope
 List<DynamicList<typename CloudType::parcelType*>>& cellOccupancy = cloud.pMesh().cellOccupancy();
                                                     ^~~~~~~~~~~~~
dynamicRefineFvMesh/dynamicRefineFvMesh.C:1178:97: error: template argument 1 is invalid
 pename CloudType::parcelType*>>& cellOccupancy = cloud.pMesh().cellOccupancy();

dynamicRefineFvMesh/dynamicRefineFvMesh.C:1181:8: error: ‘pMesh’ was not declared in this scope
 forAll(pMesh.cells(), celli)
I have attached the dynamicRefineFvMesh file I am using (OF-2012) if you wish to take a look into it. Thanks!. Solving this issue should (in theory) fix a serious bug of openfoam when using AMR with particles.

Here is the attached file:
dynamicRefineFvMesh.C
All the modifications are commented as: // JAG
jairoandres 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
UDF in case with DPM modle POSTHU Fluent UDF and Scheme Programming 0 March 3, 2021 07:21
[mesh manipulation] Importing Multiple Meshes thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 18 December 19, 2015 18:57
[OpenFOAM.org] OF2.3.1 + OS13.2 - Trying to use the dummy Pstream library aylalisa OpenFOAM Installation 23 June 15, 2015 14:49
DecomposePar unequal number of shared faces maka OpenFOAM Pre-Processing 6 August 12, 2010 09:01
Unaligned accesses on IA64 andre OpenFOAM 5 June 23, 2008 10:37


All times are GMT -4. The time now is 22:29.