Skip to content

Commit 40a73a6

Browse files
committed
Converted cantbm file to function #1
1 parent a42bf38 commit 40a73a6

4 files changed

Lines changed: 124 additions & 118 deletions

File tree

Civil.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include<stdio.h>
2+
#include<math.h>
3+
#include"Civil.h"
4+
5+
/*
6+
* Program for analysis of cantilever beam developed by Dr.G.S.Suresh and Dr.
7+
* M.N.Shesha Prakash
8+
* l = Span of the beam
9+
* p[] = Intensity of concentrated load
10+
* ac[] = Position of concentrated load measured from free end A
11+
* wu[]= Intensity of uniformly distributed load (udl)
12+
* au[] = Position of starting point of udl measured from free end A
13+
* lu[] = Length of udl
14+
* x = Position of section where SF and BM are computed, measured from free end A
15+
* dx = Length of segment computed as total length divided by number of segments
16+
* Nc = Number of concentrated loads
17+
* Nu = Number of uniformly distributed loads
18+
* N = Number of segments
19+
* Vc[] = Shear force at a section due to concentrated loads
20+
* Vu[] = Shear force at a section due to uniformly distributed loads
21+
* Mc[] = Bending moment at a section due to concentrated loads
22+
* Mu[] = Bending moment at a section due to uniformly distributed loads
23+
* V[] = Net shear force at a section due to concentrated loads and uniformly distributed
24+
* loads
25+
* M[] = Net bending moment at a section due to concentrated loads and uniformly
26+
* distributed loads
27+
* i,j,k are integer variables used as index in for loops
28+
* */
29+
int cantbm(int Nc, int Nu, float l, int N)
30+
{
31+
FILE *fp;
32+
int i, j, k;
33+
float x,dx,wu[10], au[10], lu[10], Vc[10], Mc[10], Vu[10];
34+
float Mu[10], V[10], M[10], p[10], ac[10];
35+
36+
fp = fopen("cantbm.out","a");
37+
38+
if (Nc>0)
39+
{
40+
printf("For each Concentrated Load Enter Intensity of Load and its position \n");
41+
for (i=1; i<=Nc; i++)
42+
scanf("%f%f",&p[i],&ac[i]);
43+
}
44+
if (Nu>0)
45+
{
46+
printf("For each UDL Type Intensity of Load, its distance from free ");
47+
printf("end and length \n");
48+
for (i=1; i<=Nu;i++)
49+
{
50+
scanf("%f%f%f",&wu[i],&au[i],&lu[i]);
51+
}
52+
}
53+
fprintf(fp," x SF BM\n");
54+
x=0;
55+
dx=l/N;
56+
for (i=0;i<=N; i++)
57+
{
58+
Vc[i]=0;
59+
Mc[i]=0;
60+
Vu[i]=0;
61+
Mu[i]=0;
62+
V[i]=0;
63+
M[i]=0;
64+
}
65+
for (i=0; i<=N;i++)
66+
{
67+
for (j=1;j<=Nc;j++)
68+
{
69+
if (x>ac[j])
70+
{
71+
Vc[i]=Vc[i]+p[j];
72+
Mc[i]=Mc[i]-p[j]*(x-ac[j]);
73+
}
74+
}
75+
76+
for (k=1; k<=Nu; k++)
77+
{
78+
if ((x>au[k]) && (x<=au[k]+lu[k]))
79+
{
80+
Vu[i]=Vu[i]+wu[k]*(x-au[k]);
81+
Mu[i]=Mu[i]-wu[k]*(x-au[k])*(x-au[k])/2.0;
82+
}
83+
else if (x>(au[k]+lu[k]))
84+
{
85+
Vu[i]=Vu[i]+wu[k]*lu[k];
86+
Mu[i]=Mu[i]-wu[k]*lu[k]*(x-au[k]-lu[k]/2.0);
87+
}
88+
}
89+
V[i]=Vc[i]+Vu[i];
90+
M[i]=Mc[i]+Mu[i];
91+
fprintf(fp, "%5.0f %10.3f %10.3f\n",x,V[i],M[i]);
92+
for(j=1; j<=Nc; j++)
93+
if (x==ac[j])
94+
fprintf(fp, "%5.0f %10.3f %10.3f\n", x, V[i]+p[j],M[i]);
95+
x=x+dx;
96+
}
97+
98+
return 0;
99+
100+
}

Civil.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* \file Civil.h
3+
*
4+
* \brief This file contains the header of the Civil Program Functions
5+
*
6+
* \version 0.1
7+
* \date 01/27/2014 05:41:23 PM\n
8+
* Compiler g++
9+
*
10+
* \author H. S. RAI
11+
* License GNU General Public License
12+
* \copyright Copyright (c) 2014, GreatDevelopers
13+
* https://github.com/GreatDevelopers
14+
*/
15+
16+
int cantbm(int Nc, int Nu, float l, int N);

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ OUTPUT = main
33

44

55

6-
all:
7-
g++ -o $(OUTPUT) main.c
6+
all: Civil.o
7+
g++ -o $(OUTPUT) main.c Civil.o
88

9+
Civil.o: Civil.h Civil.c
10+
g++ -c Civil.c
911

10-
output:
12+
output: gnuplot.sh
1113
cat gnuplot.sh | gnuplot

main.c

