Skip to content

Commit

Permalink
improved graph time stepping
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenaH84 committed Jun 27, 2024
1 parent 31cc9fe commit cb9e8e4
Show file tree
Hide file tree
Showing 8 changed files with 709 additions and 5,245 deletions.
74 changes: 49 additions & 25 deletions streamlit/app_scripts/app_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6357,7 +6357,7 @@ def set_dynamic_dashboard(_self):
state += 1
time = time_values[state]

_self.view_plots_static(time, state)
_self.view_plots_static(time, state, step_size)

# def set_colormaps(_self):
# Colormaps
Expand Down Expand Up @@ -6609,8 +6609,9 @@ def find_max_length_array_y_axis(self, arrays):

return arrays

def find_closest_value_index(self, array, value):
"""Find the index of the value in the array that is closest to the specified value."""
def find_closest_value_index(self, array, value, step_size):
"""Find the index of the value in the array that is closest to the specified value,
but only if the difference is smaller than step_size."""
if isinstance(array, (np.ndarray, list)):
# Convert the array to a numpy array for uniform handling
array = np.array(array)
Expand All @@ -6625,12 +6626,15 @@ def find_closest_value_index(self, array, value):
# Find the index of the minimum difference in the valid array
closest_index_in_valid_array = np.argmin(diff)

# Map the index back to the original array
closest_index = np.where(mask)[0][closest_index_in_valid_array]

return closest_index
# Check if the minimum difference is within the step_size
if diff[closest_index_in_valid_array] < step_size:
# Map the index back to the original array
closest_index = np.where(mask)[0][closest_index_in_valid_array]
return closest_index
else:
return None
else:
st.write("Type not handled:", type(array))
print("Type not handled:", type(array))
return None

# def find_closest_value_index(self,array, value):
Expand All @@ -6653,7 +6657,7 @@ def find_closest_value_index(self, array, value):
# st.write("type " + type(array)+"not handled")
# return None

def view_plots_static(_self, time, state):
def view_plots_static(_self, time, state, step_size):

initial_graph_limits = _self.get_graph_initial_limits()
xmin = initial_graph_limits[0]
Expand Down Expand Up @@ -6683,7 +6687,7 @@ def view_plots_static(_self, time, state):
phimin_ne,
phimax_pe,
phimin_pe,
] = _self.get_graph_limits_from_state(time, state)
] = _self.get_graph_limits_from_state(time, state, step_size)

# Negative Electrode Concentration
if isinstance(_self.electrolyte_grid[0], float):
Expand Down Expand Up @@ -6717,7 +6721,9 @@ def view_plots_static(_self, time, state):
negative_electrode_concentration_ext = np.full(
length_grid_elyte, np.nan
)
state_index = _self.find_closest_value_index(_self.time_values[i], time)
state_index = _self.find_closest_value_index(
_self.time_values[i], time, step_size
)

if state_index != None:
negative_electrode_concentration_ext[0:length_grid_NE] = dataset[
Expand Down Expand Up @@ -6764,7 +6770,9 @@ def view_plots_static(_self, time, state):
)

for i, dataset in enumerate(_self.electrolyte_concentration):
state_index = _self.find_closest_value_index(_self.time_values[i], time)
state_index = _self.find_closest_value_index(
_self.time_values[i], time, step_size
)
if state_index != None:
elyte_concentration_ext_list.append(dataset[state_index])
else:
Expand Down Expand Up @@ -6817,7 +6825,9 @@ def view_plots_static(_self, time, state):
positive_electrode_concentration_ext = np.full(
length_grid_elyte, np.nan
)
state_index = _self.find_closest_value_index(_self.time_values[i], time)
state_index = _self.find_closest_value_index(
_self.time_values[i], time, step_size
)
if state_index != None:
positive_electrode_concentration_ext[-length_grid_PE:] = dataset[
state_index
Expand Down Expand Up @@ -6902,7 +6912,9 @@ def view_plots_static(_self, time, state):
for i, dataset in enumerate(_self.negative_electrode_potential):
length_grid_NE = len(dataset[0])
negative_electrode_potential_ext = np.full(length_grid_elyte, np.nan)
state_index = _self.find_closest_value_index(_self.time_values[i], time)
state_index = _self.find_closest_value_index(
_self.time_values[i], time, step_size
)
if state_index != None:

negative_electrode_potential_ext[0:length_grid_NE] = dataset[
Expand Down Expand Up @@ -6944,7 +6956,9 @@ def view_plots_static(_self, time, state):
)

for i, dataset in enumerate(_self.electrolyte_potential):
state_index = _self.find_closest_value_index(_self.time_values[i], time)
state_index = _self.find_closest_value_index(
_self.time_values[i], time, step_size
)
if state_index != None:

elyte_potential_ext_list.append(dataset[state_index])
Expand Down Expand Up @@ -6991,7 +7005,9 @@ def view_plots_static(_self, time, state):
for i, dataset in enumerate(_self.positive_electrode_potential):
length_grid_PE = len(dataset[0])
positive_electrode_potential_ext = np.full(length_grid_elyte, np.nan)
state_index = _self.find_closest_value_index(_self.time_values[i], time)
state_index = _self.find_closest_value_index(
_self.time_values[i], time, step_size
)
if state_index != None:

positive_electrode_potential_ext[-length_grid_PE:] = dataset[
Expand Down Expand Up @@ -7222,7 +7238,7 @@ def safe_nanmax(_self, array):
return max_val if not np.isnan(max_val) else None

@st.cache_data
def find_max(_self, data, time=None, state=None):
def find_max(_self, data, time=None, state=None, step_size=None):

# if state_index:
# positive_electrode_concentration_ext[-length_grid_PE:] = dataset[state_index]
Expand All @@ -7240,7 +7256,7 @@ def find_max(_self, data, time=None, state=None):
for i, array in enumerate(adapted_data):

state_index = _self.find_closest_value_index(
_self.time_values[i], time
_self.time_values[i], time, step_size
)
max_values.append(_self.safe_nanmax(array[state_index]))

Expand Down Expand Up @@ -7315,7 +7331,7 @@ def get_graph_initial_limits(_self):
]

@st.cache_data
def get_graph_limits_from_state(_self, time, state):
def get_graph_limits_from_state(_self, time, state, step_size):
[
xmin,
xmax,
Expand All @@ -7333,26 +7349,34 @@ def get_graph_limits_from_state(_self, time, state):
init_phimin_pe,
] = _self.get_graph_initial_limits()

cmax_elyte_sub = _self.find_max(_self.electrolyte_concentration, time, state)
cmax_elyte_sub = _self.find_max(
_self.electrolyte_concentration, time, state, step_size
)
cmin_elyte_sub = _self.find_min(_self.electrolyte_concentration, state)

cmax_ne_sub = _self.find_max(
_self.negative_electrode_concentration, time, state
_self.negative_electrode_concentration, time, state, step_size
)
cmin_ne_sub = _self.find_min(_self.negative_electrode_concentration, state)

cmax_pe_sub = _self.find_max(
_self.positive_electrode_concentration, time, state
_self.positive_electrode_concentration, time, state, step_size
)
cmin_pe_sub = _self.find_min(_self.positive_electrode_concentration, state)

phimax_elyte_sub = _self.find_max(_self.electrolyte_potential, time, state)
phimax_elyte_sub = _self.find_max(
_self.electrolyte_potential, time, state, step_size
)
phimin_elyte_sub = _self.find_min(_self.electrolyte_potential, state)

phimax_ne_sub = _self.find_max(_self.negative_electrode_potential, time, state)
phimax_ne_sub = _self.find_max(
_self.negative_electrode_potential, time, state, step_size
)
phimin_ne_sub = _self.find_min(_self.negative_electrode_potential, state)

phimax_pe_sub = _self.find_max(_self.positive_electrode_potential, time, state)
phimax_pe_sub = _self.find_max(
_self.positive_electrode_potential, time, state, step_size
)
phimin_pe_sub = _self.find_min(_self.positive_electrode_potential, state)

cmax_elyte = max(init_cmax_elyte, cmax_elyte_sub)
Expand Down
Binary file modified streamlit/database/BattMo_gui.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"lower_cutoff_voltage": {
"model_name": ["P2D","P3D"],
"par_class": "non_material",
"difficulty": "advanced",
"difficulty": "basis",
"context_type_iri":"https://w3id.org/emmo/domain/electrochemistry#electrochemistry_534dd59c_904c_45d9_8550_ae9d2eb6bbc9",
"max_value": 4,
"min_value": 0,
Expand All @@ -91,7 +91,7 @@
"upper_cutoff_voltage": {
"model_name": ["P2D","P3D"],
"par_class": "non_material",
"difficulty": "advanced",
"difficulty": "basis",
"context_type_iri":"https://w3id.org/emmo/domain/electrochemistry#electrochemistry_6dcd5baf_58cd_43f5_a692_51508e036c88",
"max_value": 5,
"min_value": 3,
Expand Down
32 changes: 16 additions & 16 deletions streamlit/input_files/battmo_formatted_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"Coating": {
"thickness": 8.499999999999999e-05,
"N": 20,
"effectiveDensity": 1770.4,
"effectiveDensity": 1789.6000000000001,
"bruggemanCoefficient": 1.5,
"ActiveMaterial": {
"massFraction": 0.9,
"massFraction": 0.95,
"density": 2260.0,
"electronicConductivity": 100.0,
"specificHeatCapacity": 632.0,
Expand All @@ -27,7 +27,7 @@
"chargeTransferCoefficient": 0.5,
"openCircuitPotential": {
"type": "function",
"functionname": "computeOCP_Graphite_SiOx_Chen2020",
"function": "1.9793 * exp(-39.3631*(c/cmax)) + 0.2482 - 0.0909 * tanh(29.8538*((c/cmax) - 0.1234)) - 0.04478 * tanh(14.9159*((c/cmax) - 0.2769)) - 0.0205 * tanh(30.4444*((c/cmax) - 0.6103))",
"argumentlist": [
"c",
"cmax"
Expand All @@ -44,7 +44,7 @@
},
"Binder": {
"density": 1780.0,
"massFraction": 0.05,
"massFraction": 0.0,
"electronicConductivity": 100.0,
"specificHeatCapacity": 1400.0,
"thermalConductivity": 0.165
Expand All @@ -67,12 +67,12 @@
"Coating": {
"thickness": 7.599999999999999e-05,
"N": 20,
"effectiveDensity": 3151.12,
"effectiveDensity": 3258.8999999999996,
"bruggemanCoefficient": 1.5,
"ActiveMaterial": {
"massFraction": 0.9,
"massFraction": 0.95,
"density": 4950.0,
"electronicConductivity": 100.0,
"electronicConductivity": 0.8,
"specificHeatCapacity": 632.0,
"thermalConductivity": 2.1,
"Interface": {
Expand All @@ -87,7 +87,7 @@
"chargeTransferCoefficient": 0.5,
"openCircuitPotential": {
"type": "function",
"functionname": "computeOCP_NMC811_Chen2020",
"function": "-0.8090 * (c/cmax) + 4.4875 - 0.0428 * tanh(18.5138*((c/cmax) - 0.5542)) - 17.7326 * tanh(15.7890*((c/cmax) - 0.3117)) + 17.5842 * tanh(15.9308*((c/cmax) - 0.3120))",
"argumentlist": [
"c",
"cmax"
Expand All @@ -96,15 +96,15 @@
},
"diffusionModelType": "full",
"SolidDiffusion": {
"activationEnergyOfDiffusion": 5000.0,
"referenceDiffusionCoefficient": 3.9e-14,
"particleRadius": 1e-06,
"activationEnergyOfDiffusion": 80000.0,
"referenceDiffusionCoefficient": 1e-14,
"particleRadius": 5e-07,
"N": 10
}
},
"Binder": {
"density": 1780.0,
"massFraction": 0.05,
"massFraction": 0.0,
"electronicConductivity": 100.0,
"specificHeatCapacity": 1400.0,
"thermalConductivity": 0.165
Expand Down Expand Up @@ -139,14 +139,14 @@
"density": 1200,
"ionicConductivity": {
"type": "function",
"functionname": "computeElectrolyteConductivity_Chen2020",
"function": "0.1297*(c/1000)^3 - 2.51*(c/1000)^(1.5) + 3.329*(c/1000)",
"argumentlist": [
"c"
]
},
"diffusionCoefficient": {
"type": "function",
"functionname": "computeDiffusionCoefficient_Chen2020",
"function": "8.794*10^(-11)*(c/1000)^2 - 3.972*10^(-10)*(c/1000) + 4.862*10^(-10)",
"argumentlist": [
"c"
]
Expand All @@ -170,11 +170,11 @@
"Control": {
"controlPolicy": "CCCV",
"initialControl": "charging",
"numberOfCycles": 1,
"numberOfCycles": 5,
"CRate": 1.0,
"DRate": 1.0,
"lowerCutoffVoltage": 2.4,
"upperCutoffVoltage": 4.1,
"upperCutoffVoltage": 3.6,
"rampupTime": 10.0,
"dIdtLimit": 0.0001,
"dEdtLimit": 0.01
Expand Down
Loading

0 comments on commit cb9e8e4

Please sign in to comment.