emerge 0.6.1__py3-none-any.whl → 0.6.3__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.

Potentially problematic release.


This version of emerge might be problematic. Click here for more details.

@@ -18,7 +18,6 @@
18
18
  import numpy as np
19
19
  from ....elements import Nedelec2
20
20
  from scipy.sparse import csr_matrix, coo_matrix
21
- from numba_progress import ProgressBar, ProgressBarType
22
21
  from ....mth.optimized import local_mapping, matinv, dot_c, cross_c, compute_distances
23
22
  from numba import c16, types, f8, i8, njit, prange
24
23
 
@@ -167,8 +166,7 @@ def tet_mass_stiffness_matrices(field: Nedelec2,
167
166
  nE = edges.shape[1]
168
167
  nTri = tris.shape[1]
169
168
 
170
- with ProgressBar(total=nT, ncols=100, dynamic_ncols=False) as pgb:
171
- dataE, dataB, rows, cols = _matrix_builder(nodes, tets, tris, edges, field.mesh.edge_lengths, tet_to_field, tet_to_edge, ur, er, pgb)
169
+ dataE, dataB, rows, cols = _matrix_builder(nodes, tets, tris, edges, field.mesh.edge_lengths, tet_to_field, tet_to_edge, ur, er)
172
170
 
173
171
  E = coo_matrix((dataE, (rows, cols)), shape=(nE*2 + nTri*2, nE*2 + nTri*2)).tocsr()
174
172
  B = coo_matrix((dataB, (rows, cols)), shape=(nE*2 + nTri*2, nE*2 + nTri*2)).tocsr()
@@ -426,9 +424,8 @@ def ned2_tet_stiff_mass(tet_vertices, edge_lengths, local_edge_map, local_tri_ma
426
424
  i8[:,:],
427
425
  i8[:,:],
428
426
  c16[:,:,:],
429
- c16[:,:,:],
430
- ProgressBarType), cache=True, nogil=True, parallel=True)
431
- def _matrix_builder(nodes, tets, tris, edges, all_edge_lengths, tet_to_field, tet_to_edge, ur, er, pgb: ProgressBar):
427
+ c16[:,:,:]), cache=True, nogil=True, parallel=True)
428
+ def _matrix_builder(nodes, tets, tris, edges, all_edge_lengths, tet_to_field, tet_to_edge, ur, er):
432
429
  nT = tets.shape[1]
433
430
  nedges = edges.shape[1]
434
431
 
@@ -442,8 +439,6 @@ def _matrix_builder(nodes, tets, tris, edges, all_edge_lengths, tet_to_field, te
442
439
 
443
440
  for itet in prange(nT): # ty: ignore
444
441
  p = itet*400
445
- if np.mod(itet,10)==0:
446
- pgb.update(10)
447
442
  urt = ur[:,:,itet]
448
443
  ert = er[:,:,itet]
449
444
 
@@ -18,7 +18,6 @@
18
18
  import numpy as np
19
19
  from ....elements.nedleg2 import NedelecLegrange2
20
20
  from scipy.sparse import csr_matrix
21
- from numba_progress import ProgressBar, ProgressBarType
22
21
  from ....mth.optimized import local_mapping, matinv, compute_distances, gaus_quad_tri
23
22
  from numba import c16, types, f8, i8, njit, prange
24
23
 
@@ -54,8 +53,7 @@ def generelized_eigenvalue_matrix(field: NedelecLegrange2,
54
53
 
55
54
  nodes = field.local_nodes
56
55
 
57
- with ProgressBar(total=nT, ncols=100, dynamic_ncols=False) as pgb:
58
- dataE, dataB, rows, cols = _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0, pgb)
56
+ dataE, dataB, rows, cols = _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0)
59
57
 
60
58
  nfield = field.n_field
61
59
 
@@ -427,9 +425,8 @@ def generalized_matrix_GQ(tri_vertices, local_edge_map, Ms, Mm, k0):
427
425
  i8[:,:],
428
426
  c16[:,:,:],
429
427
  c16[:,:,:],
430
- f8,
431
- ProgressBarType), cache=True, nogil=True, parallel=True)
432
- def _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0, pgb: ProgressBar):
428
+ f8), cache=True, nogil=True, parallel=True)
429
+ def _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0):
433
430
 
434
431
  ntritot = tris.shape[1]
435
432
  nnz = ntritot*196
@@ -443,8 +440,6 @@ def _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0, pgb: ProgressB
443
440
 
444
441
  for itri in prange(ntritot): # type: ignore
445
442
  p = itri*196
446
- if np.mod(itri,10)==0:
447
- pgb.update(10)
448
443
  urt = ur[:,:,itri]
449
444
  ert = er[:,:,itri]
450
445
 
