TNO Intern

Commit be666768 authored by Hen Brett's avatar Hen Brett 🐔
Browse files

Setting up the utc check values test with the new property refactored jar file

parent 5cb899de
Loading
Loading
Loading
Loading
+0 −0

Empty file added.

+28 −0
Original line number Diff line number Diff line
import os
from pathlib import Path

from git import Repo
from pydantic import BaseModel, model_validator


class DoubletParameters(BaseModel):
    use_stimulation: bool = False
    use_heat_pump: bool = False
    hp_minimum_injection_temperature: float = 15
    max_cooling_temperature_range: float = 100
    stimKhMax: float = 20
    return_temperature: float = 30
    surface_temperature: float = 10
class Config(BaseModel):
    input_data_path: Path | None
    results_path: Path | None

    DoubletParameters : DoubletParameters


    @model_validator(mode="after")
    def set_paths(self):
        if not self.output_path:
            repo_path = Path(Repo(".", search_parent_directories=True).working_tree_dir)
            self.output_path = repo_path / "models" / self.model_name
        return self
+0 −0

Empty file added.

+107 −26
Original line number Diff line number Diff line
@@ -19,11 +19,13 @@ from jpype.types import *
class PyThermoGIS(TestCase):
    test_files_path = Path(path.dirname(path.dirname(__file__)), "resources") / "test_input"
    test_files_out_path = Path(path.dirname(path.dirname(__file__)), "resources") / "test_output"
    thermogis_jar_path = get_repo_root() / "resources" / "thermogis_jar" / "thermogis-1.7.0-shaded.jar"
    thermogis_jar_path = get_repo_root() / "resources" / "thermogis_jar" / "thermogis-1.7.0-shaded_newprops.jar"
    jvm_path = get_repo_root() / "resources" / "java" / "coretto-17" / "bin" / "server" / "jvm.dll"

    def setUp(self):
        outpath = Path(self.test_files_out_path)
        if outpath.exists():
            shutil.rmtree(outpath)
        outpath.mkdir(exist_ok=True)
        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"
@@ -43,12 +45,25 @@ class PyThermoGIS(TestCase):
        ProgressTracker = JClass("tno.geoenergy.gui.ProgressTracker")
        RNG = JClass("tno.geoenergy.stochastic.RandomNumberGenerator")
        ParallelTaskExecutor = JClass("thermogis.calc.ParallelTaskExecutor")
        UTCPropertiesBuilder = JClass("thermogis.properties.builders.UTCPropertiesBuilder")
        UnitTechnicalCost = JClass("thermogis.calc.steps.UnitTechnicalCost")
        ArrayList = JClass("java.util.ArrayList")

        # Instantiate ThermoGISProperties
        ThermoGISProperties = JClass("thermogis.gui.ThermoGISProperties")
        ThermoGISProperties.instantiateProperties()
        ThermoGISProperties.instantiateRunProperties()

        # Convert to java.util.List
        aquifers = ArrayList()
        for item in ["simplified", "simplified_stacked"]:
            aquifers.add(item)

        # Instantiate the UTC properties class
        propsBuilder = UTCPropertiesBuilder()
        propsBuilder.setInputDataDir(str(self.model_path) + "/InputData")
        propsBuilder.setResultsDir(str(self.model_path) + "/Results")
        propsBuilder.setCheckCopiedFiles(False)
        propsBuilder.setAquifers(aquifers)
        propsBuilder.setLevelOfDetail(1)
        propsBuilder.setPValues([50.0])
        utc_properties = propsBuilder.build()

        # Create instances of loggerMock, progressTrackerMock, taskExecutor and utc
        loggerMock = Mockito.mock(Logger)
