This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Changing volume of a cell / MeshEditor problems

0 votes

Hello,

I'm trying to change the volume of a cell on a 1D mesh. Is there any easy/straightforward way to do it?

By creating a IntervalMesh I'll get all the cells with the same volume according to the number of cell and the size of the domain and that's not what I want....

By creating a mesh manually, I can assign the vertex and the cell as:

mesh = Mesh()
editor.open(mesh, 'interval', 1, 1)
editor.init_vertices(37039)
editor.init_cells(12)

vert_id = 0
cell_id = 0
dist = 5.40118317e-8/10
total = 0.0
for i in range(37039):
    editor.add_vertex(vert_id, total)
    total += dist
    vert_id += 1

#RESERVOIR
editor.add_cell(0, 0, 18514)
#MEMBRANE
editor.add_cell(1, 18514,18515)
editor.add_cell(2, 18515,18516)
editor.add_cell(3, 18516,18517)
editor.add_cell(4, 18517,18518)
editor.add_cell(5, 18518,18519)
editor.add_cell(6, 18519,18520)
editor.add_cell(7, 18520,18521)
editor.add_cell(8, 18521,18522)
editor.add_cell(9, 18522,18523)
editor.add_cell(10, 18523,18524)
# RESERVOIR
editor.add_cell(11,18524,37038)
editor.close()
mesh.init()

but then, while generating my FunctionSpace:

element = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
finiteElementProductSpace = element
for i in range(numberOfSolutes-1):
    finiteElementProductSpace *= element

# Generating the finite element function space
ME = FunctionSpace(mesh, finiteElementProductSpace)

I get an error:

*** Error:   Unable to compute index of mesh entity.
*** Reason:  Mesh entity was not found.
*** Where:   This error was encountered inside MeshEntity.cpp.

By the documentation on the mesh class it says that by calling mesh.init() all entities would be created. Is it a problem related to the definition of topology and geometry of the generated mesh? Since my idea is to build a similar IntervalMesh, I copied the topology and geometry dimensions from it when opening the editor...

Can someone point out what i'm missing here?

Thanks in advance for the help!

closed with the note: Solved by using Gmsh and Dolfin-converter.
asked Jan 23, 2017 by lhdamiani FEniCS User (2,580 points)
closed Jan 30, 2017 by lhdamiani

1 Answer

0 votes

A few questions:

  • At which line specifically does the error occur?
  • Are you running both sets of code in the same script?

Also, looking at the documentation for MeshEditor (at https://fenicsproject.org/olddocs/dolfin/2016.2.0/python/programmers-reference/cpp/mesh/MeshEditor.html#dolfin.cpp.mesh.MeshEditor.add_cell), adding cells in 1D may require the indices to be in numpy array form e.g.

import numpy as np
editor.add_cell(1, np.array([18514]),np.array([18515]))
answered Jan 29, 2017 by SM FEniCS Novice (630 points)

Hi,

Thanks for your comment! I find my way around it by using Gmsh (http://gmsh.info/) and dolfin-converter to convert it to dolfin format and then I imported it....

Regarding your points: I quickly tried the array thing as you suggested but the error was still there.. and the error was on the line where I generated the FunctionSpace...

Thanks anyway!

...