Source code for viiapackage.strengthening.helper_functions.l2_strengthening_base

### ===================================================================================================================
###   L2 strengthening base
### ===================================================================================================================
# Copyright ©VIIA 2024

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

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

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.shapes import Surfaces, Wall
from rhdhv_fem.connections import Interface, NoConnection
from rhdhv_fem.fem_math import fem_cross_product_vector, fem_unit_vector, fem_flip_vector, \
    fem_horizontal_vector_in_plane

# References for functions and classes in the viiaPackage
from viiapackage.strengthening.helper_functions import viia_add_strengthening_shape
from viiapackage.strengthening.helper_functions.check_measure_in_gmc import viia_check_measure_in_gmc
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject


### ===================================================================================================================
###   2. Function to create L2 strengthening measures
### ===================================================================================================================

[docs]def viia_l2_base( project: ViiaProject, measure_type: str, variant: int, connection: Union[str, Interface, NoConnection] = None, shape_1: Surfaces = None, shape_2: Surfaces = None, shape_1_types: Union[Tuple[Surfaces], Surfaces] = Surfaces, shape_2_types: Union[Tuple[Surfaces], Surfaces] = Surfaces) -> Interface: """ This function creates an L2-measure. It can create an interface in between two surfaces, or make an existing interface linear. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - measure_type (str): The L2 measure type that should be created. Currently 'L2-005', 'L2-025', 'L2-043', 'L2-060' are implemented. - variant (int): The variant number of the measure that is in the GMC. - connection (str or obj): The interface that has to be made linear or the NoConnection that should be replaced. Both the name or object reference can be provided. Default is None, in this case shape_1 and shape_2 should be provided. - shape_1 (str or obj): The object reference or name of the surface to what the interface should be applied. Default is None, in this case the interface should be provided. - shape_2 (str or obj): The object reference or name of the surface to what the interface should be applied. Default is None, in this case the interface should be provided. - shape_1_types (typle of classes or class): The types that are allowed for shape 1. Default is Surfaces. - shape_2_types (typle of classes or class): The types that are allowed for shape 2. Default is Surfaces. Output: - The strengthening measure is added between shape_1 and shape_2 or the interface is made linear. - Returns the interface object reference of the measure. For example: - To make a linear interface from a non-linear interface, the following input can be used: >>> project.viia_l2_base(connection='name_of_interface') - To make a new linear interface between two shapes, the following input can be used: >>> project.viia_l2_base(shape_1='name_of_first_shape', shape_2='name_of_second_shape') """ allowed_measures = ['L2-005', 'L2-025', 'L2-043', 'L2-053', 'L2-054', 'L2-060'] if measure_type not in allowed_measures: raise ValueError(f"ERROR: The measure type {measure_type} is not recognised.") # Check if measure is in GMC measure_sub_type = f"{measure_type}-{int(variant)}" viia_check_measure_in_gmc(project=project, measure_sub_type=measure_sub_type) if isinstance(connection, str): connection = project.find(description=connection, collection='connections') if not isinstance(connection, (Interface, NoConnection)): raise ValueError( f"ERROR: Connection is not found or of the wrong type.") if connection and connection.connection_type != 'line-line': raise ValueError( f"ERROR: Only line-line interfaces can be strengthened with {measure_type}, not " f"{connection.connection_type}.") if isinstance(connection, Interface): project.write_log( f"Start applying {measure_type} measure to {connection}, the material of the original interface will be " f"modified.") material_name = f'LIN-LIJN-IF-{measure_type}-V' if connection.connecting_shapes['source_shape_geometry'].is_horizontal(): material_name = f'LIN-LIJN-IF-{measure_type}-H' connection.name = \ connection.name.replace(connection.material.name.replace('LIN', ''), material_name.replace('LIN', '')) material = project.viia_materials(material_name=material_name) connection.set_material(material=material) # Add meta-data to the interface connection.add_meta_data( {'strengthening': f'{measure_type}'}) viia_add_strengthening_shape( shape=connection.connecting_shapes['source_connecting_shape'], strengthening_shape=connection) viia_add_strengthening_shape( shape=connection.connecting_shapes['target_connecting_shape'], strengthening_shape=connection) project.write_log( f"{measure_type} measure is applied on {connection.name} with updated material.") return connection elif isinstance(connection, NoConnection): project.write_log( f"{connection} will be removed and replaced with an interface (measure {measure_type}).") source_connecting_shape, target_connecting_shape = connection.connecting_shapes['source_connecting_shape'], \ connection.connecting_shapes['target_connecting_shape'] shape_1, shape_2 = None, None if isinstance(source_connecting_shape, shape_1_types): shape_1 = source_connecting_shape elif isinstance(target_connecting_shape, shape_1_types): shape_1 = target_connecting_shape if isinstance(source_connecting_shape, shape_2_types): shape_2 = source_connecting_shape elif isinstance(target_connecting_shape, shape_2_types): shape_2 = target_connecting_shape if shape_1 is None or shape_2 is None: raise ValueError( f"{connection} cannot be changed into a {measure_type} measure. The provided NoConnection is not " f"connected to the right type of shapes.") connection.remove_connection() connection = None if connection is None: project.write_log( f"Start applying {measure_type} measure to {shape_1} and {shape_2}, an interface will made between the " f"shapes.") if not (shape_1 and shape_2): raise ValueError("ERROR: When no interface two shapes should be given.") if isinstance(shape_1, str): shape_1 = project.find(description=shape_1, collection='surfaces') if not shape_1: raise ValueError(f"ERROR: The first shape is not found.") if not isinstance(shape_1, shape_1_types): raise TypeError(f"ERROR: Shape {shape_1} is not the right wrong type. If should be a {shape_1_types}") if isinstance(shape_2, str): shape_2 = project.find(description=shape_2, collection='surfaces') if not shape_2: raise ValueError(f"ERROR: The second shape is not found.") if not isinstance(shape_2, shape_2_types): raise TypeError(f"ERROR: Shape {shape_2} is not the right wrong type. If should be a {shape_2_types}") # Remove old connections lines = shape_1.get_connecting_lines(shape=shape_2, include_openings=False) if not lines: raise ValueError( f"ERROR: No connecting lines are found for {shape_1} and {shape_2}. Not able to make the strengthening " f"measure.") old_connections = [ connection for connection in shape_1.get_connections() if connection in shape_2.get_connections() and connection.connecting_shapes['source_shape_geometry'] in lines and connection.connecting_shapes['target_shape_geometry'] in lines] if old_connections: project.write_log(f"Old connections {old_connections} between the shapes will be removed.") for connection in old_connections: connection.remove_connection() if all([line.is_vertical() for line in lines]): material_name = f'LIN-LIJN-IF-{measure_type}-V' if isinstance(shape_2, Wall): local_y_axis = fem_unit_vector( fem_horizontal_vector_in_plane(shape_2.contour.get_points(), project.check_precision)) else: local_y_axis = shape_2.element_x_axis.vector elif all([line.is_horizontal() for line in lines]): material_name = f'LIN-LIJN-IF-{measure_type}-H' local_y_axis = fem_unit_vector(fem_cross_product_vector(lines[0].get_direction().vector, [0, 0, 1])) _val = max(local_y_axis, key=abs) if _val < 0: local_y_axis = fem_flip_vector(local_y_axis) else: raise ValueError("ERROR: Connecting lines are not all vertical or horizontal.") interfaces = project.viia_create_connection( source=shape_1, target=shape_2, detail=material_name.replace('LIN-LIJN-IF-', ''), is_linear=True, local_y_axis=local_y_axis) # Add meta-data to the interface for interface in interfaces: interface.add_meta_data( {'strengthening': measure_sub_type}) viia_add_strengthening_shape( shape=shape_1, strengthening_shape=interface) viia_add_strengthening_shape( shape=shape_2, strengthening_shape=interface) project.write_log( f"{measure_type} measure is applied between {shape_1} and {shape_2}.") return interface
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================