Plot boundary conditions

Asked by Renier Marchand on 2010-05-10

Hi,

I would like to plot the boundary conditions in my problem. The boundary condition is a DirichletBC using a generic function as part of the Expression (class MyFunc : public Expression ....) I have tried the following:

Let "bc" be the DirichletBC and "be" the Expression used to describe the BC.

1. plot(bc, mesh = mesh, element=V.ufl_element())
=> "RuntimeError: Don't know how to plot given object and projection failed: <DOLFIN object x (unnamed data)"

2. plot(be, mesh = BoundaryMesh(mesh), element=V.ufl_element())
=> "RuntimeError: *** Error: Current facet is unknown"

Am I missing something?

Something that might be related and possibly a bug, when I try to plot "be" as follows:

pts = array([[0.0,0.0,0.0], [0.5,0.5,0.5]], dtype='d') # Assume points are on boundary
plot(be, mesh=mesh, element=V.ufl_element(), plot_pts=pts)
=> TypeError: in method 'MyFunc_eval', argument 3 of type 'dolfin::Data const &'
I assume that the data sent to MyFunc_eval should be of a different type, but this would be inconsistent with the general way of plotting arbitrary points.

Thank you

Renier

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Renier Marchand
Solved:
2010-06-01
Last query:
2010-06-01
Last reply:
2010-05-13
Anders Logg (logg) said : #1

On Mon, May 10, 2010 at 12:11:25PM -0000, bluejerry wrote:
> New question #110430 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/110430
>
> Hi,
>
> I would like to plot the boundary conditions in my problem. The boundary condition is a DirichletBC using a generic function as part of the Expression (class MyFunc : public Expression ....) I have tried the following:
>
> Let "bc" be the DirichletBC and "be" the Expression used to describe the BC.
>
> 1. plot(bc, mesh = mesh, element=V.ufl_element())
> => "RuntimeError: Don't know how to plot given object and projection failed: <DOLFIN object x (unnamed data)"

You can't plot a DirichletBC.

> 2. plot(be, mesh = BoundaryMesh(mesh), element=V.ufl_element())
> => "RuntimeError: *** Error: Current facet is unknown"

Your function seems to be using data.facet() which is only available
during assembly and then only when assembling over facets. That means
your function can't be plotted (since it is not well defined for
example in the interior).

--
Anders

> Am I missing something?
>
> Something that might be related and possibly a bug, when I try to plot "be" as follows:
>
> pts = array([[0.0,0.0,0.0], [0.5,0.5,0.5]], dtype='d') # Assume points are on boundary
> plot(be, mesh=mesh, element=V.ufl_element(), plot_pts=pts)
> => TypeError: in method 'MyFunc_eval', argument 3 of type 'dolfin::Data const &'
> I assume that the data sent to MyFunc_eval should be of a different type, but this would be inconsistent with the general way of plotting arbitrary points.
>
> Thank you
>
> Renier
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp

Renier Marchand (renierm) said : #2

To plot the boundary conditions (as projected to the Vector Space)

For the system Ax=b with boundary conditions bc; I first assembled A and b, then applied the boundary condition, e.g.,

A = assemble(a)
b = assemble(b)
bc.apply(A,b)

then created a function u in the Vector Space V; and set the vector of u equal bo b

u = Function(V)
u.vector()[:] = b

u can now be plotted using plot(u)

This will plot the Vector Space with only the applied Dirichlet boundary conditions applied.

Anders Logg (logg) said : #3

On Tue, Jun 01, 2010 at 09:33:18AM -0000, bluejerry wrote:
> Question #110430 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/110430
>
> Status: Answered => Solved
>
> bluejerry confirmed that the question is solved:
> To plot the boundary conditions (as projected to the Vector Space)
>
> For the system Ax=b with boundary conditions bc; I first assembled A and
> b, then applied the boundary condition, e.g.,
>
> A = assemble(a)
> b = assemble(b)
> bc.apply(A,b)
>
> then created a function u in the Vector Space V; and set the vector of u
> equal bo b
>
> u = Function(V)
> u.vector()[:] = b
>
> u can now be plotted using plot(u)
>
> This will plot the Vector Space with only the applied Dirichlet boundary
> conditions applied.

That's a good idea.

An even easier way is the following:

  u = Function(V)
  bc.apply(u.vector())
  plot(u)

I think I will add this to the plot functions to enable direct
plotting of boundary conditions:

  plot(bc)

--
Anders

Anders Logg (logg) said : #4

On Tue, Jun 01, 2010 at 09:57:17AM -0000, Anders Logg wrote:
> Question #110430 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/110430
>
> Anders Logg posted a new comment:
> On Tue, Jun 01, 2010 at 09:33:18AM -0000, bluejerry wrote:
> > Question #110430 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/110430
> >
> > Status: Answered => Solved
> >
> > bluejerry confirmed that the question is solved:
> > To plot the boundary conditions (as projected to the Vector Space)
> >
> > For the system Ax=b with boundary conditions bc; I first assembled A and
> > b, then applied the boundary condition, e.g.,
> >
> > A = assemble(a)
> > b = assemble(b)
> > bc.apply(A,b)
> >
> > then created a function u in the Vector Space V; and set the vector of u
> > equal bo b
> >
> > u = Function(V)
> > u.vector()[:] = b
> >
> > u can now be plotted using plot(u)
> >
> > This will plot the Vector Space with only the applied Dirichlet boundary
> > conditions applied.
>
> That's a good idea.
>
> An even easier way is the following:
>
> u = Function(V)
> bc.apply(u.vector())
> plot(u)
>
> I think I will add this to the plot functions to enable direct
> plotting of boundary conditions:
>
> plot(bc)

This has been added.

--
Anders