### ===================================================================================================================
### A2 Rob-test result handling
### ===================================================================================================================
# Copyright ©VIIA 2024
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, Union, Optional
from pathlib import Path
# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_math import fem_greater, fem_smaller
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
### ===================================================================================================================
### 2. Function to handle results for A2 analysis
### ===================================================================================================================
[docs]def viia_results_a2(project: ViiaProject, out_file: Path, runtime: Optional[float] = None):
"""
Combination of functions to be performed on output of A2 Rob-test.
Includes:
- Boolean of the outcome of the Rob-test analysis.
Input:
- project (obj): Project object containing collections and 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.
Alternative (str): The DIANA out-file location and filename of the analysis requested as string.
- 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.
Output:
- Result items of A2 calculation are saved in project.
"""
if project.software == 'abaqus':
project.write_log(
"WARNING: A2 result handling for ABAQUS is not available and not required for VIIA workflow in ABAQUS "
"software.")
return None
# Determine succes of Rob-test
if not out_file:
out_file = project.viia_get_file(path=project.current_analysis_folder, suffix='.out')
if out_file:
_viia_check_robtest(project, out_file)
else:
project.write_log("A2 out-file not found. Result handling for A2 skipped.")
### ===================================================================================================================
### 3. Sub-function to check if the Rob-test complies
### ===================================================================================================================
def _viia_check_robtest(project: ViiaProject, file: Union[Path, str]):
"""
Function to check if the criteria of Rob-test are met with the output file.
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 outputfile.
Output:
- Notification on screen and in log whether the ROb-test was successful or not.
- Returns boolean: the Rob-test was successful 'True' and if not 'False'.
"""
# Set the path reference when function is entered as string
if type(file) == str:
file = Path(file)
# Read file
if file.suffix != '.tb':
project.write_log(
f"ERROR: Input '{file.as_posix()}' is not a tb-file, correct the input or filetype 'tabulated'.")
return False
def is_float(inpt):
try:
num = float(inpt)
except ValueError:
return False
return True
f = open(file, 'r')
x = f.readlines()
robtest = True
data = []
for i in range(8, len(x)):
data.append(str(x[i]))
data[i - 8] = data[i - 8].split()
if not data[i - 8]:
continue
if not is_float(str(data[i - 8][0])):
continue
if fem_greater(float(data[i - 8][1]), 0.01) or fem_smaller(float(data[i - 8][1]), -0.01):
project.write_log("Rob-test has failed.")
robtest = False
break
elif fem_greater(float(data[i - 8][2]), 0.01) or fem_smaller(float(data[i - 8][2]), -0.01):
project.write_log("Rob-test has failed.")
robtest = False
break
elif fem_smaller(float(data[i - 8][3]), -1.01) or fem_greater(float(data[i - 8][3]), -0.99):
project.write_log("Rob-test has failed.")
robtest = False
break
if robtest:
project.write_log("Rob-test was successful.")
# Save the results to the result dictionary
project.results['A2'] = {'robtest': robtest}
return True
### ===================================================================================================================
### 4. End of script
### ===================================================================================================================