你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 07:24:19 +08:00
Update Magnetic Dipole for parallel build
这个提交包含在:
@@ -617,71 +617,87 @@ class MagneticDipole(RotatableMixin, GridUserObject):
|
|||||||
def hash(self):
|
def hash(self):
|
||||||
return "#magnetic_dipole"
|
return "#magnetic_dipole"
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(
|
||||||
super().__init__(**kwargs)
|
self,
|
||||||
|
p1: Tuple[float, float, float],
|
||||||
def _do_rotate(self, grid: FDTDGrid):
|
polarisation: str,
|
||||||
"""Performs rotation."""
|
waveform_id: str,
|
||||||
rot_pol_pts, self.kwargs["polarisation"] = rotate_polarisation(
|
start: Optional[float] = None,
|
||||||
self.kwargs["p1"], self.kwargs["polarisation"], self.axis, self.angle, grid
|
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):
|
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:
|
if self.do_rotate:
|
||||||
self._do_rotate(grid)
|
self._do_rotate(grid)
|
||||||
|
|
||||||
# Check polarity & position parameters
|
# Check the position of the magnetic dipole
|
||||||
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
|
|
||||||
|
|
||||||
uip = self._create_uip(grid)
|
uip = self._create_uip(grid)
|
||||||
xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str())
|
discretised_point = uip.discretise_point(self.point)
|
||||||
p2 = uip.round_to_grid_static_point(p1)
|
|
||||||
|
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
|
# Check if there is a waveformID in the waveforms list
|
||||||
if not any(x.ID == waveform_id for x in grid.waveforms):
|
if not any(x.ID == self.waveform_id for x in grid.waveforms):
|
||||||
logger.exception(
|
raise ValueError(
|
||||||
f"{self.params_str()} there is no waveform with the identifier {waveform_id}."
|
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 = MagneticDipoleUser()
|
||||||
m.polarisation = polarisation
|
m.polarisation = self.polarisation
|
||||||
m.xcoord = xcoord
|
m.coord = coord
|
||||||
m.ycoord = ycoord
|
m.coordorigin = coord
|
||||||
m.zcoord = zcoord
|
|
||||||
m.xcoordorigin = xcoord
|
|
||||||
m.ycoordorigin = ycoord
|
|
||||||
m.zcoordorigin = zcoord
|
|
||||||
m.ID = (
|
m.ID = (
|
||||||
m.__class__.__name__
|
m.__class__.__name__
|
||||||
+ "("
|
+ "("
|
||||||
@@ -692,46 +708,33 @@ class MagneticDipole(RotatableMixin, GridUserObject):
|
|||||||
+ str(m.zcoord)
|
+ str(m.zcoord)
|
||||||
+ ")"
|
+ ")"
|
||||||
)
|
)
|
||||||
m.waveform = grid.get_waveform_by_id(waveform_id)
|
m.waveform = grid.get_waveform_by_id(self.waveform_id)
|
||||||
|
|
||||||
try:
|
if self.start is None or self.stop is None:
|
||||||
# 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:
|
|
||||||
m.start = 0
|
m.start = 0
|
||||||
m.stop = grid.timewindow
|
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)
|
m.calculate_waveform_values(grid.iterations, grid.dt)
|
||||||
|
|
||||||
logger.info(
|
return m
|
||||||
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."
|
|
||||||
)
|
|
||||||
|
|
||||||
grid.magneticdipoles.append(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 {p[0]:g}m, {p[1]:g}m, {p[2]:g}m,"
|
||||||
|
f"{startstop}using waveform {m.waveform.ID} created."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TransmissionLine(RotatableMixin, GridUserObject):
|
class TransmissionLine(RotatableMixin, GridUserObject):
|
||||||
|
在新工单中引用
屏蔽一个用户