Source code for viiapackage.results.results_a12

### ===================================================================================================================
###   A12 Analysis NLTH result handling
### ===================================================================================================================
# Copyright ©VIIA 2024

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

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from pathlib import Path
import warnings

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.pictures import View

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject
from viiapackage.database import myviia_post_a12_results
from viiapackage.analyses import viia_set_base_node
from viiapackage.pictures import viia_create_result_pictures_nlth
from viiapackage.results.collect_results_for_myviia import viia_collect_results_a12
from viiapackage.results.results_load_model import viia_results_load_model


### ===================================================================================================================
###   2. Function to handle results for A12 analysis
### ===================================================================================================================

[docs]def viia_results_a12( project: ViiaProject, signal: str, bsc_nls_dir: Path, convergence_graphs: bool = True, base_shear_graphs: bool = True, wall_displacement_graphs: bool = True, acceleration_graphs: bool = True, geo_output: bool = True, result_pictures: bool = True, post_on_myviia: bool = True, load_model: bool = True, view: Optional[View] = None): """ Combination of functions to be performed on output of A12 nonlinear time history analysis. Includes: - Graph of convergence. - Graph of base shear in time-history. - Graphs of relative out-of-plane wall displacements. - Graphs of building acceleration at base, foundation and selected nodes on floors. - Generating json-file with data for the geotechnical advisor. - Result pictures for A12 analysis. Input: - project (obj): Project object containing collections and of fem objects and project variables. - signal (str): Signal to consider. Can be S1-S11. - bsc_nls_dir (Path): The path for BSC A10, which contains the geo_output_nls json-file. - convergence_graphs (bool): Toggle to generate convergence graphs. Default value is True. - base_shear_graphs (bool): Toggle to generate base shear graphs. Default value is True. - wall_displacement_graphs (bool): Toggle to generate wall displacement graphs. Default value is True. - acceleration_graphs (bool): Toggle to generate acceleration graphs. Default value is True. - 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. Default value is set to True. - result_pictures (bool): Toggle to generate result pictures. Default value is True. - 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. - post_on_myviia (bool): Select to post the collected data to MYVIIA. Default value is True. - view (obj): View that should be used for the pictures. When None the default view will be used. Default is None. Output: - Result items of A12 analysis are created. """ # Checking for version number if project.version != 1: raise ValueError("ERROR: The A12 analysis is to be applied only on non-strengthened models.") # Check if model needs to be loaded if load_model: # Load the model viia_results_load_model(project=project, analysis_nr='A12', signal=signal) # Collect the analysis analysis = project.viia_get(collection='analyses', name='A12 - Niet-lineair seismische analyse met flexbase') if analysis is None: raise ValueError("ERROR: The analysis object for A12 analysis could not be found.") # Plot convergence graphs if requested if convergence_graphs: out_file = project.viia_get_file(path=project.current_analysis_folder, suffix='.out') if out_file: project.viia_convergence_graph(file=out_file, signal=signal, analysis=analysis, show=False) else: project.write_log("WARNING: No convergence graph is created because out-file could not be found.") # Collect files required for geo-output fos = project.shallow_foundation_present() piles = project.pile_foundation_present() if not piles and not fos: raise ValueError( "ERROR: No shallow or pile foundation present in the model, please check. Maybe you are using the model " "json not the analysis json.") output_5a = None output_5b = None if fos: output_5a = project.viia_get_file(path=project.current_analysis_folder, in_name='_OUTPUT_5A', suffix='.tb') if piles: output_5b = project.viia_get_file(path=project.current_analysis_folder, in_name='_OUTPUT_5B', suffix='.tb') # Create base shear graphs if base_shear_graphs: if output_5a or output_5b: project.viia_base_shear(analysis, [output_5a, output_5b]) else: project.write_log("WARNING: OUTPUT_5A and/or OUTPUT_5B not found. Base shear plot cannot be created.") # Create graph of wall displacements if wall_displacement_graphs: output_2 = project.viia_get_file(path=project.current_analysis_folder, in_name='_OUTPUT_2', suffix='.tb') if output_2: project.viia_wall_displacements(wall_oop_tbfile=output_2, signal=signal, analysis=analysis) else: project.write_log("WARNING: OUTPUT_2 not found. Wall displacement plot cannot be created.") # Create acceleration graphs if acceleration_graphs: # Set the base point if not project.base_point: viia_set_base_node(project=project) # Add basemotion signal project.viia_add_basemotion_signals(signal_list=[int(signal.split('S')[-1])]) # Create graphs of building acceleration output_3 = project.viia_get_file(path=project.current_analysis_folder, in_name='_OUTPUT_3', suffix='.tb') if output_3: project.viia_acceleration_graphs(tb_file=output_3, signal=signal, analysis=analysis) else: project.write_log("WARNING: OUTPUT_3 not found. Acceleration graphs cannot be created.") # Create geo output if geo_output and (output_5a or output_5b): if bsc_nls_dir is None: project.write_log( "WARNING: The A10 analysis has not been performed, or could not be found. Json-file for geo-output is " "not created.") else: nls_json = bsc_nls_dir / 'geo_output_nls.json' if not nls_json.exists(): project.write_log( "WARNING: The A10 analysis geo-output json-file is required for generating the merged geo-output. " "But the file could not be found. Json-file for geo-output is not created.") else: project.viia_create_geo_output_nlth( signal=signal, output_5a=output_5a, output_5b=output_5b, bsc_nls_dir=bsc_nls_dir, analysis=analysis) elif geo_output: project.write_log("WARNING: OUTPUT_5A and OUTPUT_5B not found. Json-file for geo-output cannot be created.") # Collect all available data for A12 analysis base_shear_data = None if 'A12' in project.results and 'base_shear' in project.results['A12'] \ and signal in project.results['A12']['base_shear']: base_shear_data = project.results['A12']['base_shear'][signal] eng_a12 = viia_collect_results_a12(project=project, base_shear_data=base_shear_data, signal=signal) # Upload results of the A12 analysis to MYVIIA if post_on_myviia: response = myviia_post_a12_results(data=eng_a12, token=project.token) if not response: warnings.warn( f"WARNING: An issue occurred during uploading the A12 analysis results for signal {signal} to MYVIIA. " f"No response received, this could be due to debugging. Data that was sent: {eng_a12}.") elif response.status_code >= 300: warnings.warn( f"WARNING: An issue occurred during uploading the A12 analysis results for signal {signal} to MYVIIA. " f"Please check the outputs of the base shear for the NLTH analysis, or contact the automation-team. " f"Response: {response.status_code} | {response.text}.\n") else: project.write_log( f"Results for base-shear for A12 signal {signal} have been successfully uploaded to MYVIIA.", print_message=False) # Collect the pile reactions if project.pile_foundation_present(): output_5b = project.viia_get_file(path=project.current_analysis_folder, in_name='OUTPUT_5B', suffix='.tb') if output_5b: project.viia_collect_pile_reactions(pile_output_file=output_5b, analysis=analysis) else: project.write_log("WARNING: OUTPUT_5B not found. Pile force plots cannot be created.") # Result pictures for A12 if result_pictures: viia_create_result_pictures_nlth(project=project, analysis=analysis, view=view) # Return the collected results return eng_a12
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================