Intersection Points On QSS Solver¶
model staticB_crossPlanesEfficient_intersectionVars
Real x, y, vx, vy;
parameter Real c = 299.792458;
parameter Real m = 0.510998910;
parameter Real v0 = 0.999*c;
parameter Real B = 0.001;
parameter Real q = 1.;
parameter Real gamma2 = 22.36627204213;
constant Integer N = 0;
parameter Real initialPosition = -40.0;
discrete Integer N1;
discrete Real distBetweenPlanes;
discrete Real crossedPlanes;
discrete Real rightPlane;
discrete Real leftPlane;
discrete Real xInt;
discrete Real yInt;
initial algorithm
x := 0;
y := 0;
vx := v0;
vy := 0;
crossedPlanes := 0;
distBetweenPlanes := -2.0 * initialPosition / (N + 1);
// Pesimo hack para testear paridad de N.
N1 := N;
for i in 1:N/2 loop
N1 := N1 - 2;
end for;
if (N1 == 0) then // N par
rightPlane := distBetweenPlanes/2;
else // N impar
rightPlane := distBetweenPlanes;
end if;
leftPlane := - rightPlane;
xInt := 0;
yInt := 0;
equation
der(vx) = q*B*c*c * vy / (m*gamma2);
der(vy) = -q*B*c*c * vx / (m*gamma2);
der(x) = vx;
der(y) = vy;
algorithm
when x > rightPlane then
crossedPlanes := crossedPlanes + 1;
rightPlane := rightPlane + distBetweenPlanes;
xInt := x;
yInt := y;
end when;
when x < leftPlane then
crossedPlanes := crossedPlanes + 1;
leftPlane := leftPlane - distBetweenPlanes;
xInt := x;
yInt := y;
end when;
when vx > 0 then
rightPlane := leftPlane + distBetweenPlanes;
end when;
when vx < 0 then
leftPlane := rightPlane - distBetweenPlanes;
end when;
annotation(
experiment(
MMO_Description="StaticB model with crossed planes counter",
MMO_Solver=QSS3,
MMO_Output={x,y,xInt,yInt},
StartTime= 0.0,
StopTime=3339,
Tolerance={ 1e-5},
AbsTolerance={ 1e-8}
));
end staticB_crossPlanesEfficient_intersectionVars;
- For further details about the experimentation click here.