Opened 11 years ago

Closed 9 years ago

Last modified 9 years ago

#2659 closed defect (fixed)

Initial equation called in each time step

Reported by: Martin Sjölund Owned by: Lennart Ochel
Priority: high Milestone: 1.9.4
Component: Backend Version: trunk
Keywords: Cc: Willi Braun, Lennart Ochel

Description

File.write is called 1003 times if the when-equation doesn't stop us. With the when-equation, it is called 113 times.
With -lv LOG_INIT I can tell that initialization finishes before the first call. So it is very much not an initial equation. The flat Modelica seems to suggest it is a front-end issue...

package File

class File
  extends ExternalObject;
  function constructor
    output File file;
  external "C" file=om_file_new() annotation(Include="
#ifndef __OMC_FILE_NEW
#define __OMC_FILE_NEW
#include <stdio.h>
#include <gc.h>
static inline void* om_file_new()
{
  return GC_malloc(sizeof(FILE*));
}
#endif
");
end constructor;
  function destructor
    input File file;
  external "C" om_file_free(file) annotation(Include="
#ifndef __OMC_FILE_FREE
#define __OMC_FILE_FREE
#include <stdio.h>
static inline void om_file_free(FILE **file)
{
  if (*file) {
    fclose(*file);
    *file = 0;
  }
}
#endif
");
  end destructor;
end File;

type Mode = enumeration(Read,Write);

function open
  input File file;
  input String filename;
  input Mode mode := Mode.Read;
  output Boolean success;
external "C" success = om_file_open(file,filename,mode) annotation(Include="
#ifndef __OMC_FILE_OPEN
#define __OMC_FILE_OPEN
#include <stdio.h>
static inline int om_file_open(FILE **file,const char *filename,int mode)
{
  if (*file) {
    fclose(*file);
  }
  *file = fopen(filename, mode == 1 ? \"rb\" : \"wb\");
  fflush(NULL);
  fprintf(stderr, \"opening file...\n\");
  return *file != 0;
}
#endif
");
end open;

function write
  input File file;
  input String data;
  output Boolean success;
external "C" success = om_file_write(file,data) annotation(Include="
#ifndef __OMC_FILE_WRITE
#define __OMC_FILE_WRITE
#include <stdio.h>
static inline int om_file_write(FILE **file,const char *data)
{
  if (!*file) {
    return 0;
  }
  fflush(NULL);
  fprintf(stderr, \"writing...\n\");
  return 1 == fputs(data,*file);
}
#endif
");
end write;

end File;

model M
  File.File file = File.File();
initial equation
  File.open(file,"abc.txt",File.Mode.Write);
  File.write(file,"def.fafaf\n");
equation
  when time>0.1 then
    terminate("time>0.1\n");
  end when;
end M;

Change History (12)

comment:1 by Lennart Ochel, 11 years ago

Owner: changed from somebody to Lennart Ochel
Status: newassigned

comment:2 by Martin Sjölund, 11 years ago

Owner: changed from Lennart Ochel to Martin Sjölund

comment:3 by Martin Sjölund, 11 years ago

I can fix the front-end stuff first ;)

comment:4 by Martin Sjölund, 11 years ago

Component: FrontendBackend
Owner: changed from Martin Sjölund to Lennart Ochel

I added a new record to DAE.mo that you can translate in the back-end :)

comment:5 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:6 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:7 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:8 by Lennart Ochel, 9 years ago

Status: assignedaccepted

comment:9 by Lennart Ochel, 9 years ago

Since the systems for simulation and initialization are separated now, it is easy to remove those asserts from the simulation system.

Version 0, edited 9 years ago by Lennart Ochel (next)

comment:10 by Lennart Ochel, 9 years ago

Resolution: fixed
Status: acceptedclosed

Fixed with #210.

comment:11 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

comment:12 by Martin Sjölund, 9 years ago

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.