mesh.cells() RuntimeError: array is not writeable

Asked by Nick Davies

Hi everyone
Here is a sample code adapted from the mesh editor tutoral, when I run it then I get the error "RuntimeError: array is not writeable" with reference to the cells() command. Are there settings/flags to change this to writeable, or is this the wrong way to go about inputing cells into a mesh from generated arrays so they are protected?

from dolfin import *

coor = [[ 0, 0],
              [ 1, 0],
              [ 1, 1],
              [ 0, 1]]

cell = [[0, 1, 2],
            [0, 2, 3]]

mesh = Mesh()
editor = MeshEditor()
editor.open(mesh,2,2)
editor.init_vertices(4)
editor.init_cells(2)
mesh.coordinates()[:,:] = coor
mesh.cells()[:,:] = cell
editor.close()

Traceback (most recent call last):
  File "/home/nick/Dropbox/python_codes/meshedit.py", line 17, in <module>
    mesh.cells()[:,:] = cell
RuntimeError: array is not writeable

Cheers

Question information

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

You need to use mesheditor to fill in cell and preferrably vertex info
before you close it.

Johan
On Dec 7, 2012 6:15 AM, "Nick Davies" <email address hidden>
wrote:

> New question #216156 on FEniCS Project:
> https://answers.launchpad.net/fenics/+question/216156
>
> Hi everyone
> Here is a sample code adapted from the mesh editor tutoral, when I run it
> then I get the error "RuntimeError: array is not writeable" with reference
> to the cells() command. Are there settings/flags to change this to
> writeable, or is this the wrong way to go about inputing cells into a mesh
> from generated arrays so they are protected?
>
> from dolfin import *
>
> coor = [[ 0, 0],
> [ 1, 0],
> [ 1, 1],
> [ 0, 1]]
>
> cell = [[0, 1, 2],
> [0, 2, 3]]
>
> mesh = Mesh()
> editor = MeshEditor()
> editor.open(mesh,2,2)
> editor.init_vertices(4)
> editor.init_cells(2)
> mesh.coordinates()[:,:] = coor
> mesh.cells()[:,:] = cell
> editor.close()
>
>
> Traceback (most recent call last):
> File "/home/nick/Dropbox/python_codes/meshedit.py", line 17, in <module>
> mesh.cells()[:,:] = cell
> RuntimeError: array is not writeable
>
> Cheers
>
> --
> You received this question notification because you are a member of
> FEniCS Team, which is an answer contact for FEniCS Project.
>

Revision history for this message
Nick Davies (ntd14) said :
#2

Sorry im not sure I understand, do you mean with the add_cell and add_vertex comands?
Would you mind providing an example?

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

Yes. Have a look at the documentation of each of these methods. Or just try:

editor.add_vertex(vert_ind, x, y, z)
editor.add_cell(cell_ind, v0, v1, v2, v3)

Johan

On 12/08/2012 12:11 AM, Nick Davies wrote:
> Question #216156 on FEniCS Project changed:
> https://answers.launchpad.net/fenics/+question/216156
>
> Status: Answered => Open
>
> Nick Davies is still having a problem:
> Sorry im not sure I understand, do you mean with the add_cell and add_vertex comands?
> Would you mind providing an example?
>

Revision history for this message
Nick Davies (ntd14) said :
#4

Thanks for that, I was using add_vertex and add_cell to start with and it wasn't working (hence trying the other approach), but it turns out it was an issue some where else.