Programming a truss finite element solver in C

Similar documents
CHAPTER 3. INTRODUCTION TO MATRIX METHODS FOR STRUCTURAL ANALYSIS

The Matrix Stiffness Method for 2D Trusses

The elements used in commercial codes can be classified in two basic categories:

Nonlinear analysis and form-finding in GSA Training Course

( ) which must be a vector

Question 2: How do you solve a matrix equation using the matrix inverse?

The Basics of FEA Procedure

Advanced Structural Analysis. Prof. Devdas Menon. Department of Civil Engineering. Indian Institute of Technology, Madras. Module

LINEAR ALGEBRA W W L CHEN

18.06 Problem Set 4 Solution Due Wednesday, 11 March 2009 at 4 pm in Total: 175 points.

Structural Analysis - II Prof. P. Banerjee Department of Civil Engineering Indian Institute of Technology, Bombay. Lecture - 02

Stress Recovery 28 1

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial VI

is in plane V. However, it may be more convenient to introduce a plane coordinate system in V.

Tutorial for Assignment #2 Gantry Crane Analysis By ANSYS (Mechanical APDL) V.13.0

Finite Elements for 2 D Problems

Mathematics Course 111: Algebra I Part IV: Vector Spaces

Recall the basic property of the transpose (for any A): v A t Aw = v w, v, w R n.

bi directional loading). Prototype ten story

Structural Axial, Shear and Bending Moments

6. Cholesky factorization

Eigenvalues and Eigenvectors

Finite Element Method (ENGC 6321) Syllabus. Second Semester

Lecture L3 - Vectors, Matrices and Coordinate Transformations

3D Tranformations. CS 4620 Lecture 6. Cornell CS4620 Fall 2013 Lecture Steve Marschner (with previous instructors James/Bala)

Math 215 HW #6 Solutions

3 Concepts of Stress Analysis

EFFECTS ON NUMBER OF CABLES FOR MODAL ANALYSIS OF CABLE-STAYED BRIDGES

MAT188H1S Lec0101 Burbulla

Operation Count; Numerical Linear Algebra

Solution of Linear Systems

α = u v. In other words, Orthogonal Projection

FUNDAMENTAL FINITE ELEMENT ANALYSIS AND APPLICATIONS

Tower Cross Arm Numerical Analysis

CIVL 7/8117 Chapter 3a - Development of Truss Equations 1/80

Linearly Independent Sets and Linearly Dependent Sets

Beginner s Matlab Tutorial

ACMSM - Computer Applications in Solids Mechanics

Finite Element Formulation for Beams - Handout 2 -

CS3220 Lecture Notes: QR factorization and orthogonal transformations

x = + x 2 + x

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

Elasticity Theory Basics

MAT 200, Midterm Exam Solution. a. (5 points) Compute the determinant of the matrix A =

2.1 Introduction. 2.2 Terms and definitions

3. INNER PRODUCT SPACES

DATA ANALYSIS II. Matrix Algorithms

x1 x 2 x 3 y 1 y 2 y 3 x 1 y 2 x 2 y 1 0.

Factorization Theorems

The Singular Value Decomposition in Symmetric (Löwdin) Orthogonalization and Data Compression

CHAP 4 FINITE ELEMENT ANALYSIS OF BEAMS AND FRAMES INTRODUCTION

Problem Set 5 Due: In class Thursday, Oct. 18 Late papers will be accepted until 1:00 PM Friday.

Finite Mathematics Using Microsoft Excel

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

Mechanics lecture 7 Moment of a force, torque, equilibrium of a body

Lecture 2 Matrix Operations

Linear algebra and the geometry of quadratic equations. Similarity transformations and orthogonal matrices

SOLVING LINEAR SYSTEMS

How To Understand The Dynamics Of A Multibody System

Orthogonal Projections and Orthonormal Bases

Methods for Finding Bases

2+2 Just type and press enter and the answer comes up ans = 4

Review Jeopardy. Blue vs. Orange. Review Jeopardy

THREE DIMENSIONAL GEOMETRY

Similarity and Diagonalization. Similar Matrices

A vector is a directed line segment used to represent a vector quantity.

Linear Algebra Review. Vectors

Modeling of inflatable dams partially filled with fluid and gas considering large deformations and stability

Linear Algebra: Vectors

3 Orthogonal Vectors and Matrices

