Skip to content

Commit

Permalink
- Rewrote the simulation runtime slightly
Browse files Browse the repository at this point in the history
  - names and comments of a variable is now stored in a record instead of different arrays
  - This record also contains the Absyn.Info information (filename, line/column start/end)
- Removed sendDataHumbug. It has been replaced with preprocessor macros that disable sendData


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7497 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Dec 19, 2010
1 parent e4d0a36 commit 0d3fed3
Show file tree
Hide file tree
Showing 29 changed files with 268 additions and 541 deletions.
40 changes: 22 additions & 18 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -240,7 +240,8 @@ uniontype SimVar
// arrayCref is the name of the array if this variable is the first in that
// array
Option<DAE.ComponentRef> arrayCref;
AliasVariable aliasvar;
AliasVariable aliasvar;
Absyn.Info info;
end SIMVAR;
end SimVar;

Expand Down Expand Up @@ -601,7 +602,7 @@ algorithm
errstr = "Template did not find the simulation variable for "+& ComponentReference.printComponentRefStr(cref) +& ". ";
Error.addMessage(Error.INTERNAL_ERROR, {errstr});
then
SIMVAR(badcref, BackendDAE.STATE(), "", "", "", -1, NONE(), false, DAE.ET_REAL(), false,NONE(),NOALIAS());
SIMVAR(badcref, BackendDAE.STATE(), "", "", "", -1, NONE(), false, DAE.ET_REAL(), false, NONE(), NOALIAS(), Absyn.dummyInfo);
end matchcontinue;
end cref2simvar;

Expand Down Expand Up @@ -5526,19 +5527,18 @@ algorithm
DAE.ExpType type_;
Boolean isDiscrete;
DAE.ComponentRef arrayCref;
case (SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, isFixed, type_, isDiscrete, NONE(),_))
Absyn.Info info;
case (SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, isFixed, type_, isDiscrete, NONE(),_, info))
equation
name = ComponentReference.crefPrefixDer(name);
then
SIMVAR(name, BackendDAE.STATE_DER(), comment, unit, displayUnit, index, NONE(), isFixed, type_,
isDiscrete, NONE(),NOALIAS());
case (SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, isFixed, type_, isDiscrete, SOME(arrayCref),_))
SIMVAR(name, BackendDAE.STATE_DER(), comment, unit, displayUnit, index, NONE(), isFixed, type_, isDiscrete, NONE(), NOALIAS(), info);
case (SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, isFixed, type_, isDiscrete, SOME(arrayCref),_, info))
equation
name = ComponentReference.crefPrefixDer(name);
arrayCref = ComponentReference.crefPrefixDer(arrayCref);
then
SIMVAR(name, BackendDAE.STATE_DER(), comment, unit, displayUnit, index, NONE(), isFixed, type_,
isDiscrete, SOME(arrayCref),NOALIAS());
SIMVAR(name, BackendDAE.STATE_DER(), comment, unit, displayUnit, index, NONE(), isFixed, type_, isDiscrete, SOME(arrayCref), NOALIAS(), info);
end matchcontinue;
end derVarFromStateVar;

Expand Down Expand Up @@ -5708,11 +5708,12 @@ algorithm
Integer index_;
AliasVariable aliasvar;
list<SimVar> rest,rest2;
Absyn.Info info;
case ({},_) then {};
case (SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, isFixed, type_, isDiscrete, arrayCref, aliasvar)::rest,index_)
case (SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, isFixed, type_, isDiscrete, arrayCref, aliasvar, info)::rest,index_)
equation
rest2 = rewriteIndex(rest, index_ + 1);
then (SIMVAR(name, kind, comment, unit, displayUnit, index_, initVal, isFixed, type_, isDiscrete, arrayCref, aliasvar)::rest2);
then (SIMVAR(name, kind, comment, unit, displayUnit, index_, initVal, isFixed, type_, isDiscrete, arrayCref, aliasvar, info)::rest2);
end matchcontinue;
end rewriteIndex;

Expand Down Expand Up @@ -5800,14 +5801,14 @@ algorithm
Option<DAE.ComponentRef> arrayCref;
AliasVariable aliasvar;
String varNameStr;
case (SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, isFixed, type_, isDiscrete, arrayCref, aliasvar), initCrefs)
Absyn.Info info;
case (SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, isFixed, type_, isDiscrete, arrayCref, aliasvar, info), initCrefs)
equation
(_ :: _) = Util.listSelect1(initCrefs, name, ComponentReference.crefEqualNoStringCompare);
varNameStr = ComponentReference.printComponentRefStr(name);
Error.addMessage(Error.SETTING_FIXED_ATTRIBUTE, {varNameStr});
then SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, false, type_, isDiscrete, arrayCref, aliasvar);
case (_, _)
then simvarIn;
Error.addSourceMessage(Error.SETTING_FIXED_ATTRIBUTE, {varNameStr}, info);
then SIMVAR(name, kind, comment, unit, displayUnit, index, initVal, false, type_, isDiscrete, arrayCref, aliasvar, info);
case (_, _) then simvarIn;
end matchcontinue;
end nonFixifyIfHasInit;

