Skip to content
Snippets Groups Projects
Commit 3d702c4a authored by Delvigne Frank's avatar Delvigne Frank
Browse files

Upload New File

parent fd8cb9f5
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May 10 08:04:14 2023
@author: delvigne
"""
'''
Exercice 4.5 Modelling residence time of particles inside a CSTR
'''
import numpy as np
from matplotlib.pyplot import figure
from matplotlib.pyplot import plot
from matplotlib.pyplot import xlabel
from matplotlib.pyplot import ylabel
from matplotlib.pyplot import title
import matplotlib.pyplot as plt
import math
from numpy.random import seed
from numpy.random import rand
'''
Deterministic simulation for the outflow of soluble molecules (Euler referential)
'''
Q = 100 #in L/min
V = 1000 #in L
N = 80 # in min -> timescale
t = np.arange(N)
C_time = []
C0 = 1
for x in t:
C = C0*math.exp(-(Q/V)*x)
C_time.append(C)
figure(1)
plot(C_time)
xlabel('Time (h)')
ylabel('Concentration')
title('Deterministic-Euler simulation')
'''
Stochastic simulation for the escape of discrete particles (Lagrange referential)
'''
#Passage time of particles follows an exponential distribution
#seed(3)
r = np.random.rand(30)
t_pass = []
for y in r:
t_passage = -math.log(y)/(Q/V)
t_pass.append(t_passage)
fig2, (ax1, ax2) = plt.subplots(2,1)
ax1.eventplot(t_pass,colors='orange')
ax1.axis('off')
time2 = (sorted(t_pass,reverse=True))
ax2.plot(time2,np.arange(1,len(t_pass)+1),'tab:orange')
xlabel('Time (h)')
ylabel('Number of particles')
title('Stochastic-Lagrangian simulation')
'''
Note : you could also use Python built-in function np.random.exponential
Example :
import numpy as np
import matplotlib.pyplot as plt
import random as rand
t_pass = np.random.exponential(-V/Q,1000)
'''
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment