ttemporal.jl - Granular.jl - Julia package for granular dynamics simulation
HTML git clone git://src.adamsgaard.dk/Granular.jl
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
ttemporal.jl (5690B)
---
1 export setTotalTime!
2 """
3 setTotalTime!(simulation::Simulation, t::Float64)
4
5 Sets the total simulation time of the `simulation` object to `t`, with parameter
6 value checks.
7 """
8 function setTotalTime!(simulation::Simulation, t::Float64)
9 if t <= 0.0
10 error("Total time should be a positive value (t = $t s)")
11 end
12 simulation.time_total = t
13 nothing
14 end
15
16 export setCurrentTime!
17 """
18 setCurrentTime!(simulation::Simulation, t::Float64)
19
20 Sets the current simulation time of the `simulation` object to `t`, with
21 parameter value checks.
22 """
23 function setCurrentTime!(simulation::Simulation, t::Float64)
24 if t <= 0.0
25 error("Current time should be a positive value (t = $t s)")
26 end
27 simulation.time = t
28 nothing
29 end
30
31 export incrementCurrentTime!
32 """
33 incrementCurrentTime!(simulation::Simulation, t::Float64)
34
35 Sets the current simulation time of the `simulation` object to `t`, with
36 parameter value checks.
37 """
38 function incrementCurrentTime!(simulation::Simulation, t::Float64)
39 if t <= 0.0
40 error("Current time increment should be a positive value (t = $t s)")
41 end
42 simulation.time += t
43 simulation.file_time_since_output_file += t
44 nothing
45 end
46
47 export setOutputFileInterval!
48 """
49 setOutputFileInterval!(simulation::Simulation, t::Float64)
50
51 Sets the simulation-time interval between output files are written to disk. If
52 this value is zero or negative, no output files will be written.
53 """
54 function setOutputFileInterval!(simulation::Simulation, t::Float64;
55 verbose=true)
56 if t <= 0.0 && verbose
57 @info "No output files will be written"
58 end
59 simulation.file_time_step = t
60 nothing
61 end
62
63 export disableOutputFiles!
64 "Disables the write of output files to disk during a simulation."
65 function disableOutputFiles!(simulation::Simulation)
66 simulation.file_time_step = 0.0
67 nothing
68 end
69
70 export checkTimeParameters
71 "Checks if simulation temporal parameters are of reasonable values."
72 function checkTimeParameters(simulation::Simulation; single_step::Bool=false)
73 if !single_step && (simulation.time_total <= 0.0 || simulation.time_total <=
74 simulation.time)
75 error("Total time should be positive and larger than current " *
76 "time.\n t_total = $(simulation.time_total) s, " *
77 "t = $(simulation.time) s")
78 end
79 if simulation.time_step <= 0.0
80 error("Time step should be positive (t = $(simulation.time_step))")
81 end
82 nothing
83 end
84
85 export findSmallestGrainMass
86 "Finds the smallest mass of all grains in a simulation. Used to determine
87 the optimal time step length."
88 function findSmallestGrainMass(simulation::Simulation)
89 m_min = 1e20
90 i_min = -1
91 for i=1:length(simulation.grains)
92 @inbounds grain = simulation.grains[i]
93 if grain.mass < m_min
94 m_min = grain.mass
95 i_min = i
96 end
97 end
98 return m_min, i_min
99 end
100
101 export findLargestGrainStiffness
102 "Finds the largest elastic stiffness of all grains in a simulation. Used to
103 determine the optimal time step length."
104 function findLargestGrainStiffness(simulation::Simulation)
105 k_n_max = 0.
106 k_t_max = 0.
107 i_n_max = -1
108 i_t_max = -1
109 for i=1:length(simulation.grains)
110
111 @inbounds grain = simulation.grains[i]
112
113 if grain.youngs_modulus > 0.
114 k_n = grain.youngs_modulus*grain.thickness # A = h*r
115 k_t = k_n * 2. * (1. - grain.poissons_ratio^2.)/
116 ((2. - grain.poissons_ratio) * (1. + grain.poissons_ratio))
117 else
118 k_n = grain.contact_stiffness_normal
119 k_t = grain.contact_stiffness_tangential
120 end
121
122 if k_n > k_n_max
123 k_n_max = k_n
124 i_n_max = i
125 end
126 if k_t > k_t_max
127 k_t_max = k_t
128 i_t_max = i
129 end
130 end
131 return k_n_max, k_t_max, i_n_max, i_t_max
132 end
133
134 export setTimeStep!
135 """
136 setTimeStep!(simulation[, epsilon, verbose])
137
138 Find the computational time step length suitable given the grain radii, contact
139 stiffnesses, and grain density. Uses the scheme by Radjaii et al. 2011.
140
141 # Arguments
142 * `simulation::Simulation`: the simulation object to modify.
143 * `epsilon::Float64=0.07`: safety factor in the time step scheme. Larger values
144 are more likely to cause unstable behavior than smaller values.
145 * `verbose::Bool=true`: display the resultant time step in the console.
146 """
147 function setTimeStep!(simulation::Simulation;
148 epsilon::Float64=0.07, verbose::Bool=true)
149
150 if length(simulation.grains) < 1
151 error("At least 1 grain is needed to find the computational time step.")
152 end
153
154 k_n_max, k_t_max, _, _ = findLargestGrainStiffness(simulation)
155 m_min, _ = findSmallestGrainMass(simulation)
156
157 simulation.time_step = epsilon/(sqrt(maximum([k_n_max, k_t_max])/m_min))
158
159 if simulation.time_step <= 1.0e-20
160 error("Time step too small or negative ($(simulation.time_step) s)")
161 end
162
163 if verbose
164 @info "Time step length t=$(simulation.time_step) s"
165 end
166 nothing
167 end
168
169 export resetTime!
170 """
171 resetTime!(simulation)
172
173 Reset the current time to zero, and reset output file counters in order to
174 restart a simulation. This function does not overwrite the time step
175 (`Simulation.time_step`), the output
176 file interval (`Simulation.file_time_step`), or the total simulation time
177 (`Simulation.time_total`).
178
179 # Arguments
180 * `simulation::Simulation`: the simulation object for which to reset the
181 temporal parameters.
182 """
183 function resetTime!(sim::Simulation)
184 sim.time_iteration = 0
185 sim.time = 0.0
186 sim.file_number = 0
187 sim.file_time_since_output_file = 0.
188 end
189