# regrid.py

Script to change the grid to have different resolutions at different depths.

`regrid.``init_regrid`(self)

  Used in firn_density_spin for the initial regridding.

`regrid.``init_regrid22`(self)

  Splits the column in 5 grids: grid1(high res)-grid2(low res)-grid22(v. low res)-grid23(low res)-grid3(high res) Used in firn_density_spin for the initial regridding.

`regrid.``regrid`(self)

  Called in both firn_density_spin and firn_density_nospin

  There are 3 subgrids in the regrid module. Grid 1 is the high resolution grid near the surface. Grid 2 is the lower resolution grid at greater depths; a user-defined number of nodes (self.c[‘nodestocombine’]; refer as NTC here) are combined occasionally (every NTC time steps) to make one new node within grid 2. Grid 3 is at the bottom and has split up one grid 2 node back into a high-resolution grid (1 node into NTC nodes), which can be removed at each time step to keep the model Lagrangian.

  the variable gridtrack keeps track of which subgrid each node is in.

`regrid.``regrid22`(self)

  Called in both firn_density_spin and firn_density_nospin 5 grids:

  > grid1 -> high resolution determined by accumulation events grid2 -> low resolution by merging the batch of lowest nodestocombine layers of grid 1 grid22 -> very low resolution by merging the batch of lowest multnodestocombine layers of grid 2 grid23 -> low resolution by splitting the lowest layer of grid22 in multnodestocombine thinner layers New layer of grid23 is formed only when their stock is empty grid3 -> high resolution by splitting the lowest layer of grid23 in nodestocombine layers

  gridtrack keeps track of which grid each layer is in

`regrid.``regrid22_reciprocal`(self)

  Reciprocal of regrid22: must be called if we accumulate too many grid3 nodes because of heavy melting of surface nodes (problematic in ablation area) -> merge k batches of n1 grid3 nodes into k grid23 nodes (k is maximum nb of batches of n1 grid3 nodes available) if nb of layers in grid2 is <k:

  > -> calculate the nb of supplementary grid2 layers required -> calculate xx: the number of grid22 layers that must be split to provide the supplementary grid2 layers -> merge xx batches of n2 grid23 layers into xx grid22 layer -> divide xx grid22 layers into xx*n2 grid2 layers

  -> divide k grid2 layer into n1 grid1 layer

  5 grids:

    grid1 -> high resolution determined by accumulation events grid2 -> low resolution grid22 -> very low resolution grid23 -> low resolution grid3 -> high resolution

  gridtrack keeps track of which grid each layer is in