def test_case_description_duplicate_names_between_elements(default_well): """ Ensure Pipes and Wells has unique names (because of OutputDefinition) Ensure Nodes and Wells has unique names (because of Edge source/target) """ well_1 = attr.evolve(default_well, name="ACME Node <-> Well") well_2 = attr.evolve(default_well, name="ACME Pipe <-> Well") case = case_description.CaseDescription( nodes=[ case_description.NodeDescription( name="ACME Node <-> Well", node_type=NodeCellType.Pressure ), case_description.NodeDescription( name="Node1", node_type=NodeCellType.Pressure ), ], pipes=[ case_description.PipeDescription( name="ACME Pipe <-> Well", 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( """\ Some different type of elements needs to have unique name between them, found duplicated names for the following items: Nodes and Wells: - ACME Node <-> Well Pipes and Wells: - ACME Pipe <-> Well""" ) with pytest.raises(InvalidReferenceError, match=re.escape(expected_msg)): case.ensure_unique_names()
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()
def test_pvt_model_default_behavior(self, default_case, default_well): """ 1) CaseDescription should accept components that uses PvtModel as None while default_model is configured. 2) default_model must be a valid pvt_model defined on pvt_models 3) If default_model is None, all components that uses pvt_model must be assigined. """ from alfasim_sdk._internal.constants import NodeCellType case = attr.evolve( default_case, pvt_models=attr.evolve(default_case.pvt_models, default_model="PVT2"), nodes=[ case_description.NodeDescription( name="Node 1", node_type=NodeCellType.Pressure, pvt_model=None) ], pipes=[ case_description.PipeDescription( name="Pipe 1", pvt_model=None, source="in", target="out", segments=build_simple_segment(), profile=case_description.ProfileDescription( x_and_y=case_description.XAndYDescription( x=Array([0], "m"), y=Array([0], "m"))), ) ], wells=[ attr.evolve( default_well, pvt_model=None, annulus=attr.evolve(default_well.annulus, pvt_model=None), ) ], ) # Check 1) If default_model assigned, elements that uses pvt_model can be None case.ensure_valid_references() assert case.pvt_models.default_model == "PVT2" assert case.nodes[0].pvt_model is None assert case.pipes[0].pvt_model is None assert case.wells[0].pvt_model is None assert case.wells[0].annulus.pvt_model is None # Check 2) default_model must be filled with a valid pvt_model case_with_invalid_default_pvt_model = attr.evolve( case, pvt_models=attr.evolve(case.pvt_models, default_model="Acme"))
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_node_pvt_model(self, default_case): """ If a NodeDescription uses an invalid PvtModel, an InvalidReferenceError must be raised. """ case = attr.evolve( default_case, nodes=[ case_description.NodeDescription( name="Node 1", node_type=NodeCellType.Pressure, pvt_model="Foo") ], ) expected_error = ( "PVT model 'Foo' selected on 'Node 1' is not declared on 'pvt_models', " "available pvt_models are: PVT1, PVT2, PVT3") with pytest.raises( InvalidReferenceError, match=re.escape(expected_error), ): case.ensure_valid_references()
MASS_SOURCE_NODE_PROPERTIES_DESCRIPTION = ( case_description.MassSourceNodePropertiesDescription( fluid="fluid_1", tracer_mass_fraction=Array([1.0, 0.0], "-", "mass fraction"), source_type=constants.MassSourceType.TotalMassFlowRatePvtSplit, total_mass_flow_rate=Scalar(0.05, "kg/s"), volumetric_flow_rates_std={ constants.FLUID_GAS: Scalar(10.0, "sm3/d"), constants.FLUID_OIL: Scalar(20, "sm3/d"), constants.FLUID_WATER: Scalar(50, "sm3/d"), }, ) ) NODE_MASS_SOURCE_DESCRIPTION = case_description.NodeDescription( name="mass_source_node", pvt_model="gavea", node_type=constants.NodeCellType.MassSource, mass_source_properties=MASS_SOURCE_NODE_PROPERTIES_DESCRIPTION, ) SEPARATOR_NODE_PROPERTIES_DESCRIPTION = ( case_description.SeparatorNodePropertiesDescription( environment_temperature=Scalar("temperature", 288.6, "K"), geometry=constants.SeparatorGeometryType.Sphere, length=Scalar(10.0, "m"), nozzles={ "Pipe1": Scalar(2.0, "m"), "Pipe2": Scalar(4.0, "m"), "Pipe3": Scalar(0.0, "m"), }, overall_heat_transfer_coefficient=Scalar(0.0, "W/m2.K"), radius=Scalar(2.0, "m"), initial_phase_volume_fractions={
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()