@@ -58,16 +73,13 @@ class PyThermoGIS(TestCase):
        # Create UTC Instance
        utc = UnitTechnicalCost(progressTrackerMock, RNG(123), taskExecutor, loggerMock)

        # Create an instance of ArrayList with one value in it
        self.setupDefaultProperties(ThermoGISProperties)

        # Act
        utc.calculate()
        utc.calculate(utc_properties)

        # Assert
        self.checkOutputGridValues()

    def test_doublet(self):
    def test_doublet_single_values(self):
        if jpype.isJVMStarted():
            jpype.shutdownJVM()
        jpype.startJVM(str(self.jvm_path), classpath=[self.thermogis_jar_path])
@@ -95,7 +107,7 @@ class PyThermoGIS(TestCase):
        porosity = 0.27
        depth = 1990.0

        # Generated in runtime
        # Generated in runtime in the Java code
        khPvalue = 700.0
        kHQuantile = 139742.39

@@ -115,22 +127,91 @@ class PyThermoGIS(TestCase):
        # Assert
        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")
        Mockito = JClass("org.mockito.Mockito")
        RNG = JClass("tno.geoenergy.stochastic.RandomNumberGenerator")
        ThermoGISDoublet = JClass("thermogis.calc.doublet.ThermoGisDoublet")

        # Instantiate ThermoGISProperties
        ThermoGISProperties = JClass("thermogis.gui.ThermoGISProperties")
        ThermoGISProperties.instantiateProperties()
        ThermoGISProperties.instantiateRunProperties()
        self.setupDefaultProperties(ThermoGISProperties)

        # Create an instance of a ThermoGISDoublet
        doublet = ThermoGISDoublet(Mockito.mock(Logger), RNG(123))

        # Read grids
        thickness_grid = read_grid(self.model_path / "InputData" / "simplified__thick.zmap")
        thickness_sd_grid = read_grid(self.model_path / "InputData" / "simplified__thick_sd.zmap")
        ntg_grid = read_grid(self.model_path / "InputData" / "simplified__ntg.zmap")
        porosity_grid = read_grid(self.model_path / "InputData" / "simplified__phi.zmap")
        depth_grid = read_grid(self.model_path / "InputData" / "simplified__top.zmap")
        hc_accum_grid = read_grid(self.model_path / "InputData" / "simplified__hc_accum.zmap")

        ln_permeability_mean_grid = np.log(read_grid(self.model_path / "InputData" / "simplified__k.zmap"))
        ln_permeability_sd_grid = read_grid(self.model_path / "InputData" / "simplified__k_lnsd.zmap")

        # Calculate the reservoir temperature from a gradient of 31 degrees per km
        tres_grid = 10 + (depth_grid + thickness_grid / 2) * (31 * 0.001)

        # Generate thickness, permeability, and transmissivity for the current P-value
        hQuantile = thickness_grid
        kQuantile = ln_permeability_mean_grid
        kHQuantile_grid = np.exp(ln_permeability_mean_grid + np.log(thickness_grid))
        khPvalue_grid = kHQuantile_grid * ntg_grid / 1e3

        # Model Parameters from a config
        hp_minimum_injection_temperature = 15
        return_temperature = 30
        surface_temperature = 10
        max_cooling_temperature_range = 100
        stimKhMax = 20

        # Set Parameters on doublet
        for i in range(len(thickness_grid.x)):
            for j in range(len(thickness_grid.y)):

                depth = depth_grid.isel(x=i,y=j).data
                khPvalue = khPvalue_grid.isel(x=i,y=j).data
                porosity = porosity_grid.isel(x=i,y=j).data
                ntg = ntg_grid.isel(x=i,y=j).data
                tres = tres_grid.isel(x=i,y=j).data
                thickness = thickness_grid.isel(x=i,y=j).data
                khQuantile = kHQuantile_grid.isel(x=i,y=j).data

                set_doublet_parameters(doublet, False, stimKhMax, khPvalue, depth, porosity, ntg, tres, surface_temperature, return_temperature, False, max_cooling_temperature_range, hp_minimum_injection_temperature)
                doublet.calculateDoubletPerformance(-99999.0, thickness, khQuantile)



        # Assert
        # self.assertTrue(np.isclose(doublet.doubletCalc1DData.getFlowrate(), 499.975007564939, 1e-5))


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