你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 07:24:19 +08:00
More work for GPU.
这个提交包含在:
@@ -84,7 +84,7 @@ class Waveform(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 0
|
self.order = 1
|
||||||
self.hash = '#waveform'
|
self.hash = '#waveform'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -133,7 +133,7 @@ class VoltageSource(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 1
|
self.order = 2
|
||||||
self.hash = '#voltage_source'
|
self.hash = '#voltage_source'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -219,7 +219,7 @@ class HertzianDipole(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 2
|
self.order = 3
|
||||||
self.hash = '#hertzian_dipole'
|
self.hash = '#hertzian_dipole'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -315,7 +315,7 @@ class MagneticDipole(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 3
|
self.order = 4
|
||||||
self.hash = '#magnetic_dipole'
|
self.hash = '#magnetic_dipole'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -401,7 +401,7 @@ class TransmissionLine(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 4
|
self.order = 5
|
||||||
self.hash = '#transmission_line'
|
self.hash = '#transmission_line'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -490,7 +490,7 @@ class Rx(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 5
|
self.order = 6
|
||||||
self.hash = '#rx'
|
self.hash = '#rx'
|
||||||
self.constructor = RxUser
|
self.constructor = RxUser
|
||||||
|
|
||||||
@@ -544,7 +544,7 @@ class RxArray(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 6
|
self.order = 7
|
||||||
self.hash = '#rx_array'
|
self.hash = '#rx_array'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -617,7 +617,7 @@ class Snapshot(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 19
|
self.order = 8
|
||||||
self.hash = '#snapshot'
|
self.hash = '#snapshot'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -684,7 +684,7 @@ class Material(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 8
|
self.order = 9
|
||||||
self.hash = '#material'
|
self.hash = '#material'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -744,12 +744,12 @@ class AddDebyeDispersion(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 9
|
self.order = 10
|
||||||
self.hash = '#add_dispersion_debye'
|
self.hash = '#add_dispersion_debye'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
try:
|
try:
|
||||||
poles = self.kwargs['n_poles']
|
poles = self.kwargs['poles']
|
||||||
er_delta = self.kwargs['er_delta']
|
er_delta = self.kwargs['er_delta']
|
||||||
tau = self.kwargs['tau']
|
tau = self.kwargs['tau']
|
||||||
material_ids = self.kwargs['material_ids']
|
material_ids = self.kwargs['material_ids']
|
||||||
@@ -782,8 +782,8 @@ class AddDebyeDispersion(UserObjectMulti):
|
|||||||
disp_material.tau.append(tau[i])
|
disp_material.tau.append(tau[i])
|
||||||
else:
|
else:
|
||||||
raise CmdInputError(f"'{self.params_str()}' requires positive values for the permittivity difference.")
|
raise CmdInputError(f"'{self.params_str()}' requires positive values for the permittivity difference.")
|
||||||
if disp_material.poles > config.model_configs[grid.model_num].materials['maxpoles']:
|
if disp_material.poles > config.get_model_config().materials['maxpoles']:
|
||||||
config.model_configs[grid.model_num].materials['maxpoles'] = disp_material.poles
|
config.get_model_config().materials['maxpoles'] = disp_material.poles
|
||||||
|
|
||||||
# Replace original material with newly created DispersiveMaterial
|
# Replace original material with newly created DispersiveMaterial
|
||||||
grid.materials = [disp_material if mat.numID==material.numID else mat for mat in grid.materials]
|
grid.materials = [disp_material if mat.numID==material.numID else mat for mat in grid.materials]
|
||||||
@@ -808,12 +808,12 @@ class AddLorentzDispersion(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 10
|
self.order = 11
|
||||||
self.hash = '#add_dispersion_lorentz'
|
self.hash = '#add_dispersion_lorentz'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
try:
|
try:
|
||||||
poles = self.kwargs['n_poles']
|
poles = self.kwargs['poles']
|
||||||
er_delta = self.kwargs['er_delta']
|
er_delta = self.kwargs['er_delta']
|
||||||
tau = self.kwargs['omega']
|
tau = self.kwargs['omega']
|
||||||
alpha = self.kwargs['delta']
|
alpha = self.kwargs['delta']
|
||||||
@@ -832,20 +832,28 @@ class AddLorentzDispersion(UserObjectMulti):
|
|||||||
raise CmdInputError(f"'{self.params_str()}' material(s) {notfound} do not exist")
|
raise CmdInputError(f"'{self.params_str()}' material(s) {notfound} do not exist")
|
||||||
|
|
||||||
for material in materials:
|
for material in materials:
|
||||||
material.type = 'lorentz'
|
disp_material = DispersiveMaterialUser(material.numID, material.ID)
|
||||||
material.poles = poles
|
disp_material.er = material.er
|
||||||
material.averagable = False
|
disp_material.se = material.se
|
||||||
|
disp_material.mr = material.mr
|
||||||
|
disp_material.sm = material.sm
|
||||||
|
disp_material.type = 'lorentz'
|
||||||
|
disp_material.poles = poles
|
||||||
|
disp_material.averagable = False
|
||||||
for i in range(0, poles):
|
for i in range(0, poles):
|
||||||
if er_delta[i] > 0 and tau[i] > grid.dt and alpha[i] > grid.dt:
|
if er_delta[i] > 0 and tau[i] > grid.dt and alpha[i] > grid.dt:
|
||||||
material.deltaer.append(er_delta[i])
|
disp_material.deltaer.append(er_delta[i])
|
||||||
material.tau.append(tau[i])
|
disp_material.tau.append(tau[i])
|
||||||
material.alpha.append(alpha[i])
|
disp_material.alpha.append(alpha[i])
|
||||||
else:
|
else:
|
||||||
raise CmdInputError(f"'{self.params_str()}' requires positive values for the permittivity difference and frequencies, and associated times that are greater than the time step for the model.")
|
raise CmdInputError(f"'{self.params_str()}' requires positive values for the permittivity difference and frequencies, and associated times that are greater than the time step for the model.")
|
||||||
if material.poles > MaterialUser.maxpoles:
|
if disp_material.poles > config.get_model_config().materials['maxpoles']:
|
||||||
MaterialUser.maxpoles = material.poles
|
config.get_model_config().materials['maxpoles'] = disp_material.poles
|
||||||
|
|
||||||
log.info(f"Lorentz disperion added to {material.ID} with delta_eps_r={', '.join('%4.2f' % deltaer for deltaer in material.deltaer)}, omega={', '.join('%4.3e' % tau for tau in material.tau)} secs, and gamma={', '.join('%4.3e' % alpha for alpha in material.alpha)} created.")
|
# Replace original material with newly created DispersiveMaterial
|
||||||
|
grid.materials = [disp_material if mat.numID==material.numID else mat for mat in grid.materials]
|
||||||
|
|
||||||
|
log.info(f"Lorentz disperion added to {disp_material.ID} with delta_eps_r={', '.join('%4.2f' % deltaer for deltaer in disp_material.deltaer)}, omega={', '.join('%4.3e' % tau for tau in disp_material.tau)} secs, and gamma={', '.join('%4.3e' % alpha for alpha in disp_material.alpha)} created.")
|
||||||
|
|
||||||
|
|
||||||
class AddDrudeDispersion(UserObjectMulti):
|
class AddDrudeDispersion(UserObjectMulti):
|
||||||
@@ -863,12 +871,12 @@ class AddDrudeDispersion(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 11
|
self.order = 12
|
||||||
self.hash = '#add_dispersion_Drude'
|
self.hash = '#add_dispersion_drude'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
try:
|
try:
|
||||||
poles = self.kwargs['n_poles']
|
poles = self.kwargs['poles']
|
||||||
tau = self.kwargs['tau']
|
tau = self.kwargs['tau']
|
||||||
alpha = self.kwargs['alpha']
|
alpha = self.kwargs['alpha']
|
||||||
material_ids = self.kwargs['material_ids']
|
material_ids = self.kwargs['material_ids']
|
||||||
@@ -886,19 +894,27 @@ class AddDrudeDispersion(UserObjectMulti):
|
|||||||
raise CmdInputError(f"'{self.params_str()}' material(s) {notfound} do not exist")
|
raise CmdInputError(f"'{self.params_str()}' material(s) {notfound} do not exist")
|
||||||
|
|
||||||
for material in materials:
|
for material in materials:
|
||||||
material.type = 'drude'
|
disp_material = DispersiveMaterialUser(material.numID, material.ID)
|
||||||
material.poles = poles
|
disp_material.er = material.er
|
||||||
material.averagable = False
|
disp_material.se = material.se
|
||||||
|
disp_material.mr = material.mr
|
||||||
|
disp_material.sm = material.sm
|
||||||
|
disp_material.type = 'drude'
|
||||||
|
disp_material.poles = poles
|
||||||
|
disp_material.averagable = False
|
||||||
for i in range(0, poles):
|
for i in range(0, poles):
|
||||||
if tau[i] > 0 and alpha[i] > grid.dt:
|
if tau[i] > 0 and alpha[i] > grid.dt:
|
||||||
material.tau.append(tau[i])
|
disp_material.tau.append(tau[i])
|
||||||
material.alpha.append(alpha[i])
|
disp_material.alpha.append(alpha[i])
|
||||||
else:
|
else:
|
||||||
raise CmdInputError(f"'{self.params_str()}' requires positive values for the frequencies, and associated times that are greater than the time step for the model.")
|
raise CmdInputError(f"'{self.params_str()}' requires positive values for the frequencies, and associated times that are greater than the time step for the model.")
|
||||||
if material.poles > MaterialUser.maxpoles:
|
if disp_material.poles > config.get_model_config().materials['maxpoles']:
|
||||||
MaterialUser.maxpoles = material.poles
|
config.get_model_config().materials['maxpoles'] = disp_material.poles
|
||||||
|
|
||||||
log.info(f"Drude disperion added to {material.ID} with omega={', '.join('%4.3e' % tau for tau in material.tau)} secs, and gamma={', '.join('%4.3e' % alpha for alpha in material.alpha)} secs created.")
|
# Replace original material with newly created DispersiveMaterial
|
||||||
|
grid.materials = [disp_material if mat.numID==material.numID else mat for mat in grid.materials]
|
||||||
|
|
||||||
|
log.info(f"Drude disperion added to {disp_material.ID} with omega={', '.join('%4.3e' % tau for tau in disp_material.tau)} secs, and gamma={', '.join('%4.3e' % alpha for alpha in disp_material.alpha)} secs created.")
|
||||||
|
|
||||||
|
|
||||||
class SoilPeplinski(UserObjectMulti):
|
class SoilPeplinski(UserObjectMulti):
|
||||||
@@ -920,7 +936,7 @@ class SoilPeplinski(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 12
|
self.order = 13
|
||||||
self.hash = '#soil_peplinski'
|
self.hash = '#soil_peplinski'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -977,7 +993,7 @@ class GeometryView(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 18
|
self.order = 14
|
||||||
self.hash = '#geometry_view'
|
self.hash = '#geometry_view'
|
||||||
self.multi_grid = False
|
self.multi_grid = False
|
||||||
|
|
||||||
@@ -1056,7 +1072,7 @@ class GeometryObjectsWrite(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 14
|
self.order = 15
|
||||||
self.hash = '#geometry_objects_write'
|
self.hash = '#geometry_objects_write'
|
||||||
|
|
||||||
def create(self, grid, uip):
|
def create(self, grid, uip):
|
||||||
@@ -1112,7 +1128,7 @@ class PMLCFS(UserObjectMulti):
|
|||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.order = 15
|
self.order = 16
|
||||||
self.hash = '#pml_cfs'
|
self.hash = '#pml_cfs'
|
||||||
PMLCFS.count += 1
|
PMLCFS.count += 1
|
||||||
if PMLCFS.count == 2:
|
if PMLCFS.count == 2:
|
||||||
|
@@ -288,6 +288,7 @@ class CUDAGrid(FDTDGrid):
|
|||||||
"""Additional grid methods for solving on GPU using CUDA."""
|
"""Additional grid methods for solving on GPU using CUDA."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
# Threads per block - used for main electric/magnetic field updates
|
# Threads per block - used for main electric/magnetic field updates
|
||||||
self.tpb = (128, 1, 1)
|
self.tpb = (128, 1, 1)
|
||||||
|
@@ -140,8 +140,9 @@ def process_include_files(hashcmds, inputfile):
|
|||||||
includefile = includefile[1]
|
includefile = includefile[1]
|
||||||
|
|
||||||
# See if file exists at specified path and if not try input file directory
|
# See if file exists at specified path and if not try input file directory
|
||||||
if not os.path.isfile(includefile):
|
includefile = Path(includefile)
|
||||||
includefile = os.path.join(os.path.dirname(inputfile.name), includefile)
|
if not includefile.exists():
|
||||||
|
includefile = Path(config.sim_config.input_file_path.parent, includefile)
|
||||||
|
|
||||||
with open(includefile, 'r') as f:
|
with open(includefile, 'r') as f:
|
||||||
# Strip out any newline characters and comments that must begin with double hashes
|
# Strip out any newline characters and comments that must begin with double hashes
|
||||||
|
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from .cmds_geometry.geometry_objects_read import GeometryObjectsRead
|
|
||||||
from .cmds_geometry.edge import Edge
|
from .cmds_geometry.edge import Edge
|
||||||
from .cmds_geometry.plate import Plate
|
from .cmds_geometry.plate import Plate
|
||||||
from .cmds_geometry.triangle import Triangle
|
from .cmds_geometry.triangle import Triangle
|
||||||
@@ -52,6 +51,8 @@ def process_geometrycmds(geometry):
|
|||||||
tmp = object.split()
|
tmp = object.split()
|
||||||
|
|
||||||
if tmp[0] == '#geometry_objects_read:':
|
if tmp[0] == '#geometry_objects_read:':
|
||||||
|
from .cmds_geometry.geometry_objects_read import GeometryObjectsRead
|
||||||
|
|
||||||
if len(tmp) != 6:
|
if len(tmp) != 6:
|
||||||
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires exactly five parameters')
|
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires exactly five parameters')
|
||||||
|
|
||||||
|
@@ -193,7 +193,7 @@ def process_multicmds(multicmds):
|
|||||||
er_delta.append(float(tmp[pole]))
|
er_delta.append(float(tmp[pole]))
|
||||||
tau.append(float(tmp[pole + 1]))
|
tau.append(float(tmp[pole + 1]))
|
||||||
|
|
||||||
debye_dispersion = AddDebyeDispersion(pole=poles, er_delta=er_delta, tau=tau, material_ids=material_ids)
|
debye_dispersion = AddDebyeDispersion(poles=poles, er_delta=er_delta, tau=tau, material_ids=material_ids)
|
||||||
scene_objects.append(debye_dispersion)
|
scene_objects.append(debye_dispersion)
|
||||||
|
|
||||||
cmdname = '#add_dispersion_lorentz'
|
cmdname = '#add_dispersion_lorentz'
|
||||||
|
@@ -199,7 +199,7 @@ def htod_snapshot_array(G):
|
|||||||
# 4D arrays to store snapshots on GPU, e.g. snapEx(time, x, y, z);
|
# 4D arrays to store snapshots on GPU, e.g. snapEx(time, x, y, z);
|
||||||
# if snapshots are not being stored on the GPU during the simulation then
|
# if snapshots are not being stored on the GPU during the simulation then
|
||||||
# they are copied back to the host after each iteration, hence numsnaps = 1
|
# they are copied back to the host after each iteration, hence numsnaps = 1
|
||||||
numsnaps = 1 if config.model_configs[G.model_num].cuda['snapsgpu2cpu'] else len(G.snapshots)
|
numsnaps = 1 if config.get_model_config().cuda['snapsgpu2cpu'] else len(G.snapshots)
|
||||||
snapEx = np.zeros((numsnaps, Snapshot.nx_max, Snapshot.ny_max, Snapshot.nz_max),
|
snapEx = np.zeros((numsnaps, Snapshot.nx_max, Snapshot.ny_max, Snapshot.nz_max),
|
||||||
dtype=config.sim_config.dtypes['float_or_double'])
|
dtype=config.sim_config.dtypes['float_or_double'])
|
||||||
snapEy = np.zeros((numsnaps, Snapshot.nx_max, Snapshot.ny_max, Snapshot.nz_max),
|
snapEy = np.zeros((numsnaps, Snapshot.nx_max, Snapshot.ny_max, Snapshot.nz_max),
|
||||||
|
@@ -421,8 +421,7 @@ class CUDAUpdates:
|
|||||||
"""Snapshots - initialise arrays on GPU, prepare kernel and get kernel
|
"""Snapshots - initialise arrays on GPU, prepare kernel and get kernel
|
||||||
function.
|
function.
|
||||||
"""
|
"""
|
||||||
self.snapEx_gpu, self.snapEy_gpu, self.snapEz_gpu,
|
self.snapEx_gpu, self.snapEy_gpu, self.snapEz_gpu, self.snapHx_gpu, self.snapHy_gpu, self.snapHz_gpu = htod_snapshot_array(self.grid)
|
||||||
self.snapHx_gpu, self.snapHy_gpu, self.snapHz_gpu = htod_snapshot_array(self.grid)
|
|
||||||
kernel_store_snapshot = self.source_module(kernel_template_store_snapshot.substitute(
|
kernel_store_snapshot = self.source_module(kernel_template_store_snapshot.substitute(
|
||||||
REAL=config.sim_config.dtypes['C_float_or_double'],
|
REAL=config.sim_config.dtypes['C_float_or_double'],
|
||||||
NX_SNAPS=Snapshot.nx_max,
|
NX_SNAPS=Snapshot.nx_max,
|
||||||
@@ -504,12 +503,12 @@ class CUDAUpdates:
|
|||||||
block=Snapshot.tpb,
|
block=Snapshot.tpb,
|
||||||
grid=Snapshot.bpg)
|
grid=Snapshot.bpg)
|
||||||
if config.get_model_config().cuda['snapsgpu2cpu']:
|
if config.get_model_config().cuda['snapsgpu2cpu']:
|
||||||
dtoh_snapshot_array(self.grid.snapEx_gpu.get(),
|
dtoh_snapshot_array(self.snapEx_gpu.get(),
|
||||||
self.grid.snapEy_gpu.get(),
|
self.snapEy_gpu.get(),
|
||||||
self.grid.snapEz_gpu.get(),
|
self.snapEz_gpu.get(),
|
||||||
self.grid.snapHx_gpu.get(),
|
self.snapHx_gpu.get(),
|
||||||
self.grid.snapHy_gpu.get(),
|
self.snapHy_gpu.get(),
|
||||||
self.grid.snapHz_gpu.get(),
|
self.snapHz_gpu.get(),
|
||||||
0, snap)
|
0, snap)
|
||||||
|
|
||||||
def update_magnetic(self):
|
def update_magnetic(self):
|
||||||
|
在新工单中引用
屏蔽一个用户