def default_case(tmp_path) -> case_description.CaseDescription:
    """
    Minimum valid CaseDescription with pvt configured
    """
    tab_file = tmp_path / "dummy.tab"
    file_content = [
        'PVTTABLE LABEL = "PVT1",PHASE = THREE,',
        'PVTTABLE LABEL = "PVT2", PHASE = THREE,',
    ]
    tab_file.write_text("\n".join(file_content))
    return case_description.CaseDescription(
        pvt_models=case_description.PvtModelsDescription(
            default_model="PVT2",
            tables={"PVT1": f"{tab_file}"},
            correlations={
                "PVT2": case_description.PvtModelCorrelationDescription()
            },
            compositions={
                "PVT3": case_description.PvtModelCompositionalDescription()
            },
            table_parameters={
                "PVT4":
                case_description.PvtModelTableParametersDescription.
                create_empty()
            },
        ))
def test_invalid_fluid_reference_on_wells(default_well):
    """
    Ensure that only declared Fluids can be used on WellDescription and AnnulusDescription.
    """
    case = case_description.CaseDescription(
        pvt_models=case_description.PvtModelsDescription(
            default_model="PVT",
            compositions={
                "PVT":
                case_description.PvtModelCompositionalDescription(
                    fluids={"Fluid 1": case_description.FluidDescription()})
            },
        ),
        wells=[
            attr.evolve(
                default_well,
                initial_conditions=attr.evolve(
                    default_well.initial_conditions,
                    fluid="acme",
                ),
                annulus=attr.evolve(
                    default_well.annulus,
                    initial_conditions=attr.evolve(
                        default_well.annulus.initial_conditions,
                        fluid="acme",
                    ),
                ),
            )
        ],
    )
    expected_error = "The following elements have an invalid fluid assigned: 'Annulus from Well 1', 'Well 1'."
    with pytest.raises(InvalidReferenceError, match=re.escape(expected_error)):
        case.ensure_valid_references()
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()
Exemplo n.º 4
0
def test_invalid_fluid_reference_on_nodes():
    """
    Ensure that only declared Fluids can be used on NodeDescription
    """
    case = case_description.CaseDescription(
        pvt_models=case_description.PvtModelsDescription(
            default_model="PVT",
            compositional={
                "PVT": case_description.PvtModelCompositionalDescription(
                    fluids={"Fluid 1": case_description.CompositionalFluidDescription()}
                )
            },
        ),
        nodes=[
            case_description.NodeDescription(
                name="Node 1",
                node_type=NodeCellType.Internal,
                internal_properties=case_description.InternalNodePropertiesDescription(
                    fluid="Acme2"
                ),
            ),
            case_description.NodeDescription(
                name="Node 2",
                node_type=NodeCellType.Pressure,
                pressure_properties=case_description.PressureNodePropertiesDescription(
                    fluid="Acme3"
                ),
            ),
            case_description.NodeDescription(
                name="Node 3",
                node_type=NodeCellType.MassSource,
                mass_source_properties=case_description.MassSourceNodePropertiesDescription(
                    fluid="Acme4"
                ),
            ),
        ],
    )

    expected_error = "The following elements have an invalid fluid assigned: 'Node 1', 'Node 2', 'Node 3'."
    with pytest.raises(InvalidReferenceError, match=re.escape(expected_error)):
        case.ensure_valid_references()
