value on mesh

Asked by Tim Baker

I was wondering how to print values data on a mesh. I tried print mesh.data(), and I got <MeshData containing 1 objects>

Actually, I need all the values for all the grid points on the mesh.

Question information

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

What do you mean with values.

Johan

On 07/13/2012 05:31 PM, Tim Baker wrote:
> New question #203065 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/203065
>
> I was wondering how to print values data on a mesh. I tried print mesh.data(), and I got <MeshData containing 1 objects>
>
> Actually, I need all the values for all the grid points on the mesh.
>
>

Revision history for this message
Tim Baker (maurolap) said :
#2

I mean that after I build mesh, and I assign values on the mesh with a function, I would like to check those values from the mesh.

Let's say for example I assign 0 value all over the mesh, I would like to know the way how to check that all the values for all the cells of the mesh are actually 0

Revision history for this message
N.A. Borggren (nborggren) said :
#3

for example, you can use vector()

>>> mesh = UnitSquare(3,3)
>>> Q=FunctionSpace(mesh,"Lagrange",1)
>>> f = Function(Q)
>>> zero = Constant(0.0)
>>> f.interpolate(zero)
>>> for i,j in zip(mesh.coordinates(),f.vector()):print i,j
...
[ 0. 0.] 0.0
[ 0.33333333 0. ] 0.0
[ 0.66666667 0. ] 0.0
[ 1. 0.] 0.0
[ 0. 0.33333333] 0.0
[ 0.33333333 0.33333333] 0.0
[ 0.66666667 0.33333333] 0.0
[ 1. 0.33333333] 0.0
[ 0. 0.66666667] 0.0
[ 0.33333333 0.66666667] 0.0
[ 0.66666667 0.66666667] 0.0
[ 1. 0.66666667] 0.0
[ 0. 1.] 0.0
[ 0.33333333 1. ] 0.0
[ 0.66666667 1. ] 0.0
[ 1. 1.] 0.0

Revision history for this message
N.A. Borggren (nborggren) said :
#4

However, if you mean MeshFunction I get an error as well for values(), which the webpage makes seem like it would be available,

 http://fenicsproject.org/documentation/dolfin/1.0.0/cpp/programmers-reference/mesh/MeshFunction.html

>>> mesh = UnitSquare(2,2)
>>> sub_domains = MeshFunction("uint", mesh, mesh.topology().dim())
>>> sub_domains.set_all(7)
>>> sub_domains.values()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'MeshFunctionUInt' object has no attribute 'values'

and I get a strange error if I try:

>>> for i,j in enumerate(mesh.coordinates()):print j, sub_domains[i]
...
[ 0. 0.] 7
[ 0.5 0. ] 7
[ 1. 0.] 7
[ 0. 0.5] 7
[ 0.5 0.5] 7
[ 1. 0.5] 7
[ 0. 1.] 7
[ 0.5 1. ] 7
[ 1. 1.] 1129075456

I am not sure why the last number isn't also 7.

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

On 07/14/2012 01:30 AM, N.A. Borggren wrote:
> Question #203065 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/203065
>
> N.A. Borggren requested more information:
> However, if you mean MeshFunction I get an error as well for values(),
> which the webpage makes seem like it would be available,
>
> http://fenicsproject.org/documentation/dolfin/1.0.0/cpp/programmers-
> reference/mesh/MeshFunction.html
>
>>>> mesh = UnitSquare(2,2)
>>>> sub_domains = MeshFunction("uint", mesh, mesh.topology().dim())
>>>> sub_domains.set_all(7)
>>>> sub_domains.values()
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> AttributeError: 'MeshFunctionUInt' object has no attribute 'values'

MeshFunction.values is deprecated. Use MeshFunction.array instead.

> and I get a strange error if I try:
>
>>>> for i,j in enumerate(mesh.coordinates()):print j, sub_domains[i]
> ...
> [ 0. 0.] 7
> [ 0.5 0. ] 7
> [ 1. 0.] 7
> [ 0. 0.5] 7
> [ 0.5 0.5] 7
> [ 1. 0.5] 7
> [ 0. 1.] 7
> [ 0.5 1. ] 7
> [ 1. 1.] 1129075456
>
> I am not sure why the last number isn't also 7.

That is because you have made a MeshFunction over Cells, but iterates
over vertices. Try:

sub_domains = VertexFunction("uint", mesh, 7)

Johan

Can you help with this problem?

Provide an answer of your own, or ask Tim Baker for more information if necessary.

To post a message you must log in.