The block
Class¶
The block
class represents a block of material in a simulation. Blocks are not meant to be
interacted with directly – when using the problem
class to set up a simulation, blocks are
automatically added or deleted as needed using the provided interfaces. This documentation
is provided for completeness, but should not need to be used in regular use of the code.
The class contains information on the number of grid points in the block, the location of the block
within the simulation, the material properties using the material
class, the types of boundary
conditions at the block edges, and any complex geometries specified through the surface
and curve
classes.
-
class
fdfault.
block
(ndim, mode, nx, mat)¶ Class representing a block in a simulation
A block contains the following internal variables:
Variables: - ndim – Number of dimensions (2 or 3)
- mode – Rupture mode (2 or 3, relevant only for 2D problems)
- nx – Number of grid points (tuple of 3 positive integers)
- xm – Coordinates of lower left corner in simulation (tuple of 3 nonnegative integers)
- coords – Location of block within simulation domain (tuple of 3 nonnegative integers)
- lx – Block length in each spatial dimension (tuple of 3 positive floats, can be overridden by setting a curve or surface to one of the edges)
Parameters: - m (material) – Material properties (see
material
class) - bounds (list) – List of boundary conditions. Position indicates boundary location (0 = left,
1 = right, 2 = front, 3 = back, 4 = bottom, 5 = top). Possible strings for
boundary condition include
'absorbing'
(no incoming wave),'free'
(traction free surface),'rigid'
(no displacement), or'none'
(boundary conditions determined by interface conditions) - surfs (list) – List of bounding surfaces. Position indicates boundary location (0 = left,
1 = right, 2 = front, 3 = back, 4 = bottom, 5 = top). For 2D problems,
you can only populate the list with curves, and 3D problems require
surfaces. If the default rectangular surface is to be used, use
None
for a particular surface.
-
__init__
(ndim, mode, nx, mat)¶ Initialize a new
block
instanceCreates a new block instance with the given dimensionality, rupture mode, number of grid points, and material type. If the problem is 2d, the number of z grid points will be automatically set to one. By default, the block length is unity in each direction, the lower left coordinate is
(0., 0., 0.)
, all boundary conditions are set to'none'
, material properties take on their default values, and there are no irregular edge shapes. All of these default properties can be modified using the provided interfaces.Parameters: - ndim (int) – Number of spatial dimensions (must be 2 or 3)
- mode (int) – Slip mode (2 or 3, only relevant if the problem is in 2D)
- nx (tuple or list) – Tuple of length 3 with number of grid points
(nx, ny, nz)
- mat (str) – Block material type (string, must be
'elastic'
or'plastic'
). The method initializes a default set of material properties based on this type.
Returns: New block instance
Return type:
-
check
()¶ Checks for errors before writing input file
Checks that edges of bounding surfaces match. If the edges are not defined as surfaces, the code temporarily creates them to check that they match.
Returns: None
-
checksurfs
(tmpsurfs)¶ Checks that surface boundaries match
Input is a list of surfaces, with order corresponding to (left, right, front, back, top, bottom). In 2D problems, there is no top or bottom surface.
Parameters: tmpsurfs (list) – List of surfaces to compare (lenth 4 or 6) Returns: None
-
delete_surf
(loc)¶ Removes boundary surface for a particular block edge
Removes the bounding surface of a particular block edge. Location is determined by
loc
which is an integer that indexes into a list. Locations correspond to the following: 0 = left, 1 = right, 2 = front, 3 = back, 4 = bottom, 5 = top. Note that the location must be 0 <= loc < 2*ndimIf
loc
is out of bounds, the code will also signal an error.Parameters: loc (int) – Location of desired boundary to be removed (0 = left, 1 = right, 2 = front, 3 = back, 4 = bottom, 5 = top). For 2D problems, loc
must be between 0 and 3.Returns: None
-
get_bounds
(loc=None)¶ Returns boundary types
If
loc
(int) is provided, the method returns a specific location (str). Otherwise it returns a list of all boundaries, which will have length 4 for 2D problems and length 6 for 3D problems.loc
serves effectively as an index into the list, and the indices correspond to the following: 0 = left, 1 = right, 2 = front, 3 = back, 4 = bottom, 5 = top. Note that the location must be 0 <= loc < 2*ndimParameters: loc (int or None) – Location of boundary that is desired (optional). If loc
is not provided, returns a listReturns: Boundary type (if loc
provided, returns a string of the boundary type for the desired location, of not returns a list of strings indicating all boundary types)Return type: str or list
-
get_coords
()¶ Returns block coordinates (tuple of integer indices in each coordinate direction)
Returns: Block coordinates (tuple of 3 integers) Return type: tuple
-
get_lx
()¶ Returns block lengths as (lx, ly, lz) tuple
Returns: Block dimensions (tuple of 3 floats) in x, y, and z dimensions Return type: tuple
-
get_material
()¶ Returns material
Returns the material class associated with this block
Returns: Material class with properties for this block Return type: material
-
get_mode
()¶ Returns rupture mode (2 or 3), only valid for 2D problems (stored at domain level)
Returns: Rupture mode Return type: int
-
get_ndim
()¶ Returns Number of spatial dimensions
Returns: Number of spatial dimensions Return type: int
-
get_nx
()¶ Returns number of grid points in (nx, ny, nz) format for the given block
Returns: Number of grid points (tuple of three integers) Return type: tuple
-
get_surf
(loc)¶ Returns block boundary surface for a block edge
Returns the surface assigned to a specific edge.
loc
determines the edge that is returned (integer, corresponding to an index). Location indices correspond to the following: 0 = left, 1 = right, 2 = front, 3 = back, 4 = bottom, 5 = top Note that the location must be 0 <= loc < 2*ndim (for 2D problems,loc
cannot be 5 or 6).Returns either a curve (2D problems) or surface (3D problems) or None
If
loc
indices are out of bounds, the code will raise an error.Parameters: loc (int) – Location of desired boundary (0 = left, 1 = right, 2 = front, 3 = back, 4 = bottom, 5 = top). For 2D problems, loc
must be between 0 and 3.Returns: curve or surface corresponding to the selected location. If the desired edge does not have a bounding surface, returns None. Return type: curve or surface or None
-
get_x
(coord)¶ Returns grid value for given spatial index
For a given problem set up, returns the location of a particular set of coordinate indices. Note that since blocks are set up by setting values only on the edges, coordinates on the interior are not specified a priori and instead determined using transfinite interpolation to generate a regular grid on the block interiors. Calling
get_x
generates the interior grid to find the coordinates of the desired point.Within each call to
get_x
, the grid is generated on the fly only for the relevant block where the desired point is located. It is not stored. This helps reduce memory requirements for large 3D problems (since the Python module does not run in parallel), but is slower. Because the computational grid is regular, though, it can be done in a single step in closed form.Returns a numpy array of length 3 holding the spatial location (x, y, z).
Parameters: coord (tuple or list) – Spatial coordinate where grid values are desired (tuple or list of 3 integers or 2 integers for 2D problems) Returns: (x, y, z) coordinates of spatial location Return type: ndarray
-
get_xm
()¶ Returns starting index (zero-indexed) of block (tuple of 3 integers)
Returns: Coordinates of lower left corner (tuple of 3 integers) Return type: tuple
-
make_tempsurfs
()¶ Create temporary surface list
This method generates all six (four in 2D) bounding surfaces (curves in 2D). Note that these surfaces are not usually stored for rectangular block edges to save memory, as they are trivial to create. The temporary surfaces can be used to check that the edges of the surfaces/curves match or to use transfinite interpolation to generate the grid.
Returns: List of all bounding surfaces (not stored beyond the time they are needed) Return type: list
-
set_bounds
(bounds, loc=None)¶ Sets boundary types
Changes the type of boundary conditions on a block. Acceptable values are ‘absorbing’ (incoming wave amplitude set to zero), ‘free’ (no traction on boundary), ‘rigid’ (no displacement of boundary), or ‘none’ (boundary conditions set by imposing interface conditions).
There are two ways to use
set_bounds
:- Set
loc
to beNone
(default) and provide a list of strings specifying boundary type forbounds
. The length ofbounds
is 4 for a 2D simulation and 6 for 3D. - Set
loc
to be an integer denoting location and givebounds
as a single string. The possible locations correspond to the following: 0 = left, 1 = right, 2 = front, 3 = back, 4 = bottom, 5 = top. 4 and 5 are only applicable to 3D simulations (0 <= loc < 2*ndim).
Parameters: - bounds (str or list) – New boundary condition type (string or list of strings)
- loc (int or None) – If provided, only change one type of boundary condition rather than all (optional, loc serves as an index into the list if used)
Returns: None
- Set
-
set_coords
(coords)¶ Sets block coordinates to a new value
Set block coordinates to
coords
, and tuple of nonnegative integers denoting the location of the block in the domain.Parameters: coords (tuple or list) – New coordaintes (tuple or list of nonnegative integers) Returns: None
-
set_lx
(lx)¶ Sets block lengths
Changes block length to
lx
(tuple of 2 (2D only) or 3 floats) where the block length in each dimension is given by(lx, ly, lz)
Parameters: lx (tuple or list) – New value of block lengths (tuple of 2 (2D) or 3 floats) Returns: None
-
set_material
(mat)¶ Sets block material properties
Sets new material properties stored in an instance of the
material
class.Parameters: - newmaterial (material) – New material properties
- coords (tuple or list) – Coordinates of block to be changed (optional, omitting changes all blocks).
coords
must be a tuple or list of three integers that match the coordinates of a block.
Returns: None
-
set_mattype
(mattype)¶ Sets block material type (‘elastic’ or ‘plastic’)
Sets the material type for the block. Options are ‘elastic’ for an elastic simulation and ‘plastic’ for a plastic simulation. Anything else besides these options will cause the code to raise an error.
Parameters: mattype (str) – New material type (‘elastic’ or ‘plastic’) Returns: None
-
set_mode
(mode)¶ Sets rupture mode
Rupture mode is only valid for 2D problems, and is either 2 or 3 (other values will cause an error, and non-integer values will be converted to integers). For 3D problems, entering a different value of the rupture mode will alter the rupture mode cosmetically but will have no effect on the simulation.
Parameters: mode (int) – New value of rupture mode Returns: None
-
set_ndim
(ndim)¶ Sets number of dimensions
The new number of spatial dimensions must be an integer, either 2 or 3. If a different value is given, the code will raise an error. If a non-integer value is given that is acceptable, the code will convert it to an integer.
Note: Converting a 3D problem into a 2D problem will automatically collapse the number of grid points and the number of blocks in the $z$ direction to be 1. Any modifications to these quantities that were done previously will be lost.
Parameters: ndim (int) – New value for ndim (must be 2 or 3) Returns: None
-
set_nx
(nx)¶ Sets number of grid points
Changes the number of grid points to the specified tuple/list of 3 nonnegative integers. Bad values of
nx
will raise an error.Parameters: nx (tuple or list) – New value of number of grid points (tuple of 3 positive integers) Returns: None
-
set_surf
(loc, surf)¶ Sets boundary surface for a particular block edge
Changes the bounding surface of a particular block edge. Location is determined by
loc
which is an integer that indexes into a list. Locations correspond to the following: 0 = left, 1 = right, 2 = front, 3 = back, 4 = bottom, 5 = top. Note that the location must be 0 <= loc < 2*ndimFor 2D problems,
surf
must be a curve. For 3D problems,surf
must be a surface. Other choices will raise an error. Ifloc
is out of bounds, the code will also signal an error.Parameters: - loc (int) – Location of desired boundary (0 = left, 1 = right, 2 = front, 3 = back,
4 = bottom, 5 = top). For 2D problems,
loc
must be between 0 and 3. - surf (curve or surface) – curve or surface corresponding to the selected block and location
Returns: None
- loc (int) – Location of desired boundary (0 = left, 1 = right, 2 = front, 3 = back,
4 = bottom, 5 = top). For 2D problems,
-
set_xm
(xm)¶ Sets block lower left coordinate
Changes lower left coordinate of a block to the provided tuple/list of integers.
Parameters: xm (tuple or list) – New value of lower left coordinate (list/tuple of integers) Returns: None
-
write_input
(f, probname, directory, endian='=')¶ Writes block information to input file
Method writes information for block to file. It also writes all relevant surface data to file to describe non-rectangular geometries. Inputs inlcude the file handle for the input file, the problem name (used for naming surface files), the destination directory for all files, and endianness (optional, default is native) for binary surface files.
Parameters: - f (file) – file handle for input file
- probname (str) – Problem name
- directory (str) – Directory where output should be written
- endian (str) – Byte-ordering for binary files for surface data. Possible values are
'<'
(little endian),'>'
(big endian), or'='
(native, default)
Returns: None