Source code for viiapackage.strengthening.helper_functions.viia_strengthening_shapes

### ===================================================================================================================
###   Functions for strengthening shapes
### ===================================================================================================================
# Copyright ©VIIA 2024

### ===================================================================================================================
###   1. Import modules
### ===================================================================================================================

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Union

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.shapes import Wall, Shapes
from rhdhv_fem.connections import Connections

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject


### ===================================================================================================================
###   2. Function to check the wall argument
### ===================================================================================================================

[docs]def viia_check_shape_argument( project: ViiaProject, shape: [str, Shapes], function_name: str, check_strengthening: bool = True) -> Shapes: """ This function checks the shape input argument and returns the shape as an object reference. If the shape is not recognised by the name an error is raised. Also when the shape is not an instance of Shape class an error is raised. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - shape (obj): The object reference of the shape that has to be strengthened. Alternative (str): Name of the shape to be strengthened. - function_name (str): Name of the function for which the argument is provided (for logging). - check_strengthening (bool): When set to True, function will check if the shape is already strengthened. Otherwise, the strengthening will not be checked. Default value is True. Output: - Returns the shape as an object reference or raises an error. """ # Find the object of the shape if the name is provided if isinstance(shape, str): shape = project.viia_get('shapes', shape) # Check if shape has been found if not isinstance(shape, Shapes): raise ValueError(f"ERROR: Shape not found for {function_name} function, please check input {shape}.") # Check if the shape is already strengthened if check_strengthening and shape.meta_data and shape.meta_data.get('strengthening'): if isinstance(shape, Wall): # Add the exception of L4-D for the strengthening measures combined if function_name == 'viia_l4d' and shape.meta_data['strengthening'] != 'L4-D': project.write_log( f"Measure L4-D will be applied together with existing strengthening for {shape.name}.", False) elif shape.meta_data['strengthening'] == 'L4-D': if function_name == 'viia_l4d': raise ValueError( f"ERROR: Wall has already been strengthened with {shape.meta_data['strengthening']}. " f"The measure cannot be re-applied") else: shape.add_meta_data({'strengthening_L4_D': 'L4-D'}) shape.meta_data['strengthening'].pop('L4-D') project.write_log( f"Measure will be applied together with existing strengthening L4-D for {shape.name}.", False) else: raise NotImplementedError( f"ERROR: Wall has already been strengthened with {shape.meta_data['strengthening']}. " f"Currently measures cannot be combined in the viiaPackage. " f"Function {function_name} is not executed for {shape.name}.") else: raise NotImplementedError( f"ERROR: {shape.name} has already been strengthened with " f"{shape.meta_data['strengthening']}. Currently measures cannot be combined in the " f"viiaPackage. Function {function_name} is not executed for {shape.name}.") # Return the shape return shape
[docs]def viia_add_strengthening_shape(shape: Shapes, strengthening_shape: Union[Shapes, Connections]) -> Shapes: """ Function to collect the shapes that are created for the strengthening measure. These are stored in the meta-data attribute of the shape. Input: - shape (obj): Object reference of the original shape that is strengthened. - strengthening_shape (obj): Object reference of the newly added shape that represents some element of the strengthening measure. Output: - The meta-data of the original shape is updated with the strengthened shape. - The original shape is returned. """ if shape.meta_data is None or 'strengthening_shapes' not in shape.meta_data: shape.add_meta_data(new_data={'strengthening_shapes': [strengthening_shape]}) else: shape.meta_data['strengthening_shapes'].append(strengthening_shape) if shape.layer and not isinstance(strengthening_shape, Connections) and not strengthening_shape.layer: shape.layer.add_item(strengthening_shape) return shape
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================