Programming in OpenFOAM

Laboratory tasks I.
Programming
1
Balogh
Miklós
Modify icoFoam with additional temperature field
(Reference)
•
•
•
•
Create the application directory in your OF home dir
Copy icoFoam solver to your application directory
Modify the file names and Make properties
Add the required modifications to the files
Listing 1: make a copy from original solver
1
2
3
4
5
6
cd $FOAM_SOLVERS / incompressible
mkdir -p $ W M _ P R O J E C T _ U S E R _ D I R / applications / solvers
cp -r icoFoam $ W M _ P R O J E C T _ U S E R _ D I R / applications / solvers / icoFoamT
cd $ W M _ P R O J E C T _ U S E R _ D I R / applications / solvers / icoFoamT
mv icoFoam . C icoFoamT . C
rm icoFoam . dep
Listing 2: modify Make/files
1 icoFoamT . C
2
3 EXE = $ ( FOAM_USER_APPBIN )/ icoFoamT
Balogh Miklós
Programming
March 24, 2014
1 / 11
Laboratory tasks II.
Programming
Balogh
Miklós
Listing 3: test compilation
1 wclean
2 wmake
3 ls $ FOA M_U SE R_A PPB IN
Listing 4: add thermal diffusion coeff. to createFields.H
1
2
3
4
5
6
7
8
9
10
11
12 ...
...
di men sio ned Sca la r nu
(
t r a n s p o rt P r o p e r t i e s . lookup ( " nu " )
);
// Add DT thermal diffusion
di men sio ned Sca la r DT
(
t r a n s p o rt P r o p e r t i e s . lookup ( " DT " )
);
// end modifications
Balogh Miklós
Programming
March 24, 2014
2 / 11
Laboratory tasks III.
Programming
Balogh
Miklós
Listing 5: add temperature field to createFields.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #
19 ...
...
// Add this temperature declaration
Info < < " Reading field T \ n " << endl ;
volScalarField T
(
IOobject
(
"T",
runTime . timeName () ,
mesh ,
IOobject :: MUST_READ ,
IOobject :: AUTO_WRITE
),
mesh
);
// end modifications
include " createPhi . H "
Balogh Miklós
Programming
March 24, 2014
3 / 11
Laboratory tasks III.
Programming
Balogh
Miklós
Listing 6: add temperature eq. to icoFoamT.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Balogh Miklós
...
U = HbyA - rAU * fvc :: grad ( p );
U . c o r r e c t B o u n d a r y C o n d i t i o n s ();
}
// Add temperature eqs .
fvScalarMatrix TEqn
(
fvm :: ddt ( T )
+ fvm :: div ( phi , T )
- fvm :: laplacian ( DT , T )
);
TEqn . solve ();
// end of modifications
runTime . write ();
...
Programming
March 24, 2014
4 / 11
Laboratory tasks IV.
Programming
2
Balogh
Miklós
Perform a simulation with the new solver
• Create a copy from the original cavity case (new name:
cavityT)
• Add thermal diffusion coeff. to transportProperties
• Copy 0p field as 0T, and modify the required parts
Listing 7: make a copy from original solver
1
2
3
4
cd
cp
cd
cp
1
2
3
4
...
// Thermal diffusion coeff .
DT
DT [ 0 2 -1 0 0 0 0 ] 0.002;
...
$FOAM_RUN / tutorials / incompressible / icoFoam
-r cavity cavityT
cavityT
0/ p 0/ T
Listing 8: add thermal diffusion coeff. transportProperties
Balogh Miklós
Programming
March 24, 2014
5 / 11
Laboratory tasks V.
Programming
Balogh
Miklós
Listing 9: modification of 0/T
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
object
T;
}
...
dimensions
[0 0 0 1 0 0 0];
internalField
uniform 300;
boundaryField
{
movingWall
{
type
fixedValue ;
value
uniform 350;
}
fixedWalls
{
type
fixedValue ;
value
uniform 300;
}
frontAndBack
{
type
empty ;
}
}
...
Balogh Miklós
Programming
March 24, 2014
6 / 11
Laboratory tasks VI.
Programming
Balogh
Miklós
Listing 10: modification of system/fvSchemes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
divSchemes
{
default
div ( phi , U )
div ( phi , T )
}
none ;
Gauss linear ;
Gauss upwind limited ; // This line added
l aplacianSchemes
{
default
none ;
laplacian ( nu , U ) Gauss linear orthogonal ;
laplacian ((1| A ( U )) , p ) Gauss linear orthogonal ;
laplacian ( DT , T ) Gauss linear orthogonal ; // This line added
}
...
Balogh Miklós
Programming
March 24, 2014
7 / 11
Laboratory tasks VII.
Programming
Balogh
Miklós
Listing 11: modification of system/fvSolution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
p
{
solver
preconditioner
tolerance
relTol
PCG ;
DIC ;
1e -06;
0;
}
T
{
solver
preconditioner
tolerance
relTol
BICCG ;
DILU ;
1e -7;
0;
};
U
{
solver
preconditioner
tolerance
relTol
PBiCG ;
DILU ;
1e -05;
0;
}
Balogh Miklós
Programming
March 24, 2014
8 / 11
Laboratory tasks VIII.
Programming
Balogh
Miklós
3
Balogh Miklós
Perform the simulations and visualize the results
Programming
March 24, 2014
9 / 11
Assignments
Programming
Balogh
Miklós
1
What is the symbolic form of the temperature equation?
2
Which solver should be modified in order to take into
account turbulence?
3
How can you add technically non-uniform thermal diffusion
to the simulation?
4
How can you add heat flux on the walls? Which BC should
be used?
Balogh Miklós
Programming
March 24, 2014
10 / 11
Homework
Programming
Balogh
Miklós
1
Balogh Miklós
Read Chapter 3 in the User Guide
Programming
March 24, 2014
11 / 11