Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Modelling physical and biological systems
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mipi
Lectures
Modelling physical and biological systems
Commits
3d702c4a
Commit
3d702c4a
authored
2 years ago
by
Delvigne Frank
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
fd8cb9f5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Ex_4_5.py
+80
-0
80 additions, 0 deletions
Ex_4_5.py
with
80 additions
and
0 deletions
Ex_4_5.py
0 → 100644
+
80
−
0
View file @
3d702c4a
#!/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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment