47
Python Manual

CivilFEM Python Manual

Embed Size (px)

DESCRIPTION

Python is an interpreted, interactive object-oriented programming language sometimes compared to Perl, Java, and Tcl. It has interfaces to IP networking, windowing systems, audio, and other technologies. Integrated with CivilFEM, it provides a more powerful scripting language than procedure files as it contains conditional logic and looping statements such as if, while, and for.

Citation preview

Page 1: CivilFEM Python Manual

Python Manual

Page 2: CivilFEM Python Manual

2

Table of Contents

Python Manual ........................................................................................................................... 1

Table of Contents ....................................................................................................................... 2

Chapter 1 .................................................................................................................................... 5

1.1. Introduction to Python .......................................................................................... 6

1.1.1. Data Types ............................................................................................ 6

1.1.2. Syntax considerations ........................................................................... 6

1.1.3. Expert utilities ...................................................................................... 7

1.2. Python with CivilFEM .......................................................................................... 8

1.2.1. Basic Types .......................................................................................... 8

1.2.2. Script Editor and Command Line ......................................................... 8

1.2.3. Macro Recording ................................................................................ 11

1.2.4. Script Manual ..................................................................................... 11

1.2.5. Python libraries ................................................................................... 11

1.2.6. Default conditions .............................................................................. 12

1.2.7. Enumerates and arguments ................................................................. 13

1.2.8. Parameters .......................................................................................... 13

1.2.9. Containers ........................................................................................... 13

Chapter 2 .................................................................................................................................. 15

2.1. Files ....................................................................................................................... 16

2.2. Environment Commands .................................................................................... 17

2.3. Geometry creation ............................................................................................... 18

2.3.1. Points and lines ................................................................................... 18

Page 3: CivilFEM Python Manual

3

2.3.2. Surfaces and Volumes ........................................................................ 18

2.3.3. Import and Export geometry .............................................................. 19

2.4. Materials ............................................................................................................... 20

2.5. Cross Sections ...................................................................................................... 23

2.5.1. Create Sections ................................................................................... 23

2.5.2. Plot and Snapshot Sections ................................................................. 24

2.6. Mesh ...................................................................................................................... 25

2.6.1. Structural Elements ............................................................................ 25

2.6.2. Model Utils & Contacts ...................................................................... 26

2.6.3. Mesh & Mesh Tools ........................................................................... 26

2.7. Loading ................................................................................................................. 28

2.7.1. Loads .................................................................................................. 28

2.7.2. Load Case ........................................................................................... 29

2.8. Solve ...................................................................................................................... 30

2.8.1. Solver Configuration & Solver Output............................................... 30

2.8.2. Solve ................................................................................................... 30

2.9. CivilFEM results .................................................................................................. 31

2.9.1. General Results ................................................................................... 31

2.9.2. Envelope ............................................................................................. 32

2.9.3. Checking and Design .......................................................................... 32

2.9.4. Interaction Diagrams .......................................................................... 33

2.10. View Options ........................................................................................................ 34

2.10.1. Grid ..................................................................................................... 34

2.10.2. Camera ................................................................................................ 34

Page 4: CivilFEM Python Manual

4

Chapter 3 .................................................................................................................................. 36

3.1. Example 1: Warehouse ....................................................................................... 37

3.1.1. Problem description ............................................................................ 37

3.1.1. Python Code ....................................................................................... 40

Page 5: CivilFEM Python Manual

5

Chapter 1

General Aspect

Page 6: CivilFEM Python Manual

6

1.1. Introduction to Python

Python is an interpreted, interactive object-oriented programming language sometimes compared to

Perl, Java, and Tcl. It has interfaces to IP networking, windowing systems, audio, and other

technologies. Integrated with CivilFEM, it provides a more powerful scripting language than

procedure files as it contains conditional logic and looping statements such as if, while, and for.

1.1.1. Data Types

When programming in Python, you don’t explicitly declare a variable’s data type. Python

determines this characteristics by how the variable is being used. Python supports the following

implied data types:

Basic Data Types

string A character string similar to char data in C and character in FORTRAN. A string

may be specified using either single or double quotes.

float A floating point number similar to double data type in C and the real*8 data type

in FORTRAN.

integer An integer or fixed point number similar to the long int data type in C and the

integer*8 data type in FORTRAN.

Extended Data Types

list A Python list is essentially a linked list that can be accessed like an array using

the square bracket operators [ ]. The list can be composed of strings, floats, or

integers to name a few.

1.1.2. Syntax considerations

There are some syntax considerations to keep in mind when programming in Python.

Names and default arguments are designated between quotation marks (ex: "name").

The arguments used in CivilFEM commands should be in brackets and separated by

commas.

Python is a case sensitive language, recognizing capital and small letters as different

variables.

Page 7: CivilFEM Python Manual

7

Coordinates of the points are written in brackets and vectors in square brackets.

To create loops using for, if, while, lines of Python code that define the function

must be indented at least one space. To end the function definition, the code is

“unindented”.

Python have some reserved words: and, assert, break, class, continue,

def, del, elif, else, except, exec, finally, for, from,

global, if, import, in, is, lambda, not, or, pass, print,

raise, return, try, while, yield.

To avoid escape characters, such as /n that means newline o /s which means space, is

necessary to type "r" or “R” before the path, as follows:

execfile(r"C:\CivilFEM\Paths\new_example.py")

1.1.3. Expert utilities

As previously mentioned all Python functions are enabled in CivilFEM. Here are some examples:

When the range function is used, Python builds a list of integers starting at the first value

and ending at one less than the last value. For example:

for i in range(0,5):

print(i, "*", i,"=", i ** 2)

is actually executed as:

for i in [0,1,2,3,4]:

print(i, "*", i,"=", i ** 2)

That will return:

