beam_networks package#
Submodules#
beam_networks.assembly module#
- beam_networks.assembly.assemble_global_system(nodes_positions, edges_indices, dr, beam_prop, sorted_edges=True, vectorize=True, matrix='bsr', verbose=False)#
Assembly of the global stiffness matrix for a Timoshenko beam network (wrapper)
- Parameters:
nodes_positions (np.ndarray) – Nodal coordinates
edges_indices (np.ndarray (of ints)) – Edge connectivity
dr (np.ndarray) – Edge vectors
beam_prop (dict) – Beam properties (cross section and elastic properties)
sorted_edges (bool, optional) – Edge indices are sorted (the default is True)
vectorize (bool, optional) – Collect all element stiffness matrices in a large array before assembly. Faster, but may cause memory issues for very large systems (the default is True).
matrix (str, optional) – Format of the global stiffness matrix during assembly. Choose from [‘bsr’, ‘lil’, ‘dense’]. ‘bsr’ : Block sparse row matrix (Default) ‘lil’ : List of lists ‘dense’: Only for small matrices
verbose (bool, optional) – Verbosity (the default is False which hides the progress bar)
- Returns:
The global matrix
- Return type:
np.ndarray or scipy.sparse.bsr_array
beam_networks.bc module#
beam_networks.fracture module#
- class beam_networks.fracture.FractureProblem(*args, save_trajectory=False, no_output=False, **kwargs)#
Bases:
BeamNetwork- failure_criterion(name='vM')#
- property removed_edges#
List of inactive edges.
- Returns:
Inactive edges indices
- Return type:
list
- run(mode='cascade', sign=-1, dist=None, fail_crit='vM', no_output=False)#
- write()#
Wrapper for different output writers. Currently only calls HDF5 output.
beam_networks.geo module#
- beam_networks.geo.get_geometric_props(beam_prop)#
Get geometric properties of the beam cross section.
- Parameters:
beam_prop (dict) – Beam properties (cross section and elastic properties)
- Returns:
float – Second moment of area Iy
float – Second moment of area Iz
float – Second polar moment of area Ip
float – Area
float – Shear correction factor
float – Maximum distance from beam neutral axis to the surface
- beam_networks.geo.get_geometric_props_derivative(beam_prop, derivative)#
Get derivative of geometric properties of the beam cross section with respect to radius
- Parameters:
beam_prop (dict) – Beam properties (cross section and elastic properties)
derivative (bool) – if not None returns the derivative with respect to a shape parameter. The shape parameter is determined by the value of derivative which depends on the shape of your beam.
- Returns:
float – Derivative of second moment of area Iy
float – Derivative of second moment of area Iz
float – Derivative of second polar moment of area Ip
float – Derivative of area
float – Derivative of shear correction factor
float – Derivative of maximum distance from beam neutral axis to the surface
beam_networks.io module#
beam_networks.network module#
- class beam_networks.network.Network(nodes_positions, edges_indices, periodic=None, boxsize=None, valid=True)#
Bases:
objectBase class for network structure.
Contains methods to generate lattice structures and some basic properties of the network.
- property Lx#
Boxlength (x)
- Return type:
float
- property Ly#
Boxlength (y)
- Return type:
float
- property Lz#
Boxlength (z)
- Return type:
float
- property bondlengths#
- property bounds#
Lower and upper bounds of the nodal coordinates
- Returns:
xlo, xhi, ylo, yhi[, zlo, zhi]
- Return type:
list
- property boxsize#
- property coordination#
Mean coordination number.
- Return type:
float
- property edge_vectors#
- property edges#
Exposes only active edges.
- Return type:
np.ndarray
- classmethod generate_bowtie_lattice(a=1.0, w=0.1, bbox=[1.0, 1.0])#
Generates a bowtie lattice.
- Parameters:
a (float, optional) – Lattice constant (distance between nearest neighbors)
bbox (array-like) – Size of the bounding box, filled with repeated unit cells (the default is [1., 1., 1.])
- Returns:
Class instance with nodes and edges given by the prescribed lattice
- Return type:
- classmethod generate_cubic_lattice(a=1.0, pbc=None, bbox=[1.0, 1.0, 1.0], lattice_type='sc')#
Generates a cubic lattice.
- Parameters:
a (float, optional) – Lattice constant (distance between nearest neighbors)
pbc (iterable, optional) – Periodic boundary conditions (the default is None, which means no periodic BCs).
bbox (array-like) – Size of the bounding box, filled with repeated unit cells (the default is [1., 1., 1.])
lattice_type (str, optional) – Name of the lattice type [‘sc’, ‘bcc’, ‘fcc’] (the default is ‘sc’)
- Returns:
Class instance with nodes and edges given by the prescribed lattice
- Return type:
- classmethod generate_square_lattice(a=1.0, bbox=[1.0, 1.0], lattice_type='sc')#
Generates a cubic lattice.
- Parameters:
a (float, optional) – Lattice constant (distance between nearest neighbors)
bbox (array-like) – Size of the bounding box, filled with repeated unit cells (the default is [1., 1., 1.])
lattice_type (str, optional) – Name of the lattice type [‘sc’, ‘bcc’, ‘fcc’] (the default is ‘sc’)
- Returns:
Class instance with nodes and edges given by the prescribed lattice
- Return type:
- property is_connected#
Check if structure is fully connected
- Return type:
bool
- property nodes#
Exposes only activated nodes.
- Return type:
np.ndarray
- property num_edges#
Number of active edges
- Return type:
int
- property num_nodes#
Number of active nodes
- Return type:
int
- property pbc_edges#
Mask for edges that cross periodic boundary conditions.
- Return type:
np.ndarray
- property pbc_nodes#
Nodal positions for edges that cross periodic boundary conditions. Nodes are shifted to the neighboring periodic images for visualization purposes.
- Returns:
Nodal coordinates
- Return type:
np.ndarray
- property volume#
Compute volume of network as convex hull.
- Return type:
float
- property xhi#
- property xlo#
- property yhi#
- property ylo#
- property zhi#
- property zlo#
beam_networks.problem module#
- class beam_networks.problem.BeamNetwork(nodes, edges, beam_prop={'E': 1.0, 'name': 'circle', 'nu': 0.3, 'radius': 1.0}, periodic=None, boxsize=None, valid=True, options={'matrix': 'bsr', 'vectorize': True, 'verbose': True}, outdir='.', assemble_on_init=True)#
Bases:
NetworkBeam Network structure. Derives from Network.
Adding a cross section and elastic properties to the edges of a network makes it a beam network. Solves the elastic problem given appropriate boundary conditions.
- add_BC(name, type, select, selection, vector, active=True, num_per_point=1)#
Add boundary condition.
- Parameters:
name (str) – Name/Identifier of the BC
type (str) – BC type, either ‘D’ for Dirichlet or ‘N’ for Neumann
select (str) – How to select nodes, either ‘box’, ‘node’, or ‘point’
selection (array-like) – For box selection: lower and upper limits of bounding box in relative units, i.e. [xlo, xhi, ylo, yhi[, zlo, zhi]]. None entries cooresponds to the min/max limits, e.g. [None, None, 0.5, None, None, None] means upper half of the domain in the y-direction. For node selection: list of nodes.
vector (array-like) – Vector of length 3 and 6 for 2D and 3D systems, respectively. None means the corresponding DOF is not affected. In 2D: [ux, uy, tz] (Dircihlet) or [Fx, Fy, Mz] (Neumann) In 3D: [ux, uy, uz, tx, ty, tz] (Dircihlet) or [Fx, Fy, Fz, Mx, My, Mz] (Neumann)
num_per_point (int) – For point selection only, maximum number of closest nodes to select. The default is 1.
- assemble_BCs()#
- compute_equivalent_stress(mode='mean')#
Calculate von Mises stress and store it in self._sVM.
- Parameters:
mode (str) – Either ‘max’ or ‘mean’, i.e. calculate maximum or mean stress per beam
- Return type:
None
- compute_principal_stresses(mode='max')#
- compute_ratio()#
- delete_BC(name)#
Delete boundary condition.
- Parameters:
name (str) – Name of the BC to be removed
- property displaced_edge_vectors#
- property displaced_nodes#
- property displacement#
Nodal displacements
- Returns:
Shape (num_nodes, dim)
- Return type:
numpy.ndarray
- property dof_per_node#
- property has_bc#
- property has_stiffness#
- classmethod load(filename, recompute=True)#
Create a class instance from a tar archive.
- Parameters:
filename (str) – Name of the archive
- Returns:
A new class instance
- Return type:
- modify_BC(name, vector)#
Modify an existing BC by changing its vector. This does not change the constraint DOFs, i.e. vector needs to have ‘None’ in the same place as before. Useful for stepwise change of a load/displacement
- Parameters:
name (str) – Name of the BC to be removed
vector (array-like) – Vector of length 3 and 6 for 2D and 3D systems, respectively. None means the corresponding DOF is not affected. In 2D: [ux, uy, tz] (Dircihlet) or [Fx, Fy, Mz] (Neumann) In 3D: [ux, uy, uz, tx, ty, tz] (Dircihlet) or [Fx, Fy, Fz, Mx, My, Mz] (Neumann)
- property num_dof#
- plot(ax, node_ids=False, contour=None, cax=None, aspect=1.0, lim=None, lw=2.0, scale=1.0)#
Generate 2D plot of the deformed network structure.
- Parameters:
ax (matplotlib.pyplot.axis object) – Axis to plot into
node_ids (bool, optional) – Print node numbers nect to undeformed structure (the default is False)
contour (numpy.ndarray, optional) – Scalar field to plot as color on edges (the default is None, which means no coloring)
cax (matplotlib.pyplot.axis object or None, optional) – Axis to plot colorbar into if contour is not None (the default is None, which takes space from ax)
aspect (float, optional) – Aspect ratio (the default is 1.)
lim (tuple, optional) – Colorbar limits (the default is None, which takes the limits of contour)
- Returns:
The plotted axis
- Return type:
matplotlib.pyplot.axis object
- property rotation#
Nodal rotations
- Returns:
Shape (num_nodes, 3) for 3D; (num_nodes, 1) for 2D
- Return type:
numpy.ndarray
- save(filename)#
Save the current state of the solver as gzipped tar archive
- Parameters:
filename (str) – Name of the archive
- scale_BC(type, factor)#
Scale all BCs of a certain type by a given factor
- Parameters:
type (str) – BC type (either ‘D’ or ‘N’)
factor (float) – factor
- scale_solution(scale_factor)#
- solve(solver=None, stress_mode='mean', preconditioner=None, verbosity=0)#
Solve the linear system.
Stores the solution for all DOFs and computes the reaction forces at constraint DOFs
- Parameters:
solver (str, optional) – Type of solver to use, currently ‘direct’ and ‘cg’ available (the default is ‘direct’)
stress_mode (str) – Either ‘max’ or ‘mean’, i.e. calculate maximum or mean von Mises stress per beam
preconditioner (str, optional) – Type of preconditioner, ‘diagonal’ or None (the default is None)
verbosity (int, optional) – level of verbosity, if between 25/50 print information about displacements and reaction forces, if between 50/100 print information about stiffness matrix, if greater equal 100 print condition number (default is 0). Only active for sparse matrices.
- Raises:
RuntimeError – System can only be solved if boundary conditions are given.
- property stiffness#
Global stiffness matrix
- Return type:
numpy.ndarray or scipy.sparse.csr_array
- to_stl(file, clean=False, tol=1e-06)#
- to_vtk(file='foo.vtk')#
Write structure and possibly solution to VTK file
- Parameters:
file (str, optional) – Output filename (the default is “foo.vtk”)
beam_networks.solve module#
- beam_networks.solve.solve(K, bc_D, d_D, bc_N, F_N, solver='direct', preconditioner=None, verbosity=0)#
Solve the linear system.
- Parameters:
K (np.ndarry or scipy.sparse.csr_matrix) – Stiffness matrix
bc_D (iterable) – List of constraint DOFs (Dirichlet BCs)
d_D (iterable) – List of constraint DOF values (Dirichlet BCs)
bc_N (iterable) – List of DOFs with nonzero loads (Neumann BCs)
F_N (iterable) – List of DOF values with nonzero loads (Neumann BCs)
solver (str, optional) – Type of solver, ‘direct’ or ‘cg’ (the default is ‘direct’)
preconditioner (str, optional) – Type of preconditioner, ‘diagonal’ or None (the default is None). Only active for sparse matrices.
verbosity (int, optional) – level of verbosity, if between 25/50 print information about displacements and reaction forces, if between 50/100 print information about stiffness matrix, if greater equal 100 print condition number (default is 0). Only active for sparse matrices.
- Returns:
d (np.ndarray) – Global solution vector
F (np.ndarray) – Global load vector
info (int) – Info about numerical solution, 0 if successful
beam_networks.stiffness module#
- beam_networks.stiffness.get_element_stiffness_global(beam_prop, d, derivative=None)#
Single element stiffness matrix in global frame.
- Parameters:
beam_prop (dict) – Beam properties (cross section and elastic constants)
d (np.ndarray) – Vector pointing from one beam endpoint to the other
sparse (bool, optional) – Return as sparse matrix if true (the default is True)
derivative (None or int) – if not None returns the derivative with respect to a shape parameter. The shape parameter is determined by the value of derivative which depends on the shape of your beam.
- Returns:
Element stiffness matrix in global frame
- Return type:
np.ndarray or
- beam_networks.stiffness.get_element_stiffness_global_vec(beam_prop, d_vec, derivative=None)#
Get all element stiffness matrices in the global frame.
- Parameters:
beam_prop (dict) – Beam properties (cross section and elastic constants)
d (np.ndarray) – Vectors pointing from one beam endpoint to the other
derivative (None or int) – if not None returns the derivative with respect to a shape parameter. The shape parameter is determined by the value of derivative which depends on the shape of your beam.
- Returns:
Array with shape (num_elements, num_elem_dof, num_elem_dof)
- Return type:
np.ndarray
- beam_networks.stiffness.get_element_stiffness_local_vec(beam_prop, d, ndim, derivative=None)#
Get all element stiffness matrices in the local frame (w.o. transformation)
- Parameters:
beam_prop (dict) – Beam properties (cross section and elastic constants)
d (np.ndarray) – Edge lengths
ndim (int) – Dimension of the problem
derivative (None or int) – if not None returns the derivative with respect to a shape parameter. The shape parameter is determined by the value of derivative which depends on the shape of your beam.
- Returns:
Array with shape (num_elements, num_elem_dof, num_elem_dof)
- Return type:
np.ndarray
beam_networks.stress module#
- beam_networks.stress.get_element_mises_stress(coords, adj, d_vec, sol, beam_prop, rot=None, mode='max', return_ratio=False)#
Compute the von Mises stress for all beam elements
- Parameters:
coords (np.ndarray) – Nodal positions
adj (np.ndarray) – Edges indices
d_vec (np.ndarray) – Edge vectors
sol (np.ndarray) – Global solution vector
beam_prop (dict) – Beam properties
rot (np.ndarray or None, optional) – If all elements have the same orientation, rot is the transformation matrix from the global to the local frame (the default is None).
mode (str, optional) – Either ‘max’ or ‘mean’, i.e. calculate maximum or mean stress per beam (the default is ‘max’).
- Returns:
Von Mises stress
- Return type:
np.ndarray
- beam_networks.stress.get_element_principal_stress(coords, adj, d_vec, sol, beam_prop, rot=None, mode='max')#
- Parameters:
coords (np.ndarray) – Nodal positions
adj (np.ndarray) – Edges indices
d_vec (np.ndarray) – Edge vectors
sol (np.ndarray) – Global solution vector
beam_prop (dict) – Beam properties
rot (np.ndarray or None, optional) – If all elements have the same orientation, rot is the transformation matrix from the global to the local frame (the default is None).
mode (str, optional) – Either ‘max’ or ‘mean’, i.e. calculate maximum or mean stress per beam (the default is ‘max’).
- Return type:
np.ndarray
- beam_networks.stress.principal_stress(rhs, beam_prop, mode)#
Compute element-wise principal stress.
Principal stress values are sorted in decreasing order along the second axis.
- Parameters:
rhs (np.ndarray) – Element-wise right-hand side in local frame
beam_prop (dict) – Beam properties
mode (str) – Either ‘max’ or ‘mean’, i.e. calculate maximum or mean stress per beam
- Returns:
Principal stresses per beam (shape: (n_beams, 3))
- Return type:
np.ndarry
- beam_networks.stress.stretch_bend_ratio(rhs, beam_prop)#
- beam_networks.stress.vmises_stress(rhs, beam_prop, mode)#
Wrapper for von Mises stress calculation
- Parameters:
rhs (np.ndarray) – Element-wise right-hand side in local frame
beam_prop (dict) – Beam properties
mode (str) – Either ‘max’ or ‘mean’, i.e. calculate maximum or mean stress per beam
- Returns:
Von Mises stress, shape=(num_elements,)
- Return type:
np.ndarray
beam_networks.tesselate module#
- beam_networks.tesselate.renumber_adjacency(adj, indices_delete)#
Renumber the indices by adjusting the counting for deleted nodes.
- Parameters:
adj (np.array) – adjacency matrix.
indices_delete (np.array) – indices to be deleted.
- Returns:
adj – updated adjacency.
- Return type:
np.array
- beam_networks.tesselate.sanity_checks(coords, adj, cell, overlap=True, overlap_tol=1e-05, connected=True, duplicate_bonds=True)#
Check a given network of nodes for consistency.
- Parameters:
coords (np.ndarray) – coordinates of shape (n_nodes,ndim).
adj (np.ndarray) – adjacency list of shape (n_bonds,2).
cell (None or np.ndarray, optional) – cell lengths of shape (ndim). If None infer from coordinates (max-min).
overlap (bool, optional) – check for overlapping nodes via cKDTree.
overlap_tol (float, optional) – tolerance for detecting overlaps.
connected (bool, optional) – check whether all nodes are connected.
duplicate_bonds (bool, optional) – check for duplicate bonds.
- Raises:
AssertionError – if any discrepancies (overlapping nodes, disconnected network, duplicate bonds) detected.
- beam_networks.tesselate.tesselate(coords, adj, rep, cell=None, pbc=False, overlap_tol=1e-08, debug=False)#
Repeat unit cell in each direction. Currently implemented by copying coordinates and adjacency cell repeatedly and then detecting overlapping nodes via a cKDTree. The overlapping nodes are reduced to one node which overtakes all the connections from the overlapping nodes. Then the overlapping nodes are deleted and the adjacency matrix renumbered to account for deleted nodes.
- Parameters:
coords (np.ndarray) – coordinates of shape (n_nodes,ndim).
adj (np.ndarray) – adjacency list of shape (n_bonds,2).
rep (list or np.ndarray) – number of repetitions in each direction
cell (None or np.ndarray, optional) – cell lengths of shape (ndim). If None infer from coordinates (max-min).
pbc (bool or list, optional) – Collect all element stiffness matrices in a large array before assembly. Faster, but may cause memory issues for very large systems (the default is True).
overlap_tol (float, optional) – tolerance for detecting overlaps.
debug (bool, optional) – print out information for debugging.
- Returns:
coords (np.ndarray) – coordinates of shape (n_nodes_tesselate,ndim).
adj (np.ndarray) – adjacency list of shape (n_bonds_tesselate,2).
cell (np.ndarray) – cell lengths of shape (ndim).
beam_networks.utils module#
- beam_networks.utils.box_selection(nodes, lim)#
Select nodes which are within a cuboid.
- Parameters:
nodes (np.ndarray) – Nodal coordinates
lim (iterable) – Lower and upper bounds of the cuboid
- Returns:
Masking array for nodes
- Return type:
np.ndarray
- beam_networks.utils.check_input_dict(container, keys, defaults, allowed)#
Sanitize output settings
- Parameters:
options (dict) – Output settings
- Returns:
Sanitized output settings
- Return type:
dict
- beam_networks.utils.get_edges_from_disks(file, cutoff=3.0, atol=1e-05)#
Get adjacency matrix from a collextion of hard disks in 2D
The input file has the format:
L n_1, x_1, y_1, r_1 n_2, x_2, y_2, r_2 … n_n, x_n, y_n, r_n
where n_* denotes the disk index (1 based, will be shifted to zero), x_*, y_* are the coordinates, and r_* the radius of the disk
- Parameters:
file (str) – Filename
cutoff (float, optional) – Distance cutoff to check for possible neighbors (the default is 3.)
atol (float, optional) – Absoulte tolerance for comparison between distance and composite radius of possibly neighboring disks (the default is 1e-5)
- Returns:
np.ndarray – Nodes
np.ndarray – Edges
float – Lx
float – Ly
- beam_networks.utils.point_selection(nodes, point, num=1)#
Select nodes which are closest to a given point.
- Parameters:
nodes (np.ndarray) – Nodal coordinates
point (array-like) – Coordinates of the point
num (int) – Number of points. The default is 1.
- Returns:
Masking array for nodes
- Return type:
np.ndarray
- beam_networks.utils.zero_pad_2d_array(arr)#
beam_networks.viz module#
- beam_networks.viz.plot_solution_1D(ax, d, s, length=1.0)#
Plot a 1D solution along a 1D beam (composed of more than one element)
- Parameters:
ax (matplotlib.pyplot.axis object) – Axis to plot into
d (np.ndarray) – Solution (ux[0], uy[0], theta_z[0], …)
s (np.ndarray) – Von Mises stress per element
length (float, optional) – Length of the beam (the default is 1.)
- beam_networks.viz.vtk2img(wdir=None, dpi=300, cbar_global_lim=False, ftype='png')#