pySTK - Python bindings for Sierra Toolkit (STK)¶
- Version
v0.0.1
- Date
Jun 26, 2020
pySTK provides python bindings to Sierra Toolkit (STK). It uses the Cython bindings generator to interface with the STK C++ library. The library provides a way to interact with Exodus-II database through python for generating meshes, pre-processing and post-processing through python scripts. The python bindings can be built on Linux and MacOS platforms for Python3.
The python bindings are primarily developed for use in ExaWind framework and, therefore, the available featureset is heavily based on the needs of the Exawind project. However, the codebase only depends on the Trilinos/STK library and provides an almost 1-to-1 python version of the STK API for features that have been implemented so far.
Installation¶
pySTK needs the following packages installed on your system to be able to compile and build the python bindings:
Runtime dependencies
Build time dependencies
In addition to the runtime dependencies you will need the following packages installed on your system to build pySTK from source
Optionally, you’ll also need the following for development and generating documentation on your own machine
Building from source¶
To build from source create a new Python environment (either virtualenv or
conda env). You can use the requirements.txt
in the base directory to
install dependencies via pip
Execute the following commands to compile and install the package
# Clone the git repo
git clone git@github.com:sayerhs/pystk.git
cd pystk
# install dependencies
pip install -r requirements.txt
# Run python setup script
python setup.py install -- -DCMAKE_PREFIX_PATH=${TRILINOS_ROOT_DIR}
Building a development version¶
If you are developing pySTK you should install the package in development mode using the following commands instead of setup.py install
# Build extensions
python setup.py build_ext --inplace -- -DCMAKE_PREFIX_PATH=${TRILINOS_ROOT_DIR}
# Install package in develoment mode
pip install -e .
Once the package is installed in editable mode or (development mode), you
can execute the build_ext
command after editing the Cython files and have the
latest version of the compiled extensions available within your environment.
Note
If you have newer versions of CMake (3.15 or higher), then you can create an
environment variable STK_ROOT
and avoid passing additional arguments to
build_ext
. For example,
export STK_ROOT=${TRILINOS_INSTALL_DIR}
# Installation mode
python setup.py install
# Development mode
python setup.py build_ext --inplace
Common build issues¶
If you are using Anaconda Python (or Conda), please make sure that you install mpi4py and netcdf4-python via source and that the MPI you used to build these packages are consistent with the ones used to build STK/Trilinos. Incompatibilities amongst MPI libraries used to build STK/Trilinos and NetCDF4 can cause spurious memory errors and error messages when attempting to open Exodus-II databases.
Basic Usage¶
This section provides a high-level overview of using the pySTK to interact with
STK data structures and Exodus-II databases. The STK API is exposed as closely
as possible through the python interface. For example, every STK class (e.g.,
MetaData
, BulkData
, Part
, Selector
, etc.) has a python-wrapped
counterpart with the Stk
prefix. For example, MetaData
is exposed as
StkMetaData
within the python layer. Data getters/setters in C++ are exposed
as python properties, while methods taking arguments are exposed as normal
python methods with more or less the same arguments. The following code snippets
show the C++ source and its corresponding python equivalent.
STK usage in C++ code
int ndim=3;
MetaData meta(ndim);
// Get coordinates field
auto& coords = meta.coordinate_field();
// Get field name for coordinates
auto& coords_name = meta.coordinate_field_name();
// Get the part
auto* part = meta.get_part("block_1");
if (part == nullptr)
std::cout << "Part does not exist" << std::endl;
Corresponding Python equivalent
ndim = 3
meta = StkMetaData.create(ndim=ndim)
coords = meta.coordinate_field
coords_name = meta.coordinate_field_name
part = meta.get_part("block_1")
if part.is_null:
print("Part does not exist")
The following python script shows a sample interaction using the pySTK library.
You can download the script
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | # -*- coding: utf-8 -*-
"""\
Basic usage of pySTK interface
==============================
This tutorial provides a high-level overview of using pySTK API to interact with
Exodus-II databases and the Sierra Toolkit library.
The main entry point is the StkMesh instance which is a Python-wrapper that
holds the MetaData, BulkData, and StkMeshIoBroker instances. The user can
create multiple instances of StkMesh to manipulate different meshes.
Every class in STK (e.g., MetaData, BulkData, Part, Selector, etc.) has a
python wrapped counterpart with the `Stk` prefix. For example, `MetaData` is
exposed as `StkMetaData` within the python layer
"""
import numpy as np
import stk
from stk import StkMesh, Parallel, StkState, StkSelector, StkRank
par = Parallel.initialize()
print("MPI: rank = %d; size = %d"%(par.rank, par.size))
# Create a STK mesh instance that holds MetaData and BulkData
mesh = StkMesh(par, ndim=3)
mesh.read_mesh_meta_data(
"periodic3d.g",
purpose=stk.DatabasePurpose.READ_MESH,
auto_decomp=True,
auto_decomp_type="rcb")
# Equivalent statement as above
# mesh.read_mesh_meta_data("periodic3d.g")
# At this point the mesh metadata has been read in, but the bulk data hasn't
# been populated yet. The metadata is open for modification, i.e., the user can
# add parts, fields, etc.
# Register fields
pressure = mesh.meta.declare_scalar_field("pressure")
velocity = mesh.meta.declare_vector_field("velocity", number_of_states=3)
# Fields of type other than `double` can be declared with special syntax
iblank = mesh.meta.declare_scalar_field_t[int]("iblank")
# Register the fields on desired parts
pressure.add_to_part(mesh.meta.universal_part,
init_value=np.array([20.0]))
velocity.add_to_part(mesh.meta.universal_part,
mesh.meta.spatial_dimension,
init_value=np.array([10.0, 0.0, 0.0]))
iblank.add_to_part(mesh.meta.universal_part)
# Commit the metadata and load the mesh. Also create edges at this point (default is False)
mesh.populate_bulk_data(create_edges=True)
print("Metadata is committed: ", mesh.meta.is_committed)
# Access the coordinate field
coords = mesh.meta.coordinate_field
print("Coordinates field: ", coords.name)
# Access different field states
velold = velocity.field_state(StkState.StateNM1)
print("velocity NM1 name: ", velold.name)
# Access a part by name
part = mesh.meta.get_part("surface_1")
print("Part exists = ", (not part.is_null))
# Get a stk::mesh::Selector instance for all locally-owned entities of this part
sel = part & mesh.meta.locally_owned_part
# Check if the selector is empty for a particular entity type
print("Surface1 has elems: ", not sel.is_empty(StkRank.ELEM_RANK))
###
### Common looping concepts
###
# Iterating over entities
count = 0
miny = 1.0e6
maxy = -1.0e6
for node in mesh.iter_entities(sel, StkRank.NODE_RANK):
count += 1
xyz = coords.get(node)
miny = min(miny, xyz[1])
maxy = max(maxy, xyz[1])
print("Num. nodes = ", count, "; miny = ", miny, "; maxy = ", maxy)
# Interating and acting over entire buckets
for bkt in mesh.iter_buckets(sel, StkRank.NODE_RANK):
vel = velocity.bkt_view(bkt)
pres = pressure.bkt_view(bkt)
vel[:, -1] = pres[:]
del mesh
par.finalize()
|
pySTK API Reference¶
StkMesh¶
-
class
stk.stk.stk_mesh.
StkMesh
(Parallel comm, int ndim=3)¶ Create a new StkMesh instance
- Parameters
comm – Communicator object
ndim – Dimensionality of the mesh
-
meta
¶ A
StkMetaData
instance
-
bulk
¶ A
StkBulkData
instance
-
stkio
¶ A
StkIoBroker
instance
-
iter_buckets
(self, StkSelector sel, rank_t rank=rank_t.NODE_RANK)¶ Yield iterator for looping over buckets
-
iter_entities
(self, StkSelector sel, rank_t rank=rank_t.NODE_RANK)¶ Yield iterator for looping over entities
-
populate_bulk_data
(self, create_edges=False, auto_load_fields=False)¶ Commit MetaData and populate BulkData from the input database.
If
create_edges is True
, then edge entities will be created before the field data is loaded.if
auto_load_fields is True
then this method will automatically load the fields from the database for the latest time found in the database.
-
read_mesh_meta_data
(self, unicode filename, DatabasePurpose purpose=DatabasePurpose.READ_MESH, bool auto_decomp=True, unicode auto_decomp_type=u'rcb', bool auto_declare_fields=True, TimeMatchOption tmo=TimeMatchOption.CLOSEST)¶ Open a file and load the meta data from the file
This method combines various operations of the
StkIoBroker
for simplicityRegister an input mesh database
Assign bulk data with the STK I/O instance
Creates the metadata from the input mesh
Automatically declares all fields in the database as input fields
- Parameters
filename (str) – Path to the Exodus database
purpose (DatabasePurpose) – READ_MESH, READ_RESTART
auto_decomp (bool) – Decompose mesh for parallel runs (default: True)
auto_decomp_type (str) – Decomposition type (default: rcb)
auto_declare_fields (bool) – If True, declare fields found in file
tmo (TimeMatchOption) – CLOSEST, LINEAR_INTERPOLATION
-
set_auto_join
(self, output=True, restart=True)¶ Turn auto-join on/off for output/restart
- Parameters
output (bool) – If True, auto-join output files
restart (bool) – If True, auto-join restart files
-
set_io_properties
(self, **kwargs)¶ Set IOSS properties for Exodus I/O
One of more key-value pairs
StkMetaData¶
-
class
stk.api.mesh.meta.
StkMetaData
¶ stk::mesh::MetaData
-
commit
(self)¶ Commit the metadata
-
static
create
(int ndim=3)¶ Create a new stk::mesh::MetaData instance
- Parameters
ndim (int) – Spatial dimension of this STK mesh
- Returns
A wrapped instance of stk::mesh::MetaData
- Return type
-
declare_generic_field
(self, unicode name, rank_t rank=topology.rank_t.NODE_RANK, unsigned int number_of_states=1)¶ Declare a double generic field
- Parameters
name (str) – Name of the field
rank (rank_t) –
NODE_RANK
,ELEM_RANK
, etc.number_of_states (int) – Number of states associated with this field
- Returns
The field instance
- Return type
-
declare_part
(self, part_name, rank_t rank=topology.rank_t.NODE_RANK)¶ Declare a new part
If this method is called mutiple times with the same part name, it will return the same part instance.
-
declare_scalar_field
(self, unicode name, rank_t rank=topology.rank_t.NODE_RANK, unsigned int number_of_states=1)¶ Declare a double scalar field
- Parameters
name (str) – Name of the field
rank (rank_t) –
NODE_RANK
,ELEM_RANK
, etc.number_of_states (int) – Number of states associated with this field
- Returns
The field instance
- Return type
-
declare_vector_field
(self, unicode name, rank_t rank=topology.rank_t.NODE_RANK, unsigned int number_of_states=1)¶ Declare a double vector field
- Parameters
name (str) – Name of the field
rank (rank_t) –
NODE_RANK
,ELEM_RANK
, etc.number_of_states (int) – Number of states associated with this field
- Returns
The field instance
- Return type
-
get_field
(self, unicode name, rank_t rank=topology.rank_t.NODE_RANK, must_exist=False)¶ Return a field of name on a requested entity rank
- Parameters
name (str) – Name of the field
rank (rank_t) –
NODE_RANK
,ELEM_RANK
, etc.must_exist (bool) – If True, raise error if the field doesn’t exist
- Returns
The field instance
- Return type
-
get_field_by_name
(self, unicode name, must_exist=False)¶ Return a field by just the name
-
get_part
(self, part_name, must_exist=False)¶ Get a part by name if it exists
- Parameters
part_name (str) – Name of the part
must_exist (bool) – If true, raises AssertionError
- Returns
part instance corresponding to name
- Return type
- Raises
AttributeError – If must_exist is True and part doesn’t exist
-
get_parts
(self, io_parts_only=True)¶ Get all parts registered in STK Mesh
- Parameters
io_parts_only (bool) – If True, filters internal STK parts
- Returns
List of parts
- Return type
[StkPart]
-
initialize
(self, int ndim=3)¶ Initialize the STK mesh
- Parameters
ndim (int) – Spatial dimension
-
aura_part
¶ Aura part
-
coordinate_field
¶ Return the coordinate field
-
coordinate_field_name
¶ Return the name of the coordinates field
-
declare_generic_field_t
¶ Declare a generic field of a given datatype
A generic field is of type
Field<T, SimpleArrayTag>
with rank 1.dudx = meta.declare_generic_field[double]("dudx")
- Parameters
name (str) – Name of the field
rank (rank_t) –
NODE_RANK
,ELEM_RANK
, etc.number_of_states (int) – Number of states associated with this field
- Returns
The field instance
- Return type
-
declare_scalar_field_t
¶ Declare a scalar field of a given type
A scalar field is of type
Field<T>
and has rank 0.density = meta.declare_scalar_field[double]("density") iblank = meta.declare_scalar_field[int]("iblank")
- Parameters
name (str) – Name of the field
rank (rank_t) –
NODE_RANK
,ELEM_RANK
, etc.number_of_states (int) – Number of states associated with this field
- Returns
The field instance
- Return type
-
declare_vector_field_t
¶ Declare a vector field
A vector field is of type
Field<T, Cartesian>
of rank 1.velocity = meta.declare_vector_field[double]("velocity", number_of_states=3)
- Parameters
name (str) – Name of the field
rank (rank_t) –
NODE_RANK
,ELEM_RANK
, etc.number_of_states (int) – Number of states associated with this field
- Returns
The field instance
- Return type
Part containing shared entities with other MPI ranks
-
has_mesh
¶ Does MetaData have a BulkData instance?
-
is_committed
¶ Is the metadata committed?
-
is_initialized
¶ Flag indicating whether the MetaData has been initialized
-
locally_owned_part
¶ Part containing entities owned by the current MPI rank
-
side_rank
¶ Rank for the sidesets
-
spatial_dimension
¶ Spatial dimension of this STK mesh
-
universal_part
¶ Part that contains all entities
-
StkBulkData¶
-
class
stk.api.mesh.bulk.
StkBulkData
¶ stk::mesh::BulkData
-
bucket
(self, StkEntity entity)¶ Get the bucket containing a given entity
-
bucket_ordinal
(self, StkEntity entity)¶ Get the bucket ordinal containing the given entity
-
static
create
(StkMetaData smeta, Parallel par)¶ Create a BulkData instance
- Parameters
smeta (StkMetaData) – MetaData instance to create Bulkdata
par (Parallel) – Parallel communicator object
- Returns
Newly created BulkData
- Return type
-
identifier
(self, StkEntity entity)¶ Return the EntityID for the given entity
-
iter_buckets
(self, StkSelector sel, rank_t rank=rank_t.NODE_RANK)¶ Iterator for looping over STK buckets
- Parameters
sel (StkSelector) – Selector for fetching the desired entities
rank (rank_t) – Entity rank
- Yields
StkBucket – Bucket instances
-
iter_entities
(self, StkSelector sel, rank_t rank=rank_t.NODE_RANK)¶ Iterator for looping over STK buckets
- Parameters
sel (StkSelector) – Selector for fetching the desired entities
rank (rank_t) – Entity rank
- Yields
StkEntity – entities
-
num_edges
(self, StkEntity entity)¶ Return the number of edges for a given entity
-
num_elements
(self, StkEntity entity)¶ Return the number of elements for a given entity
-
num_faces
(self, StkEntity entity)¶ Return the number of faces for a given entity
-
num_nodes
(self, StkEntity entity)¶ Return the number of nodes for a given entity
-
parallel_owner_rank
(self, StkEntity entity)¶ Return the owning MPI rank for the given entity
-
get_max_allowed_id
¶ Maximum allowed entity ID
-
in_modifiable_state
¶ Is BulkData in a modification cycle
-
in_synchronized_state
¶ Is BulkData in a modification cycle
-
is_automatic_aura_on
¶ Flag indicating whether aura is on
-
meta
¶ MetaData associated with this bulk instance
-
parallel
¶ Parallel communicator associated with this instance
-
parallel_rank
¶ Current MPI rank
-
parallel_size
¶ Number of MPI ranks
-
synchronized_count
¶ Synchronization counter
-
StkFieldBase¶
-
class
stk.api.mesh.field.
StkFieldBase
¶ stk::mesh::FieldBase
# Declaring a field (keyword arguments are optional, defaults shown) pressure = meta.declare_scalar_field( "pressure", rank=rank_t.NODE_RANK, number_of_states=1) # Overriding defaults velocity = meta.declare_vector_field("velocity", rank_t.NODE_RANK, 3) # Getting a field (keyword arguments are optional, defaults shown) pressure1 = meta.get_field("pressure", rank=rank_t.NODE_RANK, must_exist=False) ### Accessing field data # # For an entity pres = pressure.get(entity) vel = velocity.get(entity) old = pres[0] pres[0] = 20.0 vel[0] = 10.0 vel[1] = 5.0 vel[2] = 0.0 # For buckets pres_bkt = pressure.bkt_view(bkt) tmp = pres_bkt[-1] pres_bkt[-1] = 20.0 vel_bkt = velocity.bkt_view(bkt) vel_bkt[-1, 2] = 0.0
-
get_t
(entity)¶ Get data from a field that is of a given type.
# Get an int field data int_value = field.get_t[int](entity) # Explictly get double data dbl_val = field.get_t[cython.double](entity)
-
add_to_part
(self, StkPart part, int num_components=1, double[:] init_value=None)¶ Register field to a given part
- Parameters
part (StkPart) – Part instance
num_components (int) – Number of components
init_value (np.ndarray) – Array of initialization values for the field on part
-
add_to_selected
(self, StkSelector sel, int num_components=1, double[:] init_value=None)¶ Register field to parts matching the given selector
- Parameters
sel (StkSelector) – Selector for parts where this field is added
num_components (int) – Number of components
init_value (np.ndarray) – Array of initialization values for the field on part
-
bkt_view
(self, StkBucket bkt)¶ Get the data view for a bucket
For scalar fields, this method returns a 1-D array with
bkt.size
elements. For vector fields, it returns a 2-D array of shape(bkt.size, num_components)
.- Parameters
bkt (StkBucket) – Bucket instance
- Returns
View of the bucket data as a NumPy array
- Return type
np.ndarray
-
bkt_view_int
(self, StkBucket bkt)¶ Get the data view for a bucket
-
field_state
(self, FieldState state)¶ Return the field at state
- Parameters
state (FieldState) – State parameter
- Returns
Field instance corresponding to the state requested
- Return type
-
get
(self, StkEntity entity)¶ Get the data for a given entity
Returns a 1-D numpy array containing 1 element for scalar, 3 for vector and so on. For scalars data types, returning a numpy array of shape
(1,)
allows modification of field data from the python. For example,pressure = pressure_field.get(entity) pressure[0] = 10.0
- Parameters
entity (StkEntity) – Entity instance
- Returns
View of the entity data
- Return type
np.ndarray
-
get_int
(self, StkEntity entity)¶ Get the data for a given entity
-
is_state_valid
(self, FieldState state)¶ Check if the requested state is valid
- Parameters
state (FieldState) – State parameter
- Returns
True if the field has the requested state
- Return type
bool
-
bulk_data
¶ stk::mesh::BulkData
associated with this field
-
entity_rank
¶ Entity rank on which the field is defined
-
field_array_rank
¶ Array dimensionality
-
field_ordinal
¶ Unique ordinal to identify this field
-
is_null
¶ Does the field exist
-
meta_data
¶ stk::mesh::MetaData
associated with this field
-
name
¶ Name of the field
-
number_of_states
¶ Number of states available for this field
-
StkSelector¶
-
class
stk.api.mesh.selector.
StkSelector
¶ stk::mesh::Selector
StkSelector provides the most used features of
stk::mesh::Selector
through its methods.# Get default sideset names for a generated mesh part_names = ("surface_%d"%(i+1) for i in range (6)) parts = [mesh.get_part(pname) for pname in part_names] sel = StkSelector.select_union(parts) & meta.locally_owned_part # Does this selector contain any element entities? print(sel.is_empty(rank_t.ELEM_RANK)) # Does the complement contain element entities? print(sel.complement().is_empty(rank_t.ELEM_RANK))
-
static
and_
(sel1, *args)¶ Get an intersection of selectors
The arguments can either be
Part
orStkSelector
instances.- Returns
Newly created selector instance
- Return type
-
complement
(self)¶ Return !(selector)
-
static
from_part
(StkPart part)¶ Create a selector from part
- Parameters
part (StkPart) – Part instance
- Returns
Newly created selector instance
- Return type
-
is_empty
(self, rank_t rank)¶ Check if the selector contains entities of a given rank
- Parameters
rank (rank_t) – Entity rank
- Returns
True if the selector does not contain entities of the given rank
- Return type
bool
-
static
or_
(sel1, *args)¶ Get a union of selectors
The arguments can either be
Part
orStkSelector
instances.- Returns
Newly created selector instance
- Return type
-
static
select_field
(StkFieldBase field)¶ Create a selector from a field instance
Equivalent to
stk::mesh::selectField
- Parameters
field (StkFieldBase) – Field instance
- Returns
Newly created selector instance
- Return type
-
static
select_intersection
(parts)¶ Create STK selector from intersection of given parts
- Parameters
parts (list) – A list of StkPart instances
- Returns
Python-wrapped STK selector instance
- Return type
-
static
select_union
(parts)¶ Create STK Selector from a list of parts
- Parameters
parts (list) – A list of StkPart instances
- Returns
Python-wrapped STK selector instance
- Return type
-
static
StkPart¶
-
class
stk.api.mesh.part.
StkPart
¶ stk::mesh::Part
# Create a new part and set I/O attribute on that part new_part = meta.declare_part("fluid", rank_t.ELEM_RANK) new_part.set_io_attribute(set_io=True) # Retrive a part from a mesh part = meta.get_part("blade-HEX") # Get selector for a part and locally owned sel_local = part & meta.locally_owned_part # Get selector for all entities in the MPI partition sel_all = part & (meta.locally_owned_part | meta.globally_shared_part)
-
contains
(self, StkPart part)¶ Is the part containined within this part
-
set_io_attribute
(self, set_io=True)¶ Set the I/O attribute for this part.
- Parameters
set_io (bool) – If True add to I/O, else remove from I/O
-
set_toplogy
(self, topology_t topo)¶ Set the topology type for a newly created part
-
is_io_part
¶ Return True if this part is an I/O part
-
is_null
¶ Does the part exist in the MetaData
- Returns
If True,
meta.get_part(...)
returnednullptr
- Return type
bool
-
name
¶ Name of the STK part object
-
part_id
¶ Unique part identifier
For IO part, this number is greater than 0
-
subsets
¶ Subsets of this part
- Returns
List of sub-parts
- Return type
list
-
supersets
¶ Supersets of this part
- Returns
List of super parts
- Return type
list
-
topology
¶ Topology of the STK part object
-
StkBucket¶
-
class
stk.api.mesh.bucket.
StkBucket
¶ stk::mesh::Bucket
-
bucket_id
¶ Bucket identifier
-
entity_rank
¶ Entity rank corresponding to this bucket
-
in_aura
¶ Is this an aura bucket
-
owned
¶ Does this bucket consist of owned entities
Does this bucket contain shared entities
-
size
¶ Number of entities in this bucket
-
topology
¶ Topology of this STK bucket instance
-
StkTopology¶
StkIoBroker¶
-
class
stk.api.io.io.
StkIoBroker
¶ -
add_all_mesh_fields_as_input_fields
(self, TimeMatchOption tmo=TimeMatchOption.CLOSEST)¶ Load all existing fields in mesh database as input fields
- Parameters
tmo (TimeMatchOption) – Option to interpolate for times
-
add_field
(self, size_t fidx, StkFieldBase field, unicode db_field_name=None)¶ Register a field for output to a given database.
The user can provide a different name for the field in the output database by providing db_field_name. If this is None, then the field name is taken from the StkFieldBase instance.
- Parameters
fidx – Valid file handle from create_output_mesh
field – Field instance to be output
db_field_name – Custom name for field in the output database
-
add_input_field
(self, StkFieldBase field)¶ Add an input field
-
add_mesh_database
(self, unicode filename, DatabasePurpose purpose=DatabasePurpose.READ_MESH)¶ Read an existing mesh database
- Parameters
filename (str) – Name of the input database
purpose (DatabasePurpose) – READ_MESH, READ_RESTART etc.
- Returns
File handle associated with the input mesh database
- Return type
size_t
-
add_property
(self, unicode name, unicode value)¶ Add an Ioss::Property to the broker
- Parameters
name (str) – Name of the property
value (str) – Value of the property
-
begin_output_step
(self, size_t fidx, double time)¶ Start a new output ‘time’ instance in database
- Parameters
fidx (size_t) – Valid file handle from create_output_mesh
time (double) – Start a new timestep for output
-
static
create
(Parallel comm)¶ Create a StkIoBroker instance
- Parameters
comm (Parallel) – Communicator instance
- Returns
Newly created instance
- Return type
-
create_input_mesh
(self)¶ Read/Generate metadata for the mesh
This method does not commit metadata.
-
create_output_mesh
(self, unicode filename, DatabasePurpose purpose=DatabasePurpose.WRITE_RESULTS)¶ Create an Exodus database for writing results
- Parameters
filename (str) – Name of the Exodus-II output database
tmo (TimeMatchOption) –
WRITE_RESULTS
,WRITE_RESTART
- Returns
File handle for the newly created output database
- Return type
size_t
-
end_output_step
(self, size_t fidx)¶ Mark end of output for current time
- Parameters
fidx (size_t) – Valid file handle from create_output_mesh
-
flush_output
(self)¶ Flush output to disk
-
get_active_mesh
(self)¶ Get the current active input mesh
- Returns
File handle associated with the active mesh
- Return type
size_t
-
populate_bulk_data
(self)¶ Populate the bulk data for this mesh.
This call is equivalent to calling populate_mesh followed by populate_field_data
-
populate_field_data
(self)¶ Populate field data
This method must be called after
populate_mesh
-
populate_mesh
(self)¶ Populate the mesh data but not fields
-
process_output_request
(self, size_t file_index, double time)¶ Process output request to the database
stkio.begin_output_step(file_index, time) stkio.write_defined_output_fields(file_index) stkio.end_output_step(file_index)
- Parameters
file_index (size_t) – Open file handle
time (double) – Time to write
-
read_defined_input_fields
(self, double time)¶ Read fields for a requested time.
The field depends on TimeMatchOption set for mesh fields
- Returns
The actual time for fields, list of missing fields
- Return type
(double, list)
-
read_defined_input_fields_at_step
(self, int step)¶ Read fields for a given timetep
- Parameters
step (int) – Timestep
- Returns
Time read from database, list of missing fields
- Return type
(double, list)
-
remove_mesh_database
(self, size_t fidx)¶ Remove a previously registered mesh database from list.
This method will close all open files related to that mesh database
- Parameters
fidx (size_t) – File handle associated with the file to close
-
set_active_mesh
(self, size_t fidx)¶ Set the active input mesh
- Parameters
fidx (size_t) – File handle returned by add_mesh_database
-
set_bulk_data
(self, StkBulkData bulk)¶ Associate the BulkData with this I/O broker.
- Parameters
bulk (StkBulkData) – BulkData instance
-
set_max_num_steps_before_overwrite
(self, size_t file_index, int max_num_steps_in_file)¶ Maximum number of steps in database before overwriting
-
write_defined_output_fields
(self, size_t fidx)¶ Write registered fields for a given time
The fields should have been previously added using
add_field()
.- Parameters
fidx (size_t) – Valid file handle from create_output_mesh
- Returns
Current output time step
- Return type
int
-
write_output_mesh
(self, size_t fidx)¶ Write output mesh
- Parameters
fidx (size_t) – File handle to output
-
max_time
¶ Maximum time (double) available in the database
-
num_time_steps
¶ Number of timesteps in this database
-
time_steps
¶ Return the list of timesteps available in this database
-
write_global
¶ Write a global parameter
- Parameters
file_index (size_t) – File handle from a previous call
name (str) – Name of the global data variable
data (double/int) – Value of the global data
-
Parallel¶
-
class
stk.api.util.parallel.
Parallel
¶ Interface to STK MPI
TODO: Enable linking with mpi4py
-
finalize
(self)¶ Call MPI finalize
-
static
initialize
(arg_list=None)¶ Initialize the MPI object
-
parallel_reduce_max
¶ Wrapper to stk::parallel_reduce_max
-
parallel_reduce_min
¶ Wrapper to stk::parallel_reduce_min
-
parallel_reduce_sum
¶ Wrapper to stk::parallel_reduce_sum
-
Field Operations¶
STK field operations¶
This module exposes the BLAS and parallel operations defined on fields by the STK library.
For the BLAS operations, the default functions (matching the STK library) are
implemented by default for double
data type. The templated versions for
other data types are implemented with a _t
suffix. For example,
stk::mesh::field_fill
is exposed as fill
for double
, and a
templated version is exposed for other data types as fill_t
.
-
stk.api.mesh.field_ops.
axpy
(double alpha, StkFieldBase xfield, StkFieldBase yfield, StkSelector sel=None)¶ y = alpha * x + y
- Parameters
alpha (double) – Constant coefficient
xfield (StkFieldBase) – Source field
yfield (StkFieldBase) – Destination field
sel (StkSelector) – A selector to restrict where the BLAS operation is carried out
-
stk.api.mesh.field_ops.
communicate_field_data
(StkGhosting ghosting, list fields)¶ Communicate field data for a given ghosting
-
stk.api.mesh.field_ops.
copy
(StkFieldBase xfield, StkFieldBase yfield, StkSelector sel=None)¶ yfield = xfield
- Parameters
xfield (StkFieldBase) – Source field
yfield (StkFieldBase) – Destination field
sel (StkSelector) – Restrict copy to only entities belonging to selector
Copy data from owned entities to the shared entities
- Parameters
bulk (StkBulkData) – BulkData instance
fields (list) – A list of StkFieldBase instances
-
stk.api.mesh.field_ops.
fill
(double alpha, StkFieldBase field, StkSelector sel=None)¶ field[:] = alpha
- Parameters
alpha (double) – Constant coefficient
field (StkFieldBase) – Field to be updated
sel (StkSelector) – A selector to restrict where the BLAS operation is carried out
-
stk.api.mesh.field_ops.
fill_component
(double[:] alpha, StkFieldBase field, StkSelector sel=None)¶ field[:] = alpha[:]
- Parameters
alpha (double) – Component values
field (StkFieldBase) – Field to be updated
sel (StkSelector) – A selector to restrict where the BLAS operation is carried out
-
stk.api.mesh.field_ops.
parallel_max
(StkBulkData bulk, list fields)¶ Parallel max
- Parameters
bulk (StkBulkData) – BulkData instance
fields (list) – A list of StkFieldBase instances
-
stk.api.mesh.field_ops.
parallel_max_including_ghosts
(StkBulkData bulk, list fields)¶ Parallel max
-
stk.api.mesh.field_ops.
parallel_min
(StkBulkData bulk, list fields)¶ Parallel min
- Parameters
bulk (StkBulkData) – BulkData instance
fields (list) – A list of StkFieldBase instances
-
stk.api.mesh.field_ops.
parallel_min_including_ghosts
(StkBulkData bulk, list fields)¶ Parallel min
-
stk.api.mesh.field_ops.
parallel_sum
(StkBulkData bulk, list fields)¶ Parallel sum across all shared entities for a given list of fields
- Parameters
bulk (StkBulkData) – BulkData instance
fields (list) – A list of StkFieldBase instances
-
stk.api.mesh.field_ops.
parallel_sum_including_ghosts
(StkBulkData bulk, list fields)¶ Parallel sum
-
stk.api.mesh.field_ops.
swap
(StkFieldBase xfield, StkFieldBase yfield, StkSelector sel=None)¶ Swap the contents of x and y fields
- Parameters
xfield (StkFieldBase) – Field for swapping
yfield (StkFieldBase) – Field for swapping
sel (StkSelector) – Restrict swap to only entities belonging to selector
-
stk.api.mesh.field_ops.
axpy_t
¶ y = alpha * x + y
-
stk.api.mesh.field_ops.
fill_component_t
¶ ] = alpha
- Type
field[
-
stk.api.mesh.field_ops.
fill_t
¶ ] = alpha
- Type
field[
Enumerated data types¶
-
class
stk.api.topology.topology.
rank_t
(value)¶ An enumeration.
-
CONSTRAINT_RANK
= 4¶
-
EDGE_RANK
= 1¶
-
ELEM_RANK
= 3¶
-
FACE_RANK
= 2¶
-
INVALID_RANK
= 256¶
-
NODE_RANK
= 0¶
-
-
class
stk.api.mesh.field.
FieldState
(value)¶ An enumeration.
-
StateInvalid
= 6¶
-
StateN
= 1¶
-
StateNM1
= 2¶
-
StateNM2
= 3¶
-
StateNM3
= 4¶
-
StateNM4
= 5¶
-
StateNP1
= 0¶
-
StateNew
= 0¶
-
StateNone
= 0¶
-
StateOld
= 1¶
-
-
class
stk.api.io.io.
DatabasePurpose
(value)¶ An enumeration.
-
APPEND_RESULTS
= 16¶
-
PURPOSE_UNKNOWN
= 0¶
-
READ_MESH
= 4¶
-
READ_RESTART
= 8¶
-
WRITE_RESTART
= 2¶
-
WRITE_RESULTS
= 1¶
-
-
class
stk.api.io.io.
TimeMatchOption
(value)¶ An enumeration.
-
CLOSEST
= 1¶
-
LINEAR_INTERPOLATION
= 0¶
-
SPECIFIED
= 2¶
-
-
class
stk.api.topology.topology.
topology_t
(value)¶ An enumeration.
-
BEAM_2
= 13¶
-
BEAM_3
= 14¶
-
BEGIN_TOPOLOGY
= 1¶
-
END_TOPOLOGY
= 44¶
-
HEX_20
= 42¶
-
HEX_27
= 43¶
-
HEX_8
= 41¶
-
INVALID_TOPOLOGY
= 0¶
-
LINE_2
= 2¶
-
LINE_2_1D
= 11¶
-
LINE_3
= 3¶
-
LINE_3_1D
= 12¶
-
NODE
= 1¶
-
PARTICLE
= 10¶
-
PYRAMID_13
= 36¶
-
PYRAMID_14
= 37¶
-
PYRAMID_5
= 35¶
-
QUAD_4
= 7¶
-
QUAD_4_2D
= 22¶
-
QUAD_8
= 8¶
-
QUAD_8_2D
= 23¶
-
QUAD_9
= 9¶
-
QUAD_9_2D
= 24¶
-
SHELL_LINE_2
= 15¶
-
SHELL_LINE_3
= 16¶
-
SHELL_QUAD_4
= 28¶
-
SHELL_QUAD_8
= 29¶
-
SHELL_QUAD_9
= 30¶
-
SHELL_TRI_3
= 25¶
-
SHELL_TRI_4
= 26¶
-
SHELL_TRI_6
= 27¶
-
SPRING_2
= 17¶
-
SPRING_3
= 18¶
-
TET_10
= 33¶
-
TET_11
= 34¶
-
TET_4
= 31¶
-
TET_8
= 32¶
-
TRI_3
= 4¶
-
TRI_3_2D
= 19¶
-
TRI_4
= 5¶
-
TRI_4_2D
= 20¶
-
TRI_6
= 6¶
-
TRI_6_2D
= 21¶
-
WEDGE_15
= 39¶
-
WEDGE_18
= 40¶
-
WEDGE_6
= 38¶
-