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

Calculating Patch Center for Decomposed Case

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 25, 2022, 15:03
Default Calculating Patch Center for Decomposed Case
  #1
Member
 
Kellis
Join Date: Mar 2017
Posts: 38
Rep Power: 9
Kellis is on a distinguished road
Good afternoon,

I am trying to write a piece of code that will track the center of a patch as it moves within the dynamic mesh. The center location is needed for calculations in the solver during runtime. Using the following code, I get the expected results when running the case serially:

Code:
        // Get current patch
        scalar patchNum = mesh.boundaryMesh().findPatchID(fricPatchList[patchi]);
        const polyPatch& currPatch = mesh.boundaryMesh()[patchNum];

        // Initialize center vector and area
        vector patchCenter = Zero;
        scalar patchArea = VSMALL;

        // Create pointers to face surface area and centers (used by both loops)
        const surfaceScalarField& magSf = mesh.magSf();
        const surfaceVectorField& Cf = mesh.Cf();

        // Calculate area-weighted patch center
        forAll(currPatch, facei)
        {
            // Add area-weighted face center and face area to totals
            patchCenter += Cf.boundaryField()[patchNum][facei]*magSf.boundaryField()[patchNum][facei];
            patchArea += magSf.boundaryField()[patchNum][facei];
        }

        // Calculate patch centroid
        patchCenter = patchCenter / patchArea;

        Info << "Center for patch " << fricPatchList[patchi] << " found to be at " << patchCenter << endl;
On my test case, a circle patch with origin at (0 0 0.0015), this accurately calculates the center to within rounding error. However, issues begin after decomposing the case and trying to run it in parallel. The calculated center is immediately wrong, and by adding a counter to the loop I can see that it's only looping over the faces of the patch owned by processor0, with the centroid ending up in the middle of this group of faces.

So, is there a way to access the full patch data while running in parallel? Or, will I have to come up with a workaround, such as keeping the entire patch on one processor? This would be less than ideal, as the patch is directly next to a finely discretized region in my mesh that should be split up into several parts.

Any help would be appreciated. Thanks.

Kellis
Kellis is offline   Reply With Quote

Old   February 15, 2022, 17:50
Default
  #2
Member
 
Kellis
Join Date: Mar 2017
Posts: 38
Rep Power: 9
Kellis is on a distinguished road
Bump. Has anyone been able to overcome this issue before?
Kellis is offline   Reply With Quote

Old   February 16, 2022, 13:02
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Kellis View Post
Bump. Has anyone been able to overcome this issue before?

Lots of places in OpenFOAM have that type of thing.
For example,
Code:
vector patchCentre = Zero;

scalar patchArea = 0;


// Do loops here ...


reduce(patchCentre, sumOp<vector>());
reduce(patchArea, sumOp<area>());


patchCentre /= (patchArea + VSMALL);

Not sure why this doesn't work for you.
olesen is offline   Reply With Quote

Old   February 16, 2022, 14:20
Default
  #4
Member
 
Kellis
Join Date: Mar 2017
Posts: 38
Rep Power: 9
Kellis is on a distinguished road
Olesen,


Thank you for chiming in. I'm not quite clear on the purpose of the "reduce" function. Does it somehow sum the patchCentre calculations for all processors? In that case, would it be placed after the forAll loops in my sample code? I might be missing something obvious, but I would appreciate a bit more help with the implementation.


Thanks,
Kellis
Kellis is offline   Reply With Quote

Old   February 16, 2022, 14:41
Default
  #5
Member
 
Kellis
Join Date: Mar 2017
Posts: 38
Rep Power: 9
Kellis is on a distinguished road
Nevermind, I plugged the code you mentioned into my solver and it seems to be working perfectly now - thank you for pointing me in the right direction. If anyone needs to replicate this in the future, the working patch center calculation looks like this:

Code:
        // Get current patch
        scalar patchNum = mesh.boundaryMesh().findPatchID(fricPatchList[patchi]);
        const polyPatch& currPatch = mesh.boundaryMesh()[patchNum];

        // Initialize center vector and area
        vector patchCenter = Zero;
        scalar patchArea = VSMALL;

        // Create pointers to face surface area and centers (used by both loops)
        const surfaceScalarField& magSf = mesh.magSf();
        const surfaceVectorField& Cf = mesh.Cf();

        // Calculate area-weighted patch center
        forAll(currPatch, facei)
        {
            // Add area-weighted face center and face area to totals
            patchCenter += Cf.boundaryField()[patchNum][facei]*magSf.boundaryField()[patchNum][facei];
            patchArea += magSf.boundaryField()[patchNum][facei];
        }

        reduce(patchCenter, sumOp<vector>());
        reduce(patchArea, sumOp<scalar>());

        // Calculate patch centroid
        patchCenter = patchCenter / patchArea;

         Info << "Center for patch " << fricPatchList[patchi] << " found to be at " << patchCenter << endl;
Thanks again olesen!
Kellis 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
Near wall treatment in k-omega SST Arnoldinho OpenFOAM Running, Solving & CFD 38 March 8, 2017 13:48
Possible Bug in pimpleFoam (or createPatch) (or fluent3DMeshToFoam) cfdonline2mohsen OpenFOAM 3 October 21, 2013 09:28
[Commercial meshers] Fluent msh and cyclic boundary cfdengineering OpenFOAM Meshing & Mesh Conversion 48 January 25, 2013 03:28
chtMultiRegionFoam Tutorial m.nichols19 OpenFOAM 12 September 9, 2010 11:56
Free surface boudary conditions with SOLA-VOF Fan Main CFD Forum 10 September 9, 2006 12:24


All times are GMT -4. The time now is 03:59.