Simulation of Trajectories and Comparison of Joint Variables for Robotic Manipulator Using Multibody Dynamics (MBD)

1 VECTOR SPACES AND SUBSPACES

Bedford, Fowler: Statics. Chapter 4: System of Forces and Moments, Examples via TK Solver

Chapter 6. Orthogonality

Lecture 5: Singular Value Decomposition SVD (1)

Orthogonal Projections

SSLV105 - Stiffening centrifuges of a beam in rotation

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

DERIVATIVES AS MATRICES; CHAIN RULE

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

Animation (-4, -2, 0 ) + (( 2, 6, -4 ) - (-4, -2, 0 ))*.75 = (-4, -2, 0 ) + ( 6, 8, -4)*.75 = (.5, 4, -3 ).

Inner Product Spaces and Orthogonality

Linear Algebra Notes

7. LU factorization. factor-solve method. LU factorization. solving Ax = b with A nonsingular. the inverse of a nonsingular matrix

ME 115(b): Solution to Homework #1

System of First Order Differential Equations

MATLAB and Big Data: Illustrative Example

ANALYSIS OF STRUCTURAL MEMBER SYSTEMS JEROME J. CONNOR NEW YORK : ':,:':,;:::::,,:

Code_Aster. A finite element of cable-pulley

Solving Linear Programs in Excel

Math 312 Homework 1 Solutions

Rotation Matrices and Homogeneous Transformations

Unified Lecture # 4 Vectors

MATH 304 Linear Algebra Lecture 18: Rank and nullity of a matrix.

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

Mesh Discretization Error and Criteria for Accuracy of Finite Element Solutions

WEEK #3, Lecture 1: Sparse Systems, MATLAB Graphics

Recall that two vectors in are perpendicular or orthogonal provided that their dot

5. Orthogonal matrices

Transcription:

CHAPTER 4 Programming a truss finite element solver in C In this section, some C functions are developed that allow to compute displacements and internal efforts of a two-dimensional truss structure. 4.1 Linear system solver As it was explained in Chapter 3, computing the equilibrium of a truss structure requires to solve a linear system of equations (see (3.14)). Here, we asssume the existence of a linear solver Application Program Interface (API). In such an API, the following functions should be availabe: matrix_t * create_matrix (int n, int m); This function allows to create a n m matrix. Sparse matrices are preferred in finite elements because of the low bandwidth of finite element stifness matrices. Matrix that is returned is initialized with zeros. void delete_matrix (matrix_t *K); This one removes the memory allocated by create_matrix. void add_to_matrix (matrix_t *K, int n, int m, double val); This one allows to add value val to row n and column m of matrix K. void solve_linear_system (matrix_t *K, double *f, double *x); This one solves the linear system [K](x) = (F). 4. Input and output A finite element solver of a truss takes as input the following datas: An array double *xy of size N that contains the coordinates of the N nodes (or joints) of the truss. We assume that coordinates x j 1 and x j of node j are xy[*j] and xy[*j+1], j = 0,..., N 1. 35

36 CHAPTER 4. PROGRAMMING A TRUSS FINITE ELEMENT SOLVER IN C An array int *ind of size B that contains the topology of the truss i.e. the index of starting and ending nodes of each of the B rods (or bars) of the truss. We assume that bar j s starting node b j 1 is ind[*j] and that bar j s ending node b j is ind[*j+1], j = 0,...,B 1. An array double *f of size N that contains the nodal forces applied to each of the nodes of the truss. The two components f j 1 and f j of the force that acts on node j are respectively f[*j] and f[*j+1]. The way fixations (or supports) are defined is a little more tricky. Here, we propose not to be 100% general. We could indeed ask the user to provide matrix [c] and vector (ū) of (3.1) but this is not very intuitive. The truss solver should build [c] and (ū) by itself using straightforward informations. We propose to use arrays. Assume that M constraints have to be applied to the truss and that each of the constraints is applied to one node of the truss (this is the non general part). The first array int *nc of size M contains all nodes that are associated with constraints. The second array double *vc of size 3M assigns one vector per constrained node. Vector with components vc[3*j] and vc[3*j+1] is the direction of the prescribed displacement at that node nc[j] and vc[3*j+] is the value of that displacement. An array double *ea of size B that contains products E j A j for each bar. The output (the results) of the solver are the displacements at all nodes as well as reaction forces corresponding to the constraints: An array double *x of size N that contains the nodal displacements of each node of the truss. Displacement u j 1 and u j are respectively x[*j] and x[*j+1]. An array double *r of size M that contains normal reaction forces. 4.3 Stiffness matrix The function that computes the stiffness matrix of a bar is given in 4.1. This code is a simple translation of formula (3.15). 4.4 The solver The function computes the equilibrium of a truss is given in Listings 4.. The stiffness matrix of the truss is assembled between lines 8 and 16. The force vector is set on line 17. The constraints are set between lines 18 and 7. Note that we consider that the third component v[] is the absolute value of the displacement that is prescribed along direction v[0], v[1]. We then put a unit vector in the matrix (lines to 5). If the system cannot be inverted (zero determinant), it actually means that the truss is unstable (hypostatic). This can be due to external hypostaticity (not enough constraints) or internal hypostaticity (frame modes).

