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

Why does the system method take an unmutable reference to self? #15

Open
thdhondt opened this issue Jan 4, 2023 · 3 comments
Open

Why does the system method take an unmutable reference to self? #15

thdhondt opened this issue Jan 4, 2023 · 3 comments

Comments

@thdhondt
Copy link

thdhondt commented Jan 4, 2023

Hi @srenevey ,

First of all, thanks a lot for the work you have put into this crate!
It has been really helpful for getting started with numerical simulation using Rust.

I was wondering if there was a specific reason why the system method in the System trait took an unmutable reference to self:

/// Trait needed to be implemented by the user.
pub trait System<V> {
    fn system(&self, x: f64, y: &V, dy: &mut V);
}

The system I am currently simulating has a small controller built-in.
It is a simple state machine that transitions based on the values inside the State vector.
Unfortunately, I am unable to store this data inside my object implementing the System trait, as I can't modify it via the &self reference.

I am currently a beginner in Rust, so I'm mostly interested in understanding if this was an explicit design decision or just a use case that was not yet covered :).

Thanks in advance for your assistance.

Thomas

@srenevey
Copy link
Owner

Hi Thomas,

Thanks for reaching out, it's always great to hear from people using the crate!

As for your question, there's no specific reason why an immutable reference is used as opposed to a mutable one. I didn't encounter your use case when I was developing the crate for my projects and hence didn't cover it. What you can try is fork the crate and modify the signature of the method to accept a mutable reference.

Best,

@thdhondt
Copy link
Author

This is what I did (https://github.com/thdhondt/ode-solvers/tree/Solout-for-other-solvers-and-allocation-reduction) and it works perfectly.

I did start from another fork, however, as I also needed the solout method for the Rk4 solver.

@MaygurovMV
Copy link

Hello @thdhondt, thanks for your solution. It helps me for my system. It has a couple of equations those dont not figured as y' = f(x) form. But it changes over time. It's be wonderful if this fork will be merged as soon as possible.

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

3 participants