Source code for viiapackage.results.results_a1

### ===================================================================================================================
###   A1 Static analysis result handling
### ===================================================================================================================
# Copyright ©VIIA 2024

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

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

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject
from viiapackage.database import myviia_post_a1_results
from viiapackage.results.collect_results_for_myviia import viia_collect_results_a1
from viiapackage.results.result_functions import viia_read_diana_outfile_linear_static
from viiapackage.results.results_load_model import viia_results_load_model


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

[docs]def viia_results_a1( project: ViiaProject, json_file: Optional[Path] = None, out_file: Optional[Union[Path, str]] = None, dat_file: Optional[Union[Path, str]] = None, post_on_myviia: bool = True, load_model: bool = True) \ -> Dict[str, float]: """ Combination of functions to be performed on output of A1 linear static analysis in VIIA. Includes: - Determination of the mass of the structure. - Determination of center of mass. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - json_file (path): The json-file of the model generated at the moment the A1 analysis folder with its contents was generated. Default value is None, in which case the json-file is retrieved from the current analysis folder. - 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. - post_on_myviia (bool): Select to post the collected data to MYVIIA. 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. Output: - Result items of A1 calculation are returned as dictionary. """ # Collect the out-file and raise error if not found if not out_file: out_file = project.viia_get_file(path=project.current_analysis_folder, suffix='.out') if not out_file or not out_file.exists(): raise FileNotFoundError( f"ERROR: Could not retrieve the DIANA out-file for result handling A1 analysis.") # Check if model needs to be loaded if load_model: # Load the model viia_results_load_model(project=project, analysis_nr='A1') # Collect the load combination for the mass calculation load_combination_id = project.get_load_combination(name='DL').id raw_data = viia_read_diana_outfile_linear_static( project=project, outfile=out_file, load_combination_id=load_combination_id) # Collect all required data from A1 analysis if not json_file: json_file = project.viia_get_file(path=project.current_analysis_folder, in_name=project.name, suffix='.json') if not json_file or not json_file.exists(): raise ValueError( f"ERROR: The json-file is required to reload the model, an issue was encountered while loading the A1 " f"model in {project.current_analysis_folder.as_posix()}.") eng_a1 = viia_collect_results_a1(project=project, center_of_mass=raw_data, json_file=json_file) # Post results on MYVIIA if post_on_myviia: # Upload results of the A1 analysis response = myviia_post_a1_results(data=eng_a1, token=project.token) if not response: warnings.warn( f"WARNING: An issue occurred during uploading the A1 analysis results to MYVIIA. No response received, " f"this could be due to debugging. Data that was sent: {eng_a1}.") elif response.status_code >= 300: warnings.warn( f"WARNING: An issue occurred during uploading the A1 analysis results to MYVIIA. Please check the " f"outputs of the linear analysis. It is expected that this issue is caused by the size of the " f"model, therefore retrying uploading without model. Server response: status-code " f"{response.status_code} | {response.text}.\n") eng_a1['model'] = None response = myviia_post_a1_results(data=eng_a1, token=project.token) if response.status_code >= 300: warnings.warn( f"WARNING: The A1 analysis results still could not be uploaded to MYVIIA. Please inform " f"automation team and provide this information. Server response: status-code " f"{response.status_code} | {response.text}.\n") else: project.write_log( "The results of A1 analysis have been successfully uploaded to MYVIIA, except for the model " "see the previous warning.") else: project.write_log("The results of A1 analysis have been successfully uploaded to MYVIIA.") # Collect the analysis analysis = project.viia_get(collection='analyses', name='A1 - Lineair statische analyse') if analysis is None: raise ValueError("ERROR: The analysis object for A1 analysis could not be found.") # Collect the pile reactions if project.pile_foundation_present(): output_piles = project.viia_get_file( path=project.current_analysis_folder, in_name='OUTPUT_STATIC_PILES', suffix='.tb') if output_piles: project.viia_collect_pile_reactions(pile_output_file=output_piles, analysis=analysis) else: project.write_log("WARNING: OUTPUT_STATIC_PILES not found. Pile force plots cannot be created.") # Generate result plots if required output is generated if project.viia_settings.python_result_plotting: output_file = project.viia_get_file( path=project.current_analysis_folder, in_name='OUTPUT_STATIC_TB', suffix='.tb') if not output_file.exists(): project.write_log("WARNING: Result tb-file not found for creating result plots. Plotting is skipped.") else: # Read the tb-file project.read_diana_tbfile(file=output_file) # Create result plot for displacements in z-direction project.plot_results_3d(output_item='U_z_tot') # Return the collected results return eng_a1
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================