-
Notifications
You must be signed in to change notification settings - Fork 69
Launching your first simulation
The objective of this section is to highlight the steps that are necessary to launch your a simulation after you have cloned and compiled Lethe.
Launching of an application requires an executable of the required solver, and a parameters file (with extension .prm if it uses the parameter file format, or .json if it uses the JSON file format). After building Lethe, the solver executable files can be found in :
$BUILD_FOLDER/applications directory
For instance, gd_navier_stokes_2d executable is located in the
$BUILD_FOLDER/applications/gd_navier_stokes_2d directory.
The executable for the solvers can be used directly from the folder it is compiled to. This can be achieved by:
- Writing the absolute path of the solver (e.g. $BUILD_FOLDER/applications/gd_navier_stokes_2d/gd_navier_stokes_2d`);
- Adding the lethe folder paths to your
PATHenvironment variable; - Specifying an installation folder when you compile Lethe to ensure that all the applications are grouped within a single folder;
- Locally copying the executable to the folder you are running your simulation from.
All these workflow can achieve the same result.
To launch a simulation, you must specify the solver executable and the parameter file in the following format: solver parameter_file. For example, glsNS2d poiseuille2d.prm
In what follow, we describe a simple procedure to launch your first simulation using Lethe.
The source folder of lethe contains an examples folder. This folder contains ready to run examples. Some examples use the mesh generation capacity of Lethe and only require a parameter file, whereas others contain an additional '.msh' file to describe the mesh. In the present case, we copy the 'examples/cavity' example to a new folder using the terminal 'cp -r $SOURCE_FOLDER/examples/cavity destination/first_simualtion'
The cavity example we are launching uses the 2D gls_navier_stokes solver. All of the solvers of Lethe can be found in the build folder where you have compiled Lethe or within the installation folder. Inside of your build folder, six other folders should be found:
- applications;
- applications_tests;
- CMakeFiles;
- prototypes;
- source;
- tests;
Inside the applications folder, there is one folder for each solver of Lethe. In the gls_navier_stokes_2d folder, we find the executable file with the same name as the folder: 'gls_navier_stokes_2d'. This solver solves the 2D incompressible Navier-Stokes equations using a Galerkin Least-Square formulation.
From the 'first_simulation' folder we have created, we can launch the simulation directly. I you have decided to copy the executable to the 'first_simulation' folder, you can launch using the following command: './gls_navier_stokes_2d cavity.prm'. You can also launch the simulation using the absolute path of the executable:'$BUILD_FOLDER/applications/gls_navier_stokes_2d/gls_navier_stokes_2d cavity.prm'.
Once the application has ran, the simulation results can be looked at by opening the '.pvd' file using Paraview.
Lethe comes pre-packaged with some examples which are documented on the present wiki. We greatly encourage you to look at these examples to understand how Lethe can be used to solve CFD problems. For a more in-depth understanding of the parameter file, the reader can take a look at this section of the wiki.
In this example, flow of fluid in a two-dimensional square-shaped cavity is simulated using Lethe. The geometry and boundary conditions of the simulated system is illustrated in the following.

In this case, only the upper wall boundary (ID = 3) moves in x direction with a constant velocity (u = 1 m/s) while the other boundaries are fixed (no slip boundary condition). Note the numbering method of the boundaries in Lethe format on this figure. We will use "gls_navier_stokes_2d" solver for this simulation. In the parameter handler file the geometry and mesh is determined as:
#---------------------------------------------------
# Mesh
#---------------------------------------------------
subsection mesh
set type = dealii
set grid type = hyper_cube
set grid arguments = -1 : 1 : true
set initial refinement = 6
end
As can be observed, the geometry is defined using a hyper_cube, starting from -1 to 1 in each direction and the initial number of refinements is set equal to 6. The boundary conditions of this simulation are also determined as:
# --------------------------------------------------
# Boundary Conditions
#---------------------------------------------------
subsection boundary conditions
set number = 4
subsection bc 0
set id = 0
set type = noslip
end
subsection bc 1
set id = 1
set type = noslip
end
subsection bc 2
set id = 2
set type = noslip
end
subsection bc 3
set id = 3
set type = function
subsection u
set Function expression = 1
end
subsection v
set Function expression = 0
end
end
end
In the boundary conditions section, "no slip" boundary condition was chosen for the first three boundaries, while the motion of the top wall is defined using function boundary condition. In the function boundary condition, the velocity in x direction is set equal to 1. The velocity distribution in the steady state is illustrated in the following:

In fluid mechanics, Taylor-Couette flow is the name of a fluid flow in the gap between two long concentric cylinders with different rotational velocities. One or both of these cylinders may rotate along the axis, however generally it is assumed that outer cylinder is fixed, and the inner cylinder rotates with a constant velocity. For Taylor-Couette flow, an analytical solution of the Navier-Stokes equations can be found, although this solution is not stable for all ranges of operating conditions.
We assumed that the inner cylinder rotates at a constant velocity, while the outer cylinder is fixed. The following figure shows the geometry of this problem and the corresponding boundary conditions.

Note that the outer cylinder does not rotate, while the inner cylinder rotates anti-clockwise. Since the analytical solution of this problem is available, we add an analytical solution section to the parameter handler file which contains the solution. This analytical solution can be used to find the numerical simulation error.
# --------------------------------------------------
# Analytical Solution
#---------------------------------------------------
subsection analytical solution
set enable = true
subsection uvw
# A= -(eta_ * eta_) / (1. - eta_ * eta_);
# B= ri_ * ri_ / (1. - eta_ * eta_);
set Function constants = eta=0.25, ri=0.25
set Function expression = -sin(atan2(y,x))*(-(eta*eta) / (1-eta*eta)* sqrt(x*x+y*y)+ ri*ri/(1-eta*eta)/sqrt(x*x+y*y)); cos(atan2(y,x))*(-(eta*eta) / (1-eta*eta)* sqrt(x*x+y*y)+ ri*ri/(1-eta*eta)/sqrt(x*x+y*y)) ; 0
end
end
If the user is interested in finding the torque on the outer cylinder, it can be specified in the subsection force of the parameter file:
#---------------------------------------------------
# Force
#---------------------------------------------------
subsection forces
set verbosity = verbose # Output force and torques in log
set calculate forces = false # Enable force calculation
set calculate torques = true # Enable torque calculation
set force name = force # Name prefix of force files
set torque name = torque # Name prefix of torque files
set output precision = 10 # Output precision
set display precision = 3 # Log precision
set calculation frequency = 1 # Frequency of the force calculation
set output frequency = 1 # Frequency of file update
end
For creating the geometry, hyper_shell function is used. It should be mentioned that in 3-dimensions, hyper_shell is used to create a shell between two concentric spheres. In this problem, since we are working in 2-dimensions, hyper_shell can be used utilized to create the geometry.
#---------------------------------------------------
# Mesh
#---------------------------------------------------
subsection mesh
set type = dealii
set grid type = hyper_shell
set grid arguments = 0, 0 : 0.25 : 1 : 4: true
set initial refinement = 3
end
Using this, the shell between two concentric circles (with centers at the origin of coordinates, inner radius = 0.25 and outer radius = 1) is created.
For setting up the boundary conditions, no slip condition is used for the outer cylinder, while the rotation of the inner cylinder is adjusted by setting the value of u = -y and v = x.
# --------------------------------------------------
# Boundary Conditions
#---------------------------------------------------
subsection boundary conditions
set number = 2
subsection bc 1
set type = noslip
end
subsection bc 0
set type = function
subsection u
set Function expression = -y
end
subsection v
set Function expression = x
end
subsection w
set Function expression = 0
end
end
end
The velocity distribution in the steady state is illustrated in the following:
[[images/10.png]]
The torques are obtained from the output files named torque00.dat and torque01.dat. It can be noticed that the torques are in the z direction as expected for such problem. We get two torques because we have two cylinders. On the inner cylinder, a torque is required to keep the cylinder in motion since viscosity is "stopping" the rotation. On the outer cylinder, a torque is required to keep the cylinder static (Newton third's law). With every refinement, the toques are getting closer to each other since ideally, they should have the same magnitude but opposite signs to prevent the outer cylinder from spinning.
time T_x T_y T_z
0000000000 0.0000000000 0.0000000000 -0.8192063236
0000000000 0.0000000000 0.0000000000 -0.8319958824
0000000000 0.0000000000 0.0000000000 -0.8361362740
time T_x T_y T_z
0000000000 0.0000000000 0.0000000000 0.8357076779
0000000000 0.0000000000 0.0000000000 0.8372702320
0000000000 0.0000000000 0.0000000000 0.8376393910
# Example 3 : Flow across a cylinder
In this example, a flow is passing across a fixed cylinder. The velocity profile of the flow is simulated. The parameter folder used is `cylinder_gls.prm`.
The following schematic describes the simulation.
[[images/11.png]]
* bc = 0 (No slip boundary condition)
* bc = 1 (u = 1; flow in the x-direction)
* bc = 2 (Slip boundary condition)
The initial condition implemented describes the movement of the flow in the x-direction.
#---------------------------------------------------
# Initial condition
#---------------------------------------------------
subsection initial conditions
set type = nodal
subsection uvwp
set Function expression = 1; 0; 0
end
end
The subsection uvwp allows the description of a vector-valued function representing the velocity in the x-direction where the individual components of the velocity are separated by semicolons in the set Function expression.
For the mesh, the gmsh option was chosen which requires the input of a .msh file generated by gmsh.
#---------------------------------------------------
# Mesh
#---------------------------------------------------
subsection mesh
set type = gmsh
set file name = cylinder_structured.msh
end
The .msh file can be found in the same folder where the parameter file was obtained. The set file name includes the path of the file to be used, however since in this case both the parameter and the mesh files are located in the same folder, no path needs to be identified.
# --------------------------------------------------
# Boundary Conditions
#---------------------------------------------------
subsection boundary conditions
set number = 3
subsection bc 0
set type = noslip
end
subsection bc 1
set type = function
subsection u
set Function expression = 1
end
subsection v
set Function expression = 0
end
subsection w
set Function expression = 0
end
end
subsection bc 2
set type = slip
end
end
In this section, we mainly have 3 boundary conditions. BC 0 identifies the cylinder where we apply noslip boundary conditions on its walls. This leads to a velocity of 0 for the fluid directly in contact with the walls of the cylinder.
BC 1 determines the flow of the fluid from the left wall. As mentioned before, the fluid is moving in the x-direction and therefore its boundary condition is defined with a function having a u velocity equals to 1.
BC2 is applied at the top and bottom walls. This condition allows the simulation to be performed in a finite sized domain. In real life, the cylinder would be placed in a relatively infinite domain. Using slip condition, we assume that the fluid cannot go out in the normal direction, but that it can still flow from left to right without friction. Thus, the walls have no effect of the flow of the fluid.
An implied fourth boundary condition is implemented on the right wall which represents the outlet of the flow. We do not apply anything in this region which leads to a natural boundary condition where the pressure becomes close to 0.
The results obtained are represented in what follows.
From the velocity distribution, we notice how the velocity of the fluid is 0 at the boundaries of the cylinder and how it increases gradually the further away from the cylinder the fluid is.
[[images/12.png]]
The pressure is also visualized. The pressure difference between the inlet and outlet is visible and we can see how the pressure nears a value of 0 the close to the outlet.
[[images/13.png]]