Recent Question/Assignment

python coding with instructions
needs to be completed as soon as possible
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
? 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 simulation parameters file path soil data file path output file path
? 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 incompressible fluid.
? the entire soil mass is considered as a body of fluid where the pressure is even throughout.
? water reaching a void in the soil will cause it to leak out (sink). Void are explicitly defined in every simulation.
? pressure acting on the soil will cause the equivalent water mass to leave the exit points of the soil.
? There should always be a leak point, place for water to be displaced.
? If soil has no leak points, the pressure will continue to rise and no water movement is possible until there is a break in those soil barriers such as bedrock. This building of pressure and breaking is not considered in the model or the simulation.
? water can move up into a void, against gravity. This is to reduce complexity of the assignment.
We model the rate at which water moves out of soil:
? it is constant (for simplicity)
? Water volume moved per 1kN per hour
CLAY_COMPRESSIBILITY_RATE = 0.001 SHALE_COMPRESSIBILITY_RATE = 0.0005
? More water cannot be removed from a particle:
¦ if there is 0.04 water in a particle of clay, and 100kN is applied over one hour. Water moved is 100,000 x 0.001 = 0.1. 0.1 0.04, and we expect the particle of clay will have 0.00 units of water.
File formats
? Applicable to parse_sim_parameters and parse_soil_data
The file format contains pairs of Labels and Values, as well as Comments.
# comments
label1 value(s) for label1
label2 value(s) for label2
label3 value(s) for label3
# comments ...
Comments
A comment is identified when the # symbol first appears in the line after any whitespace.
# a valid comment
# also a valid comment
### valid comment
-- # INVALID comment
NOT # a # comment
Comments can appear after or before a label/value(s) pair.
# comment1
# more of comment1
label1 value(s) for label1
# comment2
# comment2
label2 value(s) for label2 # comment3
label3 value(s) for label3
# comment4
# more comments...
Labels and Values
A label is the text used to identify the parameter. e.g. Load weight. A value is information for that label. e.g. 1000
Load weight
1000
Once a label has been identified, the value(s) are always in next lines that follow. A blank line is used to separate definitions of labels and their values.
Labels can appear at any point within the file. There is no specific ordering.
Label matching and identification
Each file format has a well define set of labels.
All label matching is case insensitive.
Duplicate labels
Labels appearing more than once are permitted, however, only the last value is used.
For example:
Load weight 1000
Load weight
800
During the reading of the file, the program should print a message to the console stderr
Warning label Load weight defined twice. Using last value of 800
Simulation Parameters file format
? Applicable to parse_sim_parameters
Load location, width
value1 , value2
Load weight
value
Load type
value
Load timing
value
Load custom data
time1, load1 , time2, load2 , time3, load3 , ...
Format details
Load location, width
? 2 integers, representing columns starting and how many columns wide
? comma separated
? must each be positive integers from 0 to 100
Load weight
? 1 integer representing kilonewtons of weight
? must be a positive integer between 0 and 1,000,000
Load type
? 1 string - Constant or Linear or Custom ? Optional, default is Constant.
Load timing
? 1 integer representing the number of hours the load will apply for Linear
? not used for Constant or Custom Load types
? must be a positive integer between 0 and 1,000,000
Load custom data
? pairs of integer values representing the weight of the load at the given time
? Comma separated in the order hour , load weight ? Used when Custom Load type is defined. Otherwise ignored.
? Must have an even number of values (a whole number of pairs)
? defines zero and positive integers
? time values defined incrementally
? no duplicate time values
Example file
Load location, width
0, 1
Load weight
100
Load type
Linear
Load timing
100
Load location, width
1, 3
Load weight
3860
Load type
Linear
Load timing
56
Load custom data
1,10, 25,50, 75,55, 4,100, 5,150
Soil data file format
Soil width, depth
value1 , value2
Soil keys
key1 , description1 , key2 , description2 , ...
Soil data
key ... key
key ... key ... ...
... key ...
... ...
key ... key
key ... key
The keys describe a symbol to use for a particular soil category. The width of the symbol is 1 character.
The key description is a string of any size
Example
Soil width, depth
30, 20
Soil keys
C,Clay, H,Shale, B,Bedrock, V,Void
Soil data
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCVCCCC
HHHHHHHHHCCCCCHHHHHHHHHHHVHHHH
HHHHHHHHHCCCCCHHHHHHHHHHHVHHHH
HHHHHHHHHCCCCCHHHHHHHHHHHHHHHH
HHHHHHHHHHHHBBBBBBBBHCCCCHHHHH
HHCCCCCCHHHHHHHHHHHHHCCCCHHHHH
HHHHHHHHHHHHHHCCCCHHHHHHHHHHHH
HHCCCCCCCCCCCCCCCCCCCHHHHHHHHH
HHHHHHVVHHHCCCCCCCCCCCCCCCCHHH
HHHHHHHHHHHHHHHVVVHHHHHHHHVHHH
HHCCCCCCCCCCCCCCCCCCCHHHHHVHHH
HHHHHHHHHHHCCCCCCCCCCCCCCCCHHH
HHHHHCCCCCCCHHHHHHHCCCCCCCCHHH
CCCCCCCCCHHHHHCCCCHHHHHCCCCCCH
HHHHHCCCCCCCHHHHHHHCCCCCCCCHHH
CCCCCCCCCHHHHHCCCCHHHHHCCCCCCC
HHCCCVVVCCCCCCCCCCCCCHHHHHHHHH
CCCCCCCCCHHHHHCCCCHHHHHCCCCCCC
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
A special particle is the void. Void is represented by a V. It represents a space which will allows water to move to (lower pressure).
Format details
? Applicable to parse_soil_data
Soil width, depth
? 2 integers representing the number of columns and the number of layers (rows) of soil data to follow
? comma separated
? must each be positive integers from 0 to 10,000
Soil keys
? pairs of character,string for representing a soil particle type by a single character
? comma separated
? must have an even number of values
? must define single character followed by a string
? no duplicate values (key or description)
Soil data
? string(s)
? must have the appropriate number of columns and rows previously defined
? must be characters defined in the Soil keys
? all rows are equal length
? all columns are equal length
Simulation parameters
? Applicable to check_simulation_data, calculate_applicable_load, calculate_current_load, simulation_start
Load location, width
Where and how wide the load is placed.
? The location is the column integer, where 0 is the left most column.
? The width is the side of the load For example:
Load location = 1 Load width = 1
In this document, we will represent load with L to illustrate the load location and width.
However, the symbol L will not be present in the file formats, or simulation.
L
BCCV
BCCB
BCCB
BBBB
Load location = 2 Load width = 1
L
BCCV
BCCB
BCCB
BBBB
Most of the problems will focus on a single load point, where Load width=1
Distributed load
The weight of the load implies a force. The width of the load implies a distribution of force over area, pressure.
For example: Load location = 1 Load width = 3
LLL
BCCCV
BCCCB
BCCCB
BBBBB
When simulating, the load will only affect the body of water which are under load
For example: Load location = 0 Load width = 3
LLL
BCCCV
BCCCB
BCCCB
BBBBB
Load on Column 0 has no effect in this model Load on Column 1 has effect in this model
Load on Column 2 has effect in this model
For simplification, you may assume that where a column is not all bedrock, the load will affect it.
For example: Load location = 1 Load width = 3
LLL
BCCCV
BBCBB
BCCCB
BBBBB
All columns affected
Hint: You should focus on load width of 1 to simulate first before moving to distributed loads
More examples for applicable load
If the load is placed above a bedrock column, the applicable load is zero:
# no load
L
BCV
BCV
BCV
If the load is placed above a non-bedrock column, the applicable load is the load:
# full load
L
BCV
BCV
BCV
So this leaves the case where there is a load across both bedrock and non-bedrock columns:
# half load
LL
BCV
BCV
BCV
We need you to implement the function to determine for a given load width, and a soil configuration, what is the applicable load on the soil (body of water). It is a proportion.
# please calculate the new load.
# load width is 6
# there are 2 bedrock columns
# 4 columns with soil
# applicable_load = load * ( 4 / 6 + 2 / 6 )
# bedrock columns have zero load
# applicable_load = load * ( 4 / 6 )
LLLLLL
BCVCBCC
BCVVBCC
BCVCBCV
Load type and timing
Constant load is fixed. Every hour will impose a force of Load weight at the load point(s).
Linear. At time zero, there is zero load. At time Load timing, there will be 100% of the Load weight at the load point(s). For example, if Load weight=100 and Load timing = 10. It would take 10 hours for the load to reach 100kN.
t=0, load=0 t=1, load=10 t=2, load=20 t=3, load=30 t=4, load=40 t=5, load=50 t=6, load=60 t=7, load=70 t=8, load=80 t=9, load=90 t=10, load=100
This affects the rate of consolidation.
Custom load are user specified times and load weights to be used in the simulation. For example, the user may specify:
t=0, load=100 t=1, load=120 t=2, load=180 t=3, load=200 t=4, load=150 t=5, load=110
The user may alternatively specify sparse time sequences:
t=0, load=0 t=1, load=500 t=6, load=1300 t=14, load=2000 t=15, load=1500 t=23, load=400
For the simulation, you may assume that the times not specified will use the same value as the previous time.
t=0, load=0 t=1, load=500 t=2-5, load=500 # this is implicit t=6, load=1300
t=7-13, load=1300 # this is implicit t=14, load=2000 t=15, load=1500
t=16-22, load=1300 # this is implicit t=23, load=400
t=24-end of simulation, 400 # this is implicit
The only error checking you need for custom data is where there are missing pairs of time/load values. Otherwise, you may assume that the custom data is correct.
A group of connected soil particles as a body of water
Particles of clay that are adjacent will share the same pressure and push of water throughout. Therefore, the simulation requires knowing which particles constitute a group, or a body of water.
Example: 1 body of water. All clay particles C are adjacent to all other clay C particles. A pressure acting on any clay particle will be transmissible throughout the body of water.
BCCCCCCCCCV
BCCCBCCBCBB
BCCCBCCBCBB
BBBBBBBBBBB
Example: 3 bodies of water. There are bedrock particles creating a barrier between the clay particles.
BCCCBCCCCCB
BCCCBCCBBBB
BCCCBCCBCBB
BBBBBBBBBBB
Important:
? You do not have to calculate a body of water
? You do not have to consider the case where a load is applied to 2 or more bodies of water.
This is calculated for you using the function
leak_points, fluid_body_particles = find_leak_points(start_particle)
Every hour of the simulation the body of water will lose an amount of water related to the load applied.
The formula for calculating the water moved in 1 hour relates to how much load is applied at the time, how much is applicable to the soil (exclude bedrock), and the rate of water movement out of soil particles (constant). water_moved = CLAY_COMPRESSIBILITY_RATE x load_applicable
Consistency checking between parameters and soil
Having both parameters and soil data, we can test whether these conditions are satisfied before proceeding.
Load over soil
Load geometry must be positioned entirely over soil (Load geometry cannot be overhanging the edge)
Example of not permitted:
L
VCC
BCC
BCC
Load not overhanging
Load must be placed over compressible soil particles (e.g. Clay) Example of not permitted:
LLL
VCC
BCC
BCC
Simulation examples
Example 1
Consider a column of clay soil with a force applied vertically.
? Let the load L be 100kN
? The water volume and capacity for clay is 0.4 in this example.
? The rate of water movement from clay is 0.001 per hour for every 1kN of force.
? The sides of the column are empty, meaning water can leak there infinitely
? There are 4 leak points in this example Void (V) particles
Initial conditions can be represented as so:
L
VCV
VCV
BBB
Initial conditions, height of middle column = 3
0 1 0
0 1 0
1 1 1
Initial conditions, as numeric values of water capacity:
i 0.4 i i 0.4 i 0 0 0
where i is infinite
Initial conditions, as numeric values of water volume:
0 0.4 0
0 0.4 0
0 0 0
After 1 hour
There is 0.1 of water removed per hour on the entire soil mass. The soil pressure is even throughout, and 0.1 water move to the 4 leak points. Water leaked = 0.1 / 4 = 0.025 capacity (always the same)
i 0.4 i i 0.4 i 0 0 0
water volume
0.025 0.35 0.025
0.025 0.35 0.025
0 0 0
0.1 water units removed from the soil in this hour 0.1 total water units removed since t=0
After 2 hours water volume
0.050 0.3 0.050
0.050 0.3 0.050
0 0 0
0.1 water units removed from the soil in this hour 0.2 total water units removed since t=0
After 3 hours water volume
0.075 0.25 0.075
0.075 0.25 0.075
0 0 0
0.1 water units removed from the soil in this hour 0.3 total water units removed since t=0
After 4 hours water volume
0.100 0.20 0.100
0.100 0.20 0.100
0 0 0
0.1 water units removed from the soil in this hour 0.4 total water units removed since t=0
After 5 hours water volume
0.125 0.15 0.125
0.125 0.15 0.125
0 0 0
0.1 water units removed from the soil in this hour 0.5 total water units removed since t=0
After 6 hours water volume
0.150 0.10 0.150
0.150 0.10 0.150
0 0 0
0.1 water units removed from the soil in this hour 0.6 total water units removed since t=0
After 7 hours water volume
0.175 0.05 0.175
0.175 0.05 0.175
0 0 0
0.1 water units removed from the soil in this hour 0.7 total water units removed since t=0
After 8 hours water volume
0.200 0.00 0.200
0.200 0.00 0.200
0 0 0
0.1 water units removed from the soil in this hour 0.8 total water units removed since t=0 Final result height of middle column = 2.2
0 0.6 0
0 0.6 0
1 1 1
0.8 units of water has been removed from the soil.
Example 2
So long as there is a lower force area, water can be pushed out.
Consider two columns of clay soil surrounded by bedrock with a vertical force applied on the left column only.
? Let the load L be 100kN
? The water volume and capacity for clay is 0.4 in this example.
? The rate of water movement from clay is 0.001 per hour for every 1kN of force.
? There is one leak point in this example Void (V) particle. water flows toward this point.
Initial conditions can be represented as so:
L
BCBCV
BCBCB
BCCCB
BBBBB
Initial conditions 5 columns:
? height of column 1 = 4
? height of column 2 = 4
? height of column 3 = 4
? height of column 4 = 4
? height of column 5 = 3
Heights:
4 4 4 4 3
1 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Initial conditions, as numeric values of water capacity:
0 0.4 0 0.4 i
0 0.4 0 0.4 0
0 0.4 0.4 0.4 0
0 0 0 0 0
Initial conditions, as numeric values of water volume:
0 0.4 0 0.4 0
0 0.4 0 0.4 0
0 0.4 0.4 0.4 0
0 0 0 0 0
After 1 hour capacity (always the same)
i
0 0.4 0 0.4 0
0 0.4 0 0.4 0
0 0.4 0.4 0.4 0
0 0 0 0 0
Water volume decreases by 0.1 from all particles sharing this force. 7 particles: 0.1 / 7 =
0.014
0 0.386 0 0.386 0.1
0 0.386 0 0.386 0
0 0.386 0.386 0.386 0
0 0 0 0 0
0.1 water units removed from the soil in this hour 0.1 total water units removed since t=0
After 2 hours water volume
0 0.371 0 0.371 0.2
0 0.371 0 0.371 0
0 0.371 0.371 0.371 0
0 0 0 0 0
0.1 water units removed from the soil in this hour 0.2 total water units removed since t=0
After 3 hours water volume
0 0.357 0 0.357 0.3
0 0.357 0 0.357 0
0 0.357 0.357 0.357 0
0 0 0 0 0
0.1 water units removed from the soil in this hour 0.3 total water units removed since t=0
...
After 28 hours water volume
0 0 0 0 2.8
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0.1 water units removed from the soil in this hour 2.8 total water units removed since t=0
Final result height of column 2 = 2.8
0.6 0.6
0.6 1
height of column 3 = 3.6 (cavity collapses)
1
1
0.6 1
height of column 4 = 2.8
0.6 0.6
0.6
1
2.8 units of water has been removed from the soil.
Example 3
This example will demonstrate the load linearly increasing to the maximum weight.
Consider a column of clay soil with a force applied vertically.
? Let the load L be 2450kN
? Let the load timing be 10 hours
? The water volume and capacity for clay is 0.4 in this example.
? The rate of water movement from clay is 0.001 per hour for every 1kN of force.
? There are 3 leak points in this example Void (V) particles
Initial conditions can be represented as so:
L
BCCCCV
BCCCCV
BCCCCV
BBBBBB
Initial conditions t=0 5 columns:
? height of column 1 = 4
? height of column 2 = 4
? height of column 3 = 4
? height of column 4 = 4
? height of column 5 = 4
? height of column 6 = 1
Heights:
4 4 4 4 4 1
1 1 1 1 1 0
1 1 1 1 1 0
1 1 1 1 1 0
1 1 1 1 1 1
Initial conditions, as numeric values of water capacity:
0 0.4 0.4 0.4 0.4 i
0 0.4 0.4 0.4 0.4 i
0 0.4 0.4 0.4 0.4 i
0 0 0 0 0 0
Initial conditions, as numeric values of water volume:
0 0.4 0.4 0.4 0.4 0
0 0.4 0.4 0.4 0.4 0
0 0.4 0.4 0.4 0.4 0
0 0 0 0 0 0
After 1 hour t=1 capacity (always the same)
0 0.4 0.4 0.4 0.4 i
0 0.4 0.4 0.4 0.4 i
0 0.4 0.4 0.4 0.4 i
0 0 0 0 0 0
Force applied at this time is: (1/10) * 2450 = 245
Based on the formula: water_moved = CLAY_COMPRESSIBILITY_RATE x load_applicable
water_moved = ( 0.001 * 245 ) = 0.245
Water volume decreases by 0.245 from all particles sharing this force.
12 particles: 0.245 / 12 = 0.020416667 loss each
0 0.380 0.380 0.380 0.380 0.0817
0 0.380 0.380 0.380 0.380 0.0817
0 0.380 0.380 0.380 0.380 0.0817
0 0 0 0 0 0
0.245 water units removed from the soil in this hour 0.245 total water units removed since t=0
After 2 hours
Force applied at this time is: (2/10) * 2450 = 490
water_moved = ( 0.1 * 490 ) / 100 = 0.49
Water volume decreases by 0.490 from all particles sharing this force.
12 particles: 0.490 / 12 = 0.040833333 loss each
0 0.339 0.339 0.339 0.339 0.245
0 0.339 0.339 0.339 0.339 0.245
0 0.339 0.339 0.339 0.339 0.245
0 0 0 0 0 0
0.490 water units removed from the soil in this hour 0.735 total water units removed since t=0
After 3 hours
Force applied at this time is: (3/10) * 2450 = 735
water_moved = ( 0.001 * 735 ) = 0.735
Water volume decreases by 0.735 from all particles sharing this force.
12 particles: 0.735 / 12 = 0.06125 loss each
0 0.278 0.278 0.278 0.278 0.49
0 0.278 0.278 0.278 0.278 0.49
0 0.278 0.278 0.278 0.278 0.49
0 0 0 0 0 0
0.735 water units removed from the soil in this hour 1.47 total water units removed since t=0
After 4 hours
Force applied at this time is: (4/10) * 2450 = 980
water_moved = ( 0.001 * 980 ) = 0.98
Water volume decreases by 0.98 from all particles sharing this force.
12 particles: 0.98 / 12 = 0.081666667 loss each
0 0.196 0.196 0.196 0.196 0.816
0 0.196 0.196 0.196 0.196 0.816
0 0.196 0.196 0.196 0.196 0.816
0 0 0 0 0 0
0.98 water units removed from the soil in this hour 2.45 total water units removed since t=0
After 5 hours
Force applied at this time is: (5/10) * 2450 = 1225
water_moved = ( 0.001 * 1225 ) = 1.225
Water volume decreases by 1.225 from all particles sharing this force.
12 particles: 1.225 / 12 = 0.102083333 loss each
0 0.094 0.094 0.094 0.094 0.816
0 0.094 0.094 0.094 0.094 0.816
0 0.094 0.094 0.094 0.094 0.816
0 0 0 0 0 0
1.225 water units removed from the soil in this hour 3.675 total water units removed since t=0
After 6 hours
Force applied at this time is: (6/10) * 2450 = 1470
water_moved = ( 0.001 * 1470 ) = 1.47
Water volume decreases by 1.47 from all particles sharing this force.
12 particles: 1.47 / 12 = 0.1225 loss each
0 0.000 0.000 0.000 0.000 0.816
0 0.000 0.000 0.000 0.000 0.816
0 0.000 0.00 0.000 0.000 0.816
0 0 0 0 0 0
1.125 water units removed from the soil in this hour (remainder) 4.8 total water units removed since t=0
Final result heights:
Column 1 2 3 4 5 6
--------------------------------
4, 2.8, 2.8, 2.8, 2.8, 1
4.8 units of water has been removed from the soil in 6 hours.
Example 4
This example will demonstrate the custom load.
Consider the scenario where sand columns are used to consolidate faster:
? Load custom data is: 0,200, 15,550, 25,977, 99,1489
? The water volume and capacity for clay is 0.4 in this example.
? The rate of water movement from clay is 0.001 per hour for every 1kN of force.
? There are 16 leak points in this example Void (V) particles
? There are 39 soil particles in this example Clay (C)
? There is only one body of water
? Sand columns are emulated as void and are positioned between clay columns.
Initial conditions can be represented as so:
LLLL
BCVCCVCCVCVCB
BCVCCVCCVCVCB
BCVCCVCCVCVCB
BCVCCVCCVCVCB
BCCCCCCCCCCCB
BBBBBBBBBBBBB
Initial conditions t=0 heights:
Column 1 2 3 4 5 6 7 8 9 10 11 12 13
-------------------------------------------6, 6, 2, 6, 6, 2, 6, 6, 2, 6, 2, 6, 6
Hours 1-14
Load is 200 for all these hours based on the custom data t=0, L=200
t=1. heights: [6, 5.974, 1.995, 5.974, 5.974, 1.995, 5.974, 5.974, 1.995,
5.974, 1.995, 5.974, 6] t=2. heights: [6, 5.949, 1.99, 5.949, 5.949, 1.99, 5.949, 5.949, 1.99, 5.949,
1.99, 5.949, 6] t=3. heights: [6, 5.923, 1.985, 5.923, 5.923, 1.985, 5.923, 5.923, 1.985,
5.923, 1.985, 5.923, 6] t=4. heights: [6, 5.897, 1.979, 5.897, 5.897, 1.979, 5.897, 5.897, 1.979,
5.897, 1.979, 5.897, 6] t=5. heights: [6, 5.872, 1.974, 5.872, 5.872, 1.974, 5.872, 5.872, 1.974,
5.872, 1.974, 5.872, 6] t=6. heights: [6, 5.846, 1.969, 5.846, 5.846, 1.969, 5.846, 5.846, 1.969,
5.846, 1.969, 5.846, 6] t=7. heights: [6, 5.821, 1.964, 5.821, 5.821, 1.964, 5.821, 5.821, 1.964,
5.821, 1.964, 5.821, 6] t=8. heights: [6, 5.795, 1.959, 5.795, 5.795, 1.959, 5.795, 5.795, 1.959,
5.795, 1.959, 5.795, 6] t=9. heights: [6, 5.769, 1.954, 5.769, 5.769, 1.954, 5.769, 5.769, 1.954,
5.769, 1.954, 5.769, 6] t=10. heights: [6, 5.744, 1.949, 5.744, 5.744, 1.949, 5.744, 5.744, 1.949,
5.744, 1.949, 5.744, 6] t=11. heights: [6, 5.718, 1.944, 5.718, 5.718, 1.944, 5.718, 5.718, 1.944,
5.718, 1.944, 5.718, 6] t=12. heights: [6, 5.692, 1.938, 5.692, 5.692, 1.938, 5.692, 5.692, 1.938,
5.692, 1.938, 5.692, 6] t=13. heights: [6, 5.667, 1.933, 5.667, 5.667, 1.933, 5.667, 5.667, 1.933,
5.667, 1.933, 5.667, 6] t=14. heights: [6, 5.641, 1.928, 5.641, 5.641, 1.928, 5.641, 5.641, 1.928,
5.641, 1.928, 5.641, 6]
Hours 15-24
Load is 550 for all these hours based on custom data t=15, L=550
t=15. heights: [6, 5.615, 1.923, 5.615, 5.615, 1.923, 5.615, 5.615, 1.923,
5.615, 1.923, 5.615, 6]
t=16. heights: [6, 5.545, 1.909, 5.545, 5.545, 1.909, 5.545, 5.545, 1.909,
5.545, 1.909, 5.545, 6] t=17. heights: [6, 5.474, 1.895, 5.474, 5.474, 1.895, 5.474, 5.474, 1.895,
5.474, 1.895, 5.474, 6] t=18. heights: [6, 5.404, 1.881, 5.404, 5.404, 1.881, 5.404, 5.404, 1.881,
5.404, 1.881, 5.404, 6] t=19. heights: [6, 5.333, 1.867, 5.333, 5.333, 1.867, 5.333, 5.333, 1.867,
5.333, 1.867, 5.333, 6] t=20. heights: [6, 5.263, 1.853, 5.263, 5.263, 1.853, 5.263, 5.263, 1.853,
5.263, 1.853, 5.263, 6] t=21. heights: [6, 5.192, 1.838, 5.192, 5.192, 1.838, 5.192, 5.192, 1.838,
5.192, 1.838, 5.192, 6] t=22. heights: [6, 5.122, 1.824, 5.122, 5.122, 1.824, 5.122, 5.122, 1.824,
5.122, 1.824, 5.122, 6] t=23. heights: [6, 5.051, 1.81, 5.051, 5.051, 1.81, 5.051, 5.051, 1.81, 5.051,
1.81, 5.051, 6] t=24. heights: [6, 4.981, 1.796, 4.981, 4.981, 1.796, 4.981, 4.981, 1.796,
4.981, 1.796, 4.981, 6]
Hours 25-37
Load is 977 for all these hours based on custom data t=25, L=977
t=25. heights: [6, 4.91, 1.782, 4.91, 4.91, 1.782, 4.91, 4.91, 1.782, 4.91,
1.782, 4.91, 6] t=26. heights: [6, 4.785, 1.757, 4.785, 4.785, 1.757, 4.785, 4.785, 1.757,
4.785, 1.757, 4.785, 6] t=27. heights: [6, 4.66, 1.732, 4.66, 4.66, 1.732, 4.66, 4.66, 1.732, 4.66,
1.732, 4.66, 6] t=28. heights: [6, 4.534, 1.707, 4.534, 4.534, 1.707, 4.534, 4.534, 1.707,
4.534, 1.707, 4.534, 6] t=29. heights: [6, 4.409, 1.682, 4.409, 4.409, 1.682, 4.409, 4.409, 1.682,
4.409, 1.682, 4.409, 6] t=30. heights: [6, 4.284, 1.657, 4.284, 4.284, 1.657, 4.284, 4.284, 1.657,
4.284, 1.657, 4.284, 6] t=31. heights: [6, 4.159, 1.632, 4.159, 4.159, 1.632, 4.159, 4.159, 1.632,
4.159, 1.632, 4.159, 6] t=32. heights: [6, 4.033, 1.607, 4.033, 4.033, 1.607, 4.033, 4.033, 1.607,
4.033, 1.607, 4.033, 6]
t=33. heights: [6, 4.0, 1.6, 4.0, 4.0, 1.6, 4.0, 4.0, 1.6, 4.0, 1.6, 4.0, 6]
Final result
15.6 units of water has been removed from the soil in 33 hours.
Your tasks
Please see the following functions for you to complete. They describe the necessary input and output.
? [ ] Complete the code necessary to load and parse the simulation parameters file.
def parse_sim_parameters(file_obj, config):
input: open file object output:
set the config variables load_location, load_width, load_weight,
load_type, load_timing, load_custom_data
close the file_obj return True on success, otherwise False
? [ ] Complete the code necessary to load and parse the soil data file
def parse_soil_data(file_obj, config):
input: open file object output:
set the config variables soil_width, soil_depth, soil_key_desc,
soil_data close the file_obj return True on success, otherwise False
? [ ] Complete the code for the summarise_sim_data() and summarise_soil_data() functions
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

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

