### ===================================================================================================================
### Preparing for running analysis in command-box DIANA
### ===================================================================================================================
# Copyright ©VIIA 2025
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING, Optional
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
### ===================================================================================================================
### 2. Function viia_prepare_analysis
### ===================================================================================================================
[docs]def viia_prepare_analysis(project: ViiaProject, location: str = 'viiaPackage', threads: int = 4) -> Optional[Path]:
"""
This function prepares the latest created dcf-file for running a calculation in a command-box. It prepares the
dcf-file by adding the information on initialising the filos file. It also adds the reference to the user
supplied subroutine file(s), depending on the location where the calculation will be running.
For fixed base analysis it is not needed to add the user supplied subroutine, input for the location is then
ignored.
.. note:: This function is specific for DIANA.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- location (str): Location where the calculation will be running. Default value is 'viiaPackage'. For running
the calculation, DIANA needs to find the user supplied subroutines for shallow and pile foundations, if
applicable. Allowed arguments are 'viiaPackage', 'server' or the directory location containing the
subroutine(s) as string. folders seperated with double backslashes and double quotation marks in string
('"E:\\VIIA\\"'). If the support-type is fixed base, this input is ignored.
- threads (int): Number of threads that should be used for the calculation.
Output:
- The latest dcf-file is prepared for calculating in command-box for DIANA.
- The file reference of the (updated) dcf-file is returned at path.
"""
# Apply user supplied subroutine for flexbase analyses
dll_name = None
if project.viia_settings.support_type != 'FixedBase':
if len(project.viia_supported_surfaces) > 0 and len(project.viia_supported_points) > 0:
# For mixed foundations
dll_name = 'usrspr_usrifc'
elif len(project.viia_supported_surfaces) > 0:
# For shallow foundations
dll_name = 'usrifc'
elif len(project.viia_supported_points) > 0:
# For pile foundations
dll_name = 'usrspr'
# Handle input value for location
usr_dll_location = None
if dll_name:
if location.lower() == 'viiapackage':
folder = project.workfolder_location / 'viiapackage' / 'software_specific' / 'DIANA' / 'subroutines' / \
dll_name
usr_dll_location = f'"{(folder / (dll_name + ".dll")).as_posix()}"'
elif location.lower() == 'server':
usr_dll_location = f'"E:\\VIIA\\{dll_name}.dll"'
elif not location:
pass
else:
usr_dll_location = f'"{location}\\{dll_name}.dll"'
# Open the latest dcf file to adjust for the location of the dll file
if project.diana_settings.latest_dcf_file is None or not project.diana_settings.latest_dcf_file.exists():
if project.diana_settings.latest_dcf_file is None:
project.write_log(
f"WARNING: The DCF-file is not present, please check if it is created with the proper functions.")
else:
project.write_log(
f"ERROR: File {project.diana_settings.latest_dcf_file.name} not found, check folder for dcf-file.")
return None
with open(project.diana_settings.latest_dcf_file, 'r') as f:
lines = f.readlines()
# Add the initialisation of the filos file for running calculations in command-box
if 'NUMTHR' in lines[0] or 'FILOS' in lines[0]:
# Initialisation is already present, no adjustments are made
project.write_log(
f"File {project.diana_settings.latest_dcf_file.name} was already prepared for calculations on command-box, "
f"no adjustments made.")
return project.diana_settings.latest_dcf_file
lines.insert(0, '%s\n' % f"NUMTHR {threads}")
lines.insert(1, '%s\n' % '*FILOS')
lines.insert(2, '%s\n' % 'INITIA')
lines.insert(3, '%s\n' % '*INPUT')
# Add location of user supplied subroutine if shallow foundation is present. Location is input value
if usr_dll_location:
lines.insert(4, '%s\n' % '*FORTRAN')
dll_line = 5
lines.insert(dll_line, '%s %s\n' % ('USE', usr_dll_location))
# Write adjusted DCF-file (overwrite existing)
text = ""
for i in range(len(lines)):
text = text + lines[i]
f = open(project.diana_settings.latest_dcf_file, 'w')
f.write(text)
f.close()
# Returns the file reference
return project.diana_settings.latest_dcf_file
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================