-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaffichages.py
153 lines (128 loc) · 4.49 KB
/
affichages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/python3
# coding: utf-8
"""
affichages.py : Debye-Huckel (finite differences), Poisson-Boltzmann (finite differences and multidimensional Newton)
"""
import matplotlib.pyplot as plt
import numpy as np
from solveurs import (
solve_debye_huckel,
solve_poisson_boltzmann_differences_finies,
solve_poisson_boltzmann_newton,
)
plt.style.use("ggplot")
def plot_solution(x, u, mu, system, method):
"""
Affichage des couples (xi, ui)
"""
plt.plot(x, u, label=f"{system} mu = {mu}")
plt.xlabel("Points de discrétisations $x_i$")
plt.ylabel("Solutions ponctuelles $u_i$")
plt.title(f"{method} pour l'équation de {system}")
plt.legend()
def plot_solution_poisson_boltzmann(n, mu, solveur_poisson_boltzmann, method):
x, u, k = solveur_poisson_boltzmann(n, mu)
print(f"k vaut {k} pour n = {n} et mu = {mu}")
plot_solution(x, u, mu, system=f"{solveur_poisson_boltzmann.__name__}", method=method)
def plot_solution_debye_huckel(
n,
mu,
solveur_debye_huckel=solve_debye_huckel,
method="Schéma aux différences finies",
):
x, u, _ = solveur_debye_huckel(n=n, mu=mu)
plot_solution(x, u, mu, system="Debye-Huckel", method=method)
def plot_comparison_finite_differences(n, mu):
plot_solution_poisson_boltzmann(
n,
mu,
solve_poisson_boltzmann_differences_finies,
"Schéma aux différences finies",
)
plot_solution_debye_huckel(n, mu)
plt.title(f"Comparaison des solutions pour mu = {mu} et n = {n}")
def plot_comparison_newton(n, mu):
plot_solution_poisson_boltzmann(
n, mu, solve_poisson_boltzmann_newton, "Méthode de newton",
)
plot_solution_poisson_boltzmann(
n,
mu,
solve_poisson_boltzmann_differences_finies,
"Schéma aux différences finies",
)
plt.title(f"Comparaison des solutions pour mu = {mu} et n = {n}")
def plot_discretisation_debye_huckel(mu, solveur_debye_huckel=solve_debye_huckel):
"""
Etude de l'influence du pas de discrétisation
"""
u0, h = [], []
for n in [10, 15, 30, 70, 100, 1000, 10000]:
_, u, _ = solveur_debye_huckel(n, mu=mu)
# plot_solution(x, u, mu, "", "")
# plt.show()
u0.append(u[0])
h.append(10 / n)
# print(h, u0)
plt.plot(h, u0, "o", label="$u_0$")
plt.xlabel("Pas de discrétisations $h$")
plt.ylabel("Solutions ponctuelles $u_0$")
plt.title("Influence du pas de la discrétisation")
plt.legend()
def plot_variations_mu_debye_huckel():
fig = plt.figure()
for mu in np.linspace(0.1, 6.4, 10):
mu = round(mu, 3)
plot_solution_debye_huckel(1000, mu)
title = f"plots/debye_mu_variations"
plt.title(title)
fig.savefig(title + ".png")
def plot_variations_mu_poisson_boltzmann(solveur_poisson_boltzmann, method):
"""
Au dela de mu = 6.4 :
RuntimeWarning: overflow encountered in sinh
RuntimeWarning: invalid value encountered in double_scalars
g = lambda x: np.sinh(x) - x
RESOLVED avec math.sinh
"""
fig = plt.figure()
for mu in np.linspace(0.1, 6.4, 10):
mu = round(mu, 3)
plot_solution_poisson_boltzmann(1000, mu, solveur_poisson_boltzmann, method)
title = f"plots/poisson_mu_variations_{solveur_poisson_boltzmann.__name__}"
plt.title(title)
fig.savefig(title + ".png")
# pour mu = 5.7 et mu = 6.4 on retombe ie. diverge
def plot_variations_mu_superposed_differences_finies():
for mu in np.linspace(0.1, 6.4, 10):
mu = round(mu, 3)
fig = plt.figure()
plot_solution_debye_huckel(1000, mu)
plot_solution_poisson_boltzmann(
1000,
mu,
solve_poisson_boltzmann_differences_finies,
"Schéma aux différences finies",
)
title = f"plots/superposed_mu{mu}_differences_finies"
plt.title(title)
fig.savefig(title + ".png")
def plot_variations_mu_superposed_newton():
for mu in np.linspace(0.1, 6.4, 10):
mu = round(mu, 3)
fig = plt.figure()
plot_solution_poisson_boltzmann(
1000,
mu,
solve_poisson_boltzmann_newton,
"Méthode de Newton",
)
plot_solution_poisson_boltzmann(
1000,
mu,
solve_poisson_boltzmann_differences_finies,
"Schéma aux différences finies",
)
title = f"plots/superposed_mu{mu}_newton"
plt.title(title)
fig.savefig(title + ".png")