local coordinates

Asked by B. Emek Abali

I need the coordinates relative to the middle of the cell in my form, so I came to the idea of

class cellcoords(Expression):
 def eval(self, out, x):
  out[0] = x[0]-self.??().midpoint()
  out[1] = x[1]-self.??().midpoint()
  out[2] = x[2]-self.??().midpoint()
 def value_shape(self):
  return (3,)

x = cellcoords()

where my lack of programming knowledge restricts me to the question marks ! I dig in the Mesh...h but could not find out..

How can I reach to a method (midpoint() ) in MeshEntity class from the Expression (I think self. directs me to the MeshData class) ?

any other method is also welcome.

Thanks a lot,

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
B. Emek Abali
Solved:
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

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

Sorry for late reply:

Try with:

 class cellcoords(Expression):
        def __init__(self, mesh):
                self.mesh = mesh
  def eval_cell(self, out, x, ufc_cell):
                dolfin_cell = Cell(self.mesh, ufc_cell.index)
                p = dolfin_cell.midpoint()
   out[0] = x[0]-p.x
   out[1] = x[1]-p.y
   out[2] = x[2]-p.z
  def value_shape(self):
   return (3,)

Johan

On Wednesday April 20 2011 06:24:29 B. Emek Abali wrote:
> New question #153591 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/153591
>
> I need the coordinates relative to the middle of the cell in my form, so I
> came to the idea of
>
> class cellcoords(Expression):
> def eval(self, out, x):
> out[0] = x[0]-self.??().midpoint()
> out[1] = x[1]-self.??().midpoint()
> out[2] = x[2]-self.??().midpoint()
> def value_shape(self):
> return (3,)
>
> x = cellcoords()
>
> where my lack of programming knowledge restricts me to the question marks !
> I dig in the Mesh...h but could not find out..
>
> How can I reach to a method (midpoint() ) in MeshEntity class from the
> Expression (I think self. directs me to the MeshData class) ?
>
> any other method is also welcome.
>
> Thanks a lot,

Revision history for this message
B. Emek Abali (bilenemek) said :
#3

no prob, exactly what I needed!

Revision history for this message
B. Emek Abali (bilenemek) said :
#4

Thanks Johan,
only this small change,
out[0] = x[0]-p.x()

it works like a charm