你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 15:10:13 +08:00
PML defaults work and docstrings
这个提交包含在:
@@ -38,7 +38,7 @@ from .geometry_outputs import save_geometry_views
|
||||
from .grid import dispersion_analysis
|
||||
from .hash_cmds_file import parse_hash_commands
|
||||
from .materials import process_materials
|
||||
from .pml import build_pml, print_pml_info, set_pml_defaults
|
||||
from .pml import build_pml, CFS, print_pml_info
|
||||
from .scene import Scene
|
||||
from .snapshots import save_snapshots
|
||||
from .utilities.host_info import mem_check_all, set_omp_threads
|
||||
@@ -137,12 +137,10 @@ class ModelBuildRun:
|
||||
# Combine available grids
|
||||
grids = [G] + G.subgrids
|
||||
|
||||
# Check for dispersive materials (and specific type) and set PML
|
||||
# defaults (must be done before memory checks)
|
||||
# Check for dispersive materials (and specific type)
|
||||
for grid in grids:
|
||||
if config.get_model_config().materials['maxpoles'] != 0:
|
||||
config.get_model_config().materials['drudelorentz'] = any([m for m in grid.materials if 'drude' in m.type or 'lorentz' in m.type])
|
||||
set_pml_defaults(grid)
|
||||
|
||||
# Set data type if any dispersive materials (must be done before memory checks)
|
||||
if config.get_model_config().materials['maxpoles'] != 0:
|
||||
@@ -157,6 +155,9 @@ class ModelBuildRun:
|
||||
# Build grids
|
||||
gridbuilders = [GridBuilder(grid) for grid in grids]
|
||||
for gb in gridbuilders:
|
||||
# Set default CFS parameter for PMLs if not user provided
|
||||
if not gb.grid.pmls['cfs']:
|
||||
gb.grid.pmls['cfs'] = [CFS()]
|
||||
logger.info(print_pml_info(gb.grid))
|
||||
if not all(value == 0 for value in gb.grid.pmls['thickness'].values()):
|
||||
gb.build_pmls()
|
||||
@@ -258,9 +259,6 @@ class ModelBuildRun:
|
||||
|
||||
Args:
|
||||
solver: solver object.
|
||||
|
||||
Returns:
|
||||
tsolve: float of time taken to execute solving (seconds).
|
||||
"""
|
||||
|
||||
# Print information about and check OpenMP threads
|
||||
@@ -303,8 +301,6 @@ class ModelBuildRun:
|
||||
# Print resource information on runtime and memory usage
|
||||
self.print_resource_info(tsolve, memsolve)
|
||||
|
||||
return tsolve
|
||||
|
||||
|
||||
class GridBuilder:
|
||||
def __init__(self, grid):
|
||||
|
@@ -16,7 +16,6 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from collections import OrderedDict
|
||||
from importlib import import_module
|
||||
|
||||
import numpy as np
|
||||
@@ -359,7 +358,7 @@ class CUDAPML(PML):
|
||||
super(CUDAPML, self).__init__(*args, **kwargs)
|
||||
|
||||
def htod_field_arrays(self):
|
||||
"""Initialise PML field and coefficient arrays on GPU."""
|
||||
"""Initialises PML field and coefficient arrays on GPU."""
|
||||
|
||||
import pycuda.gpuarray as gpuarray
|
||||
|
||||
@@ -377,14 +376,14 @@ class CUDAPML(PML):
|
||||
self.HPhi2_dev = gpuarray.to_gpu(self.HPhi2)
|
||||
|
||||
def set_blocks_per_grid(self):
|
||||
"""Set the blocks per grid size used for updating the PML field arrays
|
||||
"""Sets the blocks per grid size used for updating the PML field arrays
|
||||
on a GPU."""
|
||||
self.bpg = (int(np.ceil(((self.EPhi1_dev.shape[1] + 1) *
|
||||
(self.EPhi1_dev.shape[2] + 1) *
|
||||
(self.EPhi1_dev.shape[3] + 1)) / self.G.tpb[0])), 1, 1)
|
||||
|
||||
def get_update_funcs(self, kernelselectric, kernelsmagnetic):
|
||||
"""Get update functions from PML kernels.
|
||||
"""Gets update functions from PML kernels.
|
||||
|
||||
Args:
|
||||
kernelselectric: pycuda SourceModule containing PML kernels for
|
||||
@@ -393,13 +392,15 @@ class CUDAPML(PML):
|
||||
magnetic updates.
|
||||
"""
|
||||
|
||||
self.update_electric_dev = kernelselectric.get_function('order' + str(len(self.CFS)) + '_' + self.direction)
|
||||
self.update_magnetic_dev = kernelsmagnetic.get_function('order' + str(len(self.CFS)) + '_' + self.direction)
|
||||
self.update_electric_dev = kernelselectric.get_function('order' +
|
||||
str(len(self.CFS)) +
|
||||
'_' + self.direction)
|
||||
self.update_magnetic_dev = kernelsmagnetic.get_function('order' +
|
||||
str(len(self.CFS)) +
|
||||
'_' + self.direction)
|
||||
|
||||
def update_electric(self):
|
||||
"""This functions updates electric field components with the PML
|
||||
correction on the GPU.
|
||||
"""
|
||||
"""Updates electric field components with the PML correction on the GPU."""
|
||||
self.update_electric_dev(np.int32(self.xs),
|
||||
np.int32(self.xf),
|
||||
np.int32(self.ys),
|
||||
@@ -430,9 +431,7 @@ class CUDAPML(PML):
|
||||
block=self.G.tpb, grid=self.bpg)
|
||||
|
||||
def update_magnetic(self):
|
||||
"""This functions updates magnetic field components with the PML
|
||||
correction on the GPU.
|
||||
"""
|
||||
"""Updates magnetic field components with the PML correction on the GPU."""
|
||||
self.update_magnetic_dev(np.int32(self.xs),
|
||||
np.int32(self.xf),
|
||||
np.int32(self.ys),
|
||||
@@ -480,7 +479,7 @@ class OpenCLPML(PML):
|
||||
self.queue = queue
|
||||
|
||||
def htod_field_arrays(self):
|
||||
"""Initialise PML field and coefficient arrays on compute device."""
|
||||
"""Initialises PML field and coefficient arrays on compute device."""
|
||||
|
||||
import pyopencl.array as clarray
|
||||
|
||||
@@ -504,8 +503,8 @@ class OpenCLPML(PML):
|
||||
pass
|
||||
|
||||
def update_electric(self):
|
||||
"""This functions updates electric field components with the PML
|
||||
correction on the compute device.
|
||||
"""Updates electric field components with the PML correction on the
|
||||
compute device.
|
||||
"""
|
||||
event = self.update_electric_dev(np.int32(self.xs),
|
||||
np.int32(self.xf),
|
||||
@@ -537,8 +536,8 @@ class OpenCLPML(PML):
|
||||
event.wait()
|
||||
|
||||
def update_magnetic(self):
|
||||
"""This functions updates magnetic field components with the PML
|
||||
correction on the compute device.
|
||||
"""Updates magnetic field components with the PML correction on the
|
||||
compute device.
|
||||
"""
|
||||
event = self.update_magnetic_dev(np.int32(self.xs),
|
||||
np.int32(self.xf),
|
||||
@@ -569,23 +568,6 @@ class OpenCLPML(PML):
|
||||
config.sim_config.dtypes['float_or_double'](self.d))
|
||||
event.wait()
|
||||
|
||||
|
||||
def set_pml_defaults(G):
|
||||
"""Set default parameters for PMLs if not provided by user.
|
||||
|
||||
Args:
|
||||
G: FDTDGrid class describing a grid in a model.
|
||||
"""
|
||||
|
||||
if not G.pmls['formulation']:
|
||||
G.pmls['formulation'] = 'HORIPML'
|
||||
|
||||
if not all(G.pmls['thickness'].values()):
|
||||
G.pmls['thickness'] = OrderedDict.fromkeys(G.pmls['thickness'], 10)
|
||||
|
||||
if not G.pmls['cfs']:
|
||||
G.pmls['cfs'] = [CFS()]
|
||||
|
||||
|
||||
def print_pml_info(G):
|
||||
"""Prints information about PMLs.
|
||||
|
在新工单中引用
屏蔽一个用户