# Adding new refinement criteria¶

1. Add any new parameters you might need. (See Adding a new parameter to Enzo.)
2. Write your code to flag the cells
3. Call your method.

The first point has been discussed elsewhere.

## Writing your code to flag cells¶

Your code needs to do a couple things:

1. Be named `FlagCellsToBeRefinedByXXXXXX`, where `XXXXXX` is your criterion.
2. Increment `FlaggingField[i]`
3. Count and return the number of flaggged cells.
4. Return -1 on error.

Your code to do the cell flagging can be a grid method.

A minimal code should look like this:

```int grid::FlagCellsToBeRefinedByDensityOverTwelve(){

int NumberOfFlaggedCells = 0;
for( int i = 0; i< GridDimension[0]*GridDimension[1]*GridDimension[2]; i++ ){
if( BaryonField[0][i] > 12 ){
FlaggingField[i] ++;
NumberOfFlaggedCells ++;
}
}
return NumberOfFlaggedCells;

}
```

## Call your method¶

Edit the file `Grid_SetFlaggingField.C` In this routine, there’s a loop over the `CellFlaggingMethod` array. In this loop, you’ll see code like this:

```  /* ==== METHOD 47: By Density over 12 ==== */

case 47:

NumberOfFlaggedCells = this->FlagCellsToBeRefinedByDensityOverTwelve();
if (NumberOfFlaggedCells < 0) {
fprintf(stderr, "Error in grid->FlagCellsToBeRefinedByDensityOverTwelve.\n");
return FAIL;
}
break;
```

So we need to add a few things.

• Add a new case statement to the switch construct.
• Set `NumberOfFlaggedCells` via the method described above.
• Don’t forget the break; statement.
• Check for errors.