CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Flux calculation in electrostaticFoam (https://www.cfd-online.com/Forums/openfoam-solving/226045-flux-calculation-electrostaticfoam.html)

syavash April 15, 2020 18:06

Flux calculation in electrostaticFoam
 
Dear Foamers,

I see that in electrostaticFoam solver, flux has been calculated as follows:

Code:

rhoFlux = -k*mesh.magSf()*fvc::snGrad(phi);
where k in some scalar and phi is the electric potential:

Code:

        solve
        (
            fvm::laplacian(phi) + rho/epsilon0
        );

Accordingly, the electric field vector can be obtained in the following way:

Code:

volVectorField E = -fvc::grad(phi)
Now, my question: is it correct to calculate the flux using the following relation:


Code:

rhoFlux = fvc::interpolate(-k*E) & mesh.Sf();
The line above is consistent with the flux calculation in pimpleFoam for instance, but I get divergence when I apply it in my code instead of the first expression. Is there a significant difference between these two methods?

I appreciate any help :)

Kind regards,
syavash

Rango June 28, 2020 20:50

Hi,

The resaon for solver crash using your approach is that there is a small sign typo in your flux equation. The correct form of the equation would be:
Code:

rhoFlux = fvc::interpolate(k*E) & mesh.Sf();
Even though these two approaches may seem the same, they may lead to different results on numerical level. In your proposed approach, you introduce an extra source of error due to (unnecessary) interpolation of a field (here E), while in the original approach the gradient is computed directly on mesh faces using "surface-normal gradient" operator, "snGrad".

In this case you may get away with the introduced gradient error, but in general it can result in non-physical "checkerboard" effects.

Cheers


All times are GMT -4. The time now is 07:21.