Skip to content

Commit c6b4d3b

Browse files
committed
second article uploaded
1 parent 738c069 commit c6b4d3b

File tree

37 files changed

+1115
-498
lines changed

37 files changed

+1115
-498
lines changed
Loading
Loading

content/posts/physics/percolation/index.md

+89-37
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,37 @@ menu:
88
identifier: percolation
99
parent: physics
1010
weight: 9
11+
hero: images/lattice_illustration.png
1112
tags: ["Science", ""]
1213
categories: ["Physics"]
1314
---
14-
1515
## Introduction
1616

17-
Percolation theory is a fundamental concept in statistical physics and mathematics that describes the behavior of connected clusters in a random graph. It is a model for understanding how a network behaves when nodes or links are added, leading to a phase transition from a state of disconnected clusters to a state where a large, connected cluster spans the system. This transition occurs at a critical threshold, known as the percolation threshold. The theory has applications in various fields, including material science, epidemiology, and network theory.
17+
[Percolation theory](https://en.wikipedia.org/wiki/Percolation_theory) is a fundamental concept in statistical physics and mathematics that describes the behavior of connected clusters in a random graph. It is a model for understanding how a network behaves when nodes or links are added, leading to a phase transition from a state of disconnected clusters to a state where a large, connected cluster spans the system. This transition occurs at a critical threshold, known as the percolation threshold. The theory has applications in various fields, including material science, epidemiology, and network theory.
1818

1919
## Why is Percolation Important? Useful Applications
2020

21-
Percolation theory provides insights into the behavior of complex systems and phase transitions. Here are some key applications:
22-
23-
### Material Science
24-
25-
Percolation theory helps understand the properties of composite materials, such as electrical conductivity and strength. For example, the electrical conductivity of a composite material can change dramatically when the concentration of conductive filler reaches the percolation threshold.
26-
27-
### Epidemiology
28-
29-
In studying disease spread, percolation models can predict the outbreak and spread of epidemics. The percolation threshold represents the critical point at which a disease becomes widespread in a population.
30-
31-
### Network Theory
21+
Percolation theory is important because it provides insights into the behavior of complex systems and phase transitions. Here are some key applications:
3222

33-
Percolation theory is used to study the robustness and connectivity of networks like the internet or social networks. It helps understand how networks can be disrupted and how to make them more resilient.
34-
35-
### Geophysics
36-
37-
In oil recovery, percolation theory models the flow of fluids through porous rocks, helping to optimize extraction processes.
38-
39-
### Forest Fires
40-
41-
Percolation models can simulate the spread of forest fires, aiding in the development of strategies for fire prevention and control.
23+
* **Material Science**: Percolation theory helps in understanding the properties of composite materials, such as conductivity and strength. For example, the electrical conductivity of a composite material can change dramatically when the concentration of conductive filler reaches the percolation threshold
24+
* **Epidemiology**: In the study of disease spread, percolation models can predict the outbreak and spread of epidemics. The percolation threshold can represent the critical point at which a disease becomes widespread in a population
25+
* **Network Theory**: Percolation theory is used to study the robustness and connectivity of networks, such as the internet or social networks. It helps in understanding how networks can be disrupted and how they can be made more resilient
26+
* **Geophysics**: In oil recovery, percolation theory models the flow of fluids through porous rocks, helping to optimize extraction processes
27+
* **Forest Fires**: Percolation models can simulate the spread of forest fires, helping in the development of strategies for fire prevention and control
28+
.
4229

4330
## Python Simulation Code
4431

4532
Here is a simple example of a site percolation simulation on a square lattice in Python:
4633

4734
```python
35+
# -*- coding: utf-8 -*-
36+
"""
37+
Created on Wed Jun 19 07:15:50 2024
38+
39+
@author: stefa
40+
"""
41+
4842
import numpy as np
4943
import matplotlib.pyplot as plt
5044
import scipy.ndimage
@@ -55,34 +49,93 @@ def generate_lattice(n, p):
5549

5650
def percolates(lattice):
5751
"""Check if the lattice percolates."""
52+
intersection = get_intersection(lattice)
53+
return intersection.size > 1
54+
55+
def get_intersection(lattice):
56+
"""Check if the bottom labels or top labels have more than 1 value equal """
5857
labeled_lattice, num_features = scipy.ndimage.label(lattice)
5958
top_labels = np.unique(labeled_lattice[0, :])
6059
bottom_labels = np.unique(labeled_lattice[-1, :])
61-
return np.intersect1d(top_labels, bottom_labels).size > 1
60+
print(top_labels, bottom_labels, np.intersect1d(top_labels, bottom_labels).size)
61+
return np.intersect1d(top_labels, bottom_labels)
6262

6363
def plot_lattice(lattice):
6464
"""Plot the lattice."""
6565
plt.imshow(lattice, cmap='binary')
6666
plt.show()
67+
68+
def lattice_to_image(lattice):
69+
"""Convert the lattice in an RGB image (even if will be black and white)"""
70+
r_ch = np.where(lattice, 0, 255)
71+
g_ch = np.where(lattice, 0, 255)
72+
b_ch = np.where(lattice, 0, 255)
73+
74+
image = np.concatenate((
75+
np.expand_dims(r_ch, axis=2),
76+
np.expand_dims(g_ch, axis=2),
77+
np.expand_dims(b_ch, axis=2),
78+
), axis=2)
79+
80+
return image
81+
82+
def get_path(lattice):
83+
intersection = get_intersection(lattice)
84+
labeled_lattice, num_features = scipy.ndimage.label(lattice)
85+
print(intersection)
86+
return labeled_lattice == intersection[1]
6787

68-
# Parameters
69-
n = 100 # Lattice size
70-
p = 0.6 # Site vacancy probability
88+
def add_path_img(image, path):
89+
blank_image = np.zeros(image.shape)
90+
# set the red channel to 255-> get a red percolation path
91+
image[path, 0] = 255
92+
image[path, 1] = 20
93+
return image
94+
7195

72-
# Generate and plot lattice
73-
lattice = generate_lattice(n, p)
74-
plot_lattice(lattice)
7596

76-
# Check percolation
77-
if percolates(lattice):
78-
print("The system percolates.")
79-
else:
80-
print("The system does not percolate.")
97+
# Parameters
98+
n = 100 # Lattice size
99+
p_values = [0.2, 0.3, 0.4, 0.5, 0.58, 0.6] # Site vacancy probabilities
100+
101+
# Create a figure with subplots
102+
fig, axs = plt.subplots(2, 3, figsize=(15, 8))
103+
axs = axs.flatten()
104+
105+
106+
# Plot lattices for different p values
107+
for i, p in enumerate(p_values):
108+
lattice = generate_lattice(n, p)
109+
lattice_img = lattice_to_image(lattice)
110+
if percolates(lattice):
111+
axs[i].set_title(f"p = {p} (Percolates)")
112+
path = get_path(lattice)
113+
lattice_img = add_path_img(lattice_img, path)
114+
else:
115+
axs[i].set_title(f"p = {p} (Does not percolate)")
116+
axs[i].imshow(lattice_img)
117+
axs[i].axis('off')
118+
119+
# Adjust spacing between subplots
120+
plt.subplots_adjust(wspace=0.1, hspace=0.1)
121+
122+
# Show the plot
123+
plt.show()
81124
```
82125

83126
This code generates a square lattice of size `n` with site vacancy probability `p`, checks if the lattice percolates (i.e., if there is a connected path from the top to the bottom), and plots the lattice.
84127

85-
## GitHub Repositories
128+
In further version, also a connected path from left to right can be considered.
129+
130+
### Results
131+
{{< img src="/posts/physics/percolation/images/percolation_plot.png" align="center" title="Results">}}
132+
133+
## Conclusion
134+
The previous plot shows that with _p>0.58_ a percolation path starts to be observed. However, this is so not alwasy happening for stochastical reasons. Hence that plot is the result of several iteration to find the most interesting plot. With _p>0.60_ percolation happens more than 90% of the time.
135+
136+
In further articles we will explore some [python libraries](https://pypercolate.readthedocs.io/en/stable/) to develop a more advanced and practical example.
137+
138+
<!-- ## GitHub Repositories
86139
87140
For more advanced simulations and visualizations, you can refer to the following GitHub repositories:
88141
@@ -92,7 +145,6 @@ For more advanced simulations and visualizations, you can refer to the following
92145
These resources provide a comprehensive starting point for understanding and simulating percolation processes using Python.
93146
94147
Citations:
95-
[1] https://www.routledge.com/Introduction-To-Percolation-Theory-Second-Edition/Stauffer-Aharony/p/book/9780748402533
96148
[2] https://introcs.cs.princeton.edu/python/24percolation/
97149
[3] https://github.com/mrbrianevans/percolation
98150
[4] https://arxiv.org/pdf/1709.01141.pdf
@@ -101,4 +153,4 @@ Citations:
101153
[7] https://www.math.chalmers.se/~steif/perc.pdf
102154
[8] https://github.com/dh4gan/percolation-model
103155
[9] https://en.wikipedia.org/wiki/Percolation_theory
104-
[10] https://www.taylorfrancis.com/books/mono/10.1201/9781315274386/introduction-percolation-theory-ammon-aharony-dietrich-stauffer
156+
[10] https://www.taylorfrancis.com/books/mono/10.1201/9781315274386/introduction-percolation-theory-ammon-aharony-dietrich-stauffer -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Wed Jun 19 07:15:50 2024
4+
5+
@author: stefano
6+
"""
7+
8+
import numpy as np
9+
import matplotlib.pyplot as plt
10+
import scipy.ndimage
11+
12+
def generate_lattice(n, p):
13+
"""Generate an n x n lattice with site vacancy probability p."""
14+
return np.random.rand(n, n) < p
15+
16+
def percolates(lattice):
17+
"""Check if the lattice percolates."""
18+
intersection = get_intersection(lattice)
19+
return intersection.size > 1
20+
21+
def get_intersection(lattice):
22+
"""Check if the bottom labels or top labels have more than 1 value equal """
23+
labeled_lattice, num_features = scipy.ndimage.label(lattice)
24+
top_labels = np.unique(labeled_lattice[0, :])
25+
bottom_labels = np.unique(labeled_lattice[-1, :])
26+
print(top_labels, bottom_labels, np.intersect1d(top_labels, bottom_labels).size)
27+
return np.intersect1d(top_labels, bottom_labels)
28+
29+
def plot_lattice(lattice):
30+
"""Plot the lattice."""
31+
plt.imshow(lattice, cmap='binary')
32+
plt.show()
33+
34+
def lattice_to_image(lattice):
35+
"""Convert the lattice in an RGB image (even if will be black and white)"""
36+
r_ch = np.where(lattice, 0, 255)
37+
g_ch = np.where(lattice, 0, 255)
38+
b_ch = np.where(lattice, 0, 255)
39+
40+
image = np.concatenate((
41+
np.expand_dims(r_ch, axis=2),
42+
np.expand_dims(g_ch, axis=2),
43+
np.expand_dims(b_ch, axis=2),
44+
), axis=2)
45+
46+
return image
47+
48+
def get_path(lattice):
49+
intersection = get_intersection(lattice)
50+
labeled_lattice, num_features = scipy.ndimage.label(lattice)
51+
print(intersection)
52+
return labeled_lattice == intersection[1]
53+
54+
def add_path_img(image, path):
55+
blank_image = np.zeros(image.shape)
56+
# set the red channel to 255-> get a red percolation path
57+
image[path, 0] = 255
58+
image[path, 1] = 20
59+
return image
60+
61+
62+
63+
# Parameters
64+
n = 100 # Lattice size
65+
p_values = [0.2, 0.3, 0.4, 0.5, 0.58, 0.6] # Site vacancy probabilities
66+
67+
# Create a figure with subplots
68+
fig, axs = plt.subplots(2, 3, figsize=(15, 8))
69+
axs = axs.flatten()
70+
71+
72+
# Plot lattices for different p values
73+
for i, p in enumerate(p_values):
74+
lattice = generate_lattice(n, p)
75+
lattice_img = lattice_to_image(lattice)
76+
if percolates(lattice):
77+
axs[i].set_title(f"p = {p} (Percolates)")
78+
path = get_path(lattice)
79+
lattice_img = add_path_img(lattice_img, path)
80+
else:
81+
axs[i].set_title(f"p = {p} (Does not percolate)")
82+
axs[i].imshow(lattice_img)
83+
axs[i].axis('off')
84+
85+
# Adjust spacing between subplots
86+
plt.subplots_adjust(wspace=0.1, hspace=0.1)
87+
plt.tight_layout()
88+
89+
# Show the plot
90+
plt.show()
91+
plt.savefig("images/percolation_plot.png", dpi=300)

data/en/sections/skills.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# section information
2+
section:
3+
name: Skills
4+
id: skills
5+
enable: true
6+
weight: 2
7+
showOnNavbar: true
8+
# Can optionally hide the title in sections
9+
# hideTitle: true
10+
11+
# Your Skills.
12+
# Give a summary of you each skill in the summary section.
13+
skills:
14+
- name: Kubernetes
15+
logo: /images/sections/skills/kubernetes.png
16+
summary: "Capable of deploying, managing application on Kubernetes. Experienced in writing Kubernetes controllers for CRDs."
17+
url: "https://kubernetes.io/"
18+
19+
- name: Go Development
20+
logo: /images/sections/skills/go.png
21+
summary: "Using as the main language for professional development. Capable of writing scalable, testable, and maintainable program."
22+
url: "https://golang.org/"
23+
24+
- name: Cloud Computing
25+
logo: /images/sections/skills/cloud.png
26+
summary: "Worked with most of the major clouds such as GCP, AWS, Azure etc."
27+
28+
- name: Docker
29+
logo: /images/sections/skills/docker.svg
30+
summary: "Write most of the programs as dockerized container. Experienced with multi-stage, multi-arch build process."
31+
url: "https://www.docker.com/"
32+
33+
- name: Prometheus
34+
logo: /images/sections/skills/prometheus.png
35+
summary: "Capable of setup, configure Prometheus metrics. Experienced with PromQL, AlertManager. Also, experienced with writing metric exporters."
36+
url: "https://prometheus.io/"
37+
38+
- name: Linux
39+
logo: /images/sections/skills/linux.png
40+
summary: "Using as the main operating system. Capable of writing bash/shell scripts."
41+
42+
- name: Git
43+
logo: /images/sections/skills/git.png
44+
summary: "Experienced with git-based development. Mostly, use Github. Also, have experience in working with GitLab."
45+
url: "https://git-scm.com/"
46+
47+
- name: C++
48+
logo: /images/sections/skills/c++.png
49+
summary: "Know basic C/C++ programming. Used for contest programming and problem solving."

public/404.html

+17
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@
156156

157157

158158

159+
<li class="nav-item">
160+
<a class="nav-link" href="/#skills">Skills</a>
161+
</li>
162+
163+
164+
165+
166+
159167
<li class="nav-item">
160168
<a class="nav-link" href="/#experiences">Experiences</a>
161169
</li>
@@ -371,6 +379,15 @@ <h5>Navigation</h5>
371379

372380

373381

382+
<li class="nav-item">
383+
<a class="smooth-scroll" href="http://localhost:1313/#skills">Skills</a>
384+
</li>
385+
386+
387+
388+
389+
390+
374391
<li class="nav-item">
375392
<a class="smooth-scroll" href="http://localhost:1313/#experiences">Experiences</a>
376393
</li>

0 commit comments

Comments
 (0)