-
Notifications
You must be signed in to change notification settings - Fork 33
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
Clean-up for PinTSimE + Update for SwitchEstimator (Preparation for PR for paper stuff) #362
Changes from 12 commits
4579dbc
7ef959a
6ddeb83
e094374
a1611eb
08f5e7d
6d8ab74
752ce4d
6b56883
2a5ee42
b7ea7b1
7ceec41
bfa7fed
7bafd80
b9bbb4b
e22f87d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,16 +60,24 @@ class battery_n_capacitors(ptype): | |
dtype_u = mesh | ||
dtype_f = imex_mesh | ||
|
||
def __init__(self, ncapacitors=2, Vs=5.0, Rs=0.5, C=None, R=1.0, L=1.0, alpha=1.2, V_ref=None): | ||
def __init__(self, ncapacitors=1, Vs=5.0, Rs=0.5, C=None, R=1.0, L=1.0, alpha=1.2, V_ref=None): | ||
"""Initialization routine""" | ||
n = ncapacitors | ||
nvars = n + 1 | ||
|
||
if C is None: | ||
C = np.array([1.0, 1.0]) | ||
if C is None and ncapacitors == 1: | ||
C = np.array([1.0]) | ||
else: | ||
assert type(C) == np.ndarray, '"C" needs to be an np.ndarray' | ||
assert np.shape(C)[0] == n, 'Number of capacitance values needs to be equal to number of condensators' | ||
|
||
if V_ref is None: | ||
V_ref = np.array([1.0, 1.0]) | ||
if V_ref is None and ncapacitors == 1: | ||
V_ref = np.array([1.0]) | ||
else: | ||
assert (alpha > V_ref[k] for k in range(n)), 'Please set "alpha" greater than values of "V_ref"' | ||
assert type(V_ref) == np.ndarray, '"V_ref" needs to be an np.ndarray' | ||
assert np.shape(V_ref)[0] == n, 'Number of reference values needs to be equal to number of condensators' | ||
assert (V_ref[k] > 0 for k in range(n)), 'Please set values of "V_ref" greater than 0' | ||
|
||
# invoke super init, passing number of dofs, dtype_u and dtype_f | ||
super().__init__(init=(nvars, None, np.dtype('float64'))) | ||
|
@@ -230,6 +238,7 @@ def get_switching_info(self, u, t): | |
switch_detected = False | ||
m_guess = -100 | ||
break_flag = False | ||
k_detected = 1 | ||
for m in range(1, len(u)): | ||
for k in range(1, self.nvars): | ||
h_prev_node = u[m - 1][k] - self.V_ref[k - 1] | ||
|
@@ -244,9 +253,7 @@ def get_switching_info(self, u, t): | |
if break_flag: | ||
break | ||
|
||
state_function = ( | ||
[u[m][k_detected] - self.V_ref[k_detected - 1] for m in range(len(u))] if switch_detected else [] | ||
) | ||
state_function = [u[m][k_detected] - self.V_ref[k_detected - 1] for m in range(len(u))] | ||
|
||
return switch_detected, m_guess, state_function | ||
|
||
|
@@ -443,11 +450,20 @@ def __init__( | |
newton_maxiter=100, | ||
newton_tol=1e-11, | ||
): | ||
n = ncapacitors | ||
if C is None: | ||
C = np.array([1.0]) | ||
else: | ||
assert type(C) == np.ndarray, '"C" needs to be an np.ndarray' | ||
assert np.shape(C)[0] == n, 'Number of capacitance values needs to be equal to number of condensators' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: |
||
|
||
if V_ref is None: | ||
V_ref = np.array([1.0]) | ||
else: | ||
assert alpha > V_ref[0], 'Please set "alpha" greater than values of "V_ref"' | ||
assert type(V_ref) == np.ndarray, '"V_ref" needs to be an np.ndarray' | ||
assert np.shape(V_ref)[0] == n, 'Number of reference values needs to be equal to number of condensators' | ||
assert V_ref[0] > 0, 'Please "V_ref" greater than 0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you check these things here? You inherit from the The only thing you need here is the variables for counting Newton iterations, which you should ideally replace with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right!
|
||
|
||
super().__init__(ncapacitors, Vs, Rs, C, R, L, alpha, V_ref) | ||
self._makeAttributeAndRegister('newton_maxiter', 'newton_tol', localVars=locals(), readOnly=True) | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I don't totally know what happens here. I usually use
all
orany
for asserting things like this. Since black did not complain, this must be valid. But please be sure that it does what you want it to do and consider addingall
to improve readability by being more explicit.Also, this line should come after the check if
V_ref
is an array at all to avoid confusing error messages.