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/)
-   -   multiplication printstack error (https://www.cfd-online.com/Forums/openfoam-programming-development/141285-multiplication-printstack-error.html)

PicklER September 4, 2014 04:33

multiplication printstack error
 
Hello

I declared two volScalarfields in createFields.H, namely:
Code:

volScalarField r
(
    IOobject
    (
        "r",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    mesh,
    dimensionedScalar("0", dimLength, 1.0)
)

and

Code:

volScalarField faceCellDist
    (
        IOobject
        (
            "faceCellDist",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        mesh,
        dimensionedScalar
        ("0", dimLength, 1.0)
    );

Then I determine distance from cell centre to cell face and store it in "faceCellDist". This is to get delta x, y and z by multiply "faceCellDist" by 2. And assign a constant (initial value) to "r":

Code:

const surfaceVectorField& Cf  = mesh.Cf();
const volVectorField& C = mesh.C();
const labelList& own = mesh.owner();
forAll (own, I)
    {
        faceCellDist[I] = Foam::mag(C[own[I]] - Cf[I]);
        faceCellDist[I+1]=faceCellDist[I];
    }

The second line "faceCellDist[I+1]=faceCellDist[I];" is to set the last element, otherwise it stays 0 (zero).

and the initial value for "r":
Code:

r=r*id.value()/2;
where "id.value()" is just a constant from test case.

My printStack (multiply) error comes when I do:
Code:

r*faceCellDist
Any suggestions?
Vrede

marupio September 4, 2014 12:53

printStack is not the error. What is the error? Was it a segmentation fault? (SigSEGV) or a floating point error? (SigFPE) The forAll(own, I) loop will cause a segmentation fault when it reaches the final index (i = faceCellDist.size()-1)... because I+1 will be out of range.

PicklER September 5, 2014 02:01

Good morning David.

Thank you for the quick reply. The error is as follows:

#0 Foam::error::printStack(Foam::Ostream&) at ??:?
#1 Foam::sigSegv::sigHandler(int) at ??:?
#2 in "/lib/x86_64-linux-gnu/libc.so.6"
#3 Foam::multiply(Foam::Field<double>&, Foam::UList<double> const&, Foam::UList<double> const&) at ??:?
#4 void Foam::multiply<Foam::fvPatchField>(Foam::FieldFiel d<Foam::fvPatchField, double>&, Foam::FieldField<Foam::fvPatchField, double> const&, Foam::FieldField<Foam::fvPatchField, double> const&) at ??:?
#5 Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::operator*<Foam::fvPatchField, Foam::volMesh>(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&) at ??:?
#6
at ??:?
#7 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#8
at ??:?
Segmentation fault (core dumped)

Weirdly enough, the forAll loop does not give me an error, since it run successfully through the loop.

Note: When I did this for a "1D" test case (shock tube tutorial of rhoCentralFoam), I did not have this error. Only when I went to "2D" (30 cells in x-dir, 3 in y-dir and 1 cell in z-dir) that this error showed.

Kind regards

marupio September 5, 2014 03:22

Ah, I see. It's a segmentation fault. Opt doesn't always throw an error exactly where the bug is. You could try running in debug mode. And you should fix your forall loop.

sabago December 14, 2015 12:50

Dear all,

what if it's a floating point error?

such as

Code:

#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::sigFpe::sigHandler(int) at ??:?
#2  in "/lib/x86_64-linux-gnu/libc.so.6"
#3  Foam::multiply(Foam::Field<double>&, Foam::UList<double> const&, Foam::UList<double> const&) at ??:?
#4 
 at ??:?
#5  Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::operator*<Foam::fvPatchField, Foam::volMesh>(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > const&) at ??:?
#6 
 at ??:?
#7  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#8 
 at ??:?
Floating point exception (core dumped)

Best,
Sandra

wyldckat December 28, 2015 12:08

Quick answer:
Quote:

Originally Posted by sabago (Post 577564)
what if it's a floating point error?
such as

Correct, it's a signal for Floating Point Error: "sigFpe"
Quote:

Originally Posted by sabago (Post 577564)
Code:

#1  Foam::sigFpe::sigHandler(int) at ??:?

Occurred while multiplying two lists of double values:
Quote:

Originally Posted by sabago (Post 577564)
Code:

#3  Foam::multiply(Foam::Field<double>&, Foam::UList<double> const&, Foam::UList<double> const&) at ??:?

The two lists are actually two volume fields, identified with the type "GeometricField< ... volMesh>":
Quote:

Originally Posted by sabago (Post 577564)
Code:

#5  Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam::operator*<Foam::fvPatchField, Foam::volMesh>(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > const&) at ??:?

In order for this to occur, either one of the values was Not-a-Number (NaN) or Infinite (Inf).

If you have access to the source code for the equation where this product occurs, you can try using old school debugging, as... I've already explained here: http://www.cfd-online.com/Forums/ope...tml#post577363 post #3

sabago December 29, 2015 13:15

Forgot to update that I fixed this.

Issue was that the fields being multiplied were of different sizes so I fixed that.

Best,
Sandra


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