Initial work on user spec outputs for snapshots

这个提交包含在:
craig-warren
2022-11-11 17:08:28 +00:00
父节点 11a63828fb
当前提交 1720ea7cc4
共有 2 个文件被更改,包括 34 次插入9 次删除

查看文件

@@ -955,6 +955,8 @@ class Snapshot(UserObjectMulti):
snapshot will be taken.
fileext: optional string to indicate type for snapshot file, either
'.vti' (default) or '.h5'
outputs: optional list of outputs for receiver. It can be any
selection from Ex, Ey, Ez, Hx, Hy, or Hz.
"""
def __init__(self, **kwargs):
@@ -1017,6 +1019,22 @@ class Snapshot(UserObjectMulti):
except KeyError:
fileext = SnapshotUser.fileexts[0]
try:
outputs = self.kwargs['outputs']
except KeyError:
# If outputs are not specified, use default
outputs = SnapshotUser.allowableoutputs
outputs.sort()
# Check and add field output names
for output in outputs:
if output not in SnapshotUser.allowableoutputs:
logger.exception(self.params_str() + ' contains an '
'output type that is not allowable. '
'Allowable outputs in current context are '
f'{SnapshotUser.allowableoutputs}.')
raise ValueError
if dx < 0 or dy < 0 or dz < 0:
logger.exception(self.params_str() + ' the step size should not '
'be less than zero.')
@@ -1030,13 +1048,14 @@ class Snapshot(UserObjectMulti):
raise ValueError
s = SnapshotUser(xs, ys, zs, xf, yf, zf, dx, dy, dz, iterations,
filename, fileext=fileext)
filename, fileext=fileext, outputs=outputs)
logger.info(f'Snapshot from {p3[0]:g}m, {p3[1]:g}m, {p3[2]:g}m, to '
f'{p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m, discretisation '
f'{dx * grid.dx:g}m, {dy * grid.dy:g}m, {dz * grid.dz:g}m, '
f'at {s.time * grid.dt:g} secs with filename '
f'{s.filename}{s.fileext} will be created.')
logger.info(f"Snapshot from {p3[0]:g}m, {p3[1]:g}m, {p3[2]:g}m, to "
f"{p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m, discretisation "
f"{dx * grid.dx:g}m, {dy * grid.dy:g}m, {dz * grid.dz:g}m, "
f"at {s.time * grid.dt:g} secs with field outputs "
f"{', '.join(outputs)} and filename {s.filename}{s.fileext} "
f"will be created.")
grid.snapshots.append(s)
@@ -1660,9 +1679,9 @@ class PMLCFS(UserObjectMulti):
f'scaling direction: {cfssigma.scalingdirection}, min: '
f'{cfssigma.min:g}, max: {cfssigma.max:g}) created.')
grid.cfs.append(cfs)
grid.pmls['cfs'].append(cfs)
if len(grid.cfs) > 2:
if len(grid.pmls['cfs']) > 2:
logger.exception(self.params_str() + ' can only be used up to two '
'times, for up to a 2nd order PML.')
raise ValueError

查看文件

@@ -31,6 +31,8 @@ from .utilities.utilities import round_value
class Snapshot:
"""Snapshots of the electric and magnetic field values."""
allowableoutputs = ['Ex', 'Ey', 'Ez', 'Hx', 'Hy', 'Hz']
# Snapshots can be output as VTK ImageData (.vti) format or
# HDF5 format (.h5) files
fileexts = ['.vti', '.h5']
@@ -46,7 +48,8 @@ class Snapshot:
bpg = None
def __init__(self, xs=None, ys=None, zs=None, xf=None, yf=None, zf=None,
dx=None, dy=None, dz=None, time=None, filename=None, fileext=None):
dx=None, dy=None, dz=None, time=None, filename=None,
fileext=None, outputs=None):
"""
Args:
xs, xf, ys, yf, zs, zf: ints for the extent of the volume in cells.
@@ -54,6 +57,8 @@ class Snapshot:
time: int for the iteration number to take the snapshot on.
filename: string for the filename to save to.
fileext: string for the file extension.
outputs: optional list of outputs for receiver. It can be any
selection from Ex, Ey, Ez, Hx, Hy, or Hz.
"""
self.fileext = fileext
@@ -151,6 +156,7 @@ class Snapshot:
G: FDTDGrid class describing a grid in a model.
"""
hfield_offset = (3 * np.dtype(config.sim_config.dtypes['float_or_double']).itemsize
* self.ncells + np.dtype(np.uint32).itemsize)