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

ITK in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 9, 2014, 03:26
Default ITK in OpenFOAM
  #1
New Member
 
Join Date: Oct 2013
Posts: 11
Rep Power: 13
incompressible is on a distinguished road
How can I interlace my own OpenFOAM code with ITK?

Assume that I simply take an existing OpenFOAM code (such as icoFoam) and want to extent it using some routines for which I need to write own cpp classes. One of these cpp classes include ITK routines in order to call functions related to image processing. How do I have to change the Make/files or Make/options in order to be able to build and run all together? Checking ITK tutorials, I see that they only use cmake writing some CMakeList.txt files, so there was no example how to do it with wmake or how to bring it to run together with own OpenFOAM developments. I tried to call 'cmake' as a command in Make/files and tried to build with wmake, but no success so far. Any ideas?

Many thanks.
incompressible is offline   Reply With Quote

Old   April 9, 2014, 10:10
Default
  #2
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Hi,

I have encountered the same problem when I wanted to use Google Test. If you just use 'wmake' and provide the appropriate input in 'Make/options', you will be able to compile OpenFOAM applicaitons and classes against any other external library, here is what I did for Google Test:

Code:
EXE_INC = \
    -I$(SOME_VARIABLE)/src/lnInclude \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(SOME_VARIABLE)/third-party/gtest/include 

EXE_LIBS = \
    -L$(SOME_VARIABLE)/third-party/gtest/build \
    -lgtest \
    -lfiniteVolume
Basically, you need to introduce the include directory where ITK headers (or links to headers) are stored with the '-I$' that then uses either some variable, or the full path. Also the linker needs to be aware of the ITK binaries, which is what you can achieve by providing the directory with '-L$' option. Afterwards, you need to specify the library linked to - 'gtest' in the example above. That's it. I didn't switch the build system, there is no need, you can do quite well with wmake.
tomislav_maric is offline   Reply With Quote

Old   April 26, 2014, 12:45
Default
  #3
New Member
 
Join Date: Oct 2013
Posts: 11
Rep Power: 13
incompressible is on a distinguished road
Hi there,

Thank you very much for your response! That solved the problem very well. It was a little bit hard though, since there has been too many missing libraries, certain other Unix related issues and together with very little to almost non-descriptive error messages. But after some painfully amount of days, the issue could be resolved, in the meanwhile getting to be a fully developed Unix-Freak . I can almost hack now .
incompressible is offline   Reply With Quote

Old   April 26, 2014, 13:28
Default
  #4
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Hi, I'm glad it helped!

The problem with the almost unreadable errors you probably saw yourself when libraries are not linked properly is that symbol lookups fail - the compiler tries to find a function like:

Code:
void functionName(type argument, type2 argument2)
and you see something like

Code:
undefined reference to 73Edcvoid7sesfunction2ctype13x_type2x32
In which case using 'c++filt' to unmangle the above messed up name might help, just FYI, maybe you'll need it in the future. The compiler mangles the names (function, classes, attributes, etc) because it uses the mangled names in the overload resolution process...

@hacking: I know what you mean, it takes time to get a hang of these things, just keep digging into that stuff and post here when you encounter problems that take more than half a day to tackle...
__________________
When asking a question, prepare a SSCCE.
tomislav_maric is offline   Reply With Quote

Old   April 28, 2014, 03:28
Default
  #5
Senior Member
 
Elvis
Join Date: Mar 2009
Location: Sindelfingen, Germany
Posts: 620
Blog Entries: 6
Rep Power: 24
elvis will become famous soon enough
Hi,

unfortunately the guys that made the FreeFOAM seem to have stopped their projekt
+FreeFOAM is a fork of OpenFOAM®.
+the custom WMake build system used in OpenFOAM has been replaced by the excellent, cross-platform CMake, making it much easier to port FreeFOAM to new platforms.
elvis is offline   Reply With Quote

Old   April 28, 2014, 06:33
Default
  #6
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Quote:
Originally Posted by elvis View Post
WMake build system used in OpenFOAM has been replaced by the excellent, cross-platform CMake, making it much easier to port FreeFOAM to new platforms.
Regardless of the build system - the idea is the same. Each build system specifies in one way or the other the location of the class/function/blah declarations. It also requires the location of library binary code for linking against.

What incompressible tried to do at first can't work - using two build systems.

