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
  • Index
  • » Users
  • » abcxyz123
  • » Profile

Posts

Posts

Jan-28-15 10:40:59
Simualtion results are not shown. Error: Error while reading Simulation results
Category: Developer

It is obvious that the error occurs because of the size of 2,2 GB.
Is it possiple to manipulate the size of the .mat file, for example by changing the number of simulationsteps during the simualtion time.
I do not want to shorten the simulation time.

Jan-28-15 08:34:31
Simualtion results are not shown. Error: Error while reading Simulation results
Category: Developer

The mat-file Simulation1_res.mat size is 2,2 GB.
Does this have something to do with the error?

Jan-28-15 08:26:21
Simualtion results are not shown. Error: Error while reading Simulation results
Category: Developer

I have a strange problem.
I want to simulate a model in which I use an external C-Code Dll in the OMConnection Environment. When I simulate the Model with a Simulationtime 0,1 s everything works fine and I can see and plot the results. Setting time at 1 s ends up in the following mistake:

[:0:0-0:0] Error: Fehler beim Lesen des Simulationsergebnisses C:/Users/KIE2QS005/Documents/Entwicklung/OpenModelica/R06SimTest/Simulation1_res.mat: Corrupt header: data_2 matrix

I don't understand this. My Code must be correct because it works with a time 0,1 s, but something about reading the results doesn't work when time is bigger.
The error occurs after the Simulationprogress is 100 percent, not at the beginning of the Simulation.
I use Windows 7 and OpenModelica 1.9.1.

Does anybody know what to do?

Thanks for your help.
I did it a little bit diffrent, but now everything works fine.

Sorry for my missunderstanding.

Now I have another problem about the input arguments of my C-Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "Regler3.h"

void* RegelungInit( double pgain, double igain, double dTime, MyController * p )
{
    p->i_anteil = 0.0;
    p->pgain = pgain;
    p->igain = igain;
    p->dTime = dTime;
    return(NULL);
}

void* RegelungExit( MyController * p )
{
    return(NULL);
}

double Regler3( double target, double current, MyController * p )
{
    p->error = (target - current);
    p->p_anteil = p->error * p->pgain;
    p->i_anteil += (p->igain * p->error * p->dTime);
    p->out = p->p_anteil + p->i_anteil;

    return (p->out);
}

The Header:

typedef struct
{
    double error;
    double p_anteil;
    double pgain;
    double igain;
    double out;
    double i_anteil;
    double dTime;
} MyController;


void* RegelungInit(double pgain, double igain, double dTime, MyController * p );
void* RegelungExit( MyController * p);
double Regler3(double target, double current, MyController * p );


Obviously, I have to fit the headers. They have to have the same arguments as the functions in Modelica.

The Problem is, that I don't know how to make sure that the C-Code works, when I change the functions like this, because of the structure I use in all the C-functions:

void* RegelungInit( double pgain, double igain, double dTime );
void* RegelungExit();
double Regler3( double target, double current );


Sorry I am no expert at C-Code current/wink

Thanks for your quick reply.

I deleted "extends ModelicaReference.Classes.ExternalObject;" in class MyController, but without success.
Still I get the error: "Looking for a function MyController but found a class."

Do you have another idea?

Hey,
I try to create a sampled block PI-Controller (using external C-Code).
Besides, I want to use a class containing constructor and destructor as function, which causes the following problem.
I did it very similar to this describtion.
https://build.openmodelica.org/Document … bject.html

The main difference is, that I don't use a model, but a block, which I will use in a model later on.

When I simulate my block, I get this error:
"Looking for a function .MyController but found a class"

Here you can see my block:

block RegelungC3
  parameter Real pgain(unit = "1") = 1 "Proportional gain";
  parameter Real igain(unit = "1") = 1 "Integral gain";
  parameter Real dTime(unit = "s", final min = Modelica.Constants.small, start = 0.01) = 0.01 "Sample period";
  MyController controller = MyController(pgain = pgain, igain = igain, dTime = dTime);
  parameter Real t_start(unit = "s") = 0 "starttime";
  parameter Real target(unit = "rad/s") = 1 "Target angular velocity";
  Modelica.Blocks.Interfaces.RealInput current(unit = "rad/s") "Absolut angular velocity as input signal"
equation
  when sample(t_start, dTime) then
    y = Func3(target, current);
  end when;
end RegelungC3;

I tried to change the marked sentence to " MyController controller = MyController.constructor(...); without success.

How can I make sure that Modelica does not look for a function at this point or do I have to use a diffrent kind of class-declaration?

Here you can see the class:

class MyController
  extends ModelicaReference.Classes.ExternalObject;

  function constructor
    input Real pgain;
    input Real igain;
    input Real dTime;
    output MyController controller;
 
    external "C" controller = RegelungInit(pgain, igain, dTime) annotation(Library = "libRegler3.a", Include = "#include \"Regler3.h\"");
  end constructor;

  function destructor
    input MyController controller;
 
    external "C" RegelungExit(controller) annotation(Library = "libRegler3.a", Include = "#include \"Regler3.h\"");
  end destructor;
end MyController;


Thanks for your help.

  • Index
  • » Users
  • » abcxyz123
  • » Profile
You are here: