你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-08 07:24:19 +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()."""
|
"""gprMax.gprMax: provides entry point main()."""
|
||||||
|
|
||||||
import argparse, datetime, itertools, os, psutil, sys
|
import argparse
|
||||||
from time import perf_counter
|
import datetime
|
||||||
from enum import Enum
|
import itertools
|
||||||
|
import os
|
||||||
|
import psutil
|
||||||
|
import sys
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import gprMax
|
from time import perf_counter
|
||||||
from gprMax.constants import c, e0, m0, z0, floattype
|
from enum import Enum
|
||||||
from gprMax.exceptions import GeneralError
|
from ._version import __version__
|
||||||
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 .constants import c, e0, m0, z0
|
||||||
from gprMax.grid import FDTDGrid, dispersion_check
|
from .exceptions import GeneralError
|
||||||
from gprMax.input_cmds_geometry import process_geometrycmds
|
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 gprMax.input_cmds_file import process_python_include_code, write_processed_file, check_cmd_names
|
from .grid import FDTDGrid, dispersion_check
|
||||||
from gprMax.input_cmds_multiuse import process_multicmds
|
from .input_cmds_geometry import process_geometrycmds
|
||||||
from gprMax.input_cmds_singleuse import process_singlecmds
|
from .input_cmds_file import process_python_include_code, write_processed_file, check_cmd_names
|
||||||
from gprMax.materials import Material
|
from .input_cmds_multiuse import process_multicmds
|
||||||
from gprMax.writer_hdf5 import prepare_hdf5, write_hdf5
|
from .input_cmds_singleuse import process_singlecmds
|
||||||
from gprMax.pml import build_pmls, update_electric_pml, update_magnetic_pml
|
from .materials import Material
|
||||||
from gprMax.utilities import update_progress, logo, human_size
|
from .writer_hdf5 import prepare_hdf5, write_hdf5
|
||||||
from gprMax.yee_cell_build import build_electric_components, build_magnetic_components
|
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():
|
def main():
|
||||||
"""This is the main function for gprMax."""
|
"""This is the main function for gprMax."""
|
||||||
|
|
||||||
# Print gprMax logo, version, and licencing/copyright information
|
# Print gprMax logo, version, and licencing/copyright information
|
||||||
logo(gprMax.__version__ + ' (Bowmore)')
|
logo(__version__ + ' (Bowmore)')
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
parser = argparse.ArgumentParser(prog='gprMax', description='Electromagnetic modelling software based on the Finite-Difference Time-Domain (FDTD) method')
|
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('--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')
|
parser.add_argument('--opt-taguchi', action='store_true', default=False, help='optimise parameters using the Taguchi optimisation method')
|
||||||
args = parser.parse_args()
|
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
|
numbermodelruns = args.n
|
||||||
inputdirectory = os.path.dirname(os.path.abspath(args.inputfile))
|
inputdirectory = os.path.dirname(os.path.abspath(args.inputfile))
|
||||||
inputfile = os.path.abspath(os.path.join(inputdirectory, os.path.basename(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/>.
|
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import h5py
|
import h5py
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
import gprMax
|
from ._version import __version__
|
||||||
from gprMax.constants import floattype
|
from gprMax.constants import floattype
|
||||||
from gprMax.grid import Ix, Iy, Iz
|
from gprMax.grid import Ix, Iy, Iz
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ def prepare_hdf5(outputfile, G):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
f = h5py.File(outputfile, 'w')
|
f = h5py.File(outputfile, 'w')
|
||||||
f.attrs['gprMax'] = gprMax.__version__
|
f.attrs['gprMax'] = __version__
|
||||||
f.attrs['Title'] = G.title
|
f.attrs['Title'] = G.title
|
||||||
f.attrs['Iterations'] = G.iterations
|
f.attrs['Iterations'] = G.iterations
|
||||||
f.attrs['nx, ny, nz'] = (G.nx, G.ny, G.nz)
|
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):
|
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) + '/Vtotal'][timestep] = tl.voltage[tl.antpos]
|
||||||
f['/tls/tl' + str(tlindex + 1) + '/Itotal'][timestep] = tl.current[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:
|
except ImportError:
|
||||||
raise ImportError('gprMax requires the NumPy package.')
|
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
|
# Python version
|
||||||
if sys.version_info[:2] < (3, 4):
|
if sys.version_info[:2] < (3, 4):
|
||||||
print('gprMax requires Python 3.4 or newer')
|
print('gprMax requires Python 3.4 or newer')
|
||||||
sys.exit(-1)
|
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
|
# Process 'build' command line argument
|
||||||
if 'build' in sys.argv:
|
if 'build' in sys.argv:
|
||||||
print("'build' is not required for this package, running 'build_ext --inplace' instead.")
|
print("'build' is not required for this package, running 'build_ext --inplace' instead.")
|
||||||
@@ -176,4 +178,5 @@ setup(name=packagename,
|
|||||||
'Topic :: Scientific/Engineering'
|
'Topic :: Scientific/Engineering'
|
||||||
],
|
],
|
||||||
ext_modules=extensions,
|
ext_modules=extensions,
|
||||||
|
packages=['gprMax'],
|
||||||
include_dirs=[np.get_include()])
|
include_dirs=[np.get_include()])
|
||||||
|
在新工单中引用
屏蔽一个用户