move print information

这个提交包含在:
John Hartley
2019-07-31 17:28:58 +01:00
父节点 4951d39e62
当前提交 0d8b7e7f9c
共有 2 个文件被更改,包括 82 次插入86 次删除

查看文件

@@ -54,7 +54,8 @@ from .materials import Material
from .materials import process_materials from .materials import process_materials
from .pml import CFS from .pml import CFS
from .pml import PML from .pml import PML
from .pml import build_pmls from .pml import build_pml
from .pml import pml_information
from .receivers import gpu_initialise_rx_arrays from .receivers import gpu_initialise_rx_arrays
from .receivers import gpu_get_rx_array from .receivers import gpu_get_rx_array
from .receivers import Rx from .receivers import Rx
@@ -96,45 +97,29 @@ def run_model(solver, sim_config, model_config):
G = solver.G G = solver.G
# Estimate and check memory (RAM) usage # api for multiple scenes / model runs
G.memory_estimate_basic() try:
G.memory_check() scene = model_config.scene
if sim_config.general['messages']: # process using hashcommands
print(G.memory_message) except AttributeError:
scene = Scene()
# parse the input file into user objects and add them to the scene
scene = parse_hash_commands(args, usernamespace, appendmodelnumber, G, scene)
# Initialise an array for volumetric material IDs (solid), boolean # Creates the internal simulation objects.
# arrays for specifying materials not to be averaged (rigid), scene.create_internal_objects(G)
# an array for cell edge IDs (ID)
G.initialise_geometry_arrays()
# Initialise arrays for the field components # print PML information
G.initialise_field_arrays()
# Build the PMLs and calculate initial coefficients
# print stuff about PML
if config.general['messages']: if config.general['messages']:
# no pml print(pml_information(G))
if all(value == 0 for value in G.pmlthickness.values()):
print('PML: switched off')
if all(value == G.pmlthickness['x0'] for value in G.pmlthickness.values()): # build the PMLS
pmlinfo = str(G.pmlthickness['x0']) pbar = tqdm(total=sum(1 for value in G.pmlthickness.values() if value > 0), desc='Building PML boundaries', ncols=get_terminal_width() - 1, file=sys.stdout, disable=not config.general['progressbars'])
else:
pmlinfo = ''
for key, value in G.pmlthickness.items():
pmlinfo += '{}: {}, '.format(key, value)
pmlinfo = pmlinfo[:-2] + ' cells'
print('PML: formulation: {}, order: {}, thickness: {}'.format(G.pmlformulation, len(G.cfs), pmlinfo))
# build the PMLS for pml_id, thickness in G.pmlthickness.items():
pbar = tqdm(total=sum(1 for value in G.pmlthickness.values() if value > 0), desc='Building PML boundaries', ncols=get_terminal_width() - 1, file=sys.stdout, disable=not config.general['progressbars']) build_pml(G, pml_id, thickness)
pbar.update()
for pml_id, thickness in G.pmlthickness.items(): pbar.close()
build_pml(G, pml_id, thickness)
pbar.update()
pbar.close()
# Build the model, i.e. set the material properties (ID) for every edge # Build the model, i.e. set the material properties (ID) for every edge
# of every Yee cell # of every Yee cell
@@ -225,6 +210,8 @@ def run_model(solver, sim_config, model_config):
elif results['deltavp'] and config.general['messages']: elif results['deltavp'] and config.general['messages']:
print("\nNumerical dispersion analysis: estimated largest physical phase-velocity error is {:.2f}% in material '{}' whose wavelength sampled by {} cells. Maximum significant frequency estimated as {:g}Hz".format(results['deltavp'], results['material'].ID, results['N'], results['maxfreq'])) print("\nNumerical dispersion analysis: estimated largest physical phase-velocity error is {:.2f}% in material '{}' whose wavelength sampled by {} cells. Maximum significant frequency estimated as {:g}Hz".format(results['deltavp'], results['material'].ID, results['N'], results['maxfreq']))
disp_a = update_f.format(model_config.poles, 'A', model_config.precision, model_config.dispersion_type)
# set the dispersive update functions based on the model configuration # set the dispersive update functions based on the model configuration
solver.updates.set_dispersive_updates(model_config) solver.updates.set_dispersive_updates(model_config)

查看文件

