msh2cande/msh_load.py
def _dedup_nodes(msh: Msh, tol=0.001):
    """Modify Msh object such that all nodes are assumed to be unique."""

    nodes_df = msh.nodes

    # change node numbering of firsts (including nodes that later have a dup)
    c = itertools.count(start=1)
    firsts_slicer = (nodes_df.duplicated() ^ nodes_df.duplicated(keep=False)) | ~ nodes_df.duplicated(keep=False)
    firsts_index = nodes_df[firsts_slicer].index
    # temporarily convert first indexes to strs so not overwritten later
    nodes_df.rename({index:str(next(c)) for index in firsts_index}, inplace=True)

    # get first duplicated nodes ("duped", excluding the duplicates that come after)
    duped_slicer = nodes_df.duplicated() ^ nodes_df.duplicated(keep=False)
    duped_index = nodes_df.index[duped_slicer]

    # change the duplicate node numbers to match the first dupe
    for duped_node_index in duped_index:
        dupes_w_first_slicer = (nodes_df == nodes_df.loc[duped_node_index]).all(axis=1)
        dupes_w_first_index = nodes_df[dupes_w_first_slicer].index
        nodes_df.rename({index:duped_node_index for index in dupes_w_first_index if not isinstance(index, str)}, inplace=True)

    # change nodes index back to ints; must use nodes_df.rename(inplace=True) to maintain element and boundary
    # references to underlying index; yes this is probably slow
    nodes_df.rename({index_str: int(index_str) for index_str in nodes_df.index}, inplace=True)

    # TODO: clean duplicate boundaries

    # # dupes (excluding any firsts)
    # dupes_slicer = nodes_df.duplicated()
    # dupes_index = nodes_df.index[dupes_slicer]
    #
Modify Msh object such that all nodes are assumed to be unique.
Modify Msh object such that all nodes are assumed to be unique.
Modify Msh object such that all nodes are assumed to be unique .
def _dedup_nodes(msh: Msh, tol=0.001):
    nodes_df = msh.nodes
    c = itertools.count(start=1)
    firsts_slicer = (nodes_df.duplicated() ^ nodes_df.duplicated(keep=False)) | ~ nodes_df.duplicated(keep=False)
    firsts_index = nodes_df[firsts_slicer].index
    nodes_df.rename({index:str(next(c)) for index in firsts_index}, inplace=True)
    duped_slicer = nodes_df.duplicated() ^ nodes_df.duplicated(keep=False)
    duped_index = nodes_df.index[duped_slicer]
    for duped_node_index in duped_index:
        dupes_w_first_slicer = (nodes_df == nodes_df.loc[duped_node_index]).all(axis=1)
        dupes_w_first_index = nodes_df[dupes_w_first_slicer].index
        nodes_df.rename({index:duped_node_index for index in dupes_w_first_index if not isinstance(index, str)}, inplace=True)
    nodes_df.rename({index_str: int(index_str) for index_str in nodes_df.index}, inplace=True)
def _dedup_nodes ( msh : Msh , tol = 0.001 ) : nodes_df = msh . nodes c = itertools . count ( start = 1 ) firsts_slicer = ( nodes_df . duplicated ( ) ^ nodes_df . duplicated ( keep = False ) ) | ~ nodes_df . duplicated ( keep = False ) firsts_index = nodes_df [ firsts_slicer ] . index nodes_df . rename ( { index : str ( next ( c ) ) for index in firsts_index } , inplace = True ) duped_slicer = nodes_df . duplicated ( ) ^ nodes_df . duplicated ( keep = False ) duped_index = nodes_df . index [ duped_slicer ] for duped_node_index in duped_index : dupes_w_first_slicer = ( nodes_df == nodes_df . loc [ duped_node_index ] ) . all ( axis = 1 ) dupes_w_first_index = nodes_df [ dupes_w_first_slicer ] . index nodes_df . rename ( { index : duped_node_index for index in dupes_w_first_index if not isinstance ( index , str ) } , inplace = True ) nodes_df . rename ( { index_str : int ( index_str ) for index_str in nodes_df . index } , inplace = True )
Modify Msh object such that all nodes are assumed to be unique.
Modify Msh object such that all nodes are assumed to be unique .
"""Modify Msh object such that all nodes are assumed to be unique.""" # change node numbering of firsts (including nodes that later have a dup) # temporarily convert first indexes to strs so not overwritten later # get first duplicated nodes ("duped", excluding the duplicates that come after) # change the duplicate node numbers to match the first dupe # change nodes index back to ints; must use nodes_df.rename(inplace=True) to maintain element and boundary # references to underlying index; yes this is probably slow # TODO: clean duplicate boundaries # # dupes (excluding any firsts) # dupes_slicer = nodes_df.duplicated() # dupes_index = nodes_df.index[dupes_slicer] #
msh
Msh
tol