Using Python and SCIA to create parametric models in the Cloud

Anande Bergman

by Anande Bergman

For the design of civil structures, civil engineers commonly use SCIA Engineer to assess whether designs suffice the requirements. SCIA Engineers offers and API that allows people to automatically (re)calculate structural models within a VIKTOR web app. VIKTOR also created a Python library consisting of several specific SCIA objects that can be used to build (parametric) models that can be exported to XML format and be read in SCIA.
Download the white paper and get INSPIRED

Collaborative parametric design models allow you to work together for better solutions

Civil engineering automation

A structural design process consists of several or perhaps many design iterations. For each iteration, a civil engineer designs a structural model and uses structural analysis software, such as SCIA Engineer, to perform an assessment. If the SCIA software indicates that a structure does not meet the requirements or if some input has changed, this cycle is repeated. Therefore, this can be a very time-consuming process. The more manual actions, the greater the risk of errors.

Time and risk can be significantly reduced by automating the above steps. VIKTOR offers a binding with SCIA Engineer that enables civil engineers to calculate structural models at the push of a button, using a parametric Python model in the Cloud, without even having to open the SCIA interface.

Open-source Python library

VIKTOR developers have encountered multiple civil engineering design projects for which a SCIA Engineer model had to be created. Using all this knowledge, a growing Python library with digital building blocks came to be. At some point this library got included in the VIKTOR SDK, making it publicly available.

In addition to the Python library, an integration with SCIA itself was developed that allows the civil engineer to automatically perform analysis within a user-friendly VIKTOR app without having to open the SCIA interface at all.

Design automation with SCIA

Creating a SCIA model with a few lines of Python code

Building SCIA models using the VIKTOR SDK is done by writing object-oriented Python code; no knowledge of the SCIA Engineer API is required. All the relevant Python building blocks can be found in the module viktor.external.scia, of which the starting point is the SciaModel.

Let’s start by creating a new instance of this class, to which subsequently desired elements (e.g. nodes, cross-sections, beams, supports, loads etc.) can be added.

The example below shows what this could look like in Python code:

1Def create_scia_model(self, params) --> SciaModel: 2Model = SciaModel() 3 4 5# create nodes 6Model.create_node(‘K:1’, 0, 0, 0) # origin 7Model.create_node(‘K:2’, params.geometry.piles.x1, 0, 0) 8Model.create_node(‘K:3’, params.geometry.piles.x2, 0, 0) 910Model.create_node(‘K:n’, params.geometry.piles.floor.width, 0, 0) 11 12 13# create pile beams 14Model.create_beam(‘S:pile1’, top_pile_1, bottom_pile_1, cross_section) 1516 17 18Return model

We often recognise that it is difficult to verify whether the developed Python code actually builds up the correct SCIA Engineer model. That is why we recommend creating a visualization of the model within VIKTOR simultaneously. The visualization is not only helpful for visually verifying the model, it also serves as a very nice design overview for the end user! The method defined above can be used in a generic visualization method as shown below:

1@GeometryView(“SCIA model”, duration_guess=3) 2def create_visualization_geometries(self, params, **kwargs): 3scia_model = self.create_scia_model(params) 4 5 6# nodes 7geometry_group = Group([]) 8for node in scia_model.nodes: 9node_obj = Sphere(Point(node.x, node.y, node.z), 1) 10geometry_group.add(node_obj) 11 12 13# beams 14pile_diameter = params.geometry.piles.diameter 15for beam in scia_model.beams: 16point_top = Point(beam.begin_node.x, beam.begin_node.y, beam.begin_node.z) 17point_bottom = Point(beam.end_node.x, beam.end_node.y, beam.end_node.z) 18beam_obj = CircularExtrusion(pile_diameter, Line(point_top, point_bottom) 19geometry_group.add(beam_obj) 20 21 2223 24 25return geometry_group

By using the geometric VIKTOR Python building blocks (viktor.geometry module), the elements of the structural SCIA Engineer model can be easily converted to geometric elements and passed to a geometry result.

Visualizing structural models in the SCIA interface

It is always useful to manually load the created SCIA Engineer model in the SCIA Engineer interface, which will help to verify that, for example, all the loads are correctly defined in terms of placement and magnitude.

To visualise the created structural model in the SCIA interface, the following three files are needed:

  • model file (*.esa)
  • definition file (*.def)
  • input file (*.xml)

The model file can simply be an empty project file. The other two files can be easily generated by calling the method generate_xml_input() on the SciaModel created above. It is probably a good idea to develop a download functionality such that the end user can manually download the input files as well:

1Def download_scia_input_xml(self, params, **kwargs): 2Scia_model = self.create_scia_model(params) 3Input_xml, _ = scia_model.generate_xml_input 4 5 6Result = DownlaodResult(input_xml.getvalue(), ‘test.xml’) 7Return ViktorResult(download_result=result) 8Def download_scia_input_def(self, params, **kwargs): 9M = SciaModel() 10_, input_def = m.generate_xml_input() 11Result = DownloadResult(input_def.getvalue(), ‘viktor.xml.def’) 12Return ViktorResult(download_result=result)

The next step is to load the three files into the SCIA interface (File > Update > XML file) and verify the created model.

Analyzing the structural SCIA model within VIKTOR

In addition to the binding to build up the SCIA Engineer structural model, the viktor.external.scia module also offers an analysis Python building block (SciaAnalysis) which sends the required input files to the so-called SCIA worker, which runs on a designated (virtual) machine and executes SCIA. When the analysis has been completed, the worker sends the result file back to the web application. The OutputParser (from viktor.external.scia) can be used to easily extract specific results from the result file.

Below you can find an example of the result processing and the associated visualisation.

1@GeometryAndDataView(“SCIA Result”, duration_guess=60) 2Def run_scia(self, params, **kwargs): 3Scia_model = self.create_scia_model(params) 4 5 6# create input files 7Esa_path = Path(__file__).parent / ‘scia’ / ‘model.esa’ 8Input_esa = BytesI0() 9With open(esa_path, “rb”) as esa_file: 10Input_esa.write(esa_file.read()) 11 12 13Input_xml, input_def = scia_model.generate_xml_input() 14 15 16# analyze SCIA model 17Scia_analysis = SciaAnalysis(input_xml, input_def, input_esa) 18Scia_analysis.execute(300) # timeout after 5 minutes 19Scia_result = scia_analaysis.get_xml_output_file() 20 21 22#parse analysis result 23Parser = OutputParser(scia_result) 24Table_element = parser.get_table_element_from_name(“Reactions”, parent=’Combinations – C1’) 25Df = parser.convert_table_element_to_data_frame(table_element 26 27 28Max_rz = float(max(df[‘R_z])) 29Data_result = DataGroup( 30DataItem(‘SCIA results’, ‘, subgroup=DataGroup( 31DataItem(‘Maximum pile reaction’, max_rz, suffix=’N’, number_of_decimals=) 32)) 33) 34 35 36Geometry_group = self.create_visualization_geometries(params, scia_model) 37Return GeometryAndDataResult(geometry_group, data_result)

An example of the result processing

blog_python_scia_example_associated_processing

The associated visualization

This video shows how the parametric geometry is build within in VIKTOR and what it looks like when SCIA Engineer is used to analyze the structural design from within the app, using Python. The model is downloadable so that results can be viewed in SCIA Engineer or directly within the web app. With the app, civil engineers are sure to always work with the latest structural model, perform fast structural analysis to save time, and get clear results and rich visualisations.

A total design solution

The SCIA binding developed by VIKTOR allows for an easy conversion between a parametric model, to a meaningful input for SCIA Engineer, using only Python.

A VIKTOR worker takes care of a connection between the web application and the structural design and analysis software, such that SCIA can be executed from within the browser.

After the structural analysis, the results are returned and can be visualised on top of the model visualization. This means that the manual tasks of constructing the structural design for a SCIA Engineer model in the interface, analysing the structural model, and assessing the results can all be done by the civil engineer with a simple click of a button from within the VIKTOR interface!

See how you can integrate with your preferred software, using only Python and how you can use parametric design in the Cloud to build civil engineering apps!

SCIA scan.png

See how you can build your own apps to automate civil engineering processes:

CTA_try_for_free

Related content

A list of articles about integrations with civil engineering software and structural design & analysis software that you might find interesting as well:

Share

Related Blog Posts

plotly pandas numpy matplotlib python

Visualize your data with Python and VIKTOR

Read more

Save time by automating PLAXIS in the Cloud

Read more

Hackathon stimulates knowledge development

Read more