你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-04 11:36:52 +08:00
Update grass for parallel build
这个提交包含在:
@@ -143,7 +143,7 @@ class FractalSurface:
|
||||
|
||||
return surfacedims
|
||||
|
||||
def generate_fractal_surface(self):
|
||||
def generate_fractal_surface(self) -> bool:
|
||||
"""Generate a 2D array with a fractal distribution."""
|
||||
|
||||
surfacedims = self.get_surface_dims()
|
||||
@@ -199,6 +199,8 @@ class FractalSurface:
|
||||
- ((self.fractalrange[1] - self.fractalrange[0]) / fractalrange) * fractalmin
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class MPIFractalSurface(FractalSurface):
|
||||
def __init__(
|
||||
@@ -218,7 +220,7 @@ class MPIFractalSurface(FractalSurface):
|
||||
self.comm = comm
|
||||
self.upper_bound = upper_bound
|
||||
|
||||
def generate_fractal_surface(self):
|
||||
def generate_fractal_surface(self) -> bool:
|
||||
"""Generate a 2D array with a fractal distribution."""
|
||||
|
||||
if self.xs == self.xf:
|
||||
@@ -247,7 +249,7 @@ class MPIFractalSurface(FractalSurface):
|
||||
self.start = np.minimum(self.start, self.upper_bound)
|
||||
self.stop = np.maximum(self.stop, 0)
|
||||
self.stop = np.minimum(self.stop, self.upper_bound)
|
||||
return
|
||||
return False
|
||||
else:
|
||||
# Create new cartsesian communicator for the Fractal Surface
|
||||
comm = self.comm.Split(color=color)
|
||||
@@ -262,8 +264,17 @@ class MPIFractalSurface(FractalSurface):
|
||||
# Check domain decomosition is valid for the Fractal Volume
|
||||
if all([dim > 1 for dim in self.comm.dims]):
|
||||
raise ValueError(
|
||||
"Fractal surface must be positioned such that its MPI decomposition is 1 in at least"
|
||||
f" 1 dimension. Current decompostion is: {self.comm.dims}"
|
||||
"Fractal surface must be positioned such that its MPI decomposition is 1 in at"
|
||||
f" least 1 dimension. Current decompostion is: {self.comm.dims}"
|
||||
)
|
||||
|
||||
# Check domain decomosition is valid for the Fractal Volume
|
||||
if len(self.grass) > 0 and self.comm.size > 1:
|
||||
raise ValueError(
|
||||
"Grass cannot currently be split across multiple MPI rank. Either change the MPI "
|
||||
" decomposition such that the grass object is contained within a single MPI rank,"
|
||||
" or divide the grass object into multiple sections. Current decompostion is:"
|
||||
f" {self.comm.dims}"
|
||||
)
|
||||
|
||||
surfacedims = self.get_surface_dims()
|
||||
@@ -445,3 +456,5 @@ class MPIFractalSurface(FractalSurface):
|
||||
logger.debug(
|
||||
f"Generated fractal surface: start={self.start}, stop={self.stop}, size={self.size}, fractalrange={self.fractalrange}"
|
||||
)
|
||||
|
||||
return True
|
||||
|
@@ -173,14 +173,22 @@ class AddGrass(RotatableMixin, GeometryUserObject):
|
||||
else:
|
||||
raise ValueError(f"{self.__str__()} dimensions are not specified correctly")
|
||||
|
||||
surface = FractalSurface(xs, xf, ys, yf, zs, zf, frac_dim, seed)
|
||||
surface = grid.create_fractal_surface(xs, xf, ys, yf, zs, zf, frac_dim, seed)
|
||||
surface.ID = "grass"
|
||||
surface.surfaceID = requestedsurface
|
||||
|
||||
# Create grass geometry parameters
|
||||
# Add grass to the surface here as an MPIFractalSurface needs to
|
||||
# know if grass is present when generate_fractal_surface() is
|
||||
# called
|
||||
g = Grass(n_blades, surface.seed)
|
||||
surface.grass.append(g)
|
||||
|
||||
# Set the fractal range to scale the fractal distribution between zero and one
|
||||
surface.fractalrange = (0, 1)
|
||||
surface.operatingonID = volume.ID
|
||||
surface.generate_fractal_surface()
|
||||
if not surface.generate_fractal_surface():
|
||||
return
|
||||
if n_blades > surface.fractalsurface.shape[0] * surface.fractalsurface.shape[1]:
|
||||
raise ValueError(
|
||||
f"{self.__str__()} the specified surface is not large "
|
||||
@@ -220,10 +228,6 @@ class AddGrass(RotatableMixin, GeometryUserObject):
|
||||
surface.fractalrange[0], surface.fractalrange[1], size=1
|
||||
)
|
||||
|
||||
# Create grass geometry parameters
|
||||
g = Grass(n_blades, surface.seed)
|
||||
surface.grass.append(g)
|
||||
|
||||
# Check to see if grass has been already defined as a material
|
||||
if not any(x.ID == "grass" for x in grid.materials):
|
||||
create_grass(grid)
|
||||
|
@@ -168,7 +168,8 @@ class TestTriangleGeometry(GprMaxRegressionTest):
|
||||
@rfm.simple_test
|
||||
class TestAddGrassMpi(MpiMixin, TestAddGrass):
|
||||
tags = {"test", "mpi", "geometery", "fractal", "surface", "grass"}
|
||||
mpi_layout = parameter([[1, 2, 2], [3, 1, 3], [4, 1, 4]])
|
||||
mpi_layout = parameter([[2, 2, 2]])
|
||||
model = parameter(["add_grass_small"])
|
||||
test_dependency = TestAddGrass
|
||||
|
||||
|
||||
|
在新工单中引用
屏蔽一个用户