0 * 0 = 0

1 * 1 = 1

2 * 2 = 4

3 * 3 = 9

4 * 4 = 16

Is able to run scripts already created with the command execfile, only by giving the path of the file:

execfile(r"C:\CivilFem\script\example.py")

Page 8: CivilFEM Python Manual

8

1.2. Python with CivilFEM

All functions enabled by CivilFEM interface can be implemented through Python code, using the

script editor or the command line. All Python functions can be used in CivilFEM, including Python

libraries.

1.2.1. Basic Types

Point Is used to denote coordinates of points and units.

For example: Point(0,5,2,"m")

Vector Is used to denote coordinates of vectors.

For example: Vector(1,0,0)

Double Is a larger float type that holds both bigger and more precise numbers. Are

used to changed units.

For example: Double(15,"mm")

Formula Is used to write a formula un a point, vector o double. For example:

Formula("(8*9/6,0,0)")

WARNING! These basic types are considered reserved words, by using is made a redefine and

causes errors.

1.2.2. Script Editor and Command Line

CivilFEM has its own Script Editor to run Python code and create it without requiring external

editors. It is located in the main screen of CivilFEM, in “View” section, inside the “Windows”

menu. Furthermore, CivilFEM has a Command Line that allows running Python code and some

special commands for the script. This command line is located on the same place as the script

editor.

Image 1: location of the activation tabs of Command Line and Script Editor

Page 9: CivilFEM Python Manual

9

The Script Editor has its own menu, where the script can be saved; an existing script can be

opened, or the script can be run and stop.

Script Editor has several shortcuts, which are listed below.

F5 = run script

ctr+A = select all

ctr+S = save script

ctr+O = open script

ctr+N = new script

ctr+C = copy

ctr+V = paste

ctr+X = cut

ctr+Z = undo

sift+F10 = options

In addition to these shortcuts, the Script Editor also has autocomplete function. This is enabled by

pressing ctr+space when you start writing in the script editor.

Image 2: autocomplete function

Page 10: CivilFEM Python Manual

10

As a complement to autocompletion of the script editor, there is .help function, with which the

output attributes of each class are shown. For example, to show boundary conditions attributes,

execute BCGroupsContainer.Find("BC").BCs[0].help() in the script editor o in the

command line. In the Output window will be printed the attributes like this:

Image 3: BC attributes

The most characteristic feature in the command line is capability of executing only selected lines

of scripts. With the command run you can execute certain lines of code, only is need to type

run and the number of the lines in quotes. Something important to keep in mind is that you

should always write the starting line and the end one, so if for example, you want to run only line

5 would be type as follows:

> run "5" "5"

Image 4: Command Line and Script Editor Windows

Page 11: CivilFEM Python Manual

11

1.2.3. Macro Recording

CivilFEM has the option to record the processes, in Python language, involved to create the model

using the interface, this recording is done by macros.

The macro is located in the main screen of CivilFEM, in the “View” section inside “Macros”, there

you can start, stop and view it.

Image 5: Macros location

Keep in mind that the macro recording is performed in the document units and configuration.

1.2.4. Script Manual

All necessary information to make Python code in CivilFEM (enumerates, commands, containers

and other options) are covered in the Script Manual.

That Script Manual is divided in the same way that CivilFEM program, to ensure easier and faster

to find commands. It contains all commands and arguments to create the model, as well as all

enumerates for units, results and CivilFEM’s libraries.

The Script Manual is optimized for FireFox and Internet Explorer.

1.2.5. Python libraries

Python is characterized by the large number of libraries that can be used; CivilFEM has integrated

Python, so all the standards libraries are enabled in CivilFEM. Also can be installed other libraries

simply by copying them in the python “site-packages” folder. For example, below is used the

math library to create a point of coordinates (−𝑎 cos (𝜋

6) , 0,0).

#import library

import math as mt

#parameters

a = 0.5

createPoint("Point",[-a*mt.cos(mt.pi/6),0,0])

Page 12: CivilFEM Python Manual

12

All available Python libraries and its uses can be found at the following link. In addition CivilFEM

has the Numpy and MatPlotLib libraries already installed and ready to use.

All code is executed in CivilFEM under the "cf" module. This should be taken into account when

using user-defined functions. For example:

import numpy as np

import matplotlib.pyplot as plt

import matplotlib.animation as animation

fig = plt.figure()

ax = fig.add_subplot(111)

x = np.arange(0,2 * np.pi,0.01)

line1, = ax.plot(x,np.sin(x),'o')

def animate(i):

import cf

import numpy as np

cf.line1.set_ydata(np.sin(cf.x+i/10.0))

return cf.line1,

def init():

import cf

import numpy as np

cf.line1.set_ydata(np.ma.array(cf.x, mask=True))

return cf.line1,

ani =

animation.FuncAnimation(fig,animate,np.arange(1,200),init_func=init,inter

val=25,blit=True)

plt.show()

The variables “fig”, “ax”, “x”, “line1” and “ani”, as well as imports, are defined in the "cf" module.

To use these global variables inside a function definition you must include what you need to use.

1.2.6. Default conditions

CivilFEM works with default conditions, such as codes & standards, units or coordinates systems,

if you do not change them, Python code in CivilFEM will take them as in default. You can modify

the default properties using the Script Editor with the listed commands in the Script Manual.

Page 13: CivilFEM Python Manual

13

Image 6: CivilFEM Script Manual location

Default folder:

C:\Program Files\CivilFEM\2014 Beta Revision 1\manual\CivilFEM Script Manual.html

1.2.7. Enumerates and arguments

All enumerates and name arguments used in Python with CivilFEM are default, and must be

written as detailed in the Script Manual, because otherwise the program will not recognize them.

It should also be in mind that each command has the same model restrictions as the interface

