File: test_basic.py

package info (click to toggle)
opm-simulators 2025.10%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,460 kB
  • sloc: cpp: 193,029; sh: 1,807; python: 1,704; lisp: 1,108; makefile: 31; awk: 10
file content (87 lines) | stat: -rwxr-xr-x 4,539 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
import unittest
from pathlib import Path
from .pytest_common import pushd, create_black_oil_simulator, create_gas_water_simulator, create_onephase_simulator

class TestBasic(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        test_dir = Path(os.path.dirname(__file__))
        cls.data_dir_bo = test_dir.parent.joinpath("test_data/SPE1CASE1a")
        cls.data_dir_op = test_dir.parent.joinpath("test_data/SPE1CASE1")
        cls.data_dir_gw = test_dir.parent.joinpath("test_data/SPE1CASE2")

    # IMPORTANT: Since all the python unittests run in the same process we must be
    #  careful to not call MPI_Init() more than once.
    #  Tests are run alphabetically, so we need to make sure that
    #  the the first test calls MPI_Init(), therefore the name of the tests
    #  have a numeric label like "01" in test_01_blackoil to ensure that they
    #  are run in a given order.

    # IMPORTANT: This test must be run first since it calls MPI_Init()
    def test_01_blackoil(self):
        with pushd(self.data_dir_bo):
            sim = create_black_oil_simulator(args=['--linear-solver=ilu0'], filename="SPE1CASE1.DATA")
            sim.setup_mpi(init=True, finalize=False)
            sim.step_init()
            sim.step()
            dt = sim.get_dt()
            # NOTE: the timestep size is reduced to 1 day to avoid regression failures
            # due to changes in time stepping.
            # NOTE: The timestep should be 1 day
            #  = 24 * 60 * 60 seconds = 86400 seconds
            self.assertAlmostEqual(dt, 86400., places=7, msg='value of timestep')
            vol = sim.get_cell_volumes()
            self.assertEqual(len(vol), 300, 'length of volume vector')
            # NOTE: The volume should be 1000 ft x 1000 ft x 20 ft * 0.3 (porosity)
            #  = 600000 ft^3 = 566336.93 m^3
            self.assertAlmostEqual(vol[0], 566336.93, places=2, msg='value of volume')
            poro = sim.get_porosity()
            self.assertEqual(len(poro), 300, 'length of porosity vector')
            self.assertAlmostEqual(poro[0], 0.3, places=7, msg='value of porosity')
            poro = poro *.95
            sim.set_porosity(poro)
            sim.step()
            poro2 = sim.get_porosity()
            self.assertAlmostEqual(poro2[0], 0.285, places=7, msg='value of porosity 2')

    def test_02_onephase(self):
        with pushd(self.data_dir_op):
            sim = create_onephase_simulator(args=['--linear-solver=ilu0'], filename="SPE1CASE1_WATER.DATA")
            sim.setup_mpi(init=False, finalize=False)
            sim.step_init()
            sim.step()
            dt = sim.get_dt()  # 31 days = 31 * 24 * 60 * 60 = 2678400 seconds
            self.assertAlmostEqual(dt, 2678400., places=7, msg='value of timestep')
            vol = sim.get_cell_volumes()
            self.assertEqual(len(vol), 300, 'length of volume vector')
            self.assertAlmostEqual(vol[0], 566336.93, places=2, msg='value of volume')
            poro = sim.get_porosity()
            self.assertEqual(len(poro), 300, 'length of porosity vector')
            self.assertAlmostEqual(poro[0], 0.3, places=7, msg='value of porosity')
            poro = poro *.95
            sim.set_porosity(poro)
            sim.step()
            poro2 = sim.get_porosity()
            self.assertAlmostEqual(poro2[0], 0.285, places=7, msg='value of porosity 2')

    # IMPORTANT: This test must be run last since it calls MPI_Finalize()
    def test_99_gaswater(self):
        with pushd(self.data_dir_gw):
            sim = create_gas_water_simulator(args=['--linear-solver=ilu0'], filename="SPE1CASE2_GASWATER.DATA")
            sim.setup_mpi(init=False, finalize=True)
            sim.step_init()
            sim.step()
            dt = sim.get_dt()  # 31 days = 31 * 24 * 60 * 60 = 2678400 seconds
            self.assertAlmostEqual(dt, 2678400., places=7, msg='value of timestep')
            vol = sim.get_cell_volumes()
            self.assertEqual(len(vol), 300, 'length of volume vector')
            self.assertAlmostEqual(vol[0], 566336.93, places=2, msg='value of volume')
            poro = sim.get_porosity()
            self.assertEqual(len(poro), 300, 'length of porosity vector')
            self.assertAlmostEqual(poro[0], 0.3, places=7, msg='value of porosity')
            poro = poro *.95
            sim.set_porosity(poro)
            sim.step()
            poro2 = sim.get_porosity()
            self.assertAlmostEqual(poro2[0], 0.285, places=7, msg='value of porosity 2')