def test_physics_description_path_validator(tmp_path):
    """
    Ensure PhysicsDescription.restart_filepath only accepts created files
    """
    from pathlib import Path
    import re

    expected_error = re.escape(
        f"'restart_filepath' must be {Path} (got '' that is a {str}).")
    with pytest.raises(TypeError, match=expected_error):
        case_description.PhysicsDescription(restart_filepath="")

    tmp_file = tmp_path / "tmp.txt"
    tmp_file.touch()
    assert case_description.PhysicsDescription(restart_filepath=tmp_file)
    assert case_description.PhysicsDescription(restart_filepath=None)
Esempio n. 2
0
def test_check_restart_file_exists(default_case, tmp_path):
    """Ensure that the method EnsureValidReferences from CaseDescription catches errors with invalid restart files."""
    restart_file = tmp_path / "dummy.restart"
    case = attr.evolve(
        default_case,
        physics=case_description.PhysicsDescription(
            initial_condition_strategy=constants.InitialConditionStrategyType.Restart,
            restart_filepath=restart_file,
        ),
    )
    expected_error = re.escape(f"Restart file '{restart_file}' is not a valid file")

    with pytest.raises(
        InvalidReferenceError,
        match=expected_error,
    ):
        case.ensure_valid_references()
    stop_on_steady_state=True,
    initial_time=Scalar(1, "s"),
    final_time=Scalar(2, "s"),
    initial_timestep=Scalar(3, "s"),
    minimum_timestep=Scalar(4, "s"),
    maximum_timestep=Scalar(5, "s"),
    restart_autosave_frequency=Scalar(6, "s"),
    minimum_time_for_steady_state_stop=Scalar(7, "s"),
)

PHYSICS_DESCRIPTION = case_description.PhysicsDescription(
    hydrodynamic_model=constants.HydrodynamicModelType.ThreeLayersNineFieldsGasOilWater,
    simulation_regime=constants.SimulationRegimeType.SteadyState,
    energy_model=constants.EnergyModel.LayersModel,
    solids_model=constants.SolidsModelType.Mills1985Equilibrium,
    initial_condition_strategy=constants.InitialConditionStrategyType.SteadyState,
    restart_filepath=Path(__file__),
    keep_former_results=True,
    correlations_package=constants.CorrelationPackageType.Alfasim,
    emulsion_model=constants.EmulsionModelType.Brauner2001,
    flash_model=constants.FlashModel.HydrocarbonOnly,
)

NUMERICAL_OPTIONS_DESCRIPTION = case_description.NumericalOptionsDescription(
    tolerance=0.0,
    maximum_iterations=42,
    maximum_timestep_change_factor=4,
    maximum_cfl_value=2,
    relaxed_tolerance=42.42,
    divergence_tolerance=5.5,
    nonlinear_solver_type=constants.NonlinearSolverType.AlfasimQuasiNewton,
    friction_factor_evaluation_strategy=constants.EvaluationStrategyType.NewtonExplicit,