Skip to content

Commit

Permalink
#1129 debugging julia models
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Nov 4, 2020
1 parent a7cc4d7 commit f415d55
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions tests/unit/test_expression_tree/test_operations/quick_julia_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,39 @@
# from julia import Main


model = pybamm.lithium_ion.SPM()
model = pybamm.lithium_ion.SPMe()
sim = pybamm.Simulation(model, solver=pybamm.CasadiSolver(mode="fast"))
sim.solve([0, 3600])
sol = sim.solve([0, 3600])
param = model.default_parameter_values
timescale = param.evaluate(model.timescale)
sol = sim.solve(np.linspace(0, 0.15 * timescale, 100))
print(sol.y[:, -1])
print(sol.integration_time)
# sim.build(check_model=False)
# expr = sim.built_model.concatenated_rhs
# expr = pybamm.NumpyConcatenation(
# sim.built_model.concatenated_rhs, sim.built_model.concatenated_algebraic
# )
expr = sim.built_model.concatenated_rhs

# evaluator_str = pybamm.get_julia_function(expr)
evaluator_str = pybamm.get_julia_function(expr)
n_rhs = sim.built_model.concatenated_rhs.size
n_alg = sim.built_model.concatenated_algebraic.size
# np.set_printoptions(
# threshold=max(
# np.get_printoptions()["threshold"],
# sim.built_model.concatenated_initial_conditions.evaluate().flatten().size,
# n_rhs + n_alg,
# )
# )
# with open("tmp.txt", "w") as f:
# f.write(evaluator_str)
# f.write(
# np.array2string(
# sim.built_model.concatenated_initial_conditions.evaluate().flatten(),
# separator=",",
# )
# )
with open("tmp.txt", "w") as f:
f.write(evaluator_str + "\n\n")
# f.write(f"u0 = {np.array2string(sol.model.y0, separator=',')}\n")
# f.write(f"du0 = zeros({n_rhs + n_alg})\n")
# f.write(f"differential_vars=[zeros({n_rhs});zeros({n_alg})]\n")

expr2 = sim.built_model.variables["Terminal voltage [V]"]
evaluator_str2 = pybamm.get_julia_function(expr2)
with open("tmp2.txt", "w") as f:
f.write(evaluator_str2 + "\n\n")

# Main.eval(evaluator_str)
# Main.dy = [0, 0, 0, 0, 0, 0]
# Main.y = [2, 3, 4, 5, 6, 7]
Expand Down

0 comments on commit f415d55

Please sign in to comment.