Update Magnetic Dipole for parallel build

这个提交包含在:
nmannall
2025-01-20 17:46:10 +00:00
父节点 29d3381147
当前提交 bd55f0beae

查看文件

@@ -617,71 +617,87 @@ class MagneticDipole(RotatableMixin, GridUserObject):
def hash(self):
return "#magnetic_dipole"
def __init__(self, **kwargs):
super().__init__(**kwargs)
def _do_rotate(self, grid: FDTDGrid):
"""Performs rotation."""
rot_pol_pts, self.kwargs["polarisation"] = rotate_polarisation(
self.kwargs["p1"], self.kwargs["polarisation"], self.axis, self.angle, grid
def __init__(
self,
p1: Tuple[float, float, float],
polarisation: str,
waveform_id: str,
start: Optional[float] = None,
stop: Optional[float] = None,
):
super().__init__(
p1=p1, polarisation=polarisation, waveform_id=waveform_id, start=start, stop=stop
)
rot_pts = rotate_2point_object(rot_pol_pts, self.axis, self.angle, self.origin)
self.kwargs["p1"] = tuple(rot_pts[0, :])
self.point = p1
self.polarisation = polarisation.lower()
self.waveform_id = waveform_id
self.start = start
self.stop = stop
def build(self, grid: FDTDGrid):
try:
polarisation = self.kwargs["polarisation"].lower()
p1 = self.kwargs["p1"]
waveform_id = self.kwargs["waveform_id"]
except KeyError:
logger.exception(f"{self.params_str()} requires at least five parameters.")
raise
if self.do_rotate:
self._do_rotate(grid)
# Check polarity & position parameters
if polarisation not in ("x", "y", "z"):
logger.exception(self.params_str() + " polarisation must be x, y, or z.")
raise ValueError
if "2D TMx" in config.get_model_config().mode and polarisation in [
"y",
"z",
]:
logger.exception(self.params_str() + " polarisation must be x in 2D TMx mode.")
raise ValueError
elif "2D TMy" in config.get_model_config().mode and polarisation in [
"x",
"z",
]:
logger.exception(self.params_str() + " polarisation must be y in 2D TMy mode.")
raise ValueError
elif "2D TMz" in config.get_model_config().mode and polarisation in [
"x",
"y",
]:
logger.exception(self.params_str() + " polarisation must be z in 2D TMz mode.")
raise ValueError
# Check the position of the magnetic dipole
uip = self._create_uip(grid)
xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str())
p2 = uip.round_to_grid_static_point(p1)
discretised_point = uip.discretise_point(self.point)
if uip.check_src_rx_point(discretised_point, self.params_str()):
self._validate_parameters(grid)
magnetic_dipole = self._create_magnetic_dipole(grid, discretised_point)
grid.magneticdipoles.append(magnetic_dipole)
self._log(grid, magnetic_dipole)
def _do_rotate(self, grid: FDTDGrid):
"""Performs rotation."""
rot_pol_pts, self.polarisation = rotate_polarisation(
self.point, self.polarisation, self.axis, self.angle, grid
)
rot_pts = rotate_2point_object(rot_pol_pts, self.axis, self.angle, self.origin)
self.point = tuple(rot_pts[0, :])
def _validate_parameters(self, grid: FDTDGrid):
# Check polarity
self.polarisation = self.polarisation.lower()
if self.polarisation not in ("x", "y", "z"):
raise ValueError(f"{self.params_str()} polarisation must be x, y, or z.")
if "2D TMx" in config.get_model_config().mode and self.polarisation in ["y", "z"]:
raise ValueError(f"{self.params_str()} polarisation must be x in 2D TMx mode.")
elif "2D TMy" in config.get_model_config().mode and self.polarisation in ["x", "z"]:
raise ValueError(f"{self.params_str()} polarisation must be y in 2D TMy mode.")
elif "2D TMz" in config.get_model_config().mode and self.polarisation in ["x", "y"]:
raise ValueError(f"{self.params_str()} polarisation must be z in 2D TMz mode.")
# Check if there is a waveformID in the waveforms list
if not any(x.ID == waveform_id for x in grid.waveforms):
logger.exception(
f"{self.params_str()} there is no waveform with the identifier {waveform_id}."
if not any(x.ID == self.waveform_id for x in grid.waveforms):
raise ValueError(
f"{self.params_str()} there is no waveform with the identifier {self.waveform_id}."
)
raise ValueError
# Check start and stop
if self.start is not None and self.stop is not None:
if self.start < 0:
raise ValueError(
f"{self.params_str()} delay of the initiation of the source should not be less"
" than zero."
)
if self.stop < 0:
raise ValueError(
f"{self.params_str()} time to remove the source should not be less than zero."
)
if self.stop - self.start <= 0:
raise ValueError(
f"{self.params_str()} duration of the source should not be zero or less."
)
def _create_magnetic_dipole(
self, grid: FDTDGrid, coord: npt.NDArray[np.int32]
) -> MagneticDipoleUser:
m = MagneticDipoleUser()
m.polarisation = polarisation
m.xcoord = xcoord
m.ycoord = ycoord
m.zcoord = zcoord
m.xcoordorigin = xcoord
m.ycoordorigin = ycoord
m.zcoordorigin = zcoord
m.polarisation = self.polarisation
m.coord = coord
m.coordorigin = coord
m.ID = (
m.__class__.__name__
+ "("
@@ -692,47 +708,34 @@ class MagneticDipole(RotatableMixin, GridUserObject):
+ str(m.zcoord)
+ ")"
)
m.waveform = grid.get_waveform_by_id(waveform_id)
m.waveform = grid.get_waveform_by_id(self.waveform_id)
try:
# Check source start & source remove time parameters
start = self.kwargs["start"]
stop = self.kwargs["stop"]
if start < 0:
logger.exception(
self.params_str()
+ " delay of the initiation of the source should not be less than zero."
)
raise ValueError
if stop < 0:
logger.exception(
self.params_str() + " time to remove the source should not be less than zero."
)
raise ValueError
if stop - start <= 0:
logger.exception(
self.params_str() + " duration of the source should not be zero or less."
)
raise ValueError
m.start = start
m.stop = min(stop, grid.timewindow)
startstop = f" start time {m.start:g} secs, finish time {m.stop:g} secs "
except KeyError:
if self.start is None or self.stop is None:
m.start = 0
m.stop = grid.timewindow
startstop = " "
else:
m.start = self.start
m.stop = min(self.stop, grid.timewindow)
m.calculate_waveform_values(grid.iterations, grid.dt)
return m
def _log(self, grid: FDTDGrid, m: MagneticDipoleUser):
if self.start is None or self.stop is None:
startstop = " "
else:
startstop = f" start time {m.start:g} secs, finish time {m.stop:g} secs "
uip = self._create_uip(grid)
p = uip.discretised_to_continuous(m.coord)
logger.info(
f"{self.grid_name(grid)}Magnetic dipole with polarity"
f"{m.polarisation} at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m,"
+ startstop
+ f"using waveform {m.waveform.ID} created."
f" {m.polarisation} at {p[0]:g}m, {p[1]:g}m, {p[2]:g}m,"
f"{startstop}using waveform {m.waveform.ID} created."
)
grid.magneticdipoles.append(m)
class TransmissionLine(RotatableMixin, GridUserObject):
"""Specifies a one-dimensional transmission line model at an electric