question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

apply Dirichlet conditions by setting rows to I, rhs to value

See original GitHub issue

For the first time, I’m looking at scikit-fem in a serious manner. Diving into it, I notice that the common way the “apply” Dirichlet conditions is to eliminate the respective entries from the matrix/rhs à la

A, b = condense(A, b, I=mesh.interior_nodes())

I on the other hand would like to see those condition applied via setting the respective rows in A to diagonal 1 and 0 otherwise plus the respective rhs entry to the value. Something like

apply_dirichlet(A, b, mesh.boundary_nodes(), vals)

perhaps. The resulting matrix has the same spectral properties as the condensed A, so the number of iterations with Krylov methods will be the same, too. Advantages of this approach include the fact that neither A nor b need to be rewritten in memory. Also, the solution will include the values of all degrees of freedom, making postprocessing easier.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:29 (29 by maintainers)

github_iconTop GitHub Comments

1reaction
kinnalacommented, Mar 30, 2021

Something like

for i in dofs:
    matrix.data[matrix.indptr[i] : matrix.indptr[i + 1]] = 0.0

d = matrix.diagonal()
d[dofs] = 1.0

would set the rows to I, but perhaps one can do better than the python loop here. I’ve added a feature request in scipy, but the above would already work well as a makeshift solution.

Alright, I’m a little slow. You already had a solution here and it remains to vectorize it.

0reactions
gdmcbaincommented, Apr 9, 2021

Ah, of course:

backsolve = splu(A.T).solve

the left stepping matrix A is no longer symmetric so can’t just be transposed willy-nilly to avoid the

SparseEfficiencyWarning: splu requires CSC matrix format

Replacing that with backsolve = splu(A).solve makes it run O. K.

Read more comments on GitHub >

github_iconTop Results From Across the Web

fem1dlinear
function fem1dlinear % This function solves the 1D BVP % -au'' + bu' + cu = f in (x0, x1) % with either...
Read more >
[petsc-users] better way of setting dirichlet boundary conditions
1) First create the big system matrix (from DM da) including the identity >> rows for Dirichlet points and corresponding rhs, Lets say...
Read more >
Dirichlet boundary conditions Hcurl? - General - FEniCS Project
Hello, For an exercise class in numerics I wanted to setup a simple example for the curl-curl operator (magneto-statics) but I cannot seem ......
Read more >
Implementation of Dirichlet boundary condition when tgv=-1
As far as I read, when using tgv=-1, freefem doesn't apply dirichlet BC in a symmetric way. The symmetric way would look like...
Read more >
FEM implementation of Dirichlet boundary conditions in elastostatic ...
I do not have any Neumann boundary conditions. ... of the diagonal of the matrix, and setting the Dirichlet value in the corresponding...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found