Source code for viiapackage.results.result_functions.viia_convergence_graph

### ===================================================================================================================
###   Function to create the convergence graph for VIIA
### ===================================================================================================================
# Copyright ©VIIA 2024

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

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

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

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


### ===================================================================================================================
###   2. Function viia_convergence_graph
### ===================================================================================================================

[docs]def viia_convergence_graph( project: ViiaProject, file: Union[Path, str], criterion: str = 'energy', signal: Optional[str] = None, show: bool = True, plasticity: bool = False, analysis: Optional[Union[str, Analysis]] = None) -> Path: """ Function generates the convergence graph based on the output file of a DIANA analysis. Input: - project (obj): Project object containing collections and of fem objects and project variables. - file (path or str): File name and location as single string of the out-file (DIANA) or msg-file (ABAQUS). - criterion (str): Select the criterion to plot the convergence for. For DIANA, choose between energy, displacement or force convergence criterium. For ABAQUS, choose between force or moment convergence criterium. For ABAQUS, a displacement convergence graph is also added when force is chosen, a rotation convergence graph is added for moment. Only one criterion can be selected. Default value is energy. - signal (str): Optional input to include signal in title. Can be S1-S11. - show (bool): Switch to indicate if the pop-up screen of the graph should appear. Default value is True. - plasticity (bool): Select to add another graph for the plasticity behaviour. Default value is False, in which case only cracking behaviour is plotted. - analysis (Obj): Optional input for the object reference of the analysis that is performed. Default value is None. Also, the name of the analysis can be provided as string (in that case it is only used in the title of the plot). Output: - Returns the path of the created image with the convergence graph and supporting graphs. The image is saved in the current analysis folder. """ # Check input for the input-file from software if isinstance(file, str): file = Path(file) if not file.exists(): raise FileNotFoundError( f"ERROR: The input file for the convergence graph was not found. Expected file at: {file.as_posix()}.") if file.suffix == '.msg': raise NotImplementedError( "ERROR: Currently the functionality for the convergence graph in ABAQUS software is not supported. Please " "contact automation team and provide the msg-file for implementation.") elif file.suffix != '.out': raise ValueError( f"ERROR: The convergence graph function expects an out-file for DIANA analyses. Provided was " f"{file.as_posix()}.") # Set some default inputs for the VIIA workflow style_file = Path(project.viia_settings.project_specific_package_location) / 'viiaGraph.mplstyle' image_file = project.current_analysis_folder / 'CONVERGENCE.png' if criterion != 'energy': image_file = project.current_analysis_folder / f'CONVERGENCE_{criterion.upper()}.png' title = f'Convergence graph' if analysis: if isinstance(analysis, str): title += f' for {analysis}' else: title += f' for {analysis.name}' if signal: title += f' | Signal {signal}' graphs = ['convergence', criterion, 'force', 'cracking'] if plasticity: graphs.append('plasticity') if isinstance(analysis, str): analysis = project.viia_get(collection='analyses', name=analysis) # Read the DIANA dat-file and collect the data for the convergence behaviour analysis_log = project.read_diana_outfile(file=file, analysis=analysis, outfile_type='convergence') # Create the convergence graph return analysis_log.plot_convergence( graphs=graphs, show=show, save_file=image_file, title=title, style_file=style_file)
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================