diffenix 0.0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,265 @@
1
+ from __future__ import annotations
2
+ import gc
3
+ from typing import Any
4
+
5
+ import numpy as np
6
+
7
+ # from generation_configs import directory
8
+ from diffenix.systems import *
9
+ import pandas as pd
10
+
11
+
12
+ def new_simulation(consts_params: dict = None, directory_params: str = None) -> tuple[str, dict[str, Any]]:
13
+ """
14
+ Add directories/files needed to save the new simulation
15
+
16
+ Parameters
17
+ ----------
18
+
19
+ consts_params : dict, optional
20
+ The dictionary with all constantes and parameter for the simulation, default use the globals values defined in
21
+ Constantes.py
22
+ directory_params : str, optional
23
+ The path to a directory containing several .npz files for a given set of constants. The first non integrated
24
+ set of constant will be used for this new simulation
25
+
26
+ Returns
27
+ -------
28
+ tuple[str, dict[str, Any]]
29
+ the name of the new simulation's directory
30
+ the dictionary with all the constants
31
+
32
+ """
33
+ data: pd.DataFrame = pd.read_csv(results + "/informations.csv")
34
+ # All the keys informations about the simulations are stored into this csv file
35
+ print("data.Simulation : ", data.Simulation)
36
+ if len(data.Simulation) > 0:
37
+ n: int = int(data.Simulation.values[-1][11:])
38
+ else:
39
+ n: int = 0
40
+
41
+ if directory_params is not None:
42
+ if not os.path.exists(directory_params):
43
+ raise UserWarning("New simulation : the path to the directory containing the sets of constantes :",
44
+ directory_params, " doesn't exist")
45
+ l = os.listdir(directory_params)
46
+ l.sort()
47
+ name_consts = l.pop()
48
+ consts_params = dict(np.load(directory_params + "/" + name_consts))
49
+ while len(l) > 0 and str(consts_params["Simulation"]) in data["Simulation"]:
50
+ name_consts = l.pop()
51
+ consts_params = dict(np.load(directory_params + "/" + name_consts))
52
+ if len(l) == 0:
53
+ raise UserWarning("new_simulation : All the sets of parameters as already been integrated")
54
+ elif consts_params is None:
55
+ consts_params: dict[str, Any] = constantes() # The dictionary with all the necessary constantes
56
+
57
+ if "Simulation" in consts_params.keys():
58
+ if "Simulation_" not in str(consts_params["Simulation"]):
59
+ name: str = "Simulation_" + str(consts_params["Simulation"])
60
+ else:
61
+ name: str = str(consts_params["Simulation"])
62
+ else:
63
+ name: str = "Simulation_" + str(n + 1)
64
+ simulation: dict[str, Any] = {"Simulation": np.array(name)}
65
+
66
+ os.mkdir(results + "/" + name) # Creating the new directory
67
+ np.savez_compressed(results + "/" + name + "/interrupteur", {})
68
+ consts_params["Simulation"] = name
69
+ consts_params["directory"] = results + "/" + name
70
+ consts_params["n_simu"] = n + 1
71
+ d_enrg: dict[str, np.ndarray] = dict()
72
+ for k in consts_params.keys():
73
+ d_enrg[k] = np.array(consts_params[k])
74
+ np.savez_compressed(results + "/" + name + "/Constantes", d_enrg)
75
+ simulation.update(d_enrg)
76
+ del simulation["a_planets"]
77
+ del simulation["m_planets"]
78
+ simulation["nb_planets"] = len(d_enrg["a_planets"])
79
+ data: pd.DataFrame = pd.concat([data, pd.DataFrame(simulation, index=[0])], ignore_index=True)
80
+
81
+ # The table to be saved as the new information csv file
82
+ data.to_csv(results + "/informations.csv", index=False) # Saving the information file
83
+
84
+ return results + "/" + name, consts_params
85
+
86
+
87
+ def time_integration(tf: np.float64 = 100 * Myr, save_time_step: np.float64 = 0.1 * Myr,
88
+ consts_params: dict = None, directory_params: str = None,
89
+ integrate_only_surface_density: bool = False
90
+ ) -> Sol:
91
+ """
92
+ Build a new simulation and integrate it until tf
93
+
94
+ Parameters
95
+ ----------
96
+ tf : np.float64, optional, default = 10 Myr
97
+
98
+ save_time_step : np.float64, optional, default = 0.1 Myr
99
+ The time-steps to save the simulation
100
+
101
+ consts_params : dict, optional
102
+ The dictionary with all constantes and parameter for the simulation, default use the globals values defined in
103
+ Constantes.py
104
+
105
+ directory_params : str, optional
106
+ The path to a directory containing several .npz files for a given set of constants. The first non integrated
107
+ set of constant will be used for this new simulation
108
+
109
+ integrate_only_surface_density : bool, optional, default=False
110
+ To integrate only the evolution of surfaces densitys
111
+
112
+ Returns
113
+ -------
114
+ Sol
115
+ The new simulation
116
+
117
+ """
118
+ # if consts_params is None and directory_params is None and os.path.exists("./configs"):
119
+ # try:
120
+ # simulation, d = new_simulation(directory_params="./configs")
121
+ # except UserWarning:
122
+ # # All the set of constantes has already been integrated
123
+ # simulation, d = new_simulation()
124
+ # else:
125
+ # simulation, d = new_simulation(consts_params=consts_params, directory_params=directory_params)
126
+ if consts_params is None or "Simulation" not in consts_params.keys():
127
+ simulation, d = new_simulation(consts_params=consts_params, directory_params=directory_params)
128
+ else:
129
+ os.mkdir(results + "/" + consts_params["Simulation"]) # Creating the new directory
130
+ np.savez_compressed(results + "/" + consts_params["Simulation"] + "/interrupteur", {})
131
+ consts_params["directory"] = results + "/" + consts_params["Simulation"]
132
+ consts_params["n_simu"] = int(str(consts_params["Simulation"])[11:])
133
+ d = consts_params.copy()
134
+ print("Initialization of ", d["Simulation"])
135
+ sol = Sol(consts=d)
136
+ nu0: np.float64 = (Rgp * T0(sol.t0, sol.a0, sol.Ms) * sol.alpha * (sol.a0 ** (3 / 2))
137
+ / (sol.mu.mean() * np.sqrt(G * sol.Ms)))
138
+ dtmax: np.float64 = min(np.min((sol.r[1:] - sol.r[:-1]) * (sol.r[1:] - sol.r[:-1])
139
+ / (nu0 * ((((sol.r[1:] + sol.r[:-1]) / 2) / sol.a0) ** (3 / 2 + sol.pls_temp)))),
140
+ 60. * yr)
141
+ # dtmax: np.float64 = min((sol.r[1:] - sol.r[:-1]) * (sol.r[1:] - sol.r[:-1]) / nu(sol)[1:])
142
+ # The maximum timestep to avoid instability in numerical integration
143
+
144
+ print("dtmax=", dtmax / (C_t * 3600 * 34 * 365.25))
145
+ print("Minimum number of temporal steps:", int(tf / dtmax), "dtmax=", dtmax / (C_t * 3600 * 24 * 365.25), "y")
146
+
147
+ if tf < yr:
148
+ sol.time_integration(tf, dtmax=dtmax, integrate_only_surface_density=integrate_only_surface_density)
149
+ elif tf < 0.5 * Myr:
150
+ sol.time_integration(tf, dtmax=dtmax, integrate_only_surface_density=integrate_only_surface_density)
151
+ else:
152
+ for i in range(1, int(tf / save_time_step) + 1):
153
+ tfi = min(tf, i * save_time_step)
154
+ print("tfi ", tfi / Myr, " Myr")
155
+ sol.time_integration(tfi, dtmax=dtmax, integrate_only_surface_density=integrate_only_surface_density)
156
+ return sol
157
+
158
+
159
+ def restart(number: int | str, tf: np.float64 = 0.1 * Gyr, save_time_step : np.float64 = 0.1 * Myr,
160
+ rtol: np.float64 = None, method: str = None,
161
+ integrate_only_surface_density : bool = False) -> Sol:
162
+ """
163
+ Restart the simulation number
164
+
165
+ Parameters
166
+ ----------
167
+ number : int
168
+ The number of the simulation to be restarted
169
+
170
+ tf : np.float64, optional, default = 10 Myr
171
+
172
+ save_time_step : np.float64, optional, default = 0.1 Myr
173
+ The time-steps to save the simulation
174
+
175
+ integrate_only_surface_density : bool, optional, default=False
176
+ To integrate only the evolution of surfaces densitys
177
+
178
+ Returns
179
+ -------
180
+ Sol
181
+ The integrated solution
182
+
183
+ """
184
+ if isinstance(number, int):
185
+ name: str = "Simulation_" + str(number)
186
+ print("Restarting simulation : ", number)
187
+ else:
188
+ print("Restarting ", number)
189
+ name = number
190
+
191
+
192
+ if os.path.exists(results + "/" + name + "/infos.npz"):
193
+ infos: dict = dict(np.load(results + "/" + name + "/infos.npz"))
194
+ if infos["status"] == "integrating":
195
+ raise UserWarning("The simulation is already being integrated by another process")
196
+ elif infos["status"] == "integreted":
197
+ raise UserWarning("The simulation has already been integrated until the end")
198
+ infos["status"] = "integrating"
199
+ np.savez_compressed(results + "/" + name + "/infos.npz", **infos)
200
+ else:
201
+ infos: dict = {"status": "integrating"}
202
+ np.savez_compressed(results + "/" + name + "/infos.npz", **infos)
203
+
204
+ sol = Sol(directory=results + '/' + name, filename="Simulation_diffusion")
205
+ if rtol is not None:
206
+ sol.rtol = rtol
207
+ if method is not None:
208
+ sol.method = method
209
+ nu0: np.float64 = (Rgp * T0(sol.t0, sol.a0, sol.Ms) * sol.alpha * (sol.a0 ** (3 / 2))
210
+ / (sol.mu.mean() * np.sqrt(G * sol.Ms)))
211
+ dtmax: np.float64 = min(np.min((sol.r[1:] - sol.r[:-1]) * (sol.r[1:] - sol.r[:-1])
212
+ / (nu0 * ((((sol.r[1:] + sol.r[:-1]) / 2) / sol.a0) ** (3 / 2 + sol.pls_temp)))),
213
+ 1 * yr)
214
+ # The maximum timestep to avoid instability in numerical integration
215
+
216
+ print("Minimum number of temporal steps:", int(tf / dtmax), "dtmax=", dtmax / (C_t * 3600 * 24 * 365.25), "y")
217
+ if not integrate_only_surface_density:
218
+ t0: np.float64 = sol.tps_mf[-1]
219
+ else:
220
+ t0: np.float64 = sol.tps[-1]
221
+
222
+ gc.enable()
223
+ if tf < 0 and t0 < 1e3 * Myr:
224
+ tfi = t0 + save_time_step
225
+ print("tfi ", tfi / Myr, " Myr")
226
+ gc.collect()
227
+ sol.time_integration(tfi, dtmax=dtmax, integrate_only_surface_density=integrate_only_surface_density)
228
+ gc.collect()
229
+ else:
230
+ for i in range(int(t0 / save_time_step) + 1,
231
+ int(tf / save_time_step) + 1):
232
+ tfi = min(tf, i * save_time_step)
233
+ print("tfi ", tfi / Myr, " Myr")
234
+ gc.collect()
235
+ sol.time_integration(tfi, dtmax=dtmax, integrate_only_surface_density=integrate_only_surface_density)
236
+ gc.collect()
237
+ if sol.tps_mf[-1] < 100 * Myr:
238
+ infos["status"] = "done"
239
+ else:
240
+ infos["status"] = "integreted"
241
+ np.savez_compressed(results + "/" + name + "/infos.npz", **infos)
242
+
243
+ return sol
244
+
245
+
246
+ if __name__ == '__main__':
247
+ import sys
248
+ if len(sys.argv) > 1:
249
+ import os
250
+ if sys.argv[1] == "configs":
251
+ l = os.listdir("../configs")
252
+ l.sort()
253
+ if int(sys.argv[2]) < len(l):
254
+ params = dict(np.load("./configs/" + l[int(sys.argv[2])]))
255
+ print(int(sys.argv[2]), l[int(sys.argv[2])], params["Simulation"])
256
+ if not os.path.exists(results + "/" + params["Simulation"]):
257
+ time_integration(consts_params=params)
258
+ # else:
259
+ # restart(params["Simulation"], rtol=np.double(1e-4))
260
+ else:
261
+ print("argv :", sys.argv[1])
262
+ restart(int(sys.argv[1]), tf=100 * Myr, save_time_step=0.1 * Myr)
263
+ else:
264
+ time_integration()
265
+
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: diffenix
3
+ Version: 0.0.0.1
4
+ Summary: A library to model the gas evolution in debris discs
5
+ Author: Paul Huet
6
+ Dynamic: author
7
+ Dynamic: summary
@@ -0,0 +1,14 @@
1
+ diffenix/Constantes.py,sha256=6mBDCzvDqZ8KX1rEKkdUDR6XXq1e4AhcUsWy0AWJTu8,45866
2
+ diffenix/__init__.py,sha256=TztB5JMh0YGjc64vwDd9R-71vsdL0V1PaKl8MdpKNGQ,915
3
+ diffenix/chemains.py,sha256=OV82Qjlf8_nkbtqpYuNEJ76rxBDjOEHI-cJ4ALE-14c,4728
4
+ diffenix/classes.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ diffenix/generation_configs.py,sha256=B4XE9uyFNbdB7qK2DMfRCFxYVPAU7iwOilK2aDh-QzQ,7325
6
+ diffenix/méthodes_numériques.py,sha256=lcU77pYxeuaww_Slrqu-ep-uwv5qWRC__u-Z7yxHMCI,14508
7
+ diffenix/numericals_methods.py,sha256=tiOne2CnmeCj5CrMuvhEJdaBueAqJ8q_rsyzQ16ZCC0,8373
8
+ diffenix/solve_asteroid_belt.py,sha256=LHtIwTnFe8jLu3U0DXgraUdhrboq7Y2AK2NTdNPdrqo,65013
9
+ diffenix/systems.py,sha256=mVNvaajN61Hoyiwdb0zyrIxK0XER-d_bSD4ctV5wypQ,382483
10
+ diffenix/time_integration.py,sha256=-yyxQnUhAcbm4PouWw59u1cmWAfdwwhH9zNIFC2lme4,11031
11
+ diffenix-0.0.0.1.dist-info/METADATA,sha256=CmXa_WOd5bJSUc2DZBLvC1vz9jeS1Ce1qQbLPJBPnu8,167
12
+ diffenix-0.0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
13
+ diffenix-0.0.0.1.dist-info/top_level.txt,sha256=78gE5UGJOhOq292oiBoqZPxghvkyiIlEOXZoPAjp1KM,9
14
+ diffenix-0.0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ diffenix