Expand Down Expand Up @@ -7848,6 +7849,8 @@ algorithm
Boolean isDiscrete;
Option<DAE.ComponentRef> arrayCref;
AliasVariable aliasvar;
DAE.ElementSource source;
Absyn.Info info;
case ((dlowVar as BackendDAE.VAR(varName = cr,
varKind = kind,
varDirection = dir,
Expand All @@ -7857,7 +7860,8 @@ algorithm
comment = comment,
varType = tp,
flowPrefix = flowPrefix,
streamPrefix = streamPrefix)),optAliasVars)
streamPrefix = streamPrefix,
source = source)),optAliasVars)
equation
commentStr = unparseCommentOptionNoAnnotationNoQuote(comment);
(unit, displayUnit) = extractVarUnit(dae_var_attr);
Expand All @@ -7867,9 +7871,9 @@ algorithm
isDiscrete = BackendVariable.isVarDiscrete(dlowVar);
arrayCref = getArrayCref(dlowVar);
aliasvar = getAliasVar(dlowVar,optAliasVars);
info = DAEUtil.getElementSourceFileInfo(source);
then
SIMVAR(cr, kind, commentStr, unit, displayUnit, indx, initVal, isFixed, type_, isDiscrete,
arrayCref,aliasvar);
SIMVAR(cr, kind, commentStr, unit, displayUnit, indx, initVal, isFixed, type_, isDiscrete, arrayCref, aliasvar, info);
end matchcontinue;
end dlowvarToSimvar;

Expand Down
2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -240,6 +240,7 @@ public constant ErrorID ZERO_STEP_IN_ARRAY_CONSTRUCTOR=152;
public constant ErrorID RECURSIVE_SHORT_CLASS_DEFINITION=153;
public constant ErrorID FUNCTION_ELEMENT_WRONG_PROTECTION=154;
public constant ErrorID FUNCTION_ELEMENT_WRONG_KIND=155;
public constant ErrorID WITHOUT_SENDDATA=156 "Used in external C sources; do not use another index";

public constant ErrorID UNBOUND_PARAMETER_WITH_START_VALUE_WARNING=499;
public constant ErrorID UNBOUND_PARAMETER_WARNING=500;
Expand Down Expand Up @@ -668,6 +669,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(RECURSIVE_SHORT_CLASS_DEFINITION,TRANSLATION(),ERROR(),"Recursive short class definition of %s in terms of %s"),
(FUNCTION_ELEMENT_WRONG_PROTECTION,TRANSLATION(),ERROR(),"%s was declared %s but should be %s."),
(FUNCTION_ELEMENT_WRONG_KIND,TRANSLATION(),ERROR(),"Element is not allowed in function context: %s"),
(WITHOUT_SENDDATA,SCRIPTING(),ERROR(),"%s failed because OpenModelica was configured without sendData support."),

(COMPILER_WARNING,TRANSLATION(),WARNING(),"%s")
};
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Util/System.mo
Expand Up @@ -256,7 +256,7 @@ public function sendData
input String yLabel;
input Boolean points;
input String range;
external "C" emulateStreamData(data, title, xLabel, yLabel , interpolation, legend, grid, logX, logY, points, range) annotation(Library = "omcruntime");
external "C" System_sendData(data, title, xLabel, yLabel , interpolation, legend, grid, logX, logY, points, range) annotation(Library = "omcruntime");
end sendData;

public function enableSendData
Expand All @@ -283,7 +283,7 @@ end setVariableFilter;
public function sendData2
input String info;
input String data;
external "C" emulateStreamData2(info, data, 7778) annotation(Library = "omcruntime");
external "C" System_sendData2(info, data, 7778) annotation(Library = "omcruntime");
end sendData2;

public function writeFile
Expand Down
26 changes: 25 additions & 1 deletion Compiler/runtime/System_omc.cpp
Expand Up @@ -380,7 +380,31 @@ extern void System_freeLibrary(int _inLibHandle)

extern int System_getHasSendDataSupport()
{
return CONFIG_WITH_SENDDATA;
#ifdef CONFIG_WITH_SENDDATA
return 1;
#else
return 0;
#endif
}

extern void System_sendData(const char* _data, const char* _title, const char* _xLabel, const char* _yLabel, const char* _interpolation, int _legend, int _grid, int _logX, int _logY, int _points, const char* _range)
{
#ifdef CONFIG_WITH_SENDDATA
emulateStreamData(_data, _title, _xLabel, _yLabel , _interpolation, _legend, _grid, _logX, _logY, _points, _range);
#else
addSendDataError("System.sendData");
throw 1;
#endif
}

extern void System_sendData2(const char* _info, const char* _data, int _port)
{
#ifdef CONFIG_WITH_SENDDATA
emulateStreamData2(_info, _data, _port);
#else
addSendDataError("System.sendData2");
throw 1;
#endif
}

