CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [Tutorials] OpenFOAM programming tutorials for beginners (https://www.cfd-online.com/Forums/openfoam-community-contributions/188688-openfoam-programming-tutorials-beginners.html)

Artur June 4, 2017 17:21

OpenFOAM programming tutorials for beginners
 
Hi Foamers!

I wanted to share with you a couple of simple pieces of codes I wrote to demonstrate basic OpenFOAM functionality to beginner C++ programmers:
https://github.com/UnnamedMoose/Basi...mmingTutorials

The reason for the existence of these is that during my time at a University I've found that many students starting their research using OpenFOAM are required to develop code for it but have little to no prior knowledge of C++. This usually makes it very hard for them to jump from basic programming to the admittedly complex OpenFOAM framework, and also makes using many on-line materials quite challenging. The above tutorials hope to help with making this step. I've "tested" them on a few of my colleagues and collaborators and I hope they may help a wider audience in the future.

Feedback always welcome! But please bear in mind I'm self-taught both in OpenFOAM and C++, so go easy on me :)

Also, if you'd like to contribute a new tutorial or offer improvements to the ones already there, I'd highly welcome your input!

Happy foaming,

Artur

DoQuocVu July 11, 2017 22:40

Thank you so much for your sharing.
Actually i am at the first steps of learning programming with openfoam and this would make my live much easier.

DoQuocVu July 18, 2017 13:53

Hi Artur,

I've gone through the Tutorial number 2 and now I'm able to get access to some basic mesh informations. But I wonder is there any way to read information from a trisurface .stl mesh? For example read points and faces and put them into a list?

Artur July 18, 2017 14:44

Hi,

Glad to see more people using the materials. I've never worked with stl's in OpenFOAM so can't give precise advice, but a quick look under the hood suggests starting off with the triSurface object, defined in
Code:

$FOAM_SRC/triSurface/triSurface/triSurface.H
. See also
Code:

$FOAM_APP/utilities/surface/surfaceClean
for an example application.

If you figure out a minimum working example showing how to load a specific surface, access its elements etc. I encourage putting it on GitHub and creating a pull request into the tutorials to share your experience with the others :)

Also, it's great to hear from other people in this thread, but if you have any more specific questions about the stl stuff I suggest opening a new thread for it to make the forum more readable.

All the best

Artur

DoQuocVu July 18, 2017 16:40

Thanks for your suggestion, triSurface object seems to be a great starting point. I'll spent time to play around with it. And I would love to contribute too :)

babakflame July 25, 2017 19:25

Dear Artur

Many thanks for your tutorials. As a member of OpenFoam community, I wanted to express my gratitude for sharing these tutorials with others.
For curiosity, I went through almost all of them. Your comments were nice and helpful. Sometimes, the level of C++ was higher than my standards.;);)

Regards

ahmed425 August 6, 2017 03:43

Dear Artut,

Thank you for taking the effort in writing these materials. I'm so excited that I found them. Currently I'm trying to teach my self the basics of C++ in parallel with learning programming with OpenFOAM and every day I can see that learning C++ is a must if you are planning to do some serious work with OF. Again, thank you and I will definitely gonna give feedback on the materials once I'm done with them.

Ahmed :)

sitajeje August 7, 2017 15:36

Hello Artur,

Thank you very much for your tutorial, I learned a lot from them, especially about the mesh, volScalarField, volVectorField. I could manage some simple postProcess utilities after running your tutorials.

I have one question about the last tutorial, is the 0/beta missing? I didn't figure it out how to create one. Thank you very much in advance!

I have difficulties understanding the OFtutorial8, since there are so many include files/classes/templates which are not familiar to me. I wonder whether you have suggestions about understanding the C++ source guide of OpenFOAM? I would appreciate greatly!

Best regards,

sitajeje

Artur August 9, 2017 12:39

Hi Sitajeje,

Thank you for pointing out the missing file in 0/ in tutorial 9, I added it to the github repo now. My bad.

