Changes to rotate method to allow grid information (dx,dy,dz) to be passed in.

这个提交包含在:
Craig Warren
2020-11-17 16:44:30 +00:00
父节点 aac52efd4f
当前提交 05d56b316c
共有 11 个文件被更改,包括 188 次插入33 次删除

查看文件

@@ -51,8 +51,16 @@ class AddGrass(UserObjectGeometry):
self.hash = '#add_grass' self.hash = '#add_grass'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
"""Set parameters for rotation."""
self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self):
"""Perform rotation."""
pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) pts = np.array([self.kwargs['p1'], self.kwargs['p2']])
rot_pts = rotate_2point_object(pts, axis, angle, origin) rot_pts = rotate_2point_object(pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
self.kwargs['p2'] = tuple(rot_pts[1, :]) self.kwargs['p2'] = tuple(rot_pts[1, :])
@@ -74,6 +82,9 @@ class AddGrass(UserObjectGeometry):
except KeyError: except KeyError:
seed = None seed = None
if self.dorotate:
self.__dorotate()
# Get the correct fractal volume # Get the correct fractal volume
volumes = [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id] volumes = [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id]
try: try:

查看文件

@@ -51,8 +51,16 @@ class AddSurfaceRoughness(UserObjectGeometry):
self.hash = '#add_surface_roughness' self.hash = '#add_surface_roughness'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
"""Set parameters for rotation."""
self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self):
"""Perform rotation."""
pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) pts = np.array([self.kwargs['p1'], self.kwargs['p2']])
rot_pts = rotate_2point_object(pts, axis, angle, origin) rot_pts = rotate_2point_object(pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
self.kwargs['p2'] = tuple(rot_pts[1, :]) self.kwargs['p2'] = tuple(rot_pts[1, :])
@@ -74,6 +82,9 @@ class AddSurfaceRoughness(UserObjectGeometry):
except KeyError: except KeyError:
seed = None seed = None
if self.dorotate:
self.__dorotate()
# Get the correct fractal volume # Get the correct fractal volume
volumes = [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id] volumes = [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id]
if volumes: if volumes:

查看文件

@@ -46,8 +46,16 @@ class AddSurfaceWater(UserObjectGeometry):
self.hash = '#add_surface_water' self.hash = '#add_surface_water'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
"""Set parameters for rotation."""
self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self):
"""Perform rotation."""
pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) pts = np.array([self.kwargs['p1'], self.kwargs['p2']])
rot_pts = rotate_2point_object(pts, axis, angle, origin) rot_pts = rotate_2point_object(pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
self.kwargs['p2'] = tuple(rot_pts[1, :]) self.kwargs['p2'] = tuple(rot_pts[1, :])
@@ -62,6 +70,9 @@ class AddSurfaceWater(UserObjectGeometry):
logger.exception(self.__str__() + ' requires exactly eight parameters') logger.exception(self.__str__() + ' requires exactly eight parameters')
raise raise
if self.dorotate:
self.__dorotate()
# Get the correct fractal volume # Get the correct fractal volume
volumes = [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id] volumes = [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id]
if volumes: if volumes:

查看文件

@@ -47,8 +47,16 @@ class Box(UserObjectGeometry):
self.hash = '#box' self.hash = '#box'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
"""Set parameters for rotation."""
self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self):
"""Perform rotation."""
pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) pts = np.array([self.kwargs['p1'], self.kwargs['p2']])
rot_pts = rotate_2point_object(pts, axis, angle, origin) rot_pts = rotate_2point_object(pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
self.kwargs['p2'] = tuple(rot_pts[1, :]) self.kwargs['p2'] = tuple(rot_pts[1, :])
@@ -60,6 +68,9 @@ class Box(UserObjectGeometry):
logger.exception(self.__str__() + ' Please specify two points.') logger.exception(self.__str__() + ' Please specify two points.')
raise raise
if self.dorotate:
self.__dorotate()
# check materials have been specified # check materials have been specified
# isotropic case # isotropic case
try: try:

查看文件

@@ -32,6 +32,7 @@ class UserObjectGeometry:
self.kwargs = kwargs self.kwargs = kwargs
self.hash = '#example' self.hash = '#example'
self.autotranslate = True self.autotranslate = True
self.dorotate = False
def __str__(self): def __str__(self):
"""Readable string of parameters given to object.""" """Readable string of parameters given to object."""
@@ -150,39 +151,38 @@ def rotate_2point_object(pts, axis, angle, origin=None):
return new_pts return new_pts
def rotate_polarisation(p, polarisation, axis, angle): def rotate_polarisation(p, polarisation, axis, angle, G):
"""Rotate a geometry object that is defined by 2 points. """Rotate a geometry object that is defined by a point and polarisation.
Args: Args:
p (array): coordinates of point (x, y, z) p (array): coordinates of point (x, y, z)
polarisation (str): current polarisation (x, y, or z) polarisation (str): current polarisation (x, y, or z)
axis (str): axis about which to perform rotation (x, y, or z) axis (str): axis about which to perform rotation (x, y, or z)
angle (int): angle of rotation (degrees) angle (int): angle of rotation (degrees)
G (class): Grid class instance - holds essential parameters
describing the model.
Returns: Returns:
pts (array): coordinates of points of rotated object pts (array): coordinates of points of rotated object
new_polarisation (str): new polarisation (x, y, or z) new_polarisation (str): new polarisation (x, y, or z)
""" """
logger.debug('Need to get dxdydz into this function')
dxdydz = np.array([0.001, 0.001, 0.001])
if polarisation.lower() == 'x': if polarisation.lower() == 'x':
new_pt = (p[0] + dxdydz[0], p[1], p[2]) new_pt = (p[0] + G.dx, p[1], p[2])
if axis == 'y' and angle == 90 or angle == 270: if axis == 'y' and angle == 90 or angle == 270:
new_polarisation = 'z' new_polarisation = 'z'
if axis == 'z' and angle == 90 or angle == 270: if axis == 'z' and angle == 90 or angle == 270:
new_polarisation = 'y' new_polarisation = 'y'
elif polarisation.lower() == 'y': elif polarisation.lower() == 'y':
new_pt = (p[0], p[1] + dxdydz[1], p[2]) new_pt = (p[0], p[1] + G.dy, p[2])
if axis == 'x' and angle == 90 or angle == 270: if axis == 'x' and angle == 90 or angle == 270:
new_polarisation = 'z' new_polarisation = 'z'
if axis == 'z' and angle == 90 or angle == 270: if axis == 'z' and angle == 90 or angle == 270:
new_polarisation = 'x' new_polarisation = 'x'
elif polarisation.lower() == 'z': elif polarisation.lower() == 'z':
new_pt = (p[0], p[1], p[2] + dxdydz[2]) new_pt = (p[0], p[1], p[2] + G.dz)
if axis == 'x' and angle == 90 or angle == 270: if axis == 'x' and angle == 90 or angle == 270:
new_polarisation = 'y' new_polarisation = 'y'
if axis == 'y' and angle == 90 or angle == 270: if axis == 'y' and angle == 90 or angle == 270:

查看文件

@@ -58,9 +58,6 @@ class CylindricalSector(UserObjectGeometry):
super().__init__(**kwargs) super().__init__(**kwargs)
self.hash = '#cylindrical_sector' self.hash = '#cylindrical_sector'
def rotate(self, axis, angle, origin=None):
pass
def create(self, grid, uip): def create(self, grid, uip):
try: try:

查看文件

@@ -43,8 +43,16 @@ class Edge(UserObjectGeometry):
self.hash = '#edge' self.hash = '#edge'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
"""Set parameters for rotation."""
self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self):
"""Perform rotation."""
pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) pts = np.array([self.kwargs['p1'], self.kwargs['p2']])
rot_pts = rotate_2point_object(pts, axis, angle, origin) rot_pts = rotate_2point_object(pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
self.kwargs['p2'] = tuple(rot_pts[1, :]) self.kwargs['p2'] = tuple(rot_pts[1, :])
@@ -58,6 +66,9 @@ class Edge(UserObjectGeometry):
logger.exception(self.__str__() + ' requires exactly 3 parameters') logger.exception(self.__str__() + ' requires exactly 3 parameters')
raise raise
if self.dorotate:
self.__dorotate()
p1, p2 = uip.check_box_points(p1, p2, self.__str__()) p1, p2 = uip.check_box_points(p1, p2, self.__str__())
xs, ys, zs = p1 xs, ys, zs = p1
xf, yf, zf = p2 xf, yf, zf = p2

查看文件

@@ -54,8 +54,16 @@ class FractalBox(UserObjectGeometry):
self.hash = '#fractal_box' self.hash = '#fractal_box'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
"""Set parameters for rotation."""
self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self):
"""Perform rotation."""
pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) pts = np.array([self.kwargs['p1'], self.kwargs['p2']])
rot_pts = rotate_2point_object(pts, axis, angle, origin) rot_pts = rotate_2point_object(pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
self.kwargs['p2'] = tuple(rot_pts[1, :]) self.kwargs['p2'] = tuple(rot_pts[1, :])
@@ -77,6 +85,9 @@ class FractalBox(UserObjectGeometry):
except KeyError: except KeyError:
seed = None seed = None
if self.dorotate:
self.__dorotate()
# Default is no dielectric smoothing for a fractal box # Default is no dielectric smoothing for a fractal box
averagefractalbox = False averagefractalbox = False

查看文件

@@ -45,8 +45,16 @@ class Plate(UserObjectGeometry):
self.hash = '#plate' self.hash = '#plate'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
"""Set parameters for rotation."""
self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self):
"""Perform rotation."""
pts = np.array([self.kwargs['p1'], self.kwargs['p2']]) pts = np.array([self.kwargs['p1'], self.kwargs['p2']])
rot_pts = rotate_2point_object(pts, axis, angle, origin) rot_pts = rotate_2point_object(pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
self.kwargs['p2'] = tuple(rot_pts[1, :]) self.kwargs['p2'] = tuple(rot_pts[1, :])
@@ -69,6 +77,9 @@ class Plate(UserObjectGeometry):
logger.exception(self.__str__() + ' No materials have been specified') logger.exception(self.__str__() + ' No materials have been specified')
raise raise
if self.dorotate:
self.__dorotate()
p1, p2 = uip.check_box_points(p1, p2, self.__str__()) p1, p2 = uip.check_box_points(p1, p2, self.__str__())
xs, ys, zs = p1 xs, ys, zs = p1
xf, yf, zf = p2 xf, yf, zf = p2

查看文件

@@ -51,9 +51,17 @@ class Triangle(UserObjectGeometry):
self.hash = '#triangle' self.hash = '#triangle'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
p1 = rotate_point(self.kwargs['p1'], axis, angle, origin) """Set parameters for rotation."""
p2 = rotate_point(self.kwargs['p2'], axis, angle, origin) self.axis = axis
p3 = rotate_point(self.kwargs['p3'], axis, angle, origin) self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self):
"""Perform rotation."""
p1 = rotate_point(self.kwargs['p1'], self.axis, self.angle, self.origin)
p2 = rotate_point(self.kwargs['p2'], self.axis, self.angle, self.origin)
p3 = rotate_point(self.kwargs['p3'], self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(p1) self.kwargs['p1'] = tuple(p1)
self.kwargs['p2'] = tuple(p2) self.kwargs['p2'] = tuple(p2)
self.kwargs['p3'] = tuple(p3) self.kwargs['p3'] = tuple(p3)
@@ -67,6 +75,9 @@ class Triangle(UserObjectGeometry):
except KeyError: except KeyError:
logger.exception(self.__str__() + ' specify 3 points and a thickness') logger.exception(self.__str__() + ' specify 3 points and a thickness')
raise raise
if self.dorotate:
self.__dorotate()
# check averaging # check averaging
try: try:

查看文件

@@ -51,6 +51,7 @@ class UserObjectMulti:
self.order = None self.order = None
self.hash = '#example' self.hash = '#example'
self.autotranslate = True self.autotranslate = True
self.dorotate = False
def __str__(self): def __str__(self):
"""Readable user string as per hash commands.""" """Readable user string as per hash commands."""
@@ -155,8 +156,20 @@ class VoltageSource(UserObjectMulti):
self.hash = '#voltage_source' self.hash = '#voltage_source'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
rot_pol_pts, self.kwargs['polarisation'] = rotate_polarisation(self.kwargs['p1'], self.kwargs['polarisation'], axis, angle) """Set parameters for rotation."""
rot_pts = rotate_2point_object(rot_pol_pts, axis, angle, origin) self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self, grid):
"""Perform rotation."""
rot_pol_pts, self.kwargs['polarisation'] = rotate_polarisation(self.kwargs['p1'],
self.kwargs['polarisation'],
self.axis,
self.angle,
grid)
rot_pts = rotate_2point_object(rot_pol_pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
def create(self, grid, uip): def create(self, grid, uip):
@@ -169,6 +182,9 @@ class VoltageSource(UserObjectMulti):
logger.exception(self.params_str() + ' requires at least six parameters') logger.exception(self.params_str() + ' requires at least six parameters')
raise raise
if self.dorotate:
self.__dorotate(grid)
# Check polarity & position parameters # Check polarity & position parameters
if polarisation not in ('x', 'y', 'z'): if polarisation not in ('x', 'y', 'z'):
logger.exception(self.params_str() + ' polarisation must be x, y, or z') logger.exception(self.params_str() + ' polarisation must be x, y, or z')
@@ -256,8 +272,20 @@ class HertzianDipole(UserObjectMulti):
self.hash = '#hertzian_dipole' self.hash = '#hertzian_dipole'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
rot_pol_pts, self.kwargs['polarisation'] = rotate_polarisation(self.kwargs['p1'], self.kwargs['polarisation'], axis, angle) """Set parameters for rotation."""
rot_pts = rotate_2point_object(rot_pol_pts, axis, angle, origin) self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self, grid):
"""Perform rotation."""
rot_pol_pts, self.kwargs['polarisation'] = rotate_polarisation(self.kwargs['p1'],
self.kwargs['polarisation'],
self.axis,
self.angle,
grid)
rot_pts = rotate_2point_object(rot_pol_pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
def create(self, grid, uip): def create(self, grid, uip):
@@ -269,6 +297,9 @@ class HertzianDipole(UserObjectMulti):
logger.exception(self.params_str() + ' requires at least 3 parameters') logger.exception(self.params_str() + ' requires at least 3 parameters')
raise raise
if self.dorotate:
self.__dorotate(grid)
# Check polarity & position parameters # Check polarity & position parameters
if polarisation not in ('x', 'y', 'z'): if polarisation not in ('x', 'y', 'z'):
logger.exception(self.params_str() + ' polarisation must be x, y, or z') logger.exception(self.params_str() + ' polarisation must be x, y, or z')
@@ -366,8 +397,20 @@ class MagneticDipole(UserObjectMulti):
self.hash = '#magnetic_dipole' self.hash = '#magnetic_dipole'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
rot_pol_pts, self.kwargs['polarisation'] = rotate_polarisation(self.kwargs['p1'], self.kwargs['polarisation'], axis, angle) """Set parameters for rotation."""
rot_pts = rotate_2point_object(rot_pol_pts, axis, angle, origin) self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self, grid):
"""Perform rotation."""
rot_pol_pts, self.kwargs['polarisation'] = rotate_polarisation(self.kwargs['p1'],
self.kwargs['polarisation'],
self.axis,
self.angle,
grid)
rot_pts = rotate_2point_object(rot_pol_pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
def create(self, grid, uip): def create(self, grid, uip):
@@ -379,6 +422,9 @@ class MagneticDipole(UserObjectMulti):
logger.exception(self.params_str() + ' requires at least five parameters') logger.exception(self.params_str() + ' requires at least five parameters')
raise raise
if self.dorotate:
self.__dorotate(grid)
# Check polarity & position parameters # Check polarity & position parameters
if polarisation not in ('x', 'y', 'z'): if polarisation not in ('x', 'y', 'z'):
logger.exception(self.params_str() + ' polarisation must be x, y, or z') logger.exception(self.params_str() + ' polarisation must be x, y, or z')
@@ -466,8 +512,20 @@ class TransmissionLine(UserObjectMulti):
self.hash = '#transmission_line' self.hash = '#transmission_line'
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
rot_pol_pts, self.kwargs['polarisation'] = rotate_polarisation(self.kwargs['p1'], self.kwargs['polarisation'], axis, angle) """Set parameters for rotation."""
rot_pts = rotate_2point_object(rot_pol_pts, axis, angle, origin) self.axis = axis
self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self, grid):
"""Perform rotation."""
rot_pol_pts, self.kwargs['polarisation'] = rotate_polarisation(self.kwargs['p1'],
self.kwargs['polarisation'],
self.axis,
self.angle,
grid)
rot_pts = rotate_2point_object(rot_pol_pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
def create(self, grid, uip): def create(self, grid, uip):
@@ -480,6 +538,9 @@ class TransmissionLine(UserObjectMulti):
logger.exception(self.params_str() + ' requires at least six parameters') logger.exception(self.params_str() + ' requires at least six parameters')
raise raise
if self.dorotate:
self.__dorotate(grid)
# Warn about using a transmission line on GPU # Warn about using a transmission line on GPU
if config.sim_config.general['cuda']: if config.sim_config.general['cuda']:
logger.exception(self.params_str() + ' A #transmission_line cannot currently be used with GPU solving. Consider using a #voltage_source instead.') logger.exception(self.params_str() + ' A #transmission_line cannot currently be used with GPU solving. Consider using a #voltage_source instead.')
@@ -572,11 +633,17 @@ class Rx(UserObjectMulti):
self.constructor = RxUser self.constructor = RxUser
def rotate(self, axis, angle, origin=None): def rotate(self, axis, angle, origin=None):
logger.debug('Need to get dxdydz into this function') """Set parameters for rotation."""
dxdydz = np.array([0.001, 0.001, 0.001]) self.axis = axis
new_pt = (self.kwargs['p1'][0] + dxdydz[0], self.kwargs['p1'][1] + dxdydz[1], self.kwargs['p1'][2] + dxdydz[2]) self.angle = angle
self.origin = origin
self.dorotate = True
def __dorotate(self, G):
"""Perform rotation."""
new_pt = (self.kwargs['p1'][0] + G.dx, self.kwargs['p1'][1] + G.dy, self.kwargs['p1'][2] + G.dz)
pts = np.array([self.kwargs['p1'], new_pt]) pts = np.array([self.kwargs['p1'], new_pt])
rot_pts = rotate_2point_object(pts, axis, angle, origin) rot_pts = rotate_2point_object(pts, self.axis, self.angle, self.origin)
self.kwargs['p1'] = tuple(rot_pts[0, :]) self.kwargs['p1'] = tuple(rot_pts[0, :])
# If specific field components are specified, set to output all components # If specific field components are specified, set to output all components
@@ -596,6 +663,9 @@ class Rx(UserObjectMulti):
logger.exception(self.params_str()) logger.exception(self.params_str())
raise raise
if self.dorotate:
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) print(p1)
print(p) print(p)