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/)
-   -   Segmentation Fault error after min-max (https://www.cfd-online.com/Forums/openfoam-programming-development/146154-segmentation-fault-error-after-min-max.html)

bharat.gmail December 19, 2014 07:52

Segmentation Fault error after min-max
 
Hello Dear Foamers,

I have been writing one of my solver and am stucked at one place due to segmentation fault error. Given below are the details about this error.

Code:


boundaryField
{
    adiabatic
    {
        type            zeroGradient;
    }
    heater
    {
        type            zeroGradient;
    }
    inlet
    {
        type            zeroGradient;
    }
    outlet
    {
        type            zeroGradient;
    }
    frontAndBack
    {
        type            empty;
    }
}

DILUPBiCG:  Solving for H, Initial residual = 1, Final residual = 1.75168e-16, No Iterations 1
Enthalpy  Min(H) = -2.5054e+23 Max(H) = 5.6046e+36
#0  Foam::error::printStack(Foam::Ostream&) in "/opt/openfoam230/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1  Foam::sigSegv::sigHandler(int) in "/opt/openfoam230/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#2  in "/lib/x86_64-linux-gnu/libc.so.6"
#3  Foam::relativePermeabilityModels::krBrooksAndCorey::correct() in "/root/OpenFOAM/root-2.3.0/platforms/linux64GccDPOpt/lib/libporousModels.so"
#4 
 in "/root/OpenFOAM/root-2.3.0/platforms/linux64GccDPOpt/bin/impesFoam"
#5  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#6 
 in "/root/OpenFOAM/root-2.3.0/platforms/linux64GccDPOpt/bin/impesFoam"

The location mentioned in above error stack is :
Code:


                forAll(H_,i)
                {

             
                    if( ( H_[i] > -ROL_.value()*(scalar(2)*hvsat_.value() - hlsat_.value()) ) && ( (H_[i] < -ROV_.value()*hvsat_.value()) || (H_[i] == -ROV_.value()*hvsat_.value()) ) )
                    {

                        T_[i] = TSAT_.value();

                        dTdH_[i] = scalar(0.0);
                        Sb_[i] = - ( H_[i] + ROV_.value()*hvsat_.value() )/( ROL_.value()*hlg_.value() + (ROL_.value() - ROV_.value())*hvsat_.value() );
                    }

                }


This piece of code is written inside krBrooksAndCarey.H which contains a derived class called krBrooksAndCarey. This is derived from a base abstract class wherein this H_ is declared as a volScalarField using following:

volScalarField H_

Also the H volscalarField which is a primitive variable for enthalpy equation is declared in createFields.H file as:

volScalarField H
(
IOobject
(
"H",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

I think there is something wrong with H volScalarField. I think there is no connection b/w H_ and H defined separately. I wish them to be representing same field variable. But dont know how to do so.

Can someone help me sortout this problem. I am really stucked.

Bharat

Likun December 19, 2014 08:41

Hi Bharat,

Just an idea, please make sure that all the variables are properly initialized, sometimes that gives a Segmentation Fault error.

Best,
Likun

Tushar@cfd December 20, 2014 00:36

Hi all,

I agree with Likun, check the initialization of the variables. I think your solver is not able to initialize the variable (in your custom BC) which leads to the segmentation fault. I am not expert on custom BC, anyways I think the error could be in this formulation:

Code:

  forAll(H_,i)  {......}
As, a suggestion I would suggest you to try something like this....

Code:

  forAll(H_.BoundaryField(),i)  {......}
Also set the required internalField for the BC in you case directory. Wish you Best Luck

-
Best Regards!

bharat.gmail December 24, 2014 02:31

can the error be due to values out of bound as is printed below ?

Enthalpy Min(H) = -2.5054e+23 Max(H) = 5.6046e+36

Can some one tell me what is the maximum and minimum numerical value supported by openFoam in double or single precision ?

bharat.gmail December 24, 2014 08:30

problem solved....

:-)

Sugajen August 2, 2017 18:13

Hi all,

I have a similar problem. When I initialize a 3D array and run it for n=128, it crashes with Segmentation fault. The exact line where this happens is
Code:

double array[n+2][n+2][n+2];
The code does not throw an error during its compilation. But when running on a case, the error pops up. Also for smaller values of n (64, 32, 16...) it works fine. What could be the problem?

Thanks,
Sugajen

floquation August 7, 2017 03:53

Quote:

Originally Posted by Sugajen (Post 659292)
Hi all,

I have a similar problem. When I initialize a 3D array and run it for n=128, it crashes with Segmentation fault. The exact line where this happens is
Code:

double array[n+2][n+2][n+2];
The code does not throw an error during its compilation. But when running on a case, the error pops up. Also for smaller values of n (64, 32, 16...) it works fine. What could be the problem?

Thanks,
Sugajen

https://stackoverflow.com/questions/...ge-array-sizes

Sugajen August 7, 2017 14:30

Hi all,

I solved my problem using the following way of dynamically allocating a 3D array so that the heap memory is used. If we do a declaration as I had done on my original post, the stack memory will be used which has some memory limitations that could cause segmentation error.
Code:

double ***array = new double**[n+2];
for (int i = 0; i < n+2; i++)
{
    array[i] = new double*[n+2];
    for (int j = 0; j < n+2; j++)
    array[i][j] = new double[n+2];
}

Also, if we use heap memory, we need to explicitly release the memory later, as shown below.
Code:

for(int i = 0; i < n+2; ++i)
{
    for(int j = 0; j < n+2; ++j)
    {
        delete[] array[i][j];
    }
    delete[] array[i];
}

best,
Sugajen

PVERMA September 18, 2017 07:37

sigsegv error
 
Quote:

Originally Posted by bharat.gmail (Post 525151)
problem solved....

:-)

how was the error solved.Iam having the same type of error.


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