|
[Sponsors] |
January 25, 2022, 15:03 |
Calculating Patch Center for Decomposed Case
|
#1 |
Member
Kellis
Join Date: Mar 2017
Posts: 38
Rep Power: 9 |
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; 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 |
|
February 15, 2022, 17:50 |
|
#2 |
Member
Kellis
Join Date: Mar 2017
Posts: 38
Rep Power: 9 |
Bump. Has anyone been able to overcome this issue before?
|
|
February 16, 2022, 13:02 |
|
#3 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,706
Rep Power: 40 |
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. |
|
February 16, 2022, 14:20 |
|
#4 |
Member
Kellis
Join Date: Mar 2017
Posts: 38
Rep Power: 9 |
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 |
|
February 16, 2022, 14:41 |
|
#5 |
Member
Kellis
Join Date: Mar 2017
Posts: 38
Rep Power: 9 |
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; |
|
|
|
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 |