main.jl |
|
---|---|
The |
using openBF
|
The project name must be specified by the user when launching the simulation.
|
project_name = ARGS[1]
|
In |
openBF.projectPreamble(project_name)
|
|
println("Load project $project_name files")
include(join([project_name, "_constants.jl"]))
|
Arterial systemArterial model and structure is encoded in a |
model = openBF.readModelData(join([project_name, ".csv"]))
|
Data from |
heart, blood_prop, total_time = openBF.loadGlobalConstants(project_name,
inlet_BC_switch, inlet_type, cycles, rho, mu, gamma_profile)
|
Two data structures are used to describe the arterial system. One is a collection of |
vessels = [openBF.initialiseVessel(model[1,:], 1, heart, blood_prop,
initial_pressure, Ccfl)]
edge_list = zeros(Int8, length(model[:,1]), 3)
edge_list[1,1] = vessels[1].ID
edge_list[1,2] = vessels[1].sn
edge_list[1,3] = vessels[1].tn
|
The model matrix is read iteratively starting from the second row, the first row contains column headers. |
for i in 2:length(model[:,1])
|
Each new |
push!(vessels, openBF.initialiseVessel(model[i,:], i, heart, blood_prop,
initial_pressure, Ccfl))
edge_list[i,1] = vessels[i].ID
edge_list[i,2] = vessels[i].sn
edge_list[i,3] = vessels[i].tn
end
|
Before starting the main loop the counter |
println("Start simulation \n")
current_time = 0
|
In order to show the progress bar an initial estimate of the total running time is needed. Thus, \(\Delta t\) is calculated with system initial conditions and used to compute the number or total iterations before the end of the simulation. See ProgressMeter documentation for |
dts = zeros(Float64, length(edge_list[:,1]))
dt = openBF.calculateDeltaT(vessels, dts)
prog = ProgressMeter.Progress(Int(ceil(total_time/dt)), 1, "Running ", 50)
|
The simulation is ran in a |
passed_cycles = 0
tic()
counter = 0
counter_v = 0
while true
|
At the beginning of each time step the \(\Delta t\) is computed with |
dt = openBF.calculateDeltaT(vessels, dts)
current_time += dt
|
|
#Solve arteries
openBF.solveModel(vessels, heart, edge_list, blood_prop, dt, current_time)
|
|
openBF.updateGhostCells(vessels)
|
All quantities in each vessel are stored by |
if counter == 100
openBF.saveTempData(current_time, vessels)
counter = 0
else
counter += 1
end
#Progress bar update
ProgressMeter.next!(prog)
|
Every time a cardiac cycle has been simulated, this condition returns |
if (current_time - heart.cardiac_T*passed_cycles) >= heart.cardiac_T &&
(current_time - heart.cardiac_T*passed_cycles + dt) > heart.cardiac_T
openBF.closeTempFiles(vessels)
openBF.transferLastToOut(vessels)
openBF.openCloseLastFiles(vessels)
openBF.transferTempToLast(vessels)
openBF.openTempFiles(vessels)
passed_cycles += 1
|
When at least 3 cardiac cycles have been simulated, waveforms are checked for convergence. |
if passed_cycles >= 3
|
The error is computed for all vessels in the system by |
err = openBF.checkConvergence(vessels, 5.)
|
The convergence is reached when the difference (the error) between two consecutive waveforms is less than 5%. In this case, the main loop is exited. |
if err < 5.
println("\nConverged in $passed_cycles cycles, end!")
break
end
end
openBF.openCloseLastFiles(vessels)
openBF.transferTempToLast(vessels)
openBF.openTempFiles(vessels)
end
|
When the |
if current_time >= total_time
erlog = open("error.log", "w")
write(erlog, "Not converged after $passed_cycles cycles, End!")
close(erlog)
break
end
end
@printf "\n"
toc()
|
Make sure that data from |
openBF.closeTempFiles(vessels)
openBF.transferTempToOut(vessels)
|