PVT_MODEL_CORRELATION_DEFINITION = case_description.PvtModelCorrelationDescription(
    oil_density_std=Scalar(42, "kg/m3"),
    gas_density_std=Scalar(2, "kg/m3"),
    rs_sat=Scalar(4, "sm3/sm3"),
    pvt_correlation_package=constants.CorrelationPackage.Lasater,
)
FLUID_DESCRIPTION = case_description.FluidDescription(
    composition=[COMPOSITION_DESCRIPTION_C1, COMPOSITION_DESCRIPTION_C2],
    fraction_pairs=[BIP_DESCRIPTION],
)
PVT_MODEL_COMPOSITIONAL_DEFINITION = case_description.PvtModelCompositionalDescription(
    equation_of_state_type=constants.EquationOfStateType.SoaveRedlichKwong,
    surface_tension_model_type=constants.SurfaceTensionType.Leechien,
    viscosity_model=constants.PVTCompositionalViscosityModel.LohrenzBrayClark,
    heavy_components=[HEAVY_COMPONENT_DESCRIPTION],
    light_components=[
        LIGH_COMPONENT_DESCRIPTION,
        LIGH_COMPONENT_DESCRIPTION_OVERWRITE_C3,
    ],
    fluids={"fluid_1": FLUID_DESCRIPTION},
)
PVT_MODEL_TABLE_PARAMETERS = (
    case_description.PvtModelTableParametersDescription.create_constant(has_water=True)
)
PVT_MODELS_DEFINITION = case_description.PvtModelsDescription(
    default_model="acme",
    compositions={
        "composition 1": PVT_MODEL_COMPOSITIONAL_DEFINITION,
        "composition 2": PVT_MODEL_COMPOSITIONAL_DEFINITION,
    },
    correlations={
def test_case_description_duplicate_names(default_well):
    """
    Pipes because they are reference by OutputDescription
    Nodes because they are referenced by PipeDescription, WellDescription and OutputDescription
    PVTs names, because of default_model
    Wall Names because of PipeSegmentsDescription
    Material because of WellDescription(stagnant_fluid), CasingSectionDescription, TubingDescription
    """
    well_1 = attr.evolve(default_well, name="Well 1")
    well_2 = attr.evolve(default_well, name="Well 1")

    case = case_description.CaseDescription(
        materials=[
            case_description.MaterialDescription(name="Material"),
            case_description.MaterialDescription(name="Material"),
        ],
        walls=[
            case_description.WallDescription(name="Wall A"),
            case_description.WallDescription(name="Wall A"),
        ],
        pvt_models=case_description.PvtModelsDescription(
            default_model="PVT",
            correlations={
                "PVT1": case_description.PvtModelCorrelationDescription(),
            },
            compositions={
                "PVT1":
                case_description.PvtModelCompositionalDescription(fluids={
                    "Fluid 0":
                    case_description.FluidDescription(),
                    "Fluid 1":
                    case_description.FluidDescription(),
                }, ),
                "PVT2":
                case_description.PvtModelCompositionalDescription(
                    fluids={
                        "Fluid 0": case_description.FluidDescription(),
                        "Fluid 1": case_description.FluidDescription(),
                    }),
            },
        ),
        nodes=[
            case_description.NodeDescription(name="ACME",
                                             node_type=NodeCellType.Pressure),
            case_description.NodeDescription(name="ACME",
                                             node_type=NodeCellType.Pressure),
            case_description.NodeDescription(name="Node1",
                                             node_type=NodeCellType.Pressure),
            case_description.NodeDescription(name="FOO",
                                             node_type=NodeCellType.Pressure),
            case_description.NodeDescription(name="FOO",
                                             node_type=NodeCellType.Pressure),
        ],
        pipes=[
            case_description.PipeDescription(
                name="Pipe 1",
                source="ACME",
                target="ACME",
                segments=build_simple_segment(),
            ),
            case_description.PipeDescription(
                name="Pipe 1",
                source="ACME",
                target="ACME",
                segments=build_simple_segment(),
            ),
        ],
        wells=[well_1, well_2],
    )

    expected_msg = dedent("""\
        Elements that can be referenced must have a unique name, found multiples definitions of the following items:
        Fluids:
            - Fluid 0
            - Fluid 1
        Materials:
            - Material
        Nodes:
            - ACME
            - FOO
        PVT:
            - PVT1
        Pipes:
            - Pipe 1
        Walls:
            - Wall A
        Wells:
            - Well 1""")

    with pytest.raises(InvalidReferenceError, match=re.escape(expected_msg)):
        case.ensure_unique_names()