CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   how to implement the unit gradient vector in openfoam (https://www.cfd-online.com/Forums/openfoam/244836-how-implement-unit-gradient-vector-openfoam.html)

Youngxl August 31, 2022 01:21

how to implement the unit gradient vector in openfoam
 
Dear all,
Recently, I have implemented an equation involving the unit gradient vector, which has the following form, I don't know how to implement it, because it involves the case that the denominator is 0. Is there any good way to solve this problem?

Assumed that p is a volScalarField like pressure and I want to calculate the equation n=\frac{grad p}{mag(grad p)}.

Thans for reading my post.
Best wishes,
Young

gyr February 18, 2023 16:06

Did you solve the problem, i am facing the same situation:confused:

snak February 24, 2023 08:48

Hi,

Around line 122 of interfaceProperties.C, a unit gradient vector of alpha1_ field (scalar value of Volume Of Fluid) is calculated. This might help you.

https://www.openfoam.com/documentati...8C_source.html

Code:

    // Cell gradient of alpha
    const volVectorField gradAlpha(fvc::grad(alpha1_, "nHat"));
 
    // Interpolated face-gradient of alpha
    surfaceVectorField gradAlphaf(fvc::interpolate(gradAlpha));
 
    // Face unit interface normal
    surfaceVectorField nHatfv(gradAlphaf/(mag(gradAlphaf) + deltaN_));

Value of deltaN_ is decided in interfaceProperties constructor.

Code:

    deltaN_
    (
        "deltaN",
        1e-8/cbrt(average(alpha1.mesh().V()))
    ),



All times are GMT -4. The time now is 06:09.