TNO Intern

Commit 58b5329a authored by Hen Brett's avatar Hen Brett 🐔
Browse files

Ensuring that an independent doublet processes grids the same as the Java-code run from utc

parent b2cbdec9
Loading
Loading
Loading
Loading
+10 −102
Original line number Diff line number Diff line
@@ -2,7 +2,10 @@ import copy
import shutil
from os import path
from pathlib import Path
from time import sleep
from unittest import TestCase

from tqdm import tqdm
import xarray as xr

# Import java classes
@@ -32,13 +35,15 @@ class PyThermoGIS(TestCase):
        shutil.copytree(self.test_files_path / "model_jpype" / "simplified_preprocess_result", self.test_files_out_path / "simplified_preprocess_result")
        self.model_path = self.test_files_out_path / "simplified_preprocess_result"

        # Start JVM
        if jpype.isJVMStarted():
            jpype.shutdownJVM()
        jpype.startJVM(str(self.jvm_path), classpath=[self.thermogis_jar_path])

    def tearDown(self):
        shutil.rmtree(self.test_files_out_path)

    def test_doublet_single_values(self):
        if jpype.isJVMStarted():
            jpype.shutdownJVM()
        jpype.startJVM(str(self.jvm_path), classpath=[self.thermogis_jar_path])

        # Arrange
        # Import Java Classes
@@ -82,10 +87,6 @@ class PyThermoGIS(TestCase):
        self.assertTrue(np.isclose(doublet.doubletCalc1DData.getFlowrate(), 499.975007564939, 1e-5))

    def test_doublet_grid(self):
        if jpype.isJVMStarted():
            jpype.shutdownJVM()
        jpype.startJVM(str(self.jvm_path), classpath=[self.thermogis_jar_path])

        # Arrange
        # Import Java Classes
        Logger = JClass("logging.Logger")
@@ -167,6 +168,7 @@ class PyThermoGIS(TestCase):
                flow_rate_grid.values[j, i] = output_values["flow_rate"]
                welld_grid.values[j, i] = output_values["welld"]

        # Check values against benchmark grids
        xr.testing.assert_allclose(power_grid, read_grid(self.test_benchmark_output / "simplified__power_P50.nc"), atol=0.1)
        xr.testing.assert_allclose(utc_grid, read_grid(self.test_benchmark_output / "simplified__utc_P50.nc"), atol=0.1)
        xr.testing.assert_allclose(npv_grid, read_grid(self.test_benchmark_output / "simplified__npv_P50.nc"), atol=0.1)
