필터 지우기
필터 지우기

Save/use intermediate values on ode solver

조회 수: 4 (최근 30일)
Thales
Thales 2019년 4월 5일
댓글: Pan Zhao 2021년 8월 17일
I am doing a time integration of a system of ODEs using a stiff solver (ode15s). It is working, but I want to speed things up.
The system of equations is given in state space form:
function [dx] = fun(t,x,M,C,K,other_parameters)
% Mx'' + Cx' + Kx = F(t)
% BUNCH OF CALCULATIONS
F = myfun(x,t);
A = [zeros(n) eye(n) ; -M\K -M\C];
b = M\F;
dx = A*x + b
end
The trick part here is the forcing function F. It is highly nonlinear and depends on the x and t parameters. It uses the x parameters to solve a Poisson-type 2D equation (by the Finite Volume method). The force F is proportional to the Poisson equation solution.
function [F] = solveP()
% initialize solution
Phi = zeros(Ni,Nj);
% solve iteratively
% ...
% calculate F
F = sum(Phi(:)); % discrete integration over domain
end
Solving the Poisson equation by a iterative method requires an initial condition, which I set to zero (Phi=zeros(Ni,Nj)). I thought I could improve the speed of calculations by providing a better initial estimative of the ϕ field (a better initial condition would take faster to reach the sought answer). The optimal initial condition I can think (besides ) is the value of the ϕ field obtained in the previous iteration (the last step) of the ode solver (.
Bottom line is: how do I use/save intermediate values in the ode solution?
PS: I tried using the persistent variables, but that is not a good solution. The ode solver calculates the function in several points before advancing in time. The persistent variable saves the converged ϕ field every time the ode calls the odefun fun. That is not exactly what I want.

답변 (1개)

Pan Zhao
Pan Zhao 2021년 8월 10일
I have a similar problem. Did you manage to solve your problem?
  댓글 수: 2
Thales
Thales 2021년 8월 13일
Unfortunately, no.
The best I could come up with was to write my own integrator. Clearly, it is not as good as MATLAB's built-in ode, but I can return other variables in the function fun being integrated and use them in the time marching scheme.
Pan Zhao
Pan Zhao 2021년 8월 17일
@Thales Thank you for the update.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by