Skip to content

Commit

Permalink
#871 start making changes to quickplot, still working on 3D
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Mar 5, 2020
1 parent 6ff39b9 commit c1e615e
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 145 deletions.
14 changes: 13 additions & 1 deletion examples/scripts/DFN.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,17 @@
solution = solver.solve(model, t_eval)

# plot
plot = pybamm.QuickPlot(solution)
plot = pybamm.QuickPlot(
solution,
output_variables=[
"Negative particle surface concentration [mol.m-3]",
"Electrolyte concentration [mol.m-3]",
"Positive particle surface concentration [mol.m-3]",
"Current [A]",
"Negative electrode potential [V]",
"Electrolyte potential [V]",
"Positive electrode potential [V]",
"Terminal voltage [V]",
],
)
plot.dynamic_plot()
2 changes: 1 addition & 1 deletion examples/scripts/SPMe.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
solution = model.default_solver.solve(model, t_eval)

# plot
plot = pybamm.QuickPlot(solution)
plot = pybamm.QuickPlot(solution, ["Negative particle concentration"])
plot.dynamic_plot()
8 changes: 6 additions & 2 deletions pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def update_from_chemistry(self, chemistry):
"""
base_chemistry = chemistry["chemistry"]
# Create path to file
path = os.path.join("input", "parameters", base_chemistry)
path = os.path.join(
pybamm.root_dir(), "pybamm", "input", "parameters", base_chemistry
)
# Load each component name
for component_group in [
"cell",
Expand Down Expand Up @@ -227,7 +229,9 @@ def update(self, values, check_conflict=False, check_already_exists=True, path="
# Data is flagged with the string "[data]" or "[current data]"
elif value.startswith("[current data]") or value.startswith("[data]"):
if value.startswith("[current data]"):
data_path = os.path.join("input", "drive_cycles")
data_path = os.path.join(
pybamm.root_dir(), "pybamm", "input", "drive_cycles"
)
filename = os.path.join(data_path, value[14:] + ".csv")
function_name = value[14:]
else:
Expand Down
16 changes: 8 additions & 8 deletions pybamm/processed_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def initialise_1D(self):
)

self.entries = entries
self.dimensions = 1
self.dimensions = 0

def initialise_2D(self):
len_space = self.base_eval.shape[0]
Expand Down Expand Up @@ -147,7 +147,7 @@ def initialise_2D(self):

# assign attributes for reference (either x_sol or r_sol)
self.entries = entries
self.dimensions = 2
self.dimensions = 1
if self.domain[0] in ["negative particle", "positive particle"]:
self.first_dimension = "r"
self.r_sol = space
Expand Down Expand Up @@ -243,7 +243,7 @@ def initialise_3D(self):

# assign attributes for reference
self.entries = entries
self.dimensions = 3
self.dimensions = 2
self.first_dim_pts = first_dim_pts
self.second_dim_pts = second_dim_pts

Expand Down Expand Up @@ -307,7 +307,7 @@ def initialise_3D_scikit_fem(self):

# assign attributes for reference
self.entries = entries
self.dimensions = 3
self.dimensions = 2
self.y_sol = y_sol
self.z_sol = z_sol
self.first_dimension = "y"
Expand All @@ -322,15 +322,15 @@ def __call__(self, t=None, x=None, r=None, y=None, z=None, warn=True):
"""
Evaluate the variable at arbitrary t (and x, r, y and/or z), using interpolation
"""
if self.dimensions == 1:
if self.dimensions == 0:
out = self._interpolation_function(t)
elif self.dimensions == 1:
out = self.call_2D(t, x, r, z)
elif self.dimensions == 2:
if t is None:
out = self._interpolation_function(y, z)
else:
out = self.call_2D(t, x, r, z)
elif self.dimensions == 3:
out = self.call_3D(t, x, r, y, z)
out = self.call_3D(t, x, r, y, z)
if warn is True and np.isnan(out).any():
pybamm.logger.warning(
"Calling variable outside interpolation range (returns 'nan')"
Expand Down
Loading

0 comments on commit c1e615e

Please sign in to comment.