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

[Tutorials] OpenFOAM programming tutorials for beginners

Register Blogs Community New Posts Updated Threads Search

Like Tree195Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 4, 2017, 18:21
Lightbulb OpenFOAM programming tutorials for beginners
  #1
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20
Artur will become famous soon enough
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
pad, elvis, makaveli_lcf and 138 others like this.
Artur is offline   Reply With Quote

Old   July 11, 2017, 23:40
Default
  #2
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 10
DoQuocVu is on a distinguished road
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.
Artur likes this.
DoQuocVu is offline   Reply With Quote

Old   July 18, 2017, 14:53
Default
  #3
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 10
DoQuocVu is on a distinguished road
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?
DoQuocVu is offline   Reply With Quote

Old   July 18, 2017, 15:44
Default
  #4
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20
Artur will become famous soon enough
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

Last edited by Artur; July 18, 2017 at 17:41.
Artur is offline   Reply With Quote

Old   July 18, 2017, 17:40
Default
  #5
Member
 
Vu
Join Date: Nov 2016
Posts: 42
Rep Power: 10
DoQuocVu is on a distinguished road
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
DoQuocVu is offline   Reply With Quote

Old   July 25, 2017, 20:25
Default
  #6
Senior Member
 
Bobby
Join Date: Oct 2012
Location: Michigan
Posts: 454
Rep Power: 16
babakflame is on a distinguished road
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
Artur likes this.
babakflame is offline   Reply With Quote

Old   August 6, 2017, 04:43
Default
  #7
New Member
 
Join Date: Jun 2016
Posts: 6
Rep Power: 10
ahmed425 is on a distinguished road
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
Artur likes this.
ahmed425 is offline   Reply With Quote

Old   August 7, 2017, 16:36
Default
  #8
Member
 
Join Date: Sep 2016
Posts: 63
Rep Power: 10
sitajeje is on a distinguished road
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
sitajeje is offline   Reply With Quote

Old   August 9, 2017, 13:39
Default
  #9
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20
Artur will become famous soon enough
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:
how to use Doxygen to generate a PDF with OpenFOAM's source code documentation?
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
Artur is offline   Reply With Quote

Old   August 9, 2017, 15:26
Default
  #10
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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,
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   August 9, 2017, 15:46
Default
  #11
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20
Artur will become famous soon enough
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
Artur is offline   Reply With Quote

Old   August 22, 2017, 05:24
Default
  #12
New Member
 
tomdylan's Avatar
 
Tom Dylan
Join Date: May 2015
Posts: 20
Rep Power: 11
tomdylan is on a distinguished road
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
Artur likes this.
tomdylan is offline   Reply With Quote

Old   August 22, 2017, 17:41
Default chemFoam
  #13
New Member
 
Golden
Join Date: Jun 2017
Posts: 4
Rep Power: 9
goldersantu is on a distinguished road
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?
goldersantu is offline   Reply With Quote

Old   August 23, 2017, 11:30
Default
  #14
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20
Artur will become famous soon enough
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
Artur is offline   Reply With Quote

Old   October 20, 2017, 18:59
Default Many Thanks!
  #15
New Member
 
CFDpal
Join Date: Mar 2017
Location: Boston, MA
Posts: 20
Blog Entries: 1
Rep Power: 9
CFDpal is on a distinguished road
Artur,

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

CFDpal
Artur likes this.
CFDpal is offline   Reply With Quote

Old   November 7, 2017, 08:07
Default
  #16
New Member
 
Germilly Barreto
Join Date: Jul 2016
Location: Portugal
Posts: 25
Rep Power: 10
Germilly is on a distinguished road
Artur,

Thank you for your sharing.
This solved my problems.

Regards
Artur likes this.
Germilly is offline   Reply With Quote

Old   November 15, 2017, 05:20
Default General description of the OpenFOAM suite
  #17
Member
 
Amod Kumar
Join Date: Jan 2010
Location: Delhi, India
Posts: 39
Rep Power: 16
amod_kumar is on a distinguished road
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,
minh khang, sk11, purnp2 and 1 others like this.
amod_kumar is offline   Reply With Quote

Old   November 15, 2017, 05:53
Default
  #18
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20
Artur will become famous soon enough
Thanks for sharing, indeed quite a useful resource!
minh khang likes this.
Artur is offline   Reply With Quote

Old   November 21, 2017, 14:16
Default
  #19
New Member
 
alix cattermole
Join Date: Nov 2017
Posts: 14
Rep Power: 9
alixcattermole is on a distinguished road
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?
alixcattermole is offline   Reply With Quote

Old   November 22, 2017, 05:06
Default
  #20
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20
Artur will become famous soon enough
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:
Getting Started with OpenFOAM
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.
Tobi and granzer like this.
Artur is offline   Reply With Quote

Reply

Tags
turorial files, tutorial


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
Map of the OpenFOAM Forum - Understanding where to post your questions! wyldckat OpenFOAM 10 September 2, 2021 06:29
OpenFOAM 4.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 2 October 6, 2017 06:40
OpenFOAM Training: Programming CFD Course 12-13 and 19-20 April 2016 cfd.direct OpenFOAM Announcements from Other Sources 0 January 14, 2016 11:19
OpenFOAM v3.0.1 Training, London, Houston, Berlin, Jan-Mar 2016 cfd.direct OpenFOAM Announcements from Other Sources 0 January 5, 2016 04:18
Openfoam Programming from scratch shovan OpenFOAM Programming & Development 1 July 9, 2015 13:38


All times are GMT -4. The time now is 12:50.