Source code for viiapackage.geometry.viia_structural_type

### ===================================================================================================================
###   Functionality for adding the structural-type to shapes
### ===================================================================================================================
# Copyright ©VIIA 2024

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

# General imports
from __future__ import annotations
from warnings import warn
from enum import Enum
from typing import List, Optional, Type, TYPE_CHECKING

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.shapes.shapes import Shapes

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


### ===================================================================================================================
###    2. CLASS StructuralType
### ===================================================================================================================

[docs]class StructuralType(str, Enum): PSSE = 'psse' NSCE = 'nsce' def __repr__(self): return self.name
### =================================================================================================================== ### 3. Functions for structural-type handling ### ===================================================================================================================
[docs]def viia_set_psse(project: ViiaProject, shapes: List[Shapes]) -> None: """ This function sets the structural-type of all passed in shapes to PSSE. This is done by adding an entry to the meta_data of the shape. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - shapes (list of obj): List of shapes which will be set to PSSE. Output: - Meta-data of shapes is added or updated. """ for shape in shapes: current_structural_type = shape.meta_data.get('structural_type') if current_structural_type and current_structural_type != StructuralType.PSSE: warn(f"WARNING: Structural type of shape '{shape.name}' is changed from '{current_structural_type}' to " f"'{StructuralType.PSSE}'.") shape.add_meta_data({'structural_type': StructuralType.PSSE})
[docs]def viia_set_nsce(project: ViiaProject, shapes: List[Shapes]) -> None: """ This method sets the structural type of all passed in objects to NSCE. This is done by adding an entry to the meta_data of the shape. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - shapes (list of obj): List of shapes which will be set to NSCE. Output: - Meta-data of shapes is added or updated. """ for shape in shapes: current_structural_type = shape.meta_data.get('structural_type') if current_structural_type and current_structural_type != StructuralType.NSCE: warn(f"WARNING: Structural type of shape '{shape.name}' is changed from '{current_structural_type}' to " f"'{StructuralType.NSCE}'.") shape.add_meta_data({'structural_type': StructuralType.NSCE})
[docs]def viia_get_psse(project: ViiaProject, object_type: Optional[Type[Shapes]] = None) -> List[Shapes]: """ Gets all shapes from the collections that are PSSE. Optionally a type can be specified like Wall, Column, to only obtain shapes of that type. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - object_type (list of obj): Optional input for selecting type of shape. Output: - Returns a list of shapes that are classified PSSE, filtered for the requested object-type. """ output = [] for shape in project.collections.shapes: if shape.meta_data and shape.meta_data.get('structural_type') == StructuralType.PSSE: if object_type and not isinstance(shape, object_type): continue output.append(shape) return output
[docs]def viia_get_nsce(project: ViiaProject, object_type: Optional[Type[Shapes]] = None) -> List[Shapes]: """ Gets all shapes from the collections that are NSCE. Optionally a type can be specified like Wall, Column, to only obtain shapes of that type. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - object_type (list of obj): Optional input for selecting type of shape. Output: - Returns a list of shapes that are classified NSCE, filtered for the requested object-type. """ output = [] for shape in project.collections.shapes: if shape.meta_data and shape.meta_data.get('structural_type') == StructuralType.NSCE: if object_type and not isinstance(shape, object_type): continue output.append(shape) return output
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================