исходный код C следующей простой модели Modelica, сгенерированной OpenModelica, не компилируется. Это неудобно, потому что компилятор C жалуется на пропущенные символы, которые должны генерироваться инструментом автоматически. Однако могу добавить, что модель не проверяется с помощью Dymola. Сообщается о нескольких ошибках, первой из которых является The operand in edge(particles[bIdx].alive) must be a variable.
, что, насколько я понял язык, не так.
Я надеюсь, что с исходным кодом ниже кто-то может пролить немного света на эта ситуация и может установить sh, если я сделал что-то не так (модель не должна проверяться) или я обнаружил ошибку в генераторе C (и переводчике Dymola).
Приветствия!
model TestAlgorithm
import SI = Modelica.SIunits;
model Particle
import SI = Modelica.SIunits;
SI.Length s "Position of the particle";
SI.Velocity v "Velocity of the particle";
Real theta "Quantity transported by the particle";
Real alpha(min = 0, max = 1);
Boolean alive;
// Integer alive; // This doen't help
// Real alive; // This don't even translate
equation
der(s) = v;
der(theta) = 0;
end Particle;
parameter SI.Length L = 10 "Length of the box";
parameter Integer nParticles = 4 "Number of particles";
parameter SI.Velocity v = 1.5;
parameter SI.Length Ds = L/nParticles;
Particle particles[nParticles+1];
protected
Integer aIdx;
Integer bIdx;
initial algorithm
aIdx := 1;
bIdx := nParticles + 1;
initial equation
for i in 1:(nParticles + 1) loop
particles[i].s = (i - 1)*Ds; // Initial position of the particles
particles[i].alive = true;
// particles[i].alive = 1; // To be used with Integer and Real
particles[i].v = v; // Initial velocity of the paraticles
end for;
for i in 1:integer(nParticles/4) loop
particles[i].theta = 2;
end for;
for i in (integer(nParticles/4)+1):(nParticles + 1) loop
particles[i].theta = 1;
end for;
// Note! Moving alpha initialization from initial algorithm to initial equation made the model translable to C (still not compiling)
particles[1].alpha = 0.5;
for i in 2:nParticles loop
particles[i].alpha = 1.0;
end for;
particles[nParticles+1].alpha = 0.5;
algorithm
when
(edge(particles[bIdx].alive) and pre(particles[bIdx].alive)) or
(edge(particles[aIdx].alive) and pre(particles[aIdx].alive)) then
// (change(particles[bIdx].alive) and pre(particles[bIdx].alive)==1) or // To be used with Integer and Real
// (change(particles[aIdx].alive) and pre(particles[aIdx].alive)==1) then // To be used with Integer and Real
if v >= 0 then
aIdx := bIdx;
bIdx := mod(bIdx - 1 - 1, nParticles + 1) + 1;
else
bIdx := aIdx;
aIdx := mod(aIdx + 1 - 1, nParticles + 1) + 1;
end if;
end when;
//(nParticles + 1)*3 equations
for i in 1:nParticles + 1 loop
particles[i].alive := (particles[i].s + Ds/2 > 0) and (particles[i].s - Ds/2 < L);
// particles[i].alive := if (particles[i].s + Ds/2 > 0) and (particles[i].s - Ds/2 < L) then 1 else 0; // To be used with Integer and Real
particles[i].alpha := if (particles[i].s - Ds/2) < 0 then particles[i].s/Ds + 1/2 else if (particles[i].s + Ds/2) > L then (particles[i].s - L)/Ds + 1/2 else 1;
end for;
equation
when
(edge(particles[bIdx].alive) and pre(particles[bIdx].alive)) or
(edge(particles[aIdx].alive) and pre(particles[aIdx].alive)) then
// (change(particles[bIdx].alive) and pre(particles[bIdx].alive)==1) or // To be used with Integer and Real
// (change(particles[aIdx].alive) and pre(particles[aIdx].alive)==1) then // To be used with Integer and Real
if v >= 0 then
reinit(particles[aIdx].s, particles[mod(aIdx + 1 - 1, nParticles+1) + 1].s - Ds);
reinit(particles[aIdx].theta, particles[aIdx].theta); // Loop condition for debug purposes
else
reinit(particles[bIdx].s, particles[mod(bIdx - 1 - 1, nParticles+1) + 1].s + Ds);
reinit(particles[bIdx].theta, particles[bIdx].theta); // Loop condition for debug purposes
end if;
end when;
for i in 1:nParticles + 1 loop
particles[i].v = v;
end for;
annotation ();
end TestAlgorithm;
Сообщение об ошибке:
C:/Program Files/OpenModelica1.14.1-64bit//share/omc/scripts/Compile.bat TestAlgorithm gcc mingw64 parallel 8 0
PATH = "C:\PROGRA~1\OPENMO~1.1-6\tools\msys\mingw64\bin;C:\PROGRA~1\OPENMO~1.1-6\tools\msys\mingw64\bin\..\..\usr\bin;"
mingw32-make: Entering directory 'C:/Users/ASOPPE~1/AppData/Local/Temp/OPENMO~1/OMEdit/TESTAL~1'
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm.o TestAlgorithm.c
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_functions.o TestAlgorithm_functions.c
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_records.o TestAlgorithm_records.c
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_01exo.o TestAlgorithm_01exo.c
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_02nls.o TestAlgorithm_02nls.c
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_03lsy.o TestAlgorithm_03lsy.c
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_04set.o TestAlgorithm_04set.c
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_05evt.o TestAlgorithm_05evt.c
TestAlgorithm.c: In function 'TestAlgorithm_eqFunction_60':
TestAlgorithm.c:339:5: error: 'particles' undeclared (first use in this function)
particles[aIdx].s = (&data->localData[0]->realVars[0] /* particles[1].s STATE(1,particles[1].v) */)[calc_base_index_dims_subs(1, 5, modelica_integer_mod(data->localData[0]->integerVars[0] /* aIdx DISCRETE */ + ((modelica_integer) 1) - ((modelica_integer) 1), tmp10) + ((modelica_integer) 1))] - data->simulationInfo->realParameter[0] /* Ds PARAM */;
^
TestAlgorithm.c:339:5: note: each undeclared identifier is reported only once for each function it appears in
TestAlgorithm.c:339:15: error: 'aIdx' undeclared (first use in this function)
particles[aIdx].s = (&data->localData[0]->realVars[0] /* particles[1].s STATE(1,particles[1].v) */)[calc_base_index_dims_subs(1, 5, modelica_integer_mod(data->localData[0]->integerVars[0] /* aIdx DISCRETE */ + ((modelica_integer) 1) - ((modelica_integer) 1), tmp10) + ((modelica_integer) 1))] - data->simulationInfo->realParameter[0] /* Ds PARAM */;
^
TestAlgorithm.c: In function 'TestAlgorithm_eqFunction_59':
TestAlgorithm.c:359:5: error: 'particles' undeclared (first use in this function)
particles[aIdx].theta = (&data->localData[0]->realVars[5] /* particles[1].theta STATE(1) */)[calc_base_index_dims_subs(1, 5, data->localData[0]->integerVars[0] /* aIdx DISCRETE */)];
^
TestAlgorithm.c:359:15: error: 'aIdx' undeclared (first use in this function)
particles[aIdx].theta = (&data->localData[0]->realVars[5] /* particles[1].theta STATE(1) */)[calc_base_index_dims_subs(1, 5, data->localData[0]->integerVars[0] /* aIdx DISCRETE */)];
^
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_06inz.o TestAlgorithm_06inz.c
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_07dly.o TestAlgorithm_07dly.c
gcc -Os -falign-functions -fno-ipa-pure-const -mstackrealign -msse2 -mfpmath=sse -I"C:/Program Files/OpenModelica1.14.1-64bit//include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=TestAlgorithm -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=1 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0 -c -o TestAlgorithm_08bnd.o TestAlgorithm_08bnd.c
<builtin>: recipe for target 'TestAlgorithm.o' failed