Skip to content

Commit 6831d44

Browse files
committed
Model and solver setting
1 parent 8b7378f commit 6831d44

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

python/fd_string_model.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class FD_string_model(Model):
3030
def __init__(self, sr = 44100, **kwargs):
3131
# Copy string parameters first from Default params
3232
# and replace parameters given as kwargs
33-
self.__dict__.update(DEFAULT_STRING_PARAMS)
34-
self.__dict__.update(kwargs)
33+
self.params = DEFAULT_STRING_PARAMS
34+
self.params.update(**kwargs)
35+
self.__dict__.update(self.params)
3536
self.fill_intermediary_physical_params()
3637

3738
# Samplerate, used for choosing the spatial discretization
@@ -61,6 +62,9 @@ def print_perceptual_params(self):
6162
print(r"$f_0 = $" + f"{self.f0}")
6263
print(r"$T_{60}(0) = $" + f"{self.T60(0)}")
6364
print(r"$T_{60}(1000) = $" + f"{self.T60(2 * np.pi * 1000)}")
65+
66+
def setting(self):
67+
return {"Name": self.__class__.__name__, "N": self.N, **self.params}
6468

6569
def fill_intermediary_physical_params(self):
6670
self.A = np.pi*self.Ra**2

python/model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ def __init__(self, N = 10):
2424
# Both functions are called at the same time in the solver,
2525
# in some cases it is then computationally interesting
2626
# to compute both in the same function.
27-
self.EandFnl = lambda q: (self.Enl(q), self.Fnl(q))
27+
self.EandFnl = lambda q: (self.Enl(q), self.Fnl(q))
28+
29+
def setting(self):
30+
return {"Name": self.__class__.__name__, "N": self.N}

python/results_storage.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ def __init__(self, **kwargs):
2929
self.__dict__.update(DEFAULT_STORAGE_CONFIG)
3030
self.__dict__.update(kwargs)
3131

32-
def reserve(self, t, model):
32+
def reserve(self, t, model, solver):
3333
self.t = t
3434
self.Nt = len(t)
3535

36+
if self.SolverSetting:
37+
self.solver_dict = solver.setting()
38+
39+
if self.ModelSetting:
40+
self.model_dict = model.setting()
41+
print(self.model_dict)
42+
3643
# Force energy to be computed if power is needed
3744
if self.Power:
3845
self.Energy = True

python/sav_solver.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, model, sr = 44100, lambda0 = 0):
2020
# Shifting constant
2121
self. C0 = 0
2222
# Control parameter
23-
self.lamba0 = lambda0
23+
self.lambda0 = lambda0
2424
# Numerical epsilon
2525
self.Num_eps = 1e-16
2626

@@ -38,6 +38,13 @@ def __init__(self, model, sr = 44100, lambda0 = 0):
3838
### Check dimensions ###
3939
self.check_sizes()
4040

41+
def setting(self):
42+
"""Returns a dictionnary with solver settings.
43+
Returns:
44+
(dict): solver setings
45+
"""
46+
return {"sr": self.sr, "dt": self.dt, "num_eps": self.Num_eps, "C0": self.C0, "lambda0": self.lambda0}
47+
4148
def check_sizes(self):
4249
"""Checks that the underlying model has coherent matrices and operators
4350
shapes.
@@ -324,7 +331,7 @@ def g_mod(self, q, p, r):
324331
vector: g_mod(q,p, r)
325332
"""
326333
self.epsilon = r - np.sqrt(2 * self.model.Enl(q) + self.C0)
327-
return - self.lamba0 * self.epsilon * self.model.M * np.sign(p) / (np.abs(p) + self.Num_eps)
334+
return - self.lambda0 * self.epsilon * self.model.M * np.sign(p) / (np.abs(p) + self.Num_eps)
328335

329336
### Time stepping and integration ###
330337

@@ -385,7 +392,7 @@ def integrate(self, q0, u0, u_func, duration, ConstantRmid = False,
385392
self.t = np.arange(self.model.Nt) * self.dt
386393

387394
self.storage = ResultsStorage(**storage_config)
388-
self.storage.reserve(self.t, self.model)
395+
self.storage.reserve(self.t, self.model, self)
389396
self.plotter = Plotter(**plotter_config)
390397
self.plotter.init_plots()
391398

0 commit comments

Comments
 (0)