Singly Reinforced Problem of aRCe in Sagemath

This problem teaches how to use functions,arrays,loops, if elseand filehandling in Sagemath.

Here is the code:

(head.sage)

rccDescription=["Grade of concrete","Grade of steel", "Width(b)","Overall Depth", "Dia of reinforced on tension face[Layer1,Type1]","Number of bars on tension face [Layer 1, Type 1]","Dia of reinforced on tension face[Layer1,Type2]","Number of bars on tension face [Layer 1, Type 2]","Dia of reinforced on tension face[Layer2,Type1]","Number of bars on tension face [Layer 2, Type 1]","Dia of reinforced on tension face[Layer2,Type2]","Number of bars on tension face [Layer 2, Type 2]","Dia of reinforced on tension face[Layer3,Type1]","Number of bars on tension face [Layer 3, Type 1]","Dia of reinforced on tension face[Layer3,Type2]","Number of bars on tension face [Layer 3, Type 2]","Effective cover"]
Es=var('Es')
Es = 200 
Es *= 1000
rccDescriptionRes=["d","x_u/d","x_u_lim/d","Mu(kNm)","Ast","Steel (%)"]
rccItem=[20,415,250,450,16,3,0,0,0,0,0,0,0,0,0,0,20]
rccItemRes=[0,0,0,0,0,0]

(function.sage)

### Function is defined in this file######
def calculation(E,designParameter,designParameterRes):
 fd =  designParameter[3] -  designParameter[16];
 designParameterRes[0] =  fd;

 stArea  = (3.141 / 4.0 ) *  designParameter[5] *  designParameter[4] *  designParameter[4];
 stArea += (3.141 / 4.0 ) *  designParameter[7] *  designParameter[6] *  designParameter[6];
 stArea += (3.141 / 4.0 ) *  designParameter[9] *  designParameter[8] *  designParameter[8];
 stArea += (3.141 / 4.0 ) *  designParameter[11] *  designParameter[10] *  designParameter[10];
 stArea += (3.141 / 4.0 ) *  designParameter[13] *  designParameter[12] *  designParameter[12];
 stArea += (3.141 / 4.0 ) *  designParameter[15] *  designParameter[14] *  designParameter[14];

 fxu = 0.87 *  designParameter[1] *  stArea / (0.36 *  designParameter[0] *  designParameter[2] *  fd );
 designParameterRes[1] =  fxu;
 tmp1 = 0.85 *  designParameter[1] /  E + 0.002 ;
 xulim = 0.0035 / (0.0035 +  tmp1);

 designParameterRes[2] =  xulim;

 if ( fxu <  xulim ):
    tmp1 =  stArea*designParameter[1]/(designParameter[2]*fd*designParameter[0]) ;
    tmp1 =  1.0 -  tmp1 ;
    tmp1 *= 0.87 *  designParameter[1] *  stArea *  fd ;
    designParameterRes[3] =  tmp1 / 1.0E06 ;

 else:

     designParameterRes[3]=  0.0 ;

 designParameterRes[4] =  stArea ;
 designParameterRes[5] = 100.0 *  stArea / (  designParameter[2] *  fd )  ;

(index.sage) Main file that need to be executed by user

attach "head.sage"
attach "function.sage"
calculation(Es,rccItem, rccItemRes)

if (rccItemRes[3]<= 0.0):
    print "*** REVISE SECTION: It is over-reinforced ***"
print "Input Values are:"
print
for i in range(17):
    if(rccItem[i]<>0):
        print rccDescription[i],"=",rccItem[i]
print
print "Output Values are:"
print
for i in range(6):
    print rccDescriptionRes[i],"=",rccItemRes[i]

Run index.sage file as:

$ sage index.sage>res.txt

And the result will get stored in res.txt file. Here is res.txt file:

Input Values are:

Grade of concrete = 20
Grade of steel = 415
Width(b) = 250
Overall Depth = 450
Dia of reinforced on tension face[Layer1,Type1] = 16
Number of bars on tension face [Layer 1, Type 1] = 3
Effective cover = 20

Output Values are:

d = 430
x_u/d = 0.281316725581395
x_u_lim/d = 0.481844777146791
Mu(kNm) = 82.7289049007315
Ast = 603.072000000000
Steel (%) = 0.560997209302326

Other ways to write head.sage file are:

(head1.sage)

a=[0]*17
rccDescription=["Grade of concrete","Grade of steel", "Width(b)","Overall Depth", "Dia of reinforced on tension face[Layer1,Type1]","Number of bars on tension face [Layer 1, Type 1]","Dia of reinforced on tension face[Layer1,Type2]","Number of bars on tension face [Layer 1, Type 2]","Dia of reinforced on tension face[Layer2,Type1]","Number of bars on tension face [Layer 2, Type 1]","Dia of reinforced on tension face[Layer2,Type2]","Number of bars on tension face [Layer 2, Type 2]","Dia of reinforced on tension face[Layer3,Type1]","Number of bars on tension face [Layer 3, Type 1]","Dia of reinforced on tension face[Layer3,Type2]","Number of bars on tension face [Layer 3, Type 2]","Effective cover"]
Es=var('Es')
Es = 200 
Es *= 1000
rccItem=[0]*17

rccDescriptionRes=["d","x_u/d","x_u_lim/d","Mu(kNm)","Ast","Steel (%)"]
for i in range(17):
    o=open('value.txt','r')
    a=o.readlines(17)
for i in range(17):
     rccItem[i]=Integer(a[i])
rccItemRes=[0]*6

(head2.sage)

rccItem=[0]*17
r=[0]*17
#rcc=[0]*17
rccDescription=[0]*17
for i in range(17):
    o=open('question.txt','r')
    rccDescription = o.readlines(17)
    r[i]=raw_input(rccDescription[i])
for i in range(17):
    rccItem[i]=Integer(r[i])
    print "The values for",rccDescription[i],"=",rccItem[i]

Es=var('Es')
Es = 200 
Es *= 1000
rccDescriptionRes=["d","x_u/d","x_u_lim/d","Mu(kNm)","Ast","Steel (%)"]
rccItemRes=[0]*6

(value.txt)

20
415
250
450
16
3
0
0
0
0
0
0
0
0
0
0
20

(question.txt)

Grade of concrete
Grade of steel
Width(b)
Overall Depth
Dia of reinforced on tension face[Layer1,Type1]
Number of bars on tension face [Layer 1, Type 1]
Dia of reinforced on tension face[Layer1,Type2]
Number of bars on tension face [Layer 1, Type 2]
Dia of reinforced on tension face[Layer2,Type1]
Number of bars on tension face [Layer 2, Type 1]
Dia of reinforced on tension face[Layer2,Type2]
Number of bars on tension face [Layer 2, Type 2]
Dia of reinforced on tension face[Layer3,Type1]
Number of bars on tension face [Layer 3, Type 1]
Dia of reinforced on tension face[Layer3,Type2]
Number of bars on tension face [Layer 3, Type 2]
Effective cover

Thats all. 🙂

Advertisements

About Priyanka Kapoor

Simple, Hardworking & friendly.....
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s