Analyse a beam

Pages: 123
"Modernised"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

class Beam
{
public:
   double L, EI;
   double V0, dV0;
   Beam( double L_ = 1.0, double EI_ = 1.0 ) : L( L_ ), EI( EI_ ) {}
};

class PointLoad
{
public:
   double x, W;
   PointLoad( double x_ = 0.0, double W_ = 0.0 ) : x( x_ ), W( W_ ) {}
};

class ContinuousLoad
{
public:
   double xl, xr, wl, wr;
   double dx, dwdx;  
   ContinuousLoad( double XL = 0.0, double XR = 1.0, double WL = 0.0, double WR = 0.0 ) : xl( XL ), xr( XR ), wl( WL ), wr( WR )
   { 
      dx = xr - xl;
      dwdx = ( wr - wl ) / dx;
   }
};

class Reaction
{
public:
   double x;
   char type;   // 'F' (force) or 'M' (moment)
   double v;    // deflection or gradient
   double R;
   Reaction( double x_ = 0.0, char t_ = 'F', double v_ = 0.0 ) : x( x_ ), type( t_ ), v( v_ ) {}
};

class Monitor
{
public:
   double x;
   double v, dvdx, S, M;
   Monitor( double X = 0.0 ) : x( X ) {}
};

//

Beam beam;
vector<PointLoad> load;
vector<ContinuousLoad> cont;
vector<Reaction> react;
vector<Monitor> mon;

void problem();
void initialise();
void calculateReactions();
void solve( vector< vector<double> > &a, vector<double> &b, vector<double> &x, int size );
void output();
double deflection( double x );
double gradient( double x );
double bendingMoment( double x );
double shearForce( double x );
double Vnr( double x );
double dVnr( double x );
double Mnr( double x );
double Snr( double x );
double loadInt( double x, int p );
double reactInt( double x, int p );
double Mac( double xx, int n );

//

int main()
{
   initialise();
   problem();
   calculateReactions();
   output();
}

//

void problem()
{
   // Beam
   double L = 2.0e4, E = 2.5e4, I = 7.2e9;
   beam = { L, E * I };

   // Loads
   load.push_back( { L / 2 , 3.0e4    } ); // pt load
// cont.push_back( { 0.0, L, 2.5, 2.5 } ); // UDL

   // Reactions (simply supported: 'F'; built-in: 'F' and 'M')
   react.push_back( { 0.0, 'F', 0.0 } );
   react.push_back( { L  , 'F', 0.0 } );

   double x1 = 0.0, x2 = L;
   int nx = 20;
   double dx = ( x2 - x1 ) / nx;
   for ( int i = 0; i <= nx; i++ ) mon.push_back( Monitor( x1 + i * dx ) );
}

//

void initialise()
{
   beam = Beam( 1.0, 1.0 );
   load.clear();
   cont.clear();
   react.clear();
   mon.clear();
}

//

void calculateReactions()
// Solves the force/moment/constraint equations for vector ( V0, dV0, R[0], ...., R[nR-1] )
{
   int i, j, m, n;
   double vm, xm, xn;
   char tm, tn;
   int nR = react.size();
   int size = nR + 2;
   vector< vector<double> > A( size, vector<double>( size, 0.0 ) );
   vector<double> b( size, 0.0 );
   vector<double> x( size, 0.0 );

   // Force ( S(L+) =  0 )
   i = 0;
   for ( n = 0; n < nR; n++ )
   {
      j = n + 2;
      tn = react[n].type;
      if ( tn == 'F' ) A[i][j] = 1.0;
   }
   b[i] = Snr( beam.L );

   // Moment ( M(L+) = 0 )
   i = 1;
   for ( n = 0; n < nR; n++ )
   {
      j = n + 2;
      xn = react[n].x;
      tn = react[n].type;
      if ( tn == 'M' ) A[i][j] = 1.0;
      if ( tn == 'F' ) A[i][j] = -( beam.L - xn );
   }
   b[i] = Mnr( beam.L );

   // Constraints
   for ( m = 0; m < nR; m++ )
   {
      i = m + 2;
      xm = react[m].x;
      tm = react[m].type;
      vm = react[m].v;
      if ( tm == 'F' )
      {
         A[i][0] = 1.0;
         A[i][1] = xm;
         for ( n = 0; n < nR; n++ ) 
         {
            j = n + 2;
            xn = react[n].x;
            tn = react[n].type;
            if ( tn == 'M' ) A[i][j] =  Mac( xm - xn, 2 );
            if ( tn == 'F' ) A[i][j] = -Mac( xm - xn, 3 );
         }
         b[i] = beam.EI * vm - Vnr( xm );
      }
      if ( tm == 'M' )
      {
         A[i][0] = 0.0;
         A[i][1] = 1.0;
         for ( n = 0; n < nR; n++ ) 
         {
            j = n + 2;
            xn = react[n].x;
            tn = react[n].type;
            if ( tn == 'M' ) A[i][j] =  Mac( xm - xn, 1 );
            if ( tn == 'F' ) A[i][j] = -Mac( xm - xn, 2 );
         }
         b[i] = beam.EI * vm - dVnr( xm );
      }
   }

   solve( A, b, x, size );

   beam.V0  = x[0];
   beam.dV0 = x[1];
   for ( n = 0; n < nR; n++ ) 
   {
      i = n + 2;
      react[n].R = x[i];
   }
}

