Merge branch 'devel' into mpi

这个提交包含在:
nmannall
2024-02-02 17:16:00 +00:00
当前提交 725669c955
共有 10 个文件被更改,包括 149 次插入161 次删除

查看文件

@@ -21,9 +21,6 @@ import sys
import warnings
from pathlib import Path
# Used to suppress CompilerWarning (sub-class of UserWarning) from pyopencl
warnings.filterwarnings("ignore", category=UserWarning)
import cython
import numpy as np
from colorama import Fore, Style, init
@@ -252,6 +249,9 @@ class SimulationConfig:
self.general["precision"] = "single"
self.devices = {"devs": [], "compiler_opts": None} # pyopencl device device(s); compiler options
# Suppress CompilerWarning (sub-class of UserWarning)
warnings.filterwarnings("ignore", category=UserWarning)
# Suppress unused variable warnings on gcc
# if sys.platform != 'win32': self.devices['compiler_opts'] = ['-w']

查看文件

@@ -42,9 +42,9 @@ update_electric = {
__global $REAL *Ex,
__global $REAL *Ey,
__global $REAL *Ez,
__global const $REAL * restrict Hx,
__global const $REAL * restrict Hy,
__global const $REAL * restrict Hz
__global const $REAL* restrict Hx,
__global const $REAL* restrict Hy,
__global const $REAL* restrict Hz
"""
),
"func": Template(
@@ -118,9 +118,9 @@ update_magnetic = {
__global $REAL *Hx,
__global $REAL *Hy,
__global $REAL *Hz,
__global const $REAL * restrict Ex,
__global const $REAL * restrict Ey,
__global const $REAL * restrict Ez
__global const $REAL* restrict Ex,
__global const $REAL* restrict Ey,
__global const $REAL* restrict Ez
"""
),
"func": Template(
@@ -196,17 +196,17 @@ update_electric_dispersive_A = {
int NY,
int NZ,
int MAXPOLES,
__global const $COMPLEX* restrict updatecoeffsdispersive,
__global $COMPLEX *Tx,
__global $COMPLEX *Ty,
__global $COMPLEX *Tz,
__global const unsigned int* restrict ID,
__global $REAL *Ex,
__global $REAL *Ey,
__global $REAL *Ez,
__global const $REAL* restrict Hx,
__global const $REAL* restrict Hy,
__global const $REAL* restrict Hz
__global const $REAL* restrict Hz,
__global const $COMPLEX* restrict updatecoeffsdispersive,
__global $COMPLEX *Tx,
__global $COMPLEX *Ty,
__global $COMPLEX *Tz
"""
),
"func": Template(
@@ -238,8 +238,7 @@ update_electric_dispersive_A = {
int x_T = (i % ($NX_T * $NY_T * $NZ_T)) / ($NY_T * $NZ_T);
int y_T = ((i % ($NX_T * $NY_T * $NZ_T)) % ($NY_T * $NZ_T)) / $NZ_T;
int z_T = ((i % ($NX_T * $NY_T * $NZ_T)) % ($NY_T * $NZ_T)) % $NZ_T;
// Ex component
if ((NY != 1 || NZ != 1) && x >= 0 && x < NX && y > 0 && y < NY && z > 0 && z < NZ) {
int materialEx = ID[IDX4D_ID(0,x_ID,y_ID,z_ID)];
@@ -311,14 +310,14 @@ update_electric_dispersive_B = {
int NY,
int NZ,
int MAXPOLES,
__global const $COMPLEX* restrict updatecoeffsdispersive,
__global $COMPLEX *Tx,
__global $COMPLEX *Ty,
__global $COMPLEX *Tz,
__global const unsigned int* restrict ID,
__global const $REAL* restrict Ex,
__global const $REAL* restrict Ey,
__global const $REAL* restrict Ez
__global const $REAL* restrict Ez,
__global const $COMPLEX* restrict updatecoeffsdispersive,
__global $COMPLEX *Tx,
__global $COMPLEX *Ty,
__global $COMPLEX *Tz
"""
),
"func": Template(

查看文件

@@ -88,7 +88,7 @@ cpdef void generate_fractal3D(
scaled by weighting.
A: memoryview for access to array containing random numbers
(to be convolved with fractal function).
fractalsurface: memoryview for access to array containing fractal
fractalvolume: memoryview for access to array containing fractal
volume data.
"""

查看文件

@@ -18,6 +18,7 @@
import decimal as d
from collections import OrderedDict
from importlib import import_module
import numpy as np
@@ -309,6 +310,8 @@ class CUDAGrid(FDTDGrid):
def __init__(self):
super().__init__()
self.gpuarray = import_module("pycuda.gpuarray")
# Threads per block - used for main electric/magnetic field updates
self.tpb = (128, 1, 1)
# Blocks per grid - used for main electric/magnetic field updates
@@ -316,87 +319,79 @@ class CUDAGrid(FDTDGrid):
def set_blocks_per_grid(self):
"""Set the blocks per grid size used for updating the electric and
magnetic field arrays on a GPU.
magnetic field arrays on a GPU.
"""
self.bpg = (int(np.ceil(((self.nx + 1) * (self.ny + 1) * (self.nz + 1)) / self.tpb[0])), 1, 1)
def htod_geometry_arrays(self, queue=None):
def htod_geometry_arrays(self):
"""Initialise an array for cell edge IDs (ID) on compute device."""
self.ID_dev = self.gpuarray.to_gpu(self.ID)
def htod_field_arrays(self):
"""Initialise field arrays on compute device."""
self.Ex_dev = self.gpuarray.to_gpu(self.Ex)
self.Ey_dev = self.gpuarray.to_gpu(self.Ey)
self.Ez_dev = self.gpuarray.to_gpu(self.Ez)
self.Hx_dev = self.gpuarray.to_gpu(self.Hx)
self.Hy_dev = self.gpuarray.to_gpu(self.Hy)
self.Hz_dev = self.gpuarray.to_gpu(self.Hz)
def htod_dispersive_arrays(self):
"""Initialise dispersive material coefficient arrays on compute device."""
self.updatecoeffsdispersive_dev = self.gpuarray.to_gpu(self.updatecoeffsdispersive)
self.Tx_dev = self.gpuarray.to_gpu(self.Tx)
self.Ty_dev = self.gpuarray.to_gpu(self.Ty)
self.Tz_dev = self.gpuarray.to_gpu(self.Tz)
class OpenCLGrid(FDTDGrid):
"""Additional grid methods for solving on compute device using OpenCL."""
def __init__(self):
super().__init__()
self.clarray = import_module("pyopencl.array")
def htod_geometry_arrays(self, queue):
"""Initialise an array for cell edge IDs (ID) on compute device.
Args:
queue: pyopencl queue.
"""
if config.sim_config.general["solver"] == "cuda":
import pycuda.gpuarray as gpuarray
self.ID_dev = self.clarray.to_device(queue, self.ID)
self.ID_dev = gpuarray.to_gpu(self.ID)
elif config.sim_config.general["solver"] == "opencl":
import pyopencl.array as clarray
self.ID_dev = clarray.to_device(queue, self.ID)
def htod_field_arrays(self, queue=None):
def htod_field_arrays(self, queue):
"""Initialise field arrays on compute device.
Args:
queue: pyopencl queue.
"""
if config.sim_config.general["solver"] == "cuda":
import pycuda.gpuarray as gpuarray
self.Ex_dev = self.clarray.to_device(queue, self.Ex)
self.Ey_dev = self.clarray.to_device(queue, self.Ey)
self.Ez_dev = self.clarray.to_device(queue, self.Ez)
self.Hx_dev = self.clarray.to_device(queue, self.Hx)
self.Hy_dev = self.clarray.to_device(queue, self.Hy)
self.Hz_dev = self.clarray.to_device(queue, self.Hz)
self.Ex_dev = gpuarray.to_gpu(self.Ex)
self.Ey_dev = gpuarray.to_gpu(self.Ey)
self.Ez_dev = gpuarray.to_gpu(self.Ez)
self.Hx_dev = gpuarray.to_gpu(self.Hx)
self.Hy_dev = gpuarray.to_gpu(self.Hy)
self.Hz_dev = gpuarray.to_gpu(self.Hz)
elif config.sim_config.general["solver"] == "opencl":
import pyopencl.array as clarray
self.Ex_dev = clarray.to_device(queue, self.Ex)
self.Ey_dev = clarray.to_device(queue, self.Ey)
self.Ez_dev = clarray.to_device(queue, self.Ez)
self.Hx_dev = clarray.to_device(queue, self.Hx)
self.Hy_dev = clarray.to_device(queue, self.Hy)
self.Hz_dev = clarray.to_device(queue, self.Hz)
def htod_dispersive_arrays(self, queue=None):
def htod_dispersive_arrays(self, queue):
"""Initialise dispersive material coefficient arrays on compute device.
Args:
queue: pyopencl queue.
"""
if config.sim_config.general["solver"] == "cuda":
import pycuda.gpuarray as gpuarray
self.Tx_dev = gpuarray.to_gpu(self.Tx)
self.Ty_dev = gpuarray.to_gpu(self.Ty)
self.Tz_dev = gpuarray.to_gpu(self.Tz)
self.updatecoeffsdispersive_dev = gpuarray.to_gpu(self.updatecoeffsdispersive)
elif config.sim_config.general["solver"] == "opencl":
import pyopencl.array as clarray
self.Tx_dev = clarray.to_device(queue, self.Tx)
self.Ty_dev = clarray.to_device(queue, self.Ty)
self.Tz_dev = clarray.to_device(queue, self.Tz)
self.updatecoeffsdispersive_dev = clarray.to_device(queue, self.updatecoeffsdispersive)
class OpenCLGrid(CUDAGrid):
"""Additional grid methods for solving on compute device using OpenCL."""
def __init__(self):
super().__init__()
def set_blocks_per_grid(self):
pass
self.updatecoeffsdispersive_dev = self.clarray.to_device(queue, self.updatecoeffsdispersive)
# self.updatecoeffsdispersive_dev = self.clarray.to_device(queue, np.ones((95,95,95), dtype=np.float32))
self.Tx_dev = self.clarray.to_device(queue, self.Tx)
self.Ty_dev = self.clarray.to_device(queue, self.Ty)
self.Tz_dev = self.clarray.to_device(queue, self.Tz)
def dispersion_analysis(G):
"""Analysis of numerical dispersion (Taflove et al, 2005, p112) -

查看文件

@@ -308,7 +308,7 @@ class ModelBuildRun:
elif config.sim_config.general["solver"] in ["cuda", "opencl"]:
if config.sim_config.general["solver"] == "opencl":
solvername = "OpenCL"
platformname = " on " + " ".join(config.get_model_config().device["dev"].platform.name.split())
platformname = " ".join(config.get_model_config().device["dev"].platform.name.split()) + " with "
devicename = (
f'Device {config.get_model_config().device["deviceID"]}: '
f'{" ".join(config.get_model_config().device["dev"].name.split())}'
@@ -324,7 +324,7 @@ class ModelBuildRun:
logger.basic(
f"\nModel {config.model_num + 1}/{config.sim_config.model_end} "
f"solving on {config.sim_config.hostinfo['hostname']} "
f"with {solvername} backend using {devicename}{platformname}"
f"with {solvername} backend using {platformname}{devicename}"
)
# Prepare iterator
@@ -346,12 +346,12 @@ class ModelBuildRun:
self.write_output_data()
# Print information about memory usage and solving time for a model
# Add a string on GPU memory usage if applicable
mem_str = (
f" host + ~{humanize.naturalsize(solver.memused)} GPU"
if config.sim_config.general["solver"] == "cuda"
else ""
)
# Add a string on device (GPU) memory usage if applicable
mem_str = ""
if config.sim_config.general["solver"] == "cuda":
mem_str = f" host + ~{humanize.naturalsize(solver.memused)} device"
elif config.sim_config.general["solver"] == "opencl":
mem_str = f" host + unknown for device"
logger.info(f"\nMemory used (estimated): " + f"~{humanize.naturalsize(self.p.memory_full_info().uss)}{mem_str}")
logger.info(

查看文件

@@ -87,9 +87,9 @@ def dtoh_rx_array(rxs_dev, rxcoords_dev, G):
objects.
Args:
rxcoords_dev: int array of receiver coordinates on compute device.
rxs_dev: float array of receiver data on compute device - rows are field
components; columns are iterations; pages are receivers.
rxcoords_dev: int array of receiver coordinates on compute device.
G: FDTDGrid class describing a grid in a model.
"""

查看文件

@@ -45,9 +45,8 @@ class CPUUpdates:
Args:
G: FDTDGrid class describing a grid in a model.
"""
self.grid = G
self.dispersive_update_a = None
self.dispersive_update_b = None
def store_outputs(self):
"""Stores field component values for every receiver and transmission line."""
@@ -168,7 +167,7 @@ class CPUUpdates:
updated after the electric field has been updated by the PML and
source updates.
"""
if config.get_model_config().materials["maxpoles"] != 0:
if config.get_model_config().materials["maxpoles"] > 0:
self.dispersive_update_b(
self.grid.nx,
self.grid.ny,
@@ -231,8 +230,6 @@ class CUDAUpdates:
"""
self.grid = G
self.dispersive_update_a = None
self.dispersive_update_b = None
# Import PyCUDA modules
self.drv = import_module("pycuda.driver")
@@ -802,12 +799,10 @@ class OpenCLUpdates:
"""
self.grid = G
self.dispersive_update_a = None
self.dispersive_update_b = None
# Import pyopencl module
self.cl = import_module("pyopencl")
self.elwise = getattr(import_module("pyopencl.elementwise"), "ElementwiseKernel")
self.elwiseknl = getattr(import_module("pyopencl.elementwise"), "ElementwiseKernel")
# Select device, create context and command queue
self.dev = config.get_model_config().device["dev"]
@@ -818,6 +813,7 @@ class OpenCLUpdates:
self.env = Environment(loader=PackageLoader("gprMax", "cuda_opencl"))
# Initialise arrays on device, prepare kernels, and get kernel functions
self._set_macros()
self._set_field_knls()
if self.grid.pmls["slabs"]:
self._set_pml_knls()
@@ -828,10 +824,10 @@ class OpenCLUpdates:
if self.grid.snapshots:
self._set_snapshot_knl()
def _set_field_knls(self):
"""Electric and magnetic field updates - prepares kernels, and
gets kernel functions.
"""
def _set_macros(self):
"""Common macros to be used in kernels."""
# Set specific values for any dispersive materials
if config.get_model_config().materials["maxpoles"] > 0:
NY_MATDISPCOEFFS = self.grid.updatecoeffsdispersive.shape[1]
NX_T = self.grid.Tx.shape[1]
@@ -871,6 +867,11 @@ class OpenCLUpdates:
NZ_SNAPS=Snapshot.nz_max,
)
def _set_field_knls(self):
"""Electric and magnetic field updates - prepares kernels, and
gets kernel functions.
"""
subs = {
"CUDA_IDX": "",
"NX_FIELDS": self.grid.nx + 1,
@@ -880,8 +881,8 @@ class OpenCLUpdates:
"NY_ID": self.grid.ID.shape[2],
"NZ_ID": self.grid.ID.shape[3],
}
self.update_electric_dev = self.elwise(
self.update_electric_dev = self.elwiseknl(
self.ctx,
knl_fields_updates.update_electric["args_opencl"].substitute(
{"REAL": config.sim_config.dtypes["C_float_or_double"]}
@@ -892,7 +893,7 @@ class OpenCLUpdates:
options=config.sim_config.devices["compiler_opts"],
)
self.update_magnetic_dev = self.elwise(
self.update_magnetic_dev = self.elwiseknl(
self.ctx,
knl_fields_updates.update_magnetic["args_opencl"].substitute(
{"REAL": config.sim_config.dtypes["C_float_or_double"]}
@@ -916,11 +917,12 @@ class OpenCLUpdates:
"NX_ID": self.grid.ID.shape[1],
"NY_ID": self.grid.ID.shape[2],
"NZ_ID": self.grid.ID.shape[3],
"NX_T": NX_T,
"NY_T": NY_T,
"NZ_T": NZ_T,
"NX_T": self.grid.Tx.shape[1],
"NY_T": self.grid.Tx.shape[2],
"NZ_T": self.grid.Tx.shape[3],
}
self.dispersive_update_a = self.elwise(
self.dispersive_update_a = self.elwiseknl(
self.ctx,
knl_fields_updates.update_electric_dispersive_A["args_opencl"].substitute(
{
@@ -933,7 +935,8 @@ class OpenCLUpdates:
preamble=self.knl_common,
options=config.sim_config.devices["compiler_opts"],
)
self.dispersive_update_b = self.elwise(
self.dispersive_update_b = self.elwiseknl(
self.ctx,
knl_fields_updates.update_electric_dispersive_B["args_opencl"].substitute(
{
@@ -982,7 +985,7 @@ class OpenCLUpdates:
knl_electric_name = getattr(knl_pml_updates_electric, knl_name)
knl_magnetic_name = getattr(knl_pml_updates_magnetic, knl_name)
pml.update_electric_dev = self.elwise(
pml.update_electric_dev = self.elwiseknl(
self.ctx,
knl_electric_name["args_opencl"].substitute({"REAL": config.sim_config.dtypes["C_float_or_double"]}),
knl_electric_name["func"].substitute(subs),
@@ -991,7 +994,7 @@ class OpenCLUpdates:
options=config.sim_config.devices["compiler_opts"],
)
pml.update_magnetic_dev = self.elwise(
pml.update_magnetic_dev = self.elwiseknl(
self.ctx,
knl_magnetic_name["args_opencl"].substitute({"REAL": config.sim_config.dtypes["C_float_or_double"]}),
knl_magnetic_name["func"].substitute(subs),
@@ -1005,7 +1008,7 @@ class OpenCLUpdates:
gets kernel function.
"""
self.rxcoords_dev, self.rxs_dev = htod_rx_arrays(self.grid, self.queue)
self.store_outputs_dev = self.elwise(
self.store_outputs_dev = self.elwiseknl(
self.ctx,
knl_store_outputs.store_outputs["args_opencl"].substitute(
{"REAL": config.sim_config.dtypes["C_float_or_double"]}
@@ -1024,7 +1027,7 @@ class OpenCLUpdates:
self.srcinfo1_hertzian_dev, self.srcinfo2_hertzian_dev, self.srcwaves_hertzian_dev = htod_src_arrays(
self.grid.hertziandipoles, self.grid, self.queue
)
self.update_hertzian_dipole_dev = self.elwise(
self.update_hertzian_dipole_dev = self.elwiseknl(
self.ctx,
knl_source_updates.update_hertzian_dipole["args_opencl"].substitute(
{"REAL": config.sim_config.dtypes["C_float_or_double"]}
@@ -1040,7 +1043,7 @@ class OpenCLUpdates:
self.srcinfo1_magnetic_dev, self.srcinfo2_magnetic_dev, self.srcwaves_magnetic_dev = htod_src_arrays(
self.grid.magneticdipoles, self.grid, self.queue
)
self.update_magnetic_dipole_dev = self.elwise(
self.update_magnetic_dipole_dev = self.elwiseknl(
self.ctx,
knl_source_updates.update_magnetic_dipole["args_opencl"].substitute(
{"REAL": config.sim_config.dtypes["C_float_or_double"]}
@@ -1056,7 +1059,7 @@ class OpenCLUpdates:
self.srcinfo1_voltage_dev, self.srcinfo2_voltage_dev, self.srcwaves_voltage_dev = htod_src_arrays(
self.grid.voltagesources, self.grid, self.queue
)
self.update_voltage_source_dev = self.elwise(
self.update_voltage_source_dev = self.elwiseknl(
self.ctx,
knl_source_updates.update_voltage_source["args_opencl"].substitute(
{"REAL": config.sim_config.dtypes["C_float_or_double"]}
@@ -1081,7 +1084,7 @@ class OpenCLUpdates:
self.snapHy_dev,
self.snapHz_dev,
) = htod_snapshot_array(self.grid, self.queue)
self.store_snapshot_dev = self.elwise(
self.store_snapshot_dev = self.elwiseknl(
self.ctx,
knl_snapshots.store_snapshot["args_opencl"].substitute(
{"REAL": config.sim_config.dtypes["C_float_or_double"]}
@@ -1097,7 +1100,7 @@ class OpenCLUpdates:
def store_outputs(self):
"""Stores field component values for every receiver."""
if self.grid.rxs:
event = self.store_outputs_dev(
self.store_outputs_dev(
np.int32(len(self.grid.rxs)),
np.int32(self.grid.iteration),
self.rxcoords_dev,
@@ -1109,7 +1112,6 @@ class OpenCLUpdates:
self.grid.Hy_dev,
self.grid.Hz_dev,
)
event.wait()
def store_snapshots(self, iteration):
"""Stores any snapshots.
@@ -1121,7 +1123,7 @@ class OpenCLUpdates:
for i, snap in enumerate(self.grid.snapshots):
if snap.time == iteration + 1:
snapno = 0 if config.get_model_config().device["snapsgpu2cpu"] else i
event = self.store_snapshot_dev(
self.store_snapshot_dev(
np.int32(snapno),
np.int32(snap.xs),
np.int32(snap.xf),
@@ -1145,7 +1147,7 @@ class OpenCLUpdates:
self.snapHy_dev,
self.snapHz_dev,
)
event.wait()
if config.get_model_config().device["snapsgpu2cpu"]:
dtoh_snapshot_array(
self.snapEx_dev.get(),
@@ -1160,7 +1162,7 @@ class OpenCLUpdates:
def update_magnetic(self):
"""Updates magnetic field components."""
event = self.update_magnetic_dev(
self.update_magnetic_dev(
np.int32(self.grid.nx),
np.int32(self.grid.ny),
np.int32(self.grid.nz),
@@ -1172,7 +1174,6 @@ class OpenCLUpdates:
self.grid.Ey_dev,
self.grid.Ez_dev,
)
event.wait()
def update_magnetic_pml(self):
"""Updates magnetic field components with the PML correction."""
@@ -1182,7 +1183,7 @@ class OpenCLUpdates:
def update_magnetic_sources(self):
"""Updates magnetic field components from sources."""
if self.grid.magneticdipoles:
event = self.update_magnetic_dipole_dev(
self.update_magnetic_dipole_dev(
np.int32(len(self.grid.magneticdipoles)),
np.int32(self.grid.iteration),
config.sim_config.dtypes["float_or_double"](self.grid.dx),
@@ -1196,13 +1197,12 @@ class OpenCLUpdates:
self.grid.Hy_dev,
self.grid.Hz_dev,
)
event.wait()
def update_electric_a(self):
"""Updates electric field components."""
# All materials are non-dispersive so do standard update.
if config.get_model_config().materials["maxpoles"] == 0:
event = self.update_electric_dev(
self.update_electric_dev(
np.int32(self.grid.nx),
np.int32(self.grid.ny),
np.int32(self.grid.nz),
@@ -1218,15 +1218,11 @@ class OpenCLUpdates:
# If there are any dispersive materials do 1st part of dispersive update
# (it is split into two parts as it requires present and updated electric field values).
else:
event = self.dispersive_update_a(
self.dispersive_update_a(
np.int32(self.grid.nx),
np.int32(self.grid.ny),
np.int32(self.grid.nz),
np.int32(config.get_model_config().materials["maxpoles"]),
self.grid.updatecoeffsdispersive_dev,
self.grid.Tx_dev,
self.grid.Ty_dev,
self.grid.Tz_dev,
self.grid.ID_dev,
self.grid.Ex_dev,
self.grid.Ey_dev,
@@ -1234,10 +1230,12 @@ class OpenCLUpdates:
self.grid.Hx_dev,
self.grid.Hy_dev,
self.grid.Hz_dev,
self.grid.updatecoeffsdispersive_dev,
self.grid.Tx_dev,
self.grid.Ty_dev,
self.grid.Tz_dev,
)
event.wait()
def update_electric_pml(self):
"""Updates electric field components with the PML correction."""
for pml in self.grid.pmls["slabs"]:
@@ -1248,7 +1246,7 @@ class OpenCLUpdates:
update any Hertzian dipole sources last.
"""
if self.grid.voltagesources:
event = self.update_voltage_source_dev(
self.update_voltage_source_dev(
np.int32(len(self.grid.voltagesources)),
np.int32(self.grid.iteration),
config.sim_config.dtypes["float_or_double"](self.grid.dx),
@@ -1262,10 +1260,9 @@ class OpenCLUpdates:
self.grid.Ey_dev,
self.grid.Ez_dev,
)
event.wait()
if self.grid.hertziandipoles:
event = self.update_hertzian_dipole_dev(
self.update_hertzian_dipole_dev(
np.int32(len(self.grid.hertziandipoles)),
np.int32(self.grid.iteration),
config.sim_config.dtypes["float_or_double"](self.grid.dx),
@@ -1279,7 +1276,6 @@ class OpenCLUpdates:
self.grid.Ey_dev,
self.grid.Ez_dev,
)
event.wait()
self.grid.iteration += 1
@@ -1291,21 +1287,20 @@ class OpenCLUpdates:
source updates.
"""
if config.get_model_config().materials["maxpoles"] > 0:
event = self.dispersive_update_b(
self.dispersive_update_b(
np.int32(self.grid.nx),
np.int32(self.grid.ny),
np.int32(self.grid.nz),
np.int32(config.get_model_config().materials["maxpoles"]),
self.grid.updatecoeffsdispersive_dev,
self.grid.Tx_dev,
self.grid.Ty_dev,
self.grid.Tz_dev,
self.grid.ID_dev,
self.grid.Ex_dev,
self.grid.Ey_dev,
self.grid.Ez_dev,
self.grid.updatecoeffsdispersive_dev,
self.grid.Tx_dev,
self.grid.Ty_dev,
self.grid.Tz_dev,
)
event.wait()
def time_start(self):
"""Starts event timers used to calculate solving time for model."""
@@ -1313,7 +1308,7 @@ class OpenCLUpdates:
self.event_marker1.wait()
def calculate_memory_used(self, iteration):
"""Calculates memory used on last iteration.
"""Calculates memory used on last iteration.
Args:
iteration: int for iteration number.
@@ -1321,9 +1316,8 @@ class OpenCLUpdates:
Returns:
Memory (RAM) used on compute device.
"""
# if iteration == self.grid.iterations - 1:
# return self.drv.mem_get_info()[1] - self.drv.mem_get_info()[0]
logger.debug("Look at memory estimate for pyopencl")
# No clear way to determine memory used from PyOpenCL unlike PyCUDA.
pass
def calculate_solve_time(self):
"""Calculates solving time for model."""

查看文件

@@ -143,7 +143,7 @@ def mpl_plot(filename, outputs=Rx.defaultoutputs, fft=False, save=False):
# Plot frequency spectra
markerline, stemlines, baseline = ax2.stem(
freqs[pltrange], power[pltrange], "-.", use_line_collection=True
freqs[pltrange], power[pltrange], "-."
)
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "r")

查看文件

@@ -249,7 +249,7 @@ def mpl_plot(
# Plot frequency spectra of incident voltage
ax = plt.subplot(gs1[0, 1])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vincp[pltrange], "-.", use_line_collection=True)
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vincp[pltrange], "-.")
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "r")
plt.setp(markerline, "markerfacecolor", "r", "markeredgecolor", "r")
@@ -270,7 +270,7 @@ def mpl_plot(
# Plot frequency spectra of incident current
ax = plt.subplot(gs1[1, 1])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Iincp[pltrange], "-.", use_line_collection=True)
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Iincp[pltrange], "-.")
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "b")
plt.setp(markerline, "markerfacecolor", "b", "markeredgecolor", "b")
@@ -291,7 +291,7 @@ def mpl_plot(
# Plot frequency spectra of total voltage
ax = plt.subplot(gs1[2, 1])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vtotalp[pltrange], "-.", use_line_collection=True)
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vtotalp[pltrange], "-.")
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "r")
plt.setp(markerline, "markerfacecolor", "r", "markeredgecolor", "r")
@@ -312,7 +312,7 @@ def mpl_plot(
# Plot frequency spectra of total current
ax = plt.subplot(gs1[3, 1])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Itotalp[pltrange], "-.", use_line_collection=True)
markerline, stemlines, baseline = ax.stem(freqs[pltrange], Itotalp[pltrange], "-.")
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "b")
plt.setp(markerline, "markerfacecolor", "b", "markeredgecolor", "b")
@@ -334,7 +334,7 @@ def mpl_plot(
# Plot frequency spectra of reflected voltage
# ax = plt.subplot(gs1[4, 1])
# markerline, stemlines, baseline = ax.stem(freqs[pltrange], Vrefp[pltrange],
# '-.', use_line_collection=True)
# '-.')
# plt.setp(baseline, 'linewidth', 0)
# plt.setp(stemlines, 'color', 'r')
# plt.setp(markerline, 'markerfacecolor', 'r', 'markeredgecolor', 'r')
@@ -356,7 +356,7 @@ def mpl_plot(
# Plot frequency spectra of reflected current
# ax = plt.subplot(gs1[5, 1])
# markerline, stemlines, baseline = ax.stem(freqs[pltrange], Irefp[pltrange],
# '-.', use_line_collection=True)
# '-.')
# plt.setp(baseline, 'linewidth', 0)
# plt.setp(stemlines, 'color', 'b')
# plt.setp(markerline, 'markerfacecolor', 'b', 'markeredgecolor', 'b')
@@ -371,7 +371,7 @@ def mpl_plot(
fig2, ax = plt.subplots(num="Antenna parameters", figsize=(20, 12), facecolor="w", edgecolor="w")
gs2 = gridspec.GridSpec(2, 2, hspace=0.3)
ax = plt.subplot(gs2[0, 0])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], s11[pltrange], "-.", use_line_collection=True)
markerline, stemlines, baseline = ax.stem(freqs[pltrange], s11[pltrange], "-.")
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "g")
plt.setp(markerline, "markerfacecolor", "g", "markeredgecolor", "g")
@@ -386,7 +386,7 @@ def mpl_plot(
# Plot frequency spectra of s21
if s21 is not None:
ax = plt.subplot(gs2[0, 1])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], s21[pltrange], "-.", use_line_collection=True)
markerline, stemlines, baseline = ax.stem(freqs[pltrange], s21[pltrange], "-.")
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "g")
plt.setp(markerline, "markerfacecolor", "g", "markeredgecolor", "g")
@@ -400,7 +400,7 @@ def mpl_plot(
# Plot input resistance (real part of impedance)
ax = plt.subplot(gs2[1, 0])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].real, "-.", use_line_collection=True)
markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].real, "-.")
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "g")
plt.setp(markerline, "markerfacecolor", "g", "markeredgecolor", "g")
@@ -415,7 +415,7 @@ def mpl_plot(
# Plot input reactance (imaginery part of impedance)
ax = plt.subplot(gs2[1, 1])
markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].imag, "-.", use_line_collection=True)
markerline, stemlines, baseline = ax.stem(freqs[pltrange], zin[pltrange].imag, "-.")
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "g")
plt.setp(markerline, "markerfacecolor", "g", "markeredgecolor", "g")
@@ -430,7 +430,7 @@ def mpl_plot(
# Plot input admittance (magnitude)
# ax = plt.subplot(gs2[2, 0])
# markerline, stemlines, baseline = ax.stem(freqs[pltrange], np.abs(yin[pltrange]),
# '-.', use_line_collection=True)
# '-.')
# plt.setp(baseline, 'linewidth', 0)
# plt.setp(stemlines, 'color', 'g')
# plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')
@@ -445,7 +445,7 @@ def mpl_plot(
# Plot input admittance (phase)
# ax = plt.subplot(gs2[2, 1])
# markerline, stemlines, baseline = ax.stem(freqs[pltrange], np.angle(yin[pltrange], deg=True),
# '-.', use_line_collection=True)
# '-.')
# plt.setp(baseline, 'linewidth', 0)
# plt.setp(stemlines, 'color', 'g')
# plt.setp(markerline, 'markerfacecolor', 'g', 'markeredgecolor', 'g')

查看文件

@@ -121,7 +121,7 @@ def mpl_plot(w, timewindow, dt, iterations, fft=False, save=False):
ax1.set_ylabel("Amplitude")
# Plot frequency spectra
markerline, stemlines, baseline = ax2.stem(freqs[pltrange], power[pltrange], "-.", use_line_collection=True)
markerline, stemlines, baseline = ax2.stem(freqs[pltrange], power[pltrange], "-.")
plt.setp(baseline, "linewidth", 0)
plt.setp(stemlines, "color", "r")
plt.setp(markerline, "markerfacecolor", "r", "markeredgecolor", "r")