@@ -18,7 +18,6 @@
18
18
  import numpy as np
19
19
  from ....elements.nedleg2 import NedelecLegrange2
20
20
  from scipy.sparse import csr_matrix
21
- from numba_progress import ProgressBar, ProgressBarType
22
21
  from ....mth.optimized import local_mapping, matinv, compute_distances, gaus_quad_tri
23
22
  from numba import c16, types, f8, i8, njit, prange
24
23
 
@@ -54,8 +53,7 @@ def generelized_eigenvalue_matrix(field: NedelecLegrange2,
54
53
 
55
54
  nodes = field.local_nodes
56
55
 
57
- with ProgressBar(total=nT, ncols=100, dynamic_ncols=False) as pgb:
58
- dataE, dataB, rows, cols = _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0, pgb)
56
+ dataE, dataB, rows, cols = _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0)
59
57
 
60
58
  nfield = field.n_field
61
59
 
@@ -427,9 +425,8 @@ def generalized_matrix_GQ(tri_vertices, local_edge_map, Ms, Mm, k0):
427
425
  i8[:,:],
428
426
  c16[:,:,:],
429
427
  c16[:,:,:],
430
- f8,
431
- ProgressBarType), cache=True, nogil=True, parallel=True)
432
- def _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0, pgb: ProgressBar):
428
+ f8), cache=True, nogil=True, parallel=True)
429
+ def _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0):
433
430
 
434
431
  ntritot = tris.shape[1]
435
432
  nnz = ntritot*196
