你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-06 12:36:51 +08:00
Updates to progress bars.
这个提交包含在:
@@ -62,7 +62,22 @@ class GeometryView(object):
|
||||
filename = self.filename[:-4]
|
||||
write_output_file(filename, G, self.type)
|
||||
|
||||
def write_vtk(self, modelrun, numbermodelruns, G):
|
||||
def set_filename(self, modelrun, numbermodelruns, G):
|
||||
"""Construct filename from user-supplied name and model run number.
|
||||
|
||||
Args:
|
||||
modelrun (int): Current model run number.
|
||||
numbermodelruns (int): Total number of model runs.
|
||||
G (class): Grid class instance - holds essential parameters describing the model.
|
||||
"""
|
||||
|
||||
if numbermodelruns == 1:
|
||||
self.filename = os.path.abspath(os.path.join(G.inputdirectory, self.basefilename))
|
||||
else:
|
||||
self.filename = os.path.abspath(os.path.join(G.inputdirectory, self.basefilename + str(modelrun)))
|
||||
self.filename += self.type
|
||||
|
||||
def write_vtk(self, modelrun, numbermodelruns, G, pbar):
|
||||
"""Writes the geometry information to a VTK file. Either ImageData (.vti) for a per-cell geometry view, or PolygonalData (.vtp) for a per-cell-edge geometry view.
|
||||
|
||||
N.B. No Python 3 support for VTK at time of writing (03/2015)
|
||||
@@ -71,17 +86,10 @@ class GeometryView(object):
|
||||
modelrun (int): Current model run number.
|
||||
numbermodelruns (int): Total number of model runs.
|
||||
G (class): Grid class instance - holds essential parameters describing the model.
|
||||
pbar (class): Progress bar class instance.
|
||||
"""
|
||||
|
||||
# Construct filename from user-supplied name and model run number
|
||||
if numbermodelruns == 1:
|
||||
self.filename = os.path.abspath(os.path.join(G.inputdirectory, self.basefilename))
|
||||
else:
|
||||
self.filename = os.path.abspath(os.path.join(G.inputdirectory, self.basefilename + str(modelrun)))
|
||||
|
||||
if self.type == 'n':
|
||||
self.filename += '.vti'
|
||||
|
||||
if self.type == '.vti':
|
||||
# Calculate number of cells according to requested sampling for geometry view
|
||||
self.vtk_xscells = round_value(self.xs / self.dx)
|
||||
self.vtk_xfcells = round_value(self.xf / self.dx)
|
||||
@@ -125,6 +133,7 @@ class GeometryView(object):
|
||||
for k in range(self.zs, self.zf, self.dz):
|
||||
for j in range(self.ys, self.yf, self.dy):
|
||||
for i in range(self.xs, self.xf, self.dx):
|
||||
pbar.update(n=4)
|
||||
f.write(pack('I', G.solid[i, j, k]))
|
||||
|
||||
# Write source/PML IDs
|
||||
@@ -133,6 +142,7 @@ class GeometryView(object):
|
||||
for k in range(self.zs, self.zf, self.dz):
|
||||
for j in range(self.ys, self.yf, self.dy):
|
||||
for i in range(self.xs, self.xf, self.dx):
|
||||
pbar.update()
|
||||
f.write(pack('b', self.srcs_pml[i, j, k]))
|
||||
|
||||
# Write receiver IDs
|
||||
@@ -141,15 +151,14 @@ class GeometryView(object):
|
||||
for k in range(self.zs, self.zf, self.dz):
|
||||
for j in range(self.ys, self.yf, self.dy):
|
||||
for i in range(self.xs, self.xf, self.dx):
|
||||
pbar.update()
|
||||
f.write(pack('b', self.rxs[i, j, k]))
|
||||
|
||||
f.write('\n</AppendedData>\n</VTKFile>'.encode('utf-8'))
|
||||
|
||||
self.write_gprmax_info(f, G)
|
||||
|
||||
elif self.type == 'f':
|
||||
self.filename += '.vtp'
|
||||
|
||||
elif self.type == '.vtp':
|
||||
vtk_numpoints = (self.nx + 1) * (self.ny + 1) * (self.nz + 1)
|
||||
vtk_numpoint_components = 3
|
||||
vtk_numlines = 2 * self.nx * self.ny + 2 * self.ny * self.nz + 2 * self.nx * self.nz + 3 * self.nx * self.ny * self.nz + self.nx + self.ny + self.nz
|
||||
|
@@ -412,8 +412,12 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
||||
raise GeneralError('No geometry views found.')
|
||||
elif G.geometryviews:
|
||||
print()
|
||||
for geometryview in tqdm(G.geometryviews, desc='Writing geometry file(s)', unit='files', ncols=get_terminal_size()[0] - 1):
|
||||
geometryview.write_vtk(modelrun, numbermodelruns, G)
|
||||
for i, geometryview in enumerate(G.geometryviews):
|
||||
geometryview.set_filename(modelrun, numbermodelruns, G)
|
||||
geoiters = 6 * (((geometryview.xf - geometryview.xs) / geometryview.dx) * ((geometryview.yf - geometryview.ys) / geometryview.dy) * ((geometryview.zf - geometryview.zs) / geometryview.dz))
|
||||
pbar = tqdm(total=geoiters, unit='byte', unit_scale=True, desc='Writing geometry file {} of {}, {}'.format(i + 1, len(G.geometryviews), os.path.split(geometryview.filename)[1]), ncols=get_terminal_size()[0] - 1)
|
||||
geometryview.write_vtk(modelrun, numbermodelruns, G, pbar)
|
||||
pbar.close()
|
||||
# geometryview.write_xdmf(modelrun, numbermodelruns, G)
|
||||
|
||||
# Run simulation (if not doing geometry only)
|
||||
@@ -439,14 +443,17 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace):
|
||||
# Absolute time
|
||||
abstime = 0
|
||||
|
||||
for timestep in tqdm(range(G.iterations), desc='Calculating model ' + str(modelrun) + ' of ' + str(numbermodelruns), ncols=get_terminal_size()[0] - 1):
|
||||
for timestep in tqdm(range(G.iterations), desc='Running simulation, model ' + str(modelrun) + ' of ' + str(numbermodelruns), ncols=get_terminal_size()[0] - 1):
|
||||
# Store field component values for every receiver and transmission line
|
||||
store_outputs(timestep, G.Ex, G.Ey, G.Ez, G.Hx, G.Hy, G.Hz, G)
|
||||
|
||||
# Write any snapshots to file
|
||||
for snapshot in G.snapshots:
|
||||
if snapshot.time == timestep + 1:
|
||||
snapshot.write_vtk_imagedata(G.Ex, G.Ey, G.Ez, G.Hx, G.Hy, G.Hz, G)
|
||||
for i, snap in enumerate(G.snapshots):
|
||||
if snap.time == timestep + 1:
|
||||
snapiters = 36 * (((snap.xf - snap.xs) / snap.dx) * ((snap.yf - snap.ys) / snap.dy) * ((snap.zf - snap.zs) / snap.dz))
|
||||
pbar = tqdm(total=snapiters, leave=False, unit='byte', unit_scale=True, desc=' Writing snapshot file {} of {}, {}'.format(i + 1, len(G.snapshots), os.path.split(snap.filename)[1]), ncols=get_terminal_size()[0] - 1)
|
||||
snap.write_vtk_imagedata(G.Ex, G.Ey, G.Ez, G.Hx, G.Hy, G.Hz, G, pbar)
|
||||
pbar.close()
|
||||
|
||||
# Update electric field components
|
||||
if Material.maxpoles == 0: # All materials are non-dispersive so do standard update
|
||||
|
@@ -679,8 +679,14 @@ def process_multicmds(multicmds, G):
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires type to be either n (normal) or f (fine)')
|
||||
if tmp[10].lower() == 'f' and (dx * G.dx != G.dx or dy * G.dy != G.dy or dz * G.dz != G.dz):
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires the spatial discretisation for the geometry view to be the same as the model for geometry view of type f (fine)')
|
||||
|
||||
# Set type of geometry file
|
||||
if tmp[10].lower() == 'n':
|
||||
type = '.vti'
|
||||
else:
|
||||
type = '.vtp'
|
||||
|
||||
g = GeometryView(xs, ys, zs, xf, yf, zf, dx, dy, dz, tmp[9], tmp[10].lower())
|
||||
g = GeometryView(xs, ys, zs, xf, yf, zf, dx, dy, dz, tmp[9], type)
|
||||
|
||||
if G.messages:
|
||||
print('Geometry view from {:g}m, {:g}m, {:g}m, to {:g}m, {:g}m, {:g}m, discretisation {:g}m, {:g}m, {:g}m, filename {} created.'.format(xs * G.dx, ys * G.dy, zs * G.dz, xf * G.dx, yf * G.dy, zf * G.dz, dx * G.dx, dy * G.dy, dz * G.dz, g.basefilename))
|
||||
|
@@ -110,12 +110,13 @@ class Snapshot(object):
|
||||
self.filehandle.write('<DataArray type="{}" Name="Current" NumberOfComponents="3" format="appended" offset="{}" />\n'.format(Snapshot.floatname, vtk_current_offset).encode('utf-8'))
|
||||
self.filehandle.write('</CellData>\n</Piece>\n</ImageData>\n<AppendedData encoding="raw">\n_'.encode('utf-8'))
|
||||
|
||||
def write_vtk_imagedata(self, Ex, Ey, Ez, Hx, Hy, Hz, G):
|
||||
def write_vtk_imagedata(self, Ex, Ey, Ez, Hx, Hy, Hz, G, pbar):
|
||||
"""Writes electric and magnetic field values to VTK ImageData (.vti) file.
|
||||
|
||||
Args:
|
||||
Ex, Ey, Ez, Hx, Hy, Hz (memory view): Electric and magnetic field values.
|
||||
G (class): Grid class instance - holds essential parameters describing the model.
|
||||
pbar (class): Progress bar class instance.
|
||||
"""
|
||||
|
||||
datasize = 3 * np.dtype(floattype).itemsize * (self.vtk_xfcells - self.vtk_xscells) * (self.vtk_yfcells - self.vtk_yscells) * (self.vtk_zfcells - self.vtk_zscells)
|
||||
@@ -124,6 +125,7 @@ class Snapshot(object):
|
||||
for k in range(self.zs, self.zf, self.dz):
|
||||
for j in range(self.ys, self.yf, self.dy):
|
||||
for i in range(self.xs, self.xf, self.dx):
|
||||
pbar.update(n=12)
|
||||
# The electric field component value at a point comes from average of the 4 electric field component values in that cell
|
||||
self.filehandle.write(pack(Snapshot.floatstring, (Ex[i, j, k] + Ex[i, j + 1, k] + Ex[i, j, k + 1] + Ex[i, j + 1, k + 1]) / 4))
|
||||
self.filehandle.write(pack(Snapshot.floatstring, (Ey[i, j, k] + Ey[i + 1, j, k] + Ey[i, j, k + 1] + Ey[i + 1, j, k + 1]) / 4))
|
||||
@@ -133,6 +135,7 @@ class Snapshot(object):
|
||||
for k in range(self.zs, self.zf, self.dz):
|
||||
for j in range(self.ys, self.yf, self.dy):
|
||||
for i in range(self.xs, self.xf, self.dx):
|
||||
pbar.update(n=12)
|
||||
# The magnetic field component value at a point comes from average of 2 magnetic field component values in that cell and the following cell
|
||||
self.filehandle.write(pack(Snapshot.floatstring, (Hx[i, j, k] + Hx[i + 1, j, k]) / 2))
|
||||
self.filehandle.write(pack(Snapshot.floatstring, (Hy[i, j, k] + Hy[i, j + 1, k]) / 2))
|
||||
@@ -142,6 +145,7 @@ class Snapshot(object):
|
||||
for k in range(self.zs, self.zf, self.dz):
|
||||
for j in range(self.ys, self.yf, self.dy):
|
||||
for i in range(self.xs, self.xf, self.dx):
|
||||
pbar.update(n=12)
|
||||
self.filehandle.write(pack(Snapshot.floatstring, Ix(i, j, k, Hy, Hz, G)))
|
||||
self.filehandle.write(pack(Snapshot.floatstring, Iy(i, j, k, Hx, Hz, G)))
|
||||
self.filehandle.write(pack(Snapshot.floatstring, Iz(i, j, k, Hx, Hy, G)))
|
||||
|
在新工单中引用
屏蔽一个用户