def test_pvt_model_table_parameters_description_equal():
    import numpy as np

    table_params_1 = case_description.PvtModelTableParametersDescription(
        pressure_values=np.array([0.0]),
        temperature_values=np.array([0.0]),
        table_variables=[],
        variable_names=[],
        number_of_phases=-1,
    )
    table_params_2 = case_description.PvtModelTableParametersDescription(
        pressure_values=np.array([0.0]),
        temperature_values=np.array([0.0]),
        table_variables=[np.array([1, 2])],
        variable_names=[],
        number_of_phases=-1,
    )
    table_params_3 = case_description.PvtModelTableParametersDescription(
        pressure_values=np.array([0.0]),
        temperature_values=np.array([0.0]),
        table_variables=[np.array([2, 3])],
        variable_names=[],
        number_of_phases=-1,
    )

    # To get coverage on check "if type(self) is not type(other)"
    assert table_params_1 != "s"

    # To get coverage on check "len(self.table_variables) != len(other.table_variables)"
    assert table_params_1 != table_params_2

    # To get coverage on check "if not np.array_equal(array1, array2)"
    assert table_params_3 != table_params_2
Esempio n. 2
0
def load_pvt_model_table_parameters_description_from_alfatable(
    file_path, ) -> case_description.PvtModelTableParametersDescription:
    """
    Load the content from the alfatable in the given file_path. The validation is turned off due to performance issues.
    """
    from ruamel import yaml as ruamelyaml
    from barril.units import Scalar
    import numpy as np

    content = ruamelyaml.safe_load(Path(file_path).read_text(encoding="UTF-8"))

    table_parameter_keys_and_values = {
        "pressure_values":
        np.array(content["pressure_values"]),
        "temperature_values":
        np.array(content["temperature_values"]),
        "table_variables":
        [np.array(value) for value in content["table_variables"]],
        "variable_names":
        content["variable_names"],
        "label":
        content.get("label", None),
        "number_of_phases":
        content["number_of_phases"],
        "warn_when_outside":
        content["warn_when_outside"],
    }
    key_and_unit = {
        "pressure_std": "bar",
        "temperature_std": "degC",
        "gas_density_std": "kg/m3",
        "oil_density_std": "kg/m3",
        "water_density_std": "kg/m3",
        "gas_oil_ratio": "sm3/sm3",
        "gas_liquid_ratio": "sm3/sm3",
        "water_cut": "-",
        "total_water_fraction": "-",
    }

    table_parameter_keys_and_scalars = {
        key: Scalar(get_category_for(unit), content[key]["value"],
                    content[key]["unit"])
        for key, unit in key_and_unit.items()
    }
    return case_description.PvtModelTableParametersDescription(
        **table_parameter_keys_and_values, **table_parameter_keys_and_scalars)
def test_pvt_model_table_parameters_description_post_init():
    """
    Check that standard properties that have not been informed (None) is converted to np.nan
    for more details about this, check the docstring from  PvtModelTableParametersDescription.__attrs_post_init__
    """
    import numpy as np

    table_params = case_description.PvtModelTableParametersDescription(
        pressure_std=None,
        temperature_std=None,
        gas_density_std=None,
        oil_density_std=None,
        water_density_std=None,
        gas_oil_ratio=None,
        gas_liquid_ratio=None,
        water_cut=None,
        total_water_fraction=None,
        # Required params
        pressure_values=np.ndarray([1]),
        temperature_values=np.ndarray([1]),
        table_variables=[np.ndarray([1])],
        variable_names=["str"],
    )
    assert table_params.pressure_std.value is np.nan
    assert table_params.temperature_std.value is np.nan
    assert table_params.gas_density_std.value is np.nan
    assert table_params.oil_density_std.value is np.nan
    assert table_params.water_density_std.value is np.nan
    assert table_params.gas_oil_ratio.value is np.nan
    assert table_params.gas_liquid_ratio.value is np.nan
    assert table_params.water_cut.value is np.nan
    assert table_params.total_water_fraction.value is np.nan

    # The following check are only for coverage purpose
    assert table_params.pressure_unit == "Pa"
    assert table_params.temperature_unit == "K"