@classmethod
def cast_from_kw(cls, kw, grid, default_value=0):
    """Will convert a normal EclKW to a Ecl3DKW.

        The method will convert a normal EclKW instance to Ecl3DKw
        instance with an attached grid and a default value.

        The method will check that size of the keyword is compatible
        with the grid dimensions, i.e. the keyword must have either
        nactive or nx*ny*nz elements. If the size of the keyword is
        not compatible with the grid dimensions a ValueError exception
        is raised.

        Example:

          1. Load the poro keyword from a grdecl formatted file.
          2. Convert the keyword to a 3D keyword.


        from ecl.ecl import EclGrid,EclKW,Ecl3DKW

        grid = EclGrid("ECLIPSE.EGRID")
        poro = EclKW.read_grdecl(open("poro.grdecl") , "PORO")
        Ecl3DKW.castFromKW( poro , grid )

        print('Porosity in cell (10,11,12):%g' % poro[10,11,12])
        """
    if len(kw) == grid.getGlobalSize():
        kw.global_active = True
    elif len(kw) == grid.getNumActive():
        kw.global_active = False
    else:
        raise ValueError(
            'Size mismatch - must have size matching global/active size of grid'
            )
    kw.__class__ = cls
    kw.default_value = default_value
    kw.grid = grid
    if len(kw) == grid.getGlobalSize():
        kw.global_active = True
    else:
        kw.global_active = False
    kw.setDefault(default_value)
    return kw
