|
[Sponsors] |
June 23, 2009, 00:54 |
OpenFoam programming
|
#1 |
Senior Member
Prapanch Nair
Join Date: Mar 2009
Location: Bangalore, India
Posts: 105
Rep Power: 17 |
Hi,
I am a OpenFoam user. I have some programming knowledge in fortran. I have done pretty well in scientific programming, like writing euler equation solver for 2D unstructured grid etc. But I don't have any experience in oops, c or c++. Since openFoam is a collaborative effort, I really want to participate in its development. But I am stuck. Like it claims of its object oriented approach, I don't find it that easy to program in openFoam. For example, I thought I could write a poisson eqn solver based on LaplacianFoam. But I feel it is difficult to understand why certain header files are called. I believe that I will need an understand of how the whole code works, inorder to add or modify. I went through the programmers Guide. But I did not find that explaining what I mentioned above. I don't understand the reason why tutorial cases are explained in programmers guide. I want other programmers' advice on this. What sequence of actions should I perform so that I can get comfortable in contributing to openFoam? What would be like a first exercise, first thing to know etc. I am willing to write tutorials on what I discover too. I know this question may sound trivial. But that is because I am not in a job that demands me to learn openFoam programming. I am doing it on my own interest. Thank you Prapanj. |
|
June 24, 2009, 02:40 |
|
#2 |
Senior Member
Steve Hansel
Join Date: Jun 2009
Location: Colorado, USA
Posts: 112
Rep Power: 17 |
I'd think the first step would be to get a book on C++ and go through some of the basics like the syntax, classes, member variables, methods, etc.
I actually learned OO programming by learning basic Java. Java is a pure OO language and everything is OO. C++ is C with OO kind of tacked on. The general syntax with the {} for loops, whiles, dos, etc is the same in C, C++ and Java. I guess for you I'd suggest going straight to C++ but if you want more OO background you can also take a look at Java. Steve |
|
June 25, 2009, 11:53 |
|
#3 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
Hi
I have followed a course in C++, and I found that the book covered many of the questions one has when reading through the source code: Andrew Koenig and Barbara E. Moo Accelerated C++ Pratical Porgramming by Example The only drawback is that they base many of there exercises on string manipulation, which has few things to do with OF, however I have never seen programming books which uses engineering examples as exercises/examples. Good luck Niels |
|
July 11, 2009, 07:05 |
|
#4 | ||
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
Hi Prapanj,
Quote:
Quote:
Think of OpenFOAM C++ as a language to solve continuum mechanics problems. Understand it's language, then you can dig deeper. So here is my reciepe:
Some pointers where people have contributed modified codes which you may what to analyse: http://openfoamwiki.net/index.php/Main_CodeSnipplets http://openfoamwiki.net/index.php/Main_ContribSolvers http://openfoamwiki.net/index.php/Main_ContribUtilities http://openfoamwiki.net/index.php/Main_ContribExamples http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2007/ Henrik |
|||
July 11, 2009, 13:22 |
|
#5 |
Senior Member
Prapanch Nair
Join Date: Mar 2009
Location: Bangalore, India
Posts: 105
Rep Power: 17 |
Hi Henrik,
That was really helpful. This reply of yours is going to make my life much easier. Thank you. Prapanj. |
|
July 14, 2009, 13:36 |
|
#6 |
Senior Member
Sandy Lee
Join Date: Mar 2009
Posts: 213
Rep Power: 18 |
Hi Henrik,
I do bileve you that, after finish to read your documents a couple of years later, my boss will hire me! Yes, I agree to you that we do need not to dig very deep knowledges about C++, if we could ever use Fortran smoothly. But, we really don't need to learn more major branches of OpenFOAM? Giving your a example of mine. I don't know the reason that if I add the code sentences as follows volScalarField Sp ( IOobject ( "Sp", runTime.timeName(), mesh IOobject::MUST_READ, IOobject::AUTO_WRITE ), vDotvAlphal - vDotcAlphal ); into gammaEqn.H of interPhaseChangeFoam solver, I could not get the output file about volScalarField Sp ; however, if above same code sentences of volScalarField Sp was inserted into createFields.H, it can be output smoothly, although maybe it is the old data of last iterative step? So, as your viewpoints, in order to get OpenFOAM, which part knowledges I should further pay more efforts to study, C++ or major branches of OpenFOAM? Our police cats! |
|
July 14, 2009, 15:09 |
|
#7 |
Senior Member
Henrik Rusche
Join Date: Mar 2009
Location: Wernigerode, Sachsen-Anhalt, Germany
Posts: 281
Rep Power: 18 |
Sandy,
I remember that made this mistake, too ;-) In C++, all variables that are instantiated within a pair of curly brackets "{}" are deleted with the "}" as explained in more detail in the reference given above (Chapter 11). That's why there is no Sp when the fields are written with runTime.write(); when you instantiate the variable in gammaEqn.H. Henrik |
|
July 14, 2009, 19:56 |
|
#8 |
Senior Member
Sandy Lee
Join Date: Mar 2009
Posts: 213
Rep Power: 18 |
Yes, sir. this is a important C++ rule.
However, sometimes I am still blind. in which {} and when a variable can be added or removed with the runtime.write()? And how to transfer those closely connected varialbes between different subroutines? They actually show explicit or implicit branches of OpenFOAM in my eyes, which are really complicated and difficult to clearly learn but not only C++ rule. |
|
September 24, 2009, 01:37 |
|
#9 |
Senior Member
Prapanch Nair
Join Date: Mar 2009
Location: Bangalore, India
Posts: 105
Rep Power: 17 |
Thanks so far for the wonderful pointers. I have one more stupid question - When I begin to write a code, how do I know what header files to #include ? For example if I am trying to add a new turbulence model, and I am basing that on say std K epsilon. I then pick up the source of k epsilon and begin to modify it. Now suppose my turbulence model needs some regression values etc. So I will need some extra operations on the data. Then how will I find what header file to use? and what to remove ?
(The above was just a hypothetical example) Thanks, Prapanj |
|
February 5, 2010, 03:23 |
help
|
#10 |
Member
mohsen kh
Join Date: Nov 2009
Posts: 41
Rep Power: 15 |
Hi Foamers
I am an amateur and I want to simulate viscoelastic fluids flow, But I am completely confused with OpenFOAM. And a lot of questions arise for me working with this software. Would you possibly answer some of my questions? 1.For implementing a new model (like LPPT) is it sufficient to write a new application in (OpenFOAM/applications) or it is necessary to modify OpenFOAM/src and/or lib and/or etc. 2. Could you possibly send me one or more new application file which you have made it by yourself (a viscoelastic model for instance). Or a detailed help about implementing new models in OpenFOAM? I do need your help. Please help. That’s for my master thesis. Best wishes Mohsen – m.kh.599@gmail.com |
|
March 18, 2010, 08:23 |
|
#11 | ||
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 |
Quote:
If you just want to write some model you don't need an application, you need a library. The difference is in the fact that the library defines stuff that you need and doesn't execute anything. The application in this sense is a solver, a preprocessing or postprocessing app, anyway, something that has the Code:
int main( blah ) Code:
#include "viscoelasticModel.H" My final answer to this question would be: no, you may write your own library (the way depends on what you are doing), compile it to $FOAM_USER_LIBBIN and then just include it in your solver that's compiled to $FOAM_USER_APPBIN, there is no need to change the libOpenFOAM.so. When your work is finished, you will contribute it to the server, and then it will be where it should be, among the models somewhere in the source tree. Quote:
A piece of advice: contact the guy who wrote this viscoelastic solver (also for his Master thesis work) maybe he will be willing to help you, at least with some general pointers. |
|||
Tags |
guide, learning, object oriented, programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Programming in OpenFOAM | vinu | OpenFOAM | 2 | July 11, 2009 11:16 |
OpenFOAM Training in Europe and USA | hjasak | OpenFOAM | 0 | August 8, 2008 06:33 |
Adventure of fisrst openfoam installation on Ubuntu 710 | jussi | OpenFOAM Installation | 0 | April 24, 2008 15:25 |
OpenFOAM Debian packaging current status problems and TODOs | oseen | OpenFOAM Installation | 9 | August 26, 2007 14:50 |
OpenFOAM Training and Workshop Zagreb 2628Jan2006 | hjasak | OpenFOAM | 1 | February 2, 2006 22:07 |