model, being unable, for example, to execute 2-dimensions commands in three-dimensional

models, or transient commands in harmonic models.

1.2.8. Parameters

CivilFEM has its own parameters, which are also available through Python code. To create, modify

and delete a parameter, proceed as follows:

createParam("Param","VECTOR2D","Global Cartesian","[9, 0]","m")

modifyParam("Param", "Global Cartesian","[5, 1]", "mm")

deleteParam("P")

1.2.9. Containers

All entities’ properties are accessible through their containers. In CivilFEM there are the following

containers:

CoordSystemsContainer

GeometryContainer

MaterialsContainer

SectionsContainer

StructualElementsContainer

Page 14: CivilFEM Python Manual

14

ModelUtilsContainer

ContactsContainer

LoadGroupsContainer

BCGroupsContainer

LoadCasesContainer

To change a property of a specified entity you have to use the"Find" method and then access that

property. For example to change the mesh size of a structural element, it would be done as

follows:

#.Find("Name of the Structural Element")

s = StructuralElementsContainer.Find("Structural element")

s.MeshTool2D.ParameterMesh.SizeEdges = Double(0.12)

If you want to change one or more properties of multiple entities at the same time, you can

iterate the container. For example, if we have created several points and lines, and we want to

change the name of the points without changing lines, the code would be as follows:

i = 0

for geom in GeometryContainer:

if geom.GeomType == "VertexByCoord":

geom.GeomName="RenamePoint" + str(i+1)

i = i + 1

Pay special attention to the possibility of creating an infinite loop, do not use copy commands in

the iterator. If you have in the iterator a CivilFEM command, you can stop the execution with the

stop running script bottom.

Comparisons in the containers can be made by “==”. To change the name of several point with x

coordinate 2, proceed as follows:

i = 0

for g in GeometryContainer:

if (g.GeomType == "VertexByCoord") and (geom.Pnt.x() == 2):

g.GeomName="renamePoint" + str(i+1)

i = i+1

In comparisons of Point(),Double()and Vector(), must be set the units.

Page 15: CivilFEM Python Manual

15

Chapter 2

Basic Concepts

Page 16: CivilFEM Python Manual

16

2.1. Files

Python code in CivilFEM allows running several commands that affect documents, these are:

newDocument: create a new document from Dimension, Time and Discipline. For example to

create a 2D, Static, Structural model:

newDocument("Dim2D","Static","Structural")

openDocument: open an existing document from the path.

openDocument(".\example.cf")

closeDocument: close an existing document. No arguments.

closeDocument()

saveDocumentAs: save a new document.

saveDocumentAs(".\new example.cf")

If you already have an existing file named this way in the same directory, CivilFEM by default will

ask if you want to overwrite the file. If you want to overwrite it and avoid the stop of script

running, proceed as follows:

saveDocumentAs(".\new example.cf", True)

That will directly overwrite the file without asking.

saveDocument: save an existing document. No arguments.

saveDocument()

Page 17: CivilFEM Python Manual

17

2.2. Environment Commands

As already mentioned in section 1.2.1., CivilFEM has default properties, some of them in the

Environment of the model. These can be modified through both, the interface and the Python code.

Below you can see some examples of the changes therein:

Units System: CivilFEM has de International System ("IS") as default and it can be changed to

Imperial Units ("BFeet" or "BInch"), or a User ("User") one.

ConfigUnits.System = "BInch"

The User System allows modify one by one the different units listed through enumerates placed

in the Script Manual.

Coordinate System: in this case, the default coordinate system is Global Cartesian and changes

are linked to the dimensions of the model, i.e., 2D or 3D. You can also create several coordinate

systems and activate just the one you need in the moment you need it. For example here is the

code to create a Cartesian 3D coordinate system, and how to set it as active:

#Name,Origin,XVector,ZVector,Active

createCartesianCoordSys("C",(0,0,0),[1,0,0],[0,0,1],True)

If you have several coordinate systems create, you can activate it giving the name of the system

as follows:

activeCoordSystem("NameCoordSys")

Codes & Standards: CivilFEM has a catalogue of Codes & Standards for Reinforced Concrete and

Structural Steel. The default code in Reinforced Concrete is Eurocode 2 (EN 1992-1-1:2004/AC:

2008) and in Structural Steel is Eurocode 3 (EN 1993-1-1:2005). Each code has its own command,

to change it, set the command (changeConcreteCode, changeSteelCode) and the code

enumerate as argument (place in the Script Manual).

For example to change the Structural Steel code to the British Standard 8110:

changeSteelCode("BS8110")

Page 18: CivilFEM Python Manual

18

2.3. Geometry creation

2.3.1. Points and lines

Point and lines can be easily created in Python code. As each item, points need a command to be

created (createPoint), these are reflected in the Script Manual for each item.

Example: create a point at (0,0,0), named "Point".

createPoint("Point",[0,0,0])

Lines can be created by coordinates given or reference points already created:

createLine("Line1",[0,0,0],[5,0,0])

createLine("Line2","Point1","Point2")

You can also create groups of points or lines in a few lines of code using loops. This example

shows how to create 50 points and 49 lines in reference to these points:

Dim = 50

Point = []

Line = []

for i in range(Dim):

Point.append("Point" + str(i+1))

createPoint(Point[i],[i+10,0,i+15])

for j in range(Dim-1):

Line.append("Line" + str(j+1))

createLine(Line[j],Point[j],Point[j+1])

2.3.2. Surfaces and Volumes

Surfaces and volumes are geometric shapes easy to create using Python code. There are different

surfaces and different ways to create them as well as volumes, each one belongs to a command,

which is listed in the Script Manual. Examples below:

Page 19: CivilFEM Python Manual

19

To create a quadrilateral surface, is needed 4 points, giving its coordinates or reference points

already created ("P1","P2","P3","P4"):

createQuad("Quad",(0,0,0),(1,0,0),(1,1,0),(0,1,0))

createQuad("Quad","P1","P2","P3","P4")

CivilFEM has certain primitive volumes, such as cones, spheres and boxes. For example the cone

needs a central point of the cone base, axis, radius of the lower base, upper radius, height and

angle to truncate, shown as follows:

createCone("Cone",(0,0,0),[0,0,1],1,0,1,360)

You can also change arguments units on code with the basic type “Double”:

createCone("Cone",(0,0,0),[0,0,1],Double(1,"m"),0,Double(1,"m"),Double(360,"Deg"))

2.3.3. Import and Export geometry

CivilFEM gives the option of import or export geometry and that option is available in Python too.

There are three different options:

Import: let you import geometry from other model in igs, iges, stp, step, x_t or dxf

extensions, giving the path.

importGeom(".\folder\geometry.igs")

Export selected: Exports the selected geometry to an external file in igs, iges, stp, step, x_t or

dxf extensions, giving the entities and the path.

exportSelect([geom1,geom2,geom3],".\geometry.igs")

Export all: Exports all geometry to an external file in igs, iges, stp, step, x_t or dxf extensions,

giving the path.

exportAll(".\export_geometry.igs")

Page 20: CivilFEM Python Manual

20

2.4. Materials

CivilFEM has a materials library, which can be selected through the material. Materials properties

(listed in the Script Manual) can also be changed; these are organized through “containers”.

Steel: to create a steel material it is necessary de code and the name.

createSteelMat("Eurocode 3","Fe360")

To change structural steel properties, for example, name, Poisson ratio or thicknesses

proceed as follows:

MaterialsContainer.Find("Fe360").Name = "SteelMat"

MaterialsContainer.Find("SteelMat").Poisson = 0.5

MaterialsContainer.Find("SteelMat").Thicknesses[1] = Double(0.15,"m")

It can be also parameterized as below:

m = MaterialsContainer.Find("Fe360")

m.Name = "Mat.Example"

m.Poisson = 0.5

m.Thicknesses[1] = Double(0.15, "m")

Concrete: this material is divided in three different ways: concrete, reinforcement steel and

prestressing steel. To create a concrete material is necessary de code and the name.

createConcreteMat("Eurocode 2","C12/15")

createReinfMat("Eurocode 2","S400")

createPrestMat("Eurocode EN 10138","Y1570C")

Page 21: CivilFEM Python Manual

21

To change concrete properties, for example, Poisson ratio, cracking or damping coefficients

proceed as follows:

m = MaterialsContainer.Find("C12/15")

m.Poisson = 0.3

m.CrackingProperties.CrackingYN = True

m.DampingProperties.AutocalculateRayleigh = False

m.DampingProperties.AlphaRayleigh = Double(1,"Sec_Inv")

Rock: to create rock material is needed to set Rock Type, Rock Subtype, Rock Class and

Name, all possible arguments are listed in Script Manual.

createRockMat("Sedimentary","Siliceous","Aggregated","Flint")

To change rock properties, for example, Poisson ratio, cracking or damping coefficients

proceed as follows:

m = MaterialsContainer.Find("Flint")

m.ElastMod = Double(25000,"Pa")

m.Poisson = 0.2

Soil: CivilFEM provides a list of possible soil materials, all included in the Script Manual.

createSoilMat("Peat low plasticity")

To change soil properties, for example, Poisson ratio, cracking or damping coefficients

proceed as follows:

m = MaterialsContainer.Find("Peat low plasticity")

m.ElastMod = Double(200000,"Pa")

m.Poisson = 0.35

Page 22: CivilFEM Python Manual

22

Generic: if you prefer to create an own material, use the generic material, in this command is

needed the Elastic modulus, Poisson ratio, Density and the linear thermal expansion

coefficient.

# Name,ElastMod,Poisson,Density,ThExpans

createGenericMat("GenMat", 2500, 0.3, 1200, 0)

To change generic material properties, for example, Shear modulus or damping, proceed as

follows:

m = MaterialsContainer.Find("GenMat")

m.ShearModulus = Double(52000,"Pa")

m.DampingProperties.AutocalculateRayleigh = False

m.DampingProperties.AlphaRayleigh = Double(5,"Sec_Inv")

Page 23: CivilFEM Python Manual

23

2.5. Cross Sections

2.5.1. Create Sections

CivilFEM cross sections are created differently depending on the material of the transverse

section.

Concretre Sections: CivilFEM provides Rectangular, Circular, T, I, Box, Pipe and Capture

sections, each one have a command with different arguments, all included in the Script

Manual. For example in rectangular sections the arguments are name, material, Height and

Width:

createConcreteRectangularSection("RectSection","C12/15",1,0.5)

Cable Sections: for cable sections the arguments are name, material and outer diameter.

createCableSection("Cable", "Structural steel", Double(1,"m"))

Generic Sections: Besides the default sections CivilFEM has generic sections, whose

arguments are name, material, area, inertia about element Y axis, inertia about element Z

axis and torsion constant.

createGenericSection("Generic", "GenericMat", 2, 1300, 1300,4)

Steel from library: CivilFEM has an own library sections for steel; all items are included in

Script Manual. The arguments for this command are: material, shape, code or standard and

name.

createSteelLibrarySection("Steel","Channel","Europn UAP","UAP 80")

Steel by plates: this section is defined by adding plates, giving thickness and one point (X,Z).

For the first plate, two points are given in Python.

createSteelByPlatesSection("Steel generic", "structural steel")

sec = SectionsContainer.Find("Steel generic")

addPlate([sec],Double(0.5,"m"), (0,1),(0,5))

addPlate([sec],Double(0.5,"m"), (5,10))

Page 24: CivilFEM Python Manual

24

Steel by dimensions: There are some default sections for steel similar to concrete sections;

I, L, T, Channel, Pipe and Box, each one has an own command and different arguments. For

example, in I section the arguments are: Name, Material, Height, Width, Web thickness,

Flage thickness and Weld throat.

createSteelDimISection("Steel I","Steel",1, 1.5, 1, 0.5, 1)

2.5.2. Plot and Snapshot Sections

To make a snapshot of a section is necessary to plot first the section. So for example to make a

snapshot of an IPE 80 section, proceed as follows:

section = SectionsContainer.Find("IPE 80")

plotSection([section])

sectionSnapshot([section], r"section_Snapshot.bmp")

If a snapshot is already created with the same name, the program will ask you if you want to

overwrite the file, to avoid the pop-up is as easy as put a third boolean argument, if you want to

overwrite set True, and set False if you want to save the file with another name.

sectionSnapshot([section], r"section_Snapshot.bmp",True)

Image 7: Snapshot of a section

Page 25: CivilFEM Python Manual

25

2.6. Mesh

2.6.1. Structural Elements

In order to create structural elements required for the creation of some previous items; geometry

and section are required, for which previously is necessary to create a material. For example to

create a Beam the arguments needed are, Name of the Structural Element, Cross Section I, Cross

Section J and the Geometry:

createSEBeam("BEAM","IPE 80","IPE 80","Curve")

You can also modify the properties of the Structural Element once created, such as mesh

parameters.

s = StructuralElementsContainer.Find("BEAM")

s.MeshTool1D.OptionMeshType = "MaxLength"

st.MeshTool1D.ParameterMesh.Length = Double(0.5,"m")

To create a Shell the arguments needed are: Name of the Structural Element, Material, Thickness

and Geometry:

createSEShell("SHELL","C30/37",Double(0.05,"m"),"Surface")

Modifying the properties of the Structural Element:

SE= StructuralElementsContainer.Find("SHELL")

SE.MeshTool2D.ParameterMesh.EType = "QUAD"

SE.MeshTool2D.ParameterMesh.DivU = 12

Change the structural elements color:

changeEntityColor([SE],"#FFFFFF")

Structural Elements can be meshed one by one with the contextual command:

meshSESelected([SE1,SE2,…])

As well the mesh of each structural element can be cleared:

clearMeshSESelected([SE1,SE2,…])

Page 26: CivilFEM Python Manual

26

2.6.2. Model Utils & Contacts

Model Utils have 4 different properties: Mass, Insertion, Spring and PreMesh. To create them

proceed has follows:

# Name, structural Element, Point, Mass

createPointMass("Mass","StructElement",(0,0,0),1)

# Name, Structural Element 1, Structural Element 2

createInsertion("Insertion","ShellSE","BeamSE")

#Name, Structural Element,Spring stiffness,Degree Freedom X,Y,Z

createCurveSpring("Spring","ShellSE",1200,True,True,False)

# Name, Structural Element, Size

createPreMesh("Pre-mesh","BOX",0.1)

Contacts only need a name and the contacted and contacting Structural Element to be defined:

#Name, Contacted, Contacting

createContact("Contact pair","Beam SE","ShellSE")

2.6.3. Mesh & Mesh Tools

Through the code you can mesh all the structural elements in the model, remove the mesh,

change the elements type or do a merge of the nodes through these commands:

mesh()

clearMesh()

changeElementType("Quadratic")

#Tolerance of merge

mergeAllNodes(Double(0.5,"m"))

Page 27: CivilFEM Python Manual

27

CivilFEM also has commands to obtain information of the mesh once is done. These are:

getSEElements("SE") -> Elements list of structural element “SE”

getElementNodes(10) -> Nodes list of element 10

getNodeCoords(10) -> Coordinates (x,y,z) of node 10

getElementVolume(10) -> Volume of element 10 (hexaedrical and tetraedrical

elements). That command takes document units.

getElementArea(10) -> Area of element 10 (triangular and quadrangle

elements). That command takes document units.

Page 28: CivilFEM Python Manual

28

2.7. Loading

2.7.1. Loads

Python code in CivilFEM allows creating load groups and boundary conditions, as well as spectral

analysis and acceleration loads.

Load Groups: the first step is to create a Load Group, then you can add point loads, point

moments, linear loads, surface loads or temperature. For example to create a point load and

a point moment, proceed as follows:

LG = createLoadGroup("Load Group")

# Entity, Name, Structural element, Point, Direction, Load

addPointLoad([LG],"Punct","SE",(0,0,0),[1,0,0],Double(50,"Newton"))

# Entity, Name, Structural element, Point, Direction, Load

addPointMoment([LG],"Moment","SE",(0,0,0),[1,0,0],Double(50,"NxM"))

Harmonic loads can be also created with the same command, only by writing one more

argument:

createLoadGroup("loads","HarmonicLoads")

createLoadGroup("loads","PrestressingLoads")

Acceleration Load: To create an acceleration load is needed Name, Acceleration on X

direction, Acceleration on Y direction, Acceleration on Z direction.

createAccLoadGroup("Acceleration Load",5,0,0)

Spectral Analysis: spectral analysis can be created by two standards, Eurocode 8 EN 1998-

1:2004 and the NCSE 2002. Having each one its own command and arguments:

createSpectrumEC8("Name","Design2","A", 10, 1, 1, 0.2)

createSpectrumNCSE02("Name","Normal","Elastic", 10, 1, 1)

Page 29: CivilFEM Python Manual

29

Boundary Conditions Group: the first step is creating a Boundary Conditions Group, then you

can add point, linear, surface or displacement boundary conditions. For example to create a

linear boundary condition, proceed as follows:

BC = createBCGroup("Boundary conditions group")

