CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

error with new+modified interfaceProperties library

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By mkraposhin

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 7, 2016, 10:50
Default error with new+modified interfaceProperties library
  #1
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 16
Andrea_85 is on a distinguished road
Hello,

i am trying to modify the interfaceProperties lib. To do this i created a new library (say "myInterfaceProperties"), which, for the moment, looks exactly as the original one. The only difference is that i am trying to pass more fields to the library. I modified the constructors part in interfaceProperties.C as follow (red parts are new)


Code:
// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
Foam::myInterfaceProperties::myInterfaceProperties
(
    const volScalarField& alpha1,
    const volVectorField& U,
    const volScalarField& DeltaX,
    const volScalarField& DeltaY,
    const IOdictionary& dict
)
:    
    alpha1_(alpha1),
    U_(U),
    dx_(DeltaX),
    dy_(DeltaY),
Then, i added the declaration of the two new variables in interfaceProperties.H

Code:
 
const volScalarField& alpha1_;
const volVectorField& U_;
const volScalarField& dx_;
const volScalarField& dy_;
DeltaX and DeltaX are defined in the main code as volScalarField.
I called the new library in createField.H as

Code:
myInterfaceProperties interface(alpha1, U, DeltaX, DeltaY, twoPhaseProperties);
I have successfully compiled both the new library and the main code but when i try to run the code i get this error just after the library is called

Code:
Create mesh for time = 0


PIMPLE: Operating solver in PISO mode

Reading field p_rgh

Reading field U

Reading/calculating face flux field phi

Reading transportProperties

Selecting incompressible transport model Newtonian
Selecting incompressible transport model Newtonian

#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::myInterfaceProperties::myInterfaceProperties(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::IOdictionary const&) at ??:?
#4
 at ??:?
#5  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#6
 at ??:?
Segmentation fault (core dumped)
Note that i am not even using DeltaX DeltaY, this was just a test to see if the new variables were correctly passed to the new library and it seems they are not.

Any idea about the error?

Andrea
Andrea_85 is offline   Reply With Quote

Old   January 7, 2016, 12:21
Default
  #2
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
Hi!

Which OF version are you using? OF2.4.0 or less?

Did you pointed your Make/options file to new library, like that:

Code:
EXE_INC =
    -I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \
    -I$(LIB_SRC)/transportModels \
    -I$(LIB_SRC)/transportModels/incompressible/lnInclude \
    -I$myInterfaceProperties/lnInclude \
    -I$(LIB_SRC)/turbulenceModels/incompressible/turbulenceModel \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I$(LIB_SRC)/fvOptions/lnInclude \
    -I$(LIB_SRC)/sampling/lnInclude

EXE_LIBS = \
    -L$(FOAM_USER_LIBBIN) \
    -ltwoPhaseMixture \
    -lmyInterfaceProperties \
    -ltwoPhaseProperties \
    -lincompressibleTurbulenceModel \
    -lincompressibleRASModels \
    -lincompressibleLESModels \
    -lfiniteVolume \
    -lmeshTools \
    -lfvOptions \
    -lsampling
In any way the better practice, is to create your own derived class, which inherits standard OpenFOAM class. In this class you can put anything you want.
mkraposhin is offline   Reply With Quote

Old   January 7, 2016, 12:42
Default
  #3
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 16
Andrea_85 is on a distinguished road
Hi,

thanks for your reply. I am using 2.3.1
This is exactly what i have done. I created a new solver and linked to it the new libraries. This is how the Make/option file looks like (again in red the new parts)

Code:
EXE_INC = \
    -I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \
    -I$(LIB_SRC)/transportModels \
    -I$(LIB_SRC)/transportModels/incompressible/lnInclude \
    -I$(LIB_SRC)/transportModels/interfaceProperties/lnInclude \
    -I$(LIB_SRC)/turbulenceModels/incompressible/turbulenceModel \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/fvOptions/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I$(LIB_SRC)/triSurface/lnInclude \
    -I$(LIB_SRC)/sampling/lnInclude \
    -I./myInterfaceProperties/lnInclude \
    -I./myTwoPhaseProperties/lnInclude

EXE_LIBS = \
    -ltwoPhaseMixture \
    -linterfaceProperties \
    -ltwoPhaseProperties \
    -lincompressibleTransportModels \
    -lincompressibleTurbulenceModel \
    -lincompressibleRASModels \
    -lincompressibleLESModels \
    -lsampling \
    -lfiniteVolume \
    -lfvOptions \
    -ltriSurface \
    -lmeshTools \
    -lmyInterfaceProperties \
    -lmyTwoPhaseProperties
the "old" libraries are still there because i need both. Btw i got no error during the compilation so i am guessing they are properly linked.

Andrea
Andrea_85 is offline   Reply With Quote

Old   January 7, 2016, 12:53
Default
  #4
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
Quote:
Originally Posted by Andrea_85 View Post
the "old" libraries are still there because i need both. Btw i got no error during the compilation so i am guessing they are properly linked.

Andrea
I think, here is the point of your problem. Your program will work in two cases:
- you will create and will use child class from interfaceProperties
- you will leave only your own version of interfaceProperties
mkraposhin is offline   Reply With Quote

Old   January 7, 2016, 13:08
Default
  #5
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
By the way, did you renamed your twoPhaseProperties class?

It looks like a mismatch in data types naming
mkraposhin is offline   Reply With Quote

Old   January 7, 2016, 13:37
Default
  #6
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 16
Andrea_85 is on a distinguished road
I quickly tried to remove the link i don't need to the old libraries, recompiled but the error is still there. The Make/option file now is

