Program to calculate failure loads of rc columns

Hi all,

I am not new to c++. I took a module on computing 3 yrs ago. However, due to the lack on practice ever since, I am as good as a beginner now. Now in my final year, I have to come up with a program to predict failure loads of slender reinforced concrete column pertaining to Indian Standards (a small part of my final year project). According to my understanding, the Indian Standard on this subject is highly similar to that of BS8110 and Eurocode 2. So I'm hoping that I can get help on understanding the following extract of programming code for BS8110 and Eurocode 2, and thus, modify it for my own use. An explanation for each portion and what it does would be most helpful. Many thanks. And please do leave behind your full name as I would like add you to my acknowledgement page.

Here are the codes...
BS8110:

1
2
3
4
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<errno.h> 



char col[30];

1
2
3
4
5
float N[300],M[300],Neadd[300],Nuz,Nbal,xbal,ik,Epsc,Epst,aa,fsc,fst,Escbal,Ba;
float eadd,Nmax,Mmax,Neaddmax,xmax,Epsy,xx,fscbal,K;
int i,bb,fos;
float b,h,L,e,dd,d,fcu,fy,Asc,Ast,Es,Epscu,Fmax,DAD,DAS,DAE,DAL;
int im,ii,mm;


1
2
3
4
5
6
7
8
9
10
11
main()
{

FILE *rd;
FILE *fq;




rd=fopen("data","r");
fq=fopen("bs.out","w");


1
2
im=0;
fscanf(rd,"%d %d\n",&ii ,&fos);



1
2
3
do{
fscanf(rd,"%[^\n] %f %f %f %f %f %f %f %f %f %f %f\n",\
col, &b, &h, &L, &e, &Asc, &dd, &Ast, &d, &Es, &fy, &fcu);


float x[300]={0};

1
2
3
4
5
6
7
8
9
10
11
if(fos==1)
{
fcu=fcu/1.5;
fy=fy/1.15;
}
im=im++;
Epsy=fy/Es;
ik=1;
bb=300;
aa=1;
xx=dd/100;


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
do
{
	for(i=1; i<bb; i++)
	{
	x[i]=xx+aa*(i-1);
	Epsc=(x[i]-dd)*0.0035/x[i];
	Epst=(d-x[i])*0.0035/x[i];

	if(Epsc>Epsy)
		fsc=fy;
	else
		fsc=Es*Epsc;

	if(fabs(Epst)>Epsy)
		{
		if(Epst<0)fst=-fy;
		else fst=fy;
		}
	else
	fst=Es*Epst;

	N[i]=(0.67*fcu*b*0.9*x[i]+fsc*Asc-fst*Ast)*0.001;
	M[i]=(0.67*fcu*b*0.9*x[i]*(h/2-0.45*x[i])+fsc*Asc*(h/2-dd)+fst*Ast*(d-h/2))*1e-6;
	Nuz=(0.67*fcu*h*b+fy*(Asc+Ast))*0.001;
	xbal=0.0035*d/(0.0035+Epsy);
	Escbal=0.0035*(xbal-dd)/xbal;

			if(e==0)
			{
			e=0.05*h;
			}

	if(Escbal>Epsy)
		fscbal=fy;
	else
		fscbal=Es*Escbal;

	Nbal=(0.67*fcu*b*0.9*xbal+fscbal*Asc-fy*Ast)*0.001;
	if(N[i]<0)continue;
	K=(Nuz-N[i])/(Nuz-Nbal);
	if(K>1)K=1;
	Ba=pow((L/h),2)/2000;
	eadd=K*Ba*h;
	if(L/h<15) eadd=0;
	Neadd[i]=N[i]*(e+eadd)*0.001;
	if(fabs(Neadd[i]-M[i])<0.00000001)
	{
		Nmax=N[i];
		Mmax=M[i];
		Neaddmax=Neadd[i];
		xmax=x[i];
		i=300;
		ik=11;
	}
	else if(Neadd[i]>M[i])
		{
		if(Neadd[i]>0)
		{
		Nmax=N[i];
		Mmax=M[i];
		Neaddmax=Neadd[i];
		xmax=x[i];
		xx=x[i-1];
		i=300;
		bb=12;
		}
		else
		{
		xx=xx*2;
		i=300;
		ik=0;
		}
		}
	}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
aa=1/(pow(10,ik));
ik=ik++;
}while(ik<10);

	fprintf(fq,"%s\t %f\t kN\t %f\t mm\n",col,Nmax, eadd);

}while(im<ii);


fclose(rd);
fclose(fq);

return 0;
}
Last edited on
I probably can't help with an explanation, but I'm sure that anyone who can would prefer that you use code tags (located to the right of the message box when posting).
Please format your code with the tags "<code>" "</code>" Use square brackets instead of the "<" and ">"
{I mean "[]"}
My apologies. Thanks for the tip.
closed account (3TXyhbRD)
Still, format your code.
i have broken them up as best as i can into parts. pardon me if some of them don't belong together. thanks.
closed account (3TXyhbRD)
Totally offtopic:

