Search code examples
oceanpetrel

How to access the values of a dictionary property in a grid using Ocean for Petrel?


I'm tring to access the values of a dictionary property in a grid,such as Fluvial facies or lithologies etc.I have read the coursebook and help docs, but didn't find anything relevant.The coursebook only has examples of creating properties, but not accessing properties.Below is the code I tried:

Grid grid = arguments.Input_Grid;
if (grid == null)
{
    PetrelLogger.ErrorStatus("HelloGrid: Arguments cannot be empty.");
    return;
}
Index3 currentCell = new Index3();
int maxI = grid.NumCellsIJK.I;
int maxJ = grid.NumCellsIJK.J;
int maxK = grid.NumCellsIJK.K;
for (int i = 0; i < maxI; i++)
{
    for (int j = 0; j < maxJ; j++)
    {
        for (int k = 0; k < maxK; k++)
        {                            
             currentCell.I = i; currentCell.J = j; currentCell.K = k;                 
             if (grid.IsCellDefined(currentCell) && grid.HasCellVolume(currentCell))
             {                         
                 //DictionaryProperty p =  ???
                 //int val = p[currentCell] ???
             }
         }
     }
 }

enter image description here


Solution

  • You need to use the "FastDictionaryPropertyIndexer" or "FastPropertyIndexer" for regular properties.

    foreach (var dictProp in grid.DictionaryProperties)
    {
        int numCellsI = dictProp.NumCellsIJK[0];
        int numCellsJ = dictProp.NumCellsIJK[1];
        int numCellsK = dictProp.NumCellsIJK[2];
        
        float[] values = new float[dictProp.NumCells];
        var dpsa = dictProp.SpecializedAccess;
        using (var fdpi = dpsa.OpenFastDictionaryPropertyIndexer())
        {
            int index = 0;
            for (int k = 0; k < numCellsK; k++)
            {
                for (int j = 0; j < numCellsJ; j++)
                {
                    for (int i = 0; i < numCellsI; i++)
                    {
                        values[index] = fdpi[i, j, k];
                        index++;
                    }
                }
            }
        }
    }
    

    You also need to be careful about the indexing since it varies by project. For instance, you may need to reverse the order of traversal in the J direction or you could end up with some strange results.