As for your question, you can try:
1. Doxygen on line (my goodness, just realised they released OF 5 and I'm still using 3.0.1!):
https://cpp.openfoam.org/v4/files.html
2. you can compile doxygen yourself although I've never done it, maybe this will work:
https://www.cfd-online.com/Forums/op...mentation.html
3. Personally, I just tend to look up the header files and arrange them in my editor in order from the most basic to most "derived" class

In general, I don't think there are many shortcuts you can take on this one :) If you figure out some useful comments that would make the tutorial easier to understand I'd very much welcome your contribution!

All the best,

Artur

Tobi August 9, 2017 14:26

Hi Arthur,

very well done. Nice stuff. I love it. Especially the parallel stuff - never went into that and it is a very good start :) I like seeing people all over the world contributing to the community. One thing I want to mention. It would be great if you add a page to the openfoamwiki page. Otherwise it might happen that this thread and all your great work get lost during time.

Keep going doing that nice things :)
Cheers,

Artur August 9, 2017 14:46

Hi Tobias,

Many thanks, glad you found it useful. Very good idea with the wiki page, I'll definitely do that. I think first I need to upgrade the code to work with the new version since being two major releases behind is a bit much!

All the best,

A

tomdylan August 22, 2017 04:24

Hi Artur,

the understandingTheMesh-tutorial yielded more insight than the tens of solvers I have been trying to understand.

Thank you for the efforts!

Tom

goldersantu August 22, 2017 16:41

chemFoam
 
Hello,

I am new to openfoam and find it to be a useful program. I have a question. I am learning how to use chemFoam. How does one write extra variables to a file. The file is chemFoam.out. The file currently writes time, temperature and pressure. I want to write out all of the species variables (CH4, O2, N2, CO2, CO, ….) too. How does one do this?

Artur August 23, 2017 10:30

Hi,

Have a look at tutorial 3 which covers field operations, such as creating new fields and writing them. Specie concentrations are simply scalar fields you should be able to access without too much trouble through the multi-specie mixture interface created in createFields.H:

Code:

basicMultiComponentMixture& composition = thermo.composition();
PtrList<volScalarField>& Y = composition.Y();

If you're still struggling with it I suggest opening a new thread targeted at your specific issue.

All the best,

A

CFDpal October 20, 2017 17:59

Many Thanks!
 
Artur,

Many thanks for such a thorough tutorial. It helps big time !

CFDpal

Germilly November 7, 2017 07:07

Artur,

Thank you for your sharing.
This solved my problems.

Regards

amod_kumar November 15, 2017 04:20

General description of the OpenFOAM suite
 
Hello OF Users,
Just to add, I found this PDF file which explains each line of code (being PDF, it looks like a book). Hope this will add to the nice information already put in here. I cannot upload this file due to size restrictions and put a link to

http://cfdyna.com/Home/OpenFOAM/of_T...escription.pdf

Regards,

Artur November 15, 2017 04:53

Thanks for sharing, indeed quite a useful resource!

alixcattermole November 21, 2017 13:16

hello i am an absolute beginner and would like to go through these tutorials as i need to learn openfoam for my university project but i cannot figure out how to get started. Please can you help me and tell me where and how to start?

Artur November 22, 2017 04:06

Hi,
It's not very clear what you're asking - learning OF as in doing CFD or programming and development? If the latter, I suggest just follow the Requirements part of the README on the GitHub page, there's not much more I could say than what is already there. If you mean running CFD with OF in general, the official tutorials are always a good start, then there are some excellent pages you could find by just typing "getting started with OpenFOAM" into Google, which have all the info you might need to kick off:
https://www.cfd-online.com/Forums/op...-openfoam.html
Also look into course materials here:
http://www.tfd.chalmers.se/~hani/kurser/OS_CFD/

If you're struggling with something specific, I suggest you start a new thread under "Running, solving and CFD" to keep things organised and increase your chances of actually getting some help.


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