Sunday, September 27, 2020

Cut and Fill Volume for given GL and FL profile, using Python Code

Hi,

Please don't get afraid by the length of the code. It is very simple to copy and paste it into your Python IDEs such as Pycharm or Visual Studio and run it. 


Once you run the code, it will ask you to input the section width and slope, and then the chainage, GL(ground level), FL(Floor level) etc. Output will be the cut or fill height(h), End Areas, and then the Cut and Fill Volume. The result will be in the tabular form. 

Code: 

import NumPy as np

from pandas import DataFrame

Chain = np.array([])
GL = np.array([])
FL = np.array([])
Cutting = np.array([])
Filling = np.array([])
Area = np.array([])
Vcut = np.array([0])
Vfill = np.array([0])
n = int(input('no. of sections, n = '))
b = float(input('width of level section b = '))
s = float(input('slope s = '))
cut = 0
fill = float()
A = float()

for i in range(n):
print(f'for section{i}')
ch = float(input('Chainage = '))
Chain = np.append(Chain, ch)
gl = float(input('GL = '))
GL = np.append(GL, gl)
fl = float(input('FL = '))
FL = np.append(FL, fl)
if gl>=fl:
fill = 0
Filling = np.append(Filling, fill)
cut = gl - fl
Cutting = np.append(Cutting, cut)
A = (b+s*cut)*cut
Area = np.append(Area, A)
else:
fill = fl - gl
Filling = np.append(Filling, fill)
cut = 0
Cutting = np.append(Cutting, cut)
A = (b + s * fill) * fill
Area = np.append(Area, A)
i+=1

print(f' Please note, When GL> FL, section is in cutting, h(cutting) = GL-FL,'
f'and if GL<FL it is in Filling, h(filling) = FL-GL'
f'Area of section, A = (b + sh)h', "\n")
df = DataFrame()
df['Chainage'] = Chain
df['GL'] = GL
df['FL'] = FL
df['Cutting'] = Cutting
df['Filling'] = Filling
df['Area'] = Area
print(df)

x = float()
D=float()
i=0
for i in range(n-1):

if Cutting[i]>0 and Filling[i+1]>0:
print(f'Both cutting and Filling in between Chainage {Chain[i]} to {Chain[i+1]}',)
D = Chain[i + 1] - Chain[i]
x = D*Cutting[i]/(Filling[i+1]+Cutting[i])
Vc = Area[i]*x/2
Vcut = np.append(Vcut,Vc)
Vf = Area[i+1]*(D-x)/2
Vfill = np.append(Vfill, Vf)
print(f'Cutting till distance x = {x}, and filling in {D-x}', "\n")

elif Filling[i]>0 and Cutting[i+1]>0:
print(f'Both cutting and Filling in between Chainage {Chain[i]} to {Chain[i + 1]}')
x = D * Filling[i] / (Filling[i] + Cutting[i+1])
print(f'Filling till distance x = {x}, and Cutting in {D - x}', "\n")
Vf = Area[i]*x/2
Vfill = np.append(Vfill, Vf)
Vc = Area[i+1]*(D-x)/2
Vcut = np.append(Vcut, Vc)

elif Cutting[i]>0 and Cutting[i+1]>0:
print(f'Only cutting in between Chainage {Chain[i]} to {Chain[i + 1]}')
Vc = D*(Area[i + 1] + Area[i]) / 2
Vcut = np.append(Vcut, Vc)
Vf = 0.0
Vfill = np.append(Vfill, Vf)
print(f' Cutting Volume = {D}*({Area[i]} + {Area[i+1]}) / 2 = {Vc}', "\n")

elif Filling[i]>0 and Filling[i+1]>0:
print(f'Only Filling in between chainage {Chain[i]} to {Chain[i + 1]}')
Vf = D * (Area[i + 1] + Area[i]) / 2
Vfill = np.append(Vfill, Vf)
Vc = 0.0
Vcut = np.append(Vcut, Vc)
print(f' Filling Volume = {D}*({Area[i]} + {Area[i + 1]}) / 2 = {Vc}')

i+=1

df['Filling Volume'] = Vfill
df['Cutting Volume'] = Vcut
print(df)

No comments:

Post a Comment

Cut and Fill Volume for given GL and FL profile, using Python Code

Hi, Please don't get afraid by the length of the code. It is very simple to copy and paste it into your Python IDEs such as Pycharm or V...