你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 15:10:13 +08:00
Fixed pre-commit errors and updated black version.
这个提交包含在:
@@ -9,7 +9,7 @@ repos:
|
||||
- id: check-added-large-files
|
||||
- id: check-toml
|
||||
- repo: https://github.com/psf/black-pre-commit-mirror
|
||||
rev: 23.11.0
|
||||
rev: 23.12.0
|
||||
hooks:
|
||||
- id: black
|
||||
args: ["--line-length", "120"] # Adjust the max line length value as needed.
|
||||
|
@@ -21,11 +21,11 @@ import logging
|
||||
import numpy as np
|
||||
|
||||
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 ..cython.geometry_primitives import build_voxels_from_array, build_voxels_from_array_mask
|
||||
from gprMax.cmds_geometry.cmds_geometry import UserObjectGeometry, rotate_2point_object
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -218,7 +218,8 @@ class FractalBox(UserObjectGeometry):
|
||||
# otherwise a mixing model
|
||||
if self.volume.nbins == 1:
|
||||
self.volume.fractalvolume = np.ones(
|
||||
(self.volume.nx, self.volume.ny, self.volume.nz), dtype=config.sim_config.dtypes["float_or_double"]
|
||||
(self.volume.nx, self.volume.ny, self.volume.nz),
|
||||
dtype=config.sim_config.dtypes["float_or_double"],
|
||||
)
|
||||
materialnumID = next(x.numID for x in grid.materials if x.ID == self.volume.operatingonID)
|
||||
self.volume.fractalvolume *= materialnumID
|
||||
@@ -253,11 +254,17 @@ class FractalBox(UserObjectGeometry):
|
||||
for j in range(surface.ys, surface.yf):
|
||||
for k in range(surface.zs, surface.zf):
|
||||
if i < surface.fractalsurface[j - surface.ys, k - surface.zs]:
|
||||
self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] = 1
|
||||
self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
] = 1
|
||||
elif surface.filldepth > 0 and i < surface.filldepth:
|
||||
self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] = 2
|
||||
self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
] = 2
|
||||
else:
|
||||
self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] = 0
|
||||
self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
] = 0
|
||||
elif surface.ID == "grass":
|
||||
g = surface.grass[0]
|
||||
# Build the blades of the grass
|
||||
@@ -269,7 +276,10 @@ class FractalBox(UserObjectGeometry):
|
||||
for i in range(self.volume.xs, surface.fractalrange[1]):
|
||||
if (
|
||||
i < surface.fractalsurface[j - surface.ys, k - surface.zs]
|
||||
and self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] != 1
|
||||
and self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
]
|
||||
!= 1
|
||||
):
|
||||
y, z = g.calculate_blade_geometry(blade, height)
|
||||
# Add y, z coordinates to existing location
|
||||
@@ -304,7 +314,10 @@ class FractalBox(UserObjectGeometry):
|
||||
surface.fractalsurface[j - surface.ys, k - surface.zs]
|
||||
- self.volume.originalxf
|
||||
)
|
||||
and self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] == 1
|
||||
and self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
]
|
||||
== 1
|
||||
):
|
||||
y, z = g.calculate_root_geometry(root, depth)
|
||||
# Add y, z coordinates to existing location
|
||||
@@ -342,11 +355,17 @@ class FractalBox(UserObjectGeometry):
|
||||
for j in range(surface.fractalrange[0], surface.fractalrange[1]):
|
||||
for k in range(surface.zs, surface.zf):
|
||||
if j < surface.fractalsurface[i - surface.xs, k - surface.zs]:
|
||||
self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] = 1
|
||||
self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
] = 1
|
||||
elif surface.filldepth > 0 and j < surface.filldepth:
|
||||
self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] = 2
|
||||
self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
] = 2
|
||||
else:
|
||||
self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] = 0
|
||||
self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
] = 0
|
||||
elif surface.ID == "grass":
|
||||
g = surface.grass[0]
|
||||
# Build the blades of the grass
|
||||
@@ -358,7 +377,10 @@ class FractalBox(UserObjectGeometry):
|
||||
for j in range(self.volume.ys, surface.fractalrange[1]):
|
||||
if (
|
||||
j < surface.fractalsurface[i - surface.xs, k - surface.zs]
|
||||
and self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] != 1
|
||||
and self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
]
|
||||
!= 1
|
||||
):
|
||||
x, z = g.calculate_blade_geometry(blade, height)
|
||||
# Add x, z coordinates to existing location
|
||||
@@ -393,7 +415,10 @@ class FractalBox(UserObjectGeometry):
|
||||
surface.fractalsurface[i - surface.xs, k - surface.zs]
|
||||
- self.volume.originalyf
|
||||
)
|
||||
and self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] == 1
|
||||
and self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
]
|
||||
== 1
|
||||
):
|
||||
x, z = g.calculate_root_geometry(root, depth)
|
||||
# Add x, z coordinates to existing location
|
||||
@@ -431,11 +456,17 @@ class FractalBox(UserObjectGeometry):
|
||||
for j in range(surface.ys, surface.yf):
|
||||
for k in range(surface.fractalrange[0], surface.fractalrange[1]):
|
||||
if k < surface.fractalsurface[i - surface.xs, j - surface.ys]:
|
||||
self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] = 1
|
||||
self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
] = 1
|
||||
elif surface.filldepth > 0 and k < surface.filldepth:
|
||||
self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] = 2
|
||||
self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
] = 2
|
||||
else:
|
||||
self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] = 0
|
||||
self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
] = 0
|
||||
elif surface.ID == "grass":
|
||||
g = surface.grass[0]
|
||||
# Build the blades of the grass
|
||||
@@ -447,7 +478,10 @@ class FractalBox(UserObjectGeometry):
|
||||
for k in range(self.volume.zs, surface.fractalrange[1]):
|
||||
if (
|
||||
k < surface.fractalsurface[i - surface.xs, j - surface.ys]
|
||||
and self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] != 1
|
||||
and self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
]
|
||||
!= 1
|
||||
):
|
||||
x, y = g.calculate_blade_geometry(blade, height)
|
||||
# Add x, y coordinates to existing location
|
||||
@@ -482,7 +516,10 @@ class FractalBox(UserObjectGeometry):
|
||||
surface.fractalsurface[i - surface.xs, j - surface.ys]
|
||||
- self.volume.originalzf
|
||||
)
|
||||
and self.volume.mask[i - self.volume.xs, j - self.volume.ys, k - self.volume.zs] == 1
|
||||
and self.volume.mask[
|
||||
i - self.volume.xs, j - self.volume.ys, k - self.volume.zs
|
||||
]
|
||||
== 1
|
||||
):
|
||||
x, y = g.calculate_root_geometry(root, depth)
|
||||
# Add x, y coordinates to existing location
|
||||
|
@@ -90,9 +90,7 @@ class ModelConfig:
|
||||
except:
|
||||
deviceID = 0
|
||||
|
||||
self.device = {"dev": sim_config.set_model_device(deviceID),
|
||||
"deviceID": deviceID,
|
||||
"snapsgpu2cpu": False}
|
||||
self.device = {"dev": sim_config.set_model_device(deviceID), "deviceID": deviceID, "snapsgpu2cpu": False}
|
||||
|
||||
# Total memory usage for all grids in the model. Starts with 50MB overhead.
|
||||
self.mem_overhead = 65e6
|
||||
|
@@ -23,6 +23,7 @@ import sys
|
||||
|
||||
import humanize
|
||||
from colorama import Fore, Style, init
|
||||
|
||||
init()
|
||||
|
||||
import gprMax.config as config
|
||||
@@ -141,9 +142,11 @@ class MPIContext(Context):
|
||||
model_config = config.ModelConfig()
|
||||
# Set GPU deviceID according to worker rank
|
||||
if config.sim_config.general["solver"] == "cuda":
|
||||
model_config.device = {"dev": config.sim_config.devices["devs"][self.rank - 1],
|
||||
model_config.device = {
|
||||
"dev": config.sim_config.devices["devs"][self.rank - 1],
|
||||
"deviceID": self.rank - 1,
|
||||
"snapsgpu2cpu": False}
|
||||
"snapsgpu2cpu": False,
|
||||
}
|
||||
config.model_configs = model_config
|
||||
|
||||
G = create_G()
|
||||
@@ -156,7 +159,7 @@ class MPIContext(Context):
|
||||
del solver, model
|
||||
|
||||
# Manual garbage collection required to stop memory leak on GPUs when
|
||||
# using pycuda
|
||||
# using pycuda
|
||||
del G
|
||||
gc.collect()
|
||||
|
||||
|
@@ -96,9 +96,7 @@ class GeometryView:
|
||||
def set_filename(self):
|
||||
"""Constructs filename from user-supplied name and model run number."""
|
||||
parts = config.get_model_config().output_file_path.parts
|
||||
self.filename = Path(*parts[:-1],
|
||||
self.filenamebase +
|
||||
config.get_model_config().appendmodelnumber)
|
||||
self.filename = Path(*parts[:-1], self.filenamebase + config.get_model_config().appendmodelnumber)
|
||||
|
||||
|
||||
class GeometryViewLines(GeometryView):
|
||||
|
@@ -309,13 +309,17 @@ class ModelBuildRun:
|
||||
if config.sim_config.general["solver"] == "opencl":
|
||||
solvername = "OpenCL"
|
||||
platformname = " on " + " ".join(config.get_model_config().device["dev"].platform.name.split())
|
||||
devicename = (f'Device {config.get_model_config().device["deviceID"]}: '
|
||||
f'{" ".join(config.get_model_config().device["dev"].name.split())}')
|
||||
devicename = (
|
||||
f'Device {config.get_model_config().device["deviceID"]}: '
|
||||
f'{" ".join(config.get_model_config().device["dev"].name.split())}'
|
||||
)
|
||||
else:
|
||||
solvername = "CUDA"
|
||||
platformname = ""
|
||||
devicename = (f'Device {config.get_model_config().device["deviceID"]}: '
|
||||
f'{" ".join(config.get_model_config().device["dev"].name().split())}')
|
||||
devicename = (
|
||||
f'Device {config.get_model_config().device["deviceID"]}: '
|
||||
f'{" ".join(config.get_model_config().device["dev"].name().split())}'
|
||||
)
|
||||
|
||||
logger.basic(
|
||||
f"\nModel {config.model_num + 1}/{config.sim_config.model_end} "
|
||||
|
@@ -18,11 +18,11 @@
|
||||
|
||||
import logging
|
||||
|
||||
from gprMax.cmds_geometry.cmds_geometry import UserObjectGeometry
|
||||
from gprMax.cmds_geometry.fractal_box import FractalBox
|
||||
from gprMax.cmds_geometry.add_grass import AddGrass
|
||||
from gprMax.cmds_geometry.add_surface_roughness import AddSurfaceRoughness
|
||||
from gprMax.cmds_geometry.add_surface_water import AddSurfaceWater
|
||||
from gprMax.cmds_geometry.cmds_geometry import UserObjectGeometry
|
||||
from gprMax.cmds_geometry.fractal_box import FractalBox
|
||||
from gprMax.cmds_multiuse import UserObjectMulti
|
||||
from gprMax.cmds_singleuse import Discretisation, Domain, TimeWindow, UserObjectSingle
|
||||
from gprMax.materials import create_built_in_materials
|
||||
@@ -74,6 +74,7 @@ class Scene:
|
||||
|
||||
def process_subgrid_cmds(self):
|
||||
"""Process all commands in any sub-grids."""
|
||||
|
||||
def func(obj):
|
||||
if isinstance(obj, SubGridUserBase):
|
||||
return True
|
||||
@@ -104,8 +105,7 @@ class Scene:
|
||||
# Check for fractal boxes and modifications and pre-process them first
|
||||
proc_cmds = []
|
||||
for obj in commands:
|
||||
if isinstance(obj, (FractalBox, AddGrass,
|
||||
AddSurfaceRoughness, AddSurfaceWater)):
|
||||
if isinstance(obj, (FractalBox, AddGrass, AddSurfaceRoughness, AddSurfaceWater)):
|
||||
self.build_obj(obj, grid)
|
||||
if isinstance(obj, (FractalBox)):
|
||||
proc_cmds.append(obj)
|
||||
|
在新工单中引用
屏蔽一个用户