Skip to content

Commit

Permalink
- bugfix for alias a = time
Browse files Browse the repository at this point in the history
- bugfix for msvc compile

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13950 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 18, 2012
1 parent bfcaaaa commit c866ca5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 22 deletions.
18 changes: 14 additions & 4 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1470,11 +1470,21 @@ template functionRelations(list<ZeroCrossing> relations) "template functionRelat
let resDesc = (relations |> ZERO_CROSSING(__) => '"<%ExpressionDump.printExpStr(relation_)%>", '
;separator="\n")

let desc = match relations
case {} then
<<
const char *relationDescription[1] = {"empty"};
>>
else
<<
const char *relationDescription[] =
{
<%resDesc%>
};
>>

<<
const char *relationDescription[] =
{
<%resDesc%>
};
<%desc%>

int function_updateRelations(DATA *data, int evalforZeroCross)
{
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/openmodelica_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern "C" {
#include "model_help.h"
#include "delay.h"
#include "nonlinearSystem.h"
#include "events.h" /* sample*/

/* DATA* initializeDataStruc(); */ /*create in model code */
extern void setupDataStruc(DATA *data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void simulation_result_csv::emit(DATA *data)
const char* formatint = "%i,";
const char* formatbool = "%i,";
const char* formatstring = "\"%s\",";
modelica_real value=0;
rt_tick(SIM_TIMER_OUTPUT);
fprintf(fout, format, data->localData[0]->timeValue);

Expand All @@ -69,10 +70,14 @@ void simulation_result_csv::emit(DATA *data)
fprintf(fout, formatstring, (data->localData[0])->stringVars[i]);

for (int i = 0; i < data->modelData.nAliasReal; i++) if (!data->modelData.realAlias[i].filterOutput){
if (data->modelData.realAlias[i].aliasType == 2)
value = (data->localData[0])->timeValue;
else
value = (data->localData[0])->realVars[data->modelData.realAlias[i].nameID];
if (data->modelData.realAlias[i].negate)
fprintf(fout, format, -(data->localData[0])->realVars[data->modelData.realAlias[i].nameID]);
fprintf(fout, format, -value);
else
fprintf(fout, format, (data->localData[0])->realVars[data->modelData.realAlias[i].nameID]);
fprintf(fout, format, value);
}
for (int i = 0; i < data->modelData.nAliasInteger; i++) if (!data->modelData.integerAlias[i].filterOutput){
if (data->modelData.integerAlias[i].negate)
Expand Down
10 changes: 6 additions & 4 deletions SimulationRuntime/c/simulation/results/simulation_result_mat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ void simulation_result_mat::generateDataInfo(int32_t* &dataInfo,
rows = 1+nVars+mdl_data->nParameters+mdl_data->nVarsAliases; */
size_t ccol = 0; /* current column - index offset */
size_t indx = 1;
size_t aliascol = 0;
INTMAP::iterator it;
/* assign rows & cols */
rows = nVars + nParams;
Expand Down Expand Up @@ -424,10 +425,11 @@ void simulation_result_mat::generateDataInfo(int32_t* &dataInfo,
/* row 1 - which table */
dataInfo[ccol] = table;
/* row 2 - index of var in table (variable 'Time' have index 1) */
aliascol = table==2?1:it->second+1;
if (mdl_data->realAlias[i].negate)
dataInfo[ccol+1] = -(it->second+1);
dataInfo[ccol+1] = -aliascol;
else
dataInfo[ccol+1] = it->second+1;
dataInfo[ccol+1] = aliascol;
/* row 3 - linear interpolation == 0 */
dataInfo[ccol+2] = 0;
/* row 4 - not defined outside of the defined time range == -1 */
Expand Down Expand Up @@ -456,7 +458,7 @@ void simulation_result_mat::generateDataInfo(int32_t* &dataInfo,
{
/* row 1 - which table */
dataInfo[ccol] = table;
/* row 2 - index of var in table (variable 'Time' have index 1) */
/* row 2 - index of var in table */
if (mdl_data->integerAlias[i].negate)
dataInfo[ccol+1] = -(it->second+1);
else
Expand Down Expand Up @@ -495,7 +497,7 @@ void simulation_result_mat::generateDataInfo(int32_t* &dataInfo,
{
/* row 1 - which table */
dataInfo[ccol] = table;
/* row 2 - index of var in table (variable 'Time' have index 1) */
/* row 2 - index of var in table */
if (mdl_data->booleanAlias[i].negate)
{
dataInfo[ccol+1] = indx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void simulation_result_plt::emit(DATA *data)
*/
void simulation_result_plt::add_result(double *data, long *actualPoints, DATA *simData)
{
modelica_real value=0;
/* save time first */
/* cerr << "adding result for time: " << time; */
/* cerr.flush(); */
Expand Down Expand Up @@ -156,10 +157,14 @@ void simulation_result_plt::add_result(double *data, long *actualPoints, DATA *s
for (int i = 0; i < simData->modelData.nAliasReal; i++) {
if (!simData->modelData.realAlias[i].filterOutput) {
ss << simData->modelData.realAlias[i].info.name << "\n";
if (simData->modelData.realAlias[i].aliasType == 2)
value = (simData->localData[0])->timeValue;
else
value = (simData->localData[0])->realVars[simData->modelData.realAlias[i].nameID];
if (simData->modelData.realAlias[i].negate)
ss << (data[currentPos++] = -simData->localData[0]->realVars[simData->modelData.realAlias[i].nameID]) << "\n";
ss << (data[currentPos++] = -value) << "\n";
else
ss << (data[currentPos++] = simData->localData[0]->realVars[simData->modelData.realAlias[i].nameID]) << "\n";
ss << (data[currentPos++] = value) << "\n";
}
}
/* .. alias integers .. */
Expand Down
28 changes: 18 additions & 10 deletions SimulationRuntime/c/simulation/simulation_input_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ typedef struct omc_ModelInput
/* these two we need to know to be able to add
the stuff in <Real ... />, <String ... /> to
the correct variable in the correct map */
int lastCI; /* index */
int lastCI; /* index */
omc_ModelVariables* lastCT; /* type (classification) */
} omc_ModelInput;

Expand Down Expand Up @@ -773,11 +773,13 @@ void read_input_xml(int argc, char **argv,
modelData->realAlias[i].nameID = (*itParam).second;
modelData->realAlias[i].aliasType = 1;
}
else if(aliasTmp.compare("time"))
else if(aliasTmp.compare("time")==0)
modelData->realAlias[i].aliasType = 2;
else
THROW("Alias variable not found.");

{
std::string msg = "Real Alias variable " + aliasTmp + " not found.";
THROW(msg.c_str());
}
INFO3(LOG_DEBUG, "| read for %s aliasID %d from %s from setup file",
modelData->realAlias[i].info.name,
modelData->realAlias[i].nameID,
Expand Down Expand Up @@ -835,8 +837,10 @@ void read_input_xml(int argc, char **argv,
modelData->integerAlias[i].aliasType = 1;
}
else
THROW("Alias variable not found.");

{
std::string msg = "Integer Alias variable " + aliasTmp + " not found.";
THROW(msg.c_str());
}
INFO3(LOG_DEBUG, "| read for %s aliasID %d from %s from setup file",
modelData->integerAlias[i].info.name,
modelData->integerAlias[i].nameID,
Expand Down Expand Up @@ -894,8 +898,10 @@ void read_input_xml(int argc, char **argv,
modelData->booleanAlias[i].aliasType = 1;
}
else
THROW("Alias variable not found.");

{
std::string msg = "Boolean Alias variable " + aliasTmp + " not found.";
THROW(msg.c_str());
}
INFO3(LOG_DEBUG, "| read for %s aliasID %d from %s from setup file",
modelData->booleanAlias[i].info.name,
modelData->booleanAlias[i].nameID,
Expand Down Expand Up @@ -953,8 +959,10 @@ void read_input_xml(int argc, char **argv,
modelData->stringAlias[i].aliasType = 1;
}
else
THROW("Alias variable not found.");

{
std::string msg = "String Alias variable " + aliasTmp + " not found.";
THROW(msg.c_str());
}
INFO3(LOG_DEBUG, "| read for %s aliasID %d from %s from setup file",
modelData->stringAlias[i].info.name,
modelData->stringAlias[i].nameID,
Expand Down

0 comments on commit c866ca5

Please sign in to comment.