这个提交包含在:
jasminium
2019-08-25 19:57:34 +01:00
父节点 2780055af8
当前提交 dd7153e31b
共有 5 个文件被更改,包括 401 次插入226 次删除

查看文件

@@ -1,157 +1,303 @@
.. _commands: .. _api:
******************* *******************
API API
******************* *******************
gprMax can be also be run using its API in additional to input file commands. For instance, Introduction
==================
.. code-block:: python In additional to input file command interface gprMax can also be run using its API. The usage of the API differs from the use of the Python blocks syntax as follows. In the API gprMax functionality is called directly from any Python file via the gprMax module. Using the Python blocks syntax the Python code is executed within an embedded interpreter. The API has the advantage that it can be included within any Python file and can be included within any Python script.
import gprMax There are several advantages to using API. Firstly, users can take advantage of the Python language. For instance, the structural elements of Python can be utilised more easily. gprMax objects can be used directly within functions, classes, modules and packages. In this way collections of components can be defined, reused and modified. For example, multiple SMA type connectors can be imported as a module and combined with an antenna from another module.
# Make simulation objects The API also allows gprMax to interface with other Python libraries. For example, the API could be used to create a parametric antenna and the external library Scipy could then be used to optimise its parameters. Although, this is possible using Python blocks syntax, the script file can also be debugged.
#title: GSSI 400MHz 'like' antenna in free-space The syntax of the API is generally more verbose than the input file command syntax. However, for input file commands where there are an undefined number of parameters, such as adding dispersive properties, the user may find the API more manageable.
#domain: 0.380 0.380 0.360
#dx_dy_dz: 0.001 0.001 0.001 Example
#time_window: 12e-9 ==================
# equivalent to 'title: API example' The following example is used to give an introduction to the gprMax API. the example file is found in
title = gprMax.Title(name='API example') ``user_models/antenna_wire_dipole_fs.py``.
# equivalent to 'dx_dy_dz: 1e-3 1e-3 1e-3'
dxdydz = gprMax.Discretisation(p1=(1e-3, 1e-3, 1e-3)) First, import the gprMax module.
# equivalent to 'time_window: 6e-9'
tw = gprMax.TimeWindow(time=6e-9) .. code-block:: python
# equivalent to 'domain: 0.15 0.15 0.15'
domain = gprMax.Domain(p1=(0.15, 0.15, 0.15)) import gprMax
# equivalent to #waveform: ricker 1 1.5e9 myricker Next, simulation objects for the simulation are created from the gprMax module. Each input file command is available as an object. Simulation objects are created by passing the object parameters as key=value option arguments. The following example shows the creation of simulation objects and also their equivalent input file command for clarity.
waveform = gprMax.Waveform(wave_type='ricker', amp=1, freq=1.5e9, id='my_ricker')
# equivalent to 'hertzian_dipole: y 0.045 0.075 0.085 my_ricker' .. code-block:: python
dipole = gprMax.HertzianDipole(p1=(0.045, 0.075, 0.085), polarisation='y', waveform_id='my_ricker')
# equivalent to 'rx: 0.045, 0.075 + 10e-3, 0.085' #title: Wire antenna - half-wavelength dipole in free-space
rx = gprMax.Rx(p1=(0.045, 0.075 + 10e-3, 0.085)) title = gprMax.Title(name="Wire antenna - half-wavelength dipole in free-space")
#domain: 0.050 0.050 0.200
# make a container for the simulation domain = gprMax.Domain(p1=(0.050, 0.050, 0.200))
scene = gprMax.Scene() #dx_dy_dz: 0.001 0.001 0.001
# add the objects to the container dxdydz = gprMax.Discretisation(p1=(0.001, 0.001, 0.001))
scene.add(dxdydz) #time_window: 60e-9
scene.add(tw) time_window = gprMax.TimeWindow(time=10e-9)
scene.add(domain) #waveform: gaussian 1 1e9 mypulse
scene.add(title) waveform = gprMax.Waveform(wave_type='gaussian', amp=1, freq=1e9, id='mypulse')
scene.add(waveform) #transmission_line: z 0.025 0.025 0.100 73 mypulse
scene.add(dipole) transmission_line = gprMax.TransmissionLine(polarisation='z',
p1=(0.025, 0.025, 0.100),
# run the simulation resistance=73,
gprMax.run(scenes=[scene], n=1, geometry_only=False, outputfile='mysimulation') waveform_id='mypulse')
## 150mm length
#edge: 0.025 0.025 0.025 0.025 0.025 0.175 pec
The commands have been grouped into six categories: e1 = gprMax.Edge(p1=(0.025, 0.025, 0.025),
p2=(0.025, 0.025, 0.175),
* **Essential** - required to run any model, such as the domain size and spatial discretization material_id='pec')
* **General** - provide further control over the model
* **Material** - used to introduce different materials into the model ## 1mm gap at centre of dipole
* **Object construction** - used to build geometric shapes with different constitutive parameters #edge: 0.025 0.025 0.100 0.025 0.025 0.101 free_space
* **Source and output** - used to place source and output points in the model e2 = gprMax.Edge(p1=(0.025, 0.025, 0.100),
* **PML** - provide advanced customisation and optimisation of the absorbing boundary conditions p2=(0.025, 0.025, 0.100),
material_id='free_space')
Essential
================== #geometry_view: 0.020 0.020 0.020 0.030 0.030 0.180 0.001 0.001 0.001 antenna_wire_dipole_fs f
Most of the commands are optional but there are some essential commands which are necessary in order to construct any model. For example, none of the media and object commands are necessary to run a model. However, without specifying any objects in the model gprMax will simulate free space (air), which on its own, is not particularly useful for GPR modelling. If you have not specified a command which is essential in order to run a model, for example the size of the model, gprMax will terminate execution and issue an appropriate error message. gv = gprMax.GeometryView(p1=(0.020, 0.020, 0.020),
p2=(0.030, 0.030, 0.180),
The essential commands are: dl=(0.001, 0.001, 0.001),
filename='antenna_wire_dipole_fs',
Domain output_type='n')
------
.. autoclass:: gprMax.cmds_single_use.Domain
Next a :class:`gprMax.scene.Scene` object is created. The scene is a container for all the objects required in a simulation. The objects are added to the scene as follows:
Discretisation
-------------- .. code-block:: python
.. autoclass:: gprMax.cmds_single_use.Discretisation
# Create a scene
Time Window scene = gprMax.Scene()
----------- # Add the simulation objects to the scene
.. autoclass:: gprMax.cmds_single_use.TimeWindow scene.add(title)
scene.add(domain)
General scene.add(dxdydz)
======= scene.add(time_window)
scene.add(waveform)
Messages scene.add(transmission_line)
-------- scene.add(e1)
.. autoclass:: gprMax.cmds_single_use.Messages scene.add(e2)
scene.add(gv)
Title
-----
.. autoclass:: gprMax.cmds_single_use.Title Once the simulation objects have been added to the scene the simulation is run as follows:
Number of Threads .. code-block:: python
-----------------
.. autoclass:: gprMax.cmds_single_use.NumThreads # run the simulation
gprMax.run(scenes=[scene], n=1, outputfile='mysimulation')
Time Step Stability Factor
-------------------------- The run function arguments are similar to the flags in the CLI. The most notable difference is that a file path for the data output must be provided.
.. autoclass:: gprMax.cmds_single_use.TimeStepStabilityFactor
Multiple simulation can be specified by providing multiple scene objects to the run function. Each scene must contain the essential commands and each user object required for that particular model.
Output Directory
-------------------------- Reference
.. autoclass:: gprMax.cmds_single_use.OutputDir =========
Number of Model Runs The commands have been grouped into six categories:
--------------------
.. autoclass:: gprMax.cmds_single_use.NumberOfModelRuns * **Essential** - required to run any model, such as the domain size and spatial discretization
* **General** - provide further control over the model
* **Material** - used to introduce different materials into the model
* **Object construction** - used to build geometric shapes with different constitutive parameters
Material * **Source and output** - used to place source and output points in the model
======== * **PML** - provide advanced customisation and optimisation of the absorbing boundary conditions
Object Construction
=================== Essential
Source and Output ==================
================= Most of the commands are optional but there are some essential commands which are necessary in order to construct any model. For example, none of the media and object commands are necessary to run a model. However, without specifying any objects in the model gprMax will simulate free space (air), which on its own, is not particularly useful for GPR modelling. If you have not specified a command which is essential in order to run a model, for example the size of the model, gprMax will terminate execution and issue an appropriate error message.
Waveform The essential commands are:
--------
.. autoclass:: gprMax.cmds_multiple.Waveform Domain
------
Voltage Source .. autoclass:: gprMax.cmds_single_use.Domain
--------------
.. autoclass:: gprMax.cmds_multiple.VoltageSource Discretisation
--------------
Hertzian Dipole Source .. autoclass:: gprMax.cmds_single_use.Discretisation
----------------------
.. autoclass:: gprMax.cmds_multiple.HertzianDipole Time Window
-----------
Magnetic Dipole Source .. autoclass:: gprMax.cmds_single_use.TimeWindow
----------------------
.. autoclass:: gprMax.cmds_multiple.MagneticDipole General
=======
Transmission Line
----------------- Messages
.. autoclass:: gprMax.cmds_multiple.TransmissionLine --------
.. autoclass:: gprMax.cmds_single_use.Messages
Excitation File
--------------- Title
.. autoclass:: gprMax.cmds_single_use.ExcitationFile -----
.. autoclass:: gprMax.cmds_single_use.Title
Rx
-- Number of Threads
.. autoclass:: gprMax.cmds_multiple.Rx -----------------
.. autoclass:: gprMax.cmds_single_use.NumThreads
Rx Array
-------- Time Step Stability Factor
.. autoclass:: gprMax.cmds_multiple.RxArray --------------------------
.. autoclass:: gprMax.cmds_single_use.TimeStepStabilityFactor
Source Steps
------------ Output Directory
.. autoclass:: gprMax.cmds_single_use.SrcSteps --------------------------
.. autoclass:: gprMax.cmds_single_use.OutputDir
Rx Steps
------------ Number of Model Runs
.. autoclass:: gprMax.cmds_single_use.RxSteps --------------------
.. autoclass:: gprMax.cmds_single_use.NumberOfModelRuns
PML
===
PML Cells
-------------------------- Material
.. autoclass:: gprMax.cmds_single_use.PMLCells ========
Material
--------
.. autoclass:: gprMax.cmds_multiple.Material
Debye Dispersion
----------------
.. autoclass:: gprMax.cmds_multiple.AddDebyeDispersion
Lorentz Dispersion
------------------
.. autoclass:: gprMax.cmds_multiple.AddLorentzDispersion
Drude Dispersion
----------------
.. autoclass:: gprMax.cmds_multiple.AddDrudeDispersion
Soil Peplinski
--------------
.. autoclass:: gprMax.cmds_multiple.SoilPeplinski
Object Construction
===================
Object construction commands are processed in the order they appear in the scene. Therefore space in the model allocated to a specific material using for example the :class:`gprMax.cmds_geometry.box.Box` command can be reallocated to another material using the same or any other object construction command. Space in the model can be regarded as a canvas in which objects are introduced and one can be overlaid on top of the other overwriting its properties in order to produce the desired geometry. The object construction commands can therefore be used to create complex shapes and configurations.
Box
---
.. autoclass:: gprMax.cmds_geometry.box.Box
Cylinder
--------
.. autoclass:: gprMax.cmds_geometry.cylinder.Cylinder
Cylindrical Sector
------------------
.. autoclass:: gprMax.cmds_geometry.cylindrical_sector.CylindricalSector
Edge
----
.. autoclass:: gprMax.cmds_geometry.edge.Edge
Plate
-----
.. autoclass:: gprMax.cmds_geometry.plate.Plate
Triangle
-----
.. autoclass:: gprMax.cmds_geometry.triangle.Triangle
Sphere
-----
.. autoclass:: gprMax.cmds_geometry.sphere.Sphere
Fractal Box
-----
.. autoclass:: gprMax.cmds_geometry.fractal_box.FractalBox
Add Grass
---------
.. autoclass:: gprMax.cmds_geometry.add_grass.AddGrass
Add Surface Roughness
---------------------
.. autoclass:: gprMax.cmds_geometry.add_surface_roughness.AddSurfaceRoughness
Add Surface Water
-----------------
.. autoclass:: gprMax.cmds_geometry.add_surface_water.AddSurfaceWater
Geometry View
-------------
.. autoclass:: gprMax.cmds_multiple.GeometryView
Geometry Objects Write
----------------------
.. autoclass:: gprMax.cmds_multiple.GeometryObjectsWrite
Source and Output
=================
Waveform
--------
.. autoclass:: gprMax.cmds_multiple.Waveform
Voltage Source
--------------
.. autoclass:: gprMax.cmds_multiple.VoltageSource
Hertzian Dipole Source
----------------------
.. autoclass:: gprMax.cmds_multiple.HertzianDipole
Magnetic Dipole Source
----------------------
.. autoclass:: gprMax.cmds_multiple.MagneticDipole
Transmission Line
-----------------
.. autoclass:: gprMax.cmds_multiple.TransmissionLine
Excitation File
---------------
.. autoclass:: gprMax.cmds_single_use.ExcitationFile
Rx
--
.. autoclass:: gprMax.cmds_multiple.Rx
Rx Array
--------
.. autoclass:: gprMax.cmds_multiple.RxArray
Source Steps
------------
.. autoclass:: gprMax.cmds_single_use.SrcSteps
Rx Steps
------------
.. autoclass:: gprMax.cmds_single_use.RxSteps
Snapshot
--------
.. autoclass:: gprMax.cmds_multiple.Snapshot
PML
===
The default behaviour for the absorbing boundary conditions (ABC) is first order Complex Frequency Shifted (CFS) Perfectly Matched Layers (PML), with thicknesses of 10 cells on each of the six sides of the model domain. This can be altered by using the following command
PML Cells
--------------------------
.. autoclass:: gprMax.cmds_single_use.PMLCells
PML CFS
--------------------------
.. autoclass:: gprMax.cmds_multiple.PMLCFS
Additional API objects
======================
Function to run the simulation
------------------------------
.. autofunction:: gprMax.gprMax.run
.. autoclass:: gprMax.scene.Scene

