-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_mesh.py
49 lines (41 loc) · 1.73 KB
/
make_mesh.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
import numpy as np
class FiniteVolumeMesh(object):
def __init__(self, param, Nr=101, N_pts=51, t_steps=100, t_final=3600):
"""
Generates the meshes used for the Finite Volume discretisation, as well
as the array of times at which the solution is to be calculated.
Parameters
----------
param: object
Object containing model parameters.
Nr: int
Number of meshpoints in the radial grid.
N_pts: int
Target number of meshpoints in the x-direction component grids.
t_steps: int
Number of timesteps at which the solution is to be computed.
t_final: int
Simulation stopping time in seconds.
"""
# Set spherical grid
self.Nr = Nr
self.r = np.linspace(0, 1, Nr)
self.dr = self.r[1] - self.r[0]
# Aim to make grid as uniform as possible
targetmeshsize = min(param.L_n, param.L_s, param.L_p) / N_pts
# Negative electrode grid
self.Nx_n = round(param.L_n / targetmeshsize) + 1
self.x_n = np.linspace(0.0, param.L_n, self.Nx_n)
self.dx_n = self.x_n[1] - self.x_n[0]
# Separator grid
self.Nx_s = round(param.L_s / targetmeshsize) + 1
self.x_s = np.linspace(param.L_n, 1 - param.L_p, self.Nx_s)
self.dx_s = self.x_s[1] - self.x_s[0]
# Positive electrode grid
self.Nx_p = round(param.L_p / targetmeshsize) + 1
self.x_p = np.linspace(1 - param.L_p, 1, self.Nx_p)
self.dx_p = self.x_p[1] - self.x_p[0]
# Times to compute solution at
self.t_final = t_final / param.tau_d_star
self.t_steps = t_steps
self.t = np.linspace(0.0, self.t_final, self. t_steps)