Source code for viiapackage.reporting.helper_functions.get_wall_displacements_data

### ===================================================================================================================
###   FUNCTION: Get wall displacements data from the analyses for reporting
### ===================================================================================================================
# Copyright ©VIIA 2024

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

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Optional, Dict, List, Union
import json
from pathlib import Path

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_math import fem_smaller

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject
from viiapackage.results.result_functions.viia_limits import viia_find_limits_NLTH
from viiapackage.general.file_handling import viia_to_filename


### ===================================================================================================================
###   2. Function viia_get_wall_displacements_data
### ===================================================================================================================

[docs]def viia_get_wall_displacements_data( project: ViiaProject, result_folder: Optional[Path] = None, wall_displacements_json_file: Optional[Path] = None) \ -> Dict[str, Dict[str, Union[str, List[Dict[str, Union[int, str, bool]]]]]]: """ This function will generate a dictionary with data for the wall displacements in the requested analysis. The data can later be used in the reporting. The data is ordered to generate a table with walls and per wall the in-plane and out-of-plane displacements and limits. Also, the name of the picture with the governing wall displacements is retrieved. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - result_folder (Path): Path for the NLTH result folder for which the wall displacements will be collected. Default value None, only applicable if the json-file is provided directly. - wall_displacements_json_file (Path): Json-file with the wall displacement results of the requested governing analysis. Output: - Returns a dictionary with the data of the wall displacements relevant for summary in reporting. """ # Collect data about seismic analysis from result folder no_wall_displacements = True if isinstance(result_folder, Path): wall_displacements_json_file = result_folder / 'wall_displacements.json' if wall_displacements_json_file.exists(): no_wall_displacements = False elif result_folder is None and wall_displacements_json_file is not None and wall_displacements_json_file.exists(): # Situation where the json-file is provided manually no_wall_displacements = False # Check if the data is present to continue if no_wall_displacements: # No data found for wall_displacement if isinstance(result_folder, Path): project.write_log( f"WARNING: The json-file with the wall displacement could not be found in {result_folder.as_posix()}. " f"Results for the NLTH analysis from tb-file 'OUTPUT_2' are not added to the report. Make sure to " f"handle the results prior to executing the reporting function.") else: project.write_log( f"WARNING: No results for the governing NLTH analysis has been provided. The wall displacement results" f"will be missing in the report.") return {} # Read json file with open(wall_displacements_json_file) as fp: wall_displacements_data = json.load(fp) # Sort the list of walls based on ID and include the cavity walls wall_list = [k for k in wall_displacements_data] wall_list.sort(key=lambda x: x.split('-')[-1]) # Adding data to report_data dictionary results governing_analysis walls_displacements_unsorted = [] ip_uc_checks = [] oop_uc_checks = [] for wall_name, wall_data in wall_displacements_data.items(): if wall_name == 'N1-WANDEN-LIN-HBV-PLATEN-0.018-0.038-0.12-0.6-18-38': print() wall = project.viia_get('walls', wall_name) limits = viia_find_limits_NLTH(project=project, shape=wall) # Convert units from [m] to [mm] for reporting purposes ip_limit = limits['In-plane'] * 1000 oop_limit = limits['Out-of-plane'] * 1000 # Get maximum in-plane displacement in [mm] max_ip_positive = max(wall_data['interstorey_drift_parallel']) * 1000 min_ip_negative = min(wall_data['interstorey_drift_parallel']) * 1000 if abs(max_ip_positive) >= abs(min_ip_negative): max_ip_displacement = abs(max_ip_positive) else: max_ip_displacement = abs(min_ip_negative) # In-plane unity checks ip_failure = False if not ip_limit: ip_uc = 'UNKOWN' ip_failure = True else: ip_uc = max_ip_displacement / ip_limit if not fem_smaller(ip_uc, 1): ip_failure = True ip_uc = format(ip_uc, '.1f') ip_uc_checks.append(ip_uc) # Get maximum out-of-plane displacement in [mm] max_oop_positive = max(wall_data['interstorey_drift_perpendicular']) * 1000 min_oop_negative = min(wall_data['interstorey_drift_perpendicular']) * 1000 if abs(max_oop_positive) >= abs(min_oop_negative): max_oop_displacement = abs(max_oop_positive) else: max_oop_displacement = abs(min_oop_negative) # Out-of-plane unity checks oop_failure = False oop_uc = max_oop_displacement / oop_limit if not fem_smaller(oop_uc, 1): oop_failure = True oop_uc_checks.append(oop_uc) # Write data walls_displacements_unsorted.append({ 'name': wall.name, 'id': wall.name.split('-')[-1], 'height': format(wall_data['height'] * 1000, '.1f'), 'thickness': format(wall_data['thickness'] * 1000, '.1f'), 'width': format(wall_data['width'] * 1000, '.1f'), 'max_ip_displacements': format(max_ip_displacement, '.1f'), 'ip_limit': format(ip_limit, '.1f'), 'ip_uc': ip_uc, 'ip_failure': ip_failure, 'max_oop_displacements': format(max_oop_displacement, '.1f'), 'oop_limit': format(oop_limit, '.1f'), 'oop_uc': format(oop_uc, '.1f'), 'oop_failure': oop_failure}) # Adding governing IP and OOP walls displacement graphs max_ip_uc_index = ip_uc_checks.index(max(ip_uc_checks)) max_oop_uc_index = oop_uc_checks.index(max(oop_uc_checks)) ip_governing_wall_name = \ walls_displacements_unsorted[max_ip_uc_index]['name'] oop_governing_wall_name = \ walls_displacements_unsorted[max_oop_uc_index]['name'] ip_governing_wall_image = \ viia_to_filename(ip_governing_wall_name) oop_governing_wall_image = \ viia_to_filename(oop_governing_wall_name) # Sort the list of walls_displacement_unsorted by id: walls_displacements = sorted(walls_displacements_unsorted, key=lambda x: x['id']) return { 'wall_results_info': { 'displacements_results': walls_displacements, 'ip_governing_wall': {'name': ip_governing_wall_name, 'image_file': ip_governing_wall_image}, 'oop_governing_wall': {'name': oop_governing_wall_name, 'image_file': oop_governing_wall_image}}}
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================