meshpro / pygalmesh

:spider_web: A Python interface to CGAL's meshing tools
GNU General Public License v3.0
581 stars 57 forks source link

Specifying field with edge_size #114

Closed krober10nd closed 3 years ago

krober10nd commented 3 years ago

Hello,

I'm am trying to use pygalmesh to build a variable resolution 3d mesh of a unit cube, I'd like to specify a variable field of space for the cell_size. However, if I'm building a domain with the cuboid object, the API requires an edge_size parameter that cannot be a function of space. If I do not specify edge_size it fails. And if I specify a constant edge_size my mesh develops high valency edge connectivity near the boundary where it does not respect the cell_size function but does respect the edge_size function. If I make edge_size large this leads to badly shaped elements where mesh resolution is finer.

HMIN = 0.025 GRADE = HMIN / 1.0

class Field(pygalmesh.SizingFieldBase): def eval(self, x): return (1 - x[0]) * GRADE + HMIN

mesh = pygalmesh.generate_mesh( pygalmesh.Cuboid([0.0, 0.0, 0.0], [1.0, 1.0, 1.0]), cell_size=Field(), edge_size=HMIN, )

mesh.write("cgal_cuboid.vtk")


* Fails when specifying `edge_size` as a function. 

```python
import pygalmesh

HMIN = 0.025
GRADE = HMIN / 1.0

class Field(pygalmesh.SizingFieldBase):
    def eval(self, x):
        return (1 - x[0]) * GRADE + HMIN

mesh = pygalmesh.generate_mesh(
    pygalmesh.Cuboid([0.0, 0.0, 0.0], [1.0, 1.0, 1.0]),
    cell_size=Field(),
    edge_size=Field(),
)

 mesh.write("cgal_cuboid.vtk")
Screen Shot 2020-09-30 at 1 41 09 PM
krober10nd commented 3 years ago

I solved it by just scaling the cell_size by a fraction. The cell_size is not the same size as the edge_size.

nschloe commented 3 years ago

Let's reopen this. It should be possible to set no edge_size and have the mesh generation unaffected by it.

krober10nd commented 3 years ago

Okay fair enough. Thanks for looking into this and starting the issue there.