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

Domain error in Simulate #48

Open
DarioSlaifsteinSk opened this issue Aug 24, 2024 · 2 comments
Open

Domain error in Simulate #48

DarioSlaifsteinSk opened this issue Aug 24, 2024 · 2 comments

Comments

@DarioSlaifsteinSk
Copy link

Hi!
I'm getting

DomainError with -2.8947206947632367:
Exponentiation yielding a complex result requires a complex argument.
Replace x^y with (x+0im)^y, Complex(x)^y, or similar.

from line 224 in Simulate.jl.
This is probably because one of the concentrations Cseₙ, Ce or (cs_max .- Cseₙ) is going negative.

@DarioSlaifsteinSk
Copy link
Author

So, apparently the (cs_max .- Cseₙ) is going negative which means that the following is not working properly:

Results.Cseₙ[i + 1, :] = (SOCₙ .* Cell.Neg.cs_max .+
                                  Results.y[i + 1, CseNegInd]) >
                                 ones(size(Results.Cseₙ, 2)) * Cell.Neg.cs_max ?
                                 ones(size(Results.Cseₙ, 2)) * Cell.Neg.cs_max :
                                 (SOCₙ .* Cell.Neg.cs_max .+
                                  Results.y[i + 1, CseNegInd])

@DarioSlaifsteinSk
Copy link
Author

Two possible fixes.
If we want to keep replacing the whole row:

 Results.Cseₙ[i + 1, :] = any((SOCₙ .* Cell.Neg.cs_max .+
                                   Results.y[i + 1, CseNegInd]) .> Cell.Neg.cs_max) ?
                                  ones(size(Results.Cseₙ, 2)) * Cell.Neg.cs_max :
                                  (SOCₙ .* Cell.Neg.cs_max .+
                                   Results.y[i + 1, CseNegInd])

If we only want to replace the values out of the bounds:

# first define the concentration
Results.Cseₙ[i + 1, :] = SOCₙ .* Cell.Neg.cs_max .+ Results.y[i + 1, CseNegInd]
# then check and correct
any(Results.Cseₙ[i + 1, :] .> Cell.Neg.cs_max) ?
             Results.Cseₙ[i+1, Results.Cseₙ[i + 1, :] .> Cell.Neg.cs_max] .= Cell.Neg.cs_max :
             nothing

Was there any reason to replace the whole row?

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

1 participant