你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 23:14:03 +08:00
install gprMax as a module
这个提交包含在:
@@ -1 +1,4 @@
|
||||
from gprMax._version import __version__
|
||||
from ._version import __version__
|
||||
from .gprMax import api as run
|
||||
|
||||
__name__ = 'gprMax'
|
||||
|
@@ -18,33 +18,38 @@
|
||||
|
||||
"""gprMax.gprMax: provides entry point main()."""
|
||||
|
||||
import argparse, datetime, itertools, os, psutil, sys
|
||||
from time import perf_counter
|
||||
from enum import Enum
|
||||
import argparse
|
||||
import datetime
|
||||
import itertools
|
||||
import os
|
||||
import psutil
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
import gprMax
|
||||
from gprMax.constants import c, e0, m0, z0, floattype
|
||||
from gprMax.exceptions import GeneralError
|
||||
from gprMax.fields_update import update_electric, update_magnetic, update_electric_dispersive_multipole_A, update_electric_dispersive_multipole_B, update_electric_dispersive_1pole_A, update_electric_dispersive_1pole_B
|
||||
from gprMax.grid import FDTDGrid, dispersion_check
|
||||
from gprMax.input_cmds_geometry import process_geometrycmds
|
||||
from gprMax.input_cmds_file import process_python_include_code, write_processed_file, check_cmd_names
|
||||
from gprMax.input_cmds_multiuse import process_multicmds
|
||||
from gprMax.input_cmds_singleuse import process_singlecmds
|
||||
from gprMax.materials import Material
|
||||
from gprMax.writer_hdf5 import prepare_hdf5, write_hdf5
|
||||
from gprMax.pml import build_pmls, update_electric_pml, update_magnetic_pml
|
||||
from gprMax.utilities import update_progress, logo, human_size
|
||||
from gprMax.yee_cell_build import build_electric_components, build_magnetic_components
|
||||
from time import perf_counter
|
||||
from enum import Enum
|
||||
from ._version import __version__
|
||||
from .constants import c, e0, m0, z0
|
||||
from .exceptions import GeneralError
|
||||
from .fields_update import update_electric, update_magnetic, update_electric_dispersive_multipole_A, update_electric_dispersive_multipole_B, update_electric_dispersive_1pole_A, update_electric_dispersive_1pole_B
|
||||
from .grid import FDTDGrid, dispersion_check
|
||||
from .input_cmds_geometry import process_geometrycmds
|
||||
from .input_cmds_file import process_python_include_code, write_processed_file, check_cmd_names
|
||||
from .input_cmds_multiuse import process_multicmds
|
||||
from .input_cmds_singleuse import process_singlecmds
|
||||
from .materials import Material
|
||||
from .writer_hdf5 import prepare_hdf5, write_hdf5
|
||||
from .pml import build_pmls, update_electric_pml, update_magnetic_pml
|
||||
from .utilities import update_progress, logo, human_size
|
||||
from .yee_cell_build import build_electric_components, build_magnetic_components
|
||||
|
||||
|
||||
def main():
|
||||
"""This is the main function for gprMax."""
|
||||
|
||||
# Print gprMax logo, version, and licencing/copyright information
|
||||
logo(gprMax.__version__ + ' (Bowmore)')
|
||||
logo(__version__ + ' (Bowmore)')
|
||||
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(prog='gprMax', description='Electromagnetic modelling software based on the Finite-Difference Time-Domain (FDTD) method')
|
||||
@@ -57,6 +62,31 @@ def main():
|
||||
parser.add_argument('--write-processed', action='store_true', default=False, help='write an input file after any Python code and include commands in the original input file have been processed')
|
||||
parser.add_argument('--opt-taguchi', action='store_true', default=False, help='optimise parameters using the Taguchi optimisation method')
|
||||
args = parser.parse_args()
|
||||
|
||||
run_main(args)
|
||||
|
||||
|
||||
def api(inputfile, n=1, mpi=False, benchmark=False, geometry_only=False, geometry_fixed=False, write_processed=False, opt_taguchi=False):
|
||||
"""If you have installed gprMax as a module this is the entry point"""
|
||||
class ImportArguments:
|
||||
pass
|
||||
|
||||
args = ImportArguments()
|
||||
|
||||
args.inputfile = inputfile
|
||||
args.n = n
|
||||
args.mpi = mpi
|
||||
args.benchmark = benchmark
|
||||
args.geometry_only = geometry_only
|
||||
args.geometry_fixed = geometry_fixed
|
||||
args.write_processed = write_processed
|
||||
args.opt_taguchi = opt_taguchi
|
||||
|
||||
run_main(args)
|
||||
|
||||
|
||||
def run_main(args):
|
||||
|
||||
numbermodelruns = args.n
|
||||
inputdirectory = os.path.dirname(os.path.abspath(args.inputfile))
|
||||
inputfile = os.path.abspath(os.path.join(inputdirectory, os.path.basename(args.inputfile)))
|
||||
|
@@ -17,9 +17,8 @@
|
||||
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import h5py
|
||||
import numpy as np
|
||||
|
||||
import gprMax
|
||||
from ._version import __version__
|
||||
from gprMax.constants import floattype
|
||||
from gprMax.grid import Ix, Iy, Iz
|
||||
|
||||
@@ -36,7 +35,7 @@ def prepare_hdf5(outputfile, G):
|
||||
"""
|
||||
|
||||
f = h5py.File(outputfile, 'w')
|
||||
f.attrs['gprMax'] = gprMax.__version__
|
||||
f.attrs['gprMax'] = __version__
|
||||
f.attrs['Title'] = G.title
|
||||
f.attrs['Iterations'] = G.iterations
|
||||
f.attrs['nx, ny, nz'] = (G.nx, G.ny, G.nz)
|
||||
@@ -116,4 +115,3 @@ def write_hdf5(f, timestep, Ex, Ey, Ez, Hx, Hy, Hz, G):
|
||||
for tlindex, tl in enumerate(G.transmissionlines):
|
||||
f['/tls/tl' + str(tlindex + 1) + '/Vtotal'][timestep] = tl.voltage[tl.antpos]
|
||||
f['/tls/tl' + str(tlindex + 1) + '/Itotal'][timestep] = tl.current[tl.antpos]
|
||||
|
||||
|
35
setup.py
35
setup.py
@@ -27,28 +27,30 @@ try:
|
||||
except ImportError:
|
||||
raise ImportError('gprMax requires the NumPy package.')
|
||||
|
||||
import glob, os, shutil, sys
|
||||
import glob
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import re
|
||||
|
||||
# Importing _version__.py before building can cause issues.
|
||||
with open('gprMax/_version.py', 'r') as fd:
|
||||
version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
|
||||
fd.read(), re.MULTILINE).group(1)
|
||||
|
||||
"""
|
||||
Parse package name from init file. Importing __init__.py / gprMax will
|
||||
break as gprMax depends on compiled .pyx files.
|
||||
"""
|
||||
with open('gprMax/__init__.py', 'r') as fd:
|
||||
packagename = re.search(r'^__name__\s*=\s*[\'"]([^\'"]*)[\'"]',
|
||||
fd.read(), re.MULTILINE).group(1)
|
||||
|
||||
# Python version
|
||||
if sys.version_info[:2] < (3, 4):
|
||||
print('gprMax requires Python 3.4 or newer')
|
||||
sys.exit(-1)
|
||||
|
||||
import gprMax
|
||||
|
||||
# Package name
|
||||
packagename = gprMax.__name__
|
||||
|
||||
# Package version
|
||||
version = gprMax.__version__
|
||||
|
||||
# Process 'install' command line argument
|
||||
if 'install' in sys.argv:
|
||||
print("'install' is not required for this package, running 'build_ext --inplace' instead.")
|
||||
sys.argv.remove('install')
|
||||
sys.argv.append('build_ext')
|
||||
sys.argv.append('--inplace')
|
||||
|
||||
# Process 'build' command line argument
|
||||
if 'build' in sys.argv:
|
||||
print("'build' is not required for this package, running 'build_ext --inplace' instead.")
|
||||
@@ -176,4 +178,5 @@ setup(name=packagename,
|
||||
'Topic :: Scientific/Engineering'
|
||||
],
|
||||
ext_modules=extensions,
|
||||
packages=['gprMax'],
|
||||
include_dirs=[np.get_include()])
|
||||
|
在新工单中引用
屏蔽一个用户