Skip to content

corrosion_utils

structural_sections.steel.profile_definitions.corrosion_utils

Utilities for handling uniform corrosion related operations in structural profiles.

structural_sections.steel.profile_definitions.corrosion_utils.update_name_with_corrosion

update_name_with_corrosion(
    current_name: str,
    *,
    corrosion: MM,
    corrosion_inside: None = None,
    corrosion_outside: None = None,
) -> str
update_name_with_corrosion(
    current_name: str,
    *,
    corrosion_inside: MM,
    corrosion_outside: MM,
    corrosion: None = None,
) -> str
update_name_with_corrosion(
    current_name: str,
    *,
    corrosion: MM | None = None,
    corrosion_inside: MM | None = None,
    corrosion_outside: MM | None = None,
) -> str

Update profile name with corrosion information.

Extracts any existing corrosion value(s) from the name, adds the new corrosion, and returns the updated name with the total corrosion.

This function supports two modes: 1. Single corrosion value (uniform): Pass corrosion parameter 2. Double corrosion values (inside/outside): Pass corrosion_inside and/or corrosion_outside

Parameters:

  • current_name (str) –

    The current profile name, which may or may not include corrosion info.

  • corrosion (MM, default: None ) –

    The uniform corrosion to add (for profiles with single corrosion value) [mm]. Mutually exclusive with corrosion_inside/corrosion_outside.

  • corrosion_inside (MM, default: None ) –

    The inside corrosion to add (for hollow profiles) [mm]. Should be used with corrosion_outside.

  • corrosion_outside (MM, default: None ) –

    The outside corrosion to add (for hollow profiles) [mm]. Should be used with corrosion_inside.

Returns:

  • str

    The updated name with total corrosion information.

Raises:

  • ValueError

    If both single and double corrosion parameters are provided.

  • ValueError

    If neither single nor double corrosion parameters are provided.

Examples:

Single corrosion (uniform):

>>> update_name_with_corrosion("IPE200", corrosion=1.5)
'IPE200 (corrosion: 1.5 mm)'
>>> update_name_with_corrosion("IPE200 (corrosion: 1.5 mm)", corrosion=0.5)
'IPE200 (corrosion: 2.0 mm)'

Double corrosion (inside/outside):

>>> update_name_with_corrosion("RHS200x100x5", corrosion_inside=1.0, corrosion_outside=2.0)
'RHS200x100x5 (corrosion inside: 1.0 mm, outside: 2.0 mm)'
>>> update_name_with_corrosion("RHS200x100x5 (corrosion inside: 1.0 mm, outside: 2.0 mm)", corrosion_inside=0.5, corrosion_outside=1.0)
'RHS200x100x5 (corrosion inside: 1.5 mm, outside: 3.0 mm)'
Source code in blueprints/structural_sections/steel/profile_definitions/corrosion_utils.py
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def update_name_with_corrosion(
    current_name: str,
    *,
    corrosion: MM | None = None,
    corrosion_inside: MM | None = None,
    corrosion_outside: MM | None = None,
) -> str:
    """Update profile name with corrosion information.

    Extracts any existing corrosion value(s) from the name, adds the new corrosion,
    and returns the updated name with the total corrosion.

    This function supports two modes:
    1. Single corrosion value (uniform): Pass `corrosion` parameter
    2. Double corrosion values (inside/outside): Pass `corrosion_inside` and/or `corrosion_outside`

    Parameters
    ----------
    current_name : str
        The current profile name, which may or may not include corrosion info.
    corrosion : MM, optional
        The uniform corrosion to add (for profiles with single corrosion value) [mm].
        Mutually exclusive with corrosion_inside/corrosion_outside.
    corrosion_inside : MM, optional
        The inside corrosion to add (for hollow profiles) [mm].
        Should be used with corrosion_outside.
    corrosion_outside : MM, optional
        The outside corrosion to add (for hollow profiles) [mm].
        Should be used with corrosion_inside.

    Returns
    -------
    str
        The updated name with total corrosion information.

    Raises
    ------
    ValueError
        If both single and double corrosion parameters are provided.
    ValueError
        If neither single nor double corrosion parameters are provided.

    Examples
    --------
    Single corrosion (uniform):
    >>> update_name_with_corrosion("IPE200", corrosion=1.5)
    'IPE200 (corrosion: 1.5 mm)'
    >>> update_name_with_corrosion("IPE200 (corrosion: 1.5 mm)", corrosion=0.5)
    'IPE200 (corrosion: 2.0 mm)'

    Double corrosion (inside/outside):
    >>> update_name_with_corrosion("RHS200x100x5", corrosion_inside=1.0, corrosion_outside=2.0)
    'RHS200x100x5 (corrosion inside: 1.0 mm, outside: 2.0 mm)'
    >>> update_name_with_corrosion("RHS200x100x5 (corrosion inside: 1.0 mm, outside: 2.0 mm)", corrosion_inside=0.5, corrosion_outside=1.0)
    'RHS200x100x5 (corrosion inside: 1.5 mm, outside: 3.0 mm)'
    """
    single_mode = corrosion is not None
    double_mode = corrosion_inside is not None or corrosion_outside is not None

    if single_mode and double_mode:
        msg = "Cannot use both single corrosion and double (inside/outside) corrosion parameters"
        raise ValueError(msg)

    if not single_mode and not double_mode:
        msg = "At least one corrosion parameter must be provided"
        raise ValueError(msg)

    if single_mode:
        return _update_single_corrosion(current_name, corrosion)  # type: ignore[arg-type]
    return _update_double_corrosion(current_name, corrosion_inside or 0, corrosion_outside or 0)