Removed unnecessary if conditions at some places, and used itertools.product to make code more readable/cleaner.

这个提交包含在:
Sai-Suraj-27
2023-06-23 19:35:54 +05:30
父节点 e9416e34c8
当前提交 c0762cc112
共有 4 个文件被更改,包括 41 次插入48 次删除

查看文件

@@ -111,7 +111,7 @@ class AddGrass(UserObjectGeometry):
if ys == yf or zs == zf:
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
raise ValueError
if xs != volume.xs and xs != volume.xf:
if xs not in [volume.xs and volume.xf]:
logger.exception(f'{self.__str__()} must specify external surfaces on a fractal box')
raise ValueError
fractalrange = (round_value(limits[0] / grid.dx), round_value(limits[1] / grid.dx))
@@ -130,10 +130,10 @@ class AddGrass(UserObjectGeometry):
requestedsurface = 'xplus'
elif ys == yf:
if xs == xf or zs == zf:
if zs == zf:
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
raise ValueError
if ys != volume.ys and ys != volume.yf:
if ys not in [volume.ys and volume.yf]:
logger.exception(f'{self.__str__()} must specify external surfaces on a fractal box')
raise ValueError
fractalrange = (round_value(limits[0] / grid.dy), round_value(limits[1] / grid.dy))
@@ -152,10 +152,7 @@ class AddGrass(UserObjectGeometry):
requestedsurface = 'yplus'
elif zs == zf:
if xs == xf or ys == yf:
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
raise ValueError
if zs != volume.zs and zs != volume.zf:
if zs not in [volume.zs and volume.zf]:
logger.exception(f'{self.__str__()} must specify external surfaces on a fractal box')
raise ValueError
fractalrange = (round_value(limits[0] / grid.dz), round_value(limits[1] / grid.dz))
@@ -227,7 +224,7 @@ class AddGrass(UserObjectGeometry):
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):
if all(x.ID == 'grass' for x in grid.materials):
create_grass(grid)
# Check if time step for model is suitable for using grass

查看文件

@@ -118,7 +118,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
if ys == yf or zs == zf:
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
raise ValueError
if xs != volume.xs and xs != volume.xf:
if xs not in [volume.xs, volume.xf]:
logger.exception(f'{self.__str__()} can only be used on the external ' +
'surfaces of a fractal box')
raise ValueError
@@ -144,10 +144,10 @@ class AddSurfaceRoughness(UserObjectGeometry):
requestedsurface = 'xplus'
elif ys == yf:
if xs == xf or zs == zf:
if zs == zf:
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
raise ValueError
if ys != volume.ys and ys != volume.yf:
if ys not in [volume.ys and volume.yf]:
logger.exception(f'{self.__str__()} can only be used on the external ' +
'surfaces of a fractal box')
raise ValueError
@@ -173,10 +173,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
requestedsurface = 'yplus'
elif zs == zf:
if xs == xf or ys == yf:
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
raise ValueError
if zs != volume.zs and zs != volume.zf:
if zs not in [volume.zs and volume.zf]:
logger.exception(f'{self.__str__()} can only be used on the external ' +
'surfaces of a fractal box')
raise ValueError

查看文件

@@ -140,12 +140,11 @@ class FractalBox(UserObjectGeometry):
logger.exception(f'{self.__str__()} must be used with more than ' +
'one material from the mixing model.')
raise ValueError
if isinstance(mixingmodel, ListMaterial):
if nbins > len(mixingmodel.mat):
logger.exception(f'{self.__str__()} too many materials/bins ' +
'requested compared to materials in ' +
'mixing model.')
raise ValueError
if isinstance(mixingmodel, ListMaterial) and nbins > len(mixingmodel.mat):
logger.exception(f'{self.__str__()} too many materials/bins ' +
'requested compared to materials in ' +
'mixing model.')
raise ValueError
# Create materials from mixing model as number of bins now known
# from fractal_box command.
mixingmodel.calculate_properties(nbins, grid)

查看文件

@@ -3,9 +3,11 @@
receiver at the centre.
"""
from pathlib import Path
import gprMax
import itertools
# File path for output
fn = Path(__file__)
@@ -17,38 +19,36 @@ ompthreads = [1, 2, 4, 8, 16, 32, 64, 128]
scenes = []
for d in domains:
for threads in ompthreads:
# Discretisation
dl = 0.001
# Discretisation
dl = 0.001
for d, threads in itertools.product(domains, ompthreads):
# Domain
x = d
y = x
z = x
# Domain
x = d
y = x
z = x
scene = gprMax.Scene()
scene = gprMax.Scene()
title = gprMax.Title(name=fn.with_suffix('').name)
domain = gprMax.Domain(p1=(x, y, z))
dxdydz = gprMax.Discretisation(p1=(dl, dl, dl))
time_window = gprMax.TimeWindow(time=3e-9)
wv = gprMax.Waveform(wave_type='gaussiandotnorm', amp=1, freq=900e6,
id='MySource')
src = gprMax.HertzianDipole(p1=(x/2, y/2, z/2), polarisation='x',
waveform_id='MySource')
title = gprMax.Title(name=fn.with_suffix('').name)
domain = gprMax.Domain(p1=(x, y, z))
dxdydz = gprMax.Discretisation(p1=(dl, dl, dl))
time_window = gprMax.TimeWindow(time=3e-9)
wv = gprMax.Waveform(wave_type='gaussiandotnorm', amp=1, freq=900e6,
id='MySource')
src = gprMax.HertzianDipole(p1=(x/2, y/2, z/2), polarisation='x',
waveform_id='MySource')
omp = gprMax.OMPThreads(n=threads)
omp = gprMax.OMPThreads(n=threads)
scene.add(title)
scene.add(domain)
scene.add(dxdydz)
scene.add(time_window)
scene.add(wv)
scene.add(src)
scene.add(omp)
scenes.append(scene)
scene.add(title)
scene.add(domain)
scene.add(dxdydz)
scene.add(time_window)
scene.add(wv)
scene.add(src)
scene.add(omp)
scenes.append(scene)
# Run model
gprMax.run(scenes=scenes, n=len(scenes), geometry_only=False, outputfile=fn, gpu=None)