Answer To: Untitled document import math import sys from sim_config import sim_config from sim_results import...
Shashank answered on Jun 01 2021
basic_params.txt
Load location, width
0, 1
Load weight
100
Load type
Constant
Load timing
56
Load custom data
1,10, 25,50, 75,55, 4,100, 5,150
basic_soil.txt
Soil width, depth
1, 4
Soil keys
C,Clay, B,Bedrock, V,Void
C
C
V
B
main.py
import math
import sys
from sim_config import sim_config
from sim_results import sim_results
from sim_loader import *
from sim_particle import *
from sim_particles2d import *
def summarise_sim_data(config):
''' print the summary of the simulation parameter data
input: config variables load_location, load_width, load_weight,
load_type, load_timing, load_custom_data
output: list of strings
'''
strs_out = []
return strs_out
def summarise_soil_data(config):
''' print the summary of the soil data
input: config variables soil_width, soil_depth, soil_key_desc,'''
strs_out = []
return strs_out
def find_leak_points_r(start, fluid_body_particles):
# DO NOT MODIFY
''' Given '''
leak_points = []
p = start
if p == None:
return []
if p.processed:
return []
if p.type == 'B':
return []
if p.type == 'V':
p.processed = True
return [p]
p.processed = True
fluid_body_particles.append(p)
for i in range(4):
if p.n[i] != None:
leak_points += find_leak_points_r(p.n[i], fluid_body_particles)
return leak_points
def find_leak_points(start):
# DO NOT MODIFY
''' Given '''
fluid_body_particles = []
leak_points = find_leak_points_r(start, fluid_body_particles)
return (leak_points, fluid_body_particles)
def calculate_applicable_load(config, particles2d, current_load):
'''
Calculate how much of the load will be applied based on whether
there are bedrock columns. When there are no bedrock columns, there is no
change to the actual load. When there are all bedrock columns, the actual
load is zero. For all other cases, the actual load is load - all load
bearing bedrock columns
Formula for your idea:
load = load * ( #non-bedrock-cols / width + #bedrock-cols / width )
input:
current_load, the number of kN for the given time instance
(externally calculated based on non constant load type)
config data with Load location and dimensions.
particle2d - 2D grid of particles at present
output: the kN (single float) applied to the body of water
'''
pass
def calculate_current_load(config, hours_passed):
'''
caclulate the amount of weight to be applied at hours_passed time.
- Where the load type is constant. config.load_weight is returned.
- Where the load type is linear, a calculation is needed based on
hours_passed and load_timing. If the hours_passed exceeds load_timing,
then the full load_weight is used'''
def simulation_start(config, results):
''' Partially given
run the simulation
input: using the already loaded
- config variables
- particles2d, leak_points, fluid_body_particles
output:
- fill in the results object with information abotu the
simulation and the outcome
- list of strings for any output to be printed
'''
strs_out = []
particles2d = create_2d_particle_array(config.soil_width,
config.soil_depth, config.soil_data)
print(particles2d)
start_particles = []
start_loc = [0, config.load_location ]
for j in range(config.load_width):
start_particles.append( particles2d[start_loc[0]][start_loc[1] + j]
)
print(start_particles)
reset_particles2d(particles2d)
visualise_particles2d(particles2d)
load_connected_to_body = False
found_water_body = False
leak_points_ever_found = False
leak_points = []
fluid_body_particles = []
for start in start_particles:
leak_points, fluid_body_particles = find_leak_points(start)
# check that the load is adjacent to a body of water (only one
needed)
load_connected_to_body = False
for load_index in range(config.load_width):
if particles2d[0][config.load_location+load_index].type == 'C':
load_connected_to_body = True
break
if load_connected_to_body:
found_water_body = True
if len(leak_points) != 0:
leak_points_ever_found = True
break
# CHECK if the simulation can be run
# - is there a water body?
# - are there leak points?
# - is the load connected to the body?
total_water_removed = 0
hours_passed = 0
heights = []
# REPEAT until consolidated# update the number of hours passed
# calculate the current load
# calculate the applicable/final load
# add the final load for this timestep to results
# calculate the water moved
# calculate the amount of water to remove from each particle
# remove water from all fluid_body_particles only if they continue
to hold water
# Note: you must modify the .water attribute to reflect the water
remaining in this particle
# update the total amount of water removed so far
# calculate the heights of all columns for this hour
# add the height information for this timestep to results
#visualise_particles2d_water(particles2d)
# test if consolidated
# set the results for consolidation information
visualise_particles2d(particles2d)
print_heights(config.soil_depth, heights, 4,4)
# return
return strs_out
simp_parse.py
#only 2 function updated sorry am not well so i cant complete it
def parse_sim_parameters():
f= open("basic_params.txt",'r')
js=f.readlines()
load_location = js[1].split(',')[0]
load_width = js[1].split(',')[1]
load_weight = js[3]
load_type=js[5]
load_timing=js[7]
load_custom_data=js[9]
f.close()
if len(js)>10:
return "duplicate entry"
return True
def parse_soil_data():
f=open("basic_soil.txt","r")
js=f.readlines()
soil_width =...