@@ -443,8 +440,6 @@ def _matrix_builder(nodes, tris, edges, tri_to_field, ur, er, k0, pgb: ProgressB
443
440
 
444
441
  for itri in prange(ntritot): # type: ignore
445
442
  p = itri*196
446
- if np.mod(itri,10)==0:
447
- pgb.update(10)
448
443
  urt = ur[:,:,itri]
449
444
  ert = er[:,:,itri]
450
445
 
@@ -254,9 +254,72 @@ class FarfieldData:
254
254
  H: np.ndarray
255
255
  theta: np.ndarray
256
256
  phi: np.ndarray
257
+ ang: np.ndarray | None = None
257
258
 
259
+ @property
260
+ def Ex(self) -> np.ndarray:
261
+ return self.E[0,:]
262
+
263
+ @property
264
+ def Ey(self) -> np.ndarray:
265
+ return self.E[1,:]
266
+
267
+ @property
268
+ def Ez(self) -> np.ndarray:
269
+ return self.E[2,:]
270
+
271
+ @property
272
+ def Hx(self) -> np.ndarray:
273
+ return self.H[0,:]
274
+
275
+ @property
276
+ def Hy(self) -> np.ndarray:
277
+ return self.H[1,:]
278
+
279
+ @property
280
+ def Hz(self) -> np.ndarray:
281
+ return self.H[2,:]
282
+
283
+ @property
284
+ def Etheta(self) -> np.ndarray:
285
+ thx = -np.cos(self.theta)*np.cos(self.phi)
286
+ thy = -np.cos(self.theta)*np.sin(self.phi)
287
+ thz = np.sin(self.theta)
288
+ return thx*self.E[0,:] + thy*self.E[1,:] + thz*self.E[2,:]
289
+
290
+ @property
291
+ def Ephi(self) -> np.ndarray:
292
+ phx = -np.sin(self.phi)
293
+ phy = np.cos(self.phi)
294
+ phz = np.zeros_like(self.theta)
295
+ return phx*self.E[0,:] + phy*self.E[1,:] + phz*self.E[2,:]
296
+
297
+ @property
298
+ def Erhcp(self) -> np.ndarray:
299
+ return (self.Etheta - 1j*self.Ephi)/np.sqrt(2)
300
+
301
+ @property
302
+ def Elhcp(self) -> np.ndarray:
303
+ return (self.Etheta + 1j*self.Ephi)/np.sqrt(2)
304
+
305
+ @property
306
+ def AR(self) -> np.ndarray:
307
+ R = np.abs(self.Erhcp)
308
+ L = np.abs(self.Elhcp)
309
+ return (R+L)/(R-L)
310
+
311
+ @property
312
+ def normE(self) -> np.ndarray:
313
+ return np.sqrt(np.abs(self.E[0,:])**2 + np.abs(self.E[1,:])**2 + np.abs(self.E[2,:])**2)
314
+
315
+ @property
316
+ def normH(self) -> np.ndarray:
317
+ return np.sqrt(np.abs(self.H[0,:])**2 + np.abs(self.H[1,:])**2 + np.abs(self.H[2,:])**2)
318
+
319
+
258
320
  def surfplot(self,
259
- polarization: Literal['Ex','Ey','Ez','Etheta','Ephi','normE'],
321
+ polarization: Literal['Ex','Ey','Ez','Etheta','Ephi','normE','Erhcp','Elhcp','AR'],
322
+ quantity: Literal['abs','real','imag','angle'] = 'abs',
260
323
  isotropic: bool = True, dB: bool = False, dBfloor: float = -30, rmax: float | None = None,
261
324
  offset: tuple[float, float, float] = (0,0,0)) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
262
325
  """Returns the parameters to be used as positional arguments for the display.add_surf() function.
@@ -273,27 +336,16 @@ class FarfieldData:
273
336
  Returns:
274
337
  tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]: The X, Y, Z, F values
275
338
  """
276
- if polarization == "Ex":
277
- F = self.E[0,:]
278
- elif polarization == "Ey":
279
- F = self.E[1,:]
280
- elif polarization == "Ez":
281
- F = self.E[2,:]
282
- elif polarization == "normE":
283
- F = np.sqrt(np.abs(self.E[0,:])**2 + np.abs(self.E[1,:])**2 + np.abs(self.E[2,:])**2)
284
- elif polarization == "Etheta":
285
- thx = -np.cos(self.theta)*np.cos(self.phi)
286
- thy = -np.cos(self.theta)*np.sin(self.phi)
287
- thz = np.sin(self.theta)
288
- F = np.abs(thx*self.E[0,:] + thy*self.E[1,:] + thz*self.E[2,:])
289
- elif polarization == "Ephi":
290
- phx = -np.sin(self.phi)
291
- phy = np.cos(self.phi)
292
- phz = np.zeros_like(self.theta)
293
- F = np.abs(phx*self.E[0,:] + phy*self.E[1,:] + phz*self.E[2,:])
294
- else:
295
- logger.warning('Defaulting to normE')
296
- F = np.sqrt(np.abs(self.E[0,:])**2 + np.abs(self.E[1,:])**2 + np.abs(self.E[2,:])**2)
339
+ fmap = {
340
+ 'abs': np.abs,
341
+ 'real': np.real,
342
+ 'imag': np.imag,
343
+ 'angle': np.angle,
344
+ }
345
+ mapping = fmap.get(quantity.lower(),np.abs)
346
+
347
+ F = mapping(self.__dict__.get(polarization, self.normE))
348
+
297
349
  if isotropic:
298
350
  F = F/np.sqrt(Z0/(2*np.pi))
299
351
  if dB:
@@ -764,7 +816,7 @@ class MWField:
764
816
  ang_range: tuple[float, float] = (-180, 180),
765
817
  Npoints: int = 201,
766
818
  origin: tuple[float, float, float] | None = None,
767
- syms: list[Literal['Ex','Ey','Ez', 'Hx','Hy','Hz']] | None = None) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
819
+ syms: list[Literal['Ex','Ey','Ez', 'Hx','Hy','Hz']] | None = None) -> FarfieldData:#tuple[np.ndarray, np.ndarray, np.ndarray]:
768
820
  """Compute the farfield electric and magnetic field defined by a circle.
769
821
 
770
822
  Args:
@@ -784,7 +836,7 @@ class MWField:
784
836
  theta, phi = arc_on_plane(refdir, plane_normal_parsed, ang_range, Npoints)
785
837
  E,H = self.farfield(theta, phi, faces, origin, syms = syms)
786
838
  angs = np.linspace(*ang_range, Npoints)*np.pi/180
787
- return angs, E ,H
839
+ return FarfieldData(E, H, theta, phi, ang=angs)
788
840
 
789
841
  def farfield_3d(self,
790
842
  faces: FaceSelection | GeoSurface,
@@ -975,6 +1027,42 @@ class MWScalarNdim:
975
1027
  def S(self, i1: int, i2: int) -> np.ndarray:
976
1028
  return self.Sp[...,self._portmap[i1], self._portmap[i2]]
977
1029
 
1030
+ @property
1031
+ def Smat(self) -> np.ndarray:
1032
+ """Returns the full S-matrix
1033
+
1034
+ Returns:
1035
+ np.ndarray: The S-matrix with shape (nF, nP, nP)
1036
+ """
1037
+ Nports = len(self._portmap)
1038
+ nfreq = self.freq.shape[0]
1039
+
1040
+ Smat = np.zeros((nfreq,Nports,Nports), dtype=np.complex128)
1041
+
1042
+ for i in self._portnumbers:
1043
+ for j in self._portnumbers:
1044
+ Smat[:,i-1,j-1] = self.S(i,j)
1045
+
1046
+ return Smat
1047
+
1048
+ def emmodel(self, f_sample: np.ndarray | None = None) -> tuple[np.ndarray, np.ndarray]:
1049
+ """Returns the required date for a Heavi S-parameter component
1050
+
1051
+ Returns:
1052
+ tuple[np.ndarray, np.ndarray]: Heavi data
1053
+ """
1054
+
1055
+ if f_sample is not None:
1056
+ f = f_sample
1057
+ S = self.model_Smat(f_sample)
1058
+ else:
1059
+ f = self.freq
1060
+ S = self.Smat
1061
+
1062
+ Z0s = self.Z0
1063
+ S = renormalise_s(S, Z0s, 50.0)
1064
+ return f, S
1065
+
978
1066
  def model_S(self, i: int, j: int,
979
1067
  freq: np.ndarray,
980
1068
  Npoles: int | Literal['auto'] = 'auto',
@@ -1010,7 +1098,7 @@ class MWScalarNdim:
1010
1098
  Returns:
1011
1099
  np.ndarray: The (Nf,Np,Np) S-parameter matrix
1012
1100
  """
