Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

User tables from usertab.h

User tables from usertab.h

Hello,

The Modelica.Blocks.Tables library info, describes "Special interest topic: Statically stored tables for real-time simulation targets". these use  "usertab.c" and "usertab.h" files, and an example of how to use them is given. I've had to modify the example slightly (one too many / in the url and initial clock values required), as shown below. When compiled, the following error is displayed (next below). Any suggestions as what should be changed to get this to compile?

Thanks, Bob

C:/OpenModelica1.9.4-dev//lib//omc/libModelicaStandardTables.a(ModelicaStandardTables.o): In function `usertab':
c:\dev\OpenModelica\OMCompiler\3rdParty\ModelicaExternalC\BuildProjects\autotools/../../C-Sources/ModelicaStandardTables.c:4526: multiple definition of `usertab'
Test25_usertab_v2_functions.o:Test25_usertab_v2_functions.ccurrent/sad.text+0x1a4): first defined here
collect2: ld returned 1 exit status
\MinGW\bin\mingw32-make: *** [omc_main_target] Error 1
Compilation process failed. Exited with code 2.



model Test25_usertab_v2
  extends Modelica.Icons.Example;
public
  Modelica.Blocks.Sources.RealExpression realExpression(y=getUsertab(t_new.y))
    annotation (Placement(transformation(extent={{-40,-34},{-10,-14}})));
  Modelica.Blocks.Tables.CombiTable1D t_new(tableOnFile=true, tableName="TestTable_1D_a")
    annotation (Placement(transformation(extent={{-40,0},{-20,20}})));
  Modelica.Blocks.Sources.Clock clock(offset = 0, startTime = 0) annotation (Placement(transformation(extent={{-80,0},{-60,20}})));
protected
  encapsulated function getUsertab
    input Real dummy_u[:];
    output Real dummy_y;
   
    external "C" dummy_y=  mydummyfunc(dummy_u);
    annotation(IncludeDirectory="modelica://Modelica/Resources/Data/Tables",
           Include = "#include \"usertab.c\"
double mydummyfunc(const double* dummy_in) {
        return 0;
}
");
  end getUsertab;
equation
  connect(clock.y,t_new. u[1]) annotation (Line(
      points={{-59,10},{-42,10}},
      color={0,0,127},
      smooth=Smooth.None));
  annotation (experiment(StartTime=0, StopTime=5), uses(Modelica(version="3.2.1")));
end Test25_usertab_v2;

Re: User tables from usertab.h

Hello,

I don't know C/C++ coding, but Googling here gives a possible clue. I searched for "usertab" within *.h and *.c files in the OpenModelica install directory.

The files "ModelicaStandardTables.c" and the "usertab.c" files both have an int declaration "usetab" i.e. int usertab(char *tableName, int nipo, int dim[], int *colWise,
            double **table) {...

I tried making the "int" in usetab.c a "static int", which enabled the model to be compiled, but then simulation output gives the error message:

Function "usertab" is not implemented
Process crashed
Simulation process failed. Exited with code -1.

Thanks, Bob

There are 0 guests and 0 other users also viewing this topic