Skip to content

Commit

Permalink
Update flow past a backward facing step example (#1389)
Browse files Browse the repository at this point in the history
Description
The post-processing scripts were not working for this example and the example was long and hard to follow. This PR refactors the example by limiting it to two Reynolds numbers: 100 and 1000. To summarize:

All the parameters are revisited to ensure correct convergence for both cases.
The folders and parameter files are renamed so that it is clear for which Reynolds they are.
The results are limited to: visualizing the velocity profiles (with streamlines to identify eddy after step and zoom in plots, all in one figure), reporting the reattachment point for the last step and its relative error in comparison to reference data, and comparing the obtained velocity distribution at the outlet to the analytical solution.
The post-processing scripts are fixed so that they work for both Reynolds number by just changing the appropriate flag when running the script. Moreover, the number of vtu files is no longer hardcoded and can be found automatically by the script.

Co-authored-by: Victor Oliveira Ferreira <voferreira@outlook.com>
  • Loading branch information
lpsaavedra and voferreira authored Nov 27, 2024
1 parent 9d62ea9 commit 8977e0a
Show file tree
Hide file tree
Showing 19 changed files with 280 additions and 321 deletions.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set dimension = 2
#---------------------------------------------------
# Simulation Control
#---------------------------------------------------

subsection simulation control
set method = steady
set number mesh adapt = 10
Expand All @@ -23,7 +24,7 @@ end
subsection physical properties
set number of fluids = 1
subsection fluid 0
set kinematic viscosity = 0.01 # Re_h=2/nu
set kinematic viscosity = 0.02 # Re_h=2/nu
end
end

Expand Down Expand Up @@ -60,13 +61,13 @@ end
#---------------------------------------------------

subsection boundary conditions
set number = 3
set number = 3
subsection bc 0
set id = 0
set id = 0
set type = noslip
end
subsection bc 1
set id = 1
set id = 1
set type = function
subsection u
set Function expression = 1
Expand All @@ -79,7 +80,7 @@ subsection boundary conditions
end
end
subsection bc 2
set id = 2
set id = 2
set type = outlet
end
end
Expand All @@ -90,9 +91,8 @@ end

subsection non-linear solver
subsection fluid dynamics
set verbosity = verbose
set tolerance = 1e-6
set max iterations = 10
set verbosity = verbose
set tolerance = 1e-6
end
end

Expand All @@ -104,8 +104,8 @@ subsection linear solver
subsection fluid dynamics
set verbosity = verbose
set method = gmres
set max iters = 1000
set max krylov vectors = 1000
set max iters = 300
set max krylov vectors = 300
set relative residual = 1e-4
set minimum residual = 1e-9
set preconditioner = ilu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ subsection simulation control
set adapt = true
set max cfl = 1e5
set adaptative time step scaling = 1.2
set number mesh adapt = 0
set output name = backward_facing_step_output
set output frequency = 1
set output boundaries = false
end

#---------------------------------------------------
Expand All @@ -30,7 +28,7 @@ end
subsection physical properties
set number of fluids = 1
subsection fluid 0
set kinematic viscosity = 0.002857 # Re=2/nu
set kinematic viscosity = 0.002 # Re=2/nu
end
end

Expand All @@ -48,13 +46,11 @@ end
#---------------------------------------------------

subsection mesh adaptation
set variable = velocity
set type = kelly
set fraction refinement = 0.2
set min refinement level = 0
set max refinement level = 10
set max number elements = 250000
set frequency = 5
set variable = velocity
set type = kelly
set fraction refinement = 0.2
set max number elements = 250000
set frequency = 5
end

#---------------------------------------------------
Expand All @@ -71,8 +67,7 @@ end
#---------------------------------------------------

subsection boundary conditions
set number = 3
set time dependent = false
set number = 3
subsection bc 0
set type = noslip
end
Expand All @@ -89,7 +84,7 @@ subsection boundary conditions
end
end
subsection bc 2
set id = 2
set id = 2
set type = outlet
end
end
Expand All @@ -108,10 +103,8 @@ end

subsection non-linear solver
subsection fluid dynamics
set solver = newton
set verbosity = verbose
set tolerance = 1e-6
set max iterations = 10
set verbosity = verbose
set tolerance = 1e-6
end
end

Expand All @@ -121,13 +114,13 @@ end

subsection linear solver
subsection fluid dynamics
set verbosity = verbose
set method = gmres
set max iters = 1000
set max krylov vectors = 1000
set relative residual = 1e-4
set minimum residual = 1e-9
set preconditioner = amg
set amg preconditioner ilu fill = 1
set verbosity = verbose
set method = gmres
set max iters = 500
set max krylov vectors = 500
set relative residual = 1e-4
set minimum residual = 1e-9
set preconditioner = amg
set amg preconditioner ilu fill = 1
end
end
98 changes: 0 additions & 98 deletions examples/incompressible-flow/2d-backward-facing-step/bisection.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# SPDX-FileCopyrightText: Copyright (c) 2022, 2024 The Lethe Authors
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later

"""
Postprocessing code for 2D-backward-facing-step example
Computes the reattachment length (x_r) for Re = 100 and Re = 1000
for several meshes using a bisection algorithm
"""

import numpy as np
import matplotlib.pyplot as plt
import pyvista as pv
import re
import os
import argparse
import sys

########################################
########################################

# EXAMPLE TO COMPUTE x_r (REATTACHMENT LENGTH) FOR Re = 100 and Re = 1000
# NOTE : THIS FILE MUST BE IN THE "2d-backward-facing-step" DIRECTORY TO
# WORK PROPERLY

# Parse Reynolds number
parser = argparse.ArgumentParser(description='Arguments to compute the velocity distribution at outlet')
parser.add_argument("-Re", "--Reynolds", type=int, help="Reynolds number (only 100 and 1000 supported)", required=True)

args, leftovers = parser.parse_known_args()
Re = args.Reynolds

if (Re != 100 and Re != 1000):
sys.exit("This Reynolds number is not supported. Only Re = 100 and Re = 1000.")

#Define folder path according to Re
folder = "./Reynolds" + str(Re)

# VARIABLES
L_in = 15 # Inlet length


# Initial guesses depending on the Reynolds number and reference reattachment values
# by Erturk (2008) (see attached .txt file for other Reynolds x_r values)
if (Re == 100):
x_inf = 1.5
x_sup = 3
x_r_ref = 2.922
elif (Re == 1000):
x_inf = 12
x_sup = 14
x_r_ref = 13.121

tol = 1e-12 # Bisection stop criterion

# DATA EXTRACTION
max_number = -1
pattern = re.compile(r'backward_facing_step_output\.(\d+)\.00000.vtu')

for filename in os.listdir(folder):
match = pattern.match(filename)
if match:
number = int(match.group(1))
if number > max_number:
max_number = number

n_files_to_read = max_number
x_r = []

for i in range(0, n_files_to_read):
# Read all files except the 0 file
file = (folder + '/backward_facing_step_output.'
+ f'{i+1:05d}' + '.00000.vtu')
data = pv.read(file)
data.set_active_vectors("velocity")

# Initial guesses
x1 = L_in + x_inf
x2 = L_in + x_sup
j = 0
# Bisection loop
while abs(x2-x1)>tol and j<=20:
xm = (x1+x2)/2

# Profiles extraction
a = np.array([x1, 0, 0])
b = np.array([x1, 0.01, 0])
profil1 = data.sample_over_line(a, b, resolution=1000)
u1 = profil1["velocity"][:,0]
y = profil1["Distance"]

a = np.array([xm, 0, 0])
b = np.array([xm, 0.01, 0])
profilm = data.sample_over_line(a, b, resolution=1000)
um = profilm["velocity"][:,0]

a = np.array([x2, 0, 0])
b = np.array([x2, 0.01, 0])
profil2 = data.sample_over_line(a, b, resolution=1000)
u2 = profil2["velocity"][:,0]


# Derivatives
dudy1 = (-u1[2] + 4*u1[1] - 3*u1[0]) / (y[2] - y[0])
dudym = (-um[2] + 4*um[1] - 3*um[0]) / (y[2] - y[0])
dudy2 = (-u2[2] + 4*u2[1] - 3*u2[0]) / (y[2] - y[0])

# Signs check
if (abs(dudym) < 0.1*tol):
break
if (dudy1*dudym < 0):
x2 = xm
else:
x1 = xm

j+=1

x_r.append(xm - L_in) # Add distance from the step
print("Output file " + str(i+1) + ", reattachment point x_r: " , xm - L_in)

# Calculate relative error using last reattachment point and ref values
e = abs(x_r_ref - x_r[-1])/x_r_ref
print("Reference value Erturk (2008): ", x_r_ref)
print("Relative error abs(x_r_ref - x_r)/x_r_ref = ", e)
Loading

0 comments on commit 8977e0a

Please sign in to comment.