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 Tree192Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 19, 2021, 10:51
Default post processing
  #61
New Member
 
Join Date: Feb 2016
Posts: 13
Rep Power: 10
fanny is on a distinguished road
Hi Artur. Thank you very much for that great tutorial. It helps very much !


I have two questions concerning the postprocessing functions (tutorial 09).



- Why we have a 0 directory inside the directory postProcessing ?



- How can I use the postProcess utility ? When specified without additional arguments, the postProcess utility should execute all function objects defined in the system/controlDict file for all time directories but I have the error message

--> FOAM FATAL ERROR:
request for volVectorField U from objectRegistry region0 failed
available objects of type volVectorField are
0()

From function const Type& Foam:bjectRegistry::lookupObject(const Foam::word&) const [with Type = Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>]
in file /home/ubuntu/OpenFOAM/OpenFOAM-7/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 193.

FOAM aborting




Thank you !
Fanny
fanny is offline   Reply With Quote

Old   February 19, 2021, 11:23
Default
  #62
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 19
Artur will become famous soon enough
Hi,


The 0 folder follows OF convention whereby subsequent restarts or calls write data to a specific time (in this case iteration) directory. The utility doesn't even specify this explicitly, it gets done automatically. The only thing done here is appending the name of the object to the existing file names inside
Code:
Foam::wordList Foam::functionObjects::pipeCalc::createFileNames
.


I am not sure where the second error is coming from. The main point here is that the utility has been written to be executed in parallel with the solver and not after this has been run. Hence, it works fine within simpleFoam but apparently some fields do not get read properly when it is run with postProcess. My hunch is that the velocity field would need to be explicitly requested somehow, but it's beyond the scope of the tutorial as I intended it. If you do figure it out, please do share


Kind regards,


A
Artur is offline   Reply With Quote

Old   February 19, 2021, 11:31
Default
  #63
New Member
 
Join Date: Feb 2016
Posts: 13
Rep Power: 10
fanny is on a distinguished road
Thank you so much Artur for this quick and clear answer
fanny is offline   Reply With Quote

Old   June 6, 2021, 16:49
Default
  #64
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 19
Artur will become famous soon enough
Hello everyone,


I recently completed a tutorial on discretisation schemes after a request from the community. Hope you'll find it useful!


Happy foaming,


A
cellCentreValues.jpg tutorial15.jpg
Artur is offline   Reply With Quote

Old   July 22, 2021, 11:29
Default
  #65
Member
 
JunaidAhmad's Avatar
 
Junaid Ahmad Khan
Join Date: Mar 2010
Location: Islamabad
Posts: 43
Rep Power: 16
JunaidAhmad is on a distinguished road
I have a question how can I explore member function of "volScalarField"
Code:
volScalarField T
(
    IOobject(
        "T",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE),
    mesh
);


e.g.
the output of
Code:
Info<< T << nl;

is
Code:
dimensions      [0 0 0 1 0 0 0];


internalField   uniform 0;

boundaryField
{
    left_sides
    {
        type            zeroGradient;
    }
    right_sides
    {
        type            fixedValue;
        value           uniform 1;
    }
    empty
    {
        type            empty;
    }
}

the output of
Code:
Info<< T.dimensions()    << endl;

is
Code:
[0 0 0 1 0 0 0]

and output of
Code:
Info<<T.boundaryField()  << endl;

is
Code:
3
(
    type            zeroGradient;

    type            fixedValue;
    value           uniform 1;

    type            empty;

)


output of
Code:
forAll(T.internalField(), cellI)
{
    Info<<"T.internalField()["<<cellI<<"]: "<<T.internalField()[cellI]<<nl ;
    
}

is
Code:
T.internalField()[0]: 0
T.internalField()[1]: 0
Now question is how can i explor boundaryField name, or all other member functions from doxygen or any other user guide.
JunaidAhmad is offline   Reply With Quote

Old   July 22, 2021, 14:53
Default
  #66
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 19
Artur will become famous soon enough
Hi,


I'm not really sure what you're asking - do you mean printing text representation of various objects / output of functions? If so, then there isn't much more to say than what you've just demonstrated, beyond that not every object has the relevant formatting functions included in its definition. If you want to know more about input/output in general, tutorial 01 is the place to look.


As this is a very generic question not related to the tutorials, please consider making a separate thread for it.


Happy foaming,


A
Artur is offline   Reply With Quote

Old   July 22, 2021, 16:02
Default
  #67
Member
 
JunaidAhmad's Avatar
 