//

void solve( vector< vector<double> > &A, vector<double> &b, vector<double> &x, int size )
{
   int i, ibig, ii, j;
   double big, f, temp;

   // Scale rows
   for ( i = 0; i < size; i++ )
   {
      big = abs( A[i][0] );
      for ( j = 1;  j < size; j++ ) big = max( abs( A[i][j] ), big );
      for ( j = 0;  j < size; j++ ) A[i][j] /= big;
      b[i] /= big;
   }

   // Upper-triangular
   for ( i = 0; i < size - 1; i++ )
   {
      // Make A[i][i] largest in i column on or below diagonal
      big = abs( A[i][i] );
      ibig = i;
      for ( ii = i + 1;  ii < size; ii++ )
      {
         temp = abs( A[ii][i] );
         if ( temp > big)
         {
            big = temp;
            ibig = ii;
         }
      }
      if ( ibig != i )
      {
         for ( j = i; j < size; j++ ) swap( A[i][j], A[ibig][j] );
         swap( b[i], b[ibig] );
      }

      // Pivot
      for ( ii = i + 1; ii < size; ii++ )
      {
         f = A[ii][i] / A[i][i];
         for ( j = i; j < size; j++ ) A[ii][j] -= f * A[i][j];
         b[ii] -= f * b[i];
      }
   }

   // Back-sub
   for ( i = size - 1; i >= 0; i-- )
   {
      x[i] = b[i];
      for ( j = i + 1; j < size; j++ ) x[i] -= A[i][j] * x[j];
      x[i] /= A[i][i];
   }
}

//

void output()
{
   #define SP << setw( 15 ) <<
   #define NL << endl;

   for ( auto &e : mon )
   {
      double x = e.x;
      e.v    = deflection( x );
      e.dvdx = gradient( x );
      e.S    = shearForce( x );
      e.M    = bendingMoment( x );
   }

   cout << "Beam:\n";
   cout << "  L:  " << beam.L  NL;
   cout << "  EI: " << beam.EI NL;
   cout NL;

   cout << "Point loads:\n" SP "x" SP "Value" NL;
   for ( auto &e : load ) cout SP e.x SP e.W NL;
   cout NL;

   cout << "Continuous loads:\n" SP "xl" SP "xr" SP "wl" SP "wr" NL;
   for ( auto &e : cont ) cout SP e.xl SP e.xr SP e.wl SP e.wr NL;
   cout NL;

   cout << "Reactions:\n" SP "x" SP "Type" SP "Value" NL;
   for ( auto &e : react ) cout SP e.x SP e.type SP e.R NL;
   cout NL;

   cout << "Monitors:\n" SP "x" SP "S" SP "M" SP "slope" SP "down" NL;
   for ( auto &e: mon ) cout SP e.x SP e.S SP e.M SP e.dvdx SP e.v NL;
   cout NL;
}

//

double deflection( double x )
{
   return ( Vnr( x ) + reactInt( x, 4 ) + beam.dV0 * x + beam.V0 ) / beam.EI;
}

//

double gradient( double x )
{
   return ( dVnr( x ) + reactInt( x, 3 ) + beam.dV0 ) / beam.EI;
}

//

double bendingMoment( double x )
{
   return Mnr( x ) - reactInt( x, 2 );
}

//

double shearForce( double x )
{
   return Snr( x ) + reactInt( x, 1 );
}

//

double Vnr( double x )
{ 
   return loadInt( x, 4 );
}

//

double dVnr( double x )
{
   return loadInt( x, 3 );
}

//

double Mnr( double x )   // Non-reaction bending moment (dM/dx = -S)
{
   return -loadInt( x, 2 );
}

//

double Snr( double x )   // Non-reaction shear force (Integral w dx)
{
   return loadInt( x, 1 );
}

//

double loadInt( double x, int p )  // pth integral of load
{
   double val = 0.0;
   for ( auto &e : load ) val += e.W * Mac( x - e.x, p - 1 ); // Point loads

   for ( auto &e : cont )
   {
      val += e.wl   * ( Mac( x - e.xl, p     ) - Mac( x - e.xr, p     ) ); // UDL
      val += e.dwdx * ( Mac( x - e.xl, p + 1 ) - Mac( x - e.xr, p + 1 )    // triangular
                        - e.dx * Mac( x - e.xr, p ) ); 
   }
   return val;
}

//