#Entity, Name, Structural Element, Constrain X,Y,Z movement,

Constrain X,Y,Z Rotation

addCurveBC([BC],"BC Curve","SE",True,True,False,False,False,True)

2.7.2. Load Case

Loads and Boundary conditions have to be added to a Load Case once the Load Case is created as

follows:

LC = createLoadCase("Load case")

#Entity, Load Group, Factor

addLoadGroupToLoadCase([LC],"LG",1)

Page 30: CivilFEM Python Manual

30

2.8. Solve

2.8.1. Solver Configuration & Solver Output

Python code allowed changing the solver configuration by ConfigSolver command as shown

below:

ConfigSolver.LargeDeflections = True

ConfigSolver.ConvergenceDisp = True

ConfigSolver.FrictionForceTolerance = Double(0.02,"Newton")

Also can be changed the solver output with SolverOutput command:

SolverOutput.NodeResults.Results_CSTATUS = False

SolverOutput.NodeResults.Results_CSHEARF = False

2.8.2. Solve

As seen in mesh commands Python code can execute de solver and stop it:

solve()

stopSolve()

Page 31: CivilFEM Python Manual

31

2.9. CivilFEM results

Once the model is solved, it's time to plot the results. With Python code results can be displayed as

in the GUI, by listing, plotting, or obtain specific results of a particular node or element.

First step is to open the results file which we want to get the data from, giving the path or just the

name and file extension as it is stored in the same location where the model was saved.

2.9.1. General Results

After opening the result file to get general results, set the results to be shown. To do this is

necessary to set: the Result Type ("NodeResults", "ElementResults" or "EndResults"),

the Result Enumerate (the argument names are place in the Script Manual), and optionally the

