Skip to content

Unreasonable node spacing causes kernel crash/restart #42

Description

@kcpevey

reproducible example:

df = pd.read_csv('~/san_diego_boundary2.csv')
df = df.drop('Unnamed: 0', axis=1)
  
def xmsmesh_to_dataframe(pts, cells):
    """
    Convert mesh pts and cells to dataframe

    Args:
      pts (MultiPolyMesherIo.points): Points from a MultiPolyMesherIo
      cells (MultiPolyMesherIo.cells: Cells from a MultiPolyMesherIo

    Returns:
      pd.DataFrame: MultiPolyMesherIo points in a dataframe
      pd.DataFrame: MultiPolyMesherIo cells in a dataframe
    """
    r_pts = pd.DataFrame(pts, columns=['x', 'y', 'z'])
    r_cells = pd.DataFrame([(cells[x + 2], cells[x + 3], cells[x + 4]) for x in range(0, len(cells), 5)],
                           columns=['v0', 'v1', 'v2'])
    return r_pts, r_cells


def df_to_array(df):
    """ This nasty little code converts a df of polygons separated by nans into an array of polygon arrays.
    It should probably be replaced with something more efficient"""
    arr = []
    arr_list = []
    for index, row in df.iterrows():
        if np.isnan(row['x']):
            arr_list.append(arr)
            arr = []
        else:
            arr.append([row['x'], row['y'], 0])

    arr_list.append(arr)
    nparr = np.array([np.array(xi) for xi in arr_list])

    return nparr
  
# set the node spacing
# a reasonable number, like 0.01 works
# an unreasonable number, like 200 will cause the kernel to restart with no warnings or errors
node_spacing=0.01
  
nparr = df_to_array(df)


input_polygon = []
for data in nparr:
    # instantiate the redistribution class
    rdp = xmsmesh.meshing.PolyRedistributePts()
    # set the node distance
    rdp.set_constant_size_func(node_spacing)  # create_constant_size_function
    # run the redistribution function
    outdata = rdp.redistribute(data[::-1])
    # convert the polygon to an 'input polygon'
    input_polygon.append(xmsmesh.meshing.PolyInput(outside_polygon=outdata))

# add the input polygons as polygons to the mesher class
mesh_io = xmsmesh.meshing.MultiPolyMesherIo(poly_inputs=input_polygon)

# Generate Mesh
succeded, errors = xmsmesh.meshing.mesh_utils.generate_mesh(mesh_io=mesh_io)
if succeded:
    print('Meshing was successful')
else:
    print('Meshing errors found:')
    for err in errors:
        print('\t{}'.format(err))

The data is in lat/long. If node_spacing of 200 is requested, the kernel will attempt to restart with no warnings or errors. If node_spacing of 0.01 is requested, the mesh will successfully create.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions