Python Code – Section Areas ( of Level Section, Two-Level Section, and Three-Level Sections ) and Cut and Fill Volume using Prismoidal Formula

In order to find the Cut and Fill Volume of soil for a given profile, the first step is to calculate the section areas at a specified interval. End areas are calculated for a level trapezoid differently than for a two-level and three-level section. The following Python code contains all the formulas at the right places. 

Once the code given below is run, few inputs are to be provided, as per the standard formulas as and when asked. When asked for the unit, put a unit of length such as m, ft etc. Also, ‘n’ is for the number of sections, for example, you might need to calculate the areas at 5 different sections, on the given profile, then n = 5. 

The Volume Calculation at the end, for the cut and fill, is done using the prismoidal formula which works only when you have an odd number of sections. If you don’t need the volume part, simply copy the code only above the comment “# Volume using Prismoidal Formula”.

Code:

import math
import numpy as np
# Type of Sections
a = input('Section Areas given? y/n ')
A = float()
u = str()
l = str()
if a.lower() == "n":
l = input('Is there any level section? y/n ')

m = str()
if l.lower() == "n":
m = input('Is there any two-level section? y/n ')

w = str()
if l.lower() == "n":
w = input('Is there any three-level section? y/n ')
# Different approaches for level, two-level and three-level sections
Areas = np.array([])

if l.lower() == "y":
print("Level Trapezoidal Section,", "n",
" area is given as A = (b+sh)h")
n = int(input('number of sections = '))
for i in range(n):
i+=1
print(f'for Secion{i}')
b = float(input('b = '))
s = float(input('s = '))
h = float(input('h = '))
u = input('unit= ')

A = (b+s*h)*h
Areas = np.append(Areas, A )
print(f' Area{i} A{i} = ({b}+{s}*{h})*{h} = {A} {u}^2', "n")

if m.lower() == "y":

print(“Two-Level Trapezoidal Section,”, n,
” area is given as A = {(b/2s + h)(b1+b2)-b^2/2s}/2,”, n
“where, b1 = b/2 + n*s(h + b/(2*n))/(n-s)”, n
“b2 = b/2 + n*s(h – b/(2*n))/(n-s)”, n)

n = int(input(‘number of sections = ‘))
for i in range(n):
i += 1
print(f’for Secion{i})
b = float(input(‘b = ‘))
s = float(input(‘s = ‘))
h = float(input(‘h = ‘))
u = input(‘unit of length = ‘)
n = float(input(‘ground slope n = ‘))
b1 = b / 2 + n * s * (h + b / (2 * n)) / (n – s)
b2 = b / 2 + n * s * (h – b / (2 * n)) / (n – s)
A = ((b / 2 * s + h) * (b1 + b2) – b ** 2 / (2 * s)) / 2
Areas = np.append(Areas, A)

print(f”’ putting all values for section{i}, b1 = {b1} {u}, b2= {b2} {u},
Area{i} A{i} = (({b} / 2 * {s} + {h}) * ({b1} + {b2}) – {b} ** 2 / (2 * {s})) / 2 ‘
f’= {A} {u}^2”’, n)

if w.lower() == “y”:

print(“Three-Level Section,”, n,
” area is given as A = h*(b1+b2)/2 + b*(h1+h2)/2″, n
“where, b1 = n1*s*(h + b/(2*s))/(n1-s)”, n
“b2 = n2*s*(h + b/(2*s))/(n2+s)”
“h1 = h + b1/n1”
” h2 = h – b2/n2″, n)

n = int(input(‘number of sections = ‘))
for i in range(n):
i += 1
print(f’for secion{i})
b = float(input(‘b = ‘))
s = float(input(‘s = ‘))
h = float(input(‘h = ‘))
u = input(‘unit= ‘)
n1 = float(input(‘ground slope1, n1 = ‘))
n2 = float(input(‘ground slope2, n2 = ‘))
b1 = n1 * s * (h + b / (2 * s)) / (n1 – s)
b2 = n2*s*(h + b/(2*s))/(n2+s)
h1 = h + b1/n1
h2 = h – b2/n2
A = h*(b1+b2)/2 + b*(h1+h2)/2
Areas = np.append(Areas, A)
print(f’putting all the values, b1= {b1}{u}, b2 = {b2}{u}, ‘
f’h1 = {h1}{u}, and h2 = {h2}{u})
print(f’ Area{i} A{i} = {h}*({b1}+{b2})/2 + {b}*({h1}+{h2})/2 ‘
f’= {A} {u}^2′, n)

elif a.lower() == “y”:
n = int(input(‘number of sections = ‘))
u = input(‘units of area = ‘)
for i in range(n):
i += 1
print(f’for Secion{i})
A = input(‘Area = ‘)
Areas = np.append(Areas, A)

print(f’all the areas are {Areas} {u}^2′)

# Volume using Prismoidal Formula

n = np.size(Areas) –1
print(f’number of areas, n = {n+1})

V= float()
V2 = float()
V3 = float()
V1 = float()
if (n+1)%2 == 1:
print(‘Calculation of Cut and Fill using Prismoidal Formula:’,
n, ‘ Volume (Cutting or Filling), V = D{A1 + An + 4(A2 + A4 + An-1) + 2(A3 + A5 + ..+An-2)}’)
D = float(input(‘Distance between consecutive Sections, D = ‘))
V1 = D*(Areas[0] + Areas[n])/3
i = 0
while i < n/2:

V2 = V2+ 4*Areas[1+2*i]*D/3
i+=1
i=0
while i < (n/21):
V3 = V3 + 2 * Areas[2 + 2 * i] * D / 3
i+=1
V = V1 + V2 + V3
print(f’Putting all values, volume V = {V} {u}^3′)

if (n+1)%2 == 0:
print(‘Prismoidal formular is not applicable for even number of sections’)

Leave a Comment

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By : XYZScripts.com