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

mesh_from_Dict does not handle MultiLineStrings() #150

Closed
duarte-jfs opened this issue Apr 19, 2024 · 4 comments
Closed

mesh_from_Dict does not handle MultiLineStrings() #150

duarte-jfs opened this issue Apr 19, 2024 · 4 comments

Comments

@duarte-jfs
Copy link
Contributor

I have noticed an issue when using mesh_from_Dict(), stemming from the following lines:

       # Add overall bounding box
        total = unary_union(list(shapes_dict.values()))
        all_polygons = [total, *list(shapes_dict.values())]
        # Break up all shapes so that plane is tiled with non-overlapping layers, get the maximal number of fragments
        # Equivalent to BooleanFragments
        np.seterr(invalid="ignore")
        listpoly = [a.intersection(b) for a, b in combinations(all_polygons, 2)]
        np.seterr(**initial_settings)
        rings = [
            LineString(list(object.exterior.coords))
            for object in listpoly
            if not (object.geom_type in ["Point", "LineString"] or object.is_empty)
        ]

This is due to the fact that listpoly will have a MultiLineString when intersecting a LinearString with total. The change that could (probably) solve this is:

       # Add overall bounding box
        total = unary_union(list(shapes_dict.values()))
        all_polygons = [total, *list(shapes_dict.values())]
        # Break up all shapes so that plane is tiled with non-overlapping layers, get the maximal number of fragments
        # Equivalent to BooleanFragments
        np.seterr(invalid="ignore")
        listpoly = [a.intersection(b) for a, b in combinations(all_polygons, 2)]
        np.seterr(**initial_settings)
        rings = [
            LineString(list(object.exterior.coords))
            for object in listpoly
            if not (object.geom_type in ["Point", "LineString", "MultiLineString"] or object.is_empty)
        ]

Minimal working example

from collections import OrderedDict

import numpy as np

from shapely.geometry import box, LineString, MultiLineString
from skfem.io.meshio import from_meshio

from femwell.mesh import mesh_from_OrderedDict,mesh_from_Dict

box1 = box(-1,-1,1,1)
box2 = box(-1,5,1,6)

surface = box1.buffer(0.5).exterior
polygons = dict(box1 = box1,
               box2 = box2,
               surface = surface)

resolutions = dict(box1 = {'resolution': 0.2, 'distance':1},
                   box2 =  {'resolution': 0.2, 'distance':1},
                   surface =  {'resolution': 0.2, 'distance':1})

mesh = from_meshio(mesh_from_Dict(polygons, resolutions))

mesh.draw()
@HelgeGehring
Copy link
Owner

Great catch!
Could you make a pull request?

We mostly use mesh_from_OrderedDict, as that way you can define which objects should be in the mesh in case things are overlapping. (I don´t remember what was the advantage of mesh_from_Dict, do you @simbilod ?)
Could you make sure that it also works with that one?

@duarte-jfs
Copy link
Contributor Author

Could you make a pull request?

Once I figure out how, I will XD

We mostly use mesh_from_OrderedDict, as that way you can define which objects should be in the mesh in case things are overlapping. (I don´t remember what was the advantage of mesh_from_Dict, do you @simbilod ?)
Could you make sure that it also works with that one?

The same test with OrderedDict worked fine, and I assume is because it filters if it is a Polygon or not, rather than if it is a point or line.

@HelgeGehring
Copy link
Owner

Yay, sounds great! 🥳

@simbilod
Copy link
Contributor

I think mesh_from_Dict was meant to add the ability to have different polygons be tagged the same way

I should really finish the conversion to meshwell at some point so we have one place to discuss the meshing issues :)

duarte-jfs added a commit to duarte-jfs/femwell that referenced this issue May 23, 2024
HelgeGehring added a commit that referenced this issue May 28, 2024
fixed meshing issues: issue #150 | discussion #156
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants