# mpacts.contact.matrix. pythontools¶

In order to be able to use this module import it like this:

```import mpacts.contact.matrix.pythontools
#or assign it to a shorter name
import mpacts.contact.matrix.pythontools as pyt
```
`mpacts.contact.matrix.pythontools.``ContactMatrix_to_np_matrix`(mat)

CombinedContactDataMatrix (or its base) to a python matrix for detailed analysis. Uses scipy sparse if available.

`mpacts.contact.matrix.pythontools.``ContactMatrix_to_np_matrix_np`(mat)

CombinedContactDataMatrix (or its base) to a np.array for detailed analysis.

`mpacts.contact.matrix.pythontools.``ContactMatrix_to_np_matrix_sparse`(mat)

CombinedContactDataMatrix (or its base) to a np.array for detailed analysis.

`mpacts.contact.matrix.pythontools.``SuperSymmetric_np_matrix`(mat)
`mpacts.contact.matrix.pythontools.``Symmetric_3x3_to_np_matrix`(m)

from R3::SymmatricMatrix_t (SymmetricMatrix) to a full np.array.

`mpacts.contact.matrix.pythontools.``compute_friction_forces`(mat, pc_list=None, sim=None, Ffric_name='F_fric', diagonal_name='ContactMatrixDiagonal', vname='v')

(Post-)compute the forces associated with friction (dissipative forces) in a system where the velocities were solved in a matrix form, e.g. with the ConjugateGradientSolver. These forces are simply computed as the matrix multiplication Gamma_F * v, with Gamma_F the contact matrix where all diagonal elements (background dissipation) are set to zero. Next, we do a new ‘SumToDiagonalCommand’ and compute the matrix multiplication Gamma_F * v to obtain F_fric, the vector of frictional forces

param mat: param list pc_list: The contact matrix List of particle containers. If not given, we search it as a property from mat. Mpacts simulation tree. If not given, we search it as a property of mat. Name of the vector elements per particle that will contain the computed frictional forces If this array does not yet exist, we will make it. Name of the ContactMatrixDiagonal array. These values will be reset to zero by this command. Hence it is of utmost importantce that compute_friction_forces is called after the ConjugateGradientSolver has been executed in the simulation tree.
`mpacts.contact.matrix.pythontools.``make_CG_solver`(mat, pc_list=None, sim=None, reset_x=False, warn=True, vname='v', **kwargs)

Makes the necessary ingredients for a typical CG-solver from a CombinedContactDataMatrix and the _corresponding_ list of array-managers (which I unfortunately cannot get back from the matrix itself, yet...), or from the mat itself, if it is a FrictionMatrix object. Be sure to set the property optimization_limit to a sensible value for your system!

`mpacts.contact.matrix.pythontools.``make_LDLT_solver`(mat, pc_list=None, sim=None, warn=True, vname='v', **kwargs)

Makes the necessary ingredients for a typical LDLT-solver from a CombinedContactDataMatrix and the _corresponding_ list of array-managers (which I unfortunately cannot get back from the matrix itself, yet...), or from the mat itself, if it is a FrictionMatrix object.

`mpacts.contact.matrix.pythontools.``np_3x3_to_Symmetric`(mat, check=False)

From a 3x3 np.array to a SymmetricMatrix tuple that can be understood by DEMeter. If check==False (default), we just take the lower triangular matrix, else we check that the matrix really is symmetrical.

`mpacts.contact.matrix.pythontools.``np_matrix_to_ContactMatrix`(NMat, mgrlist)

Making a CombinedContactDataMatrix with several managers (whose total size must match with the matrix’ size/3).

`mpacts.contact.matrix.pythontools.``np_matrix_to_single_ContactMatrix`(NMat, mgr)

Making a CombinedContactDataMatrix with just one manager (for test-purposes).

`mpacts.contact.matrix.pythontools.``np_print_max`()
`mpacts.contact.matrix.pythontools.``np_reset_print`()
`mpacts.contact.matrix.pythontools.``np_submatrix_3x3`(i, j, mat)
`mpacts.contact.matrix.pythontools.``partition`(pred, iterable)

Use a predicate to partition entries into false entries and true entries - from itertools recepies

`mpacts.contact.matrix.pythontools.``reset_contact_data`(contactDetector, simulation=None, delete_irrelevant_contacts=True)