extern int System_userIsRoot()
Expand Down
23 changes: 16 additions & 7 deletions Compiler/runtime/System_rml.c
Expand Up @@ -624,7 +624,7 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__sendData)
{

#ifdef CONFIG_WITH_SENDDATA
char* data = RML_STRINGDATA(rmlA0);
char* interpolation = RML_STRINGDATA(rmlA1);
char* title = RML_STRINGDATA(rmlA2);
Expand All @@ -645,23 +645,28 @@ RML_BEGIN_LABEL(System__sendData)

// emulateStreamData(data, 7778, title, "time", "", legend, grid, 0, 0, 0, 0, logX, logY, interpolation, 1);



emulateStreamData(data, title, xLabel, yLabel , interpolation, legend, grid, logX, logY, points, range);
RML_TAILCALLK(rmlSC);
#else
addSendDataError("System.sendData");
RML_TAILCALLK(rmlFC);
#endif

// emulateStreamData(data, 7778, "Plot by OpenModelica", "time", "", 1, 1, 0, 0, 0, 0, 0, 0, "linear");

RML_TAILCALLK(rmlSC);
}
RML_END_LABEL

RML_BEGIN_LABEL(System__sendData2)
{
#ifdef CONFIG_WITH_SENDDATA
char* info = RML_STRINGDATA(rmlA0);
char* data = RML_STRINGDATA(rmlA1);
emulateStreamData2(info, data, 7778);

RML_TAILCALLK(rmlSC);
#else
addSendDataError("System.sendData2");
RML_TAILCALLK(rmlFC);
#endif
}
RML_END_LABEL

Expand Down Expand Up @@ -706,7 +711,11 @@ RML_END_LABEL

RML_BEGIN_LABEL(System__getHasSendDataSupport)
{
rmlA0 = CONFIG_WITH_SENDDATA ? RML_TRUE : RML_FALSE;
#ifdef CONFIG_WITH_SENDDATA
rmlA0 = RML_TRUE;
#else
rmlA0 = RML_FALSE;
#endif
RML_TAILCALLK(rmlSC);
}
RML_END_LABEL
Expand Down
2 changes: 1 addition & 1 deletion Compiler/runtime/config.unix.h.in
@@ -1,7 +1,7 @@
/* @configure_input@ */
#define CONFIGURE_COMMANDLINE "Configured @date@ using arguments: '@CONFIGURE_ARGS@'"
#define LDFLAGS_SENDDATA "@LIBSENDDATA_LDFLAGS@ -lpthread"
#define CONFIG_WITH_SENDDATA @WITH_SENDDATA@
@WITH_SENDDATA@
#define CONFIG_EXE_EXT ""
#define CONFIG_DLL_EXT ".so"
#define CONFIG_PLATFORM "Unix"
Expand Down
25 changes: 21 additions & 4 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -111,9 +111,13 @@ static int hasStreamConnectors = 0;
static char* class_names_for_simulation = NULL;
static const char *select_from_dir = NULL;

#ifdef CONFIG_WITH_SENDDATA
// SendData crap
int getVariableListSize(const char* model);
unsigned char getVariableList(const char* model, char* lst);
void emulateStreamData(const char* data, const char*, const char*, const char*, const char*, int, int, int, int, int, const char*);
void emulateStreamData2(const char*, const char*, int);
#endif

/*
* Common implementations
Expand All @@ -132,7 +136,7 @@ static int stringContains(char *str,char c)

static int filterString(char* buf,char* bufRes)
{
int res,i,bufPointer = 0,slen,isNumeric=0,numericEncounter=0;
int i,bufPointer = 0,slen,isNumeric=0,numericEncounter=0;
char preChar,cc;
char filterChars[] = "0123456789.\0";
char numeric[] = "0123456789\0";
Expand Down Expand Up @@ -317,7 +321,6 @@ int SystemImpl__writeFile(const char* filename, const char* data)
#endif
FILE * file = NULL;
int len = strlen(data); /* RML_HDRSTRLEN(RML_GETHDR(rmlA1)); */
int x = 0;
/* adrpo: 2010-09-22 open the file in BINARY mode as otherwise \r\n becomes \r\r\n! */
file = fopen(filename,fileOpenMode);
if (file == NULL) {
Expand Down Expand Up @@ -513,7 +516,7 @@ extern int SystemImpl__directoryExists(const char *str)
char* SystemImpl__readFileNoNumeric(const char* filename)
{
char* buf, *bufRes;
int res,i,bufPointer = 0,numCount;
int res,bufPointer = 0,numCount;
FILE * file = NULL;
struct stat statstr;
res = stat(filename, &statstr);
Expand Down Expand Up @@ -883,17 +886,31 @@ static int SystemImpl__getVariableValue(double timeStamp, void* timeValues, void
return 0;
}

static void addSendDataError(const char* functionName)
{
c_add_message(156, /* WITHOUT_SENDDATA */
"SCRIPTING",
"ERROR",
"%s failed because OpenModelica was configured without sendData support.",
&functionName,
1);
}

static char* SystemImpl__getVariableNames(const char* model)
{
#ifdef CONFIG_WITH_SENDDATA
int size = getVariableListSize(model);
char *res;
if(!size) return NULL;
res = (char*)malloc(sizeof(char)*size +1);
getVariableList(model, res);
return res;
#else
addSendDataError("getVariableNames");
return NULL;
#endif
}


#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 0d3fed3

Please sign in to comment.