? See basic simulation scenario for the output string formats. ? [ ] Complete the code for the functions of class sim_results
def __init__(self):
set initial values of the simulation state
# suggested
# self.consolidation_time = 0
# self.total_water_removed = 0
# self.heights_data = [ [0] ] # multiple per time step
# self.load_data = [0] # one per time step pass
def get_consolidation_time(self):
return the number of hours that consolidation required
def get_total_water_removed(self):
return the amount of water removed after consolidation
def get_height_data(self, time):
return the list of heights for each column at the given time. The time value must be between 0 and consolidation_time
input: time (hours since start simulation) output:
on success, list of height values for the given time on failure, return an empty list

def get_load_data(self, time):
return the final load value applied to the water body at the given
time.
The final load value is after all calculations involving timing and bedrock columns.
The time value must be between 0 and consolidation_time
input: time (hours since start simulation) output:
on success, load value (single float) for the given time on failure, return -1.0
Expand (38 lines)
? [ ] Complete the code for the calculate_heights() function
def calculate_heights(particles2d): calculate the height of each column input: 2D grid of particles (list of lists) output: a list of heights for each column

? [ ] Complete the code for the get_bedrock_columns function
def get_bedrock_columns(particles2d):
returns a list of boolean values to represent whether the column is entirely bedrock input: 2D grid of particles (list of lists) output: a list of bool, where the list length is the number of columns
example:
BCCS
BCCS
BCCS
BBBB
[ True, False, False, False ]

