Untitled document 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 * '''...

2 answer below »
python coding assignment help needed as soon as possible


Untitled document 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 * ''' simulate.py Student is to complete the functions: summarise_sim_data summarise_soil_data check_simulation_data calculate_applicable_load calculate_current_load simulation_start No modification is needed for functions, or sections: find_leak_points find_leak_points_r setup_config simulate_main main if __name__ == "__main__": ''' 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, soil_data output: list of strings ''' strs_out = [] return strs_out def check_simulation_data(config): ''' check the simulation parameters and soil data are compatible - load location must be within the columns of soil defined - load width cannot overhang last soil column input: config variables for simulation parameters and soil output: on success, return True, otherwise return False ''' pass 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 - Where the load type is custom, the calculation follows the pairs of time,load values in config.load_custom_data. config.load_custom_data is assumed to be in time sorted order with no duplicates. The intermediate values of custom data use the last known time's load value. If the hours_passed is before all time/load pairs, then the load is zero. input: config information config.load_weight, config.load_type, config.load_timing, config.load_custom_data hours_passed - representing the current time in the simulation. must be a positive integer output: on success, the load applied (single float) is returned (without considering the soil information) on failure, -1.0 is returned ''' pass 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 def setup_config(sim_param_file, soil_data_file, output_file): # DO NOT MODIFY ''' Given input: three file names output: on success, return a sim_config object with all variables filled in using the functions parse_sim_parameters and parse_soil_data on any failure, raise an exception with appropriate message ''' config = sim_config() config.sim_param_file = sim_param_file config.soil_data_file = soil_data_file config.output_file = output_file parse_success = False try: f = open(config.sim_param_file, 'r') parse_success = parse_sim_parameters(f, config) except FileNotFoundError: raise Exception('sim params: could not find file: {}'.format(sim_param_file)) except OSError: raise Exception('sim params: error encountered when reading file: {}'.format(sim_param_file)) if not parse_success: raise Exception('sim params: parsing simulation parameters failed') else: print('OK parsed simulation parameters successfully') parse_success = False try: f = open(config.soil_data_file, 'r') parse_success = parse_soil_data(f, config) except FileNotFoundError: raise Exception('soil data: could not find file: {}'.format(config.soil_data_file)) except OSError: raise Exception('soil data: error encountered when reading file: {}'.format(config.soil_data_file)) if not parse_success: raise Exception('soil data: parsing soil data failed') else: print('OK parsed soil data successfully') sim_data_ok = check_simulation_data(config) if not sim_data_ok: raise Exception('simulation data incompatible') else: print('OK simulation data compatible') return config def simulate_main(argv): # DO NOT MODIFY ''' Given input: list of string as arguments to the program (do not use sys.argv, use argv) load data, run the simulation output: save the results in the output file on success, return sim_results object on failure return the Exception object: - for lacking command line arguments - for failing to setup configuration - for failing to run the simulation - for failing to write the output data ''' if len(argv) < 4:="" print("usage:="" python3="" simulate.py="">
") print("python3 simulate.py block01_config.txt clay1.txt block01_output.txt") raise Exception('error: not enough parameters') config = setup_config(argv[1], argv[2], argv[3]) for l in summarise_sim_data(config): print(l) for l in summarise_soil_data(config): print(l) results = sim_results() strs = simulation_start(config, results) for line in strs: print(line) try: f = open(config.output_file, 'w') f.write('sim_param: {}\n'.format(config.sim_param_file)) f.write('soil_data: {}\n'.format(config.soil_data_file)) for l in summarise_sim_data(config): f.write("{}\n".format(l)) for l in summarise_soil_data(config): f.write("{}\n".format(l)) f.write('Consolidation time: {}\n'.format(results.get_consolidation_time())) f.write('Total water removed: {}\n'.format(results.get_total_water_removed())) for t in range(results.get_consolidation_time()): load = results.get_load_data(t) heights = results.get_height_data(t) f.write("t={}. load: {} heights: {}\n".format(t, load, heights)) f.close() except: raise Exception('writing results: error encountered when writing file: {}', config.output_file) return results def main(argv): # DO NOT MODIFY print('--------------------') print('-START -------------') print('--------------------') simulate_main(argv) print('--------------------') print('-END ---------------') print('--------------------') # DO NOT MODIFY if __name__ == "__main__": # DO NOT MODIFY main(sys.argv) # DO NOT MODIFY Untitled document Background Consolidation is the gradual changes in volume of a partly or fully saturated soil when subject to a sustained load. The changes are mainly due to the removal of gases, fluids and organic matter from the soil. We simplify our model to consider this matter as water. A sample of soil shows the particles arranged with voids between them. Soil can be composed of many minerals, primary silica, but clay, sand, shale, rock. Some of these have more water content than others. Water is present within soil and we can assume water is an incompressible fluid, where any pressure applied will cause the water to move to a lower pressure. The water is effectively squeezed out of the soil very slowly. Soil consolidation has a huge impact on the planning and construction of buildings throughout history. The leaning tower of Pisa is a great example to showcase the importance of soil consolidation [https://www.geoengineer.org/education/web-class-projects/ce-179-geosystems-engineering -design/assignments/the-tilt-of-the-tower-of-pisa-why-and-how ]. https://www.youtube.com/watch?v=nK4oDD-4CeE The purpose of the simulation is to determine: ● how long consolidation will take for a given load and placement over a soil configuration https://www.geoengineer.org/education/web-class-projects/ce-179-geosystems-engineering-design/assignments/the-tilt-of-the-tower-of-pisa-why-and-how https://www.geoengineer.org/education/web-class-projects/ce-179-geosystems-engineering-design/assignments/the-tilt-of-the-tower-of-pisa-why-and-how https://www.youtube.com/watch?v=nK4oDD-4CeE ● how much water is displaced during consolidation ● what are the changes in height of the soil after consolidation Simulation Input and Output ● functionality for file input/output provided for you The simulation will require information about the nature of the soil, the load, and the parameters used to simulate. These are read from a file using the three command line arguments. $ simulate.py

