The NextFEM APIs give the opportunity to create a finite element model through a few lines of code, which directly call the modelling commands and provide full access to the results of the finite element analysis. In this example we will deal with a projecting roof anchored at 45, modelled through the Python programming language.

 

For this tutorial we will use Visual Studio 2019, which implements Python 3.7. Once inside the Python development environment, you need to check that you have loaded all the packages necessary for our purpose. The NextFEM APIs were created in .NET language, therefore the "Python for NET" package must be present in the Python environment, which allows interoperability between the two programming languages. By accessing the Python interface window from Tools / Python / Python environments it will be possible to install, if not already present, the pythonnet package by typing it in the Packages (PyPI) search bar and running the suggested command pip install pythonnet.

 

 

 

Firstly, import the sys module, which will allow to interact with the interpreter of the operating system we are using.

 

import sys

 

The NextFEM APIs can be loaded into the project environment using the AddReference method of the PythonNET clr instance, specifying the path where the NextFEMapi.dll file is located. If you are using 32bit NextFEM Designer the path to use is C:\Program Files (x86)\NextFEM\NextFEM Designer 32bit\NextFEMapi.dll, while for 64bit it is C:\Program Files\NextFEM\NextFEM Designer 64bit\NextFEMapi.dll. Remember that in Python the backslash (\) in the paths must be doubled, or it must be replaced with the slash (/).

 

import clr

clr.AddReference("C:\\Program Files\\NextFEM\\NextFEM Designer 64bit\\NextFEMapi.dll")

 

You can now create an instance that allows to use API methods, defined in the current example as nf.

 

import NextFEMapi

nf=NextFEMapi.API()

 

It is advisable to start always with a check on the activation of the API license, which will report an error on the screen in case APIs are not licensed and will close the application.

Not all methods needs a license, some are free to use. See the API reference for more information.

 

if nf.isAPIlicensed() == False:

print("APIs are NOT licensed")

sys.exit(0)

else:

print("APIs are licensed")

 

 

 

The NextFEM API methods are listed and exemplified on the page www.nextfem.it/api. The chosen method can be called in the Python environment with the instance.method syntax. In this case, the following line of code will be used to create a new model:

 

nf.newModel

 

To display the model units, two variables can be created, which we will call Lu for length and Fu for force units, and print them on the screen using these commands:

 

Lu=nf.getLenUnit()

Fu=nf.getForceUnit()

print("Model units: " + Lu + ", " + Fu)

 

By launching the application, the result obtained up to this point is the following:

 

 

Now the projecting roof is modelled, having dimensions 2.0x4.0m. The coordinates of the nodes can be entered with the addNode method, which also allows to specify the coordinates of two versors and thus rotate the node according to a local reference system. In this example the nodes 1 and 4 will be rotated by 45 assuming that the structure is supported by oblique columns.

 

n1=nf.addNode(0,0,0,1,0,-1,0,1,0)

n2=nf.addNode(2,0,0)

n3=nf.addNode(2,4,0)

n4=nf.addNode(0,4,0,1,0,-1,0,1,0)

 

The API documentation of each method in the NextFEM API is available on nextfem.it/api or in the reference made in Windows Guide format included with the installation.

 

 

The setBC method is used to assign constraints to the indicated node, specifying the directions to retain, as listed in the Designer.

 

nf.setBC(n1, True, True, True, False, True, True)

nf.setBC(n4, True, True, True, False, False, False)

 

Assuming four steel beams with IPE 140 profile, material and section are loaded with the addSectFromLib and addMatFromLib methods, using the archive already present in the software. Note that the IDs of nodes, elements, materials and sections are saved in variables (sectID, matID, etc.) which can be reused later to associate the properties of the element.

 

sectID=nf.addSectFromLib("IPE 140")

matID=nf.addMatFromLib("S275")

 

To create the beam elements, you must specify the start node, the end node, the material and the section assigned using the addBeam method.

 

beamID1=nf.addBeam(n1, n2, sectID, matID)

beamID2=nf.addBeam(n2, n3, sectID, matID)

beamID3=nf.addBeam(n3, n4, sectID, matID)

beamID4=nf.addBeam(n4, n1, sectID, matID)

 

The loads on the projecting roof are assumed to be 1.8kN/m2, for which a floor load will be assigned within the load case G. In the method for the floor load, in addition to the name and load case, the intensity of force and the direction of application must be defined. To apply the load, the mode must also be defined, indicated with number 2 and representing the load distributed on all 4 sides. Here are the commands:

 

nf.addLoadCase("G")

nf.setFloorLoad("load", "G", 1.8, 0, 0, -1)

nf.addFloorLoadPlane("load", 2, n1, n2, n3, n4)

 

Then the newly created model is analysed, and then opened in Designer with the results already available:

 

s=nf.RunModel(); print(s)

nf.saveModel("proj_roof.nxf")

nf.startDesigner("proj_roof.nxf")

 

 

 

 

Constraint forces and reactions are influenced by the new local axes assigned during the node creation phase. As can be seen in the figure, the constraint reactions along the Z direction are rotated by 45.

 

The entire code used is shown below:

 

import sys

import clr

clr.AddReference("C:\\Program Files\\NextFEM\\NextFEM Designer 64bit\\NextFEMapi.dll")

 

import NextFEMapi

nf=NextFEMapi.API()

if nf.isAPIlicensed() == False:

print("APIs are NOT licensed")

sys.exit(0)

else:

print("APIs are licensed")

nf.newModel

Lu=nf.getLenUnit()

Fu=nf.getForceUnit()

print("Model units: " + Lu + ", " + Fu)

n1=nf.addNode(0,0,0,1,0,-1,0,1,0)

n2=nf.addNode(2,0,0)

n3=nf.addNode(2,4,0)

n4=nf.addNode(0,4,0,1,0,-1,0,1,0)

nf.setBC(n1, True, True, True, True, True, True)

nf.setBC(n4, True, True, True, True, True, True)

sectID=nf.addSectFromLib("IPE 140")

matID=nf.addMatFromLib("S275")

beamID1=nf.addBeam(n1, n2, sectID, matID)

beamID2=nf.addBeam(n2, n3, sectID, matID)

beamID3=nf.addBeam(n3, n4, sectID, matID)

beamID4=nf.addBeam(n4, n1, sectID, matID)

nf.addLoadCase("G")

nf.setFloorLoad("load", "G", 1.8, 0, 0, -1)

nf.addFloorLoadPlane("load", 2, n1, n2, n3, n4)

s=nf.RunModel(); print(s)

nf.saveModel("proj_roof.nxf")

nf.startDesigner("proj_roof.nxf")

 

The methods that can be used will be implemented by including all the current features of the software and those currently under development, with particular attention to smart checking and the results processing.