-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (50 loc) · 1.72 KB
/
main.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
#!/usr/bin/python3
# %% Loading packages :
# Standard packages :
from __future__ import annotations
import os.path
import numpy as np
import dotb.initiate as init
import dotb.input_yaml as input
import dotb.postt as postt
from dotb.build_model import create_solver
# %% main function definition :
def main():
maindir = os.path.dirname(__file__)
# default_input = 'ballistic_default_input.yaml'
# default_input = 'rabbit_default_input.yaml'
default_input = 'diffusion_2D_default_input.yaml'
# Reading argument :
config_file_path = input.get_config_file(maindir, default_input)
print(f'Using config file: {config_file_path}')
# input.yaml --> config dict
config = input.load_config(config_file_path)
# Checking the types of the input variables :
# (conformity to TypedDict classes?)
input.check_type(config)
# y-initialization :
print('Initializing problem ...')
y, t, config = init.intiate_y(config)
# ... then re-checked :
input.check_type(config)
# Check time step value (diffusion only : CFL) to avoid divergence :
print('Checking input data types...')
input.check_time_step(config)
# Solver creation :
print(
f"Solving the {config['case']} case \n using the {config['solver']} solver",
)
simu = create_solver(y, t, config)
# Run simulation :
sol = simu.solve(**config)
print(f'Number of saved time steps = {np.shape(sol)[0]}')
print(f'sol.shape = {sol.shape}')
# Post-treatment :
print(f'Postreatment...')
t_save = np.linspace(0., config['t_end'], len(sol))
postt.plot_postt(t_save, sol, **config)
# %% direct execution :
if __name__ == '__main__':
main()
else:
print('This script was imported')