Skip to content

How to do Nonzero Neumann boundary condition for Laplace and heat equations #1155

Answered by kinnala
aquillen asked this question in Q&A
Discussion options

You must be logged in to vote

Here is the code (scikit-fem==10.0.1):

from skfem import *
from skfem.helpers import *

m = MeshTri().refined(5).with_defaults()  # left, right, etc. tagged
e = ElementTriP1()
basis = Basis(m, e)

fbasis_gamma = basis.boundary('right')

@BilinearForm
def laplace(u, v, _):
    return dot(grad(u), grad(v))

@LinearForm
def bodyload(v, w):
    x, y = w.x
    f = 1 + 0 * x  # this can depend on x and y
    return f * v

@LinearForm
def neumann(v, w):
    x, y = w.x
    g = y ** 2  # this can depend on x and y
    return g * v


A = asm(laplace, basis)
b = asm(bodyload, basis) + asm(neumann, fbasis_gamma)

u = basis.zeros()
x = solve(*condense(A, b, D=basis.get_dofs({'left', 'top', 'bottom'})))

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@kinnala
Comment options

@kinnala
Comment options

@kinnala
Comment options

Answer selected by aquillen
@kinnala
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants