|
[Sponsors] |
[Tutorials] OpenFOAM programming tutorials for beginners |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
November 22, 2017, 05:56 |
|
#21 |
New Member
alix cattermole
Join Date: Nov 2017
Posts: 14
Rep Power: 9 |
I just wanted to know how to start the beginners tutorials that were posted, i am unsure how to.
|
|
November 22, 2017, 09:44 |
|
#22 |
Senior Member
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20 |
Right, sorry if it's not clear enough. Here are the steps I'd recommend:
1. Learn to run a few simple cases in OpenFOAM using the official tutorials (https://cfd.direct/openfoam/user-guide/tutorials/), in case you're not familiar with running simulations with it - it'll be impossible for you to do some development if you don't understand how OF is actually used. 2. Find a built-in tutorial or materials on-line which will help you set up a case similar to what you want to work with eventually (rotating propeller, aerofoil, whatever) 3. Make sure your C++ is up to scratch by convincing yourself you can follow most of the contents here without wondering what's going on: http://www.cplusplus.com/doc/tutorial/ 4. Go through each of the tutorials I posted, open the source code for it, read the comments, then compile and run the test cases as explained in the README 5. ??? 6. Profit |
|
December 9, 2017, 06:34 |
|
#23 |
New Member
Join Date: Sep 2017
Posts: 4
Rep Power: 9 |
Hi Everyone,
First of all thank you very much, Artur, for the tutorial. It was very helpful! I would like to add few tips for the beginners. Apparently, when you go to the first tutorial folder Code:
/OFtutorial0_helloWorld Code:
wmake Code:
sudo mv /path/of/OpenFOAM /path/where/you/want add an 'alias' in your .bashrc. Which should look something like this Code:
alias ofpro='source $HOME/path/where/you/want/OpenFOAM/OpenFOAM-4.1/etc/bashrc WM_ARCH_OPTION=32 FOAMY_HEX_MESH=yes' Code:
ofpro Code:
sudo chown -R $USER:$USER /path/where/you/want/OpenFOAM Code:
OFtutorial4.C: In function ‘int main(int, char**)’: OFtutorial4.C:148:30: error: no match for ‘operator=’ (operand types are ‘const Internal {aka const Foam::DimensionedField<double, Foam::volMesh>}’ and ‘Foam::tmp<Foam::Field<double> >’) / (r/rFarCell+1e-12); ^ In file included from /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/DimensionedField.H:366:0, from /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvMesh.H:58, from /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/fvCFD.H:7, from OFtutorial4.C:26: /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/DimensionedField.C:424:6: note: candidate: void Foam::DimensionedField<Type, GeoMesh>::operator=(const Foam::DimensionedField<Type, GeoMesh>&) [with Type = double; GeoMesh = Foam::volMesh] void DimensionedField<Type, GeoMesh>::operator= ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/DimensionedField.C:424:6: note: no known conversion for argument 1 from ‘Foam::tmp<Foam::Field<double> >’ to ‘const Foam::DimensionedField<double, Foam::volMesh>&’ /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/DimensionedField.C:445:6: note: candidate: void Foam::DimensionedField<Type, GeoMesh>::operator=(const Foam::tmp<Foam::DimensionedField<Type, GeoMesh> >&) [with Type = double; GeoMesh = Foam::volMesh] void DimensionedField<Type, GeoMesh>::operator= ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/DimensionedField.C:445:6: note: no known conversion for argument 1 from ‘Foam::tmp<Foam::Field<double> >’ to ‘const Foam::tmp<Foam::DimensionedField<double, Foam::volMesh> >&’ /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/DimensionedField.C:469:6: note: candidate: void Foam::DimensionedField<Type, GeoMesh>::operator=(const Foam::dimensioned<Type>&) [with Type = double; GeoMesh = Foam::volMesh] void DimensionedField<Type, GeoMesh>::operator= ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/DimensionedField.C:469:6: note: no known conversion for argument 1 from ‘Foam::tmp<Foam::Field<double> >’ to ‘const Foam::dimensioned<double>&’ /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/wmake/rules/General/transform:8: recipe for target 'Make/linuxGccDPInt32Opt/OFtutorial4.o' failed make: *** [Make/linuxGccDPInt32Opt/OFtutorial4.o] Error 1 Code:
In file included from pipeCalc.C:26:0: pipeCalc.H:50:32: fatal error: functionObjectFile.H: No such file or directory #include "functionObjectFile.H" ^ compilation terminated. /home/nick/Drives/C/OpenFOAM/OpenFOAM-4.1/wmake/rules/General/transform:8: recipe for target 'Make/linuxGccDPInt32Opt/pipeCalc.o' failed make: *** [Make/linuxGccDPInt32Opt/pipeCalc.o] Error 1 Artur, could you please look in to these errors? Thanks! |
|
December 10, 2017, 08:49 |
|
#24 |
Senior Member
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20 |
Hi,
Thanks for the interest in the tutorials. Regarding the permissions issue, that's purely to do with something you're doing when saving the zip/cloning the repo. The tutorials themselves don't require anything specific about the folder permissions so you can safely change those not to require root access to work with them, avoiding the workarounds you suggested. As for the errors, they are clearly to do with the different OF version (4.1) compared to what the tutorials were developed for (3.0.1). The first one is strange to me as it suggests a conversion needs to take place between the tmpField created on the RHS and the "Internal" object this is to be assigned to. Honestly don't know much about it as it's the first time I'm seeing the Internal object. There's probably a new convention of some sort. Had a quick look at some random files where I expected this might be used but to no avail, would need a bit more time to figure out than I have on my hands at the moment. The second error is due to a change in code structure for version 4: https://cpp.openfoam.org/v4/dir_b139...a698f3c2b.html compared to versions 3: https://cpp.openfoam.org/v3/dir_b139...a698f3c2b.html Had a quick look at the new implementations of some of the functionObjects: https://github.com/OpenFOAM/OpenFOAM...nObjects/field And they appear to be quite different structure-wise to the old ones, making it difficult to say what the most suitable solution or workaround is without diving deeper into the issue. My suggestion would be that if you want to learn a bit about OF development from scratch, running the tutorials on the older version where they all work will still be a valuable experience, after which you can just move on to the new version. Alternatively, you can ignore the tutorials which don't work, or maybe just look through them without necessarily compiling and running them. I'm sorry but I can't really devote enough time to upgrade all of the code to a newer version at the moment, especially since 4.1 is no longer the newest release and so if I had the time I'd go for 5.0. Best of luck, Artur |
|
January 19, 2018, 17:46 |
|
#25 |
Senior Member
|
Dear Artur,
despite my 10th year with OpenFOAM... I just opened the very first tutorials from you, and it's WOOW!!! Back to basics) We invest a lot of time for the complex things, and forget to build our OpenFOAM knowledge step by step with key things of the OF application. Thank you for your effort! Cheers)
__________________
Best regards, Dr. Alexander VAKHRUSHEV Christian Doppler Laboratory for "Metallurgical Applications of Magnetohydrodynamics" Simulation and Modelling of Metallurgical Processes Department of Metallurgy University of Leoben http://smmp.unileoben.ac.at |
|
February 1, 2018, 16:32 |
|
#26 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Artur I have a question. You have some tutorials for the parallel stuff, right. I want to modify / add / change the moveConeTopoFvMesh library in order to enable parallel execution. I already modified the application for my needs but for a parallel execution it does not work. Is your tutorial a good starting point or would you suggest something for me? Thanks in advance. Tobi
__________________
Keep foaming, Tobias Holzmann |
|
February 2, 2018, 05:59 |
|
#27 |
New Member
Join Date: Oct 2017
Posts: 3
Rep Power: 9 |
First of all, I would like to thank Artur for sharing this material with the community. I am experiencing myself the gap existing between basic programming skills and the complex tasks required to develop my own code in OpenFOAM, thus any dedicated learning material is appreciated.
Anyway, while running tutorial 1, I got this error: Code:
OFtutorial1.C: In function ‘int main(int, char**)’: OFtutorial1.C:52:17: error: ‘class Foam::IOobject’ has no member named ‘headerOk’ if (!dictIO.headerOk()) ^ /opt/openfoam5/wmake/rules/General/transform:25: recipe for target 'Make/linux64GccDPInt32Opt/OFtutorial1.o' failed make: *** [Make/linux64GccDPInt32Opt/OFtutorial1.o] Error 1 Code:
bool headerOk(); Code:
template<class Type> bool typeHeaderOk(const bool checkType = true); When removing the line, the tutorial runs without further problems. Last edited by dkuesten; February 7, 2018 at 15:26. |
|
February 2, 2018, 06:08 |
|
#28 | |
Senior Member
|
Hi,
you are right, it is different in the OF v5. typeHeaderOk () is a new method of IOobject. You can use Doxygen for such things. Cheers, Alexander Quote:
__________________
Best regards, Dr. Alexander VAKHRUSHEV Christian Doppler Laboratory for "Metallurgical Applications of Magnetohydrodynamics" Simulation and Modelling of Metallurgical Processes Department of Metallurgy University of Leoben http://smmp.unileoben.ac.at |
||
February 2, 2018, 06:08 |
|
#29 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hi,
the function: Code:
headerOk() Code:
typeHeaderOk<Type> Code:
dict.typeHeaderOk<IOdictonary>(true) PS: As Alex said, you should be able to use the typeHeaderOk() function. My suggestion are based on my implementation which can be seen here OpenComfortLibrary However, I should recheck the stuff.
__________________
Keep foaming, Tobias Holzmann |
|
February 2, 2018, 06:10 |
|
#30 |
Senior Member
|
Short remark:
I personally 'hate' those headerOk() to typeHeaderOk() changes in OF. For which purpose are they? It is just getting away from OOP paradigm, no backward compatibility at all.
__________________
Best regards, Dr. Alexander VAKHRUSHEV Christian Doppler Laboratory for "Metallurgical Applications of Magnetohydrodynamics" Simulation and Modelling of Metallurgical Processes Department of Metallurgy University of Leoben http://smmp.unileoben.ac.at |
|
February 4, 2018, 07:17 |
|
#31 |
Senior Member
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20 |
Hi,
Thanks for the useful hints on OF 5.0 compatibility. It looks like I might have a bit of free time in the not-so-distant future and I'l hoping to spend it on updating the tutorials to work with the most recent official release and so any input regarding that is most welcome as it'll make it an easier task for me. And I do agree that many of these changes seem counterproductive - sure, there's probably a rationale behind them but maybe it'd be better in the grand scheme of things to leave minor bits like those unchanged in order to improve backward compatibility at the price of a bit more code to maintain. Tobi, I have to say I've no experience with dynamic mesh refinement aside from using it a couple of times to see what it can do. Hence, it's hard for me to gauge the difficulties involved in parallelising it. The general principles will be similar to what's in the tutorial though: the mesh for each subdomain will be stored in a separate process and any global information will need to be gathered/scattered. In general, though, as long as what happens on one processor doesn't affect it's neighbours (e.g. each one refines the grid according to local criteria) it may be enough to make sure that each individual processor carries out whatever it needs to do and avoiding too many complications on the communication side. The only major potential hole I see in the entire thing is varying numbers of hanging nodes on processor boundaries - these are effectively baffles with a matching number of faces. If one processor decides to refine that face on its side but the neighbour doesn't do it this things will go south fast. I'd imagine though that the *DyMFoam family of solvers would have introduced solutions that cover that, but I have never looked into it so cannot say for sure. I tried looking for the library you mention to get a closer look but I don't appear to be able to find it mentioned anywhere except for one of your older posts on this forum? All the best, Artur |
|
February 8, 2018, 12:28 |
|
#32 |
New Member
Join Date: Oct 2017
Posts: 3
Rep Power: 9 |
Hi there,
while running tutorial 4 as it is, I get these two errors: Code:
OFtutorial4.C:72:34: error: ‘blocking’ is not a member of ‘Foam::Pstream’ Pstream::scatter(meshVolume, Pstream::blocking); ^ OFtutorial4.C:155:20: error: no match for ‘operator=’ (operand types are ‘const Internal {aka const Foam::DimensionedField<double, Foam::volMesh>}’ and ‘Foam::tmp<Foam::Field<double> >’) p.internalField() = Foam::sin(2.*constant::mathematical::pi*f*runTime.time().value()) / (r/(rFarCell+1e-12)); Code:
OFtutorial4.C:72:63: error: no matching function for call to ‘Foam::Pstream::scatter(Foam::scalar&, Foam::UPstream::commsTypes)’ Pstream::scatter(meshVolume, Pstream::commsTypes::blocking); ^ In file included from /opt/openfoam5/src/OpenFOAM/lnInclude/parRun.H:35:0, from /opt/openfoam5/src/finiteVolume/lnInclude/fvCFD.H:4, from OFtutorial4.C:26: /opt/openfoam5/src/OpenFOAM/lnInclude/Pstream.H:117:25: note: candidate: template<class T> static void Foam::Pstream::scatter(const Foam::List<Foam::UPstream::commsStruct>&, T&, int, Foam::label) static void scatter ^ /opt/openfoam5/src/OpenFOAM/lnInclude/Pstream.H:117:25: note: template argument deduction/substitution failed: OFtutorial4.C:72:63: note: cannot convert ‘meshVolume’ (type ‘Foam::scalar {aka double}’) to type ‘const Foam::List<Foam::UPstream::commsStruct>&’ Pstream::scatter(meshVolume, Pstream::commsTypes::blocking); Thanks in advance |
|
February 9, 2018, 14:52 |
|
#33 |
Senior Member
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20 |
Hi,
Thanks for the comment about Pstream;:blocking, I'll make sure to change it when I start working on a new version. As for the second error, someone else posted about it before; I had a look at it then and it seems like the internalField() method is no longer supported. I haven't found an alternative yet so will need to do some more digging. Sorry I couldn't be of more use at this time, A |
|
February 19, 2018, 08:43 |
|
#34 |
New Member
Germilly Barreto
Join Date: Jul 2016
Location: Portugal
Posts: 25
Rep Power: 10 |
Hello Artur,
Thank you again for this tutorial. Do you know how to pass arguments to a main when running the application? The main is defined as: int main (int argc, char *argv[]) In my work, I need to run my application by passing arguments to the main. For example, if my application is called app1, when I am running it, I think I must do: $app1 my_argument where my_argument is a string to be used in my code. I think this is how we must pass argument to the main. But, doing that, it doesn't work, I get the following error --> FOAM FATAL ERROR: Wrong number of arguments, expected 0 found 1 Thank you Germilly Last edited by Germilly; February 19, 2018 at 09:47. |
|
February 19, 2018, 15:14 |
|
#35 |
Senior Member
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20 |
Hi,
An excellent question, thanks, I'll make sure to add it into any subsequent versions of the tutorials. A short answer is that you do it like so: Code:
// utility help argList::addNote ( "Calculates things.\n" "\n" "Input arguments:\n" "----------------\n" " someWord - does stuff\n" ); // prepare argument list argList::noParallel(); argList::validArgs.append("someArgument"); argList::validArgs.append("anotherArgument"); // prepare options argList::addOption ( "dict", "word", "Path to the dict file if different than './system/someDict'" ); argList::addBoolOption ( "pRelative", "Switches from A to B" ); // create argument list Foam::argList args(argc, argv); // <- normally defined inside setRootCase.H if (!args.checkRootCase()) { Foam::FatalError.exit(); } Code:
// read arguments const word someWord = args[1]; std::string anotherWord = args[2]; // read the options fileName dictPath("./system/defaultDict"); args.optionReadIfPresent("dict", dictPath); // conditional to the the option being passed if (args.optionFound("someOption")) { ... } // switch options const bool someConstBool = args.optionFound("someSwitch"); Happy foaming, Artur |
|
February 19, 2018, 15:59 |
|
#36 |
New Member
Germilly Barreto
Join Date: Jul 2016
Location: Portugal
Posts: 25
Rep Power: 10 |
Thank you so much for your answer!
You've helped me so much. It is now working perfectly. Ok, if I have, I will do it. Thank you Germilly |
|
February 24, 2018, 18:35 |
Upgraded the tutorials to OpenFOAM 5.x!
|
#37 |
Senior Member
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20 |
Hi All,
Just wanted to say I (finally) upgraded all of the tutorials to work with OpenFOAM 5.x. Sorry it took so long, but they're here now. I also added a new tutorial showing how to deal with parsing command line arguments and options, following up on some questions asked in this thread a while ago. If you find any mistakes or things to improve, please do let me know. Also, contributions from other authors more than welcome Happy foaming, Artur |
|
May 11, 2018, 16:59 |
Tutorial version compatible with OF3.0.1
|
#38 |
New Member
Patrick Reis
Join Date: Mar 2018
Posts: 4
Rep Power: 8 |
Hello Artur,
is there any chance to get the previous tutorial version for OF3.0.1? thanks in advance! Patrick |
|
May 14, 2018, 15:57 |
|
#39 |
Senior Member
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 20 |
Hi,
I posted the old OF301-compatibile version on GitHub as per your request. Unfortunately I don't have the manpower to maintain two or more parallel versions so the old tutorials are no longer under development. At present the differences are minimal, however. Hope these are useful. All the best A |
|
May 14, 2018, 16:28 |
Thanks
|
#40 |
New Member
Patrick Reis
Join Date: Mar 2018
Posts: 4
Rep Power: 8 |
Hi Artur,
Thank you very much! Your tutorials are very helpful anyways. I totally understand that you can't update several versions! Best wishes, Patrick |
|
Tags |
turorial files, tutorial |
|
|
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 |