|
[Sponsors] |
Virtual inheritance problem while adding public member function to LES SGS Model |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 17, 2013, 17:04 |
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 |
Dear Foamers,
I have a really strange programming issue concerning virtual inheritance. What I want to do:
What I basically did to achieve this goal:
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:
I would be very happy about any advice or hint! Cheers, Konrad |
|
October 23, 2013, 13:15 |
Update
|
#2 |
New Member
Konrad Makowka
Join Date: Apr 2012
Location: München, Germany
Posts: 6
Rep Power: 14 |
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. |
|
October 23, 2013, 14:14 |
|
#3 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
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_; }; 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. |
|
October 24, 2013, 04:21 |
|
#4 | |
New Member
Konrad Makowka
Join Date: Apr 2012
Location: München, Germany
Posts: 6
Rep Power: 14 |
Thanks ngj,
Quote:
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! |
||
November 4, 2013, 12:37 |
Solved
|
#5 |
New Member
Konrad Makowka
Join Date: Apr 2012
Location: München, Germany
Posts: 6
Rep Power: 14 |
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. |
|
|
|
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 |