Source code for viiapackage.reporting.viia_forces_l2_measures

### ===================================================================================================================
###   Export forces from L2 measures to Excel
### ===================================================================================================================
# Copyright ©VIIA 2024

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

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING
from pathlib import Path
from datetime import datetime
import pytz

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_DIANAutils import fem_read_diana_tbfile
from rhdhv_fem.fem_tools import fem_create_folder

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

# Packages for writing the Excel file for forces from L2 measures
from openpyxl import load_workbook
from openpyxl.utils.cell import get_column_letter
from openpyxl.styles import PatternFill
from openpyxl.worksheet.table import Table


### ===================================================================================================================
###   2. Function to export forces from L2 measures to Excel
### ===================================================================================================================

[docs]def viia_forces_l2_measures(project: ViiaProject, json: Path, tb_4a_file: Path) -> Path: """ This function can be used to obtain the maximum and minimum forces in L2 measures (interfaces). The output produces an Excel sheet with a summary of the maximum and minimum forces per interface. Input: - project (obj): Project object reference containing collections of fem objects and project variables. - json_file (Path): Path to the location of the json-file including the analysis. - tb_file (Path): Path to the location of the tb-file which contains the results of the stresses in the interfaces from output 4 in the NLTH analysis. Output: - Creates an Excel sheet with a summary of the maximum and minimum forces in the interfaces for strengthening measures L2. - Returns the path of the Excel-file. """ # Read the files analysis_json = project.viia_read_dump(json) tb_file_diana = fem_read_diana_tbfile(project=project, file=tb_4a_file) # Access the data data = get_l2_measure_results(project=project) # Generate the report in Excel # Get some general information set cet_time = datetime.now(pytz.timezone('CET')) time_reference = cet_time.strftime('%Y%m%d%H%M%S') output_document_name = \ f"VIIA_{project.project_information['objectnummer_viia']}_Interface_Stresses_{time_reference}.xlsx" # Collect template file template_location = \ project.viia_settings.project_specific_package_location / 'reporting' / 'templates' / \ 'VIIA_Template_Interface_Forces.xlsx' fem_create_folder(project.workfolder_location / 'ER') target_file = project.workfolder_location / 'ER' / output_document_name fill_colour = PatternFill(start_color='FABF8F', end_color='FABF8F', fill_type='solid') # Writing to excel wb = load_workbook(template_location) ws = wb['Interfaces'] # Fill in header ws['E2'] = project.project_information['objectnummer_viia'] ws['E3'] = f"{project.project_information['objectdeel']} {project.project_information['analysis_subtype']}" ws['E4'] = datetime.now() # Collect table object headings = ['Interface name', 'FSx max', 'FSx min', 'FNy max', 'FNy min', 'FNz max', 'FNz min'] table = Table(displayName='Results', ref='A5:G6') table._initialise_columns() for column, value in zip(table.tableColumns, headings): column.name = value ws.add_table(table) # Set up table size top_left_cell = 'A5' bottom_right_cell = 'G' + str(5 + len(data)) table.ref = top_left_cell + ':' + bottom_right_cell column_mapping = { 'Interface name': 'element_nr', 'FSx min': 'min_t_x', 'FSx max': 'max_t_x', 'FNy min': 'min_t_y', 'FNy max': 'max_t_y', 'FNz min': 'min_t_z', 'FNz max': 'max_t_z'} row_delta = 6 for i, interface in enumerate(data): for column_name, force_type in column_mapping.items(): if column_name == 'Interface name': cell_number = ws[get_column_letter(table.column_names.index(column_name) + 1) + str(i + row_delta)] cell_number.value = interface.name else: cell_number = ws[get_column_letter(table.column_names.index(column_name) + 1) + str(i + row_delta)] cell_number.value = data[interface][force_type][1] i += 1 wb.save(target_file) project.write_log(f"Successfully created Excel-sheet for finding maximum stresses at '{target_file.as_posix()}'.") return target_file
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================