Result Entity Type ("Nodal", "Truss", "Beam", "Shell", "Solid") and the Units (the

argument names are place in the Script Manual.

An example of results of the nodal displacement of the X component in a beam, shown in mm:

openResultsFile("ExampleResults.rcf")

setResult("NodeResults", "UTx", "Beam", "mm")

Once the results want to be shown are set, you can list and plot them as follows:

listResults()

plotResults()

You can also get specific data from a node or a particular element, stored in memory for a later

export or to be displayed in the Output Window by the Python command "print".

First get the data from the results file:

res = getResults("ExampleResults.rcf")

Nodal Results: Get the displacement of the X component in the node 3.

iNode = Double(0.0)

res.getNodeResult(iNode, "UTx", 3)

print(str(iNode.getValue()))

Page 32: CivilFEM Python Manual

32

Element Results: Get the X component of stress in the element 1, extreme 1 and first integer

point.

iElement = Double(0.0)

res.getElementResult(iElement, "Sx", 1, 1, 1)

print(str(iElement.getValue()))

End Results: Get the direct membrane force per width unit in local X-direction in the element

1 and extreme 1

iEnd = Double(0.0)

res.getEndResult(iEnd, "SF1", 1, 1)

print(str(iEnd.getValue()))

Checking results are given by end results, so if you want to get them only is needed to use

checking enumerate results in end results commands.

2.9.2. Envelope

To create an envelope of CivilFEM results it is not necessary to open a results file, it must be set

only if the expected results are maximum or minimum, the name of the envelope and its file path

and the results file paths as follows:

envelope("Max","Max","Max","Max","Max","Max","Max","Max","Envelope","enve

lope.rcf",["Load case.rcf","Load case2.rcf","Load case3.rcf"])

2.9.3. Checking and Design

CivilFEM features checks of concrete and steel beams and concrete plates are also accessible via

Python code through their own commands.

For example to check in axial bending a concrete beam, open results file and proceed has follows:

#Name, concrete stress, steel stress, dirkey

checkConcreteBeamAxialBending("Check", 0, 0,"XY")

To design in axial bending a concrete beam, open results file and proceed as follows:

Page 33: CivilFEM Python Manual

33

#Name,Concrete stress,Steel stress,Min amount,Max amount,Dirkey

designConcreteBeamAxialBending("Design",0,0,0.5,2,"XY")

2.9.4. Interaction Diagrams

To create an Interaction Diagram of beams or shells and save it, proceed as follows:

#BEAMS

#Element, End, concrete stress, steel stress, dirkey

beamInteractionDiagram(1,0,Double(0),Double(0),"XY","Spiral")

interactionDiagramSnapshot(r".\DiagramBeam.bmp")

#SHELLS

#Element, End, concrete stress, steel stress, dirkey

shellInteractionDiagram(1,1,Double(0),Double(0),"X")

interactionDiagramSnapshot(r".\DiagramShell.bmp")

Image 8: Snapshot of a concrete pipe interaction diagram

Page 34: CivilFEM Python Manual

34

2.10. View Options

2.10.1. Grid

One of the view options is the capability of activating a grid in the model, the default grid has its

centre of the origin and is 10x10m size. Python commands allow activating and removing the grid

and modify its configuration using the following commands:

#Activate the Grid

showGrid()

#Centre the view

lookAtGrid()

#Grid Configuration: GridType, Center, Normal, Rotation Spacing, Size

configGrid("Rectangular",(0,0,0),[0,0,1],Double(0,"Deg"),(1,1),(5,5))

2.10.2. Camera

With the camera is possible to make zoom, select different ways of viewing the model and even

to take a snapshot of the model using the following commands:

makeZoom: This command allow change zoom and fit the model to the view window by

using different arguments:

makeZoom("ZoomIn")

makeZoom("ZoomOut")

makeZoom("Fit")

changeView: This command makes possible to change the view of the model according to

their positive or negative ordinates x y z.

changeView("XNegative")

changeView("YPositive")

changeView("ZNegative")

Page 35: CivilFEM Python Manual

35

snapShot: Capture a snapshot of the graphical view and store it in a file giving the path

and the png, bmp, jpg or gif extension.

snapShot(r".\model image.jpg")

Image 9: Snapshot of a model in jpg extension

rotateCamera: With this command you can rotate your model in X, Y or Z direction in an

angle, only by giving the three coordinates. You can also set the unit type of the angles

("Deg" or "Rad") if you want, by default takes document units.

rotateCamera(Vector(0,3.1415,0,"Rad"))

rotateCamera((0,180,0))

Page 36: CivilFEM Python Manual

36

Chapter 3

Examples

Page 37: CivilFEM Python Manual

37

3.1. Example 1: Warehouse

3.1.1. Problem description

Perform a linear static analysis to obtain the results that self-weight and snow load cause on the

warehouse below.

Material: ASTM A529 Grade 42

The structure is composed of different profiles (which are described later) for

columns, belts, diagonals and beams. Plates will be modelled with shells.

Constant thickness of 0.5 inches for all steel plates.

Apply a wind load (global +X) to columns (1000 lbf/in) and snow load over steel

plates (0.1 psi).

Constrain all translations and rotations at base of columns.

Define two load cases to analyze the structure due to effect of gravity, snow load and

wind load according to following combinations: 1.20 x Self Weight + 1.20 x Snow Load

1.35 x Self Weight + 0.55 x Wind Load

Page 38: CivilFEM Python Manual

38

Table summary of X, Y, Z point coordinates:

Note that a new coordinate system CS1 is created. Coordinates of points P01 to P22 are oriented

according to global Cartesian System. Coordinates of points P23 to P27 are oriented according to

CS1.

Page 39: CivilFEM Python Manual

39

Suggested Steps:

1. Create a new model.

2. Set units.

3. Create the geometry points.

4. Create the geometry lines.

5. Create the geometry surfaces.

6. Create the material.

7. Cross sections

8. Create the structural elements.

9. Create the mesh.

10. Apply loads.

11. Create the boundary conditions.

12. Create all load cases.

13. Analyze the model.

14. Post process results

Page 40: CivilFEM Python Manual

40

3.1.1. Python Code

# New 3D Structural Anslysis

newDocument("Dim3D","Static","Structural")

# Save model

saveDocumentAs(r"C:\CivilFEM\EM_EX06.cf")

# Set units System

ConfigUnits.System = "BInch"

#Def. Points

pnt("P1",[0,0,120])

pnt("P2",[120,0,120])

pnt("P3",[120,240,120])

pnt("P4",[0,240,120])

pnt("P5",[240,0,120])

pnt("P6",[240,240,120])

pnt("P7",[360,0,120])

pnt("P8",[360,240,120])

pnt("P9",[480,120,120])

pnt("P10",[480,240,120])

pnt("P11",[120,480,120])

pnt("P12",[0,480,120])

pnt("P13",[240,480,120])

pnt("P14",[360,480,120])

pnt("P15",[480,480,120])

pnt("P16",[0,240,0])

pnt("P17",[0,480,0])

pnt("P18",[360,0,0])

pnt("P19",[480,120,0])

pnt("P20",[480,240,0])

pnt("P21",[480,480,0])

pnt("P22",[0,0,0])

#Coord. change

createCartesianCoordSys("Cartesian",[360,0,120],[480,480,0],[0,0,1],True)

pnt("P23",[170,-120,0])

pnt("P24",[0,-120,0])

pnt("P25",[170,-120,-120])

pnt("P26",[0,-120,-120])

pnt("P27",[85,-60,45])

# Def. Columns

COL = []

for i in range(9):

COL.append("COLUMN" + str(i+1))

line(COL[0],"P1","P22")

Page 41: CivilFEM Python Manual

41

line(COL[1],"P4","P16")

line(COL[2],"P12","P17")

line(COL[3],"P7","P18")

line(COL[4],"P24","P26")

line(COL[5],"P23","P25")

line(COL[6],"P19","P9")

line(COL[7],"P10","P20")

line(COL[8],"P15","P21")

# Def. Beams

BM = []

for i in range(14):

BM.append("BEAM" + str(i+1))

b1 = line(BM[0],"P1","P4")

b2 = line(BM[1],"P4","P12")

b11 = line(BM[2],"P2","P3")

b12 = line(BM[3],"P3","P11")

b21 = line(BM[4],"P5","P6")

b22 = line(BM[5],"P6","P13")

b31 = line(BM[6],"P7","P8")

b32 = line(BM[7],"P8","P14")

b41 = line(BM[8],"P9","P10")

b42 = line(BM[9],"P10","P15")

b51 = line(BM[10],"P7","P24")

b52 = line(BM[11],"P24","P23")

b53 = line(BM[12],"P23","P9")

b54 = line(BM[13],"P9","P7")

# Def. Belts

BT = []

for i in range(11):

BT.append("BELT" + str(i+1))

bt1 = line(BT[0],"P1","P2")

bt2 = line(BT[1],"P2","P5")

bt3 = line(BT[2],"P5","P7")

bt11 = line(BT[3],"P4","P3")

bt12 = line(BT[4],"P3","P6")

bt13 = line(BT[5],"P6","P8")

bt14 = line(BT[6],"P8","P10")

bt21 = line(BT[7],"P12","P11")

bt22 = line(BT[8],"P11","P13")

bt23 = line(BT[9],"P13","P14")

bt24 = line(BT[10],"P14","P15")

# Def. Diag.

DIAG = []

for i in range(4):

DIAG.append("DIAG" + str(i+1))

d1 = line(DIAG[0],"P7","P27")

Page 42: CivilFEM Python Manual

42

d2 = line(DIAG[1],"P24","P27")

d3 = line(DIAG[2],"P23","P27")

d4 = line(DIAG[3],"P9","P27")

# Def. Polyline surface

PT = []

for i in range(12):

PT.append("PLATE" + str(i+1))

fillFace(PT[0],[bt1,b1,bt11,b11])

fillFace(PT[1],[bt2,b21,bt12,b11])

fillFace(PT[2],[bt3,b21,bt13,b31])

fillFace(PT[3],[b54,b41,bt14,b31])

fillFace(PT[4],[bt21,b2,bt11,b12])

fillFace(PT[5],[bt22,b22,bt12,b12])

fillFace(PT[6],[bt23,b22,bt13,b32])

fillFace(PT[7],[bt24,b42,bt14,b32])

fillFace(PT[8],[d1,b54,d4])

fillFace(PT[9],[d3,b53,d4])

fillFace(PT[10],[d3,b52,d2])

fillFace(PT[11],[d1,b51,d2])

# Def. Structure

createSteelMat("ASTM","A529 grade 42")

Ht1=12.12

Wth1=12.0

WT1=0.39

FT1=0.605

WdT1=1e-05

createSteelDimISection("Steel I COL","A529 grade 42",Ht1,Wth1,WT1,FT1,WdT1)

Ht2=16.97

Wth2=10.425

WT2=0.585

FT2=0.985

WdT2=1e-05

createSteelDimISection("Steel I BELT","A529 grade 42",Ht2,Wth2,WT2,FT2,WdT2)

Ht3=8.06

Wth3=6.535

WT3=0.285

FT3=0.465

WdT3=1e-05

createSteelDimISection("Steel I BEAM","A529 grade 42",Ht3,Wth3,WT3,FT3,WdT3)

HtB=6.0

WthB=6.0

WTB=0.25

FTB=0.25

WdTB=0.25

createSteelDimBoxSection("Steel Box Diagonal","A529 grade 42",HtB,

WthB,WTB,FTB,WdTB)

Page 43: CivilFEM Python Manual

43

#Structural Elements

for i in range(12):

createSEShell(PT[i],"A529 grade 42",Double(0.5, "Inch"),PT[i])

SE1 = StructuralElementsContainer.Find(PT[i]).MeshTool2D.ParameterMesh

SE1.EType = "QUAD"

SE1.SizeEdges = Double(35,"Inch")

SE1.Tol = Double(0.01,"Inch")

for i in range(9):

createSEBeam(COL[i],"Steel I COL","Steel I COL",COL[i])

StructuralElementsContainer.Find(COL[i]).MeshTool1D.ParameterMesh.NumberOfSegments= 3

for i in range(14):

createSEBeam(BM[i],"Steel I BEAM","Steel I BEAM",BM[i])

SE3 = StructuralElementsContainer.Find(BM[i]).MeshTool1D

SE3.OptionMeshType = "MaxLength"

SE3.ParameterMesh.Length = Double(35, "Inch")

for i in range(11):

createSEBeam(BT[i],"Steel I BELT","Steel I BELT",BT[i])

SE4 = StructuralElementsContainer.Find(BT[i]).MeshTool1D

SE4.OptionMeshType = "MaxLength"

SE4.ParameterMesh.Length = Double(35, "Inch")

for i in range(4):

createSEBeam(DIAG[i],"Steel Box Diagonal","Steel Box Diagonal",DIAG[i])

SE5 = StructuralElementsContainer.Find(DIAG[i]).MeshTool1D

SE5.OptionMeshType = "MaxLength"

SE5.ParameterMesh.Length = Double(35, "Inch")

# Mesh

mesh()

# Load Groups

lg1 = createLoadGroup("Snow Load")

Load_on = []

for i in range(12):

Load_on.append("Load_on" + str(i+1))

for i in range(12):

addSurfaceLoad([lg1],Load_on[i],PT[i],[0,0,-1],Double(0.1, "Psi"))

lg2 = createLoadGroup("Wind load+X")

addCurveLoad([lg2],"Load 1","COLUMN1",[1,0,0],Double(1000, "Pli"))

addCurveLoad([lg2],"Load 2","COLUMN2",[1,0,0],Double(1000, "Pli"))

addCurveLoad([lg2],"Load 3","COLUMN3",[1,0,0],Double(1000, "Pli"))

Page 44: CivilFEM Python Manual

44

# Boundary Conditions

bc = createBCGroup("Fixed")

BC = ["BC 1","BC 2","BC 3","BC 4","BC 5","BC 6","BC 7","BC 8","BC 9"]

for i in range(9):

addPointBC([bc],BC[i],COL[i],[0,0,0],True,True,True,True,True,True)

# Load Cases

lc1 = createLoadCase("Comb1")

addLoadGroupToLoadCase([lc1],lg1,1.2)

addLoadGroupToLoadCase([lc1],"Gravity",1.2)

addBCGroupToLoadCase([lc1],bc)

lc2 = createLoadCase("Comb2")

addLoadGroupToLoadCase([lc2],lg2,0.55)

addLoadGroupToLoadCase([lc2],"Gravity",1.35)

addBCGroupToLoadCase([lc2],bc)

# Solve

solve()

openResultsFile("Comb1.rcf")

makeZoom("Fit")

# x-component of stress

setResult("ElementResults","Sx")

setResultsViewStyle("Deformed")

plotResults()

Page 45: CivilFEM Python Manual

45

# Z-component of displacement

setResult("NodeResults","UTz")

plotResults()

for i in range (12):

SE = StructuralElementsContainer.Find(PT[i])

changeViewStyle([SE],"Hide")

Page 46: CivilFEM Python Manual

46

# Bending moment about the local Z-axis

setResult("EndResults","SM2","Beam","Klxi")

setResultsViewStyle("Deformed")

setResultsViewStyle("Line")

plotResults()

Page 47: CivilFEM Python Manual

47

#Axial Force

setResult("EndResults","SF1","Beam","Kip")

plotResults()