? [ ] Complete the code for the check_simulation_data function
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 columninput: config variables for simulation parameters and soil output: on success, return True, otherwise return False
? [ ] Complete the code for the calculate_applicable_load function
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
? [ ] Complete the code for the calculate_current_load function
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 times 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
? [ ] Complete the partially completed code for the simulation_start() function. Refer to the scaffold code provided.
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

# 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
# test if consolidated
# set the results for consolidation information
Expand (39 lines)
Testing
Staff will run tests on your code. The functions will be called to evalute the output to your functions. You are to ensure the correct data is returned or set in memory as described by the function.
? Test loading the configuration file for simulation parameters
? Test loading the configuration file for soil data
? Test for checking the simulation data is consistent
? Test for summarising the simulation configuration
? Test for calculating the load for a given time
? Test for calculating the load applicable
? Test for calculating the heights of columns at any time of the simulation
? Test for setting the results information and returning the information correctly
Some testing files and output date are provided for you. Please refer to the tests directory in the workspace on Ed.
How do I begin?
It is always good to start with the simplest possible simulation to run. Small number of particles, very well defined input and outcome. Pick a simple scenario. Here is a suggested one.
Create a simple configuration
The configuration files: basic_params.in
Load location, width
0, 1
Load weight
100
Load type Constant
basic_soil.in
Soil width, depth
1, 4
Soil keys
C,Clay, B,Bedrock, V,Void
C
C
V
B
Expectations
Can you predict the expected outcome?
C becomes
C --- C
V --- C
B --- B
Height should be 0.6 + 0.6 + 0 + 1 = 2.2 Time taken?
? 1 clay has 0.4 water
? total water for 2 clay is thus 0.8 water
? CLAY_COMPRESSIBILITY_RATE = 0.001 hence it would take 8 hours
Code for the basic simulation scenario
No need to write code for:
? simulate.py
? summarise_sim_data()
Expected to return this list of strings
[ Load location, width: 0, 1,
Load weight: 100,
Load type: constant,
Load timing: -1,
Load custom data: [0, 0] ]
? summarise_soil_data()
Expected to return this list of strings
[ -Soil width, depth: 1, 4-,
-Soil keys and description:-,
- C - Clay-,
-Soil data:-,
-[C]-,
-[C]-,
-[V]-,
-[B]- ]
Easy implementation for the basic simulation scenario
? check_simulation_data() - always returns True
? calculate_applicable_load() - always returns current_load
? calculate_current_load() - always returns config.load_weight ? sim_loader.py
? parse_sim_parameters()
config.load_location = 0 config.load_width = 1 config.load_weight = 100 config.load_type = -Constant- return True
? parse_soil_data()
config.soil_width = 1
config.soil_depth = 4 config.soil_keys = [ C,Clay, B,Bedrock, , V,Void] config.soil_data = [ [C], [C], [V], [B] ] return True
? sim_particles2d.py
? get_bedrock_columns() - always returns [ False ]
? calculate_heights()
height = 0
height += (1 - particles2d[0][0].capacity) + particles2d[0][0].water height += (1 - particles2d[1][0].capacity) + particles2d[1][0].water # for particles2d[2][0], skip adding height of void particle # for particles2d[3][0], always add height 1 for bedrock particle height += 1 return [height]
? sim_results.py init() - use suggested variables get_consolidation_time() - returns self.consolidation_time get_total_water_removed() - returns self.total_water_removed get_height_data() - returns self.heights_data get_load_data() - returns self.load_data
Hardest part
? simulate.py
? simulation_start()
t = 0
epsilon_soil = 0.0001
# REPEAT until consolidated
# update the number of hours passed t = t + 1
# calculate the current load
# calculate the applicable/final load
# add the final load for this timestep to results Always 100 in basic results.load_data.append(100)
# calculate the water moved
Should be 0.1
# calculate the amount of water to remove from each particle
Should be 0.05
# 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 fluid_body_particles[0].water -= 0.05 fluid_body_particles[1].water -= 0.05
# update the total amount of water removed so far It is 0.05 + 0.05 = 0.1 results.total_water_removed += 0.1
# calculate the heights of all columns for this hour heights_t = calculate_heights()
# add the height information for this timestep to results results.heights_data.append(heights_t) visualise_particles2d_water(particles2d)
# test if consolidated to stop repetition check all water removed from fluid_body_particles i.e.
fluid_body_particles[0].water = epsilon_soil and fluid_body_particles[1].water
= epsilon_soil results.consolidation_time = t
Expand (41 lines)
Run the code:
python3 simulate.py tests/basic_params.in tests/basic_soil.in results.txt
Check your results
The results file should look like this:
sim_param: basic_params.in soil_data: basic_soil.in
Consolidation time: 8
Total water removed: 0.7999999999999999 t=0. load: [0, 100, 100, 100, 100, 100, 100, 100, 100] heights: [[0], [2.9],
[2.8], [2.7], [2.6], [2.5], [2.4000000000000004], [2.3], [2.2]] t=1. load: [0, 100, 100, 100, 100, 100, 100, 100, 100] heights: [[0], [2.9],
[2.8], [2.7], [2.6], [2.5], [2.4000000000000004], [2.3], [2.2]] t=2. load: [0, 100, 100, 100, 100, 100, 100, 100, 100] heights: [[0], [2.9],
[2.8], [2.7], [2.6], [2.5], [2.4000000000000004], [2.3], [2.2]] t=3. load: [0, 100, 100, 100, 100, 100, 100, 100, 100] heights: [[0], [2.9],
[2.8], [2.7], [2.6], [2.5], [2.4000000000000004], [2.3], [2.2]] t=4. load: [0, 100, 100, 100, 100, 100, 100, 100, 100] heights: [[0], [2.9],
[2.8], [2.7], [2.6], [2.5], [2.4000000000000004], [2.3], [2.2]]
t=5. load: [0, 100, 100, 100, 100, 100, 100, 100, 100] heights: [[0], [2.9],
[2.8], [2.7], [2.6], [2.5], [2.4000000000000004], [2.3], [2.2]] t=6. load: [0, 100, 100, 100, 100, 100, 100, 100, 100] heights: [[0], [2.9],
[2.8], [2.7], [2.6], [2.5], [2.4000000000000004], [2.3], [2.2]] t=7. load: [0, 100, 100, 100, 100, 100, 100, 100, 100] heights: [[0], [2.9],
[2.8], [2.7], [2.6], [2.5], [2.4000000000000004], [2.3], [2.2]]
What next?
Now you can pick which part to increase in complexity.
? How about checking the file format values for this basic simulation scenario are correct or rejected? (test your code!)
? How about changing the number of clay particles from 2 -- 3? but ideally how can you change it from 2 -- N particles!
? How about a different shape of soil? ? How about a different load location?
? How about changing from Constant to Linear Load Type? ? etc.
Take small steps. Test as you go using the previous as well as new scenarios. Use scenarios where you already know or can confirm the outcome!
Code Submission
Your code submission must be made via Ed in this lesson.
? To make a submission, you will need to press the -Mark- button.
? You may submit as many times as you wish without penalty.
? You are able to view previous submissions from the code submission section.
? Every submission you make includes the README.md and the python .py files
The following rules apply to your code submission:
? Only the file simulate.py will be started by the automarker ? Only the last submission will be graded.
? Only the final README.md file of the last submission will be graded by your tutor
? Submission after the due date will incur a late penalty as described in the unit of study outline.
? Your submission must be able to compile and run within the Ed environment provided.
After each submission, the marking system will automatically check your code against the public test cases.
The Python version is that which is presently being used on Ed system:
$ python3 --version
Python 3.9.2
Please ensure you carefully follow the assignment description. Your program output must exactly match the output shown in the examples.
Late is late!
The computer does not discriminate about what is late. There are two files for submission
? all python files .py
? README.md
They are both in your Ed workspace. Make sure these are the ones for your submission.
Changes to these files after the deadline will incur a penalty for both (not individually).
Marking criteria
This assignment is 20% of your final course grade.
The grade you will receive is based on the number of test cases passed as well as manual grading by your tutor.
We have provided you with some sample test cases but these do not test all the functionality described in the assignment. It is important that you thoroughly test your own code.
Automatic tests 15 / 20
These are marked by a computer.
? There are public test cases
? There are hidden test cases
? There are private test cases
Manual grading 5 / 20
The manual grading from your tutor will consider the style, layout and comments you provide in your code. Your tutor will not be debugging or running your code against any test cases.
? edit the README.md file to describe the parts you have completed and the general structure of your code. Maximum 1000 words. See scaffold file directory in Ed.
? Explain how each of these modules and their functions are used as part of the simulation:
¦ sim_config.py
¦ sim_loader.py
¦ sim_particle.py
¦ sim_particles2d.py
¦ sim_results.py
¦ simulate.py
? Justify the choice of testing tool and type of tests that you have conducted to verify your work. Additional Python files and logs that were created to run these tests must be included in your submission.
? in your python code files .py:
? Please ensure your code is comprehensible for the purposes of marking. We recommend that your code adheres to the PEP 8 style guide https://www.python.org/dev/peps/pep-0008/
? Please use comments or docstrings for sections of code to explain the sections purpose. e.g. the following block of code will -search for-, -calculate-, -get input for options- etc.