bc pointwise search by MeshFunction of dim 0

Asked by Jan Blechta on 2012-12-31

Hello,
is there currently way to choose points for pointwise DirichletBC by MeshFunction of dim 0?

I know for which points of mesh I would like to set bc (I could mark them by MeshFunction of dim 0 for example). It seems that only way is to create SubDomain with inside method. So everytime bc.apply will be called, all points will be checked by calling inside method of SubDomain object instead of simply checking for value of corresponding MeshFunction.

Thanks,
Jan

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Garth Wells
Solved:
2013-01-04
Last query:
2013-01-04
Last reply:
2013-01-02
Best Garth Wells (garth-wells) said : #1

On Mon, Dec 31, 2012 at 5:26 PM, Jan Blechta
<email address hidden> wrote:
> New question #218000 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/218000
>
> Hello,
> is there currently way to choose points for pointwise DirichletBC by MeshFunction of dim 0?
>

No.

> I know for which points of mesh I would like to set bc (I could mark them by MeshFunction of dim 0 for example). It seems that only way is to create SubDomain with inside method. So everytime bc.apply will be called, all points will be checked by calling inside method of SubDomain object instead of simply checking for value of corresponding MeshFunction.
>

The problem with this is that it will make sense only for P1 elements.

What we perhaps could add is an interface that takes a vector/set of
dof indices.

Garth

> Thanks,
> Jan
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Jan Blechta (blechta) said : #2

> The problem with this is that it will make sense only for P1 elements.
>
I see.

> What we perhaps could add is an interface that takes a vector/set of
> dof indices.
>
That could be useful. If I understandt it correctly search for
dirichlet dofs is performed when instance of DirichletBC is created.
When DirichletBC.apply is called appropriate entries in matrix and
vector are set. Am I right?

When for example mesh is moved (but topology remains same) new instance
of DirichletBC for appropriate function space must be created
(or not?) therefore search is again performed. If some new method of
DirichletBC could return this suggested vector/set of dofs it could be
reused for moved mesh without performing search. Sounds like savings of
resources...

Jan

Anders Logg (logg) said : #3

On Tue, Jan 01, 2013 at 05:11:13PM -0000, Jan Blechta wrote:
> Question #218000 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/218000
>
> Status: Answered => Open
>
> Jan Blechta is still having a problem:
> > The problem with this is that it will make sense only for P1 elements.
> >
> I see.
>
> > What we perhaps could add is an interface that takes a vector/set of
> > dof indices.
> >
> That could be useful. If I understandt it correctly search for
> dirichlet dofs is performed when instance of DirichletBC is created.
> When DirichletBC.apply is called appropriate entries in matrix and
> vector are set. Am I right?

Yes.

> When for example mesh is moved (but topology remains same) new instance
> of DirichletBC for appropriate function space must be created
> (or not?) therefore search is again performed. If some new method of
> DirichletBC could return this suggested vector/set of dofs it could be
> reused for moved mesh without performing search. Sounds like savings of
> resources...

This is only a problem if you set your BCs based on coordinates
(x-values). If you use a MeshFunction to mark your boundaries, then
the markers will still be valid when the mesh is moved.

So do this:

1. Define one or more SubDomain subclasses to define your BCs.

2. Create a FacetFunction and set all values to some default value

   f.set_all(0)

3. Use your SubDomain classes to mark boundaries

   my_domain_1.mark(f, 1)
   my_domain_1.mark(f, 2)
   my_domain_1.mark(f, 3)

4. Use the FacetFunction f to define your BCs:

   bc1 = DirichletBC(V, g1, f, 1)
   bc2 = DirichletBC(V, g1, f, 2)
   bc3 = DirichletBC(V, g1, f, 3)

--
Anders

Jan Blechta (blechta) said : #4

On Wed, 02 Jan 2013 20:41:23 -0000
Anders Logg <email address hidden> wrote:
> Your question #218000 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/218000
>
> Status: Open => Answered
>
> Anders Logg proposed the following answer:
> On Tue, Jan 01, 2013 at 05:11:13PM -0000, Jan Blechta wrote:
> > Question #218000 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/218000
> >
> > Status: Answered => Open
> >
> > Jan Blechta is still having a problem:
> > > The problem with this is that it will make sense only for P1
> > > elements.
> > >
> > I see.
> >
> > > What we perhaps could add is an interface that takes a vector/set
> > > of dof indices.
> > >
> > That could be useful. If I understandt it correctly search for
> > dirichlet dofs is performed when instance of DirichletBC is created.
> > When DirichletBC.apply is called appropriate entries in matrix and
> > vector are set. Am I right?
>
> Yes.

So search by SubDomain.inside() method is performed everytime bc is
applied on newly moved mesh and in other cases found dofs are cached
and reused?

>
> > When for example mesh is moved (but topology remains same) new
> > instance of DirichletBC for appropriate function space must be
> > created (or not?) therefore search is again performed. If some new
> > method of DirichletBC could return this suggested vector/set of
> > dofs it could be reused for moved mesh without performing search.
> > Sounds like savings of resources...
>
> This is only a problem if you set your BCs based on coordinates
> (x-values). If you use a MeshFunction to mark your boundaries, then
> the markers will still be valid when the mesh is moved.
>
> So do this:
>
> 1. Define one or more SubDomain subclasses to define your BCs.
>
> 2. Create a FacetFunction and set all values to some default value
>
> f.set_all(0)
>
> 3. Use your SubDomain classes to mark boundaries
>
> my_domain_1.mark(f, 1)
> my_domain_1.mark(f, 2)
> my_domain_1.mark(f, 3)
>
> 4. Use the FacetFunction f to define your BCs:
>
> bc1 = DirichletBC(V, g1, f, 1)
> bc2 = DirichletBC(V, g1, f, 2)
> bc3 = DirichletBC(V, g1, f, 3)
>

I am aware of this way. But consider poitwise bcs for vertices which
have no bc-constrained neighbour, so no facet exists to define this
bc. So the only way is to find coordinates of these known vertices and
define SubDomain of DOLFIN_EPS neighbourhood of these vertices.

Like Garth noted it is not obvious how to use this approach for another
elements than P1.

Actually I'm using this approach to solve multiphysics problem (because
restriction is still rather experimental and not implemented in
python I guess). For me it seems that new functionality suggested by
Garth could be useful in some (maybe special) cases.

Jan

> --
> Anders
>

Jan Blechta (blechta) said : #5

Thanks Garth Wells, that solved my question.