transiflow.interface.PETSc
- class Interface(parameters, nx, ny, nz=1, dim=None, dof=None, boundary_conditions=None, comm=<MagicMock name='mock.PETSc.COMM_WORLD' id='140493778385760'>)
Bases:
ParallelBaseInterfaceThis class defines an interface to the PETSc backend for the discretization. This backend can be used for testing low-resolution parallel runs as well as a base for a class that implements a better linear solver. It should not be used for any meaningful simulations.
The PETSc backend partitions the domain into Cartesian subdomains. The subdomains will be distributed over multiple processors if MPI is used to run the application.
PETSc parallel vectors (and matrices) are distributed such that each process owns a contiguous range of indices (rows) without holes. The natural ordering is therefore mapped to PETSc’s ordering.
See
Discretizationfor the descriptions of the constructor arguments.- Parameters:
- parametersdict
Key-value pairs that can be used to modify parameters in the discretization as well as the linear solver and eigenvalue solver.
- array_from_vector(vector)
Create a numpy array suitable for postprocessing from a state vector.
- eigs(state, return_eigenvectors=False, enable_recycling=False)
Compute the generalized eigenvalues of $\beta * J(u, p) * v = \alpha * M(p) * v$.
- Parameters:
- statearray_like
State $u$ at which to evaluate $J(u, p)$.
- return_eigenvectorsbool, optional
Whether to return the eigenvectors $v$.
- enable_recyclingbool, optional
Whether to use the previous eigenvalue space as initial search space.
- Returns:
- eigsarray_like
Eigenvalues $\alpha / \beta$.
- varray_like
Corresponding eigenvectors in case
return_eigenvectorsisTrue.
- get_comm_rank()
Get the rank of the current processor.
- get_comm_size()
Get the total number of processors.
- get_parameter(name)
Get a parameter value from the discretization.
- Parameters:
- namestr
Name of the parameter in the parameter list.
- jacobian(state)
Compute the Jacobian matrix $J(u, p)$ of the right-hand side of the DAE. That is the Jacobian matrix of $F(u, p)$ in
\[M(p) \frac{\d u}{\d t} = F(u, p)\]The Jacobian matrix is computed on the overlapping subdomain map and then distributed using the non-overlapping map that is used by the linear solver.
- Parameters:
- statearray_like
State $u$ at which to evaluate $J(u, p)$.
- Returns:
- jacPETSc.Mat
The matrix $J(u, p)$ in a CSR matrix format that allows for distributing the overlap.
- load_json(name)
Load the an object from a json file.
- Parameters:
- namestr
Name of the file without extension.
- load_parameters(name)
Load the parameter set from a file.
- Parameters:
- namestr
Name of the file without extension.
- load_state(name)
Load the state
xalong with the current parameter set.- Parameters:
- namestr
Name of the file.
- mass_matrix()
Compute the mass matrix of the DAE. That is the mass matrix $M(p)$ in
\[M(p) \frac{\d u}{\d t} = F(u, p)\]- Returns:
- massMatrix
The matrix $M(p)$ in a suitable sparse format
- rhs(state)
Compute the right-hand side of the DAE. That is the right-hand side $F(u, p)$ in
\[M(p) \frac{\d u}{\d t} = F(u, p)\]The RHS is computed on the overlapping subdomain map and then distributed using the non-overlapping map that is used by the linear solver.
- Parameters:
- statearray_like
State $u$ at which to evaluate $F(u, p)$.
- Returns:
- rhsarray_like
The value of $F(u, p)$.
- save_json(name, obj)
Save an object to a json file
- Parameters:
- namestr
Name of the file.
- objAny
Serializable object to save to the file.
- save_parameters(name)
Save the current parameter set to a file.
- Parameters:
- namestr
Name of the file without extension.
- save_state(name, x)
Save the state
xalong with the current parameter set.- Parameters:
- namestr
Name of the file.
- xarray_like
State at the current parameter values.
- set_parameter(name, value)
Set a parameter in the discretization.
- Parameters:
- namestr
Name of the parameter in the parameter list.
- valuescalar
Value of the parameter.
- solve(jac, rhs)
Solve $J(u, p) y = x$ for $y$.
- Parameters:
- jacMatrix
The Jacobian matrix $J(u, p)$ as returned by
jacobian().- rhsarray_like
The right-hand side vector $x$.
- rhs2array_like, optional
Extension of
rhsin case a bordered system is solved.- Varray_like, optional
Border case a bordered system
[A, V; W^T, C] [y; y2] = [x; x2]is solved.- Warray_like, optional
Border case a bordered system
[A, V; W^T, C] [y; y2] = [x; x2]is solved.- Cmatrix_like, optional
Border case a bordered system
[A, V; W^T, C] [y; y2] = [x; x2]is solved.
- vector()
Return a zero-initialized state vector suitable for the currently defined problem type.
- vector_from_array(array)
Create a state vector suitable for this interface from an array.