Junaid Ahmad Khan
Join Date: Mar 2010
Location: Islamabad
Posts: 43
Rep Power: 16
JunaidAhmad is on a distinguished road
Thanks for your response, I want to know a systematic way to explore attributes and functions of classes in C++ or openfoam. Like in python there is a dir() function. If there isn't then we need one. As I just started foam so was wondering if some senior can develop one.
JunaidAhmad is offline   Reply With Quote

Old   July 22, 2021, 16:10
Default
  #68
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 19
Artur will become famous soon enough
Hmm, that seems like a pretty involved C++ question rather than an OpenFOAM-specific one, to be honest. I have no answer to it myself, I'm afraid. Personally, I tend to rely on the auto-generated dependency graphs like the one at the bottom of this page whenever I get stuck:
https://cpp.openfoam.org/v9/classFoa...ionCoeffs.html
Artur is offline   Reply With Quote

Old   July 23, 2021, 01:20
Default
  #69
Member
 
JunaidAhmad's Avatar
 
Junaid Ahmad Khan
Join Date: Mar 2010
Location: Islamabad
Posts: 43
Rep Power: 16
JunaidAhmad is on a distinguished road
Thanks, can u also share a similar link for volScalarField. And a pdf for doxygen.
JunaidAhmad is offline   Reply With Quote

Old   July 23, 2021, 06:17
Default
  #70
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 19
Artur will become famous soon enough
There's a list of all the objects on the left and a search button in the top right corner
Artur is offline   Reply With Quote

Old   July 23, 2021, 06:45
Default
  #71
Member
 
JunaidAhmad's Avatar
 
Junaid Ahmad Khan
Join Date: Mar 2010
Location: Islamabad
Posts: 43
Rep Power: 16
JunaidAhmad is on a distinguished road
I figured that out , but thanks to your above link, I found it. Due to some reason my computer got stuck then I searched the volscalarfeild previously in that top right corner. Thanks for all your guidance I learned a lot.
JunaidAhmad is offline   Reply With Quote

Old   July 24, 2021, 12:01
Default OFtutorial7 Error
  #72
New Member
 
Kumar Pushpak
Join Date: Apr 2019
Posts: 9
Rep Power: 7
khool_chelsea is on a distinguished road
I am using OpenFOAM -v1906. I am getting an error in compiling the solver.
Code:
Make/linux64GccDPInt32Opt/OFtutorial7.o: In function `main':
OFtutorial7.C:(.text.startup+0xaeb): undefined reference to `computeR(Foam::fvMesh const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>, Foam::dimensioned<Foam::Vector<double> >)'
collect2: error: ld returned 1 exit status
/home/administrator/OpenFOAM/OpenFOAM-v1906/wmake/makefiles/general:140: recipe for target '/home/administrator/OpenFOAM/administrator-v1906/platforms/linux64GccDPInt32Opt/bin/ofTutorial7' failed
The library was compiled without any issue so the solver must have access to the function computeR(). I am attaching the Make(files and options) for solver.
For Solver,
Make/file
Code:
OFtutorial7.C

EXE = $(FOAM_USER_APPBIN)/ofTutorial7
Make/options
Code:
EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -IcustomLibrary

EXE_LIBS = \
    -lfiniteVolume \
    -lmeshTools \
     -L$(FOAM_USER_LIBBIN) -lcustomLibrary
For Library,

Make/file
Code:
customLibrary.C

LIB = $(FOAM_USER_LIBBIN)/libcustomLibrary
Make/options
Code:
EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude

LIB_LIBS = \
    -lfiniteVolume \
    -lmeshTools
Any ideas where i might be wrong?
khool_chelsea is offline   Reply With Quote

Old   July 24, 2021, 13:04
Default
  #73
New Member
 
Kumar Pushpak
Join Date: Apr 2019
Posts: 9
Rep Power: 7
khool_chelsea is on a distinguished road
Issue resolved. there was a syntax error in the definition of computeR.
khool_chelsea is offline   Reply With Quote

Old   July 25, 2021, 09:07
Default
  #74
Member
 
JunaidAhmad's Avatar
 
Junaid Ahmad Khan
Join Date: Mar 2010
Location: Islamabad
Posts: 43
Rep Power: 16
JunaidAhmad is on a distinguished road
Quote:
Originally Posted by Artur View Post
There's a list of all the objects on the left and a search button in the top right corner
Dear Artur,
I finally got the hang of this top right corner button. Thanks for you guidance again.
I thought to let the new users like me to know how to go about to find there way using extended guide. Below is the problem statement and its solution.



