:py:mod:`femo_alpha.fea.utils_dolfinx` ====================================== .. py:module:: femo_alpha.fea.utils_dolfinx .. autoapi-nested-parse:: Utility functions for the PETSc and UFL operations .. !! processed by numpydoc !! Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: femo_alpha.fea.utils_dolfinx.NonlinearSNESProblem Functions ~~~~~~~~~ .. autoapisummary:: femo_alpha.fea.utils_dolfinx.F femo_alpha.fea.utils_dolfinx.J femo_alpha.fea.utils_dolfinx.NewtonSolver femo_alpha.fea.utils_dolfinx.SNESSolver femo_alpha.fea.utils_dolfinx.applyBC femo_alpha.fea.utils_dolfinx.assemble femo_alpha.fea.utils_dolfinx.assembleMatrix femo_alpha.fea.utils_dolfinx.assembleScalar femo_alpha.fea.utils_dolfinx.assembleSystem femo_alpha.fea.utils_dolfinx.assembleVector femo_alpha.fea.utils_dolfinx.assemble_partials femo_alpha.fea.utils_dolfinx.computeMatVecProductBwd femo_alpha.fea.utils_dolfinx.computeMatVecProductFwd femo_alpha.fea.utils_dolfinx.computePartials femo_alpha.fea.utils_dolfinx.convertToCOO femo_alpha.fea.utils_dolfinx.convertToDense femo_alpha.fea.utils_dolfinx.createCustomMeasure femo_alpha.fea.utils_dolfinx.createFunction femo_alpha.fea.utils_dolfinx.createIntervalMesh femo_alpha.fea.utils_dolfinx.createRectangleMesh femo_alpha.fea.utils_dolfinx.createUnitSquareMesh femo_alpha.fea.utils_dolfinx.errorNorm femo_alpha.fea.utils_dolfinx.findNodeIndices femo_alpha.fea.utils_dolfinx.getFuncArray femo_alpha.fea.utils_dolfinx.gradx femo_alpha.fea.utils_dolfinx.import_mesh femo_alpha.fea.utils_dolfinx.locateDOFs femo_alpha.fea.utils_dolfinx.meshSize femo_alpha.fea.utils_dolfinx.move femo_alpha.fea.utils_dolfinx.moveBackward femo_alpha.fea.utils_dolfinx.project femo_alpha.fea.utils_dolfinx.readFEAMesh femo_alpha.fea.utils_dolfinx.reconstructFEAMesh femo_alpha.fea.utils_dolfinx.setFuncArray femo_alpha.fea.utils_dolfinx.setUpKSP_MUMPS femo_alpha.fea.utils_dolfinx.solveKSP femo_alpha.fea.utils_dolfinx.solveKSP_mumps femo_alpha.fea.utils_dolfinx.solveNonlinear femo_alpha.fea.utils_dolfinx.transpose femo_alpha.fea.utils_dolfinx.update Attributes ~~~~~~~~~~ .. autoapisummary:: femo_alpha.fea.utils_dolfinx.DOLFIN_EPS femo_alpha.fea.utils_dolfinx.comm .. py:class:: NonlinearSNESProblem(F, u, bcs, J=None) .. py:method:: F(snes, x, b) .. py:method:: J(snes, x, J, P) Assemble Jacobian matrix. .. !! processed by numpydoc !! .. py:function:: F(uhat) Compute the determinant of the deformation gradient used in the integration measure of the deformed configuration wrt the the reference configuration. uhat: DOLFINx function for mesh movements .. !! processed by numpydoc !! .. py:function:: J(uhat) Compute the determinant of the deformation gradient used in the integration measure of the deformed configuration wrt the the reference configuration. uhat: DOLFINx function for mesh movements .. !! processed by numpydoc !! .. py:function:: NewtonSolver(F, w, bcs=[], abs_tol=1e-50, rel_tol=1e-30, max_it=3, initialize=False, error_on_nonconvergence=False, report=False) Wrap up the nonlinear solver for the problem F(w)=0 and returns the solution .. !! processed by numpydoc !! .. py:function:: SNESSolver(F, w, bcs=[], abs_tol=1e-13, rel_tol=1e-13, max_it=100, report=False) https://github.com/FEniCS/dolfinx/blob/main/python/test/unit/nls/test_newton.py#L182-L205 .. !! processed by numpydoc !! .. py:function:: applyBC(res, u, bcs) .. py:function:: assemble(f, dim=0, bcs=[]) .. py:function:: assembleMatrix(M, bcs=[]) Compute the array representation of the matrix form .. !! processed by numpydoc !! .. py:function:: assembleScalar(c) Compute the array representation of the scalar form .. !! processed by numpydoc !! .. py:function:: assembleSystem(J, F, bcs=[]) Compute the array representations of the linear system .. !! processed by numpydoc !! .. py:function:: assembleVector(v) Compute the array representation of the vector form .. !! processed by numpydoc !! .. py:function:: assemble_partials(of=None, wrt=None, dim=1) util method for assembling the partial derivative matrices for education or verification. .. !! processed by numpydoc !! .. py:function:: computeMatVecProductBwd(A, R) Compute y = A.T * R A: PETSc matrix R: ufl function .. !! processed by numpydoc !! .. py:function:: computeMatVecProductFwd(A, x) Compute y = A * x A: PETSc matrix x: ufl function .. !! processed by numpydoc !! .. py:function:: computePartials(form, function) .. py:function:: convertToCOO(A) Convert a PETSc matrix to scipy.coo Matrix .. !! processed by numpydoc !! .. py:function:: convertToDense(A_petsc) Convert the PETSc matrix to a dense numpy array (super unefficient, only used for debugging purposes) .. !! processed by numpydoc !! .. py:function:: createCustomMeasure(mesh, dim, SubdomainFunc, measure: str, tag: int) .. py:function:: createFunction(function) .. py:function:: createIntervalMesh(n, x0, x1) Create interval mesh for test purposes .. !! processed by numpydoc !! .. py:function:: createRectangleMesh(pt1, pt2, nx, ny) Create rectangle mesh for test purposes .. !! processed by numpydoc !! .. py:function:: createUnitSquareMesh(n) Create unit square mesh for test purposes .. !! processed by numpydoc !! .. py:function:: errorNorm(v, v_ex, norm='L2') Calculate the L2 norm of two functions .. !! processed by numpydoc !! .. py:function:: findNodeIndices(node_coordinates, coordinates) Find the indices of the closest nodes, given the `node_coordinates` for a set of nodes and the `coordinates` for all of the vertices in the mesh, by using scipy.spatial.KDTree .. !! processed by numpydoc !! .. py:function:: getFuncArray(v) Compute the array representation of the Function .. !! processed by numpydoc !! .. py:function:: gradx(f, uhat) Convert the differential operation from the reference domain to the measure in the deformed configuration based on the mesh movement of `uhat` f: DOLFINx function for the solution of the physical problem uhat: DOLFIN function for mesh movements .. !! processed by numpydoc !! .. py:function:: import_mesh(prefix='mesh', subdomains=False, dim=2, directory='.') Function importing a dolfinx mesh. Arguments: prefix (str, optional): mesh files prefix (eg. my_mesh.msh, my_mesh_domain.xdmf, my_mesh_bondaries.xdmf). Defaults to 'mesh'. subdomains (bool, optional): True if there are subdomains. Defaults to False. dim (int, optional): dimension of the domain. Defaults to 2. directory (str, optional): directory of the mesh files. Defaults to '.'. Output: - dolfinx Mesh object containing the domain; - dolfinx MeshFunction object containing the physical lines (dim=2) or surfaces (dim=3) defined in the msh file and the sub-domains; - association table .. !! processed by numpydoc !! .. py:function:: locateDOFs(coords, V, input='polar') Find the indices of the dofs for setting up the boundary condition in the mesh motion subproblem .. !! processed by numpydoc !! .. py:function:: meshSize(mesh) .. py:function:: move(mesh, u) .. py:function:: moveBackward(mesh, u) .. py:function:: project(v, target_func, bcs=[], lump_mass=False) L2 projection of an UFL object (expression) to targeted function. Typically used for visualization in post-processing. `lump_mass` is an optional boolean argument set to be False by default; it's set to be True when lumping is needed for preventing oscillation when projecting discontinous data. .. !! processed by numpydoc !! .. py:function:: readFEAMesh(meshFile, format='HDF') Reads mesh from input meshFile, optionally display statistics .. !! processed by numpydoc !! .. py:function:: reconstructFEAMesh(filename, nodes, connectivity) .. py:function:: setFuncArray(v, v_array) Set the fuction based on the array .. !! processed by numpydoc !! .. py:function:: setUpKSP_MUMPS(A) Implementation of KSP solution of the linear system Ax=b using MUMPS .. !! processed by numpydoc !! .. py:function:: solveKSP(A, b, x) Wrap up the KSP solver for the linear system Ax=b .. !! processed by numpydoc !! .. py:function:: solveKSP_mumps(A, b, x) Implementation of KSP solution of the linear system Ax=b using MUMPS .. !! processed by numpydoc !! .. py:function:: solveNonlinear(res, func, bc, solver, report, initialize) .. py:function:: transpose(A) Transpose for matrix of DOLFIN type .. !! processed by numpydoc !! .. py:function:: update(v, v_values) Update the nodal values in every dof of the DOLFIN function `v` according to `v_values`. v: dolfin function v_values: numpy array .. !! processed by numpydoc !! .. py:data:: DOLFIN_EPS :value: 3e-16 .. py:data:: comm