From 388e025aed04dfd4681159c879fc1529f13fd8aa Mon Sep 17 00:00:00 2001 From: nmannall Date: Mon, 20 May 2024 15:20:20 +0100 Subject: [PATCH] Revert "Refactor remaining UserObjectGeometry build processes" This reverts commit 444f2a6a7f1434612feaddfbd459a63921ff8f73. --- gprMax/cmds_geometry/add_surface_roughness.py | 5 ++-- gprMax/cmds_geometry/add_surface_water.py | 11 ++++---- gprMax/cmds_geometry/box.py | 13 +++++----- gprMax/cmds_geometry/cone.py | 13 +++++----- gprMax/cmds_geometry/cylinder.py | 13 +++++----- gprMax/cmds_geometry/cylindrical_sector.py | 13 +++++----- gprMax/cmds_geometry/edge.py | 5 ++-- gprMax/cmds_geometry/ellipsoid.py | 13 +++++----- gprMax/cmds_geometry/fractal_box.py | 25 ++++++++----------- gprMax/cmds_geometry/geometry_objects_read.py | 9 +++---- gprMax/cmds_geometry/plate.py | 5 ++-- gprMax/cmds_geometry/sphere.py | 13 +++++----- gprMax/cmds_geometry/triangle.py | 13 +++++----- gprMax/grid/fdtd_grid.py | 5 +++- gprMax/model.py | 2 -- 15 files changed, 72 insertions(+), 86 deletions(-) diff --git a/gprMax/cmds_geometry/add_surface_roughness.py b/gprMax/cmds_geometry/add_surface_roughness.py index b54d935f..a127a1ae 100644 --- a/gprMax/cmds_geometry/add_surface_roughness.py +++ b/gprMax/cmds_geometry/add_surface_roughness.py @@ -65,7 +65,7 @@ class AddSurfaceRoughness(UserObjectGeometry): self.kwargs["p1"] = tuple(rot_pts[0, :]) self.kwargs["p2"] = tuple(rot_pts[1, :]) - def build(self, model, uip): + def build(self, grid, uip): try: p1 = self.kwargs["p1"] p2 = self.kwargs["p2"] @@ -91,7 +91,7 @@ class AddSurfaceRoughness(UserObjectGeometry): self._do_rotate() # Get the correct fractal volume - volumes = [volume for volume in model.fractalvolumes if volume.ID == fractal_box_id] + volumes = [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id] if volumes: volume = volumes[0] else: @@ -121,7 +121,6 @@ class AddSurfaceRoughness(UserObjectGeometry): raise ValueError # Check for valid orientations - grid = uip.grid if xs == xf: if ys == yf or zs == zf: logger.exception(f"{self.__str__()} dimensions are not specified correctly") diff --git a/gprMax/cmds_geometry/add_surface_water.py b/gprMax/cmds_geometry/add_surface_water.py index 4614d7a9..79a6af72 100644 --- a/gprMax/cmds_geometry/add_surface_water.py +++ b/gprMax/cmds_geometry/add_surface_water.py @@ -60,7 +60,7 @@ class AddSurfaceWater(UserObjectGeometry): self.kwargs["p1"] = tuple(rot_pts[0, :]) self.kwargs["p2"] = tuple(rot_pts[1, :]) - def build(self, model, uip): + def build(self, grid, uip): """ "Create surface water on fractal box.""" try: p1 = self.kwargs["p1"] @@ -74,7 +74,7 @@ class AddSurfaceWater(UserObjectGeometry): if self.do_rotate: self._do_rotate() - if volumes := [volume for volume in model.fractalvolumes if volume.ID == fractal_box_id]: + if volumes := [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id]: volume = volumes[0] else: logger.exception(f"{self.__str__()} cannot find FractalBox {fractal_box_id}") @@ -89,7 +89,6 @@ class AddSurfaceWater(UserObjectGeometry): raise ValueError # Check for valid orientations - grid = uip.grid if xs == xf: if ys == yf or zs == zf: logger.exception(f"{self.__str__()} dimensions are not specified correctly") @@ -166,11 +165,11 @@ class AddSurfaceWater(UserObjectGeometry): raise ValueError # Check to see if water has been already defined as a material - if not any(x.ID == "water" for x in model.materials): - create_water(model) + if not any(x.ID == "water" for x in grid.materials): + create_water(grid) # Check if time step for model is suitable for using water - water = next((x for x in model.materials if x.ID == "water")) + water = next((x for x in grid.materials if x.ID == "water")) if testwater := next((x for x in water.tau if x < grid.dt), None): logger.exception( f"{self.__str__()} requires the time step for the model " diff --git a/gprMax/cmds_geometry/box.py b/gprMax/cmds_geometry/box.py index cf82e320..1544f7e5 100644 --- a/gprMax/cmds_geometry/box.py +++ b/gprMax/cmds_geometry/box.py @@ -60,7 +60,7 @@ class Box(UserObjectGeometry): self.kwargs["p1"] = tuple(rot_pts[0, :]) self.kwargs["p2"] = tuple(rot_pts[1, :]) - def build(self, model, uip): + def build(self, grid, uip): try: p1 = self.kwargs["p1"] p2 = self.kwargs["p2"] @@ -89,7 +89,7 @@ class Box(UserObjectGeometry): averagebox = self.kwargs["averaging"] except KeyError: # Otherwise go with the grid default - averagebox = model.averagevolumeobjects + averagebox = grid.averagevolumeobjects p3, p4 = uip.check_box_points(p1, p2, self.__str__()) # Find nearest point on grid without translation @@ -99,7 +99,7 @@ class Box(UserObjectGeometry): xf, yf, zf = p4 # Look up requested materials in existing list of material instances - materials = [y for x in materialsrequested for y in model.materials if y.ID == x] + materials = [y for x in materialsrequested for y in grid.materials if y.ID == x] if len(materials) != len(materialsrequested): notfound = [x for x in materialsrequested if x not in materials] @@ -118,11 +118,11 @@ class Box(UserObjectGeometry): numIDy = materials[1].numID numIDz = materials[2].numID requiredID = materials[0].ID + "+" + materials[1].ID + "+" + materials[2].ID - averagedmaterial = [x for x in model.materials if x.ID == requiredID] + averagedmaterial = [x for x in grid.materials if x.ID == requiredID] if averagedmaterial: numID = averagedmaterial.numID else: - numID = len(model.materials) + numID = len(grid.materials) m = Material(numID, requiredID) m.type = "dielectric-smoothed" # Create dielectric-smoothed constituents for material @@ -132,9 +132,8 @@ class Box(UserObjectGeometry): m.sm = np.mean((materials[0].sm, materials[1].sm, materials[2].sm), axis=0) # Append the new material object to the materials list - model.materials.append(m) + grid.materials.append(m) - grid = uip.grid build_box( xs, xf, diff --git a/gprMax/cmds_geometry/cone.py b/gprMax/cmds_geometry/cone.py index e5a1a98c..dfde0650 100644 --- a/gprMax/cmds_geometry/cone.py +++ b/gprMax/cmds_geometry/cone.py @@ -48,7 +48,7 @@ class Cone(UserObjectGeometry): super().__init__(**kwargs) self.hash = "#cone" - def build(self, model, uip): + def build(self, grid, uip): try: p1 = self.kwargs["p1"] p2 = self.kwargs["p2"] @@ -64,7 +64,7 @@ class Cone(UserObjectGeometry): averagecylinder = self.kwargs["averaging"] except KeyError: # Otherwise go with the grid default - averagecylinder = model.averagevolumeobjects + averagecylinder = grid.averagevolumeobjects # Check materials have been specified # Isotropic case @@ -101,7 +101,7 @@ class Cone(UserObjectGeometry): raise ValueError # Look up requested materials in existing list of material instances - materials = [y for x in materialsrequested for y in model.materials if y.ID == x] + materials = [y for x in materialsrequested for y in grid.materials if y.ID == x] if len(materials) != len(materialsrequested): notfound = [x for x in materialsrequested if x not in materials] @@ -120,11 +120,11 @@ class Cone(UserObjectGeometry): numIDy = materials[1].numID numIDz = materials[2].numID requiredID = materials[0].ID + "+" + materials[1].ID + "+" + materials[2].ID - averagedmaterial = [x for x in model.materials if x.ID == requiredID] + averagedmaterial = [x for x in grid.materials if x.ID == requiredID] if averagedmaterial: numID = averagedmaterial.numID else: - numID = len(model.materials) + numID = len(grid.materials) m = Material(numID, requiredID) m.type = "dielectric-smoothed" # Create dielectric-smoothed constituents for material @@ -134,9 +134,8 @@ class Cone(UserObjectGeometry): m.sm = np.mean((materials[0].sm, materials[1].sm, materials[2].sm), axis=0) # Append the new material object to the materials list - model.materials.append(m) + grid.materials.append(m) - grid = uip.grid build_cone( x1, y1, diff --git a/gprMax/cmds_geometry/cylinder.py b/gprMax/cmds_geometry/cylinder.py index 7c91c157..d29c015f 100644 --- a/gprMax/cmds_geometry/cylinder.py +++ b/gprMax/cmds_geometry/cylinder.py @@ -46,7 +46,7 @@ class Cylinder(UserObjectGeometry): super().__init__(**kwargs) self.hash = "#cylinder" - def build(self, model, uip): + def build(self, grid, uip): try: p1 = self.kwargs["p1"] p2 = self.kwargs["p2"] @@ -61,7 +61,7 @@ class Cylinder(UserObjectGeometry): averagecylinder = self.kwargs["averaging"] except KeyError: # Otherwise go with the grid default - averagecylinder = model.averagevolumeobjects + averagecylinder = grid.averagevolumeobjects # Check materials have been specified # Isotropic case @@ -86,7 +86,7 @@ class Cylinder(UserObjectGeometry): raise ValueError # Look up requested materials in existing list of material instances - materials = [y for x in materialsrequested for y in model.materials if y.ID == x] + materials = [y for x in materialsrequested for y in grid.materials if y.ID == x] if len(materials) != len(materialsrequested): notfound = [x for x in materialsrequested if x not in materials] @@ -105,11 +105,11 @@ class Cylinder(UserObjectGeometry): numIDy = materials[1].numID numIDz = materials[2].numID requiredID = materials[0].ID + "+" + materials[1].ID + "+" + materials[2].ID - averagedmaterial = [x for x in model.materials if x.ID == requiredID] + averagedmaterial = [x for x in grid.materials if x.ID == requiredID] if averagedmaterial: numID = averagedmaterial.numID else: - numID = len(model.materials) + numID = len(grid.materials) m = Material(numID, requiredID) m.type = "dielectric-smoothed" # Create dielectric-smoothed constituents for material @@ -119,9 +119,8 @@ class Cylinder(UserObjectGeometry): m.sm = np.mean((materials[0].sm, materials[1].sm, materials[2].sm), axis=0) # Append the new material object to the materials list - model.materials.append(m) + grid.materials.append(m) - grid = uip.grid build_cylinder( x1, y1, diff --git a/gprMax/cmds_geometry/cylindrical_sector.py b/gprMax/cmds_geometry/cylindrical_sector.py index 00be9fb5..849a41c5 100644 --- a/gprMax/cmds_geometry/cylindrical_sector.py +++ b/gprMax/cmds_geometry/cylindrical_sector.py @@ -55,7 +55,7 @@ class CylindricalSector(UserObjectGeometry): super().__init__(**kwargs) self.hash = "#cylindrical_sector" - def build(self, model, uip): + def build(self, grid, uip): try: normal = self.kwargs["normal"].lower() ctr1 = self.kwargs["ctr1"] @@ -76,7 +76,7 @@ class CylindricalSector(UserObjectGeometry): averagecylindricalsector = self.kwargs["averaging"] except KeyError: # Otherwise go with the grid default - averagecylindricalsector = model.averagevolumeobjects + averagecylindricalsector = grid.averagevolumeobjects # Check materials have been specified # Isotropic case @@ -110,7 +110,7 @@ class CylindricalSector(UserObjectGeometry): raise ValueError # Look up requested materials in existing list of material instances - materials = [y for x in materialsrequested for y in model.materials if y.ID == x] + materials = [y for x in materialsrequested for y in grid.materials if y.ID == x] if len(materials) != len(materialsrequested): notfound = [x for x in materialsrequested if x not in materials] @@ -129,11 +129,11 @@ class CylindricalSector(UserObjectGeometry): numIDy = materials[1].numID numIDz = materials[2].numID requiredID = f"{materials[0].ID}+{materials[1].ID}+{materials[2].ID}" - averagedmaterial = [x for x in model.materials if x.ID == requiredID] + averagedmaterial = [x for x in grid.materials if x.ID == requiredID] if averagedmaterial: numID = averagedmaterial.numID else: - numID = len(model.materials) + numID = len(grid.materials) m = Material(numID, requiredID) m.type = "dielectric-smoothed" # Create dielectric-smoothed constituents for material @@ -143,7 +143,7 @@ class CylindricalSector(UserObjectGeometry): m.sm = np.mean((materials[0].sm, materials[1].sm, materials[2].sm), axis=0) # Append the new material object to the materials list - model.materials.append(m) + grid.materials.append(m) else: averaging = False # Isotropic case @@ -170,7 +170,6 @@ class CylindricalSector(UserObjectGeometry): elif normal == "z": ctr1, ctr2, level = uip.round_to_grid((ctr1, ctr2, extent1)) - grid = uip.grid build_cylindrical_sector( ctr1, ctr2, diff --git a/gprMax/cmds_geometry/edge.py b/gprMax/cmds_geometry/edge.py index 4f4665bf..e6a0ca88 100644 --- a/gprMax/cmds_geometry/edge.py +++ b/gprMax/cmds_geometry/edge.py @@ -54,7 +54,7 @@ class Edge(UserObjectGeometry): self.kwargs["p1"] = tuple(rot_pts[0, :]) self.kwargs["p2"] = tuple(rot_pts[1, :]) - def build(self, model, uip): + def build(self, grid, uip): """Creates edge and adds it to the grid.""" try: p1 = self.kwargs["p1"] @@ -74,13 +74,12 @@ class Edge(UserObjectGeometry): xs, ys, zs = p1 xf, yf, zf = p2 - material = next((x for x in model.materials if x.ID == material_id), None) + material = next((x for x in grid.materials if x.ID == material_id), None) if not material: logger.exception(f"Material with ID {material_id} does not exist") raise ValueError - grid = uip.grid # Check for valid orientations # x-orientated edge if ( diff --git a/gprMax/cmds_geometry/ellipsoid.py b/gprMax/cmds_geometry/ellipsoid.py index edc0861b..dc4f16a1 100644 --- a/gprMax/cmds_geometry/ellipsoid.py +++ b/gprMax/cmds_geometry/ellipsoid.py @@ -45,7 +45,7 @@ class Ellipsoid(UserObjectGeometry): super().__init__(**kwargs) self.hash = "#ellipsoid" - def build(self, model, uip): + def build(self, grid, uip): try: p1 = self.kwargs["p1"] xr = self.kwargs["xr"] @@ -62,7 +62,7 @@ class Ellipsoid(UserObjectGeometry): averageellipsoid = self.kwargs["averaging"] except KeyError: # Otherwise go with the grid default - averageellipsoid = model.averagevolumeobjects + averageellipsoid = grid.averagevolumeobjects # Check materials have been specified # Isotropic case @@ -81,7 +81,7 @@ class Ellipsoid(UserObjectGeometry): xc, yc, zc = uip.discretise_point(p1) # Look up requested materials in existing list of material instances - materials = [y for x in materialsrequested for y in model.materials if y.ID == x] + materials = [y for x in materialsrequested for y in grid.materials if y.ID == x] if len(materials) != len(materialsrequested): notfound = [x for x in materialsrequested if x not in materials] @@ -100,11 +100,11 @@ class Ellipsoid(UserObjectGeometry): numIDy = materials[1].numID numIDz = materials[2].numID requiredID = materials[0].ID + "+" + materials[1].ID + "+" + materials[2].ID - averagedmaterial = [x for x in model.materials if x.ID == requiredID] + averagedmaterial = [x for x in grid.materials if x.ID == requiredID] if averagedmaterial: numID = averagedmaterial.numID else: - numID = len(model.materials) + numID = len(grid.materials) m = Material(numID, requiredID) m.type = "dielectric-smoothed" # Create dielectric-smoothed constituents for material @@ -114,9 +114,8 @@ class Ellipsoid(UserObjectGeometry): m.sm = np.mean((materials[0].sm, materials[1].sm, materials[2].sm), axis=0) # Append the new material object to the materials list - model.materials.append(m) + grid.materials.append(m) - grid = uip.grid build_ellipsoid( xc, yc, diff --git a/gprMax/cmds_geometry/fractal_box.py b/gprMax/cmds_geometry/fractal_box.py index f5eecaa7..af5d9bba 100644 --- a/gprMax/cmds_geometry/fractal_box.py +++ b/gprMax/cmds_geometry/fractal_box.py @@ -24,8 +24,6 @@ import gprMax.config as config from gprMax.cmds_geometry.cmds_geometry import UserObjectGeometry, rotate_2point_object from gprMax.fractals import FractalVolume from gprMax.materials import ListMaterial -from gprMax.model import Model -from gprMax.user_inputs import MainGridUserInput from ..cython.geometry_primitives import build_voxels_from_array, build_voxels_from_array_mask @@ -75,7 +73,7 @@ class FractalBox(UserObjectGeometry): self.kwargs["p1"] = tuple(rot_pts[0, :]) self.kwargs["p2"] = tuple(rot_pts[1, :]) - def pre_build(self, model: Model, uip: MainGridUserInput): + def pre_build(self, grid, uip): try: p1 = self.kwargs["p1"] p2 = self.kwargs["p2"] @@ -142,8 +140,8 @@ class FractalBox(UserObjectGeometry): # Find materials to use to build fractal volume, either from mixing # models or normal materials. - mixingmodel = next((x for x in model.mixingmodels if x.ID == mixing_model_id), None) - material = next((x for x in model.materials if x.ID == mixing_model_id), None) + mixingmodel = next((x for x in grid.mixingmodels if x.ID == mixing_model_id), None) + material = next((x for x in grid.materials if x.ID == mixing_model_id), None) nbins = n_materials if mixingmodel: @@ -161,7 +159,7 @@ class FractalBox(UserObjectGeometry): raise ValueError # Create materials from mixing model as number of bins now known # from fractal_box command. - mixingmodel.calculate_properties(nbins, model) + mixingmodel.calculate_properties(nbins, grid) elif not material: logger.exception( f"{self.__str__()} mixing model or material with " @@ -179,7 +177,7 @@ class FractalBox(UserObjectGeometry): dielectricsmoothing = "on" if self.volume.averaging else "off" logger.info( - f"{self.grid_name(uip.grid)}Fractal box {self.volume.ID} from " + f"{self.grid_name(grid)}Fractal box {self.volume.ID} from " f"{p3[0]:g}m, {p3[1]:g}m, {p3[2]:g}m, to {p4[0]:g}m, " f"{p4[1]:g}m, {p4[2]:g}m with {self.volume.operatingonID}, " f"fractal dimension {self.volume.dimension:g}, fractal weightings " @@ -188,14 +186,13 @@ class FractalBox(UserObjectGeometry): f"with {self.volume.nbins} material(s) created, dielectric smoothing " f"is {dielectricsmoothing}." ) - model.fractalvolumes.append(self.volume) + grid.fractalvolumes.append(self.volume) - def build(self, model, uip): + def build(self, grid, uip): if self.do_pre_build: - self.pre_build(model, uip) + self.pre_build(grid, uip) self.do_pre_build = False else: - grid = uip.grid if self.volume.fractalsurfaces: self.volume.originalxs = self.volume.xs self.volume.originalxf = self.volume.xf @@ -240,7 +237,7 @@ class FractalBox(UserObjectGeometry): dtype=config.sim_config.dtypes["float_or_double"], ) materialnumID = next( - x.numID for x in model.materials if x.ID == self.volume.operatingonID + x.numID for x in grid.materials if x.ID == self.volume.operatingonID ) self.volume.fractalvolume *= materialnumID else: @@ -655,8 +652,8 @@ class FractalBox(UserObjectGeometry): root += 1 # Build voxels from any true values of the 3D mask array - waternumID = next((x.numID for x in model.materials if x.ID == "water"), 0) - grassnumID = next((x.numID for x in model.materials if x.ID == "grass"), 0) + waternumID = next((x.numID for x in grid.materials if x.ID == "water"), 0) + grassnumID = next((x.numID for x in grid.materials if x.ID == "grass"), 0) data = self.volume.fractalvolume.astype("int16", order="C") mask = self.volume.mask.copy(order="C") build_voxels_from_array_mask( diff --git a/gprMax/cmds_geometry/geometry_objects_read.py b/gprMax/cmds_geometry/geometry_objects_read.py index 233260d4..46b7c243 100644 --- a/gprMax/cmds_geometry/geometry_objects_read.py +++ b/gprMax/cmds_geometry/geometry_objects_read.py @@ -39,7 +39,7 @@ class GeometryObjectsRead(UserObjectGeometry): def rotate(self, axis, angle, origin=None): pass - def build(self, model, uip): + def build(self, grid, uip): """Creates the object and adds it to the grid.""" try: p1 = self.kwargs["p1"] @@ -62,7 +62,7 @@ class GeometryObjectsRead(UserObjectGeometry): matfile = Path(config.sim_config.input_file_path.parent, matfile) matstr = matfile.with_suffix("").name - numexistmaterials = len(model.materials) + numexistmaterials = len(grid.materials) # Read materials from file with open(matfile, "r") as f: @@ -82,10 +82,10 @@ class GeometryObjectsRead(UserObjectGeometry): scene.add(material_obj) # Creates the internal simulation objects - scene.process_cmds(material_objs, model) + scene.process_cmds(material_objs, grid) # Update material type - for material in model.materials: + for material in grid.materials: if material.numID >= numexistmaterials: if material.type: material.type += ",\nimported" @@ -101,7 +101,6 @@ class GeometryObjectsRead(UserObjectGeometry): # Open geometry object file and read/check spatial resolution attribute f = h5py.File(geofile, "r") dx_dy_dz = f.attrs["dx_dy_dz"] - grid = uip.grid if round_value( (dx_dy_dz[0] / grid.dx) != 1 or round_value(dx_dy_dz[1] / grid.dy) != 1 diff --git a/gprMax/cmds_geometry/plate.py b/gprMax/cmds_geometry/plate.py index 907eb155..8ac92cb2 100644 --- a/gprMax/cmds_geometry/plate.py +++ b/gprMax/cmds_geometry/plate.py @@ -55,7 +55,7 @@ class Plate(UserObjectGeometry): self.kwargs["p1"] = tuple(rot_pts[0, :]) self.kwargs["p2"] = tuple(rot_pts[1, :]) - def build(self, model, uip): + def build(self, grid, uip): try: p1 = self.kwargs["p1"] p2 = self.kwargs["p2"] @@ -94,14 +94,13 @@ class Plate(UserObjectGeometry): raise ValueError # Look up requested materials in existing list of material instances - materials = [y for x in materialsrequested for y in model.materials if y.ID == x] + materials = [y for x in materialsrequested for y in grid.materials if y.ID == x] if len(materials) != len(materialsrequested): notfound = [x for x in materialsrequested if x not in materials] logger.exception(f"{self.__str__()} material(s) {notfound} do not exist") raise ValueError - grid = uip.grid # yz-plane plate if xs == xf: # Isotropic case diff --git a/gprMax/cmds_geometry/sphere.py b/gprMax/cmds_geometry/sphere.py index ed8da164..185cac80 100644 --- a/gprMax/cmds_geometry/sphere.py +++ b/gprMax/cmds_geometry/sphere.py @@ -43,7 +43,7 @@ class Sphere(UserObjectGeometry): super().__init__(**kwargs) self.hash = "#sphere" - def build(self, model, uip): + def build(self, grid, uip): try: p1 = self.kwargs["p1"] r = self.kwargs["r"] @@ -57,7 +57,7 @@ class Sphere(UserObjectGeometry): averagesphere = self.kwargs["averaging"] except KeyError: # Otherwise go with the grid default - averagesphere = model.averagevolumeobjects + averagesphere = grid.averagevolumeobjects # Check materials have been specified # Isotropic case @@ -76,7 +76,7 @@ class Sphere(UserObjectGeometry): xc, yc, zc = uip.discretise_point(p1) # Look up requested materials in existing list of material instances - materials = [y for x in materialsrequested for y in model.materials if y.ID == x] + materials = [y for x in materialsrequested for y in grid.materials if y.ID == x] if len(materials) != len(materialsrequested): notfound = [x for x in materialsrequested if x not in materials] @@ -95,11 +95,11 @@ class Sphere(UserObjectGeometry): numIDy = materials[1].numID numIDz = materials[2].numID requiredID = materials[0].ID + "+" + materials[1].ID + "+" + materials[2].ID - averagedmaterial = [x for x in model.materials if x.ID == requiredID] + averagedmaterial = [x for x in grid.materials if x.ID == requiredID] if averagedmaterial: numID = averagedmaterial.numID else: - numID = len(model.materials) + numID = len(grid.materials) m = Material(numID, requiredID) m.type = "dielectric-smoothed" # Create dielectric-smoothed constituents for material @@ -109,9 +109,8 @@ class Sphere(UserObjectGeometry): m.sm = np.mean((materials[0].sm, materials[1].sm, materials[2].sm), axis=0) # Append the new material object to the materials list - model.materials.append(m) + grid.materials.append(m) - grid = uip.grid build_sphere( xc, yc, diff --git a/gprMax/cmds_geometry/triangle.py b/gprMax/cmds_geometry/triangle.py index 808e6064..714524c2 100644 --- a/gprMax/cmds_geometry/triangle.py +++ b/gprMax/cmds_geometry/triangle.py @@ -63,7 +63,7 @@ class Triangle(UserObjectGeometry): self.kwargs["p2"] = tuple(p2) self.kwargs["p3"] = tuple(p3) - def build(self, model, uip): + def build(self, grid, uip): try: up1 = self.kwargs["p1"] up2 = self.kwargs["p2"] @@ -82,7 +82,7 @@ class Triangle(UserObjectGeometry): averagetriangularprism = self.kwargs["averaging"] except KeyError: # Otherwise go with the grid default - averagetriangularprism = model.averagevolumeobjects + averagetriangularprism = grid.averagevolumeobjects # Check materials have been specified # Isotropic case @@ -126,7 +126,7 @@ class Triangle(UserObjectGeometry): raise ValueError # Look up requested materials in existing list of material instances - materials = [y for x in materialsrequested for y in model.materials if y.ID == x] + materials = [y for x in materialsrequested for y in grid.materials if y.ID == x] if len(materials) != len(materialsrequested): notfound = [x for x in materialsrequested if x not in materials] @@ -146,11 +146,11 @@ class Triangle(UserObjectGeometry): numIDy = materials[1].numID numIDz = materials[2].numID requiredID = materials[0].ID + "+" + materials[1].ID + "+" + materials[2].ID - averagedmaterial = [x for x in model.materials if x.ID == requiredID] + averagedmaterial = [x for x in grid.materials if x.ID == requiredID] if averagedmaterial: numID = averagedmaterial.numID else: - numID = len(model.materials) + numID = len(grid.materials) m = Material(numID, requiredID) m.type = "dielectric-smoothed" # Create dielectric-smoothed constituents for material @@ -160,7 +160,7 @@ class Triangle(UserObjectGeometry): m.sm = np.mean((materials[0].sm, materials[1].sm, materials[2].sm), axis=0) # Append the new material object to the materials list - model.materials.append(m) + grid.materials.append(m) else: averaging = False # Isotropic case @@ -175,7 +175,6 @@ class Triangle(UserObjectGeometry): numIDy = materials[1].numID numIDz = materials[2].numID - grid = uip.grid build_triangle( x1, y1, diff --git a/gprMax/grid/fdtd_grid.py b/gprMax/grid/fdtd_grid.py index 17cebba6..1660db42 100644 --- a/gprMax/grid/fdtd_grid.py +++ b/gprMax/grid/fdtd_grid.py @@ -32,7 +32,8 @@ from gprMax import config from gprMax.cython.yee_cell_build import build_electric_components, build_magnetic_components # from gprMax.geometry_outputs import GeometryObjects, GeometryView -from gprMax.materials import Material, process_materials +from gprMax.fractals import FractalVolume +from gprMax.materials import ListMaterial, Material, PeplinskiSoil, RangeMaterial, process_materials from gprMax.pml import CFS, PML, build_pml, print_pml_info from gprMax.receivers import Rx from gprMax.snapshots import Snapshot @@ -95,6 +96,8 @@ class FDTDGrid: self.pmls["thickness"] = OrderedDict((key, 10) for key in PML.boundaryIDs) self.materials: List[Material] = [] + self.mixingmodels: List[Union[PeplinskiSoil, RangeMaterial, ListMaterial]] = [] + self.fractalvolumes: List[FractalVolume] = [] self.waveforms: List[Waveform] = [] self.voltagesources: List[VoltageSource] = [] self.hertziandipoles: List[HertzianDipole] = [] diff --git a/gprMax/model.py b/gprMax/model.py index 496ecb88..0a6c0cd3 100644 --- a/gprMax/model.py +++ b/gprMax/model.py @@ -66,8 +66,6 @@ class Model: self.G = self._create_grid() self.subgrids: List[SubGridBaseGrid] = [] - self.mixingmodels: List[Union[PeplinskiSoil, RangeMaterial, ListMaterial]] = [] - self.geometryviews: List[GeometryView] = [] self.geometryobjects: List[GeometryObjects] = []