Skip to content
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

adding arctan function in pybamm #972

Closed
gyouhoc opened this issue Apr 29, 2020 · 4 comments
Closed

adding arctan function in pybamm #972

gyouhoc opened this issue Apr 29, 2020 · 4 comments

Comments

@gyouhoc
Copy link
Contributor

gyouhoc commented Apr 29, 2020

Hi,

I have a OCP function as

u_eq = (
    + 0.1493 + 0.8493*exp(-61.79*sto)
    + 0.3824*exp(-665.8*sto) - exp(-39.42*sto - 41.92)
- 0.03131*atan(25.59*sto - 4.099) 	
- 0.009434*atan(32.49*sto - 15.74)
)

And I just realize that there is no atan function defined in pybamm.
I tried to add an atan function as below but it doesn't work.
Would you let me know the proper way to add atan function in pybamm?

In the function file, I add following lines.

class Arctan(SpecificFunction):
""" Arctan function """

def __init__(self, child):
    super().__init__(np.arctan, child)

def _function_diff(self, children, idx):
    """ See :meth:`pybamm.Function._function_diff()`. """
    return 1 / (children[0] ** 2 + 1)

def atan(child):
" Returns hyperbolic tan function of child. "
return pybamm.simplify_if_constant(Arctan(child), keep_domains=True)

However, I still have a following error.

 18         + 0.3824*exp(-665.8*sto) - exp(-39.42*sto - 41.92)
 19         - 0.03131*atan(25.59*sto - 4.099)

---> 20 - 0.009434atan(32.49sto - 15.74)
21 )
22

NameError: name 'atan' is not defined

@valentinsulzer
Copy link
Member

Did you import atan in the first line of your ocp function file? (from pybamm import exp, atan)

@gyouhoc
Copy link
Contributor Author

gyouhoc commented Apr 29, 2020

Yes, I did.

Below is from my input file.

from pybamm import exp, atan

def graphite_ocp_NCM2020(sto):
"""
Graphite Open Circuit Potential (OCP) as a function of the stochiometry [1].

   References
   ----------
   .. [1] Kim, G. H., Smith, K., Lee, K. J., Santhanagopalan, S., & Pesaran, A.
   (2011). Multi-domain modeling of lithium-ion batteries encompassing
   multi-physics in varied length scales. Journal of The Electrochemical
   Society, 158(8), A955-A969.
   """

u_eq = (
    + 0.1493 + 0.8493*exp(-61.79*sto)
    + 0.3824*exp(-665.8*sto) - exp(-39.42*sto - 41.92)
- 0.03131*atan(25.59*sto - 4.099) 	
- 0.009434*atan(32.49*sto - 15.74)
)

return u_eq

@gyouhoc
Copy link
Contributor Author

gyouhoc commented Apr 29, 2020

Nevermind. It is working after I restart the code.

thx

@gyouhoc gyouhoc closed this as completed Apr 29, 2020
@valentinsulzer
Copy link
Member

Great! When you're ready, it would be great if you could open a PR adding the atan function to the code

@gyouhoc gyouhoc mentioned this issue Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants