Difference between revisions of "Sig Turbomachinery / Tutorials"

From OpenFOAMWiki
m
m (Added to category "Tutorials")
 
(19 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Here you can add turbomachinery tutorials to the standard distribution, or to the turbomachinery developments of OpenFOAM.
+
Here you can write detailed tutorials to accompany the tutorial cases of the OpenFOAM distribution, or user contributed tutorial cases. The source files for applications, libraries and cases should be located in the [http://sourceforge.net/projects/openfoam-extend OpenFOAM extensions repository].
  
Whenever possible, the tutorials should be included in the basic structure of the[http://www.openfoamwiki.net OpenFOAM Wiki], and here you can add links to those tutorials that are of interest to the turbomachinery field.
+
== Solvers ==
  
== Applications ==
+
=== How to implement a new application (OF-1.4.1)===
 +
 
 +
* The applications are located in the '''$WM_PROJECT_DIR/applications''' directory.
 +
* Copy an application that is similar to what you would like to do and modify it for your purposes. In this case we will make our own copy of the '''icoFoam''' solver and put it in our '''$WM_PROJECT_USER_DIR''' with the same file structure as in the OpenFOAM installation:
 +
<cpp>
 +
cd $WM_PROJECT_DIR
 +
cp -riuv --parents --backup applications/solvers/incompressible/icoFoam $WM_PROJECT_USER_DIR
 +
cd $WM_PROJECT_USER_DIR/applications/solvers/incompressible
 +
mv icoFoam myIcoFoam
 +
cd myIcoFoam
 +
wclean
 +
mv icoFoam.C myIcoFoam.C
 +
</cpp>
 +
* Modify '''Make/files''' to:
 +
<cpp>
 +
myIcoFoam.C
 +
EXE = $(FOAM_USER_APPBIN)/myIcoFoam
 +
</cpp>
 +
* Modify the source code of '''myIcoFoam'''.
 +
* Compile with '''wmake''' in the '''myIcoFoam''' directory. '''rehash''' if necessary.
 +
 
 +
--[[User:Hani|Hani]] 09:45, 10 Dec 2007 (CET)
  
 
== Utilities ==
 
== Utilities ==
 +
Like the standard distribution
 +
 +
== Libraries ==
 +
Things that can be linked against an application or used as plugins to existing applications
 +
 +
=== Cylindrical Coordinate Systems (OF-1.3)===
 +
 +
The example requires that you have a mesh and a velocity field U, and that you have defined inletPatchID. You also need to do #include "cylindricalCS.H". If your base code writes out the velocity field U you can then visualize the radial, tangential and axial coordinates as U at the inlet patch using for instance paraFoam.
 +
 +
<cpp>
 +
//Test of cylindricalCS
 +
 +
//Find the Cartesian positions at the patch
 +
const fvPatchVectorField& cartFaceCentres = mesh.Cf().boundaryField()[inletPatchID];
 +
 +
//Put the results in U at the patch so that you can visualize the result
 +
fvPatchVectorField& CCSin = U.boundaryField()[inletPatchID];
 +
 +
//Define your cylindrical coordinate system
 +
cylindricalCS ccs
 +
(
 +
"ccs",
 +
vector(0, 0, 0), //center point of ccs
 +
vector(0, 0, 1), //axis of ccs
 +
vector(1, 1, 0) //base axis for cylindrical angle
 +
);
 +
 +
//It doesn't seem to be possible to do the whole field at once, so
 +
//loop through all the patch faces and set the radial, tangential and
 +
//axial position
 +
 +
forAll(CCSin, facei)
 +
{
 +
CCSin[facei] = ccs.toLocal(cartFaceCentres[facei]);
 +
//Make sure that you have only positive angles and that the
 +
//angle is zero at the base axis:
 +
CCSin[facei][1] = CCSin[facei][1] + neg(CCSin[facei][1])*360;
 +
}
 +
 +
//You can also look at a single cylindrical component, here radial:
 +
Info << "ccs.toLocal(cartFaceCentres[0]).component(vector::X)" << endl;
 +
Info << ccs.toLocal(cartFaceCentres[0]).component(vector::X) << endl;
 +
</cpp>
 +
 +
--[[User:Hani|Hani]] 11:24, 7 Dec 2007 (CET)
 +
 +
=== How to implement a new turbulence model (OF-1.4.1)===
 +
 +
* The implementations of the turbulence models are located in '''src/turbulenceModel'''
 +
* Copy the source of the turbulence model that is most similar to what you want to do. In this case we will make our own copy of the kEpsilon turbulence model:
 +
<cpp>
 +
cd $WM_PROJECT_USER_DIR
 +
cp -r $WM_PROJECT_DIR/src/turbulenceModels/incompressible/kEpsilon ./mykEpsilon
 +
cd mykEpsilon
 +
wclean
 +
</cpp>
 +
we also need a Make/files:
 +
<cpp>
 +
mykEpsilon.C
 +
LIB = $(FOAM_USER_LIBBIN)/libmyTurbulenceModels
 +
</cpp>
 +
and a Make/options:
 +
<cpp>
 +
EXE_INC = \
 +
    -I$(LIB_SRC)/finiteVolume/lnInclude \
 +
    -I$(LIB_SRC)/meshTools/lnInclude \
 +
    -I$(LIB_SRC)/transportModels \
 +
    -I$(LIB_SRC)/turbulenceModels/incompressible/lnInclude
 +
LIB_LIBS =
 +
</cpp>
 +
 +
* We need to modify the file names and the class name of our new turbulence model:
 +
<cpp>
 +
mv kEpsilon.C mykEpsilon.C
 +
mv kEpsilon.H mykEpsilon.H
 +
</cpp>
 +
Then open''' mykEpsilon.C''' and '''mykEpsilon.H''' and change all occurances of '''kEpsilon''' to '''mykEpsilon''' so that we have a new class name.
 +
* Introduce a small modification so that we can see if we use our new model. Line 89 in mykEpsilon.C:
 +
<cpp>
 +
Info << "Defining my own kEpsilon model" << endl; }
 +
</cpp>
 +
* Compile using:
 +
<cpp>
 +
wmake libso
 +
</cpp>
 +
which will build a dynamic library in $(FOAM_USER_LIBBIN)/libmyTurbulenceModels.
 +
 +
====How to use your own turbulence model====
 +
 +
* Tell OpenFOAM to use your new library by adding a line to '''controlDict''':
 +
<cpp>
 +
libs ("libmyTurbulenceModels.so");
 +
</cpp>
 +
* You choose turbulence model in the '''constant/turbulenceProperties''' dictionary:
 +
<cpp>
 +
turbulenceModel mykEpsilon;
 +
</cpp>
 +
* You also have to set the needed coefficients for your turbulence model, which in this case will be the same as for the '''kEpsilon''' model:
 +
<cpp>
 +
mykEpsilonCoeffs
 +
{
 +
    Cmu            Cmu [0 0 0 0 0 0 0] 0.09;
 +
    C1              C1 [0 0 0 0 0 0 0] 1.44;
 +
    C2              C2 [0 0 0 0 0 0 0] 1.92;
 +
    alphaEps        alphaEps [0 0 0 0 0 0 0] 0.76923;
 +
}
 +
</cpp>
 +
* Now you can run '''simpleFoam''' with your new turbulence model. Try both '''kEpsilon''' and '''mykEpsilon''' and look for your write-statement in the log file.
 +
* Simply add appropriate source terms to implement a variant of kEpsilon.
 +
 +
====A note on new turbulence models====
 +
 +
* The turbulence models in OpenFOAM are sub-classes to the virtual class '''turbulenceModel'''.
 +
* You are only allowed to use the same member function definitions as in the '''turbulenceModel''' class. If you need other member functions you will have to add those to the '''turbulenceModel''' class, which requires that you copy and mofify all of '''src/turbulenceModel'''.
 +
* It might be a good idea to use the same file structure as in OpenFOAM also for your own implementations, but you don't have to. In this case we didn't.
 +
 +
--[[User:Hani|Hani]] 11:24, 7 Dec 2007 (CET)
 +
 +
===How to implement a new boundary condition (OF-1.4.1)===
 +
 +
* The implementations for the boundary conditions are located in '''src/finiteVolume/fields/fvPatchFields/'''
 +
* We will now try adding parabolicVelocityFvPatchVectorField to the simpleFoam solver from OpenFOAM-1.4.1-dev in sourceForge to OpenFOAM-1.4.1, and use it for the pitzDaily tutorial.
 +
 +
====Compile a boundary condition as a new dynamic library====
 +
 +
* Find an existing boundary condition that does almost what you want and copy it to somewhere outside the OpenFOAM installation:
 +
<cpp>
 +
mkdir parabolicVelocity
 +
cd parabolicVelocity
 +
wget http://svn.code.sf.net/p/openfoam-extend/svn/trunk/Core/OpenFOAM-1.4.1-dev/src/finiteVolume/fields/fvPatchFields/derived/parabolicVelocity/parabolicVelocityFvPatchVectorField.C
 +
wget http://svn.code.sf.net/p/openfoam-extend/svn/trunk/Core/OpenFOAM-1.4.1-dev/src/finiteVolume/fields/fvPatchFields/derived/parabolicVelocity/parabolicVelocityFvPatchVectorField.H
 +
</cpp>
 +
* We need a Make/files file:
 +
<cpp>
 +
parabolicVelocityFvPatchVectorField.C
 +
LIB = $(FOAM_USER_LIBBIN)/libmyBCs
 +
</cpp>
 +
and a Make/options file:
 +
<cpp>
 +
EXE_INC = \
 +
    -I$(LIB_SRC)/finiteVolume/lnInclude
 +
EXE_LIBS =
 +
</cpp>
 +
* Compile the dynamic library:
 +
<cpp>
 +
wmake libso
 +
</cpp>
 +
* This will generate the new library in $(FOAM_USER_LIBBIN)/libmyBCs
 +
 +
====Use your boundary condition from the dynamic library====
 +
 +
* The boundary condition will not be recognized by any of the original OpenFOAM solvers unless we tell OpenFOAM that the library exists. In OpenFOAM-1.4.1 this is done by adding a line in the '''system/controlDict''' file:
 +
<cpp>
 +
libs ("libmyBCs.so");
 +
</cpp>
 +
i.e. the library must be added for each case that will use it, but no re-compilation is needed for any solver. '''libmyBCs.so''' is found using the '''LD_LIBRARY_PATH''' environment variable, and if you followed the instructions on how to set up OpenFOAM and compile the boundary condition this should work automatically.
 +
* You can now set up the pitzDaily tutorial by modifying the entry for the '''inlet''' boundary condition in '''0/U''' to:
 +
<cpp>
 +
        type            parabolicVelocity;
 +
        n              (1 0 0);
 +
        y              (0 1 0);
 +
        maxValue        1;
 +
        value          (0 0 0); // Dummy for paraFoam, which will NOT show a correct profile at time 0.
 +
</cpp>
 +
* The contents of this entry must be in accordance with the constructor in the '''parabolicVelocityFvPatchVectorField''' class. '''n''' is the direction of the flow, '''y''' is the coordinate direction of the profile, and maxvalue is the centerline velocity.
 +
* Run it using the original '''simpleFoam''' solver. Note that we never re-compiled the original '''simpleFoam''' solver, and if you do '''ldd `which simpleFoam`''' your new library will NOT show up since it is linked at run-time (using dlopen).
 +
* You now have a boundary condition that you can modify without destroying anything else in OpenFOAM.
 +
 +
--[[User:Hani|Hani]] 11:24, 7 Dec 2007 (CET)
 +
 +
== Other ==
 +
Things that don't fit any of the above categories: shell scripts that help to use OpenFOAM, language bindings, plugins to third party software that enables it to interact with OpenFOAM ...
 +
 +
 +
Back to [[Sig Turbomachinery]]
 +
 +
[[Category:Tutorials]]

Latest revision as of 15:01, 4 January 2015

Here you can write detailed tutorials to accompany the tutorial cases of the OpenFOAM distribution, or user contributed tutorial cases. The source files for applications, libraries and cases should be located in the OpenFOAM extensions repository.

1 Solvers

1.1 How to implement a new application (OF-1.4.1)

  • The applications are located in the $WM_PROJECT_DIR/applications directory.
  • Copy an application that is similar to what you would like to do and modify it for your purposes. In this case we will make our own copy of the icoFoam solver and put it in our $WM_PROJECT_USER_DIR with the same file structure as in the OpenFOAM installation:
 
cd $WM_PROJECT_DIR
cp -riuv --parents --backup applications/solvers/incompressible/icoFoam $WM_PROJECT_USER_DIR
cd $WM_PROJECT_USER_DIR/applications/solvers/incompressible
mv icoFoam myIcoFoam
cd myIcoFoam
wclean
mv icoFoam.C myIcoFoam.C
  • Modify Make/files to:
 
myIcoFoam.C
EXE = $(FOAM_USER_APPBIN)/myIcoFoam
  • Modify the source code of myIcoFoam.
  • Compile with wmake in the myIcoFoam directory. rehash if necessary.

--Hani 09:45, 10 Dec 2007 (CET)

2 Utilities

Like the standard distribution

3 Libraries

Things that can be linked against an application or used as plugins to existing applications

3.1 Cylindrical Coordinate Systems (OF-1.3)

The example requires that you have a mesh and a velocity field U, and that you have defined inletPatchID. You also need to do #include "cylindricalCS.H". If your base code writes out the velocity field U you can then visualize the radial, tangential and axial coordinates as U at the inlet patch using for instance paraFoam.

 
//Test of cylindricalCS 
 
//Find the Cartesian positions at the patch
const fvPatchVectorField& cartFaceCentres = mesh.Cf().boundaryField()[inletPatchID]; 
 
//Put the results in U at the patch so that you can visualize the result
fvPatchVectorField& CCSin = U.boundaryField()[inletPatchID]; 
 
//Define your cylindrical coordinate system
cylindricalCS ccs
(
"ccs",
vector(0, 0, 0), //center point of ccs
vector(0, 0, 1), //axis of ccs
vector(1, 1, 0) //base axis for cylindrical angle
); 
 
//It doesn't seem to be possible to do the whole field at once, so
//loop through all the patch faces and set the radial, tangential and
//axial position
 
forAll(CCSin, facei)
{
CCSin[facei] = ccs.toLocal(cartFaceCentres[facei]);
//Make sure that you have only positive angles and that the
//angle is zero at the base axis:
CCSin[facei][1] = CCSin[facei][1] + neg(CCSin[facei][1])*360;
} 
 
//You can also look at a single cylindrical component, here radial: 
Info << "ccs.toLocal(cartFaceCentres[0]).component(vector::X)" << endl; 
Info << ccs.toLocal(cartFaceCentres[0]).component(vector::X) << endl;

--Hani 11:24, 7 Dec 2007 (CET)

3.2 How to implement a new turbulence model (OF-1.4.1)

  • The implementations of the turbulence models are located in src/turbulenceModel
  • Copy the source of the turbulence model that is most similar to what you want to do. In this case we will make our own copy of the kEpsilon turbulence model:
 
cd $WM_PROJECT_USER_DIR
cp -r $WM_PROJECT_DIR/src/turbulenceModels/incompressible/kEpsilon ./mykEpsilon
cd mykEpsilon
wclean

we also need a Make/files:

 
mykEpsilon.C
LIB = $(FOAM_USER_LIBBIN)/libmyTurbulenceModels

and a Make/options:

 
EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I$(LIB_SRC)/transportModels \
    -I$(LIB_SRC)/turbulenceModels/incompressible/lnInclude
LIB_LIBS =
  • We need to modify the file names and the class name of our new turbulence model:
 
mv kEpsilon.C mykEpsilon.C
mv kEpsilon.H mykEpsilon.H

Then open mykEpsilon.C and mykEpsilon.H and change all occurances of kEpsilon to mykEpsilon so that we have a new class name.

  • Introduce a small modification so that we can see if we use our new model. Line 89 in mykEpsilon.C:
 
Info << "Defining my own kEpsilon model" << endl; }
  • Compile using:
 
wmake libso

which will build a dynamic library in $(FOAM_USER_LIBBIN)/libmyTurbulenceModels.

3.2.1 How to use your own turbulence model

  • Tell OpenFOAM to use your new library by adding a line to controlDict:
 
libs ("libmyTurbulenceModels.so");
  • You choose turbulence model in the constant/turbulenceProperties dictionary:
 
turbulenceModel mykEpsilon;
  • You also have to set the needed coefficients for your turbulence model, which in this case will be the same as for the kEpsilon model:
 
mykEpsilonCoeffs
{
    Cmu             Cmu [0 0 0 0 0 0 0] 0.09;
    C1              C1 [0 0 0 0 0 0 0] 1.44;
    C2              C2 [0 0 0 0 0 0 0] 1.92;
    alphaEps        alphaEps [0 0 0 0 0 0 0] 0.76923;
}
  • Now you can run simpleFoam with your new turbulence model. Try both kEpsilon and mykEpsilon and look for your write-statement in the log file.
  • Simply add appropriate source terms to implement a variant of kEpsilon.

3.2.2 A note on new turbulence models

  • The turbulence models in OpenFOAM are sub-classes to the virtual class turbulenceModel.
  • You are only allowed to use the same member function definitions as in the turbulenceModel class. If you need other member functions you will have to add those to the turbulenceModel class, which requires that you copy and mofify all of src/turbulenceModel.
  • It might be a good idea to use the same file structure as in OpenFOAM also for your own implementations, but you don't have to. In this case we didn't.

--Hani 11:24, 7 Dec 2007 (CET)

3.3 How to implement a new boundary condition (OF-1.4.1)

  • The implementations for the boundary conditions are located in src/finiteVolume/fields/fvPatchFields/
  • We will now try adding parabolicVelocityFvPatchVectorField to the simpleFoam solver from OpenFOAM-1.4.1-dev in sourceForge to OpenFOAM-1.4.1, and use it for the pitzDaily tutorial.

3.3.1 Compile a boundary condition as a new dynamic library

  • Find an existing boundary condition that does almost what you want and copy it to somewhere outside the OpenFOAM installation:
 
mkdir parabolicVelocity
cd parabolicVelocity
wget http://svn.code.sf.net/p/openfoam-extend/svn/trunk/Core/OpenFOAM-1.4.1-dev/src/finiteVolume/fields/fvPatchFields/derived/parabolicVelocity/parabolicVelocityFvPatchVectorField.C
wget http://svn.code.sf.net/p/openfoam-extend/svn/trunk/Core/OpenFOAM-1.4.1-dev/src/finiteVolume/fields/fvPatchFields/derived/parabolicVelocity/parabolicVelocityFvPatchVectorField.H
  • We need a Make/files file:
 
parabolicVelocityFvPatchVectorField.C
LIB = $(FOAM_USER_LIBBIN)/libmyBCs

and a Make/options file:

 
EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude
EXE_LIBS =
  • Compile the dynamic library:
 
wmake libso
  • This will generate the new library in $(FOAM_USER_LIBBIN)/libmyBCs

3.3.2 Use your boundary condition from the dynamic library

  • The boundary condition will not be recognized by any of the original OpenFOAM solvers unless we tell OpenFOAM that the library exists. In OpenFOAM-1.4.1 this is done by adding a line in the system/controlDict file:
 
libs ("libmyBCs.so");

i.e. the library must be added for each case that will use it, but no re-compilation is needed for any solver. libmyBCs.so is found using the LD_LIBRARY_PATH environment variable, and if you followed the instructions on how to set up OpenFOAM and compile the boundary condition this should work automatically.

  • You can now set up the pitzDaily tutorial by modifying the entry for the inlet boundary condition in 0/U to:
 
        type            parabolicVelocity;
        n               (1 0 0);
        y               (0 1 0);
        maxValue        1;
        value           (0 0 0); // Dummy for paraFoam, which will NOT show a correct profile at time 0.
  • The contents of this entry must be in accordance with the constructor in the parabolicVelocityFvPatchVectorField class. n is the direction of the flow, y is the coordinate direction of the profile, and maxvalue is the centerline velocity.
  • Run it using the original simpleFoam solver. Note that we never re-compiled the original simpleFoam solver, and if you do ldd `which simpleFoam` your new library will NOT show up since it is linked at run-time (using dlopen).
  • You now have a boundary condition that you can modify without destroying anything else in OpenFOAM.

--Hani 11:24, 7 Dec 2007 (CET)

4 Other

Things that don't fit any of the above categories: shell scripts that help to use OpenFOAM, language bindings, plugins to third party software that enables it to interact with OpenFOAM ...


Back to Sig Turbomachinery