### ===================================================================================================================
### _viia_mrs_nmodes
### ===================================================================================================================
# Copyright ©VIIA 2024
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
from typing import TYPE_CHECKING
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
### ===================================================================================================================
### 2. Function to read A3 - eigen value fixed base or A7 - eigen value flex base results and get nmodes automatically
### ===================================================================================================================
[docs]def viia_mrs_nmodes(project: ViiaProject):
"""
This function finds the number of nodes that are needed as input in MRS analysis. It looks through files in project
directory for A3 - Eigenvalue fixed base OR A7 - Eigenvalue flex base results. If results are available then it
finds nmodes from the .out file. If results are not present, then an error message is logged, asking user to either
provide nmodes, or to put A3/A7 result files in the project directory.
Input:
- project (obj): Project object containing collections and of fem objects and project variables.
Output:
- Returns nmodes, an integer for number of modes needed in MRS analysis.
"""
# Check if A3 or A7 folders are present
folder_list = [path for path in project.workfolder_location.iterdir() if path.is_dir()]
folder_a7 = False
folder_a3 = False
if 'A7 - Eigenvalue flex base' in folder_list:
folder = project.workfolder_location / 'A7 - Eigenvalue flex base'
project.write_log(
"A7 analysis folder found, nmodes for MRS (A5) will be collected from the latest A7 analysis, please "
"make sure the latest A7 analysis is the relevant one.")
elif 'A3 - Eigenvalue fixed base' in folder_list:
folder = project.workfolder_location / 'A3 - Eigenvalue fixed base'
project.write_log(
"A3 analysis folder found, nmodes for MRS (A5) will be collected from the latest A3 analysis, please make "
"sure the latest A3 analysis is the relevant one.")
else:
raise FileNotFoundError(
f"ERROR: A3 / A7 analysis were not found in {project.workfolder_location}, either 1) Run eigen value "
f"analysis or 2) provide value of nmodes in MRS (A5) analysis manually.")
if folder:
# Check the names of folder and get the latest folder (corresponding to most recent A7 analysis)
from viiapackage.results.result_functions.viia_get_latest_result_folder import viia_get_latest_folder
latest_folder = viia_get_latest_folder(project.version, folder)
# From the latest folder, find .out file
out_file = next(x for x in max(latest_folder.values()).iterdir() if x.suffix == '.out')
# Analyse out-file and get cumulative modal participation in x- and y- direction
result_items = project.read_diana_outfile(out_file, outfile_type='eigenvalue')
for key, value in result_items.items():
if value['cum. percentage x-direction'] > 70 and value['cum. percentage y-direction'] > 70:
return key
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================