Merge remote-tracking branch 'drake/feature/estimate-cfl-timestep'

pull/110/head
Thorsten Liebig 2023-03-19 11:45:14 +01:00
commit c651cce61f
1 changed files with 17 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import numpy as np
from CSXCAD import CSPrimitives
from CSXCAD.Utilities import CheckNyDir, GetMultiDirs
from openEMS.physical_constants import C0
def mesh_combine(mesh1, mesh2, sort=True):
mesh = [None, None, None]
@ -96,3 +97,19 @@ def mesh_hint_from_box(box, dirs, **kw):
return mesh_combine(hint, kw['mesh'])
return hint
def mesh_estimate_cfl_timestep(mesh):
""" mesh_estimate_cfl_timestep(mesh)
Estimate the maximum CFL time step of the given mesh needed to ensure numerical stability,
assuming propagation in pure vacuum.
:returns: the maximum CFL time step, in seconds
"""
invMinDiff = [None, None, None]
for ny in range(3):
invMinDiff[ny] = np.min(np.diff(mesh.GetLines(ny))) ** -2
delta_t = mesh.GetDeltaUnit() / (C0 * np.sqrt(np.sum(invMinDiff)))
return delta_t