查看文件

@@ -52,7 +52,7 @@ from .cmds_geometry.add_surface_water import AddSurfaceWater
from .cmds_geometry.add_grass import AddGrass from .cmds_geometry.add_grass import AddGrass
from .scene import Scene from .scene import Scene
from .gprMax import api as run from .gprMax import run as run
import gprMax.config as config import gprMax.config as config

查看文件

@@ -22,9 +22,8 @@ from .solvers import create_solver
import argparse import argparse
def api( def run(
scenes=None, scenes=None,
id=None,
inputfile=None, inputfile=None,
outputfile=None, outputfile=None,
n=1, n=1,
@@ -40,8 +39,36 @@ def api(
geometry_fixed=False, geometry_fixed=False,
write_processed=False, write_processed=False,
): ):
"""If installed as a module this is the entry point.""" """Run the simulation for the given list of scenes.
:param scenes: List of the scenes to run the model. Multiple scene objects can given in order to run multiple simulation runs. Each scene must contain the essential simulation objects
:type scenes: list, optional
:param inputfile: Input file path. Can also run simulation by providing an input file.
:type inputfile: str, optional
:param outputfile: File path to the output data file.
:type outputfile: str, non-optional
:param n: Number of required simulation runs.
:type n: int, non-optional
:param task: task identifier (model number) when running simulation as a job array on open grid scheduler/grid engine. for further details see the parallel performance section of the user guide
:type task: int, optional
:param restart: model number to start/restart simulation from. It would typically be used to restart a series of models from a specific model number, with the n argument, e.g. to restart from A-scan 45 when creating a B-scan with 60 traces
:type restart: int, optional
:param mpi: number of Message Passing Interface (MPI) tasks, i.e. master + workers, for MPI task farm. This option is most usefully combined with n to allow individual models to be farmed out using a MPI task farm, e.g. to create a B-scan with 60 traces and use MPI to farm out each trace1. For further details see the parallel performance section of the User Guide
:type mpi: int, optional
:param mpi_no_spawn: use MPI task farm without spawn mechanism. For further details see the parallel performance section of the User Guide.
:type mpi_no_spawn: bool, optional
:param gpu: Flag to use NVIDIA GPU or list of NVIDIA GPU device ID(s) for specific GPU card(s)
:type gpu: list or bool, optional
:param subgrid: Use sub-gridding.
:type subgrid: bool, optional
:param benchmark: Switch on benchmarking mode. This can be used to benchmark the threading (parallel) performance of gprMax on different hardware. For further details see the benchmarking section of the User Guide
:type benchmark: bool, optional
:param geometry_only: build a model and produce any geometry views but do not run the simulation.
:type geometry_only: bool, optional
:param geometry_fixed: build a model and produce any geometry views but do not run the simulation.
:type geometry_fixed: bool, optional
"""
class ImportArguments: class ImportArguments:
pass pass

查看文件

@@ -13,11 +13,10 @@ from .utilities import human_size
class Scene: class Scene:
"""Scene stores all of the user created objects."""
"""Scene stores all of the user created objects
"""
def __init__(self): def __init__(self):
"""Constructor"""
self.multiple_cmds = [] self.multiple_cmds = []
self.single_cmds = [] self.single_cmds = []
self.geometry_cmds = [] self.geometry_cmds = []
@@ -28,12 +27,17 @@ class Scene:
fbb = FractalBoxBuilder() fbb = FractalBoxBuilder()
self.add(fbb) self.add(fbb)
def add(self, node): def add(self, user_object):
if isinstance(node, UserObjectMulti): """Add the user object to the scene.
self.multiple_cmds.append(node)
elif isinstance(node, UserObjectGeometry): :param user_object: User object to add to the scene. For example, :class:`gprMax.cmds_single_use.Domain`
self.geometry_cmds.append(node) :type user_object: UserObjectMulti/UserObjectGeometry/UserObjectSingle
elif isinstance(node, UserObjectSingle): """
if isinstance(user_object, UserObjectMulti):
self.multiple_cmds.append(user_object)
elif isinstance(user_object, UserObjectGeometry):
self.geometry_cmds.append(user_object)
elif isinstance(user_object, UserObjectSingle):
self.single_cmds.append(node) self.single_cmds.append(node)
else: else:
raise Exception('This Object is Unknown to gprMax') raise Exception('This Object is Unknown to gprMax')

查看文件

@@ -1,56 +1,54 @@
# import the gprMax module # import the gprMax module
import gprMax import gprMax
# Create simulation objects. The equivalent input commands are given.
# Create simulation objects. The equivalent input commands are given. #title: Wire antenna - half-wavelength dipole in free-space
title = gprMax.Title(name="Wire antenna - half-wavelength dipole in free-space")
#title: Wire antenna - half-wavelength dipole in free-space #domain: 0.050 0.050 0.200
title = gprMax.Title(name="Wire antenna - half-wavelength dipole in free-space") domain = gprMax.Domain(p1=(0.050, 0.050, 0.200))
#domain: 0.050 0.050 0.200 #dx_dy_dz: 0.001 0.001 0.001
domain = gprMax.Domain(p1=(0.050, 0.050, 0.200)) dxdydz = gprMax.Discretisation(p1=(0.001, 0.001, 0.001))
#dx_dy_dz: 0.001 0.001 0.001 #time_window: 60e-9
dxdydz = gprMax.Discretisation(p1=(0.001, 0.001, 0.001)) time_window = gprMax.TimeWindow(time=10e-9)
#time_window: 60e-9 #waveform: gaussian 1 1e9 mypulse
time_window = gprMax.TimeWindow(time=10e-9) waveform = gprMax.Waveform(wave_type='gaussian', amp=1, freq=1e9, id='mypulse')
#waveform: gaussian 1 1e9 mypulse #transmission_line: z 0.025 0.025 0.100 73 mypulse
waveform = gprMax.Waveform(wave_type='gaussian', amp=1, freq=1e9, id='mypulse') transmission_line = gprMax.TransmissionLine(polarisation='z',
#transmission_line: z 0.025 0.025 0.100 73 mypulse p1=(0.025, 0.025, 0.100),
transmission_line = gprMax.TransmissionLine(polarisation='z', resistance=73,
p1=(0.025, 0.025, 0.100), waveform_id='mypulse')
resistance=73, ## 150mm length
waveform_id='mypulse') #edge: 0.025 0.025 0.025 0.025 0.025 0.175 pec
## 150mm length e1 = gprMax.Edge(p1=(0.025, 0.025, 0.025),
#edge: 0.025 0.025 0.025 0.025 0.025 0.175 pec p2=(0.025, 0.025, 0.175),
e1 = gprMax.Edge(p1=(0.025, 0.025, 0.025), material_id='pec')
p2=(0.025, 0.025, 0.175),
material_id='pec') ## 1mm gap at centre of dipole
#edge: 0.025 0.025 0.100 0.025 0.025 0.101 free_space
## 1mm gap at centre of dipole e2 = gprMax.Edge(p1=(0.025, 0.025, 0.100),
#edge: 0.025 0.025 0.100 0.025 0.025 0.101 free_space p2=(0.025, 0.025, 0.100),
e2 = gprMax.Edge(p1=(0.025, 0.025, 0.100), material_id='free_space')
p2=(0.025, 0.025, 0.100),
material_id='free_space') #geometry_view: 0.020 0.020 0.020 0.030 0.030 0.180 0.001 0.001 0.001 antenna_wire_dipole_fs f
gv = gprMax.GeometryView(p1=(0.020, 0.020, 0.020),
#geometry_view: 0.020 0.020 0.020 0.030 0.030 0.180 0.001 0.001 0.001 antenna_wire_dipole_fs f p2=(0.030, 0.030, 0.180),
gv = gprMax.GeometryView(p1=(0.020, 0.020, 0.020), dl=(0.001, 0.001, 0.001),
p2=(0.030, 0.030, 0.180), filename='antenna_wire_dipole_fs',
dl=(0.001, 0.001, 0.001), output_type='n')
filename='antenna_wire_dipole_fs',
output_type='n') # create a scene
scene = gprMax.Scene()
# create a scene # add the simulation objects to the scene
scene = gprMax.Scene() scene.add(title)
# add the simulation objects to the scene scene.add(domain)
scene.add(title) scene.add(dxdydz)
scene.add(domain) scene.add(time_window)
scene.add(dxdydz) scene.add(waveform)
scene.add(time_window) scene.add(transmission_line)
scene.add(waveform) scene.add(e1)
scene.add(transmission_line) scene.add(e2)
scene.add(e1) scene.add(gv)
scene.add(e2)
scene.add(gv) # run the simulation
gprMax.run(scenes=[scene], n=1, outputfile='mysimulation')
# run the simulation
gprMax.run(scenes=[scene], n=1, outputfile='mysimulation')