Beispiel #1
0
    def test_throw_on_invalid_recovery(self):
        recoveries = [("PARSE_RANDOM_SLASH", 3.14)]

        with self.assertRaises(TypeError):
            parse_context = ParseContext(recoveries)
            deck = Parser().parse(self.spe3fn, parse_context)

        with self.assertRaises(TypeError):
            parse_context = ParseContext("PARSE_RANDOM_SLASH")
            deck = Parser().parse(self.spe3fn, parse_context)
Beispiel #2
0
    def test_parse_ignore_keyword(self):
        deck_string = """
FIPNUM
  100*1 100*2 /

KEYWORD
  1 2 3 /
        """

        parse_context = ParseContext()
        parser = Parser()
        parse_context.ignore_keyword("KEYWORD")
        deck = parser.parse_string(deck_string, parse_context)
        self.assertEqual(len(deck), 1)
Beispiel #3
0
    def test_parser_section_deckItems(self):

        all_spe1case1 = [
            "RUNSPEC", "TITLE", "DIMENS", "EQLDIMS", "TABDIMS", "REGDIMS",
            "OIL", "GAS", "WATER", "DISGAS", "FIELD", "START", "WELLDIMS",
            "UNIFOUT", "UDQDIMS", "UDADIMS", "GRID", "INIT", "NOECHO", "DX",
            "DY", "DZ", "TOPS", "PORO", "PERMX", "PERMY", "PERMZ", "ECHO",
            "PROPS", "PVTW", "ROCK", "SWOF", "SGOF", "DENSITY", "PVDG", "PVTO",
            "REGIONS", "EQLNUM", "FIPNUM", "SOLUTION", "EQUIL", "RSVD",
            "SUMMARY", "FOPR", "WGOR", "FGOR", "BPR", "BGSAT", "WBHP", "WGIR",
            "WGIT", "WGPR", "WGPT", "WOIR", "WOIT", "WOPR", "WOPT", "WWIR",
            "WWIT", "WWPR", "WWPT", "WUOPRL", "SCHEDULE", "UDQ", "RPTSCHED",
            "RPTRST", "DRSDT", "WELSPECS", "COMPDAT", "WCONPROD", "WCONINJE",
            "TSTEP"
        ]

        # notice that RUNSPEC keywords will always be parsed since these properties from these keyword
        # are needed to parse following sections.

        props_spe1case1 = [
            "RUNSPEC", "TITLE", "DIMENS", "EQLDIMS", "TABDIMS", "REGDIMS",
            "OIL", "GAS", "WATER", "DISGAS", "FIELD", "START", "WELLDIMS",
            "UNIFOUT", "UDQDIMS", "UDADIMS", "GRID", "PVTW", "ROCK", "SWOF",
            "SGOF", "DENSITY", "PVDG", "PVTO"
        ]

        parser = Parser()

        error_recovery = [("PARSE_RANDOM_SLASH", opm.io.action.ignore),
                          ("PARSE_EXTRA_RECORDS", opm.io.action.ignore)]

        context = ParseContext(error_recovery)

        deck1 = parser.parse(test_path("data/SPE1CASE1.DATA"), context)

        self.assertEqual(len(deck1), len(all_spe1case1))

        test_1 = [dkw.name for dkw in deck1]

        for test, ref in zip(test_1, all_spe1case1):
            self.assertEqual(test, ref)

        section_list = [eclSectionType.PROPS]

        deck2 = parser.parse(test_path("data/SPE1CASE1.DATA"), context,
                             section_list)

        self.assertEqual(len(deck2), len(props_spe1case1))

        test_2 = [dkw.name for dkw in deck2]

        for test, ref in zip(test_2, props_spe1case1):
            self.assertEqual(test, ref)

        # props section keyword located in include file for this deck (SPE1CASE1B.DATA)
        # not possible to parse individual sections

        with self.assertRaises(RuntimeError):
            parser.parse(test_path("data/SPE1CASE1B.DATA"), context,
                         section_list)
Beispiel #4
0
    def test_parse_with_multiple_recoveries(self):
        recoveries = [("PARSE_RANDOM_SLASH", opm.io.action.ignore),
                      ("FOO", opm.io.action.warn),
                      ("PARSE_RANDOM_TEXT", opm.io.action.throw)]

        parse_context = ParseContext(recoveries)
        deck = Parser().parse(self.spe3fn, parse_context)
        state = EclipseState(deck)
Beispiel #5
0
    def test_parse_norne(self):
         parse_context = ParseContext( [('PARSE_RANDOM_SLASH', opm.io.action.ignore)] )
         deck = Parser().parse(self.norne_fname, parse_context)
         es = EclipseState( deck )

         self.assertEqual(46, es.grid().nx)
         self.assertEqual(112, es.grid().ny)
         self.assertEqual(22, es.grid().nz)
Beispiel #6
0
    def test_raw_string_output(self):
        deck_string = """
UDQ
   DEFINE WUOPR2   WOPR '*' * WOPR '*' /
   DEFINE WUGASRA  3 - WGLIR '*' /
/
        """

        parse_context = ParseContext( )
        parser = Parser()
        parse_context.ignore_keyword("KEYWORD")
        deck = parser.parse_string( deck_string )
        udq = deck[0]
        s = ""
        for rec in udq:
            for item in rec:
                s += item.get_str(0)
