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

Loading Mesh from file in for cycle

+2 votes

Hello,

I am working on an adaptivity algorithm and I am facing an issue that is reproduced in the following dummy code:

from dolfin import *

M=UnitSquareMesh(10,10)
File('us.xml')<<M

for i in xrange(2):
    M1=Mesh('us.xml')
    plot(M1)
interactive()

The first time the mesh is loaded correctly, but the second time is totally wrong, and looks like this:
wrong mesh

Using more complicated meshes the result is basically random, but I noticed that the second mesh has the same vertex numbering around each element (i.e. M1.cells() is identical).
On the other hand the second mesh has vertices coordinates that are integer values corresponding to the first non-zero digit of the first mesh coordinates.. for example:

from dolfin import *

M=UnitSquareMesh(20,20)
File('us.xml')<<M

for i in xrange(2):
    M1=Mesh('us.xml')
    plot(M1)
    print M1.coordinates()[0:4]
interactive()

gives this output:
[[ 0. 0. ]
[ 0.05 0. ]
[ 0.1 0. ]
[ 0.15 0. ]]
[[ 0. 0.]
[ 5. 0.]
[ 1. 0.]
[ 1. 0.]]

The strange thing is also that the following code plots the meshes correctly:
from dolfin import *

M=UnitSquareMesh(10,10)

for i in xrange(2):
    plot(M)
    interactive()

And this code gives the correct output:

from dolfin import *

M=UnitSquareMesh(20,20)
File('us.xml')<<M

for i in xrange(2):
    M1=Mesh('us.xml')
    print M1.coordinates()[0:4]

its output is, as expected:
[[ 0. 0. ]
[ 0.05 0. ]
[ 0.1 0. ]
[ 0.15 0. ]]
[[ 0. 0. ]
[ 0.05 0. ]
[ 0.1 0. ]
[ 0.15 0. ]]

soooo probably is causing the problem is the combination of a mesh loaded from a file, and
interactive(). What am I doing wrong? Any Idea?

thanks a lot.

asked Jan 17, 2014 by DLongoni FEniCS Novice (300 points)
edited Jan 18, 2014 by DLongoni

3 Answers

–1 vote

Hi, Try and check version

M=UnitSquare(20,20)
answered Jan 18, 2014 by Manickam FEniCS Novice (450 points)

Hello,

thanks for your answer. I tried it, and it does not change anything. The problem occurs with any mesh so far, even the ones generated with gmsh and converted with dolfin-convert. Can you confirm that you also experience the bug, please?

edit: I added a picture of the wrong mesh in the main post

+2 votes

This is fixed in version 1.3: See https://bitbucket.org/fenics-project/dolfin/issue/101

answered Jan 18, 2014 by Garth N. Wells FEniCS Expert (35,930 points)

Hello Garth, thanks for your answer. I am using ffc version 1.3 though.

Works fine for me. Make sure you have DOLFIN 1.3.

Let me post you a couple of commands with their respective outputs:

python -c"import dolfin;print dolfin.__version__"

Says 1.3.0. And running

dpkg -l '*dolfin*'

I have the following packages listed (version 1.3.0 for all of them):

dolfin-bin
dolfin-doc
libdolfin1.3
libdolfin1.3-dev
python-dolfin

and I also have python-dolfin-adjoint with version 1.2.0

Do you have any Idea of what could be wrong?

thanks,

Davide

I can't reproduce the problem. I get two windows with the correct mesh in each one.

I also can't reproduce the problem. I tried on Ubuntu 13.10 with the 1.3.0 packages from the FEniCS PPA. Which version of Ubuntu are you running?

I am also running 13.10, and I have added the fenics repository. Tomorrow I'll try a full reinstall and see if it works. Can you confirm that these are the dolfin packages you also have installed? Thanks a lot

Yes, I have:

$ dpkg -l '*dolfin*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                   Version                  Architecture             Description
ii  dolfin-bin                             1.3.0+dfsg-2~ppa1~saucy1 all                      Executable scripts for DOLFIN
ii  dolfin-doc                             1.3.0+dfsg-2~ppa1~saucy1 all                      Documentation and demo programs for DOLFIN
un  libdolfin0-dev                         <none>                                            (no description available)
un  libdolfin1.0-dev                       <none>                                            (no description available)
un  libdolfin1.1-dev                       <none>                                            (no description available)
un  libdolfin1.2-dev                       <none>                                            (no description available)
ii  libdolfin1.3                           1.3.0+dfsg-2~ppa1~saucy1 amd64                    Shared libraries for DOLFIN
un  libdolfin1.3-dbg                       <none>                                            (no description available)
ii  libdolfin1.3-dev                       1.3.0+dfsg-2~ppa1~saucy1 amd64                    Shared links and header files for DOLFIN
ii  python-dolfin                          1.3.0+dfsg-2~ppa1~saucy1 amd64                    Python interface for DOLFIN

Thanks again.. one more try.. python version? I'm running 2.7.5

So, I reinstalled both python and fenics... nothing changed. Should I open a bug report on launchpad for this?

+1 vote

For information:
I had the same problem even in version 1.5.0 because my locale (language settings of my system) was non-standard. It seems this is fixed in the developement version by changing the locale locally in dolfin, see this discussion on bitbucket.
To fix the issue by oneself in earlier versions, one can simply change the locale globally, temporarily by typing

export LC_ALL=C

in a terminal, or even permanently with

sudo update-locale LC_ALL=C

Disclaimer: I don't really know about the other effects of changing the locale, since I have only just discovered that this fixes the problem.

answered May 7, 2015 by Gregor Mitscha-Baude FEniCS User (2,280 points)
...