Skip to content
Snippets Groups Projects
Commit 7c8f1ab4 authored by Ulrich Kerzel's avatar Ulrich Kerzel
Browse files

add continuous casting exercise

parent f3180b6f
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Continuous Casting with Conic Supply Vessel
In the following example, we consider a continuous steel casting production plant that is supplied with a conic vessel holding molten steel.
To ensure operations of the production plant, we require a througput of 6000 kg/min of molten steel and changing the vessels takes 60 seconds.
The height of the liquid steel inside the vessel is 2 metres initially and the radius at the bottom is $R_1 = 0.9$, the radius at the top is $R_2 = 1.2$ m.
The vessel has an outlet of radius $r$ and we need to optimise the radius such that we can maintain the required throughput and include the 60 second change-over time as well.
The geometry of the vessel looks like this:
![image.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAacAAAGcCAYAAAB9Um/2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAADWTSURBVHhe7d17eFTnfSfw7zlnNLqOriBAIJubkUBgYxvMxTgGYaNxagk3j0uC22yTrrdd/LSbpHnsdtNuTS7dzToX25vWbvI4XbfdOsRN2sROjBAX3cBcpBkQIIQAibu4IyGBQJeZ2T9mNNK8OnM06DLn9v08zxTxe0cKdrG+en/nPb8jBQKBAIiIiAxEFgtERER6YzgREZHhMJyIiMhwJF5zIpp4P3jn3fDHX39lU8QaEQ3HcCKKgxmLFoc/vnDkUMQaEQ3Hth4RERkOw4mIiAyH4URERIbDcCIiIsNhOBERkeEwnIiIyHAYTkREZDgMJyIiMhyGE1EcrFi6JPwiopFxQgQRERkOd05ERGQ4DCciIjIchhMRERkOw4mIiAyH4URERIbDcCIiIsPhUXKiONj8xvcGP37t1Yg1IhqO4UQUB3wSLtH9YVuPiIgMhzsnIiIyHO6ciIjIcBhORKSr1tZWSJKk+mptbRXfTjbBcCIiQ9i0aRMCgUD4VVJSgjlz5mDLli3iW8kGGE5EZEjl5eUAgL/+678Wl8gGGE5EZFhz5swRS2QThgunA96D+Oeff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7zxBiRJQmtrK9xuNyRJwty5c8W3EVkOw4nIBNatW4fi4mIEAgGcOnVKXCayHIYTkUm89tprYonIshhORCbw/vvviyUiS2M4ERGR4TCciOLg/MW28IuIRsZwIoqDFe7Phl+62bhRrBAZFsOJyC4++ECsEBkWw4koDja/9mr4RUQjYzgRxcHLX/z98IuIRsbxRUREZDjcORERkeEwnIiIyHAYTkREZDgMJyIiMhyGExERGQ5P6xHFwYqSwckQe7d9ErFGRMNx50QUB+fb2sIvIhoZw4mIiAyH4URERIbDcCIiIsNhOBERkeEwnIiIyHAYTkREZDgMJyIiMhzehEsUBx/+6qPwxxteKItYI6LhGE5ERGQ4bOsREZHhMJyIiMhw/j9JFgxqLH8rkQAAAABJRU5ErkJggg==)
N.B. This is the same example as discussed in the lecture "Numerische Modellierung in der Prozesstechnik" and we discuss this example here to apply the methods of this course to the same example.
%% Cell type:markdown id: tags:
## Torrielli's Law
We model this using Torricelli's law, assuming
- laminar and continuous flow
- ignorign the effects of viscosity
- incompressible liqued with uniform density
- $r << R_1, R_2$
- no effects from the geometry of the outlet orifice, etc.
Then, Torricelli's law gives the velocity of the liquid as:
$$ v = \sqrt{2gh}$$
where $g$ is the constant of gravity, and $h$ is the height of the liquid.
The volumetric flow rate trough the hole at the bottom is given by
$$Q = av$$
with $a = \pi r^2$.
Due to the conic shape of the vessel, the volume of a slice through the cone depends on the height, leading to:
$$ \frac{dV}{dt} = - Q = - a \sqrt{2 g h} = A(h) \frac{dh}{dt}$$
Hence, the differential equation we have to solve (for each $r$) is given by:
$$
\frac{dh}{dt} = -\frac{a}{\pi \left[ R_1 + s h \right]^2} \sqrt{2 g h}
$$
where:
$$
s = \frac{R_2 - R_1}{H}
$$
Substituting $ s $ into the equation:
$$
\frac{dh}{dt} = -\frac{a}{\pi \left[ R_1 + \left( \dfrac{R_2 - R_1}{H} \right) h \right]^2} \sqrt{2 g h}
$$
%% Cell type:code id: tags:
```
# make sure we have the required libraries
# ! pip install torchdiffeq
```
%% Cell type:code id: tags:
```
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# constant of gravity, take the pre-defined one instead of defining our own
import scipy
import torch
from torchdiffeq import odeint
from datetime import datetime
```
%% Cell type:markdown id: tags:
# Plot Height vs Time
As a first step, we visualise how the height of the molten steel in the conic vessel changes with time.
We will use $r=2$ cm for this example, though the radius $r$ is the quantity we want to optimise later to make sure we can maintain the required throughput, including the change-over time.
%% Cell type:code id: tags:
```
# Geometry of the truncated cone
H = 2.0 # Total height of the vessel (m)
R1 = 0.9 # Radius at the bottom (m)
R2 = 1.2 # Radius at the top (m)
s = (R2 - R1) / H # Slope of the radius as a function of height
```
%% Cell type:code id: tags:
```
# assume a fixed radius of the orifice
a = np.pi * (0.02)**2 # Area of the hole at the bottom (m^2)
# assuming r=2cm
```
%% Cell type:code id: tags:
```
# Time parameters
t0 = 0.0 # Initial time (s)
t_end = 3000.0 # End time (s)
dt = 0.1 # Time step (s)
t_values = torch.arange(t0, t_end + dt, dt)
# Initial condition
h0 = torch.tensor([H], dtype=torch.float32) # Initial height of the liquid (full vessel)
# Physical Constants
g = torch.tensor(# YOUR CODE HERE, dtype=torch.float32)
```
%% Cell type:markdown id: tags:
This is the differential equation from above, assuming Torricelli's law.
We need to encode this as ```torch``` tensors, so that we can make use of the advanced compute capabilities of PyTorch.
We use [torch.clamp](https://pytorch.org/docs/stable/generated/torch.clamp.html) to make sure that the height of the steel in the vessel does not become negative.
**N.B.** The function ```def dhdt(t,h)``` also depends on the parameter ```a``` (the area of the outlet orifice) and ```g```. Here, we have specified these as a global variables above.
Since the function ```odeint``` does not take additional arguments, we have to specify these outside the scope of the function.
This is not an issue at this stage, but we will see later that this requires us to write the code in a specific way when we want to optimise the radius of the orifice and, hence, the area ```a```.
%% Cell type:code id: tags:
```
# Function defining the differential equation dh/dt
def dhdt(t, h):
# Ensure h is non-negative
h = # YOUR CODE HERE
# Compute r(h)
r = R1 + s * h
# Compute A(h)
A = torch.pi * r ** 2
# Compute dh/dt
sqrt_term = torch.sqrt(2 * g * h)
dh = - (a / A) * sqrt_term
# Handle h = 0 to prevent division by zero
dh = torch.where(h > 0.0, dh, torch.tensor(0.0))
return dh
```
%% Cell type:code id: tags:
```
# Solve the ODE using torchdiffeq's odeint function
h_values = odeint(dhdt, h0, t_values, method='dopri5')
# Flatten the result to 1D tensor for easy handling
h_values = h_values.view(-1)
# Ensure non-negative heights
h_values = torch.clamp(h_values, min=0.0)
```
%% Cell type:code id: tags:
```
# Plot the results
t_np = t_values.numpy()
h_np = h_values.detach().numpy()
plt.figure(figsize=(8, 5))
sns.lineplot(x=t_np, y=h_np)
plt.title('Height of Liquid in Truncated Cone Over Time')
plt.xlabel('Time (s)')
plt.ylabel('Height (m)')
plt.grid(True)
plt.show()
```
%% Output
%% Cell type:markdown id: tags:
# Optimising Outlet Radius - Differential Equation
We will now find the optimal radius of the output orifice $r$.
As discussed above, we need to maintain a specific throughput, as well as consider the time it takes to change vessels for continuous operations.
This means that we need to find a radius of the output orifice such that the vessel is empty at the target time ```t_target = 428.32``` s.
N.B. in the following, we will denote the radius of the output orifice for each step of the optimisation as $r_0$ to avoid confusion with values inside each optimisation step.
%% Cell type:code id: tags:
```
# Target emptying time
t_target = torch.tensor(428.32, dtype=torch.float32) # seconds
```
%% Cell type:markdown id: tags:
We now define the function that computes the height of the remaining molten steel inside the vessel at the target time ```t_target``` for a given radius $r_0$ of the output orifice.
We then want to find the value $r_0$ where the height is zero at the end, i.e. when the vessel is empty.
This is implemented in the following way: For each radius, we solve the differential equation, calculate the height at various times $t$, and, in particular the time at ```t_target```.
Since we want to find the value of $r_0$ for which the function is zero, we want to find the *root* of the function of the heights as we change $r_0$.
Note:
Unlike earlier, the area of the orifice now depends on the radius $r_0$ that we are changing. Ideally, we would add another argument to the function with the differential equation.
However, the function ```odeint``` of [torchdiffeq](https://github.com/rtqichen/torchdiffeq) does not support this. Therefore, we define the function for the differential equation within the function computing the height at time ```t_target```. Then, for each round, the value of the area $a$ is defined and we, kind-off, side-step the problem.
%% Cell type:code id: tags:
```
# Compute the height of the molten steel for a given
# radius of the outlet orifice r_0 after t_target has elapsed
def compute_h_at_tend(r_o):
# Ensure r_o is a tensor with requires_grad=True
if not isinstance(r_o, torch.Tensor):
r_o = torch.tensor(r_o, dtype=torch.float32, requires_grad=True)
else:
r_o = r_o.clone().detach().requires_grad_(True)
# a is used inside dhdt, but we cannot pass it as an argument
# hence, we define a here, making it a "global" variable as
# far as dhdt is concerned.
# (same for g, but that truly is a constant, at least for our purposes here.)
a = # YOUR CODE HERE
# Define the differential equation dh/dt
def dhdt(t, h):
h = # YOUR CODE HERE
r = R1 + s * h
A = torch.pi * r ** 2
sqrt_term = torch.sqrt(2 * g * h)
dh = - (a / A) * sqrt_term
return dh
# Time points for solving the ODE (start and end)
t_span = torch.tensor([0.0, t_target], dtype=torch.float32)
# Solve the ODE
h_values = odeint(dhdt, h0, t_span, method='dopri5')
h_tend = h_values[-1, 0] # Height at t_target
return h_tend, r_o
```
%% Cell type:markdown id: tags:
Before we find the optimal value, we can plot the result to get a feeling for our expectation.
N.B. due to the line ```h = h.clamp(min=0.0)``` we cannot have negative heights in the vessel.
%% Cell type:markdown id: tags:
**Exercise**
Plot the function of the height of the remaining steel in the vessel after the target time ```t_target``` has elapsed for the radius in the interval $(0.02, 0.05)$ for 100 steps.
Note that we need PyTorch tensors.
%% Cell type:code id: tags:
```
# Generate x_space and compute y_space
x_space = torch.linspace(0.02, 0.05, steps=50) # Orifice radii from 0.02 m to 0.05 m
y_space = []
##
## your code here
##
# Convert to NumPy arrays for plotting
x_space_np = x_space.numpy()
y_space_np = np.array(y_space)
# Plotting
plt.figure(figsize=(10, 6))
plt.plot(x_space_np, y_space_np, label='h(t_target)')
plt.axhline(y=0, color='black', linestyle='--', label='h=0')
# Include known solution
plt.axvline(x=0.038, color='red', linestyle='--', label='r=0.038 m')
plt.title('Height at $t_{target}$ vs Orifice Radius (Conic Vessel)')
plt.xlabel('Orifice Radius $r$ (m)')
plt.ylabel('Height $h(t_{target})$ (m)')
plt.legend()
plt.grid(True)
plt.show()
```
%% Cell type:markdown id: tags:
## Newton's Method
We can find the root of the above function using, for example, Newton's method, and detemine the optimal radius of the outlet orifice.
%% Cell type:code id: tags:
```
def newtons_method(f, r_o_init, tol=1e-6, rtol=1e-6, max_iter=20):
r_o = torch.tensor(r_o_init, dtype=torch.float32, requires_grad=True)
for i in range(max_iter):
h_tend, r_o = f(r_o)
f_r_o = h_tend # We aim for h_tend = 0
if torch.abs(f_r_o) < tol:
print(f"Converged at iteration {i}: r_o = {r_o.item():.6f} m")
return r_o.item()
f_r_o.backward()
f_prime = r_o.grad.item()
if f_prime == 0:
print("Derivative zero. Stopping iteration.")
return r_o.item()
# Update r_o using Newton's method
r_o_new = # YOUR CODE HERE
# Check for convergence based on change in r_o
delta_r_o = torch.abs(r_o_new - r_o)
if delta_r_o < rtol:
print(f"Converged at iteration {i}: r_o = {r_o_new.item():.6f} m (delta_r_o < {rtol})")
return r_o_new.item()
# Prepare for next iteration
r_o = r_o_new.detach().requires_grad_(True)
print(f"Iteration {i}: r_o = {r_o.item():.6f} m, h(t_end) = {h_tend.item():.6f}, f'(r_o) = {f_prime:.6f}, delta_r_o = {delta_r_o.item():.6f}")
print("Maximum iterations reached without convergence.")
return r_o.item()
```
%% Cell type:code id: tags:
```
# Define the function f(r_o)
def f(r_o):
h_tend, r_o = compute_h_at_tend(r_o)
return h_tend, r_o
# Initial guess for r_o (in meters)
r_o_initial = 0.025 # 25 mm
# Run Newton's method
t_start = datetime.now()
optimal_r_o = newtons_method(f, r_o_initial, tol=1e-5, rtol=1e-6, max_iter=50)
t_stop = datetime.now()
print(f"\nOptimal orifice radius found: {optimal_r_o * 1000:.2f} mm")
print(f'Time taken: {t_stop - t_start}')
```
%% Output
Iteration 0: r_o = 0.035460 m, h(t_end) = 0.871790, f'(r_o) = -83.348442, delta_r_o = 0.010460
Iteration 1: r_o = 0.037223 m, h(t_end) = 0.081241, f'(r_o) = -46.081654, delta_r_o = 0.001763
Iteration 2: r_o = 0.038015 m, h(t_end) = 0.018847, f'(r_o) = -23.784437, delta_r_o = 0.000792
Iteration 3: r_o = 0.038396 m, h(t_end) = 0.004587, f'(r_o) = -12.040705, delta_r_o = 0.000381
Iteration 4: r_o = 0.038583 m, h(t_end) = 0.001134, f'(r_o) = -6.053280, delta_r_o = 0.000187
Iteration 5: r_o = 0.038676 m, h(t_end) = 0.000282, f'(r_o) = -3.034362, delta_r_o = 0.000093
Iteration 6: r_o = 0.038722 m, h(t_end) = 0.000070, f'(r_o) = -1.519046, delta_r_o = 0.000046
Iteration 7: r_o = 0.038746 m, h(t_end) = 0.000018, f'(r_o) = -0.759962, delta_r_o = 0.000023
Converged at iteration 8: r_o = 0.038746 m
Optimal orifice radius found: 38.75 mm
Time taken: 0:00:01.596860
%% Cell type:markdown id: tags:
Now plot the final function of height vs time for the optimal radius
(remember that we cannot add another argument to the function ```dhdt```, so we need to define it again with the optimal radius).
%% Cell type:code id: tags:
```
def dhdt_opt(t, h):
h = h.clamp(min=0.0)
r = R1 + s * h
A = torch.pi * r ** 2
sqrt_term = torch.sqrt(2 * g * h)
a_opt = torch.pi * optimal_r_o ** 2
dh = - (a_opt / A) * sqrt_term
return dh
t_values = torch.linspace(0.0, t_target.item(), steps=200)
h_values_opt = odeint(dhdt_opt, h0, t_values, method='dopri5')
h_values_opt = h_values_opt.view(-1)
h_values_opt = h_values_opt.clamp(min=0.0).detach().numpy()
plt.figure(figsize=(10, 6))
plt.plot(t_values.numpy(), h_values_opt)
plt.title('Height of Liquid in Truncated Cone Over Time (Optimal r_o via Newton\'s Method)')
plt.xlabel('Time (s)')
plt.ylabel('Height (m)')
plt.grid(True)
plt.show()
```
%% Output
%% Cell type:markdown id: tags:
# Optimising Outlet Radius - Iterative Approach
Instead of using a package to solve the differential equation, we can also use an iterative approach and discretise the differential equation.
The following function computes the height at a specific target time ```desired_time``` as a function of the radius ```r``` of the output orifice.
The remainnig parameters (```R1, R2, initial_height```) specifiy the geometry and initial height of the molten steel in the vessel. We can make these parameters argument to the function here as we are not constrained by the calling function like ```odeint``` earlier.
N.B. We need to work with PyTorch tensors (or types that are easily converted) to be able to call Newton's method efficiently later on.
%% Cell type:code id: tags:
```
def calculate_height_fixpoint(r: torch.tensor, delta_t: float = 1.0, t_max: float = 100000.0,
R1: float = 0.9, R2: float = 1.2, initial_height: float = 2.0,
desired_time: float = 428.2) -> torch.tensor:
"""
Calculate the height at a specific desired time based on the given radius value.
Parameters:
r (torch.tensor): Radius value with requires_grad=True.
delta_t (float): Time step for calculations (default is 1.0).
t_max (float): Maximum time for simulation in seconds (default is 100000.0).
R1 (float): First radius constant in meters (default is 0.9).
R2 (float): Second radius constant in meters (default is 1.2).
initial_height (float): The starting height in meters (default is 2.0).
desired_time (float): The specific time at which to calculate the height.
Returns:
torch.tensor: The height at the desired time.
"""
# Ensure r has requires_grad=True
if not r.requires_grad:
r.requires_grad = True
# Number of steps
num_steps = int(torch.ceil(torch.tensor(t_max / delta_t)).item())
desired_step = int(torch.ceil(torch.tensor(desired_time / delta_t)).item())
max_step = min(num_steps, desired_step)
# Initialize heights as a list to avoid in-place operations
heights = []
current_height = torch.tensor(initial_height, dtype=torch.float32)
# convert the numerical constants used in the code below
# into torch.tensors, so we can use them without breaking the graph.
# (PyTorch does not contain a set of mathematical or physical constants)
pi = torch.tensor(np.pi, dtype=torch.float32)
g = torch.tensor(scipy.constants.g, dtype=torch.float32)
for i in range(max_step):
# Ensure no negative heights for sqrt
current_height_pos = torch.clamp(current_height, min=0.0)
effective_radius = R1 + (current_height_pos / initial_height) * (R2 - R1)
flow_rate = (r / effective_radius)**2 * torch.sqrt(2 * g * current_height_pos)
next_height = current_height - delta_t * flow_rate
# Ensure next_height is not negative
next_height = torch.clamp(next_height, min=0.0)
# Append current_height to the list
heights.append(current_height)
# Update current_height for the next iteration
current_height = next_height
# The height at the desired time
height_at_desired_time = current_height
return height_at_desired_time
```
%% Cell type:markdown id: tags:
**Exercise**
Use the above function to call the function ```newtons_method``` we defined earlier and find the optimal radius of the output orifice.
%% Cell type:code id: tags:
```
##
## your code goes here
##
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment