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

Virtual inheritance problem while adding public member function to LES SGS Model

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By konneym

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 17, 2013, 17:04
Default Virtual inheritance problem while adding public member function to LES SGS Model
  #1
New Member
 
Konrad Makowka
Join Date: Apr 2012
Location: München, Germany
Posts: 6
Rep Power: 14
konneym is on a distinguished road
Dear Foamers,

I have a really strange programming issue concerning virtual inheritance.

What I want to do:
  • Add a member function to the LES SGS Model I implemented, so that I can access a certain field in my actual solver

What I basically did to achieve this goal:
  • Added a virtual function to the header of compressible::turbulenceModel by appending it to the end of the rest of the functions in the header file:
virtual tmp<volScalarField> myCoolFunction() const = 0;
  • Added the corresponding function to my LES SGS Model header file and implementation file
virtual tmp<volScalarField> myCoolFunction(); // header

tmp<volScalarField> myCoolFunction() // implementation file
{
return myCoolvolScalarField_;
}

My code compiles and seems to make sense from a programming point of view, if I got virtual inheritance correctly.

However: When I call my new function with turbulence->myCoolFunction() in my solver code, I do not get myCoolvolScalarField_. Interestingly, what happens instead is that some random(?) other function from compressible:turbulenceModel gets called (e.g. printing some LES SGS model coefficients).
By changing the order of the functions in the compressible:turbulenceModel header file, I can influence, which function from compressible::turbulenceModel gets called (so it is not that random at all), which means that the order of functions header file seems to matter! This is weird and doesn't make sense!

Anyhow, I can't call my function, also after having done some fancy reordering.

After a long while of googling without any useful results, I found that the construction of the virtual tables for the involved classes can produce the behavior I experienced, caused by peculiarities of some compilers. I run OpenSuse 12.1 and my compiler is gcc 4.6.2. I still use OpenFOAM 2.1.1.

What I would like to know is:
  • whether I made a programming mistake
  • if there is a related bug, potentially caused by the combination of my OF version and the compiler
  • if anyone had similar experiences

I would be very happy about any advice or hint!

Cheers,

Konrad
konneym is offline   Reply With Quote

Old   October 23, 2013, 13:15
Default Update
  #2
New Member
 
Konrad Makowka
Join Date: Apr 2012
Location: München, Germany
Posts: 6
Rep Power: 14
konneym is on a distinguished road
I also tried to trick the virtual function table and added a couple of other dummy functions and put my actual function in between. Unfortunately, without success.

Furthermore, I added some dummy function input parameter (e.g. bool dummy), with the same idea in mind, again without success.

This is really weird and doesn't make any sense to me.
konneym is offline   Reply With Quote

Old   October 23, 2013, 14:14
Default
  #3
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Good evening,

I suppose that myCoolVolScalarField is a volScalarField, so why do you return it as a tmp<volScalarField>?

Try do the following instead (using a reference):

Code:
inline const volScalarField& myCoolFunction const
{
    return myCoolVolScalarField_;
};
Of course, you can remove any of the "const", which do not suite your needs.

Kind regards

Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   October 24, 2013, 04:21
Default
  #4
New Member
 
Konrad Makowka
Join Date: Apr 2012
Location: München, Germany
Posts: 6
Rep Power: 14
konneym is on a distinguished road
Thanks ngj,

Quote:
I suppose that myCoolVolScalarField is a volScalarField, so why do you return it as a tmp<volScalarField>?
I basically followed the function declaration of the other standard return function, e.g:

virtual tmp<volScalarField> alphaEff() const = 0;

.. which is why I return a tmp<volScalarField>


I tried your solution, unfortunately, it does not solve my problem. I still get the same behavior (call of some other function in turbulenceModel).

Thanks, anyway!
konneym is offline   Reply With Quote

Old   November 4, 2013, 12:37
Default Solved
  #5
New Member
 
Konrad Makowka
Join Date: Apr 2012
Location: München, Germany
Posts: 6
Rep Power: 14
konneym is on a distinguished road
I solved the problem:

It wasn't a programming issue, but basically a conflict between parts of our OpenFOAM being compiled on a server with a slighty different architecture. My locally compiled solver and libraries accessed libraries from the server, which is the root cause for my problem.

By compiling a local version on my machine, I got a consistently compiled OpenFOAM, and my weird error is gone.

Lesson learned: Either keep your architecture PC<-->server the same or compile everything on the machine, where you want to run your code.
ngj likes this.
konneym 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
Compile problem ivanyao OpenFOAM Running, Solving & CFD 1 October 12, 2012 10:31
[blockMesh] BlockMesh FOAM warning gaottino OpenFOAM Meshing & Mesh Conversion 7 July 19, 2010 15:11
Compilation errors in ThirdPartymallochoard feng_w OpenFOAM Installation 1 January 25, 2009 07:59
LES and combustion model Margherita Cadorin CFX 0 October 29, 2008 06:24
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51


All times are GMT -4. The time now is 20:27.