4.5. POST PROCESSING 37 1 void stiffnessmatrix (double x1, double y1, double x, double y, double ea, double k[4][4]) 3 { 4 double t = atan(y y1, x x1) ; 5 double c = cos(t) ; 6 double s = sin(t) ; 7 double l = sqrt ((x x1) * (x x1) +(y y1) * (y y1) ) ; 8 double f = ea/l ; 9 k[0][0] = k[][] = c*c* f; 10 k[1][1] = k[3][3] = s* s * f; 11 k[0][] = k[][0] = c*c* f; 1 k[3][1] = k[1][3] = s * s * f; 13 k[0][1] = k[1][0] = k[3][] = k[][3] = s*c* f; 14 k[3][0] = k[0][3] = k[][1] = k[1][] = s *c* f; 15 } Listing 4.1: Computation of the stiffness matrix of a bar Let us now try our truss solver on the same simple truss as the one of 3.5. The code given in 4.3 shows how to define input data for this simple truss. Note that this way of defining data is clearly not the one that should be use to solve large trusses. Computer Aided Design systems like AutoCAD, ArchiCAD, ProEngineer, CATIA or SolidWorks allow to define complex structures in a WYSIWYG fashion. We should in principle be able to connect such a system and get relevant informations that can be automatically translated into our input format. The computed displacement at node is u1 = 4.7619e 05 which is in accordance to what we found in 3.5 i.e. FL EA = 1000 1 10 10 5 = 4.7619 10 5. Similarly, u = 0.00018306 which is also correct. The value of the 4 lagrangle multipliers is ( ) = { 1000,0,1000, 1000} which is obviously the right value of reactions forces at nodes 0 and 1. 4.5 Post processing It is indeed possible to compute normal efforts n j, j = 0,..., N 1 in each bar of the truss in a post processing stage. For that, let us give the following interresting interpretation of the local stiffness matrix [k j ] of bar j. Let us isolate bar j and let s apply to bar j the displacements (u j ) = {u bi 1 1,ubi 1,ubi 1,ubi }.

38 CHAPTER 4. PROGRAMMING A TRUSS FINITE ELEMENT SOLVER IN C 1 int trusssolver (int N, int B, int M, double *xy, int *ind, double * f, int *nc, double *vc, double *ea, 3 double *x, double * r) { 4 double stiff [4][4]; 5 matrix_t *K = create_matrix (*N+M, *N+M) ; 6 double *F = (double * ) malloc ((*N+M) * sizeof( double)); 7 double *X = (double * ) malloc ((*N+M) * sizeof( double)); 8 for ( int i=0;i<b;i++){ 9 int n1 = ind [* i]; 10 int n = ind [ * i +1]; 11 int indx [4] = {*n1, * n1+1,*n, * n+1}; 1 stiffnessmatrix ( xy[indx[0]], xy[indx[1]], 13 xy[ indx []], xy[ indx [3]], ea[ i ], s t i f f ) ; 14 for ( int j=0;j<4;j++) for ( int k=0;k<4;k++) 15 add_to_matrix(k, indx[ j ], indx[k], s t i f f [ j ][ k]) ; 16 } 17 for ( int i=0;i<*n; i ++) F[ i ] = f [ i ] ; 18 for ( int i=0;i<m;i++) { 19 int indx [] = {*nc[ i ], *nc[ i ] +1}; 0 double v[3] = {vc[3* i], vc[3* i+1], vc[3* i+]}; 1 double norm = s q r t ( v [ 0 ] * v[0] + v[1]* v[1]); add_to_matrix(k,*n+ i, indx [ 0 ], v [ 0 ] / norm) ; 3 add_to_matrix(k,*n+ i, indx [ 1 ], v [ 1 ] / norm) ; 4 add_to_matrix(k, indx [0],*N+ i, v [ 0 ] / norm) ; 5 add_to_matrix(k, indx [1],*N+ i, v [ 1 ] / norm) ; 6 F[*N+ i ] = v [ ] ; 7 } 8 bool result = solve_linear_system (K, F, X) ; 9 if (result == false)printf("error : the truss is not stable\n") ; 30 for ( int i=0;i<*n; i ++) x[ i ] = X[ i ] ; 31 for ( int i=0;i<m;i++) r[i] = X[*N+ i ] ; 3 delete_matrix(k) ; 33 free(f) ; 34 free(x) ; 35 return result ; 36 } Listing 4.: A truss solver