It's not bad that you broken them into parts however try to separate header/source files. For instance if you have A.hpp, B.hpp, A.cpp and B.cpp your post should look like:

1
2
3
4
5
6
#ifndef A_HPP
#define A_HPP

// header stuff such as function prototypes, class declaration, template information etc.

#endif 


1
2
3
4
5
6
#ifndef B_HPP
#define B_HPP

// Same as the previous

#endif 


1
2
3
#include "A.hpp"

// Implementations, template specializations etc. 


1
2
3
#include "B.hpp"

// Same as previous. 


Using this style (#ifndef.. define.. endif, also called guards and they are recommended) for headers tells us the file name so one doesn't need to write extra information like: this is file A.hpp.

When implementing prototypes, class declarations or specializing templates written in a header one must include the respective file therefore by having the #include ... we, again, know the file name and what it implements.

Next stop is "code formatting". It is essential to write code in a specific format because it becomes more easy to follow and it's less tiring to read. One can view it as a book or a magazine.

Typically when you read books or magazines you don't see phrases start at different distances from the left side. All distances between paragraphs are the same, all important titles share the same style (font, color, underlined or not etc.). The same should happen with source code since one of its purposes is to make it easier for humans to read.

Most IDEs will format the code for you in a default format and some even allow you to fully customize it (Eclipse for example). What's important is that one should know things like: I have an opening brace, do I place it on a new line? Do I leave it at the end of the line? Do I indent it? Until the end of day it's trial and error. One needs to either try all possible situations or filter some with his own mind because it is clear that they will look horrible.

For instance a code like (I don't know what it does):
1
2
3
4
5
6
7
8
9
10
int myFunction(){
int i, j, k = 0;
for(i=0;i<10;i++)
if(i%2==0){
j = 1;
while(j<10)
k++;
j++;}
return k;
}

Is harder to read and understand than this (same code, only a bit formatted):
1
2
3
4
5
6
7
8
9
10
11
int myFunction(){
    int i, j, k = 0;
    for (i = 0; i < 10; i++)
        if (i % 2 == 0){
            j = 1;
            while (j < 10)
                k++;
            j++;
        }
    return k;
}

Woah! Infinite loop at line 6.

Examples can go on. One important note thought, format your code. Make it readable. Make it say "READ ME EVEN IF I MAKE NO SENSE!". Off course I am exaggerating a bit, but still format your code if you want someone to read and debug it.

PS: for learning more about what code formatting means look into IDEs for code formatter or similar names. Once you get there you should be able to edit all formatting options and some IDEs have a code snippet next to the option pane so you can see the differences (before and after thingy, really nice).
I've forgotten cleanly about all that as well. thanks for taking the time to explain.
A lot of this are physics formulas. Whats probably occurring is the do loop is traversing the data file applying calculations to each specific portion of the column to obtain a value which will later be determined as a possible failure.

You'll want to refer to your Indian Code standards and you physics books to determine what each calculation does.

You'll also have to be more specific about what it is you hope to accomplish.

Whoever wrote this did not intend to maintain it, or assumed that people who would be reading it would understand what is going on.

This is a C++ board, with topics that stay within the boundaries of the language. If you have questions on the proper usage of C++, this is a good place.

In other words: Determining failure loads on reinforced concrete as it pertains to Indian and European Standards might be a little off topic for this board.

Again, you'll need to be more specific about what you want to accomplish.
Hi Pogrady, sorry for the overdue reply.

Thanks for your explanation. It was what i needed. I didn't understand what the do loop does but you helped clear that up.

In hand calculation of failure loads, we would first construct an design interaction curve with data of columns from experiments, such as column dimensions, reinforcements and end eccentricity. By your explanation, I think the values obtain in the loop are coordinates (M, N) used to generate the curve.

The next step in hand calculation is to assume an N value within the range in the interaction curve. The corresponding M value is then graphically read from the curve.

Using the combination of a few equations, the design moment is obtained.

When the design moment falls outside the interaction curve, the initial assumed value of N is too high. On the other hand, if design moment falls within the interaction curve, a higher N is to be used for the assumption.

When the design moment falls on the interaction curve, this indicated the column is in a state of failure. Therefore the assumed N value is the failure load of the column.

I think its safe to say that Neadd is the design moment.

My immediate challenge is to figure out what some of the abbreviation stand for. Usually in an analysis we would require 10 or less parameters but in this code there are 46. Nevertheless, with your help at least now I have some idea how to start.

Thank you. Any further inputs are welcome.
Topic archived. No new replies allowed.