pymoto.AssembleGeneral
- class pymoto.AssembleGeneral(domain: ~pymoto.common.domain.VoxelDomain, element_matrix: ~numpy.ndarray | ~typing.Iterable[~numpy.ndarray], bc=None, bcdiagval=None, matrix_type: type = <class 'scipy.sparse._csr.csr_matrix'>, add_constant=None, reuse_sparsity: bool = True)
Assembles a sparse matrix according to element scaling \(\mathbf{A} = \sum_e x_e \mathbf{A}_e\)
Each element matrix is scaled and with the scaling parameter of that element \(\mathbf{A} = \sum_e \sum_i x_{i,e} \mathbf{A}_{i,e}\). The number of degrees of freedom per node is deduced from the size of the element matrix passed into the module. For instance, in case an element matrix of shape
(3*4, 2*4)gets passed with a 2DVoxelDomain, the number of dofs per node equals3in the row-direction and2in the column direction.Non-square matrices and complex values are supported. Dirichlet boundary conditions are possible to set, which are implemented by setting the entire row and column of the constrained dof to zero, and placing a finite value on the diagonal (optionally).
- Input Signal:
*x: Scaling vector(s) of size(Nel)
- Output Signal:
A: System matrix of size(m, n)
- __init__(domain: ~pymoto.common.domain.VoxelDomain, element_matrix: ~numpy.ndarray | ~typing.Iterable[~numpy.ndarray], bc=None, bcdiagval=None, matrix_type: type = <class 'scipy.sparse._csr.csr_matrix'>, add_constant=None, reuse_sparsity: bool = True)
Initialize assembly module
- Parameters:
domain (
pymoto.VoxelDomain) – The domain for which should be assembledelement_matrix (np.ndarray or List of np.ndarray) – The element matrix \(\mathbf{K}_e\) of size (#dofs_per_element, #dofs_per_element). Multiple element matrices can also be provied
bc (optional) – Indices of any dofs that are constrained to zero (Dirichlet boundary condition). These boundary conditions are enforced by setting the row and column of that dof to zero.
bcdiagval (optional) – Value to put on the diagonal of the matrix at dofs where boundary conditions are active. Default is maximum value of the element matrix.
matrix_type (optional) – The matrix type to construct. This is a constructor which must accept the arguments matrix_type((vals, (row_idx, col_idx)), shape=(n, n)). Defaults to scipy.sparse.csc_matrix.
add_constant (optional) – A constant (e.g. sparse matrix) to add. This is added after setting Dirichlet boundary conditions.
reuse_sparsity (bool, optional) – Reuse the sparsity pattern of the sparse matrix. This improves performance during iterations at the cost of a longer setup time.
Methods
__init__(domain, element_matrix[, bc, ...])Initialize assembly module
connect(sig_in[, sig_out])Connect without automatic adding to a function network
get_input_sensitivities([as_list])get_input_states([as_list])get_output_sensitivities([as_list])get_output_states([as_list])reset()Reset the state of the sensitivities (they are set to zero or to None)
response()Calculate the response from sig_in and output this to sig_out
Calculate sensitivities using backpropagation
Attributes
Get the number of input signals
Get the number of output signals
- connect(sig_in: Signal | Iterable[Signal], sig_out: Signal | Iterable[Signal] = None)
Connect without automatic adding to a function network
- get_input_sensitivities(as_list=False)
- get_input_states(as_list=False)
- get_output_sensitivities(as_list=False)
- get_output_states(as_list=False)
- property n_in: int
Get the number of input signals
- property n_out: int
Get the number of output signals
Note: Cannot be used in the initial __call__()
- reset()
Reset the state of the sensitivities (they are set to zero or to None)
- response()
Calculate the response from sig_in and output this to sig_out
- sensitivity()
Calculate sensitivities using backpropagation
Based on the sensitivity we get from sig_out, reverse the process and output the new sensitivities to sig_in
- sig_in: List = None
- sig_out: List = None