Beispiel #7
0
def parse(fname):
    s = dt.now()
    ps = ParseContext([('PARSE_RANDOM_SLASH', opm.io.action.ignore)])
    deck = Parser().parse(fname, ps)
    es = EclipseState(deck)
    e = dt.now()
    print('Parsing took %s sec' % (e - s).seconds)
    return es
Beispiel #8
0
    def test_parser_deckItems(self):

        parser = Parser()

        error_recovery = [("PARSE_RANDOM_SLASH", opm.io.action.ignore),
                          ("PARSE_EXTRA_RECORDS", opm.io.action.ignore)]

        context = ParseContext(error_recovery)

        self.deck_spe1case1 = parser.parse(test_path("data/SPE1CASE1.DATA"),
                                           context)

        dkw_compdate = self.deck_spe1case1["COMPDAT"]

        self.assertTrue(dkw_compdate[0][0].is_string())
        self.assertFalse(dkw_compdate[0][1].is_string())

        self.assertTrue(dkw_compdate[0][1].is_int())
        self.assertFalse(dkw_compdate[0][1].is_double())

        self.assertTrue(dkw_compdate[0][8].is_double())

        self.assertTrue(dkw_compdate[0][0].value == "PROD")

        conI = dkw_compdate[0][1].value
        conJ = dkw_compdate[0][2].value
        conK = dkw_compdate[0][3].value

        self.assertEqual(dkw_compdate[0][5].value, "OPEN")

        self.assertTrue((conI, conJ, conK) == (10, 10, 3))

        self.assertFalse(dkw_compdate[0][7].valid)
        self.assertTrue(dkw_compdate[0][7].defaulted)

        self.assertEqual(dkw_compdate[0][6].value, 0)

        self.assertEqual(dkw_compdate[0][8].value, 0.5)

        dkw_wconprod = self.deck_spe1case1["WCONPROD"]

        welln = dkw_wconprod[0][0].value
        self.assertEqual(dkw_wconprod[0][2].value, "ORAT")
        self.assertEqual(dkw_wconprod[0][3].value, "WUOPRL")
        self.assertEqual(dkw_wconprod[0][5].value, 1.5e5)

        dkw_permx = self.deck_spe1case1["PERMX"]
        permx = dkw_permx.get_raw_array()
        self.assertEqual(len(permx), 300)
        self.assertTrue(isinstance(permx, np.ndarray))
        self.assertEqual(permx.dtype, "float64")

        dkw_eqlnum = self.deck_spe1case1["EQLNUM"]
        eqlnum = dkw_eqlnum.get_int_array()

        self.assertEqual(len(eqlnum), 300)
        self.assertTrue(isinstance(eqlnum, np.ndarray))
        self.assertEqual(eqlnum.dtype, "int32")
Beispiel #9
0
    def test_create(self):
        parser = Parser()
        deck = parser.parse(self.spe3fn)

        context = ParseContext()
        deck = parser.parse(self.spe3fn, context)

        with open(self.spe3fn) as f:
            string = f.read()
        deck = parser.parse_string(string)
        deck = parser.parse_string(string, context)
Beispiel #10
0
    def test_parser_extension(self):
        error_recovery = [("PARSE_RANDOM_SLASH", opm.io.action.ignore)]

        parse_context = ParseContext(error_recovery)
        parser = Parser()
        for kw in self.KEYWORDS:
            parser.add_keyword(json.dumps(kw))

        deck = parser.parse_string(self.DECK_ADDITIONAL_KEYWORDS,
                                   parse_context)

        self.assertIn('TESTKEY0', deck)
        self.assertIn('TESTKEY1', deck)
        self.assertIn('TESTKEY2', deck)
Beispiel #11
0
    def test_create(self):
        parser = Parser()
        deck = parser.parse(self.spe3fn)
        active_unit_system = deck.active_unit_system()
        default_unit_system = deck.default_unit_system()
        self.assertEqual(active_unit_system.name, "Field")

        context = ParseContext()
        deck = parser.parse(self.spe3fn, context)

        with open(self.spe3fn) as f:
            string = f.read()
        deck = parser.parse_string(string)
        deck = parser.parse_string(string, context)
Beispiel #12
0
 def test_parse_with_recovery(self):
     recovery = [("PARSE_RANDOM_SLASH", opm.io.action.ignore)]
     parse_context = ParseContext(recovery)
     deck = Parser().parse(self.spe3fn, parse_context)
     state = EclipseState(deck)
Beispiel #13
0
 def test_parser_fail_without_extension(self):
     error_recovery = [("PARSE_RANDOM_SLASH", opm.io.action.ignore)]
     with self.assertRaises(RuntimeError):
         parse_context = ParseContext(error_recovery)
         deck = Parser().parse_string(self.DECK_ADDITIONAL_KEYWORDS,
                                      parse_context)