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 to customize solver algorithm: May be needed in some physical problem. #873

Closed
fangrh opened this issue Jun 11, 2022 · 9 comments
Closed

Comments

@fangrh
Copy link

fangrh commented Jun 11, 2022

In the document, the code below can get a serial of solutions with time step of 1e-8.
sol = solve(prob, Tsit5(), saveat=1e-8)
However, in some case, we only concern about the sum of these solutions. To achieve this, I get a serial of solutions firstly and then calculate the sum of these solutions. This cost may memory resource since we should save all the solutions in memory.
My question is

  1. Can we just calculate the sum of solutions at every step.
  2. Is there possible to customize solver algorithm as like Tsit5(), TRBDF2() ...
@ChrisRackauckas
Copy link
Member

Is there possible to customize solver algorithm as like Tsit5(), TRBDF2() ...

What do you mean?

Can we just calculate the sum of solutions at every step.

Yes, see the documentation on SavingCallback. https://diffeq.sciml.ai/stable/features/callback_library/#saving_callback

@fangrh
Copy link
Author

fangrh commented Jun 11, 2022

Yes, see the documentation on SavingCallback. https://diffeq.sciml.ai/stable/features/callback_library/#saving_callback

Thanks very much.

What do you mean?

sol = solve(prob, alg, saveat=1e-8)
I mean how to customize algorithm for the alg argument.

@ChrisRackauckas
Copy link
Member

Customize what?

@fangrh
Copy link
Author

fangrh commented Jun 11, 2022

Customize OrdinaryDiffEqAlgorithm or OrdinaryDiffEqAdaptiveAlgorithm

@ChrisRackauckas
Copy link
Member

I still have no idea what you're asking for. Customizing what about them? Do you mean https://diffeq.sciml.ai/stable/solvers/ode_solve/#Extra-Options ?

@fangrh
Copy link
Author

fangrh commented Jun 11, 2022

I still have no idea what you're asking for. Customizing what about them? Do you mean https://diffeq.sciml.ai/stable/solvers/ode_solve/#Extra-Options ?

Although it is different from my origin diea, maybe this is a more fashionable way. Let me try. Thanks again.

@ChrisRackauckas
Copy link
Member

Can you describe what you're asking for?

@fangrh
Copy link
Author

fangrh commented Jun 11, 2022

I want to customized the MyCustomAlgorithm

using DifferentialEquations
f(u,p,t) = 1.01*u
u0 = 1/2
tspan = (0.0,1.0)
prob = ODEProblem(f,u0,tspan)
struct MyCustomAlgorithm <: OrdinaryDiffEqAdaptiveAlgorithm end # I want to customize a algorithm.
sol = solve(prob, MyCustomAlgorithm(), reltol=1e-8, abstol=1e-8) # And used for solve function

@ChrisRackauckas
Copy link
Member

See the developer docs section.

https://docs.sciml.ai/dev/modules/DiffEqDevDocs/contributing/adding_packages/

https://github.com/SciML/SimpleDiffEq.jl/blob/master/src/tsit5/gpuatsit5.jl are some simple examples.

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