How to use template script for server

The serverscript allows engineers to:

  1. create model

  2. run analysis

  3. perform result handling

all at once on the server, by only running the serverscript in pycharm. The script works by executing the mainscript and the resultscript. Engineers are able to use part of the above mentioned functions by defining the booleans in the template. The server template is avaiable for NLTH now. If you would like to extend features, please submit a feature request.

Template serverscript NLTH

Get packages installed correctly in DIANA

Note

First, make sure that you have read How to use the VIIA servers and understand the policy of using the servers.

The rhdhv_fem and viiaPackage and its dependency should already be installed on DIANA in the server. Please check your version by import rhdhv_fem and viiapackage in DIANA.

_images/import.png

It is important to have the package up-to-date for the serverscript to work properly. To update the viiapackage in Diana, you can open the cmd and run the following (use required version):

>>> "C:\Program Files\Diana 10.9\python\python.exe" -m  pip install --upgrade viiapackage==70.0.1 --user --extra-index-url="https://corporateroot.pkgs.visualstudio.com/VIIA/_packaging/viiapackage@Release/pypi/simple/"

Please note this will upgrade your DIANA python on server, if you want to use the system python, replace the first string with python. Make sure your viiaPackage is up-to-date and imported by the main/result/server script. The rhdhv_fem package will automatically be installed as part of the viiaPackage requirements.

The flowchart shows how the server template works and provides what are the input and output of each step, the engineer could customize the template based on their need:

_images/workflow.png

Get packages installed correctly in workfolder

It is necessary to have the viiapackage and rhdhv_fem package installed in the server workfolder, since the serverscript needs to be ran in pycharm.

The packages need to be installed manually through pip-install. First of all, a new project needs to be created and a virtual environment set. A detailed explanation of how to do this is found in this link: Manual setup workfolder.

Once the project and virtual environment are created, it is possible to install the packages in your workfolder:

>>> pip install viiapackage --extra-index-url=https://corporateroot.pkgs.visualstudio.com/VIIA/_packaging/viiapackage@Release/pypi/simple/

Note

This will also install the rhdhv_fem package.

Note

If you encounter difficulties during installation, it might be needed to perform the microsoft authentication process in the web browser of your local pc.

Required files in the server

The serverscript requires the following files to be saved in the workfolder in the server:

  1. Mainscript (the same used to perform all other analysis)

  2. Resultscript

  3. user_config (the same found in your local workfolder)

  4. model folder with json file (model/json)

The resultscript should be set with the correct object number, signal and desired output files.

Your workfolder in the server should look like this:

_static/howto_server_template/workfolder_structure.png

Serverscript overview

The serverscript is composed of 5 sections, each one labelled in the script.

The first section corresponds to the initialization of the script. This section is used to import the viia package and create the project. Make sure to input the correct object name under ‘project_name’.

# Import the viiaPackage
from viiapackage import *

# Create the project
project = viia_create_project(project_name='XXX')

The second section of the script contains the user input. In this section you can find a series of booleans and other variables:

  • run_maincript: controls whether the mainscript is ran in DIANA to generate the dcf and dat files.

  • signal: indicates which signal to run. Note that the signal needs to match in the serverscript, mainscript and resultsript!

  • run_analysis: controls if the analysis is ran in the command box using the dat and dcf files.

  • result_handling indicates if the resultscript is executed to generate the result pictures and other files.

# Booleans
run_mainscript = True  # Runs mainscript to create the .dat and .dcf files, set to false if files are already generated
run_analysis = True  # Runs the analysis in the cmd
result_handling = True  # Runs the resultscript to obtain result files and pictures

signal = 'SX'  # Should be consistent with the signal indicated in the mainscript and resultscript!
project_name = 'XXXX'

Then, the locations of the mainscript and the resultscript (in the server) are retrieved automatically, since these will be executed.

# Retrieve the mainscript and resultscript
current_directory = Path.cwd()
mainscript_path = project.viia_get_scripts_in_folder(folder=current_directory, file='mainscript')
resultscript_path = project.viia_get_scripts_in_folder(folder=current_directory, file='resultscript')

The script then checks if the ‘model’ folder and the ‘user_config’ file are present in the workfolder:

If these are not present, the user will receive a warning.

Step 1 - Run mainscript in DianaIE

First, the mainscript is run by DianaIE to create interfaces, analysis, etc… the output of this part is the dat-file and dcf-file, which should be created in the corresponding folder with timestamp. If you already have those files, set the run_mainscript boolean to False and jump to step 2.

Note

You will not see the log/error information from DianaIE, make sure your script is bug-free

# Create model in DianaIE -> .dat .dcf
if run_mainscript:
    # Run analysis through Diana IE
    viia_start_dianaie(file=mainscript_path, version='10.9')

Step 2 - Run analysis in Commandbox

If you skipped the first step make sure that the analysis_folder that contains the dat & dcf-files is set properly, otherwise the code will choose the latest folder.

if run_analysis:
    # Can be set to specific path by user
    analysis_folder = project.viia_get_latest_model_folder()

    # Result get dat-file and dcf-file
    # Make the default version of A12
    viia_run_diana_command_box(analysis_folder=analysis_folder/signal)

After the calculation is finished through the DIANA command box, the result files should be created in the folder, for example, the displacement and base shear tb-file and the NL_STATIC dnb-file.

Step 3 - Run result handling in DianaIE

Since the result pictures need to be generated in DianaIE, the following code will invoke DianaIE and run the result script. For more details of the result handling, please refer to How to use the resultscript for NLTH

# Result collection and post process A12
if result_handling:
    # Result collection and post process
    viia_start_dianaie(file=resultscript_path)

Finally, you should see all the result pictures generated along with all the analysis file, result file in the time-stamp folder.

_images/result_pic.png

Note

The last step is to collect result pictures and put it into report, it is in development.

There are two demo videos that show how to create analysis from the model json to the result handling in one go on server.

Create analysis

Result handling