1013
- Nports = len(self.datasets[0].excitation)
1101
+ Nports = len(self._portmap)
1014
1102
  nfreq = frequencies.shape[0]
1015
1103
 
1016
1104
  Smat = np.zeros((nfreq,Nports,Nports), dtype=np.complex128)
@@ -15,13 +15,11 @@
15
15
  # along with this program; if not, see
16
16
  # <https://www.gnu.org/licenses/>.
17
17
 
18
- from numba_progress import ProgressBar
19
18
  from ...mesh3d import SurfaceMesh
20
19
  import numpy as np
21
20
  from loguru import logger
22
21
  from numba import c16, njit, prange, f8
23
22
  from numba.types import Tuple as TupleType # ty: ignore
24
- from numba_progress.progress import ProgressBarType
25
23
  from ...const import Z0
26
24
 
27
25
  LR = 0.001
@@ -34,14 +32,13 @@ LR = 0.001
34
32
  f8[:, :],
35
33
  f8[:, :],
36
34
  f8,
37
- ProgressBarType,
38
35
  ),
39
36
  parallel=True,
40
37
  fastmath=True,
41
38
  cache=True,
42
39
  nogil=True,
43
40
  )
44
- def stratton_chu_ff(Ein, Hin, vis, wns, tpout, k0, pgb):
41
+ def stratton_chu_ff(Ein, Hin, vis, wns, tpout, k0):
45
42
 
46
43
  Ex = Ein[0, :].flatten()
47
44
  Ey = Ein[1, :].flatten()
@@ -125,7 +122,6 @@ def stratton_chu_ff(Ein, Hin, vis, wns, tpout, k0, pgb):
125
122
  Eoutz += Q * (rx * ie1y - ry * ie1x)
126
123
 
127
124
  # ii += iadd
128
- pgb.update(1)
129
125
  Eout[0, :] = Eoutx
130
126
  Eout[1, :] = Eouty
131
127
  Eout[2, :] = Eoutz
@@ -162,14 +158,13 @@ def stratton_chu(Ein, Hin, mesh: SurfaceMesh, theta: np.ndarray, phi: np.ndarray
162
158
  Eout = None
163
159
  Hout = None
164
160
  tpout = np.array([theta, phi])
165
- with ProgressBar(total=Ntot, ncols=100, dynamic_ncols=False) as pgb:
166
- Eout, Hout = stratton_chu_ff(
167
- Ein.astype(np.complex128),
168
- Hin.astype(np.complex128),
169
- vis.astype(np.float64),
170
- wns.astype(np.float64),
171
- tpout.astype(np.float64),
172
- np.float64(k0),
173
- pgb,
174
- )
161
+
162
+ Eout, Hout = stratton_chu_ff(
163
+ Ein.astype(np.complex128),
164
+ Hin.astype(np.complex128),
165
+ vis.astype(np.float64),
166
+ wns.astype(np.float64),
167
+ tpout.astype(np.float64),
168
+ np.float64(k0),
169
+ )
175
170
  return Eout.astype(np.complex128), Hout.astype(np.complex128)
@@ -342,8 +342,6 @@ and sparse frequency annotations (e.g., labeled by frequency).
342
342
  fdiv = units[key]
343
343
 
344
344
  # --- figure/axes ---
345
- fig: Figure
346
- ax: Axes
347
345
  fig, ax = plt.subplots(figsize=(6, 6))
348
346
 
349
347
  # --- smith grid (kept out of legend) ---
@@ -62,7 +62,7 @@ class Simulation:
62
62
 
63
63
  def __init__(self,
64
64
  modelname: str,
65
- loglevel: Literal['DEBUG','INFO','WARNING','ERROR'] = 'INFO',
65
+ loglevel: Literal['TRACE','DEBUG','INFO','WARNING','ERROR'] = 'INFO',
66
66
  load_file: bool = False,
67
67
  save_file: bool = False,
68
68
  logfile: bool = False,