setting double meshfunction on subdomain

Asked by Chaffra Affouda

This is what I'd like to do:

m = UnitInterval(100)
f = CellFunction('double',m)

class Left(SubDomain):
  def inside(self, x, on_boundary):
    return x[0] < 0.5

left = Left()
left.mark(f,0.01)

Obviously this does not work because mark only accepts MeshFunctionUInt. Is there a simple way to do this with a MeshFunctionDouble?

Thanks,
Chaffra

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Johan Hake (johan-hake) said :
#1

Use a uint cell function and then convert the values:

m = UnitInterval(100)
f = CellFunction('uint',m)

class Left(SubDomain):
  def inside(self, x, on_boundary):
    return x[0] < 0.5

left = Left()
f.set_all(0)
left.mark(f,1)

fd = CellFunction('double',m)
fd.values()[:] = f.values()*0.01

Johan

On Monday January 24 2011 17:34:33 Chaffra wrote:
> New question #142746 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/142746
>
> This is what I'd like to do:
>
> m = UnitInterval(100)
> f = CellFunction('double',m)
>
> class Left(SubDomain):
> def inside(self, x, on_boundary):
> return x[0] < 0.5
>
> left = Left()
> left.mark(f,0.01)
>
> Obviously this does not work because mark only accepts MeshFunctionUInt. Is
> there a simple way to do this with a MeshFunctionDouble?
>
> Thanks,
> Chaffra

Revision history for this message
Chaffra Affouda (chaffra) said :
#2

Thanks Johan,
but I am still wondering why SubDomain.mark does not accommodate other types such as double or even vectors of the correct size. What I am really looking for if a way to cell values for a given subdomain with values from a vector. Conversely is it possible given a meshfunction to extract the values corresponding to a subdomain?

Revision history for this message
Johan Hake (johan-hake) said :
#3

On Monday January 24 2011 18:58:21 Chaffra wrote:
> Question #142746 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/142746
>
> Status: Answered => Open
>
> Chaffra is still having a problem:
> Thanks Johan,
> but I am still wondering why SubDomain.mark does not accommodate other
> types such as double or even vectors of the correct size.

It would make sense to include a mark for double, bool and int. These are the
supported formats of MeshFunctions. If no one objects this addition I can add
them. We could template the present mark method and make it private. This
function could then be overloaded by public versions of the implemented ones.

> What I am really
> looking for if a way to cell values for a given subdomain with values from
> a vector. Conversely is it possible given a meshfunction to extract the
> values corresponding to a subdomain?

Not sure what you mean. Do you mean:

  MeshFunction<std::vector>

This is not supported.

Johan

Revision history for this message
Anders Logg (logg) said :
#4

On Tue, Jan 25, 2011 at 04:57:29PM -0000, Johan Hake wrote:
> Question #142746 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/142746
>
> Status: Open => Answered
>
> Johan Hake proposed the following answer:
> On Monday January 24 2011 18:58:21 Chaffra wrote:
> > Question #142746 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/142746
> >
> > Status: Answered => Open
> >
> > Chaffra is still having a problem:
> > Thanks Johan,
> > but I am still wondering why SubDomain.mark does not accommodate other
> > types such as double or even vectors of the correct size.
>
> It would make sense to include a mark for double, bool and int. These are the
> supported formats of MeshFunctions. If no one objects this addition I can add
> them. We could template the present mark method and make it private. This
> function could then be overloaded by public versions of the implemented ones.

Sure, go ahead.

--
Anders

> > What I am real
> > looking for if a way to cell values for a given subdomain with values from
> > a vector. Conversely is it possible given a meshfunction to extract the
> > values corresponding to a subdomain?
>
> Not sure what you mean. Do you mean:
>
> MeshFunction<std::vector>
>
> This is not supported.
>
> Johan
>

Revision history for this message
Best Johan Hake (johan-hake) said :
#5

On Tuesday January 25 2011 10:21:29 Anders Logg wrote:
> Question #142746 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/142746
>
> Anders Logg proposed the following answer:
>
> On Tue, Jan 25, 2011 at 04:57:29PM -0000, Johan Hake wrote:
> > Question #142746 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/142746
> >
> > Status: Open => Answered
> >
> > Johan Hake proposed the following answer:
> >
> > On Monday January 24 2011 18:58:21 Chaffra wrote:
> > > Question #142746 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/142746
> > >
> > > Status: Answered => Open
> > >
> > > Chaffra is still having a problem:
> > > Thanks Johan,
> > > but I am still wondering why SubDomain.mark does not accommodate other
> > > types such as double or even vectors of the correct size.
> >
> > It would make sense to include a mark for double, bool and int. These are
> > the supported formats of MeshFunctions. If no one objects this addition
> > I can add them. We could template the present mark method and make it
> > private. This function could then be overloaded by public versions of
> > the implemented ones.
>
> Sure, go ahead.

Should eb fixed now.

Johan

> --
> Anders
>
> > > What I am real
> > > looking for if a way to cell values for a given subdomain with values
> > > from a vector. Conversely is it possible given a meshfunction to
> > > extract the values corresponding to a subdomain?
> >
> > Not sure what you mean. Do you mean:
> > MeshFunction<std::vector>
> >
> > This is not supported.
> >
> > Johan

Revision history for this message
Chaffra Affouda (chaffra) said :
#6

Thanks Johan Hake, that solved my question.

Revision history for this message
Chaffra Affouda (chaffra) said :
#7

Thanks guys. How do I get the new code? I am running on Ubuntu lucid. Do I need a ppa or something like that?

Thanks again.