@@ -431,8 +431,21 @@ class PML(object):
config.dtypes['float_or_double'](self.d), config.dtypes['float_or_double'](self.d),
block=config.cuda['gpus'].tpb, grid=config.cuda['gpus'].bpg) block=config.cuda['gpus'].tpb, grid=config.cuda['gpus'].bpg)
def pml_information(G):
# no pml
if all(value == 0 for value in G.pmlthickness.values()):
return 'PML: switched off'
def build_pmls(G, pbar): if all(value == G.pmlthickness['x0'] for value in G.pmlthickness.values()):
pmlinfo = str(G.pmlthickness['x0'])
else:
pmlinfo = ''
for key, value in G.pmlthickness.items():
pmlinfo += '{}: {}, '.format(key, value)
pmlinfo = pmlinfo[:-2] + ' cells'
return 'PML: formulation: {}, order: {}, thickness: {}'.format(G.pmlformulation, len(G.cfs), pmlinfo))
def build_pml(G, key, thickness):
"""This function builds instances of the PML and calculates the initial """This function builds instances of the PML and calculates the initial
parameters and coefficients including setting profile parameters and coefficients including setting profile
(based on underlying material er and mr from solid array). (based on underlying material er and mr from solid array).
@@ -440,58 +453,54 @@ def build_pmls(G, pbar):
Args: Args:
G (class): Grid class instance - holds essential parameters G (class): Grid class instance - holds essential parameters
describing the model. describing the model.
pbar (class): Progress bar class instance.
""" """
if value > 0:
sumer = 0 # Sum of relative permittivities in PML slab
summr = 0 # Sum of relative permeabilities in PML slab
for key, value in G.pmlthickness.items(): if key[0] == 'x':
if value > 0: if key == 'x0':
sumer = 0 # Sum of relative permittivities in PML slab pml = PML(G, ID=key, direction='xminus', xf=value, yf=G.ny, zf=G.nz)
summr = 0 # Sum of relative permeabilities in PML slab elif key == 'xmax':
pml = PML(G, ID=key, direction='xplus', xs=G.nx - value, xf=G.nx, yf=G.ny, zf=G.nz)
G.pmls.append(pml)
for j in range(G.ny):
for k in range(G.nz):
numID = G.solid[pml.xs, j, k]
material = next(x for x in G.materials if x.numID == numID)
sumer += material.er
summr += material.mr
averageer = sumer / (G.ny * G.nz)
averagemr = summr / (G.ny * G.nz)
if key[0] == 'x': elif key[0] == 'y':
if key == 'x0': if key == 'y0':
pml = PML(G, ID=key, direction='xminus', xf=value, yf=G.ny, zf=G.nz) pml = PML(G, ID=key, direction='yminus', yf=value, xf=G.nx, zf=G.nz)
elif key == 'xmax': elif key == 'ymax':
pml = PML(G, ID=key, direction='xplus', xs=G.nx - value, xf=G.nx, yf=G.ny, zf=G.nz) pml = PML(G, ID=key, direction='yplus', ys=G.ny - value, xf=G.nx, yf=G.ny, zf=G.nz)
G.pmls.append(pml) G.pmls.append(pml)
for i in range(G.nx):
for k in range(G.nz):
numID = G.solid[i, pml.ys, k]
material = next(x for x in G.materials if x.numID == numID)
sumer += material.er
summr += material.mr
averageer = sumer / (G.nx * G.nz)
averagemr = summr / (G.nx * G.nz)
elif key[0] == 'z':
if key == 'z0':
pml = PML(G, ID=key, direction='zminus', zf=value, xf=G.nx, yf=G.ny)
elif key == 'zmax':
pml = PML(G, ID=key, direction='zplus', zs=G.nz - value, xf=G.nx, yf=G.ny, zf=G.nz)
G.pmls.append(pml)
for i in range(G.nx):
for j in range(G.ny): for j in range(G.ny):
for k in range(G.nz): numID = G.solid[i, j, pml.zs]
numID = G.solid[pml.xs, j, k] material = next(x for x in G.materials if x.numID == numID)
material = next(x for x in G.materials if x.numID == numID) sumer += material.er
sumer += material.er summr += material.mr
summr += material.mr averageer = sumer / (G.nx * G.ny)
averageer = sumer / (G.ny * G.nz) averagemr = summr / (G.nx * G.ny)
averagemr = summr / (G.ny * G.nz)
elif key[0] == 'y': pml.calculate_update_coeffs(averageer, averagemr, G)
if key == 'y0':
pml = PML(G, ID=key, direction='yminus', yf=value, xf=G.nx, zf=G.nz)
elif key == 'ymax':
pml = PML(G, ID=key, direction='yplus', ys=G.ny - value, xf=G.nx, yf=G.ny, zf=G.nz)
G.pmls.append(pml)
for i in range(G.nx):
for k in range(G.nz):
numID = G.solid[i, pml.ys, k]
material = next(x for x in G.materials if x.numID == numID)
sumer += material.er
summr += material.mr
averageer = sumer / (G.nx * G.nz)
averagemr = summr / (G.nx * G.nz)
elif key[0] == 'z':
if key == 'z0':
pml = PML(G, ID=key, direction='zminus', zf=value, xf=G.nx, yf=G.ny)
elif key == 'zmax':
pml = PML(G, ID=key, direction='zplus', zs=G.nz - value, xf=G.nx, yf=G.ny, zf=G.nz)
G.pmls.append(pml)
for i in range(G.nx):
for j in range(G.ny):
numID = G.solid[i, j, pml.zs]
material = next(x for x in G.materials if x.numID == numID)
sumer += material.er
summr += material.mr
averageer = sumer / (G.nx * G.ny)
averagemr = summr / (G.nx * G.ny)
pml.calculate_update_coeffs(averageer, averagemr, G)
pbar.update()