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

How do I use callback_initializealg? #3298

Closed
tpdsantos opened this issue Jan 8, 2025 · 6 comments
Closed

How do I use callback_initializealg? #3298

tpdsantos opened this issue Jan 8, 2025 · 6 comments
Labels
question Further information is requested

Comments

@tpdsantos
Copy link

Question❓

I'm trying to model a chromatographic column, which involves a second-order PDE in space. At some points in time, I change the flowrate and concentration in the beginning of the column through discrete callbacks but I get initialization errors. I tried to use the initializealg = ShampineCollocationInit() option inside solve, but to no avail. After reading #3254 I found out about the callback_initializealg option that I wanted to try, but how and where should I use it?

Thanks

@tpdsantos tpdsantos added the question Further information is requested label Jan 8, 2025
@AayushSabharwal
Copy link
Member

callback_initializealg is a lower-level detail. In MTK, you can set it by providing the reinitializealg keyword to SymbolicContinuousCallback or SymbolicDiscreteCallback. The docstring for SymbolicContinuousCallback describes this.

@tpdsantos
Copy link
Author

I see. And how would I add this keyword considering I introduced my callbacks inside @mtkmodel in the @discrete_events environment? or would I need to provide it separately in order to use it?

@AayushSabharwal
Copy link
Member

Just normally:

@discrete_events begin
    ModelingToolkit.SymbolicDiscreteCallback(condition, affect; reinitializealg = ShampineCollocationInit())
end

inside the @mtkmodel macro.

@tpdsantos
Copy link
Author

tpdsantos commented Jan 9, 2025

Thanks a lot, the BrownFullBasicInit() works like a charm! It helped me a lot, I didn't know you could pass a function directly in the environment.

@AayushSabharwal
Copy link
Member

I didn't know you could pass a function directly in the environment.

Yeah we aren't fully transparent about the things you can do inside @mtkmodel. For the most part, it works like the docs but there are edge cases like this and the other issue you opened.

Can this issue be closed now?

@tpdsantos
Copy link
Author

Yes, it answered my question and solved my problem, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants