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 refinement does not work for GeometryList with inners #26

Open
grongen opened this issue Jul 28, 2022 · 0 comments
Open

Mesh refinement does not work for GeometryList with inners #26

grongen opened this issue Jul 28, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@grongen
Copy link

grongen commented Jul 28, 2022

MeshKernel does not refine a mesh with with a GeometryList that contains an inner (a polygon with a hole)

To reproduce, run the code at the bottom. The plot below results from the code. The left one is the base mesh. The middle one refined correcly, based on a GeometryList object without inners. The right one does not refine, as a GeometryList object with inner is provided.
image

Version info:

  • OS: Windows
  • Version: meshkernel 1.0.0

Script to test
`# Import modules
import meshkernel as mk
import matplotlib.pyplot as plt
import numpy as np

Polygons

outer = mk.GeometryList(
x_coordinates=np.array([2.5, 6.5, 7.5, 1.5, 2.5]), y_coordinates=np.array([2.5, 1.5, 6.5, 7.5, 2.5])
)

inner = mk.GeometryList(
x_coordinates=np.array([4.0, 6.0, 6.0, 4.0, 4.0])-0.2, y_coordinates=np.array([4.0, 4.0, 6.0, 6.0, 4.0])-0.2,
)

holed = mk.GeometryList(
x_coordinates=np.concatenate([outer.x_coordinates, [outer.inner_outer_separator], inner.x_coordinates]),
y_coordinates=np.concatenate([outer.y_coordinates, [outer.inner_outer_separator], inner.y_coordinates]),
)

Refinement parameters

parameters = mk.MeshRefinementParameters(
refine_intersected=True,
use_mass_center_when_refining=False,
min_face_size=10.0, # Does nothing?
refinement_type=1, # No effect?
connect_hanging_nodes=True,
account_for_samples_outside_face=False,
max_refinement_iterations=1,
)

Meshkernel

meshkernel = mk.MeshKernel()

Function to create base mesh

def generate_base_mesh():
mesh2d_input = mk.Mesh2dFactory.create_rectilinear_mesh(
rows=10,
columns=10,
origin_x=0,
origin_y=0,
spacing_x=1,
spacing_y=1,
)
return mesh2d_input

Create base mesh

mesh2d_input = generate_base_mesh()
meshkernel.mesh2d_set(mesh2d_input)
mesh2d_base = meshkernel.mesh2d_get()

Create refined mesh

mesh2d_input = generate_base_mesh()
meshkernel.mesh2d_set(mesh2d_input)
meshkernel.mesh2d_refine_based_on_polygon(outer, parameters)
mesh2d_refined = meshkernel.mesh2d_get()

Create mesh that should be refined based on holed polygon

mesh2d_input = generate_base_mesh()
meshkernel.mesh2d_set(mesh2d_input)
meshkernel.mesh2d_refine_based_on_polygon(holed, parameters)
mesh2d_should_be_refined = meshkernel.mesh2d_get()

Plot

fig, axs = plt.subplots(ncols=3, figsize=(13.5, 5), constrained_layout=True)
for ax in axs:
ax.set(aspect=1.0)

mesh2d = meshkernel.mesh2d_get()
ax = axs[0]
mesh2d_base.plot_edges(ax=ax)

ax = axs[1]
mesh2d = meshkernel.mesh2d_get()
mesh2d_refined.plot_edges(ax=ax)
ax.plot(outer.x_coordinates, outer.y_coordinates, color='k')

ax = axs[2]
mesh2d_should_be_refined.plot_edges(ax=ax)
ax.plot(outer.x_coordinates, outer.y_coordinates, color='k')
ax.plot(inner.x_coordinates, inner.y_coordinates, color='k')`

@grongen grongen added the bug Something isn't working label Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant