I want to stop the simulation when my output reaches a certain limit or value irrespective of the simulation time. Let's take an example my output is 'prod' a variable which has the product of two numbers stored in it. If the product of the two numbers is greater than 12 then the simulation must stop irrespective of the other values left in the array.
is there any keyword which would do this in open modelica? I tried using the break and terminate command, but the output of prod after 3 seconds reached 12 and then the plot continued for 5 seconds(which was the simulation time) and the value stored in prod was zero. I want my simulation to stop and the product is 12 and it should not calculate the product after that and shouldn't display those values in the plot as well.
model ForLoopExample;
Real A[5] = {1,2,3,4,5};
Real B[5] = {2,3,4,5,6};
Real prod[5];
Boolean test_case(start = false);
algorithm
for i in 1:size(A,1) loop
prod[i]:=A[i]*B[i];
if prod[i]>=12 then
test_case = true;
break;
end if;
end for;
when test_case then
terminate("product above 12");
end when;
end ForLoopExample;