bugpyFormex - Bugs: bug #59092, Cannot concatenate meshes if one...


bug #59092: Cannot concatenate meshes if one of them was loaded from a pickle file

Submitted by:  Tim Dezutter <tdezutter>
Submitted on:  Thu 10 Sep 2020 02:00:31 PM UTC  
Category:  Core Severity:  4 - Important
Item Group:  Functionality error Status:  Fixed
Privacy:  Public Assigned to:  Benedict Verhegghe <bverheg>
Open/Closed:  Open

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Fri 11 Sep 2020 03:45:37 PM UTC, comment #3: 

The problem was fixed in commit b4277aa0

The commit fixes the failing registration problem, sanitizes the pickling of the Elems.eltype attribute, and provides a fix to read back old pickles that had stored Elems.eltype in an unwanted way.

See the log message for the commit for details.

As an added benefit, if you pickle the m2 Mesh again, the file is only 659 bytes instead of 8146. Attached as tri1.pic.

(file #49786)

Benedict Verhegghe <bverheg>
Project AdministratorIn charge of this item.
Thu 10 Sep 2020 09:45:25 PM UTC, comment #2: 

Oops. There actually is a bug in the registration of the ElementTypes. They are registered with the lower case name, but the check is done with the capitalized name. This needs a fix, because now an ElementType can be redefined. Imagine creating a Mesh of some eltype, and then the definition of that eltype changes...

Benedict Verhegghe <bverheg>
Project AdministratorIn charge of this item.
Thu 10 Sep 2020 02:45:45 PM UTC, comment #1: 

Wow, this comes as a surprise. Because the ElementType instances are considered to be static data and should only be constructed once. The _init_ function therefore checks that a name is not reused. But I forgot about pickling. I guess unpickling just creates a new instance filled with the pickled data, but never calls the _init_. So what we need to do is change the pickling/unpickling behavior of ElementType: it should just store the name, and on unpickling use ElementType.get(name) to get the static ElementType data.

I will try and test this out. In the mean time, you can use your solution as a work-around.

Benedict Verhegghe <bverheg>
Project AdministratorIn charge of this item.
Thu 10 Sep 2020 02:00:31 PM UTC, original submission:  

See script in attachment, in which a first Mesh is constructed and a second Mesh is loaded from a pickle file (also in attachment). When trying to concatenate the two meshes, the following exception is raised:

    Traceback (most recent call last):
      File "/home/tim/Downloads/concatenate_pickled_mesh.py", line 30, in <module>
      File "/home/tim/Downloads/concatenate_pickled_mesh.py", line 21, in run
        m3 = m1 + m2
      File "/home/tim/Documents/pyformex/pyformex/mesh.py", line 3131, in _add_
        return self.concatenate([self, other])
      File "/home/tim/Documents/pyformex/pyformex/mesh.py", line 3200, in concatenate
        raise ValueError("Cannot concatenate meshes with different"
    ValueError: Cannot concatenate meshes with differenteltype: ['tri3', 'tri3']

I think the cause lies in mesh.py, line 3198. Uniqueness of the mesh element types is tested by constructing a set of ElementType objects. However, for the two meshes in the example, even though both are ElementType objects with the name "tri3", they are not considered to be the same, resulting in a set containing more than one item (and thus failure of the concatenation).

Not sure if it would be acceptable, but testing uniqueness of the mesh element names instead of their element types resolves the issue, as this results in a set of strings instead of a set of ElementType objects. Line 3198 in mesh.py would become:

    eltype = {m.elName() for m in meshes}

Tim Dezutter <tdezutter>
Project Member


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #49786:  tri1.pic added by bverheg (659B - application/octet-stream)
file #49778:  tri.pic added by tdezutter (8KiB - application/octet-stream)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by bverheg (Posted a comment)
  • -email is unavailable- added by tdezutter (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-09-11 bverheg Attached File- => Added tri1.pic, #49786
        StatusConfirmed => Fixed
    2020-09-10 bverheg Severity3 - Normal => 4 - Important
        StatusNone => Confirmed
        Assigned toNone => bverheg
    2020-09-10 tdezutter Attached File- => Added concatenate_pickled_mesh.py, #49777
        Attached File- => Added tri.pic, #49778

    Back to the top

    Powered by Savane 3.5