Skip to content

Commit eae49f5

Browse files
authored
add save_stats flag (#65)
1 parent 2edfc91 commit eae49f5

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "openBF"
22
uuid = "e815b1a4-10eb-11ea-25f1-272ff651e618"
33
authors = ["alessandro <alessandro_melis@rocketmail.com>"]
4-
version = "2.2.0"
4+
version = "2.3.0"
55

66
[deps]
77
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"

docs/src/man/quickstart.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ run_simulation(
1818
yaml_config_path::String;
1919
verbose::Bool = false, # show progress bars
2020
out_files::Bool = false, # save .out files with the all the cycles
21+
save_stats::Bool = false, # save .conv file with simulation stats
2122
)
2223
```
2324

@@ -27,7 +28,7 @@ Running a simulation consists in calling
2728

2829
```julia
2930
using openBF
30-
run_simulation("input.yml", verbose=true)
31+
run_simulation("input.yml", verbose=true, save_stats=true)
3132
```
3233

3334
This will create a `<project_name>_results` folder containing all the output files from the simulation.
@@ -40,6 +41,16 @@ By default only `.last` files are saved. Thes contains only the _last_ simulated
4041

4142
You can also set `out_files = true` when calling `run_simulation`. This results in the writing of `.out` files which contain the _whole_ simulation history, i.e., all the cardiac cycles simulated.
4243

43-
### Format
44+
When setting `save_stats=true`, a `<project_name>.conv` file is written in the results dolder. This reads
45+
46+
```
47+
<has the simulation converged> # boolean: true or false
48+
<elapsed cardiac cycles> # integer
49+
<elapsed time> # float, seconds
50+
<memory allocated> # integer, bytes
51+
<garbace collection % time> # float, percentage
52+
```
53+
54+
### `.last`/`.out` Format
4455

4556
These files contain as many rows as defined in the config by the `jump` parameter (default `100`), and 6 columns. The first column contains the simulation time for the current cardiac cycles; column 2-6 report waveforms at five locations along the vessel, namely _inlet_, _1/4th_ of the length, _mid-point_, _3/4th_ of the length and _outlet_.

src/simulation.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function run_simulation(
8888
yaml_config::String;
8989
verbose::Bool = true,
9090
out_files::Bool = false,
91+
save_stats::Bool = false,
9192
)
9293
initial_dir = pwd()
9394
config = preamble(yaml_config, verbose)
@@ -117,7 +118,8 @@ function run_simulation(
117118
prog = getprog(passed_cycles, verbose)
118119
counter = 1
119120
conv_error = floatmax()
120-
@time while true
121+
converged = false
122+
stats = @timed while true
121123

122124
# step
123125
dt = calculate_Δt(network)
@@ -166,12 +168,17 @@ function run_simulation(
166168
passed_cycles == config["solver"]["cycles"] ||
167169
conv_error < config["solver"]["convergence_tolerance"]
168170
verbose && finish!(prog)
171+
converged = true
169172
break
170173
end
171174
current_time += dt
172175
end
173176
tokeep = get(config, "write_results", [])
174177
cleanup.(values(network.vessels), Ref(tokeep))
178+
179+
verbose && printstats(stats, converged, passed_cycles)
180+
save_stats && savestats(stats, converged, passed_cycles, config["project_name"])
181+
175182
cd(initial_dir)
176183
end
177184

@@ -181,3 +188,25 @@ function cleanup(v::Vessel, tokeep)
181188
l tokeep && rm.(glob("$(v.label)_$l.*"), force=true)
182189
end
183190
end
191+
192+
function printstats(s, converged, passed_cycles)
193+
if converged
194+
println("Simulation converged after $passed_cycles cardiac cycles")
195+
else
196+
println("Simulation not converged, stopping after $passed_cycles cardiac cycles")
197+
end
198+
@printf "Elapsed time: %5.2fs\n" s.time
199+
@printf "Memory: %5.2fGB\n" s.bytes*1e-9
200+
gctime = @sprintf "GC time: %5.2f" s.gctime
201+
println("$(gctime)%")
202+
end
203+
204+
function savestats(s, converged, passed_cycles, simulation_name)
205+
open("$simulation_name.conv", "w") do io
206+
println(io, "$converged")
207+
println(io, "$passed_cycles")
208+
println(io, "$(s.time)")
209+
println(io, "$(s.bytes)")
210+
println(io, "$(s.gctime)")
211+
end
212+
end

0 commit comments

Comments
 (0)