multiuse relative to main grid

这个提交包含在:
jasminium
2021-01-05 11:35:11 +01:00
父节点 b8150e1e77
当前提交 1f99a58004
共有 2 个文件被更改,包括 33 次插入12 次删除

查看文件

@@ -200,6 +200,7 @@ class VoltageSource(UserObjectMulti):
raise ValueError raise ValueError
xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str()) xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str())
p2 = uip.round_to_grid_static_point(p1)
if resistance < 0: if resistance < 0:
logger.exception(self.params_str() + ' requires a source resistance of zero or greater') logger.exception(self.params_str() + ' requires a source resistance of zero or greater')
@@ -245,7 +246,7 @@ class VoltageSource(UserObjectMulti):
v.calculate_waveform_values(grid) v.calculate_waveform_values(grid)
logger.info(self.grid_name(grid) + f'Voltage source with polarity {v.polarisation} at {v.xcoord * grid.dx:g}m, {v.ycoord * grid.dy:g}m, {v.zcoord * grid.dz:g}m, resistance {v.resistance:.1f} Ohms,' + startstop + f'using waveform {v.waveformID} created.') logger.info(self.grid_name(grid) + f'Voltage source with polarity {v.polarisation} at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m, resistance {v.resistance:.1f} Ohms,' + startstop + f'using waveform {v.waveformID} created.')
grid.voltagesources.append(v) grid.voltagesources.append(v)
@@ -315,6 +316,8 @@ class HertzianDipole(UserObjectMulti):
raise ValueError raise ValueError
xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str()) xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str())
p2 = uip.round_to_grid_static_point(p1)
# 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 == waveform_id for x in grid.waveforms):
@@ -368,9 +371,9 @@ class HertzianDipole(UserObjectMulti):
h.calculate_waveform_values(grid) h.calculate_waveform_values(grid)
if config.get_model_config().mode == '2D': if config.get_model_config().mode == '2D':
logger.info(self.grid_name(grid) + f'Hertzian dipole is a line source in 2D with polarity {h.polarisation} at {h.xcoord * grid.dx:g}m, {h.ycoord * grid.dy:g}m, {h.zcoord * grid.dz:g}m,' + startstop + f'using waveform {h.waveformID} created.') logger.info(self.grid_name(grid) + f'Hertzian dipole is a line source in 2D with polarity {h.polarisation} at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m,' + startstop + f'using waveform {h.waveformID} created.')
else: else:
logger.info(self.grid_name(grid) + f'Hertzian dipole with polarity {h.polarisation} at {h.xcoord * grid.dx:g}m, {h.ycoord * grid.dy:g}m, {h.zcoord * grid.dz:g}m,' + startstop + f'using waveform {h.waveformID} created.') logger.info(self.grid_name(grid) + f'Hertzian dipole with polarity {h.polarisation} at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m,' + startstop + f'using waveform {h.waveformID} created.')
grid.hertziandipoles.append(h) grid.hertziandipoles.append(h)
@@ -440,6 +443,8 @@ class MagneticDipole(UserObjectMulti):
raise ValueError raise ValueError
xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str()) xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str())
p2 = uip.round_to_grid_static_point(p1)
# 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 == waveform_id for x in grid.waveforms):
@@ -483,7 +488,7 @@ class MagneticDipole(UserObjectMulti):
m.calculate_waveform_values(grid) m.calculate_waveform_values(grid)
logger.info(self.grid_name(grid) + f'Magnetic dipole with polarity {m.polarisation} at {m.xcoord * grid.dx:g}m, {m.ycoord * grid.dy:g}m, {m.zcoord * grid.dz:g}m,' + startstop + f'using waveform {m.waveformID} created.') logger.info(self.grid_name(grid) + f'Magnetic dipole with polarity {m.polarisation} at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m,' + startstop + f'using waveform {m.waveformID} created.')
grid.magneticdipoles.append(m) grid.magneticdipoles.append(m)
@@ -561,6 +566,8 @@ class TransmissionLine(UserObjectMulti):
raise ValueError raise ValueError
xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str()) xcoord, ycoord, zcoord = uip.check_src_rx_point(p1, self.params_str())
p2 = uip.round_to_grid_static_point(p1)
if resistance <= 0 or resistance >= config.sim_config.em_consts['z0']: if resistance <= 0 or resistance >= config.sim_config.em_consts['z0']:
logger.exception(self.params_str() + ' requires a resistance greater than zero and less than the impedance of free space, i.e. 376.73 Ohms') logger.exception(self.params_str() + ' requires a resistance greater than zero and less than the impedance of free space, i.e. 376.73 Ohms')
@@ -607,7 +614,7 @@ class TransmissionLine(UserObjectMulti):
t.calculate_waveform_values(grid) t.calculate_waveform_values(grid)
t.calculate_incident_V_I(grid) t.calculate_incident_V_I(grid)
logger.info(self.grid_name(grid) + f'Transmission line with polarity {t.polarisation} at {t.xcoord * grid.dx:g}m, {t.ycoord * grid.dy:g}m, {t.zcoord * grid.dz:g}m, resistance {t.resistance:.1f} Ohms,' + startstop + f'using waveform {t.waveformID} created.') logger.info(self.grid_name(grid) + f'Transmission line with polarity {t.polarisation} at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m, resistance {t.resistance:.1f} Ohms,' + startstop + f'using waveform {t.waveformID} created.')
grid.transmissionlines.append(t) grid.transmissionlines.append(t)
@@ -667,8 +674,7 @@ class Rx(UserObjectMulti):
self.__dorotate(grid) self.__dorotate(grid)
p = uip.check_src_rx_point(p1, self.params_str()) p = uip.check_src_rx_point(p1, self.params_str())
print(p1) p2 = uip.round_to_grid_static_point(p1)
print(p)
r = self.constructor() r = self.constructor()
r.xcoord, r.ycoord, r.zcoord = p r.xcoord, r.ycoord, r.zcoord = p
@@ -694,7 +700,7 @@ class Rx(UserObjectMulti):
logger.exception(self.params_str() + f' contains an output type that is not allowable. Allowable outputs in current context are {allowableoutputs}') logger.exception(self.params_str() + f' contains an output type that is not allowable. Allowable outputs in current context are {allowableoutputs}')
raise ValueError raise ValueError
logger.info(self.grid_name(grid) + f"Receiver at {r.xcoord * grid.dx:g}m, {r.ycoord * grid.dy:g}m, {r.zcoord * grid.dz:g}m with output component(s) {', '.join(r.outputs)} created.") logger.info(self.grid_name(grid) + f"Receiver at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m with output component(s) {', '.join(r.outputs)} created.")
grid.rxs.append(r) grid.rxs.append(r)
@@ -728,6 +734,8 @@ class RxArray(UserObjectMulti):
xs, ys, zs = uip.check_src_rx_point(p1, self.params_str(), 'lower') xs, ys, zs = uip.check_src_rx_point(p1, self.params_str(), 'lower')
xf, yf, zf = uip.check_src_rx_point(p2, self.params_str(), 'upper') xf, yf, zf = uip.check_src_rx_point(p2, self.params_str(), 'upper')
p3 = uip.round_to_grid_static_point(p1)
p4 = uip.round_to_grid_static_point(p2)
dx, dy, dz = uip.discretise_point(dl) dx, dy, dz = uip.discretise_point(dl)
if xs > xf or ys > yf or zs > zf: if xs > xf or ys > yf or zs > zf:
@@ -755,7 +763,7 @@ class RxArray(UserObjectMulti):
logger.exception(self.params_str() + ' the step size should not be less than the spatial discretisation') logger.exception(self.params_str() + ' the step size should not be less than the spatial discretisation')
raise ValueError raise ValueError
logger.info(self.grid_name(grid) + f'Receiver array {xs * grid.dx:g}m, {ys * grid.dy:g}m, {zs * grid.dz:g}m, to {xf * grid.dx:g}m, {yf * grid.dy:g}m, {zf * grid.dz:g}m with steps {dx * grid.dx:g}m, {dy * grid.dy:g}m, {dz * grid.dz:g}m') logger.info(self.grid_name(grid) + f'Receiver array {p3[0]:g}m, {p3[1]:g}m, {p3[2]:g}m, to {p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m with steps {dx * grid.dx:g}m, {dy * grid.dy:g}m, {dz * grid.dz:g}m')
for x in range(xs, xf + 1, dx): for x in range(xs, xf + 1, dx):
for y in range(ys, yf + 1, dy): for y in range(ys, yf + 1, dy):
@@ -767,10 +775,14 @@ class RxArray(UserObjectMulti):
r.xcoordorigin = x r.xcoordorigin = x
r.ycoordorigin = y r.ycoordorigin = y
r.zcoordorigin = z r.zcoordorigin = z
# Point relative to main grid
p5 = np.array([x, y, z])
p5 = uip.descretised_to_continuous(p5)
p5 = uip.round_to_grid_static_point(p5)
r.ID = r.__class__.__name__ + '(' + str(x) + ',' + str(y) + ',' + str(z) + ')' r.ID = r.__class__.__name__ + '(' + str(x) + ',' + str(y) + ',' + str(z) + ')'
for key in RxUser.defaultoutputs: for key in RxUser.defaultoutputs:
r.outputs[key] = np.zeros(grid.iterations, dtype=config.sim_config.dtypes['float_or_double']) r.outputs[key] = np.zeros(grid.iterations, dtype=config.sim_config.dtypes['float_or_double'])
logger.info(f" Receiver at {r.xcoord * grid.dx:g}m, {r.ycoord * grid.dy:g}m, {r.zcoord * grid.dz:g}m with output component(s) {', '.join(r.outputs)} created.") logger.info(f" Receiver at {p5[0]:g}m, {p5[1]:g}m, {p5[2]:g}m with output component(s) {', '.join(r.outputs)} created.")
grid.rxs.append(r) grid.rxs.append(r)
@@ -816,6 +828,9 @@ class Snapshot(UserObjectMulti):
xf, yf, zf = p2 xf, yf, zf = p2
dx, dy, dz = uip.discretise_point(dl) dx, dy, dz = uip.discretise_point(dl)
p3 = uip.round_to_grid_static_point(p1)
p4 = uip.round_to_grid_static_point(p2)
# If number of iterations given # If number of iterations given
try: try:
iterations = self.kwargs['iterations'] iterations = self.kwargs['iterations']
@@ -859,7 +874,7 @@ class Snapshot(UserObjectMulti):
s = SnapshotUser(xs, ys, zs, xf, yf, zf, dx, dy, dz, iterations, filename, fileext=fileext) s = SnapshotUser(xs, ys, zs, xf, yf, zf, dx, dy, dz, iterations, filename, fileext=fileext)
logger.info(f'Snapshot from {xs * grid.dx:g}m, {ys * grid.dy:g}m, {zs * grid.dz:g}m, to {xf * grid.dx:g}m, {yf * grid.dy:g}m, {zf * grid.dz:g}m, discretisation {dx * grid.dx:g}m, {dy * grid.dy:g}m, {dz * grid.dz:g}m, at {s.time * grid.dt:g} secs with filename {s.filename}{s.fileext} will be created.') logger.info(f'Snapshot from {p3[0]:g}m, {p3[1]:g}m, {p3[2]:g}m, to {p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m, discretisation {dx * grid.dx:g}m, {dy * grid.dy:g}m, {dz * grid.dz:g}m, at {s.time * grid.dt:g} secs with filename {s.filename}{s.fileext} will be created.')
grid.snapshots.append(s) grid.snapshots.append(s)
@@ -1258,6 +1273,8 @@ class GeometryView(UserObjectMulti):
xf, yf, zf = p2 xf, yf, zf = p2
dx, dy, dz = uip.discretise_static_point(dl) dx, dy, dz = uip.discretise_static_point(dl)
p3 = uip.round_to_grid_static_point(p1)
p4 = uip.round_to_grid_static_point(p2)
if dx < 0 or dy < 0 or dz < 0: if dx < 0 or dy < 0 or dz < 0:
logger.exception(self.params_str() + ' the step size should not be less than zero') logger.exception(self.params_str() + ' the step size should not be less than zero')
@@ -1283,7 +1300,7 @@ class GeometryView(UserObjectMulti):
g = GeometryViewUser(xs, ys, zs, xf, yf, zf, dx, dy, dz, filename, fileext, grid) g = GeometryViewUser(xs, ys, zs, xf, yf, zf, dx, dy, dz, filename, fileext, grid)
logger.info(f'Geometry view from {xs * grid.dx:g}m, {ys * grid.dy:g}m, {zs * grid.dz:g}m, to {xf * grid.dx:g}m, {yf * grid.dy:g}m, {zf * grid.dz:g}m, discretisation {dx * grid.dx:g}m, {dy * grid.dy:g}m, {dz * grid.dz:g}m, multi_grid={self.multi_grid}, grid={grid.name}, with filename base {g.filename} created.') logger.info(f'Geometry view from {p3[0]:g}m, {p3[1]:g}m, {p3[2]:g}m, to {p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m, discretisation {dx * grid.dx:g}m, {dy * grid.dy:g}m, {dz * grid.dz:g}m, multi_grid={self.multi_grid}, grid={grid.name}, with filename base {g.filename} created.')
# Append the new GeometryView object to the geometry views list # Append the new GeometryView object to the geometry views list
grid.geometryviews.append(g) grid.geometryviews.append(g)

查看文件

@@ -83,6 +83,10 @@ class UserInput:
def round_to_grid(self, p): def round_to_grid(self, p):
"""Function to get the nearest continuous point on the grid from a continuous point in space.""" """Function to get the nearest continuous point on the grid from a continuous point in space."""
return self.discretise_point(p) * self.grid.dl return self.discretise_point(p) * self.grid.dl
def descretised_to_continuous(self, p):
"""Function to return a point given as indices to a continous point in the real space."""
return p * self.grid.dl
class MainGridUserInput(UserInput): class MainGridUserInput(UserInput):