Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error adding meshes #272

Closed
fipymigrate opened this issue Sep 19, 2014 · 12 comments
Closed

Error adding meshes #272

fipymigrate opened this issue Sep 19, 2014 · 12 comments
Milestone

Comments

@fipymigrate
Copy link

@fipymigrate fipymigrate commented Sep 19, 2014

When I add meshes like
mesh = mesh1 + mesh2
I obtain the error

mesh1 = mesh1 + mesh2
File "/usr/lib/python2.7/dist-packages/numpy/lib/arraysetops.py", line 328, in in1d
mask |= (ar1 == a)
ValueError: operands could not be broadcast together with shapes (2) (2,8140) (2)

The solution would be in abstractMesh.py to flatten the arrays first:

@@ -351,11 +351,11 @@
self_faceVertexIDs = MA.masked_values(self_faceVertexIDs, -1)

want self's Faces for which all faceVertexIDs are in vertexCorrelates

  •    self_matchingFaces = numerix.in1d(self_faceVertexIDs,
    
  •    self_matchingFaces = numerix.in1d(self_faceVertexIDs.flatten(),
    
    vertexCorrelates[0]).reshape(self_faceVertexIDs.shape).all(axis=0).nonzero()[0]

want other's Faces for which all faceVertexIDs are in vertexCorrelates

  •    other_matchingFaces = numerix.in1d(other_faceVertexIDs,
    
  •    other_matchingFaces = numerix.in1d(other_faceVertexIDs.flatten(),
    
    vertexCorrelates[1]).reshape(other_faceVertexIDs.shape).all(axis=0).nonzero()[0]

I find it somehow strange I'm the only one hitting this.

Imported from trac ticket #368, created by bm@cage.ugent.be on 10-11-2011 at 10:09, last modified: 09-09-2013 at 18:43

@fipymigrate fipymigrate added this to the 3.1 milestone Sep 19, 2014
@fipymigrate
Copy link
Author

@fipymigrate fipymigrate commented Sep 19, 2014

bm@cage.ugent.be attached test.py on 10-13-2011 at 03:31

@fipymigrate
Copy link
Author

@fipymigrate fipymigrate commented Sep 19, 2014

Note that it is a pitty the array iterator .flat cannot be used with in1d of numpy, so as to avoid the copying of the original array

Trac comment by anonymous on 10-11-2011 at 10:19

@guyer
Copy link
Member

@guyer guyer commented Sep 19, 2014

We certainly do test mesh concatenation.

Can you provide example meshes that cause the problem?

Trac comment by guyer on 10-12-2011 at 22:29

@fipymigrate
Copy link
Author

@fipymigrate fipymigrate commented Sep 19, 2014

I have it with this code. Note that I am using scipy trunk and numpy trunk

from fipy import *
from fipy.meshes.numMesh.grid2D import Grid2D
Lval = 2. # half length of a periodic entitiy
lval = 1. # half length of the slug
Hval = 0.1 # half height of the microchannel
hval = 0.01 # distance wall to slug
nxtot = 200 # intervalnr in x direction
nytot = 40 # intervalnr in y direction
dx = Lval / float(nxtot)
dy = Hval / float(nytot)
nx1 = (Lval-lval)/2/dx
nx2 = lval/dx
ny1 = Hval/dy
ny2 = hval/dy
mesh1 = Grid2D(dx=dx, dy=dy, nx=2*nx1, ny=ny1) + [[-(Lval-lval)/2], [0]]
mesh2 = Grid2D(dx=dx, dy=dy, nx=nx2/2, ny=ny2) + [[(Lval-lval)/2],[0]]
mesh3 = Grid2D(dx=dx, dy=dy, nx=nx2/2, ny=ny2) + [[-Lval/2], [0]]
mesh1 = mesh1 + mesh2

Which gives the error:
Traceback (most recent call last):
File "test.py", line 18, in
mesh1 = mesh1 + mesh2
File "/usr/lib/python2.7/dist-packages/FiPy-2.2_dev4804-py2.7.egg/fipy/meshes/abstractMesh.py", line 892, in add
return self._concatenatedClass(**self._getAddedMeshValues(other=other))
File "/usr/lib/python2.7/dist-packages/FiPy-2.2_dev4804-py2.7.egg/fipy/meshes/abstractMesh.py", line 356, in _getAddedMeshValues
vertexCorrelates[0]).reshape(self_faceVertexIDs.shape).all(axis=0).nonzero()[0]
File "/usr/lib/python2.7/dist-packages/numpy/lib/arraysetops.py", line 328, in in1d
mask |= (ar1 == a)
ValueError: operands could not be broadcast together with shapes (2) (2,8140) (2)

With change in bug comment, so .flatten(), things work again as before.

Trac comment by bm@cage.ugent.be on 10-13-2011 at 03:30

@fipymigrate
Copy link
Author

@fipymigrate fipymigrate commented Sep 19, 2014

Added file test.py, to avoid the bad formatting in the bug submission

Trac comment by bm@cage.ugent.be on 10-13-2011 at 03:31

@wd15
Copy link
Contributor

@wd15 wd15 commented Sep 19, 2014

Works for me with the following config:

fipy version 2.1.3-dev4751
numpy version 1.6.1
pysparse version 1.2-dev
PyTrilinos version 4.4
scipy version 0.9.0
matplotlib version 0.98.1
gist is not installed
mpi4py is not installed
enthought.mayavi is not installed

and python 2.5.2.

Trac comment by wd15 on 10-14-2011 at 12:09

@fipymigrate
Copy link
Author

@fipymigrate fipymigrate commented Sep 19, 2014

On my laptop at home it also works I see now. Monday I'll see what is different on my work box (newer numpy for sure, but then, it could be due to a numpy bug in trunk).

Trac comment by bm@cage.ugent.be on 10-14-2011 at 12:57

@wd15
Copy link
Contributor

@wd15 wd15 commented Sep 19, 2014

Do you use virtualenv and virtualenv-wrapper?

Trac comment by wd15 on 10-14-2011 at 13:02

@fipymigrate
Copy link
Author

@fipymigrate fipymigrate commented Sep 19, 2014

No, never heard of that packages before :-)
numpy trunk, scipy trunk, ... normally don't cause problems in those parts that are well established.

Trac comment by bm@cage.ugent.be on 10-14-2011 at 13:13

@wd15
Copy link
Contributor

@wd15 wd15 commented Sep 19, 2014

Replying to bm@…:

No, never heard of that packages before :-)
numpy trunk, scipy trunk, ... normally don't cause problems in those parts that are well established.

I was just pointing out virtualenv because it's extremely useful when you're switching between versions of various packages or doing any python development. It makes life much easier.

Trac comment by wd15 on 10-17-2011 at 09:46

@guyer
Copy link
Member

@guyer guyer commented Sep 19, 2014

bump

Benny, did you ever figure out what was different about your work configuration?

Our build slaves are all running NumPy 1.6.x, which is current and SciPy 0.9.x or 0.10.x, which is not. Any guess as to which is newer on your system?

Trac comment by guyer on 01-28-2013 at 11:57

@guyer
Copy link
Member

@guyer guyer commented Sep 19, 2014

We are unable to reproduce the failure. Please reopen if this is still an issue.

Trac comment by guyer on 09-09-2013 at 18:43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants