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

Foam Version as a compile-time macro

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By deepsterblue
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 29, 2009, 18:35
Default Foam Version as a compile-time macro
  #1
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
Just a suggestion, but perhaps it would be useful to have the Foam version as a compile-time macro. For example, something like this for OF-1.5:

#define FOAM_MAJOR_REVISION 1
#define FOAM_MINOR_REVISION 5

Or something on similar lines (Maybe passed in to g++ with a -D option). Considering how member functions change over revisions, (like faceOwner instead of allOwner in polyMesh, for instance), backward compatibility is sometimes an issue. I agree that it makes code uglier because of #ifdefs all around the source code, but it might be handy to have...
MakisH likes this.
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   May 25, 2009, 05:36
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,694
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by deepsterblue View Post
Just a suggestion, but perhaps it would be useful to have the Foam version as a compile-time macro. For example, something like this for OF-1.5:

#define FOAM_MAJOR_REVISION 1
#define FOAM_MINOR_REVISION 5
wmake already has/had a PROJECT_VERSION defined as major, 3 digits minor and 3 digits revision.
For example, 1.5 == -DPROJECT_VERSION=1005000.
Unfortunately this breaks down horribly when versions contain non-digits (eg, like 1.5.x). I would thus avoid using it at all.

IMO the better method is to keep your code up-to-date with the latest developments and use branching within git if you also need to maintain code for legacy versions. This is not only much cleanier to read than piles of #ifdefs, but also avoids strange and possibly hard to trace bugs. For example, if you'd moved from 1.5 to 1.5.x, the wrong chunk would get evaluated here:
Code:
#if PROJECT_VERSION >= 1005000
chunk1 ...
#else
chunk2 ...
#endif
I think the need for using PROJECT_VERSION disappeared with the introduction of git for version control. I wouldn't be surprised if PROJECT_VERSION disappeared in a future version, but you can copy the same idea in your own Make/options if you'd like.
MakisH likes this.
olesen is offline   Reply With Quote

Old   January 7, 2019, 02:13
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,694
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by olesen View Post
IMO the better method is to keep your code up-to-date with the latest developments and use branching within git if you also need to maintain code for legacy versions. This is not only much cleanier to read than piles of #ifdefs, but also avoids strange and possibly hard to trace bugs.

Someone brought this old thread back to my attention, so I figured it could make sense to update it.
The OPENFOAM compiler define, which is a 4-digit value corresponding to the api version, can be used for transitional features etc. Eg,

Code:
#if (OPENFOAM >= 1812)
Info<< "using some OpenFOAM-v1812 version" << nl;
#else
Info<< "using some other version" << nl;
#endif

The value is defined within the wmake rules, so it should correspond to the currently active OpenFOAM environment/version.
olesen 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
Physical Reason for stability of Implicit Schemes? radhakrishnan Main CFD Forum 26 October 3, 2023 22:05
SimpleFoam k and epsilon bounded nedved OpenFOAM Running, Solving & CFD 16 March 4, 2017 08:30
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 05:36
IcoFoam parallel woes msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 02:58
unsteady calcs in FLUENT Sanjay Padhiar Main CFD Forum 1 March 31, 1999 12:32


All times are GMT -4. The time now is 10:59.