CasADi Integrator setup for transport equation

22 Ansichten (letzte 30 Tage)
Cedric
Cedric am 12 Dez. 2023
Bearbeitet: Cedric am 12 Dez. 2023
Hello there,
I am using Matlab R2023a and the CasADi (https://web.casadi.org/) 3.6.4 version for Windows.
What I want to do with it is to solve a transport/traffic equation with the algorithm of CasADi of the following form:
ρ: density
: constant velocity
h: spatial step size
So you can see that this is an ODE with in which I already discretized the spatial differentiation. For describing my problem I set the initial condition of rho to a gaussian and the boundary condition on the "left side" to stay constant. I setup a grid with 40 grid points and want to integrate over one time step. In the following you see the code that I used until now:
addpath(genpath("casadi-3.6.4-windows64-matlab2018b"));
import casadi.*
%% Integrator creation
% symbolic variables for setting up the integrator
rho = MX.sym('rho',[params.sim.gridPoints,1]);
dxi = MX.sym('dxi');
u_dot = MX.sym('u_dot');
v_const = MX.sym('v_const');
% model equations
x =[rho]; % state
p =[u_dot;v_const;dxi] % parameters
diffEquation =[u_dot; % first grid point bc of boundary condition
-v_const*(rho(2:end)-rho(1:end-1))/dxi; % all other points
];
% summing up the dynamics
mySys = struct('x',x,'p',p,'ode',diffEquation);
% create integrator
TranspIntegrator=integrator('TranspIntegrator','collocation',mySys);
disp(TranspIntegrator)
%% Problem Solution
u_dot = 0; % this is the left boundary condition. With u_dot=0 the most left rho value should stay the same.
v_const = 100; % chosen constant velocity
dxi = 1; % spatial step size
% create initial condition
xAxes = linspace(0,4,40); % spatial vector for creating initial condition
rho_0 = (10+(250-40)*gaussmf(xAxes,[0.5 2]))'; % gaussian initial condition
disp(x_0)
r = TranspIntegrator('x0',rho_0,'p',[u_dot;v_const;dxi]);
disp(r.xf)
The displayed result looks like this:
[10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704, 10.0704]
Regarding the fact that I have a constant velocity in a transport equation I would expect my rho values to shift along the x Axes in positiv direction. What the results are giving me are 40 values that are in direct realtion to rho_0(1) and u_dot (when I changed this value there where slight changes in the result).
I guess I missed something in the implementation of the solving algorithm but I could not find it. So I am asking for your help. If I forgot some crutial information I will deliver it afterwards. Anyway I already want to thank you for any help. Best Regards!

Akzeptierte Antwort

Torsten
Torsten am 12 Dez. 2023
Bearbeitet: Torsten am 12 Dez. 2023
With a velocity of 100 and a length of 4 for the region of integration, it takes at most 4/100 sec until "rho" gets constant and equal to its value at the inlet. What is the time for which you received the result vector ?
  5 Kommentare
Torsten
Torsten am 12 Dez. 2023
Bearbeitet: Torsten am 12 Dez. 2023
Yes, the speed of transport looks correct now. But the dissipation is far too strong. The curve in its form should remain - it should only be translated to the right. But the peak gets lower and the whole curve smears out. This is due to your first-order discretization with Euler backwards in space. You will either need many more grid points or an upwind discretization of second order to keep your curve in its original form.
Cedric
Cedric am 12 Dez. 2023
Bearbeitet: Cedric am 12 Dez. 2023
I see your point and will consider these steps in my ongoing work. Thanks for your great help :)
If there will come up some more interesting things up I will post theme here.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by