Add methods to the grid to add sources and receivers

This is needed as the MPI grid needs to convert the location of the
source/receiver to its local coordinates. Doing this in the grid means
the multi use commands don't need to know about the MPI implementation
这个提交包含在:
nmannall
2025-01-21 15:23:05 +00:00
父节点 da79de828d
当前提交 b99d734bdc
共有 3 个文件被更改,包括 30 次插入5 次删除

查看文件

@@ -153,6 +153,21 @@ class FDTDGrid:
self.pmls["thickness"]["ymax"] = int(thickness[4])
self.pmls["thickness"]["zmax"] = int(thickness[5])
def add_source(self, source: Source):
if isinstance(source, VoltageSource):
self.voltagesources.append(source)
elif isinstance(source, HertzianDipole):
self.hertziandipoles.append(source)
elif isinstance(source, MagneticDipole):
self.magneticdipoles.append(source)
elif isinstance(source, TransmissionLine):
self.transmissionlines.append(source)
else:
raise TypeError(f"Source of type '{type(source)}' is unknown to gprMax")
def add_receiver(self, receiver: Rx):
self.rxs.append(receiver)
def build(self) -> None:
"""Build the grid."""

查看文件

@@ -155,6 +155,16 @@ class MPIGrid(FDTDGrid):
if self.has_neighbour(Dim.Z, Dir.POS):
self.pmls["thickness"]["zmax"] = 0
def add_source(self, source: Source):
source.coord = self.global_to_local_coordinate(source.coord)
source.coordorigin = self.global_to_local_coordinate(source.coordorigin)
return super().add_source(source)
def add_receiver(self, receiver: Rx):
receiver.coord = self.global_to_local_coordinate(receiver.coord)
receiver.coordorigin = self.global_to_local_coordinate(receiver.coordorigin)
return super().add_receiver(receiver)
def is_coordinator(self) -> bool:
"""Test if the current rank is the coordinator.

查看文件

@@ -441,7 +441,7 @@ class VoltageSource(RotatableMixin, GridUserObject):
if uip.check_src_rx_point(discretised_point, self.params_str()):
self._validate_parameters(grid)
voltage_source = self._create_voltage_source(grid, discretised_point)
grid.voltagesources.append(voltage_source)
grid.add_source(voltage_source)
self._log(grid, voltage_source)
@@ -591,7 +591,7 @@ class HertzianDipole(RotatableMixin, GridUserObject):
if uip.check_src_rx_point(discretised_point, self.params_str()):
self._validate_parameters(grid)
hertzian_dipole = self._create_hertzian_dipole(grid, discretised_point)
grid.hertziandipoles.append(hertzian_dipole)
grid.add_source(hertzian_dipole)
self._log(grid, hertzian_dipole)
@@ -645,7 +645,7 @@ class MagneticDipole(RotatableMixin, GridUserObject):
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)
grid.add_source(magnetic_dipole)
self._log(grid, magnetic_dipole)
def _do_rotate(self, grid: FDTDGrid):
@@ -802,7 +802,7 @@ class TransmissionLine(RotatableMixin, GridUserObject):
if uip.check_src_rx_point(discretised_point, self.params_str()):
self._validate_parameters(grid)
transmission_line = self._create_transmission_line(grid, discretised_point)
grid.transmissionlines.append(transmission_line)
grid.add_source(transmission_line)
self._log(grid, transmission_line)
def _validate_parameters(self, grid: FDTDGrid):
@@ -996,7 +996,7 @@ class Rx(RotatableMixin, GridUserObject):
if uip.check_src_rx_point(discretised_point, self.params_str()):
receiver = self._create_receiver(grid, discretised_point)
grid.rxs.append(receiver)
grid.add_receiver(receiver)
p = uip.discretised_to_continuous(discretised_point)
logger.info(