Source code for viiapackage.viiaResults

### =============================================================================================================== ###
###                                                                                                                 ###
###                                                  viiaResults.py                                                 ###
###                                                                                                                 ###
### =============================================================================================================== ###
# This module ``viiaResults`` contains functions to handle results and to check the model to compliance criteria of the
# project. Also, the function to retrieve model and results from SCIA in XML format is contained in this module.

# Module is based on:
# VIIA_QE_R376 Basis of Design Retrofit Advice NLTH, v11.0, d.d. 29 August 2024
# VIIA_QE_R376 Basis of Design Step-by-Step MRS, v1.0, d.d. 21 January 2022
# VIIA_QE_R1674 Uitgangspuntenrapport engineering NLPO, v1.0, d.d. 1 August 2019

# This script was based upon the Constitution For Python At VIIA
# For use by VIIA
# Copyright RHDHV

### ===================================================================================================================
###    Contents
### ===================================================================================================================

#   1. Import modules

#   2. User function to create the default VIIA output per analysis

#   3. End of script

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

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

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_tools import fem_create_folder
from rhdhv_fem.analyses import Analysis

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject
from viiapackage.results import viia_results_a1, viia_results_a2, viia_results_a3, viia_results_a4, viia_results_a7, \
    viia_results_a10, viia_results_a12, viia_results_a13, viia_results_a15
from viiapackage.viiaSettings import ViiaSettings


### ===================================================================================================================
###    2. User function to create the default VIIA output per analysis
### ===================================================================================================================

