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/)
-   -   Error arise after alpha smooth modification in interfaceProperties::calculateK (https://www.cfd-online.com/Forums/openfoam-programming-development/141211-error-arise-after-alpha-smooth-modification-interfaceproperties-calculatek.html)

red.yxg September 2, 2014 11:47

Error arise after alpha smooth modification in interfaceProperties::calculateK
 
Dear All:

Now I am using interFoam to simulate 2-phase flow. I smoothed the alpha by some changes in interfaceProperties.c in Foam::interfaceProperties::calculateK() according to Laplacian filter(3.51) in Onno Ubbink's thesis. No error arise in recompilation of interfaceProperties.c and interFoam.c . But when I call interFoam calculating a case, error arised:

Quote:

new cannot satisfy memory request.
This does not necessarily mean you have run out of virtual memory.
It could be due to a stack violation caused by e.g. bad use of pointers or an out of date shared library.
So I just go back to the interfaceProperties.c and change the code line by line to check what caused this problem:

Code:

void Foam::interfaceProperties::calculateK()
{
    const fvMesh& mesh = alpha1_.mesh();
    const surfaceVectorField& Sf = mesh.Sf();
 
 
    const volScalarField& volSmoothAlpha0=alpha1_;  // added by me
    const volScalarField& surfaceSumArea=fvc::surfaceSum(mesh.magSf()); // added by me
 
    const surfaceScalarField& surfaceSmoothAlpha0=Foam::linearInterpolate(volSmoothAlpha0); // added by me

    const surfaceScalarField& surfaceAreatimesAlpha0=surfaceSmoothAlpha0*mesh.magSf();  // added by me

    const volScalarField& surfaceSumAreatimesAlpha0=fvc::surfaceSum(surfaceAreatimesAlpha0); // added by me

    const volScalarField& volSmoothAlpha1=surfaceSumAreatimesAlpha0/surfaceSumArea; // added by me, this one cause the problem. !!!



The last line caused the error. I am new to OpenFoam. Maybe this is a simple question.:confused: So anyone has the hint ? Thanks !:)

Yin

marupio September 3, 2014 04:30

You are misusing references (the ampersand '&').

1. volScalarField theActualObject;
2. volScalarField& referenceToObject = objectToWhichItRefers;

1 is an actual instance of an object that takes up real memory.
2 is a reference to another object stored elsewhere, and notice it *must* be initialized by the object it points to right away.

Only use the '&' if you know the object exists already somewhere else. Hope that helps.

red.yxg September 3, 2014 04:40

Hi, David:

Thank you for your reply. Yeah, you are right. I am just too new to C++ and OpenFOAM:D. I will check whether I can manage it.

Cheers,
Yin

suchi89 March 24, 2015 17:02

Hi,

Have you been able to resolve this?
Also, I am trying to implement the same smoother in alphaEqnSubCycle.C instead of at interfaceProperties.C

Was there a specific reason why the implementation is at interfaceProperties.C and not after calculating alpha at alphaEqnSubCycle.C?\

Thanks,

red.yxg March 25, 2015 08:50

Hi,

Yes, later I found smoothing alpha has little influence on my result. So I just quit.
We only need the smoothed alpha for surface tension calculation, so I directly modify in interfaceproperties.C, I think this is more convenient. But I am not sure.

Yin

mheinz March 7, 2016 11:46

Quote:

Originally Posted by red.yxg (Post 538146)
Hi,

Yes, later I found smoothing alpha has little influence on my result. So I just quit.
We only need the smoothed alpha for surface tension calculation, so I directly modify in interfaceproperties.C, I think this is more convenient. But I am not sure.

Yin

I would add that smoothing the alpha field would likely be counterproductive because in general one wants the interface to be sharp. The calculation of the curvature on the other hand is quite inaccurate for a sharp alpha field.

So it seems convenient to use a smoothed alpha field only for the calculation of interface properties.


All times are GMT -4. The time now is 12:22.