diff --git a/docs/source/input.rst b/docs/source/input.rst index 79f0bc21..73d6f691 100644 --- a/docs/source/input.rst +++ b/docs/source/input.rst @@ -790,7 +790,7 @@ or * ``f4 f5 f6`` are the upper right (x,y,z) coordinates of the volume of the snapshot in metres. * ``f7 f8 f9`` are the spatial discretisation of the snapshot in metres. * ``f10`` or ``i1`` are the time in seconds (float) or the iteration number (integer) which denote the point in time at which the snapshot will be taken. -* ``file1`` is the filename of the file where the snapshot will be stored. +* ``file1`` is the name of the file where the snapshot will be stored. Snapshot files are automatically stored in a directory with the name of the input file appended with '_snaps'. For multiple model runs each model run will have its own directory, i.e. '_snaps1', 'snaps2' etc... For example to save a snapshot of the electromagnetic fields in the model at a simulated time of 3 nanoseconds use: ``#snapshot: 0 0 0 1 1 1 0.1 0.1 0.1 3e-9 snap1`` diff --git a/gprMax/gprMax.py b/gprMax/gprMax.py index bf126edf..99a34128 100644 --- a/gprMax/gprMax.py +++ b/gprMax/gprMax.py @@ -257,6 +257,7 @@ def run_model(args, modelrun, numbermodelruns, inputfile, usernamespace): # Initialise an instance of the FDTDGrid class G = FDTDGrid() + G.inputfilename = os.path.split(inputfile)[1] G.inputdirectory = usernamespace['inputdirectory'] # Create built-in materials diff --git a/gprMax/grid.py b/gprMax/grid.py index 365b2d08..45b011d4 100644 --- a/gprMax/grid.py +++ b/gprMax/grid.py @@ -27,6 +27,7 @@ class FDTDGrid: """Holds attributes associated with the entire grid. A convenient way for accessing regularly used parameters.""" def __init__(self): + self.inputfilename = '' self.inputdirectory = '' self.title = '' self.messages = True diff --git a/gprMax/snapshots.py b/gprMax/snapshots.py index b8ceb449..8766eaa8 100644 --- a/gprMax/snapshots.py +++ b/gprMax/snapshots.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with gprMax. If not, see . -import sys +import os, sys import numpy as np from struct import pack @@ -77,11 +77,15 @@ class Snapshot: self.vtk_ny = self.yf - self.ys self.vtk_nz = self.zf - self.zs - # Construct filename from user-supplied name and model run number + # Create directory and construct filename from user-supplied name and model run number if numbermodelruns == 1: - self.filename = G.inputdirectory + self.filename + '.vti' + snapshotdir = os.path.join(G.inputdirectory, os.path.splitext(G.inputfilename)[0] + '_snaps') else: - self.filename = G.inputdirectory + self.filename + '_' + str(modelrun) + '.vti' + snapshotdir = os.path.join(G.inputdirectory, os.path.splitext(G.inputfilename)[0] + '_snaps' + str(modelrun)) + + if not os.path.exists(snapshotdir): + os.mkdir(snapshotdir) + self.filename = os.path.join(snapshotdir, self.filename + '.vti') # Calculate number of cells according to requested sampling self.vtk_xscells = round_value(self.xs / self.dx)