예제 #1
0
def test_remove_redundant_input_type_data_option(
        remove: bool, input_type: MultiInputType) -> None:
    mass_source_equipment_description = case_description.MassSourceEquipmentDescription(
        position=Scalar(0, "m"), temperature_input_type=input_type)
    yaml = convert_description_to_alfacase(
        mass_source_equipment_description,
        remove_redundant_input_type_data=remove)

    def has_key_in_yaml(key: str) -> bool:
        pattern = rf"^\s*{re.escape(key)}\s*:"
        return bool(re.search(pattern, yaml, re.MULTILINE))

    if remove:
        assert not has_key_in_yaml("temperature_input_type")
        if input_type == MultiInputType.Constant:
            assert has_key_in_yaml("temperature")
            assert not has_key_in_yaml("temperature_curve")
        elif input_type == MultiInputType.Curve:
            assert not has_key_in_yaml("temperature")
            assert has_key_in_yaml("temperature_curve")

    else:
        assert has_key_in_yaml("temperature_input_type")
        assert has_key_in_yaml("temperature")
        assert has_key_in_yaml("temperature_curve")
예제 #2
0
    def test_pipe_pvt_model(self, default_case, default_well):
        """
        If a Elements on case uses an invalid PvtModel, the pvt_model must reset to None when calling ResetInvalidReferences()
        """
        case = attr.evolve(
            default_case,
            nodes=[
                case_description.NodeDescription(
                    name="Node 1",
                    node_type=NodeCellType.Pressure,
                    pvt_model="InvalidPVT",
                )
            ],
            wells=[
                attr.evolve(
                    default_well,
                    pvt_model="InvalidPVT",
                    annulus=case_description.AnnulusDescription(
                        has_annulus_flow=False,
                        pvt_model="InvalidPVT",
                        top_node="Node 1",
                    ),
                )
            ],
            pipes=[
                case_description.PipeDescription(
                    name="Pipe 1",
                    pvt_model="InvalidPVT",
                    source="in",
                    target="out",
                    profile=_empty_profile(),
                    segments=build_simple_segment(),
                    equipment=case_description.EquipmentDescription(
                        mass_sources={
                            "Mass Equip. 1": case_description.MassSourceEquipmentDescription(
                                position=Scalar(0, "m")
                            )
                        }
                    ),
                )
            ],
        )

        case.reset_invalid_references()
        assert case.pipes[0].pvt_model is None
        assert case.nodes[0].pvt_model is None
        assert case.wells[0].pvt_model is None
        assert case.wells[0].annulus.pvt_model is None
def test_invalid_fluid_reference_on_pipes():
    """
    Ensure that only declared Fluids can be used on:
       PipeDescription, MassSourceEquipmentDescription, ReservoirInflowEquipmentDescription.
    """
    case = case_description.CaseDescription(
        pvt_models=case_description.PvtModelsDescription(
            default_model="PVT",
            compositions={
                "PVT":
                case_description.PvtModelCompositionalDescription(
                    fluids={"Fluid 1": case_description.FluidDescription()})
            },
        ),
        pipes=[
            case_description.PipeDescription(
                name="Pipe 1",
                source="",
                target="",
                segments=build_simple_segment(),
                initial_conditions=case_description.
                InitialConditionsDescription(fluid="acme5"),
                equipment=case_description.EquipmentDescription(
                    mass_sources={
                        "MassSource":
                        case_description.MassSourceEquipmentDescription(
                            position=Scalar(1, "m"), fluid="a6")
                    },
                    reservoir_inflows={
                        "Reservoir":
                        case_description.ReservoirInflowEquipmentDescription(
                            start=Scalar(1, "m"),
                            length=Scalar(10, "m"),
                            fluid="a7")
                    },
                ),
            )
        ],
    )
    expected_error = "The following elements have an invalid fluid assigned: 'MassSource from Pipe 1', 'Pipe 1', 'Reservoir from Pipe 1'."
    with pytest.raises(InvalidReferenceError, match=re.escape(expected_error)):
        case.ensure_valid_references()
    ),
    temperatures=case_builders.build_constant_initial_temperatures_description(
        123.4, "K"
    ),
    fluid="fluid_1",
)
MASS_SOURCE_DESCRIPTION = case_description.MassSourceEquipmentDescription(
    position=Scalar(10, "m"),
    gas_oil_ratio=Scalar(100.0, "sm3/sm3", get_category_for("sm3/sm3")),
    water_cut=Scalar(0.2, "-", "volume fraction"),
    volumetric_flow_rates_std={
        "gas": Scalar(1000.5, "sm3/d"),
        "oil": Scalar(20.5, "sm3/d"),
        "water": Scalar(20.5, "sm3/d"),
    },
    tracer_mass_fraction=Array([1.0], "-", "mass fraction"),
    temperature=Scalar(15, "degC"),
    fluid="fluid_1",
    source_type=constants.MassSourceType.MassFlowRates,
    mass_flow_rates={
        constants.FLUID_GAS: Scalar(0.005, "kg/s"),
        constants.FLUID_OIL: Scalar(0.5, "kg/s"),
        constants.FLUID_WATER: Scalar(0.001, "kg/s"),
    },
)
MATERIAL_DESCRIPTION = case_description.MaterialDescription(
    name="Durepoxi",
    material_type=constants.MaterialType.Fluid,
    density=Scalar("density", 2900.0, "kg/m3"),
    heat_capacity=Scalar("specific heat capacity", 1000.0, "J/kg.degC"),
    thermal_conductivity=Scalar("thermal conductivity", 5.9, "W/m.degC"),
예제 #5
0
MASS_SOURCE_DESCRIPTION = case_description.MassSourceEquipmentDescription(
    position=Scalar(10, "m"),
    gas_oil_ratio=Scalar(100.0, "sm3/sm3", get_category_for("sm3/sm3")),
    water_cut=Scalar(0.2, "-", "volume fraction"),
    volumetric_flow_rates_std_input_type=constants.MultiInputType.Constant,
    volumetric_flow_rates_std={
        "gas": Scalar(1000.5, "sm3/d"),
        "oil": Scalar(20.5, "sm3/d"),
        "water": Scalar(20.5, "sm3/d"),
    },
    volumetric_flow_rates_std_curve={
        "gas": Curve(Array([1000.5, 2000.5], "sm3/d"), Array([0, 3.5], "s")),
        "oil": Curve(Array([20.5, 30.5], "sm3/d"), Array([0, 2.0], "s")),
        "water": Curve(Array([20.5, 10.5], "sm3/d"), Array([0, 10], "s")),
    },
    tracer_mass_fraction=Array([1.0, 0.0], "-", "mass fraction"),
    temperature=Scalar(15, "degC"),
    fluid="fluid_1",
    source_type=constants.MassSourceType.MassFlowRates,
    mass_flow_rates_input_type=constants.MultiInputType.Constant,
    mass_flow_rates={
        constants.FLUID_GAS: Scalar(0.005, "kg/s"),
        constants.FLUID_OIL: Scalar(0.5, "kg/s"),
        constants.FLUID_WATER: Scalar(0.001, "kg/s"),
    },
    mass_flow_rates_curve={
        constants.FLUID_GAS: Curve(Array([0.005, 0.009], "kg/s"), Array([0, 5], "s")),
        constants.FLUID_OIL: Curve(Array([0.5, 0.3], "kg/s"), Array([0, 2], "s")),
        constants.FLUID_WATER: Curve(Array([0.001, 0.002], "kg/s"), Array([0, 7], "s")),
    },
)