double reactInt( double x, int p )  // pth integral of reactions ("neg. loads")
{
   double val = 0.0;
   for ( auto &e : react )
   {
      if ( e.type == 'F' ) val -= e.R * Mac( x - e.x, p - 1 );
      if ( e.type == 'M' ) val += e.R * Mac( x - e.x, p - 2 );
   }
   return val;
}

//

double Mac( double xx, int n )    // Macaulay bracket and integrals
{
   if ( xx < 0 || n < 0 ) return 0.0;
   if ( n == 0 ) return 1.0;

   double val = xx;
   for ( int i = 2; i <= n; i++ ) val *= xx / i;
   return val;
}

closed account (48T7M4Gy)
----------------------------------------------------------------------
                      +++ ACTIONS ALONG BEAM +++                      
----------------------------------------------------------------------
      LOAD TAG: Pt load (Pt load at centre, P = 30000)
      BEAM TAG: CPP2, E = 1e+14, I = 1.8, L = 20000, dx = 1000
 END REACTIONS: Ra =   15000   Rb =   15000
   END MOMENTS: Ma =       0   Mb =       0
----------------------------------------------------------------------
   PT         X         V             BM          Slope         Defl'n
____^_________^_________^______________^______________^______________^
    0         0     15000              0    -0.00416667              0
    1      1000     15000        1.5e+07      -0.004125       -4.15278
    2      2000     15000          3e+07         -0.004       -8.22222
    3      3000     15000        4.5e+07    -0.00379167        -12.125
    4      4000     15000          6e+07        -0.0035       -15.7778
    5      5000     15000        7.5e+07      -0.003125       -19.0972
    6      6000     15000          9e+07    -0.00266667            -22
    7      7000     15000       1.05e+08      -0.002125       -24.4028
    8      8000     15000        1.2e+08        -0.0015       -26.2222
    9      9000     15000       1.35e+08   -0.000791667        -27.375
   10     10000     15000        1.5e+08              0       -27.7778
   11     11000    -15000       1.35e+08    0.000791667        -27.375
   12     12000    -15000        1.2e+08         0.0015       -26.2222
   13     13000    -15000       1.05e+08       0.002125       -24.4028
   14     14000    -15000          9e+07     0.00266667            -22
   15     15000    -15000        7.5e+07       0.003125       -19.0972
   16     16000    -15000          6e+07         0.0035       -15.7778
   17     17000    -15000        4.5e+07     0.00379167        -12.125
   18     18000    -15000          3e+07          0.004       -8.22222
   19     19000    -15000        1.5e+07       0.004125       -4.15278
   20     20000    -15000              0     0.00416667              0
----------------------------------------------------------------------


@lastchance As you no doubt expected there is essentially total agreement again.

I now see your earlier point about shear force at the RH end being zero as a check. That was the only difference I could see. It is another interesting artifact at the limit of the discontinuity and forces a decision on whether the design shear is -15000 (+15000) or 0 at the support. Given it is a beam segment I think it is 15000, keeping in mind if my program spat out 0 I probably wouldn't have objected ...

Just a thought, but you probably realise that your 'Macaulay integrator' plus end fixity and restraint matrix solver has the advantage of making the problem completely general. ie any load function f(x) can be applied to the beam, so separate load types are not needed if you have a system of writing and parsing f(x) whereby the load constructor is more or less just an equation.
Hi @kemort, thanks for taking the time to try this out.

any load function f(x) can be applied to the beam, so separate load types are not needed if you have a system of writing and parsing f(x) whereby the load constructor is more or less just an equation.


Yes, I had noted this. However, I steered clear of it here because most structural load conditions are usually given in terms of point loads and piecewise linear ones (effectively, UDL + triangle). Also, I would still have to integrate it analytically several times, so the only realistic combinations would be simple functions like polynomials, exponentials or the trig functions. The only cases where I encounter much more complicated distributions are on aerodynamic shapes like airfoils or wind loading on "vertical beams" (e.g. wind-turbine monopiles).

A more complicated, but still tractable problem, is where the beam sectional properties (especially I) change with distance - for example, wind loading on tapered monopiles.

My original code also had point moments in (e.g. from side connections) but, as you will see from the almost complete dearth of comments in my code, I was really struggling to make it fit into the allowable post size, so I dropped them.

It's been a good learning exercise, but I hope the original poster doesn't think I'm a structural engineer! My first degree is in maths - I'm just supposed to understand things like beam loading when working in an engineering department.
@lastchance
I won't hold it against you!
It's been an interesting discussion and I've learned quite a bit. However, with my lack of knowledge of C++ it's going to be some time before I write code to the same level as you (if ever). At the moment I'm sticking to the simple mechanics of a simply supported beam, with no frills like applied moments, torsion etc. That should get me through structs, functions and possibly OOP.

Thanks very much for your help.
Last edited on
Topic archived. No new replies allowed.
Pages: 123