[docs]def viia_results( project: ViiaProject, analysis_nr: str, out_file: Optional[Union[Path, str]] = None, dat_file: Optional[Union[Path, str]] = None, signal: Optional[str] = None, runtime: Optional[float] = None, geo_output: Optional[bool] = True, node_foundation: int = None, node_top: int = None, bsc_nls_dir: Optional[Path] = None, tva_nls_dir: Optional[Path] = None, save_mode_pictures: Optional[int] = 5, load_model: bool = True, json_file: Optional[Union[Path, str]] = None, convergence_graphs: bool = True, base_shear_graphs: bool = True, wall_displacement_graphs: bool = True, acceleration_graphs: bool = True, result_pictures: bool = True, diana_view_point: Optional[Union[Tuple, List]] = None): """ This function will perform the result handling for the selected analysis. It will retrieve the DIANA calculation files from the requested or the most recent analysis folder if not specified. What result pictures / graphs or other info is retrieved is different for the analysis. .. note:: Most analysis result handling require this function to be run in DIANA to generate the requested result pictures. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - analysis_nr (str): Number of the VIIA analysis. For example 'A1'. - out_file (path): The DIANA out-file location and filename of the analysis requested as path. Optional input, if not provided the out-file will be retrieved from the analysis folder. Alternative (str): The DIANA out-file location and filename of the analysis requested as string. - dat_file (path): The ABAQUS dat-file location and filename of the analysis requested as path. Optional input, if not provided the dat-file will be retrieved from the analysis folder. Alternative (str): The ABAQUS dat-file location and filename of the analysis requested as string. - signal (str): The signal for which the results need to be created. Example format is 'S1'. This is used for A4, A12 and A15 analysis. Default value is None. - runtime (float): The time that the analysis ran, in [s]. This value is optional and only used to log and stored in database. Default value is None. - geo_output (bool): This allows the user to choose if the geo output needs to be created. This can be handy if the user wants to create results for multiple signals together. Then the user does not need to create the geo output each time. Currently used only for analysis A12. Default value is set to True. - node_foundation (int): Optional node number from which to extract the foundation accelerations. If no input is given, the first node encountered in both a fstrip and the tb-file is used - node_top (int): Node number from which to extract the top of building accelerations. If no input is given, the node from the tb-file with the highest z-coordinate is selected. - bsc_nls_dir (Path): The path for BSC A10 folder. If there is no difference in the mass and load distribution between BSC and TVA, the geo output will be the same for BSC and TVA. - tva_nls_dir (Path): The path for TVA A13 folder, default is None. If None, the geo output will be the same for BSC and TVA. Otherwise, the TVA A13 folder should be specified. - save_mode_pictures (int): This refers to number of modes, for which the result items displacement DispXYZ and rotation RotXYZ is plotted for the entire structure. Default value is set to 5. - load_model (bool): Select to reload the model. Default value is True, but when directly creating analysis and running, it needs to be switched off. - json_file (path): The json-file of the model, location and filename of the analysis requested as path. Alternative (str): The json-file location and filename of the analysis requested as string. Default value is None, using the default VIIA path for analysis files. - convergence_graphs (bool): Toggle to generate convergence graphs in NLTH analyses. Default value is True. - base_shear_graphs (bool): Toggle to generate base shear graphs in NLTH analyses. Default value is True. - wall_displacement_graphs (bool): Toggle to generate wall displacement graphs in NLTH analyses. Default value is True. - acceleration_graphs (bool): Toggle to generate acceleration graphs in NLTH analyses. Default value is True. - result_pictures (bool): Toggle to generate result pictures in NLTH analyses. Default value is True. - diana_view_point (list or tuple): The diana view point that should be used for the picture. Can be used when the default view is not sufficient. (Use 'currentViewPoint()' in DianaIE to retrieve the diana view point). The diana view point is a list or tuple of 11 floats where: 1st to 3rd values are camera position coordinates, 4th to 6th values are camera view vector direction, 7th to 9th values are camera focal point coordinates, 10th value is camera viewing angle in degrees and 11th value is the viewpoint height. When None the default view will be used. Default is None. Output: - The required result pictures are generated. For this the function should run in DIANA. - The required graphs are created. - The required data is retrieved from the files and returned. - All files are generated in the analysis folder. """ # Argument handling # Convert str to path for out-file if isinstance(out_file, str): out_file = Path(out_file) # Check if out-file exists if not out_file.exists(): out_file = None # Convert str to path for json-file if isinstance(json_file, str): json_file = Path(json_file) # Check if out-file exists if not json_file.exists(): json_file = None # Assign the folders based on the analysis for Geo Output if folders are not already provided if geo_output and analysis_nr in ['A10', 'A12', 'A13', 'A15']: if not bsc_nls_dir: bsc_nls_dir = project.viia_get_latest_model_folder( folder=project.workfolder_location / project.diana_settings.analysis_settings['A10']['folder_name'], version=1) if analysis_nr == 'A15' and not tva_nls_dir: tva_nls_dir = project.viia_get_latest_model_folder( folder=project.workfolder_location / project.diana_settings.analysis_settings['A13']['folder_name']) # Check if the analysis folder is correct if not project.current_analysis_folder: raise ValueError( f"ERROR: The analysis folder is not set correctly. First provide the folder to be used for the result " f"handling.") view = None if diana_view_point is not None: view = project.create_view_from_diana_view_point(diana_view_point=diana_view_point) # Select the analysis number to handle results if analysis_nr == 'A1': viia_results_a1( project=project, json_file=json_file, out_file=out_file, dat_file=dat_file, load_model=load_model) elif analysis_nr == 'A2': viia_results_a2(project=project, out_file=out_file, runtime=runtime) elif analysis_nr == 'A3': viia_results_a3( project=project, json_file=json_file, out_file=out_file, dat_file=dat_file, load_model=load_model) elif analysis_nr == 'A4': viia_results_a4( project=project, signal=signal, convergence_graphs=convergence_graphs, wall_displacement_graphs=wall_displacement_graphs, result_pictures=result_pictures, load_model=load_model, view=view) elif analysis_nr == 'A7': viia_results_a7( project=project, json_file=json_file, out_file=out_file, dat_file=dat_file, load_model=load_model, result_pictures=result_pictures, view=view) elif analysis_nr == 'A10': viia_results_a10( project=project, convergence_graphs=convergence_graphs, geo_output=geo_output, result_pictures=result_pictures, load_model=load_model, view=view) elif analysis_nr == 'A12': viia_results_a12( project=project, signal=signal, bsc_nls_dir=bsc_nls_dir, convergence_graphs=convergence_graphs, base_shear_graphs=base_shear_graphs, wall_displacement_graphs=wall_displacement_graphs, acceleration_graphs=acceleration_graphs, geo_output=geo_output, result_pictures=result_pictures, load_model=load_model, view=view) elif analysis_nr == 'A13': viia_results_a13( project=project, convergence_graphs=convergence_graphs, geo_output=geo_output, load_model=load_model, view=view) elif analysis_nr == 'A15': viia_results_a15( project=project, signal=signal, bsc_nls_dir=bsc_nls_dir, tva_nls_dir=tva_nls_dir, convergence_graphs=convergence_graphs, base_shear_graphs=base_shear_graphs, wall_displacement_graphs=wall_displacement_graphs, acceleration_graphs=acceleration_graphs, geo_output=geo_output, result_pictures=result_pictures, load_model=load_model, view=view) else: project.write_log( f"WARNING: Result handling for {analysis_nr} is currently not supported. Please contact VIIA automation " f"team if you have to perform this analysis for your object.") return None # Log the runtime of the calculation when provided if runtime: project.write_log(f"Runtime of {analysis_nr}: {runtime} s")
### =================================================================================================================== ### 3. User function to create movie of the results in DIANA ### ===================================================================================================================
[docs]def viia_create_movie_diana( project: ViiaProject, analysis: Optional[Union[str, Analysis]] = None, output_block: str = 'OUTPUT_MOVIE', result_type: Optional[str] = None, result_component: str = 'TrDtXYZ', deformation_type: str = 'absolute', deformation_scale_factor: Optional[float] = None, deformed_edge_view: int = 1, undeformed_edge_view: int = 1, fixed_legend: bool = True, min_legend_value: float = 0, max_legend_value: float = 60, save_movie: bool = True, frames_per_second: int = 12, width: int = 1024, height: int = 768, output_file_type: str = 'avi', units: Optional[Dict[str, str]] = None, diana_view_point: Optional[Union[Tuple, List]] = None) \ -> Optional[Path]: """ Function to prepare and create a movie of the results in DIANA software. Input: - project (obj): Project object containing collections of fem objects and project variables. - analysis (str or obj): Name of the analysis or the object reference of the analysis with the results for the movie. Default value is None, in which case the analysis will be retrieved from project, but only if there is one present, otherwise the user should specify which analysis to use. - output_block (str): Name of the output block in DIANA. Default value is 'OUTPUT_MOVIE'. - result_type (str): Type of result to be shown in the movie. Example: 'Displacements (2498)'. Default value is None. - result_component (str): Component of the result to be shown in the movie. Default value is 'TrDtXYZ'. Other options can be 'TrDtX', 'TrDtY', 'TrDtZ' etc. - deformation_type (str): Type of deformation to be shown in the movie. Default value is 'absolute' or it can also be set to 'normalized'. - deformation_scale_factor (float): Scale factor for the deformation. Default value for absolute deformation is 10 and for normalized deformation is 0.05. - deformed_edge_view (int): Option to select the deformed mesh edge view in DIANA. Default value is 1. Allowable values are: 1: Free face edges 2: Feature edges 3: No edges - undeformed_edge_view (int): Option to select the undeformed mesh edge view in DIANA. Default value is 1. Allowable values are: 1: Free face edges 2: Feature edges 3: No edges - fixed_legend (bool): Option to set the legend to fixed values. Default value is True. - min_legend_value (float): Minimum value for the legend. Default value is 0. - max_legend_value (float): Maximum value for the legend. Default value is 60. - save_movie (bool): Option to save the movie. Default value is True. - frames_per_second (int): Number of frames per second in the movie. Default value is 12. - width (int): Width of the movie display. Default value is 1024 pixels. - height (int): Height of the movie display. Default value is 768 pixels. - output_folder (str or Path): Folder location where the movie should be saved. By default, the movie will be saved in the workfolder. - output_file_type (str): Type of the output file. Default value is 'avi'. It can also be set to 'ogg'. - units (dict): Dictionary with the type of units and its desired unit. Default value is {'LENGTH': 'mm'}. Some of the other examples can be {'MASS': 'KG'}, {'FORCE': 'KN'}, {'TIME': 'SEC'} etc. - diana_view_point (View, list or tuple): The view point that should be used for the picture. Can be used when the default view is not sufficient. (Use 'currentViewPoint()' in DianaIE to retrieve the DIANA view point). The DIANA view point is a list or tuple of 11 floats where: 1st to 3rd values are camera position coordinates, 4th to 6th values are camera view vector direction, 7th to 9th values are camera focal point coordinates, 10th value is camera viewing angle in degrees and 11th value is the viewpoint height. When None the default view will be used. Default is None, using the ISO1 viewpoint. Output: - The movie settings are set in DIANA. - As per user choice, the movie is saved in the specified folder. """ # Analysis name if analysis is None: if len(project.collections.analyses) != 1: project.write_log( "WARNING: Multiple analyses found in the project. Provide the specific analysis for the creation of " "the movie. Create move function aborted.") return None analysis = project.collections.analyses[0] if analysis.name not in project.rhdhvDIANA.analyses(): project.write_log( f"WARNING: The analysis is not present in DIANA. Please check for {analysis.name}. Found analyses are: " f"{', '.join(project.rhdhvDIANA.analyses())}. Create move function aborted.") return # Result cases result_cases = project.rhdhvDIANA.resultCases(str(analysis.name), output_block) # Result type # Default result_type is that of the first result case in the output block if not result_type: result_type = project.rhdhvDIANA.availableResults( {'analysis': analysis.name, 'block': output_block, 'case': result_cases[0], 'location': 'node'})[0][2] # Set the result view project.rhdhvDIANA.showView('Result') project.rhdhvDIANA.selectResult({'component': result_component, 'result': result_type, 'type': 'Node'}) project.rhdhvDIANA.setResultPlot('contours') # Execute if the movie should be saved if save_movie: # Create the folder and prepare the name of the file time_reference = datetime.now().strftime('%Y%m%d%H%M%S') output_folder = project.workfolder_location folder = f'{time_reference}-v{str(project.version).zfill(3)}' fem_create_folder(ViiaSettings.DEFAULT_DIANA_MOVIE_FOLDER, ref_folder=output_folder) fem_create_folder(folder, ref_folder=output_folder / ViiaSettings.DEFAULT_DIANA_MOVIE_FOLDER) output_file_location = output_folder / ViiaSettings.DEFAULT_DIANA_MOVIE_FOLDER / folder output_file_name = output_file_location / f'movie_{result_component}' # Create the movie return project.create_movie_diana( analysis=analysis, result_cases=result_cases, deformation_type=deformation_type, deformation_scale_factor=deformation_scale_factor, deformed_edge_view=deformed_edge_view, undeformed_edge_view=undeformed_edge_view, fixed_legend=fixed_legend, min_legend_value=min_legend_value, max_legend_value=max_legend_value, frames_per_second=frames_per_second, width=width, height=height, output_file_name=output_file_name, output_file_type=output_file_type, units=units, diana_view_point=diana_view_point) # Only prepare for the movie (movie is not saved). else: return project.animation_settings_diana( analysis=analysis, result_cases=result_cases, deformation_type=deformation_type, deformation_scale_factor=deformation_scale_factor, deformed_edge_view=deformed_edge_view, undeformed_edge_view=undeformed_edge_view, fixed_legend=fixed_legend, min_legend_value=min_legend_value, max_legend_value=max_legend_value, units=units, diana_view_point=diana_view_point)
### =================================================================================================================== ### 4. End of script ### ===================================================================================================================