Problem: I had a volScalarField T and I want to find the dx or delta x of first node in mesh from object T.
Here is the procedure.

Code:
volScalarField T(
    IOobject(
        "T",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE),
    mesh);




I started by searching volScalarField in extended guide the search gave me



This shows that volScalarField is an object of GeometricField.
I clicked on GeometricField it lead me to

Code:
GeometricField< Type, PatchField, GeoMesh > Class Template Reference
In GeometricField I found internalField() function
Code:
const Internal & internalField () const
this return internal object which is
Code:
typedef DimensionedField<Type, GeoMesh> Internal
this give us DimensionedField where I found mesh() function
Code:
const Mesh & mesh () const
this return a Mesh object
Code:
typedef GeoMesh::Mesh Mesh
Till this point it was straight forward and here comes the twist. I search Mesh in search bar for typedefs of extended guide and found
In one of basic programming notes I read that Mesh reside in fvMesh so I go to fvMesh and found a function
Code:
tmp< surfaceVectorField > delta () const
I clicked on surfaceVectorField which takes me to
this show that delta() is tmp<surfaceVectorField> type template which is a GeometricField temporary object. in
Code:
tmp< T > Class Template Reference
there I found
Code:
T * ptr () const
pointer of GeometricField type. which contains internalField function which we can access using internalField()[0].x()
Using all the knowledge above we can print the dx by the following expression.


Code:
Info << T.internalField().mesh().delta().ptr()->internalField()[0].x()<< nl;



PS: Dear Seniors if you can suggest a better way of doing this please guide.
JunaidAhmad is offline   Reply With Quote

Old   August 5, 2021, 17:32
Default
  #75
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 19
Artur will become famous soon enough
Dear All,


I have updated the tutorials to work with OpenFOAM 9. The changes required were pretty minimal - the only part that was significantly affected was tutorial 12 which used to use the old fvOption infrastructure that has now become fvModels.


I have also added a new tutorial originally contributed by Ramkumar that demonstrates how an existing flow solution can be used in order to perform very simple Lagrangian particle tracking. This particular topic is quite dear to me (which you'll know if you've read my thesis ), and I'm hoping I can build on this tutorial in the future.


As always, happy foaming!


Artur
lourencosm, tobiasS and wo315 like this.
Artur is offline   Reply With Quote

Old   September 28, 2021, 05:51
Default Tutorial9 with OF2012
  #76
New Member
 
irengclenk
Join Date: Feb 2021
Posts: 5
Rep Power: 5
irengclenk is on a distinguished road
Hi Arthur,

First of all, thank you so much for the exercise, very helpful.
I am a beginner and use your exercises to learn Openfoam programming

I'm currently doing postprocessing exercise (Tutorial 9) using OF2012.
However I got this error:

Code:
pipeCalc.C:71:31: error: no matching function for call to \u2018Foam::functionObjects::pipeCalc::file(const label&)\u2019
             writeHeader(file(i), "Flow rate through face zone");
                               ^
In file included from /home/u0142217/OpenFOAM/OpenFOAM-v2012/src/OpenFOAM/lnInclude/logFiles.H:46:0,
                 from pipeCalc.H:43,
                 from pipeCalc.C:26:
/home/u0142217/OpenFOAM/OpenFOAM-v2012/src/OpenFOAM/lnInclude/writeFile.H:206:27: note: candidate: virtual Foam::OFstream& Foam::functionObjects::writeFile::file()
         virtual OFstream& file();
I noticed that there is no writeHeader function defined in the pipeCalc.H, then I gave a try to also include writeFile.H in it where we have writeHeader definition, but that doesnt work either. Or is it related to compatibility issue where your code only work for openfoam.org version?

Thanks!
irengclenk is offline   Reply With Quote

Old   October 7, 2021, 11:03
Default
  #77
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 19
Artur will become famous soon enough
Hi,


I haven't tried the code with other versions of OpenFOAM, but indeed this seems like something that might be related to compatibility issues. Worth having a quick go at installing the recommended version to double check, of course, but this tutorials has been around for a while so it's unlikely to not function properly.


BEst wishes,


A
Artur is offline   Reply With Quote

Old   October 29, 2021, 04:23
Default Some experience using the tutorial
  #78
New Member
 
Bill
Join Date: Jun 2017
Posts: 11
Rep Power: 8
Bill_Yang is on a distinguished road
Dear all,

I am a new user of openfoam. This is a very good tutorial for learning openfoam programming. I am writing this reply just to show the experience or issue I have when running the tutorial.