● Your program will read in a file for the simulation parameters from argument 1 ● Your program will read in a file for the soil geometry and composition from argument 2 ● Your program will write to a file for the results of the simulation from argument 3 For example: $ simulate.py tests/params_example1.in tests/soil_example1.in sim_results_p1_s1.txt Modelling of the problem The modelling of soil consolidation in this assignment makes the following assumptions: ● soil particles have no air ● soil particles initially have a capacity to hold water and is considered full ○ for example, if clay can hold 40% water, then at the beginning of the simulation, the clay particle holds 40% water. ● water is an incompressible fluid ● water moving out of a particle will cause the particle to compress ● any amount of water removed from a particle cannot be reintroduced ● soil particle categorisation is limited to Clay and Shale and only relevant to the initial conditions ● bedrock is an incompressible particle and will always provide an equal and opposite reactive force ● The void particle is a simple characterisation of representing a lower pressure area and it is assume to have no volume or capacity. A sand column could be represented as a lower pressure region, but as a void it has no capacity. We model a particle of soil. ● soil consists of a mixture of solid matter (aggregate) and water. ● soil particle has a capacity to hold water. This is dictated by the soil type and the water capacity value [0,1] ● soil particle has pressure acting on it. ● Initially the soil particle is at a rest state, in equilibrium with its neighbours. ● adding force to the soil will cause change in pressure and result in a movement of water ● assume a particle is 1 unit wide and 1 unit deep (square) We model the movement of water. ● water is an

Answered 15 days AfterMay 17, 2021University of Sydney

Answer To: Untitled document import math import sys from sim_config import sim_config from sim_results import...

Shashank answered on Jun 01 2021
154 Votes
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,
lo
ad_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 =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here