Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mrst utils cleanup #5

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions examples/battery/example_battery.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ end

# sim, forces, state0, parameters, exported, model = BattMo.setup_sim(name, use_p2d = use_p2d)

do_json = true
do_json = false # true

if do_json

states, reports, extra = run_battery_1d(info_level = 0, extra_timing = false);
fn = string(dirname(pathof(BattMo)), "/../test/battery/data/jsonfiles/", name, "_jl.json")
init = JSONFile(fn)
states, reports, extra = run_battery(init;use_p2d=use_p2d,info_level = 0, extra_timing = false);


nsteps = size(states)
Expand All @@ -66,7 +67,7 @@ if do_json

else

states, reports, extra, exported = run_battery(name, use_p2d = use_p2d, info_level = 5, max_step = nothing);
states, reports, extra, exported = run_battery(name; use_p2d = use_p2d, info_level = 0, max_step = nothing);

nsteps = size(states, 1)

Expand All @@ -75,7 +76,7 @@ else
time = cumsum(timesteps[1 : nsteps])
E = [state[:BPP][:Phi][1] for state in states]

statesref = extra[:states_ref]
statesref = extra[:init].object["states"]
timeref = time
Eref = [state["Control"]["E"] for state in statesref[1 : nsteps]]

Expand Down
21 changes: 11 additions & 10 deletions examples/battery/example_cycle.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using BattMo
name="model1D_50"
#name="model1D_50"
name = "p2d_40"
# Run base case and plot the results against BattMo-MRST reference
states, reports, extra = run_battery(name, info_level = 1, max_step = nothing);
prm = extra[:parameters]
model = extra[:model]
timesteps = extra[:timesteps]
steps = size(states, 1)
stateref = extra[:states_ref]
stateref = extra[:init].object["states"]
E = Matrix{Float64}(undef,steps,2)
for step in 1:steps
phi = states[step][:BPP][:Phi][1]
Expand All @@ -22,15 +23,15 @@ Plots.plot!(T, E[:, 2], label = "BattMo")
closeall()
display(plot1)
## Compute and plot the charge flux
f = :ELYTE
ix = 1
get_j = ix -> output_flux(model[f], states[ix][f], prm[f], :charge_conservation)
# f = :ELYTE
# ix = 1
# get_j = ix -> output_flux(model[f], states[ix][f], prm[f], :charge_conservation)

plot2 = Plots.plot(get_j(1))
for ix in 5:5:length(states)
Plots.plot!(get_j(ix))
end
display(plot2)
# plot2 = Plots.plot(get_j(1))
# for ix in 5:5:length(states)
# Plots.plot!(get_j(ix))
# end
# display(plot2)

## Set up a cycle policy and simulate
using Jutul
Expand Down
7 changes: 4 additions & 3 deletions src/BattMo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ include("models/current_and_voltage_boundary.jl")
include("models/battery_cross_terms.jl") # Works now
include("models/convergence.jl")
include("physics.jl")
include("types.jl")
include("mrst_test_utils.jl")
include("linsolve.jl")

# Precompilation of solver. Run a small battery simulation to precompile everything.
@compile_workload begin
for use_general_ad in [false, true]
run_battery("p2d_40", info_level = -1, general_ad = use_general_ad);
end
for use_general_ad in [false, true]
run_battery("p2d_40"; general_ad = use_general_ad,info_level = -1);
end
end

end # module
Loading
Loading