1) openfoam and ubuntu
I am using openfoam 8 and windows 10 based ubuntu 20.

2)
(tutorial 00, helloworld)
I type in the following command to run the case at the top-level directory:
: wmake
: ofTutorial0

The case is running OK.

3)
(tutorial 01, inputoutput)
I type in the following command to run the case at the top-level directory:
: wmake
: ofTutorial1

There is an error. It reminds me there is no mesh files found.
This is how I solve this error (may be a stupid way):
: So, I enter the testCase directory, then type: blockMesh
: Then I go back to the top-level directory and copy all the case files into the top-level directory.
: run 'ofTutorial 1' again.
The tutorial is running OK.

I think there should be a better way to do this. If anyone else can share this would be very useful.
A sgguestion from Artur and it works for me:
Code:
./Allwmake
cd testCase
./Allrun
For my case, I need to do this following
Code:
chmod +x Allwmake
./Allwmake
cd testCase
chmod +x Allrun
./Allrun
4)
(tutorial 02, command line argument and options)
This following codes work for me:
Code:
chmod +x Allwmake
./Allwmake
cd testCase
chmod +x Allrun
./Allrun
You can also try to input any other optional command lines according to the tutorial.
5)
(tutorial 03, understand the mesh)
The above code works.
Note: This tutorial presents how to get access the mesh info using the openfoam in-built class functions. It is very useful.

6)
(tutorial 04, basic field operations)
The above code works.
According to the suggestions in the tutorial, we could try to replace the for loop in the tutorial by first commenting the for loop command lines and then adding the following code:
Code:
/*replacement of the for loop*/
volScalarField r2 = (mag(dimensionedVector("x0", dimLength, originVector) - mesh.C()) / rFarCell);
volScalarField rR2 = (1. / (r2 + dimensionedScalar("tmp1", dimLength, 1e-12)));
scalar f2 (1.);
p = Foam::sin(2. * Foam::constant::mathematical::pi * f2 * runTime.time().value()) * rR2 * dimensionedScalar("tmp2", dimVolume, 1.)
			/ (dimensionedScalar("tmp3", dimTime, 1.) * dimensionedScalar("tmp3", dimTime, 1.));
7)
(tutorial 05, basic parallel computing)
Note: if you need to view the computational results, please remove the following code in Allrun:

Code:
rm -r processor* 2>/dev/null
I only have one issue with this tutorial. After running. I received the following error:
Code:
3 more processes have sent help message help-btl-vader.txt / cma-permission-denied
Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages
I will keep updating this.

Last edited by Bill_Yang; November 2, 2021 at 13:50. Reason: Update
Bill_Yang is offline   Reply With Quote

Old   October 29, 2021, 04:36
Default
  #79
Senior Member
 
Artur's Avatar
 
Artur
Join Date: May 2013
Location: Southampton, UK
Posts: 372
Rep Power: 19
Artur will become famous soon enough
Hi Bill,


Indeed, there is an easier way You can do everything by doing

Code:
./Allwmake
cd testCase
./Allrun
You may then check contents of each script to see precisely what is being done. In case of tutorial 1, that's just what you've figured out yourself:


Code:
blockMesh > log.blockMesh
ofTutorial1
Best wishes,


Artur
Artur is offline   Reply With Quote

Old   October 29, 2021, 04:50
Default
  #80
New Member
 
Bill
Join Date: Jun 2017
Posts: 11
Rep Power: 8
Bill_Yang is on a distinguished road
Quote:
Originally Posted by Artur View Post
Hi Bill,


Indeed, there is an easier way You can do everything by doing

Code:
./Allwmake
cd testCase
./Allrun
You may then check contents of each script to see precisely what is being done. In case of tutorial 1, that's just what you've figured out yourself:


Code:
blockMesh > log.blockMesh
ofTutorial1
Best wishes,


Artur
Thanks a lot Artur. That's very helpful. I just tried the commands and they work.
Bill_Yang 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 05:29
OpenFOAM 4.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 2 October 6, 2017 05:40
OpenFOAM Training: Programming CFD Course 12-13 and 19-20 April 2016 cfd.direct OpenFOAM Announcements from Other Sources 0 January 14, 2016 10:19
OpenFOAM v3.0.1 Training, London, Houston, Berlin, Jan-Mar 2016 cfd.direct OpenFOAM Announcements from Other Sources 0 January 5, 2016 03:18
Openfoam Programming from scratch shovan OpenFOAM Programming & Development 1 July 9, 2015 12:38


All times are GMT -4. The time now is 22:09.