@@ -175,97 +177,3 @@ class PyThermoGIS(TestCase):
        xr.testing.assert_allclose(pres_grid, read_grid(self.test_benchmark_output / "simplified__pres_P50.nc"), atol=0.1)
        xr.testing.assert_allclose(flow_rate_grid, read_grid(self.test_benchmark_output / "simplified__flowr_P50.nc"), atol=2)
        xr.testing.assert_allclose(welld_grid, read_grid(self.test_benchmark_output / "simplified__welld_P50.nc"), atol=0.1)
 No newline at end of file

    def checkOutputGridValues(self):
        flowRateGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__flowr_P50.nc")
        copGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__cop_P50.nc")
        thicknessGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__h_P50.nc")
        hProdGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__hprod_P50.nc")
        permeabilityGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__k_P50.nc")
        khGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__kh_P50.nc")
        npvGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__npv_P50.nc")
        ntgGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__ntg.nc")
        porosityGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__porosity.nc")
        powerGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__power_P50.nc")
        pressureGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__pres_P50.nc")
        temperatureGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__temperature.nc")
        topDepthGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__top_depth.nc")
        utcGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__utc_P50.nc")
        wellDepthGrid = read_grid(self.model_path / "Results" / "simplified" / "BaseCase" / "simplified__welld_P50.nc")

        tolerance = 0.00001

        # // Flow rate
        self.assertTrue(np.isclose(0.000000, flowRateGrid.min(), 0.000001))
        self.assertTrue(np.isclose(499.99496459, flowRateGrid.max(), 0.000001))
        self.assertTrue(np.isclose(421.22686768, flowRateGrid.mean(), 0.00001))

        # // COP
        self.assertTrue(np.isclose(0.000000, copGrid.min(), 0.000001))
        self.assertTrue(np.isclose(29.10140991, copGrid.max(), 0.000001))
        self.assertTrue(np.isclose(20.41528702, copGrid.mean(), 0.000001))

        # // Thickness
        self.assertTrue(np.isclose(175.0, thicknessGrid.min(), 0.000001))
        self.assertTrue(np.isclose(205.0, thicknessGrid.max(), 0.0001))
        self.assertTrue(np.isclose(195.666671, thicknessGrid.mean(), 0.00001))

        # // H Prod
        self.assertTrue(np.isclose(0.000000, hProdGrid.min(), tolerance))
        self.assertTrue(np.isclose(3093648.75, hProdGrid.max(), tolerance))
        self.assertTrue(np.isclose(2592955.00000000, hProdGrid.mean(), tolerance))

        # // Permeability
        self.assertTrue(np.isclose(100.00000000, permeabilityGrid.min(), tolerance))
        self.assertTrue(np.isclose(900.00000000, permeabilityGrid.max(), tolerance))
        self.assertTrue(np.isclose(500.00000000, permeabilityGrid.mean(), tolerance))

        # // KH
        self.assertTrue(np.isclose(17.35536957, khGrid.min(), tolerance))
        self.assertTrue(np.isclose(164.42192078, khGrid.max(), tolerance))
        self.assertTrue(np.isclose(94.08833313, khGrid.mean(), tolerance))

        # // NPV
        self.assertTrue(np.isclose(0.0, npvGrid.min(), tolerance))
        self.assertTrue(np.isclose(5.36793852, npvGrid.max(), tolerance))
        self.assertTrue(np.isclose(3.52801609, npvGrid.mean(), tolerance))

        # // NTG
        self.assertTrue(np.isclose(0.94, ntgGrid.min(), tolerance))
        self.assertTrue(np.isclose(0.99000001, ntgGrid.max(), tolerance))
        self.assertTrue(np.isclose(0.95333332, ntgGrid.mean(), tolerance))

        # // Porosity
        self.assertTrue(np.isclose(25.0, porosityGrid.min(), tolerance))
        self.assertTrue(np.isclose(27.0, porosityGrid.max(), tolerance))
        self.assertTrue(np.isclose(26.0, porosityGrid.mean(), tolerance))

        # // Power
        self.assertTrue(np.isclose(0.000000, powerGrid.min(), tolerance))
        self.assertTrue(np.isclose(24.44868851, powerGrid.max(), tolerance))
        self.assertTrue(np.isclose(20.49176979, powerGrid.mean(), tolerance))

        # // Pressure
        self.assertTrue(np.isclose(0.000000, pressureGrid.min(), tolerance))
        self.assertTrue(np.isclose(60.59999847, pressureGrid.max(), tolerance))
        self.assertTrue(np.isclose(42.27748108, pressureGrid.mean(), tolerance))

        # // Temperature
        self.assertTrue(np.isclose(74.71250153, temperatureGrid.min(), tolerance))
        self.assertTrue(np.isclose(75.42550659, temperatureGrid.max(), tolerance))
        self.assertTrue(np.isclose(75.17062378, temperatureGrid.mean(), tolerance))

        # // Top depth
        self.assertTrue(np.isclose(1990.0, topDepthGrid.min(), tolerance))
        self.assertTrue(np.isclose(2020.0, topDepthGrid.max(), tolerance))
        self.assertTrue(np.isclose(2004.44445801, topDepthGrid.mean(), tolerance))

        # // Unit technical cost
        self.assertTrue(np.isclose(0.0000, utcGrid.min(), tolerance))
        self.assertTrue(np.isclose(5.03445578, utcGrid.max(), tolerance))
        self.assertTrue(np.isclose(4.10233593, utcGrid.mean(), tolerance))

        # // Well depth
        self.assertTrue(np.isclose(0.000000, wellDepthGrid.min(), tolerance))
        self.assertTrue(np.isclose(1193.16406250, wellDepthGrid.max(), tolerance))
        self.assertTrue(np.isclose(1019.05383301, wellDepthGrid.mean(), tolerance))