My suggestion is to use whatever build system your OpenFOAM version is using (wmake, cmake, boost.build, whatever), to build OpenFOAM applications and libraries. Likewise, one should switch to the build system of the other platform (in this case ITK) to build apps and libs that only make use of OpenFOAM headers / libraries within that platform.
__________________
When asking a question, prepare a SSCCE.
tomislav_maric is offline   Reply With Quote

Old   April 28, 2014, 17:42
Default
  #7
New Member
 
Join Date: Oct 2013
Posts: 11
Rep Power: 13
incompressible is on a distinguished road
Quote:
Originally Posted by tomislav_maric View Post
Regardless of the build system - the idea is the same. Each build system specifies in one way or the other the location of the class/function/blah declarations. It also requires the location of library binary code for linking against.
Sure, but not exactly the truth. Besides the linkage of some libraries and paths of header directories, build systems can also be used to prepare certain other utilities, which makes it a little bit complicated to integrate something (such as ITK), which was mainly build with one build system (cmake), with something else (e.g OpenFOAM) using another build system (lets say wmake).

In ITK, for example, they use certain design patterns whose objects are created and prepared in their certain cmake files directly. In terms of a given try to what computer scientist call "information hiding", this should happen behind the knowledge of the user or they shouldn't care about how these objects are actually created. One example of such structures are the factory classes responsible to create and manage objects to handle, lets say, different file formats such as PNG, JPEG, TIFF etc. Now, if an ITK user, whatever her own ITK application she prepares with cmake, loads a PNG image, she won't even now or realise the factory objects that does the job. As she builds her application with cmake, one of the main cmake files of ITK are called automatically, which creates these objects. However, if an OpenFOAM user, such as me, now goes forward and tries to integrate ITK platform to his OpenFOAM framework, he will just wonder why his images cannot even be loaded at all. So it is not "enough" to just put the libraries and includes to the wmake files, but all necessary factory objects now have to be created manually in own code, as long as one does not follow the path given by cmake builds. Therefore the statement with "the same idea regardless of the build system" might not always be valid, but in general of course the truth.

Maybe its a little bit more clear now, why I originally tried to call something like 'cmake' from wmake with a hopeless hope to be able to build another application and dynamically link it to OpenFOAM framework without having to perform two separate builds.
incompressible is offline   Reply With Quote

Old   April 29, 2014, 05:24
Default
  #8
Senior Member
 
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21
tomislav_maric is on a distinguished road
Quote:
However, if an OpenFOAM user, such as me, now goes forward and tries to integrate ITK platform to his OpenFOAM framework, he will just wonder why his images cannot even be loaded at all. So it is not "enough" to just put the libraries and includes to the wmake files, but all necessary factory objects now have to be created manually in own code, as long as one does not follow the path given by cmake builds.
Wow, OK, I definitely was not aware of that. With Google Test it went smoothly as soon as I have let the build system know where the headers/binaries are.

IMHO, to me this seems like a strange approach to set up an object factory. I don't see the logical connection between the build system and the factory at all... If a generic factory is used, I would expect the client code (some ITK/OpenFOAM application cpp file) to instantiate the appropriate factory at compile time. On the other hand, if something like OpenFOAM's run-time selection is used, then the object generation will be bound to the class hierarchy and governed by configuration (input) files - are they using make files for this in ITK? Binding it to the build system just sounds a bit weird to me... but maybe it's done this way because there are no case directories like for OpenFOAM where you can then shove the input data for the run-time selection of the factory. Anyway, no wonder it took you some time to set that up.

Was the factory a pointer to the base factory class in the client ITK code, and you kept getting run-time errors? Segfaults since the concrete factory is not initialized would be my first guess. That must have been 'extremely fun' to find.
__________________
When asking a question, prepare a SSCCE.
tomislav_maric 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
Frequently Asked Questions about Installing OpenFOAM wyldckat OpenFOAM Installation 3 November 14, 2023 12:58
OpenFOAM Foundation Releases OpenFOAM v2.3.0 opencfd OpenFOAM Announcements from OpenFOAM Foundation 3 December 23, 2014 04:43
Suggestion for a new sub-forum at OpenFOAM's Forum wyldckat Site Help, Feedback & Discussions 20 October 28, 2014 10:04
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 19:07
OpenFOAM Training and Workshop Hrvoje Jasak Main CFD Forum 0 October 7, 2005 08:14


All times are GMT -4. The time now is 07:43.