4.5. POST PROCESSING 39 1 int main( void) { const double L = 1.0; 3 const double F = 1000; 4 const double A = 1e 4; 5 const double E = 10e9; 6 const int N= 3; 7 double xy[*n] = {0,0,0,L, L, 0 } ; 8 const int B = ; 9 int ind[*b] = {1,,0,}; 10 double ea[b] = {E*A,E*A}; 11 double f [*N] = {0,0,0,0,0, F}; 1 const int M= 4; 13 int nc[m] = {0,0,1,1}; 14 double vc[3*m] = { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0 } ; 15 double x[*n]; 16 double r[m]; 17 int result = trusssolver (N,B,M, xy,ind,f,nc,vc,ea,x,r) ; 18 return result ; 19 } Listing 4.3: Example of use of the truss solver that were computed by the truss solver. The product [f j ] = [k j ](u j ) allows to compute two force vectors (f j ) = {f bi 1 1, f bi 1, f bi 1 {z }, f bi } {z } f bi 1 f bi at both ends b i 1 and bi of the bar. Matrix [kj ] of (3.15) is of rank : its rows 1 and 3 are the opposite of each other. This is also true for rows and 4. This means actually that f bi 1 1 = f bi 1 and f bi 1 = f bi. Then, we have fbi 1 = f bi. This makes sense: the bar is in equilibrium. Then it is easy to see that f bi 1 is aligned with the axis of the bar. Consider a vector n = {sinµ, cosµ} that is orthogonal to bar j. It is easy to see that f bi 1 n = 0. This result again makes a lot of sense: the bar can only handle axial forces along X 1. The normal effort at both ends can then be computed as n j = f bi 1 t = 0 with t = {cosµ,sinµ}. We choose to use f bi 1 in order that a positive n j correspond to a bar in traction. The code given in 4.4 allows to compute normal efforts in every bar of the truss. In our simple example, we find which is obviously the right answer. (n) = {1414.1, 1000}

40 CHAPTER 4. PROGRAMMING A TRUSS FINITE ELEMENT SOLVER IN C 1 void postpro ( int B, double *xy, int *ind, double *ea, double *x, double *n) { 3 double stiff [4][4]; 4 for ( int i=0;i<b;i++){ 5 int n1 = ind [* i]; 6 int n = ind [* i+1]; 7 int indx [4] = {*n1, * n1+1,*n, * n+1}; 8 stiffnessmatrix ( xy[indx[0]], xy[indx[1]], 9 xy[ indx []], xy[ indx [3]], ea[ i ], s t i f f ) ; 10 double f [4] = {0,0,0,0}; 11 for ( int j=0;j<4;j++) { 1 for ( int k=0;k<4;k++) { 13 f[j] += stiff[j][k] * x[indx[k]]; 14 } 15 } 16 double t = atan( xy[indx[1]] xy[ indx [3]], xy[ indx[0]] xy[ indx []]) ; 17 n[ i ] = f [0] * cos( t ) + f [1] * sin( t ) ; 18 } 19 } Listing 4.4: Computing normal efforts in all bars 4.6 Example Figure 4.1: A Howe truss. The deformation of the truss is enhanced 100 times. The color correspond to traction (red) and compression (blue) We consider here a truss with a well known topology that is called a Howe truss (see Figure 4.1. The Howe Truss was designed by William Howe in 1840. It used mostly wood in construction and was suitable for longer spans than the Pratt truss.

4.6. EXAMPLE 41 Therefore, it became very popular and was considered one of the best designs for railroad bridges back in the day.