Lines changed: 3 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,9 @@
1-
/*
2-
* Program for analysis of cantilever beam developed by Dr.G.S.Suresh and Dr.
3-
* M.N.Shesha Prakash
4-
* l = Span of the beam
5-
* p[] = Intensity of concentrated load
6-
* ac[] = Position of concentrated load measured from free end A
7-
* wu[]= Intensity of uniformly distributed load (udl)
8-
* au[] = Position of starting point of udl measured from free end A
9-
* lu[] = Length of udl
10-
* x = Position of section where SF and BM are computed, measured from free end A
11-
* dx = Length of segment computed as total length divided by number of segments
12-
* Nc = Number of concentrated loads
13-
* Nu = Number of uniformly distributed loads
14-
* N = Number of segments
15-
* Vc[] = Shear force at a section due to concentrated loads
16-
* Vu[] = Shear force at a section due to uniformly distributed loads
17-
* Mc[] = Bending moment at a section due to concentrated loads
18-
* Mu[] = Bending moment at a section due to uniformly distributed loads
19-
* V[] = Net shear force at a section due to concentrated loads and uniformly distributed
20-
* loads
21-
* M[] = Net bending moment at a section due to concentrated loads and uniformly
22-
* distributed loads
23-
* i,j,k are integer variables used as index in for loops
24-
* */
25-
26-
271
#include<stdio.h>
282
#include<math.h>
3+
#include"Civil.h"
294

305
int main()
316
{
32-
/* Declaring the pointer fp as a file */
33-
FILE *fp;
34-
int i, j, k, Nc, Nu, N;
35-
float x,l,dx,p[10],ac[10], wu[10], au[10], lu[10], Vc[10], Mc[10], Vu[10];
36-
float Mu[10], V[10], M[10];
37-
38-
/* Assigning output file cantbm.out */
39-
fp = fopen("cantbm.out","a");
40-
41-
/* Printed on the screen to guide user to enter values */
42-
printf("Enter the values of Nc, Nu, l, N\n");
43-
44-
/* Input of general information of beam */
45-
scanf("%d%d%f%d",&Nc,&Nu,&l,&N);
46-
47-
/* Input is done when concentrated load is present */
48-
if (Nc>0)
49-
{
50-
printf("For each Concentrated Load Enter Intensity of Load and its position \n");
51-
for (i=1; i<=Nc; i++)
52-
/* Input of intensity of concentrated load and its position */
53-
scanf("%f%f",&p[i],&ac[i]);
54-
}
55-
56-
/* Input is done when uniformaly distributed load is present */
57-
if (Nu>0)
58-
{
59-
printf("For each UDL Type Intensity of Load, its distance from free ");
60-
printf("end and length \n");
61-
for (i=1; i<=Nu;i++)
62-
{
63-
/* Input of intensity of uniformly distributed load its, position and its length */
64-
scanf("%f%f%f",&wu[i],&au[i],&lu[i]);
65-
}
66-
}
67-
/* Printing of the header of table */
68-
fprintf(fp," x SF BM\n");
69-
x=0;
70-
dx=l/N;
71-
for (i=0;i<=N; i++) /* Initialization */
72-
{
73-
Vc[i]=0;
74-
Mc[i]=0;
75-
Vu[i]=0;
76-
Mu[i]=0;
77-
V[i]=0;
78-
M[i]=0;
79-
}
80-
for (i=0; i<=N;i++) /* Loop for computing SF and BM at equal Interval */
81-
{
82-
for (j=1;j<=Nc;j++) /* Loop for computing SF and BM due to concentrated load */
83-
{
84-
if (x>ac[j])
85-
{
86-
Vc[i]=Vc[i]+p[j]; /* Computation of SF */
87-
Mc[i]=Mc[i]-p[j]*(x-ac[j]); /* Computation of BM */
88-
}
89-
}
90-
91-
for (k=1; k<=Nu; k++) /* Loop for computing SF and BM due to uniformly distributed load */
92-
{
93-
if ((x>au[k]) && (x<=au[k]+lu[k]))/* Section on UDL */
94-
{
95-
/* Computation of SF */
96-
Vu[i]=Vu[i]+wu[k]*(x-au[k]);
97-
98-
/* Computation of BM */
99-
Mu[i]=Mu[i]-wu[k]*(x-au[k])*(x-au[k])/2.0;
100-
}
101-
else if (x>(au[k]+lu[k]))
102-
{
103-
/* Computation of SF */
104-
Vu[i]=Vu[i]+wu[k]*lu[k];
105-
106-
/* Computation of BM */
107-
Mu[i]=Mu[i]-wu[k]*lu[k]*(x-au[k]-lu[k]/2.0);
108-
}
109-
}
110-
V[i]=Vc[i]+Vu[i]; /* Computation of net Shear Force of Section */
111-
M[i]=Mc[i]+Mu[i]; /* Computation of net Bending moment of section */
112-
fprintf(fp, "%5.0f %10.3f %10.3f\n",x,V[i],M[i]);
113-
/* To check for the section to have any concetrated load */
114-
for(j=1; j<=Nc; j++)
115-
if (x==ac[j])
116-
fprintf(fp, "%5.0f %10.3f %10.3f\n", x, V[i]+p[j],M[i]); /* Adds intensity of concentrated load to Sf at the section */
117-
x=x+dx;
118-
}
119-
7+
cantbm(3,0,5,5);
1208
return 0;
121-
}
9+
}

0 commit comments

Comments
 (0)