__MACOSX/._Assignment (empty scaffold)
Assignment (empty scaffold)/simulate.py
# Name:
# SID:
# unikey:
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:
XXXXXXXXXXsummarise_sim_data
XXXXXXXXXXsummarise_soil_data
XXXXXXXXXXcheck_simulation_data
XXXXXXXXXXcalculate_applicable_load
XXXXXXXXXXcalculate_cu
ent_load
XXXXXXXXXXsimulation_start
No modification is needed for functions, or sections:
XXXXXXXXXXfind_leak_points
XXXXXXXXXXfind_leak_points_
XXXXXXXXXXsetup_config
XXXXXXXXXXsimulate_main
XXXXXXXXXXmain
XXXXXXXXXXif __name__ == "__main__":
'''
def summarise_sim_data(config):
''' print the summary of the simulation parameter data
XXXXXXXXXXinput: config variables load_location, load_width, load_weight, load_type, load_timing, load_custom_data
XXXXXXXXXXoutput: list of strings
'''
strs_out = []
i=0
while True:
XXXXXXXXXXstrs_out.append[]
return strs_out
def summarise_soil_data(config):
''' print the summary of the soil data
XXXXXXXXXXinput: config variables soil_width, soil_depth, soil_key_desc, soil_data
XXXXXXXXXXoutput: list of strings
'''
strs_out = []
return strs_out
def check_simulation_data(config):
'''
XXXXXXXXXXcheck the simulation parameters and soil data are compatible
XXXXXXXXXXload location must be within the columns of soil defined
XXXXXXXXXXload width cannot overhang last soil column
XXXXXXXXXXinput: config variables for simulation parameters and soil
XXXXXXXXXXoutput: 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:
XXXXXXXXXXreturn []
if p.processed:
XXXXXXXXXXreturn []
if p.type == 'B':
XXXXXXXXXXreturn []
if p.type == 'V':
XXXXXXXXXXp.processed = True
XXXXXXXXXXreturn [p]
p.processed = True
fluid_body_particles.append(p)
for i in range(4):
XXXXXXXXXXif p.n[i] != None:
XXXXXXXXXXleak_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, cu
ent_load):
'''
XXXXXXXXXXCalculate 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
XXXXXXXXXXFormula for your idea:
XXXXXXXXXXload = load * ( #non-bedrock-cols / width + #bedrock-cols / width )
XXXXXXXXXXinput:
XXXXXXXXXXcu
ent_load, the number of kN for the given time instance (externally calculated based on non constant load type)
XXXXXXXXXXconfig data with Load location and dimensions.
XXXXXXXXXXparticle2d - 2D grid of particles at present
XXXXXXXXXXoutput: the kN (single float) applied to the body of wate
'''
pass
def calculate_cu
ent_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:
XXXXXXXXXXconfig information config.load_weight, config.load_type, config.load_timing, config.load_custom_data
XXXXXXXXXXhours_passed - representing the cu
ent time in the simulation. must be a positive intege
output:
XXXXXXXXXXon success, the load applied (single float) is returned (without considering the soil information)
XXXXXXXXXXon failure, -1.0 is returned
'''
pass
def simulation_start(config, results):
''' Partially given
XXXXXXXXXXrun the simulation
XXXXXXXXXXinput: using the already loaded
XXXXXXXXXXconfig variables
XXXXXXXXXXparticles2d, leak_points, fluid_body_particles
XXXXXXXXXXoutput:
XXXXXXXXXXfill in the results object with information abotu the simulation and the outcome
XXXXXXXXXXlist of strings for any output to be printed
'''
strs_out = []
particles2d = create_2d_particle_a
ay(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):
XXXXXXXXXXstart_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:
XXXXXXXXXXleak_points, fluid_body_particles = find_leak_points(start)
# check that the load is adjacent to a body of water (only one needed)
XXXXXXXXXXload_connected_to_body = False
XXXXXXXXXXfor load_index in range(config.load_width):
XXXXXXXXXXif particles2d[0][config.load_location+load_index].type == 'C':
XXXXXXXXXXload_connected_to_body = True
eak
XXXXXXXXXXif load_connected_to_body:
XXXXXXXXXXfound_water_body = True
XXXXXXXXXXif len(leak_points) != 0:
XXXXXXXXXXleak_points_ever_found = True
eak
# 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 cu
ent 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 wate
# Note: you must modify the .water attribute to reflect the water remaining in this particle
# update the total amount of water removed so fa
# calculate the heights of all columns for this hou
# 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
XXXXXXXXXXinput: three file names
XXXXXXXXXXoutput: