Compiler errors 使用OpenModelica v1.14.1(64位)编译简单Modelica代码时出现多个未声明的标识符错误

Compiler errors 使用OpenModelica v1.14.1(64位)编译简单Modelica代码时出现多个未声明的标识符错误,compiler-errors,modelica,openmodelica,Compiler Errors,Modelica,Openmodelica,OpenModelica生成的以下简单Modelica模型的C源代码无法编译。这很尴尬,因为C编译器会抱怨缺少符号,而这些符号应该由工具自动生成。但是,我可以补充一点,该模型没有与Dymola进行核对。报告了几个错误,第一个是边缘(particles[bIdx].alive)中的操作数必须是变量。,就我对语言的理解而言,情况并非如此 我希望通过下面的源代码,有人可以了解一下这种情况,并确定我是否做错了什么(模型不应该检查得很好),或者我在C源代码生成器(和Dymola翻译程序)中发现了错误 干杯

OpenModelica生成的以下简单Modelica模型的C源代码无法编译。这很尴尬,因为C编译器会抱怨缺少符号,而这些符号应该由工具自动生成。但是,我可以补充一点,该模型没有与Dymola进行核对。报告了几个错误,第一个是
边缘(particles[bIdx].alive)中的操作数必须是变量。
,就我对语言的理解而言,情况并非如此

我希望通过下面的源代码,有人可以了解一下这种情况,并确定我是否做错了什么(模型不应该检查得很好),或者我在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;
模型测试算法
导入SI=Modelica.SIunits;
模型粒子
导入SI=Modelica.SIunits;
SI.长度s“粒子位置”;
速度v“粒子的速度”;
实θ“粒子传输的量”;
实际α(最小值=0,最大值=1);
布尔活着;
//整数活动;//这没用
//真正活着;//这甚至不能翻译
方程式
der(s)=v;
der(θ)=0;
末端粒子;
参数SI.Length L=10“盒子的长度”;
参数整数nParticle=4“粒子数”;
参数SI.速度v=1.5;
参数SI.Length Ds=L/nParticle;
粒子[nParticle+1];
受保护的
整数aIdx;
整数bIdx;
初始算法
aIdx:=1;
bIdx:=nParticle+1;
初始方程
对于i in 1:(nParticle+1)循环
粒子[i].s=(i-1)*Ds;//粒子的初始位置
粒子[i].alive=true;
//粒子[i]。活动=1;//与整数和实数一起使用
粒子[i].v=v;//副桨初速度
结束于;
对于1中的i:整数(nParticle/4)循环
粒子[i],θ=2;
结束于;
对于(整数(nParticle/4)+1)中的i:(nParticle+1)循环
粒子[i],θ=1;
结束于;
//注意!将alpha初始化从初始算法移动到初始方程,使模型可转换为C(仍然未编译)
粒子[1],α=0.5;
对于2中的i:nParticle循环
粒子[i],α=1.0;
结束于;
粒子[nParticle+1]。alpha=0.5;
算法
什么时候
(边(粒子[bIdx].alive)和前置(粒子[bIdx].alive))或
(边(粒子[aIdx].alive)和前置(粒子[aIdx].alive)),然后
//(更改(粒子[bIdx].alive)和pre(粒子[bIdx].alive)==1)或//与整数和实数一起使用
//(更改(粒子[aIdx].alive)和pre(粒子[aIdx].alive)==1),然后//与整数和实数一起使用
如果v>=0,则
aIdx:=bIdx;
bIdx:=mod(bIdx-1-1,nParticle+1)+1;
其他的
bIdx:=aIdx;
aIdx:=mod(aIdx+1-1,nParticle+1)+1;
如果结束;
结束时;
//(nParticle+1)*3方程
对于1中的i:nParticle+1循环
粒子[i].活动:=(粒子[i].s+Ds/2>0)和(粒子[i].s-Ds/2<1);
//粒子[i].alive:=如果(粒子[i].s+Ds/2>0)和(粒子[i].s-Ds/2L则粒子[i].s-L)/Ds+1/2否则1;
结束于;
方程式
什么时候
(边(粒子[bIdx].alive)和前置(粒子[bIdx].alive))或
(边(粒子[aIdx].alive)和前置(粒子[aIdx].alive)),然后
//(更改(粒子[bIdx].alive)和pre(粒子[bIdx].alive)==1)或//与整数和实数一起使用
//(更改(粒子[aIdx].alive)和pre(粒子[aIdx].alive)==1),然后//与整数和实数一起使用
如果v>=0,则
reinit(粒子[aIdx].s,粒子[mod(aIdx+1-1,nParticle+1)+1].s-Ds);
reinit(粒子[aIdx].θ,粒子[aIdx].θ);//用于调试目的的循环条件
其他的
reinit(粒子[bIdx].s,粒子[mod(bIdx-1-1,nParticle+1)+1].s+Ds);
reinit(粒子[bIdx].θ,粒子[bIdx].θ);//用于调试目的的循环条件
如果结束;
结束时;
对于1中的i:nParticle+1循环
粒子[i].v=v;
结束于;
注释();
终端测试算法;
错误消息是

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
C:/Program Files/OpenModelica1.14.1-64位//共享/omc/scripts/Compile.bat测试算法gcc mingw64并行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:正在输入目录“C:/Users/ASOPPE~1/AppData/Local/Temp/OPENMO~1/OMEdit/TESTAL~1”
gcc-Os-fallign functions-fno ipa pure const-mstackreallign-msse2-mfpmath=sse-I“C:/Program Files/OpenModelica1.14.1-64位//include/omc/C”-I.-DOPENMODELICA\u XML\u FROM\u FILE\u AT\u RUNTIME-DOMC\u MODEL\u PREFIX=TestAlgorithm-DOMC\u NUM\u MIXED\u SYSTEMS=0-DOMC\u NUM\u LINEAR\u SYSTEMS=0-DOMC\u NUM\u NONLINEAR\u SYSTEMS=1-DOMC\u NDELAY\u EXPRESSIONS=0-DOMC\u NVAR\u STRING=0-c-o TestAlgorithm.o TestAlgorithm.c
gcc-Os-fallign functions-fno ipa pure const-mstackreallign-msse2-mfpmath=sse-I“C:/Program Files/OpenModelica1.14.1-64位//include/omc/C”-I.-DOPENMODELICA\u XML\u来自运行时的文件\u-DOMC\u-MODEL\u PREFIX=TestAlgorithm-DOMC\u NUM\u MIXED\u SYSTEMS=0-DOMC\u NUM\u LINEAR\u SYSTEMS=0-DOMC\u NUM\u非线性\u SYSTEMS=1-DOMC\u NDELAY\u表达式=0-DOMC\u NVAR\u STRING=0-c-o TestAlgorithm\u functions.o TestAlgorithm\u functions.c
gcc-Os-fallign functions-fno ipa pure const-mstackreallign-msse2-mfpmath=sse-I“C:/Program Files/OpenModelica1.14.1-64位//include/omc/C”-I.-DOPENMODELICA\u XML\u来自运行时的文件\u-DOMC\u-MODEL\u PREFIX=TestAlgorithm-DOMC\u NUM\u MIXED\u SYSTEMS=0-DOMC\u NUM\u LINEAR\u SYSTEMS=0-DOMC\u NUM\u非线性\u SYSTEMS=1-DOMC\u NDELAY\u表达式=0-DOMC\u NVAR\u STRING=0-c-o TestAlgorithm\u records.o TestAlgorithm\u records.c
gcc-Os-FALLIGN函数-fno ipa纯常量-mstackrealign-msse2-mfpmath=sse