Skip to content

neighbour_graph

NeighbourGraph(cellboxes=None, grid_width=0)

A NeighbourGraph is a class that defines the graphical representation of the adjacency relationship between CellBoxes in the Mesh.

Attributes:

Name Type Description
neighbour_graph dict

a dictionary that contains cellboxes ids along with their adjacent neighbours in the following form

{

    <CellBox id_1>: {

        "1": [id_1,...,id_n],

        "2": [id_1,...,id_n],

        "3": [id_1,...,id_n],

        "4": [id_1,...,id_n],

        "-1": [id_1,...,id_n],

        "-2": [id_1,...,id_n],

        "-3": [id_1,...,id_n],

        "-4": [id_1,...,id_n],

    },

    ...,

    {

        <CellBox id_n>: {

            ...

        }

    }

}

add_neighbour(index, direction, neighbour_indx)

adds a neighbour in a certain direction

Args: index (int): the index of the cellbox to be updated direction (int): the direction into which the neighbour will be added neighbour_indx (int): the index of the cellbox to be added as a neighbour

add_node(index, neighbour_map)

method that adds a node to the neighbour_graph at a given index Args: index(int):the index at which the node will be added in the neighbour_graph neighbour_map (dict): a dict that contains the neighbours of the node

from_json(ng_json) classmethod

method that initializes a graph from a json object Args: ng_json (json_object): json object that contains the neighbour_graph data

get_global_mesh_neighbour_case(cellbox_a, cellbox_b)

Given two cellboxes in a global mesh (cellbox_a, cellbox_b) returns a case number representing where the two cellboxes are touching.

Parameters:

Name Type Description Default
cellbox_a CellBox

starting CellBox

required
cellbox_b CellBox

destination CellBox

required

Returns:

Name Type Description
int

an int representing the direction of the adjacency between input cellbox_a and cellbox_b. The meaning of each case is as follows -

case 0 -> CellBoxes are not neighbours

case 1 -> cellbox_b is the North-East corner of cellbox_a

case 2 -> cellbox_b is East of cellbox_a

case 3 -> cellbox_b is the South-East corner of cellbox_a

case 4 -> cellbox_b is South of cellbox_a

case -1 -> cellbox_b is the South-West corner of cellbox_a

case -2 -> cellbox_b is West of cellbox_a

case -3 -> cellbox_b is the North-West corner of cellbox_a

case -4 -> cellbox_b is North of cellbox_a

get_graph()

returns the graph dict

get_neighbour_case(cellbox_a, cellbox_b)

Given two cellboxes (cellbox_a, cellbox_b) returns a case number representing where the two cellboxes are touching.

Parameters:

Name Type Description Default
cellbox_a CellBox

starting CellBox

required
cellbox_b CellBox

destination CellBox

required

Returns:

Name Type Description
int

an int representing the direction of the adjacency between input cellbox_a and cellbox_b. The meaning of each case is as follows -

case 0 -> CellBoxes are not neighbours

case 1 -> cellbox_b is the North-East corner of cellbox_a

case 2 -> cellbox_b is East of cellbox_a

case 3 -> cellbox_b is the South-East corner of cellbox_a

case 4 -> cellbox_b is South of cellbox_a

case -1 -> cellbox_b is the South-West corner of cellbox_a

case -2 -> cellbox_b is West of cellbox_a

case -3 -> cellbox_b is the North-West corner of cellbox_a

case -4 -> cellbox_b is North of cellbox_a

get_neighbour_case_bounds(bounds_a, bounds_b)

Given two bounds (bounds_a, bounds_b) returns a case number representing where the two bounds are touching.

Parameters:

Name Type Description Default
bounds_a Bounds

starting Bounds

required
bounds_b Bounds

destination Bounds

required

Returns:

Name Type Description
int

an int representing the direction of the adjacency between input bounds_a and bounds_b. The meaning of each case is as follows -

case 0 -> Bounds are not neighbours

case 1 -> bounds_b is the North-East corner of bounds_a

case 2 -> bounds_b is East of bounds_a

case 3 -> bounds_b is the South-East corner of bounds_a

case 4 -> bounds_b is South of bounds_a

case -1 -> bounds_b is the South-West corner of bounds_a

case -2 -> bounds_b is West of bounds_a

case -3 -> bounds_b is the North-West corner of bounds_a

case -4 -> bounds_b is North of bounds_a

get_neighbours(cellbox_indx, direction)

returns neighbour in a certain direction

increment_ids(inc)

Increments all ID's within the neighbour_graph by a given int inc

Args:
    inc (int): The number to increment all ID's in the neighbour_graph by

initialise_map(cellbox_indx, grid_width, cellboxes_length)

initialse the neighbour map of a cellbox with the given cellbox_index

initialise_neighbour_graph(cellboxes, grid_width)

initialize the neighbour graph

remove_neighbour(index, direction, neighbour_index)

remove certain neighbour in a specific direction

remove_node(cellbox_index)

method that removes a node to the neighbour_graph at a given index Args: cellbox_index (int): the index of the cellbox that will get removed from the neoghbpur_graph

remove_node_and_update_neighbours(cellbox_index)

method that removes a node in the neighbour_graph at a given index. remove_node_from_neighbours should be called first. Args: cellbox_index (int): the index of the cellbox that will get removed from the neighbour_graph

remove_node_from_neighbours(cellbox_indx, direction)

method that goes through neighbours in a given direction and remove cellbox_index from their neighbour_maps Args: cellbox_indx (int): the index of the cellbox that we will go through its neighbours and remove this index from their neighbour_map direction (int): an int that represents the direction of the neighbours that will get updated (e.g. north, south ,..)

update_corner_neighbours(cellbox_indx, north_west_indx, north_east_indx, south_west_indx, south_east_indx)

method that updates the corner neighbours of cellbox_indx with the given indeces

update_neighbour(index, direction, neighbours)

updates the neighbour in a certain direction

update_neighbours(cellbox_indx, new_neighbours_indx, direction, cellboxes)

method that updates the neighbour of a certain cellbox in a specific direction. It removes cellbox_indx from the neighbour_map of its neighbours in a specific direction and add new_neighbour_indx

Parameters:

Name Type Description Default
cellbox_index int

index of the cellbox that its neighbour will be updated

required
new_neighbour_indx int

the index of the new neighbour that will replace cellbox_index

required
direction int

an int that represents the direction of the neighbours that will get updated (e.g. north, south ,..)

required
cellboxes list<CellBox>

the list that contains all the cellboxes of the mesh

required