Skip to content

Commit

Permalink
Convert ecm to jellybamm
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTranter committed Feb 8, 2024
1 parent 01fcc4a commit a5b1cdb
Show file tree
Hide file tree
Showing 48 changed files with 288 additions and 243 deletions.
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.ipynb_checkpoints/
ecm/__pycache__/
ecm.egg-info/
jellybamm/__pycache__/
jellybamm.egg-info/
*.pyc
.coverage
ecm/output/1d/
ecm/output/spiral/1.5A/
ecm/output/spiral_tesla/
ecm/output/tomography/3.0A/
jellybamm/output/1d/
jellybamm/output/spiral/1.5A/
jellybamm/output/spiral_tesla/
jellybamm/output/tomography/3.0A/
build/
dist/
.virtual_documents/
Expand Down
26 changes: 13 additions & 13 deletions docs/examples/01 Getting started.ipynb

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions docs/examples/02 Network from an image.ipynb

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions docs/examples/03 Running a simulation.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: ecm
::: jellybamm
21 changes: 21 additions & 0 deletions ecm.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Metadata-Version: 2.1
Name: ecm
Version: 0.0.2
Summary: Equivalent Circuit Model for battery modelling using PyBaMM
Home-page: https://ecm.readthedocs.io/en/latest/
Author: Tom Tranter
Author-email: t.g.tranter@gmail.com
Project-URL: Documentation, https://ecm.readthedocs.io/en/latest/
Project-URL: Source, https://github.com/TomTranter/pybamm_pnm
Project-URL: Tracker, https://github.com/TomTranter/pybamm_pnm/issues
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Physics
License-File: LICENSE
Requires-Dist: numba
Requires-Dist: pybamm
Requires-Dist: liionpack
Requires-Dist: openpnm==2.8.2
Requires-Dist: ffmpeg-python
18 changes: 18 additions & 0 deletions ecm.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
LICENSE
README.md
setup.cfg
setup.py
ecm/__battery__.py
ecm/__definitions__.py
ecm/__funcs__.py
ecm/__init__.py
ecm/__liionsolve__.py
ecm/__postprocess__.py
ecm/__segment_jellyroll__.py
ecm/__topology__.py
ecm/__utilities__.py
ecm.egg-info/PKG-INFO
ecm.egg-info/SOURCES.txt
ecm.egg-info/dependency_links.txt
ecm.egg-info/requires.txt
ecm.egg-info/top_level.txt
File renamed without changes.
5 changes: 5 additions & 0 deletions ecm.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
numba
pybamm
liionpack
openpnm==2.8.2
ffmpeg-python
1 change: 1 addition & 0 deletions ecm.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ecm
File renamed without changes.
4 changes: 2 additions & 2 deletions ecm/__definitions__.py → jellybamm/__definitions__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
@author: tom
"""

import ecm
import jellybamm
import os

ROOT_DIR = os.path.dirname(os.path.abspath(ecm.__file__))
ROOT_DIR = os.path.dirname(os.path.abspath(jellybamm.__file__))
PARENT_DIR = os.path.dirname(ROOT_DIR)
TESTS_DIR = os.path.join(PARENT_DIR, 'tests')
FIXTURES_DIR = os.path.join(TESTS_DIR, 'fixtures')
Expand Down
2 changes: 1 addition & 1 deletion ecm/__funcs__.py → jellybamm/__funcs__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def get_cc_heat(net, alg, V_terminal):
)


def run_ecm(net, alg, V_terminal, plot=False):
def run_jellybamm(net, alg, V_terminal, plot=False):
potential_pairs = net["throat.conns"][net.throats("spm_resistor")]
P1 = potential_pairs[:, 0]
P2 = potential_pairs[:, 1]
Expand Down
3 changes: 1 addition & 2 deletions ecm/__init__.py → jellybamm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
jellysim: a package for simulating Li-ion electrochemistry
on jellyroll structures
JellyBaMM: a package for simulating Li-ion electrochemistry on jellyroll structures with PyBaMM
"""

from .__funcs__ import *
Expand Down
22 changes: 11 additions & 11 deletions ecm/__liionsolve__.py → jellybamm/__liionsolve__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
import os
import numpy as np
import ecm
import jellybamm
import pybamm
import time as ticker
import openpnm as op
Expand Down Expand Up @@ -74,7 +74,7 @@ def run_simulation_lp(parameter_values, experiment, initial_soc, project):
###########################################################################
# Make the pybamm simulation - should be moved to a simfunc #
###########################################################################
parameter_values = ecm.adjust_parameters(parameter_values, I_typical)
parameter_values = jellybamm.adjust_parameters(parameter_values, I_typical)
# width = parameter_values["Electrode width [m]"]
# t1 = parameter_values["Negative electrode thickness [m]"]
# t2 = parameter_values["Positive electrode thickness [m]"]
Expand All @@ -89,12 +89,12 @@ def run_simulation_lp(parameter_values, experiment, initial_soc, project):
###########################################################################
# Output variables #
###########################################################################
output_variables = ecm.output_variables()
output_variables = jellybamm.output_variables()
###########################################################################
# Thermal parameters #
###########################################################################
T0 = parameter_values["Initial temperature [K]"]
lumpy_therm = ecm.lump_thermal_props(parameter_values)
lumpy_therm = jellybamm.lump_thermal_props(parameter_values)
cp = lumpy_therm["lump_Cp"]
rho = lumpy_therm["lump_rho"]
###########################################################################
Expand All @@ -103,7 +103,7 @@ def run_simulation_lp(parameter_values, experiment, initial_soc, project):
# outer_step = 0
# if config.getboolean("PHYSICS", "do_thermal"):
# Always do thermal
ecm.setup_thermal(project, parameter_values)
jellybamm.setup_thermal(project, parameter_values)
# try:
# thermal_third = config.getboolean("RUN", "third")
# except KeyError:
Expand All @@ -112,12 +112,12 @@ def run_simulation_lp(parameter_values, experiment, initial_soc, project):
# New Liionpack code #
###########################################################################
dim_time_step = 10
neg_econd, pos_econd = ecm.cc_cond(project, parameter_values)
neg_econd, pos_econd = jellybamm.cc_cond(project, parameter_values)
Rs = 1e-2 # series resistance
Ri = 90 # initial guess for internal resistance
V = 3.6 # initial guess for cell voltage
# I_app = 0.5
netlist = ecm.network_to_netlist(net, Rs, Ri, V, I_app)
netlist = jellybamm.network_to_netlist(net, Rs, Ri, V, I_app)
T0 = parameter_values["Initial temperature [K]"]
e_heights = net["throat.electrode_height"][net.throats("throat.spm_resistor")]
spm_temperature = np.ones(Nspm) * T0
Expand Down Expand Up @@ -171,9 +171,9 @@ def run_simulation_lp(parameter_values, experiment, initial_soc, project):
# key = "Volume-averaged Ohmic heating CC [W.m-3]"
# vh[key][outer_step, :] = Q_ohm_cc[sorted_res_Ts]
Q[res_Ts] += Q_tot
ecm.apply_heat_source_lp(project, Q)
jellybamm.apply_heat_source_lp(project, Q)
# Calculate Global Temperature
ecm.run_step_transient(project, dim_time_step, T0, cp, rho, thermal_third)
jellybamm.run_step_transient(project, dim_time_step, T0, cp, rho, thermal_third)
# Interpolate the node temperatures for the SPMs
spm_temperature = phase.interpolate_data("pore.temperature")[res_Ts]
# T_non_dim_spm = fT_non_dim(parameter_values, spm_temperature)
Expand Down Expand Up @@ -231,9 +231,9 @@ def run_simulation_lp(parameter_values, experiment, initial_soc, project):
# key = "Volume-averaged Ohmic heating CC [W.m-3]"
# vh[key][outer_step, :] = Q_ohm_cc[sorted_res_Ts]
Q[res_Ts] += Q_tot
ecm.apply_heat_source_lp(project, Q)
jellybamm.apply_heat_source_lp(project, Q)
# Calculate Global Temperature
ecm.run_step_transient(project, dim_time_step, T0, cp, rho, thermal_third)
jellybamm.run_step_transient(project, dim_time_step, T0, cp, rho, thermal_third)
# Interpolate the node temperatures for the SPMs
spm_temperature = phase.interpolate_data("pore.temperature")[res_Ts]
###################################################################
Expand Down
8 changes: 4 additions & 4 deletions ecm/__postprocess__.py → jellybamm/__postprocess__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from matplotlib import gridspec
import matplotlib.ticker as mtick
from string import ascii_lowercase as abc
import ecm
import jellybamm


prop_cycle = plt.rcParams["axes.prop_cycle"]
Expand Down Expand Up @@ -188,7 +188,7 @@ def load_data(filepath):

