Remove the rows and columns corresponding to boundary condition

Hi all,
I want to solve a general eigenvalue problem using dolfinx and have two matrices assembled
A = assemble_matrix(a, bcs=[bc])
A.assemble()
B = assemble_matrix(b, bcs=[bc])
B.assemble()
How do I remove the rows and columns corresponding to the bc boundary from A and B matrices? Thank you in advance.

It is not a suggested approach, as it requires a complete restructuring of the sparsity pattern of the matrix, see for instance: https://scicomp.stackexchange.com/questions/35282/how-to-delete-nth-row-and-nth-column-of-a-matrix-k-in-petsc-and-restru

Dear dokken,
Thank you. A few months ago Francesco Ballarin gave an approach using his dolfinx branch to get the correct eigenvalue whose code is

V = FiniteElement('N1curl', mesh.ufl_cell(), 2)
Q = FiniteElement('P', mesh.ufl_cell(), 3)
W = FunctionSpace(mesh, V*Q)

# Define restrictions.
dofs_W = np.arange(0, W.dofmap.index_map.block_size * (
    W.dofmap.index_map.size_local + W.dofmap.index_map.num_ghosts))
bdofs_W = locate_dofs_topological(W, mvc_boundaries.dim, mvc_boundaries.indices[mvc_boundaries.values == 1] )
non_bdofs_W = np.setdiff1d(dofs_W, bdofs_W)
restriction_W_Gamma = DofMapRestriction(W.dofmap, non_bdofs_W)  # TODO: remove without fork

A = assemble_matrix(a, bcs=[], restriction=(restriction_W_Gamma, restriction_W_Gamma))
A.assemble()
B = assemble_matrix(b, bcs=[], restriction=(restriction_W_Gamma, restriction_W_Gamma))
B.assemble()

I need an similar approach using the master dolfinx to calculate the correct eigenvalue. Do you know any better approach to solve it with the newest dolfinx if it’s not a suggested approach?

Hi, I confirm that I am trying to keep my fork up to date with current master, see https://github.com/francesco-ballarin/dolfinx/tree/migration

I am currently a few commits behind (mainly with recent changes to DofMap which happened about a week ago on dolfinx master), but I usually get my fork up to date as soon as possible.

Note that the sparsity pattern is correctly allocated from the beginning, in order to avoid having to recompute it again due to row/col elimination.

1 Like

@fballarin I guess that there is a rather large set of functions that you are not modifiying in your fork. If Yes, have you considered making your fork into a add-on package? Similar to my dolfinx_mpc (https://github.com/jorgensd/dolfinx_mpc)
which contains a MultiPointConstraint-class + custom assembly routines.

Dear fballarin,
I would prefer a docker version. It’s a bit troublesome for me to install the dependent libraries like petsc and I tried to compile the source code several times but failure. At last I installed the docker version.

You can use the docker image dolfinx/dev-env which only requires you to install ufl, fiat,ffcx and dolfinx

dokken, thank you and I’ll try it.

dokken, why did the error occur when I cmake dolfinx with dolfinx/dev-env:
PETSc could not be found. Be sure to set PETSC_DIR as an environment variable. (missing: PETSC_FOUND) (Required is at least version “3.10”

Check if PETSc_dir is set with
echo $PETSC_DIR.

I used export PETSC_DIR=/usr/local/petsc to set it.

I believe we did already discuss this in the past (in a shared google document accompanying the fork), and we highlighted pros and cons. I am definitely interested in resuming such discussion (albeit probably elsewhere in order not to bring this question too much off topic)

1 Like

For the fork, you may use the docker image from multiphenics/multiphenics:dolfinx-proposal

Check $PETSC_ARCH as well.

it displayed empty .

Thank you. I’ll try it

It should be set to either linux-gnu-real-32 or linux-gnu-complex-32

Dear dokken,
I installed petsc and slepc according to dolfinx/Dockerfile at 89ec89f1ab8737e6d7c65ee0d66b1abb9bb0df0e · FEniCS/dolfinx (github.com).
I have checked PETSC_DIR and it prints “/usr/local/petsc”. It outputs the error “ERROR: Unable to link with PETSc” when I executed the command “sudo -E python3 ./configure”. What happened?

Petsc is already installed in the image, so you should not neeed to install it. See for instance: https://github.com/jorgensd/dolfinx_mpc/blob/master/.gitlab-ci.yml line 80-109

Dear dokken,
I want to install dolfinx without docker image and so I need to compile petsc and slepc by myself. Fortunately I have installed it successfully. Thank you for your help.