Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors committed Jul 9, 2015
2 parents 9205fb7 + f923680 commit 8cb67d0
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 60 deletions.
28 changes: 8 additions & 20 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -2526,28 +2526,21 @@ template genreinits(SimWhenClause whenClauses, Text &varDecls, Text &auxFunction
::=
match whenClauses
case SIM_WHEN_CLAUSE(__) then
let helpIf = (conditions |> e => ' || (<%cref(e)%> && !$P$PRE<%cref(e)%> /* edge */)')
let ifthen = functionWhenReinitStatementThen(false, reinits, &varDecls, &auxFunction)
let initial_assign = match initialCall
case true then functionWhenReinitStatementThen(true, reinits, &varDecls, &auxFunction)
else '; /* nothing to do */'
let helpIf = (conditions |> e => '(<%cref(e)%> && !$P$PRE<%cref(e)%> /* edge */)';separator=" || ")
let ifthen = functionWhenReinitStatementThen(reinits, &varDecls, &auxFunction)

if reinits then
if boolAnd(intGt(listLength(conditions), 0), intGt(listLength(reinits), 0)) then
<<
/* for whenclause index <%int%> */
if(initial())
{
<%initial_assign%>
}
else if(0<%helpIf%>)
if(<%helpIf%>)
{
<%ifthen%>
}
>>
end genreinits;


template functionWhenReinitStatementThen(Boolean initialCall, list<WhenOperator> reinits, Text &varDecls, Text &auxFunction)
template functionWhenReinitStatementThen(list<WhenOperator> reinits, Text &varDecls, Text &auxFunction)
"Generates re-init statement for when equation."
::=
let body = (reinits |> reinit =>
Expand All @@ -2560,14 +2553,11 @@ template functionWhenReinitStatementThen(Boolean initialCall, list<WhenOperator>
'copy_real_array_data_mem(<%val%>, &<%cref(stateVar)%>);'
else
'<%cref(stateVar)%> = <%val%>;'
let needToIterate =
if not initialCall then
"data->simulationInfo.needToIterate = 1;"
<<
infoStreamPrint(LOG_EVENTS, 0, "reinit <%cref(stateVar)%> = %f", <%val%>);
<%preExp%>
<%lhs%>
<%needToIterate%>
infoStreamPrint(LOG_EVENTS, 0, "reinit <%cref(stateVar)%> = <%crefToPrintfArg(stateVar)%>", <%cref(stateVar)%>);
data->simulationInfo.needToIterate = 1;
>>
case TERMINATE(__) then
let &preExp = buffer ""
Expand Down Expand Up @@ -3323,7 +3313,6 @@ template functionODE(list<list<SimEqSystem>> derivativEquations, Text method, Op
data->simulationInfo.callStatistics.functionODE++;
data->simulationInfo.discreteCall = 0;
<%if Flags.isSet(Flags.PARMODAUTO) then 'PM_functionODE(<%nrfuncs%>, data, functionODE_systems);'
else '<%fncalls%>' %>
Expand Down Expand Up @@ -3355,7 +3344,6 @@ template functionAlgebraic(list<list<SimEqSystem>> algebraicEquations, String mo
TRACE_PUSH
<%varDecls%>
data->simulationInfo.discreteCall = 0;
<%if Flags.isSet(Flags.PARMODAUTO) then 'PM_functionAlg(<%nrfuncs%>, data, functionAlg_systems);'
else '<%fncalls%>' %>
Expand Down Expand Up @@ -3416,6 +3404,7 @@ template functionDAE(list<SimEqSystem> allEquationsPlusWhen, list<SimWhenClause>
<%if Flags.isSet(Flags.PARMODAUTO) then 'PM_functionDAE(<%nrfuncs%>, data, functionDAE_systems);'
else '<%fncalls%>' %>
<%reinit%>
data->simulationInfo.discreteCall = 0;

TRACE_POP
return 0;
Expand Down Expand Up @@ -3477,7 +3466,6 @@ template functionZeroCrossing(list<ZeroCrossing> zeroCrossings, list<SimEqSystem
data->simulationInfo.callStatistics.functionZeroCrossingsEquations++;
data->simulationInfo.discreteCall = 0;
<%eqs%>
TRACE_POP
Expand Down
4 changes: 4 additions & 0 deletions Makefile.omdev.mingw
Expand Up @@ -218,6 +218,10 @@ fmil_msvc:
(cp -puf 3rdParty/FMIL/install_msvc/lib/fmilib_shared.dll $(OMBUILDDIR)/bin/fmilib.dll)
(cp -puf 3rdParty/FMIL/install_msvc/lib/fmilib_shared.dll $(OMBUILDDIR)/lib/omc/msvc/fmilib.dll)
(cp -puf 3rdParty/FMIL/install_msvc/lib/fmilib_shared.lib $(OMBUILDDIR)/lib/omc/msvc/fmilib.lib)
# copy the dll with the actual name: fmilib_shared.dll as the fmilib.lib contains that name and the exe will look for it
(cp -puf 3rdParty/FMIL/install_msvc/lib/fmilib_shared.dll $(OMBUILDDIR)/bin/fmilib_shared.dll)
(cp -puf 3rdParty/FMIL/install_msvc/lib/fmilib_shared.dll $(OMBUILDDIR)/lib/omc/msvc/fmilib_shared.dll)
(cp -puf 3rdParty/FMIL/install_msvc/lib/fmilib_shared.lib $(OMBUILDDIR)/lib/omc/msvc/fmilib_shared.lib)

CMinpack_msvc:
rm -f $(OMBUILDDIR)/lib/omc/msvc/cminpack.*
Expand Down
7 changes: 0 additions & 7 deletions SimulationRuntime/c/meta/meta_modelica_builtin.c
Expand Up @@ -38,13 +38,6 @@
#include <string.h>
#include <stdio.h>

#if defined(_MSC_VER)
#include <float.h>
#define isinf(d) (!_finite(d) && !_isnan(d))
#define isnan _isnan
#define snprintf _snprintf
#endif

#define GEN_META_MODELICA_BUILTIN_BOXPTR
#include "meta_modelica_builtin_boxptr.h"

Expand Down
47 changes: 27 additions & 20 deletions SimulationRuntime/c/simulation/solver/perform_qss_simulation.c
Expand Up @@ -112,22 +112,22 @@ modelica_integer prefixedName_performQSSSimulation(DATA* data, SOLVER_INFO* solv
modelica_real* dQ = NULL; /* change in quantity of every state, default = nominal*10^-4 */

/* allocate memory*/
qik = calloc(STATES, sizeof(modelica_real));
fail = (qik == NULL) ? 1 : ( 0 | fail);
xik = calloc(STATES, sizeof(modelica_real));
fail = (xik == NULL) ? 1 : ( 0 | fail);
derXik = calloc(STATES, sizeof(modelica_real));
fail = (derXik == NULL) ? 1 : ( 0 | fail);
tq = calloc(STATES, sizeof(modelica_real));
fail = (tq == NULL) ? 1 : ( 0 | fail);
tx = calloc(STATES, sizeof(modelica_real));
fail = (tx == NULL) ? 1 : ( 0 | fail);
tqp = calloc(STATES, sizeof(modelica_real));
fail = (tqp == NULL) ? 1 : ( 0 | fail);
nQh = calloc(STATES, sizeof(modelica_real));
fail = (nQh == NULL) ? 1 : ( 0 | fail);
dQ = calloc(STATES, sizeof(modelica_real));
fail = (dQ == NULL) ? 1 : ( 0 | fail);
qik = (modelica_real*)calloc(STATES, sizeof(modelica_real));
fail = (qik == NULL) ? 1 : ( 0 | fail);
xik = (modelica_real*)calloc(STATES, sizeof(modelica_real));
fail = (xik == NULL) ? 1 : ( 0 | fail);
derXik = (modelica_real*)calloc(STATES, sizeof(modelica_real));
fail = (derXik == NULL) ? 1 : ( 0 | fail);
tq = (modelica_real*)calloc(STATES, sizeof(modelica_real));
fail = (tq == NULL) ? 1 : ( 0 | fail);
tx = (modelica_real*)calloc(STATES, sizeof(modelica_real));
fail = (tx == NULL) ? 1 : ( 0 | fail);
tqp = (modelica_real*)calloc(STATES, sizeof(modelica_real));
fail = (tqp == NULL) ? 1 : ( 0 | fail);
nQh = (modelica_real*)calloc(STATES, sizeof(modelica_real));
fail = (nQh == NULL) ? 1 : ( 0 | fail);
dQ = (modelica_real*)calloc(STATES, sizeof(modelica_real));
fail = (dQ == NULL) ? 1 : ( 0 | fail);


if (fail)
Expand All @@ -152,7 +152,7 @@ modelica_integer prefixedName_performQSSSimulation(DATA* data, SOLVER_INFO* solv
}

/* Transform the sparsity pattern into a data structure for an index based access. */
modelica_integer* der = calloc(ROWS, sizeof(modelica_integer));
modelica_integer* der = (modelica_integer*)calloc(ROWS, sizeof(modelica_integer));
if (NULL==der)
return OO_MEMORY;
for (i = 0; i < ROWS; i++)
Expand Down Expand Up @@ -507,14 +507,15 @@ static modelica_integer getStatesInDer(const unsigned int* index, const unsigned
{
uinteger i = 0, k = 0; /* loop var */
uinteger numDer = 0;
modelica_integer* der = calloc(ROWS, sizeof(modelica_integer));
modelica_integer* der = (modelica_integer*)calloc(ROWS, sizeof(modelica_integer));
uinteger* stackPointer = (uinteger*)calloc(ROWS, sizeof(uinteger));

if (NULL == der)
return OO_MEMORY;

for (i = 0; i < ROWS; i++)
der[i] = -1;

uinteger stackPointer[ROWS];
for (i = 0; i < ROWS; i++)
stackPointer[i] = 0;

Expand All @@ -534,6 +535,7 @@ static modelica_integer getStatesInDer(const unsigned int* index, const unsigned
}

free(der);
free(stackPointer);
return OK;
}

Expand All @@ -548,7 +550,12 @@ static uinteger minStep(const modelica_real* tqp, const uinteger size )
{
uinteger i = 0;
uinteger ind = i;
modelica_real tmin = 1.0/0.0; /* Wwe can have a QNAN at any index and tqp[i] < QNAN will fail in every case. */
modelica_real tmin =
#if defined(_MSC_VER)
NAN;
#else
1.0/0.0; /* We can have a QNAN at any index and tqp[i] < QNAN will fail in every case. */
#endif

for (i = 0; i < size; i++)
{
Expand Down
7 changes: 0 additions & 7 deletions SimulationRuntime/c/simulation/solver/radau.c
Expand Up @@ -32,13 +32,6 @@
* author: team Bielefeld :)
*/

#if defined(_MSC_VER)
#include <float.h>
#define isinf(d) (!_finite(d) && !_isnan(d))
#define isnan _isnan
#define snprintf _snprintf
#endif

#include <string.h>

#include "radau.h"
Expand Down
5 changes: 0 additions & 5 deletions SimulationRuntime/c/util/division.c
Expand Up @@ -74,11 +74,6 @@ modelica_real division_error(threadData_t *threadData, modelica_real b, const ch
return b;
}

#if defined(_MSC_VER)
#include <float.h>
#define isnan _isnan
#endif

modelica_real isnan_error(threadData_t *threadData,modelica_real b, const char* division_str, const char* file, long line)
{
if(isnan(b))
Expand Down
9 changes: 9 additions & 0 deletions SimulationRuntime/c/util/omc_msvc.h
Expand Up @@ -84,6 +84,15 @@ int vasprintf(char **strp, const char *fmt, va_list ap);

unsigned int alarm (unsigned int seconds);

#include <float.h>
#define isinf(d) (!_finite(d) && !_isnan(d))
#define isnan _isnan
#define fpu_error(x) (isinf(x) || isnan(x))

#if !defined(snprintf)
#define snprintf snprintf_s
#endif

#else /* not msvc */

/* define inline for non-MSVC */
Expand Down
Expand Up @@ -61,7 +61,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
//("emit_protected", "emits protected variables to the result file")
("emit_protected", "emits protected variables to the result file")
("runtime-library,r", po::value<string>(),"path to cpp runtime libraries")
("Modelica-system-library,m", po::value<string>(), "path to Modelica library")
("results-file,R", po::value<string>(),"name of results file")
Expand Down

0 comments on commit 8cb67d0

Please sign in to comment.