Source code for viiapackage.analyses.helper_functions.viia_create_analysis_files_diana

### ===================================================================================================================
###  FUNCTION: Create the files required for the analysis in DIANA
### ===================================================================================================================
# Copyright ©VIIA 2024

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

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

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

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


### ===================================================================================================================
###   2. Function viia_create_analysis_files_diana
### ===================================================================================================================

[docs]def viia_create_analysis_files_diana( project: ViiaProject, analysis: Analysis, combox_location: Optional[str] = None) -> List[Path]: """ Function to create or collect the files required to perform the analysis. These files are collected in the current analysis folder. When the analysis is not performed in DIANA GUI directly, the dcf-file is updated and prepared for the analysis in DIANA command box. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - analysis (obj): Object reference of the analysis for which the files are created / collected. - combox_location (str): Optional input to prepare the dcf-file for running analysis. For example the location of the user supplied subroutines, if any. Default value is None, dcf-file is not updated. Output: - Returns list of all created files in the 'current analysis folder'. """ # Collect the files files = list() # Copy dat-file dat_file = fem_copy_file( file_to_copy=project.diana_settings.latest_dat_file, destination_folder=project.current_analysis_folder) files.append(dat_file) # Determine the name of the dpf-file and save a copy of the DIANA model dpf_file_name = f'{project.name}_v{project.version}.dpf' dpf_file = project.current_analysis_folder / dpf_file_name project.rhdhvDIANA.saveProjectAs(dpf_file.as_posix()) dpf_file = project.workfolder_location / dpf_file_name project.rhdhvDIANA.saveProjectAs(dpf_file.as_posix()) # Move dcf-file to the folder dcf_file = fem_copy_file( file_to_copy=project.diana_settings.latest_dcf_file.as_posix(), destination_folder=project.current_analysis_folder.as_posix()) if dcf_file: # Rename the file for convenience in command-box new_file = project.current_analysis_folder / f'{dat_file.stem}.dcf' dcf_file.rename(new_file) files.append(new_file) project.diana_settings.latest_dcf_file = new_file # When the analysis is to be performed in DIANA command-box, the files are prepared for this if combox_location: # Prepare the dcf-file for running in com-box viia_prepare_analysis(project=project, location=combox_location) # Return the created / collected files return files
### =================================================================================================================== ### 3. End of script ### ===================================================================================================================