### ===================================================================================================================
### Result pictures for nonlinear static analysis
### ===================================================================================================================
# Copyright ©VIIA 2024
### ===================================================================================================================
### 1. Import modules
### ===================================================================================================================
# General imports
from __future__ import annotations
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.pictures import ResultPicture, View
# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
from viiapackage.viiaStatus import ViiaProject
from viiapackage.pictures.result_pictures.helper_functions import viia_load_result_picture_yaml, \
viia_get_resultcase_info, viia_get_output_item, viia_get_scope_shape_sets, viia_get_result_picture_name, \
viia_set_model_and_analysis_diana
### ===================================================================================================================
### 2. Function to create the result pictures for nonlinear static analysis
### ===================================================================================================================
[docs]def viia_create_result_pictures_nls(
project: ViiaProject, analysis: Analysis, view: Optional[View] = None) -> List[ResultPicture]:
"""
Function to create the nonlinear static analysis result pictures.
Input:
- project (obj): VIIA project object containing collections of fem objects and project variables.
- analysis (obj): Object reference of analysis, to retrieve the result case, result items, result file and
relevant information.
- view (obj): View that should be used for the pictures. When None the default view will be used. Default is
None.
Output:
- Returns the result pictures created for nonlinear static analysis.
"""
# Get the result picture dictionary
picture_data = viia_load_result_picture_yaml(project=project)
# Find the result scope
result_scopes = picture_data['result_scope'][analysis.name]
output_block_pic = analysis.calculation_blocks[-1].output_blocks[0]
# Set up the path of the result file
result_file = project.current_analysis_folder / (output_block_pic.output_filename + '.dnb')
# Create render and view
# The model is created
if not project.rhdhvDIANA.model_created:
if not project.diana_settings.latest_dat_file:
project.diana_settings.latest_dat_file = project.viia_get_file(path=project.current_analysis_folder,
suffix='.dat')
if project.rhdhvDIANA.run_diana:
viia_set_model_and_analysis_diana(project=project, analysis=analysis)
if view is None:
if project.rhdhvDIANA.model_created and project.rhdhvDIANA.run_diana:
project.rhdhvDIANA.showAll('SHAPE')
project.rhdhvDIANA.setViewPoint('ISO1')
diana_view_point = list(project.rhdhvDIANA.currentViewPoint()).copy()
view = project.create_view_from_diana_view_point(name='User_defined', diana_view_point=diana_view_point)
else:
view = project.create_view(name='ISO1')
render = project.create_render(name='Render_NLS')
# Loop through result scope and picture type
pictures = []
for pic_type_key, scopes in result_scopes.items():
picture_type = picture_data['picture_type'][pic_type_key]
# Set units for the result picture
unit_setting = None
if picture_type.get('unit_type'):
unit_setting = {}
for unit_type, units in zip(picture_type.get('unit_type'), picture_type.get('units')):
unit_setting[unit_type] = units
# Get the step and execute block
step, execute = viia_get_resultcase_info(
analysis=analysis, analysis_block=analysis.calculation_blocks[-1],
case=picture_type['case'], eigenfrequencies=None)
# Loop through scopes, defining the shapes visible
for scope in scopes:
shape_sets = viia_get_scope_shape_sets(project=project, scope=scope, pic_type=pic_type_key)
# Defining the components, defining for example the directions
for component in picture_type['components']:
# Collect the output-item required for the result picture
output_item = viia_get_output_item(
project=project, picture_type=picture_type, output_item_lst=output_block_pic.output_items,
component=component)
if not output_item:
continue
abbreviation = output_item.diana_result_picture(
plot_type=picture_type['plot_type'], result_component=component)['component']
# Create pictures
for layer, shapes in shape_sets.items():
layer_name = layer
if layer == 'Building':
layer_name = None
# Setting the contour legend for the result picture
contour_legend = project.create_contour_legend(
unit_settings=unit_setting, legend_size=[0.015, 0.8])
# Create the picture name
pic_name = viia_get_result_picture_name(
diana_component_abbreviation=abbreviation, scope=scope, analysis_type='nls',
layer=layer_name, pic_type_key=pic_type_key)
# Create the picture
pictures.append(project.create_result_picture(
name=pic_name, analysis=analysis, render=render, shapes=shapes, view=view,
output_block=output_block_pic, legend=contour_legend, execute_block=execute,
output_item=output_item, result_layer=picture_type.get('result_layer'), step=step,
plot_type=picture_type.get('plot_type'), result_file=result_file.as_posix()))
# Create the result pictures when running in DIANA
if project.rhdhvDIANA.run_diana:
# Getting result picture from existing result files
current_dnb_file = None
for picture in pictures:
picture.to_diana(current_dnb_file=current_dnb_file)
current_dnb_file = picture.result_file
project.write_log(f"{len(pictures)} result pictures for {analysis.name.split(' - ')[0]} are created.")
return pictures
### ===================================================================================================================
### 3. End of script
### ===================================================================================================================