def get_net(filepath=None, filename="spider_net.pnm"):
if filepath is None:
filepath = ecm.INPUT_DIR
filepath = jellybamm.INPUT_DIR
wrk.load_project(os.path.join(filepath, filename))
sim_name = list(wrk.keys())[-1]
project = wrk[sim_name]
Expand Down Expand Up @@ -592,7 +592,7 @@ def animate_data4(data, case, amp, variables=None, filename=None):
net = data[case]["network"]
weights = get_weights(net)
project = net.project
im_spm_map = np.load(os.path.join(ecm.INPUT_DIR, "im_spm_map.npz"))["arr_0"]
im_spm_map = np.load(os.path.join(jellybamm.INPUT_DIR, "im_spm_map.npz"))["arr_0"]
title = filename.split("\\")
if len(title) == 1:
title = title[0]
Expand Down Expand Up @@ -744,7 +744,7 @@ def jellyroll_subplot(
soc_arr = np.asarray(soc_list)
(nrows, ncols) = soc_arr.shape
fig, axes = plt.subplots(nrows, ncols, figsize=(12, 12), sharex=True, sharey=True)
spm_map = np.load(os.path.join(ecm.INPUT_DIR, "im_spm_map.npz"))["arr_0"]
spm_map = np.load(os.path.join(jellybamm.INPUT_DIR, "im_spm_map.npz"))["arr_0"]
spm_map_copy = spm_map.copy()
spm_map_copy[np.isnan(spm_map_copy)] = -1
spm_map_copy = spm_map_copy.astype(int)
Expand Down
20 changes: 10 additions & 10 deletions ecm/__segment_jellyroll__.py → jellybamm/__segment_jellyroll__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
import os
import openpnm as op
import openpnm.topotools as tt
import ecm
import jellybamm


wrk = op.Workspace()


def average_images(path=None):
if path is None:
path = ecm.INPUT_DIR
path = jellybamm.INPUT_DIR
# Get File list
files = []
for file in os.listdir(path):
Expand Down Expand Up @@ -117,9 +117,9 @@ def adjust_radial_average(im, step, deg, dt):

def remove_beam_hardening(im, dt, step, deg):
# Compute radial averages and adjustments for beam hardening - soften image
dat_im = ecm.get_radial_average(im, step, dt)
im_soft = ecm.adjust_radial_average(im, step, deg, dt)
dat_soft = ecm.get_radial_average(im_soft, step, dt)
dat_im = jellybamm.get_radial_average(im, step, dt)
im_soft = jellybamm.adjust_radial_average(im, step, deg, dt)
dat_soft = jellybamm.get_radial_average(im_soft, step, dt)
fig, axes = plt.subplots(2, 1, figsize=(10, 10))
axes[0].imshow(im_soft - im.astype(float))
axes[1].plot(dat_im[:, 0], dat_im[:, 1])
Expand Down Expand Up @@ -375,9 +375,9 @@ def spider_web_network(im_soft, mhs, cc_im, dtheta=10, pixel_size=10.4e-6,
outer_pos = net['pore.coords'][net.pores('outer')]
x = outer_pos[:, 0] - mhs
y = outer_pos[:, 1] - mhs
r, t = ecm.polar_transform(x, y)
r, t = jellybamm.polar_transform(x, y)
r_new = np.ones(num_free) * (r + 25)
new_x, new_y = ecm.cartesian_transform(r_new, t)
new_x, new_y = jellybamm.cartesian_transform(r_new, t)
free_coords = outer_pos.copy()
free_coords[:, 0] = new_x + mhs
free_coords[:, 1] = new_y + mhs
Expand All @@ -395,9 +395,9 @@ def spider_web_network(im_soft, mhs, cc_im, dtheta=10, pixel_size=10.4e-6,
inner_pos = net['pore.coords'][net.pores('inner')]
x = inner_pos[:, 0] - mhs
y = inner_pos[:, 1] - mhs
r, t = ecm.polar_transform(x, y)
r, t = jellybamm.polar_transform(x, y)
r_new = np.ones(num_inner) * (r - 25)
new_x, new_y = ecm.cartesian_transform(r_new, t)
new_x, new_y = jellybamm.cartesian_transform(r_new, t)
inner_coords = inner_pos.copy()
inner_coords[:, 0] = new_x + mhs
inner_coords[:, 1] = new_y + mhs
Expand All @@ -421,6 +421,6 @@ def spider_web_network(im_soft, mhs, cc_im, dtheta=10, pixel_size=10.4e-6,
net['throat.arc_length'] = net['throat.radial_position'] * np.deg2rad(dtheta)

if path is None:
path = ecm.INPUT_DIR
path = jellybamm.INPUT_DIR
wrk.save_project(project=prj, filename=os.path.join(path, filename))
return net
12 changes: 6 additions & 6 deletions ecm/__topology__.py → jellybamm/__topology__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from openpnm.topotools import plot_coordinates as pcoord
import os
import matplotlib.pyplot as plt
import ecm
import jellybamm
import pandas as pd


Expand All @@ -23,8 +23,8 @@ def plot_topology(net, ax=None):
c3 = np.array([[100 / 255, 100 / 255, 100 / 255, 1]]) # Granite Gray
if ax is None:
fig, ax = plt.subplots(1, 1, figsize=(10, 10))
ax = ecm.plot_resistors(net, throats=net.throats("throat.neg_cc"), color=c1, ax=ax)
ax = ecm.plot_resistors(net, throats=net.throats("throat.pos_cc"), color=c2, ax=ax)
ax = jellybamm.plot_resistors(net, throats=net.throats("throat.neg_cc"), color=c1, ax=ax)
ax = jellybamm.plot_resistors(net, throats=net.throats("throat.pos_cc"), color=c2, ax=ax)
ax = pcoord(net, pores=net.pores("neg_cc"), color=c1, s=25, ax=ax)
ax = pcoord(net, pores=net.pores("pos_cc"), color=c2, s=25, ax=ax)
ax = pcoord(net, pores=net["pore.neg_tab"], color=c1, s=75, ax=ax)
Expand Down Expand Up @@ -253,7 +253,7 @@ def make_spiral_net(
op.topotools.trim(network=net, throats=net.throats("trimmers"))

# print("N SPM", net.num_throats("spm_resistor"))
geo = ecm.setup_geometry(net, dtheta, spacing, length_3d=length_3d)
geo = jellybamm.setup_geometry(net, dtheta, spacing, length_3d=length_3d)
net["throat.arc_length"] = np.deg2rad(dtheta) * net["throat.radial_position"]
phase = op.phases.GenericPhase(network=net)
op.physics.GenericPhysics(network=net, phase=phase, geometry=geo)
Expand All @@ -262,7 +262,7 @@ def make_spiral_net(

def make_tomo_net(tomo_pnm, dtheta, spacing, length_3d, pos_tabs, neg_tabs):
wrk = op.Workspace()
input_dir = ecm.INPUT_DIR
input_dir = jellybamm.INPUT_DIR
wrk.load_project(os.path.join(input_dir, tomo_pnm))
sim_name = list(wrk.keys())[-1]
project = wrk[sim_name]
Expand Down Expand Up @@ -291,7 +291,7 @@ def make_tomo_net(tomo_pnm, dtheta, spacing, length_3d, pos_tabs, neg_tabs):
# Add 1 more
arc_edges.append(arc_edges[-1] + d)
arc_edges = np.asarray(arc_edges)
geo = ecm.setup_geometry(net, dtheta, spacing, length_3d=length_3d)
geo = jellybamm.setup_geometry(net, dtheta, spacing, length_3d=length_3d)
phase = op.phases.GenericPhase(network=net)
op.physics.GenericPhysics(network=net, phase=phase, geometry=geo)
return project, arc_edges
Expand Down
4 changes: 2 additions & 2 deletions ecm/__utilities__.py → jellybamm/__utilities__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Utilities
#

import ecm
import jellybamm
import os
import numpy as np
from scipy.interpolate import NearestNDInterpolator


def interpolate_timeseries(project, data):
im_soft = np.load(os.path.join(ecm.INPUT_DIR, 'im_soft.npz'))['arr_0']
im_soft = np.load(os.path.join(jellybamm.INPUT_DIR, 'im_soft.npz'))['arr_0']
x_len, y_len = im_soft.shape
net = project.network
res_Ts = net.throats('spm_resistor')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions jellybamm/output/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 2 additions & 2 deletions post_scripts/animate_saved_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pybamm
import openpnm as op
import matplotlib.pyplot as plt
import ecm
import jellybamm
import os
from scipy import io
import numpy as np
Expand Down Expand Up @@ -64,5 +64,5 @@
variables[plot_time] = time_amalg

save_path = os.path.join(save_root, 'Current collector current density')
ecm.animate_data4(project, variables, plot_left, plot_right, weights,
jellybamm.animate_data4(project, variables, plot_left, plot_right, weights,
filename=save_path)
8 changes: 4 additions & 4 deletions post_scripts/compare_jelly_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
@author: Tom
"""

import ecm
import jellybamm
import os
from scipy import io
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

root = 'D:\\pybamm_pnm_results\\Chen2020_v3'
cases = ecm.get_cases()
amps = ecm.get_amp_cases()
cases = jellybamm.get_cases()
amps = jellybamm.get_amp_cases()
data_suff = ['mean', 'std', 'chi']
d = {}
for case in cases.keys():
Expand Down Expand Up @@ -66,7 +66,7 @@ def jellyroll_multiplot(data, cases=[0, 1, 2], amps=[1.75, 3.5, 5.25], var='std'
im = ax.imshow(arr, cmap=cm.inferno)
ax.set_axis_off()
plt.colorbar(im, ax=ax, format='%.' + str(dp) + 'f')
ax.set_title(ecm.format_case(case, amp, expanded=False))
ax.set_title(jellybamm.format_case(case, amp, expanded=False))

return fig

Expand Down
Loading

0 comments on commit a5b1cdb

Please sign in to comment.