CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Field Laplacian smoothing (https://www.cfd-online.com/Forums/openfoam-programming-development/251878-field-laplacian-smoothing.html)

nikovasi September 12, 2023 18:19

Field Laplacian smoothing
 
Hello everyone,


I'm trying to write a Laplacian smoothing function that takes a noisy volScalarField f0 and returns a smoothed field f.

The following simple code snippet works fine in serial execution.

However, it doesn't work as intended in parallel for cells that are adjacent to a processor patch.

This is due to the fact that, when looking for the cells j adjacent to cell i, only the cells that belong to the same processor are found.

Thus there is a clear "discontinuity" across processor boundaries.


Code:

    forAll(mesh.cells(), i)
    {
        f[i] = f0[i];
        forAll(mesh.cellCells()[i],j)
        {
            const label k = mesh.cellCells()[i][j];
            f[i] += f0[k];
        }
        f[i] /= (1.0+mesh.cellCells()[i].size());
    }

Is there a way to perform the implement the above smoothing function in parallel?

Thanks!

LongGe September 12, 2023 19:27

Hello nikovasi

Does "fvc::smooth" not achieve your goal? It may not be "Laplacian smoothing", but it can smooth volScalarField, etc.

see: OpenFOAM-11/src/finiteVolume/finiteVolume/fvc/fvcSmooth/fvcSmooth.H

nikovasi September 13, 2023 05:16

Hello LongGe and thanks for your reply.

I have tried to solve my problem with the "fvc::smooth" function.

However, "fvc::smooth" takes the smallest field value (which is left unchanged) and propagates it through the domain based on the user defined maximum ratio.
This leads to problems when there are large differences between adjacent cells, where "fvc::smooth" propagates the smallest filed value too far.

That's why I came up with the idea of Laplacian smoothing.
So that small field values increase and large field values decrease based on their adjacent field values.

Maybe running my Laplacian smoothing and then fvc::smooth to smooth out any differences across processor boundaries could be a possible solution.

Tobermory September 13, 2023 10:01

Nikos - you could try reverse engineer fvSmooth, and see how it manages to address all of the cells, and not just the processor's set. It might be a deep dive into the coding though ...

nikovasi September 13, 2023 14:29

Hello everyone,

I stumbled across the following post which seems to give some possible solutions for smoothing a field over the whole domain.

https://www.cfd-online.com/Forums/op...urce-term.html

For reference I wrote the following code snippet which seems to work in both serial and parallel.

The smoothingPasses variable is used to determine the degree of smoothing, with higher smoothing passes leading to a more smoothed out field.

Code:

    label smoothingPasses = 5;
    for (label pass=1; pass<=smoothingPasses; pass++)
    {
        f = fvc::average(fvc::interpolate(f0));
        f.correctBoundaryConditions();
        f0 = f;
    }



All times are GMT -4. The time now is 08:30.