dolfinx_mpc.utils#

Helper functions for tests in Dolfinx mpc

dolfinx_mpc.utils.compare_CSR(A: csr_matrix, B: csr_matrix, atol=1e-10)[source]#

Compare CSR matrices A and B

dolfinx_mpc.utils.compare_mpc_lhs(A_org: Mat, A_mpc: Mat, mpc: MultiPointConstraint, root: int = 0, atol: floating[Any] = np.float64(5.0000000000000005e-12))[source]#

Compare an unmodified matrix for the problem with the one assembled with a multi point constraint.

The unmodified matrix is multiplied with K^T A K, where K is the global transformation matrix.

dolfinx_mpc.utils.compare_mpc_rhs(b_org: Vec, b: Vec, constraint: MultiPointConstraint, root: int = 0)[source]#

Compare an unconstrained RHS with an MPC rhs.

dolfinx_mpc.utils.create_normal_approximation(V: FunctionSpace, mt: MeshTags_int32, value: int)[source]#

Creates a normal approximation for the dofs in the closure of the attached entities. Where a dof is attached to entities facets, an average is computed

Parameters:
  • V – The function space

  • mt – The meshtag containing the indices

  • value – Value for the entities in the mesh tag to compute normal on

Returns:

The normal vector

Return type:

nh

dolfinx_mpc.utils.determine_closest_block(V, point)[source]#

Determine the closest dofs (in a single block) to a point and the distance

dolfinx_mpc.utils.facet_normal_approximation(V, mt: MeshTags, mt_id: int, tangent=False, jit_options: dict = {}, form_compiler_options: dict = {})[source]#

Approximate the facet normal by projecting it into the function space for a set of facets

Parameters:
  • V – The function space to project into

  • mt – The dolfinx.mesh.MeshTagsMetaClass containing facet markers

  • mt_id – The id for the facets in mt we want to represent the normal at

  • tangent – To approximate the tangent to the facet set this flag to True

  • jit_options – Parameters used in CFFI JIT compilation of C code generated by FFCx. See FEniCS/dolfinx for all available parameters. Takes priority over all other parameter values.

  • form_compiler_options – Parameters used in FFCx compilation of this form. Run ffcx - -help at the commandline to see all available options. Takes priority over all other parameter values, except for scalar_type which is determined by DOLFINx.

dolfinx_mpc.utils.gather_PETScMatrix(A: Mat, root=0) csr_matrix[source]#

Given a distributed PETSc matrix, gather in on process ‘root’ in a scipy CSR matrix

dolfinx_mpc.utils.gather_PETScVector(vector: Vec, root=0) ndarray[source]#

Gather a PETScVector from different processors on process ‘root’ as an numpy array

dolfinx_mpc.utils.gather_constants(constraint, root=0)[source]#

Given a multi-point constraint, gather all constants

dolfinx_mpc.utils.gather_transformation_matrix(constraint, root=0)[source]#

Creates the transformation matrix K (dim x dim-len(slaves)) for a given MPC and gathers it as a scipy CSR matrix on process ‘root’.

Example:

For dim=3, where:

u_1 = alpha u_0 + beta u_2

Input:

slaves = [1] masters = [0, 2] coeffs = [alpha, beta] offsets = [0, 1]

Output:

K = [[1,0], [alpha beta], [0,1]]

dolfinx_mpc.utils.get_assemblers(request)[source]#

Get eiher numba assembler or C++ assembler depending on the request

dolfinx_mpc.utils.log_info(message)[source]#

Wrapper for logging a simple string on the zeroth communicator Reverting the log level

dolfinx_mpc.utils.rigid_motions_nullspace(V: FunctionSpace)[source]#

Function to build nullspace for 2D/3D elasticity.

Parameters:

V – The function space