Code:
EXE_INC = \
    -I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \
    -I$(LIB_SRC)/transportModels \
    -I$(LIB_SRC)/transportModels/incompressible/lnInclude \
    -I$(LIB_SRC)/turbulenceModels/incompressible/turbulenceModel \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/fvOptions/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I$(LIB_SRC)/triSurface/lnInclude \
    -I$(LIB_SRC)/sampling/lnInclude \
    -I./myInterfaceProperties/lnInclude \
    -I./myTwoPhaseProperties/lnInclude

EXE_LIBS = \
    -ltwoPhaseMixture \
    -ltwoPhaseProperties \
    -lincompressibleTransportModels \
    -lincompressibleTurbulenceModel \
    -lincompressibleRASModels \
    -lincompressibleLESModels \
    -lsampling \
    -lfiniteVolume \
    -lfvOptions \
    -ltriSurface \
    -lmeshTools \
    -lmyInterfaceProperties \
    -lmyTwoPhaseProperties
The "twoPhaseProperties" lib is there for the alphaContactAngle that i need. In myTwoPhaseProperties ive implemented new Bc for another scalarField (levelSet). The lib has a different name and i changed all the names of all the functions inside. It shouldn't be a problem.

Before, I successfully compiled and used the same solver (with both "old" and "new" interfaceProperties and twoPhaseProperties linked to the main program) but without the additional fields (DeltaX and DeltaY) in the new myInterfaceProperties. Now i need to perform extra calculation and i would like to do it inside the library. That's why i am trying to pass the two fields. I think the error is somewhere there. maybe a wrong variable declaration?

anyway thanks for spending your time on it!

Andrea
Andrea_85 is offline   Reply With Quote

Old   January 7, 2016, 13:49
Default
  #7
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
There is a type conflict somewhere else. My suggestion is to re-use standard OpenFOAM classes:

in .H:
Code:
class myInterfaceProperties
: public interfaceProperties
in .C:
Code:
Foam::myInterfaceProperties::myInterfaceProperties
(
    const volScalarField& alpha1,
    const volVectorField& U,
    const volScalarField& DeltaX,
    const volScalarField& DeltaY,
    const IOdictionary& dict
)
:    
    interfaceProperties(alpha1, U, dict)
    dx_(DeltaX),
    dy_(DeltaY),
If you will switch to OF2.3.0 or 2.4.0, i can try to compile and test your, because i think that you are missing something small.

Also, i took part in this thread where this problem was also solved
Adding the Energy Equation to interFoam (OF 2.4.0)
mkraposhin is offline   Reply With Quote

Old   January 8, 2016, 10:57
Default
  #8
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 16
Andrea_85 is on a distinguished road
Hello,

after a depth debugging i think i understand (at least) where the error comes from but still i do not know how to fix it. I rewrote the library adding things step by step. Now i am able to corretly pass the two fields DeltaX and DeltaY. The error seems to be generated by another volScalarField i defined inside the library. The variable is named nuGamma_

in myInterfaceProperties.C i added the variable constructor by copy paste nHatf_ from the original interfaceProperties.C

Code:
  nuGamma_
    (
        IOobject
        (
            "nuGamma",
            alpha1_.time().timeName(),
            alpha1_.mesh()
        ),
        alpha1_.mesh(),
        dimensionedScalar("nuGamma", dimless, 0.0)
    ),
in myInterfaceProperties.H i added the variable declaration and the member function


Code:
/*---------------------------------------------------------------------------*\
                           Class myInterfaceProperties Declaration
\*---------------------------------------------------------------------------*/

class myInterfaceProperties
{
.
.
volScalarField nuGamma_;
.
.
.
 // Member Functions
.
 const volScalarField& nuGamma() const
  {
            return nuGamma_;
   }
I am not using nuGamma, for the moment ive just declared it.
With these lines i got the error in my first post, without these line the code runs with no problem. I really dont see where is the problem.
Andrea_85 is offline   Reply With Quote

Old   January 8, 2016, 12:45
Default
  #9
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
This problem can be solved easily - check that you are initializing alpha1_ before nuGamma_

If this works, tell me, and i will give explanation later
mkraposhin is offline   Reply With Quote

Old   January 8, 2016, 15:41
Default
  #10
Senior Member
 
Andrea Ferrari
Join Date: Dec 2010
Posts: 319
Rep Power: 16
Andrea_85 is on a distinguished road
oh...that was really easy...it works

I did not know it was important the initialization order...i learn new things every day...

thank you very much

andrea
Andrea_85 is offline   Reply With Quote

Old   January 9, 2016, 03:29
Default
  #11
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
Hi,

Yes, initialization order makes sense.

Sometimes, compiler watches for this - for example, if you declare dx_ and then dy_ in interfaceProperties.H, but initialize dx_ after dy_ in interfaceProperties.C, you will get compiler "warning". This should not generate error in most cases. But it is a good practice to declare and initialize variables in the same order

In your case, you tried to use members of reference to object (volScalarField& alpha1_), which was not initialized.
Reference - is a special type of C++, which must be initialized during it's definition.
In your case, everything, that is between body of constructor " {} " and arguments " : " is treated as the default initialization for members, declared in interfaceProperties.H
lihaoyun likes this.
mkraposhin is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Other] Multi species mass transport library [update] novyno OpenFOAM Community Contributions 111 November 9, 2021 23:37
ERROR: unable to find library HJH CFX 6 February 26, 2019 06:52
decomposePar is missing a library whk1992 OpenFOAM Pre-Processing 8 March 7, 2015 07:53
Compiled library vs. inInclude Files, DSMC solver crashes after run GPesch OpenFOAM Programming & Development 8 April 18, 2013 07:17
OpenFOAM141dev linking error on IBM AIX 52 matthias OpenFOAM Installation 24 April 28, 2008 15:49


All times are GMT -4. The time now is 05:58.