Skip to content

Commit

Permalink
- Fix to a possibly nasty error (I've got it) when platform specific …
Browse files Browse the repository at this point in the history
…external libraries are located in their platform specific folders (e.g., mingw32/ and win32/)

  The problem is when compiling simulation code with g++ on windows and a .lib version library is found before its .a version
  e.g., for MyExternal library, if there is Resources/Library/mingw32/libMyExternal.a and Resources/Library/win32/MyExternal.lib
  Previously, the Library paths generated in the makefile was in the opposite order, 
  so that Resources/Library/win32/MyExternal.lib was picked first by g++ ((wtf??) the lib was compiled by MSVC 2010)
  In my case, the difference was that simulation failed in time = 0.5 because of NLS solution failed ... really weird
  - Now, the library paths are generated in the expected order (back again), from the most specific (stating with mingw32 on Windows) to the least specific
  (this "bug" was introduced only lately by changing the order with more sophisticated conditional cons-ing ...)
- using extern inline in model_help.c to prevent MSVC making the functions static
- an update to CodegenCSharp.tpl

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15482 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
pavolpr committed Mar 5, 2013
1 parent bff05d6 commit 48a0ffd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Compiler/BackEnd/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9054,9 +9054,9 @@ algorithm
str1 = Util.if_(platform1 ==& "", "", "\"-L" +& str +& "/" +& platform1 +& "\"");
str2 = Util.if_(platform2 ==& "", "", "\"-L" +& str +& "/" +& platform2 +& "\"");
str3 ="\"-L" +& str +& "\"";
libs = List.consOnTrue(System.directoryExists(str +& "/" +& platform1), str1, libs);
libs = List.consOnTrue(System.directoryExists(str +& "/" +& platform2), str2, libs);
libs = List.consOnTrue(System.directoryExists(str), str3, libs);
libs = List.consOnTrue(System.directoryExists(str +& "/" +& platform2), str2, libs);
libs = List.consOnTrue(System.directoryExists(str +& "/" +& platform1), str1, libs);
then libs;
case (_, _, _, libs)
equation
Expand All @@ -9067,9 +9067,9 @@ algorithm
str1 = Util.if_(platform1 ==& "", "", "\"-L" +& str +& "/" +& platform1 +& "\"");
str2 = Util.if_(platform2 ==& "", "", "\"-L" +& str +& "/" +& platform2 +& "\"");
str3 ="\"-L" +& str +& "\"";
libs = List.consOnTrue(System.directoryExists(str +& "/" +& platform1), str1, libs);
libs = List.consOnTrue(System.directoryExists(str +& "/" +& platform2), str2, libs);
libs = List.consOnTrue(System.directoryExists(str), str3, libs);
libs = List.consOnTrue(System.directoryExists(str +& "/" +& platform2), str2, libs);
libs = List.consOnTrue(System.directoryExists(str +& "/" +& platform1), str1, libs);
then libs;
else inLibs;
end matchcontinue;
Expand Down
54 changes: 48 additions & 6 deletions Compiler/Template/CodegenCSharp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ namespace Bodylight.Models<%modelNameSpace(modelInfo.name)%>
<%functionCallExternalObjectConstructors(extObjInfo, simCode)%>
<%functionCallExternalObjectDestructors(extObjInfo, simCode)%>
<%functionExtraResiduals(initialEquations, simCode)%>
<%functionExtraResiduals(inlineEquations, simCode)%>
<%functionExtraResiduals(parameterEquations, simCode)%>
<%functionExtraResiduals(allEquations, simCode)%>
<%functionInput(modelInfo, simCode)%>
Expand All @@ -59,7 +64,9 @@ namespace Bodylight.Models<%modelNameSpace(modelInfo.name)%>
<%functionInitial(startValueEquations, simCode)%>
<%functionInitialResidual(residualEquations, simCode)%>
<%functionInitialEquations(useSymbolicInitialization, initialEquations, simCode)%>
<%functionBoundParameters(parameterEquations, simCode)%>
<%functionODE(odeEquations, simCode)%>
Expand Down Expand Up @@ -319,7 +326,7 @@ end funStatement;
constant String localRepresentationArrayDefines =
"var X = states; var Xd = statesDerivatives; var Y = algebraics; var P = parameters; var H = helpVars; var EO = externalObjects;
var preX = savedStates; var preXd = savedStatesDerivatives; var preY = savedAlgebraics; var preH = savedHelpVars;
var preYI = savedAlgebraicsInt; var preYB = savedAlgebraicsBool; var YI = algebraicsInt; var YB = algebraicsBool; var PI = parametersInt; var PB = parametersBool;
var preYI = savedAlgebraicsInt; var preYB = savedAlgebraicsBool; var YI = algebraicsInt; var YB = algebraicsBool; var PI = parametersInt; var PB = parametersBool; var PS = parametersString;
/*TODO: HACK FOR non-time varying params*/ var preP = P; var prePI = PI; var prePB = PB;";


Expand Down Expand Up @@ -352,7 +359,7 @@ const int
NPSTR = <%varInfo.numStringParamVars%>;

public override string ModelName { get { return "<%dotPath(name)%>"; }}
public override int HelpVarsCount { get { return NHELP; } }
public override int HelpVarsCount { get { return 0; } }
public override int ZeroCrossingsCount { get { return NG; } }
public override int RelationsCount { get { return NREL; } }
public override int SampleTypesCount { get { return NG_SAM; } }
Expand All @@ -363,6 +370,7 @@ public override int AlgebraicsBoolCount { get { return NYB; } }
public override int ParametersCount { get { return NP; } }
public override int ParametersIntCount { get { return NPI; } }
public override int ParametersBoolCount { get { return NPB; } }
public override int ParametersStringCount { get { return NPSTR; } }

public override int OutputsCount { get { return NO; } }
public override int InputsCount { get { return NI; } }
Expand Down Expand Up @@ -438,6 +446,9 @@ public <%lastIdentOfPath(name)%>() {
//**** parameters Bool *****
<%initVals("parametersBool", vars.boolParamVars, simCode)%>
//**** parameters String *****
<%initVals("parametersString", vars.stringParamVars, simCode)%>
}
#endregion
>>
Expand Down Expand Up @@ -492,7 +503,7 @@ end varInfos;
template initVals(String arrName, list<SimVar> varsLst, SimCode simCode) ::=
varsLst |> sv as SIMVAR(__) =>
match initialValue
case SOME(v) then
case SOME(v) then
let &preExp = buffer "" //dummy ... the value is always a constant
match daeExp(v, contextOther, &preExp, simCode)
case vStr as "0"
Expand All @@ -505,7 +516,7 @@ template initVals(String arrName, list<SimVar> varsLst, SimCode simCode) ::=
case vStr then
'<%arrName%>[<%sv.index%>] = <%vStr%>; //<%crefStr(sv.name, simCode)%>'
end match
else '//<%arrName%>[<%sv.index%>] = 0.0; //<%crefStr(sv.name, simCode)%> --> default val'
else '//<%arrName%>[<%sv.index%>] = 0.0; //<%crefStr(sv.name, simCode)%> --> default val'
;separator="\n"
end initVals;

Expand Down Expand Up @@ -536,7 +547,24 @@ case EXTOBJINFO(__) then
>>
end functionCallExternalObjectConstructors;

template functionCallExternalObjectDestructors(ExtObjInfo extObjInfo, SimCode simCode)
"Generates external objects construction calls."
::=
match extObjInfo
case EXTOBJINFO(__) then
<<
public override void FunCallExternalObjectDestructors() {
<% localRepresentationArrayDefines %>
<% vars |> var as SIMVAR(varKind=ext as EXTOBJ(__)) =>
<<
_<%underscorePath(ext.fullClassName)%>_destructor(<%cref(var.name, simCode)%>);
>>
;separator="\n"
%>
}

>>
end functionCallExternalObjectDestructors;

template functionAlgebraic(list<list<SimEqSystem>> algebraicEquations, SimCode simCode) ::=
let()= System.tmpTickReset(1)
Expand Down Expand Up @@ -924,6 +952,18 @@ template functionExtraResidual(SimEqSystem equ, SimCode simCode) ::=
>>
end functionExtraResidual;

template functionInitialEquations(Boolean useSymbolicInitialization, list<SimEqSystem> initalEquations, SimCode simCode) ::=
let()= System.tmpTickReset(1)
<<
public override bool UseSymbolicInitialization { get { return <%useSymbolicInitialization%>; } }
public override void FunInitialEquations()
{
<% localRepresentationArrayDefines %>
<%initalEquations |> eq => equation_(eq, contextSimulationDiscrete, simCode) ;separator="\n"%>
}
>>
end functionInitialEquations;

template functionBoundParameters(list<SimEqSystem> parameterEquations, SimCode simCode) ::=
let()= System.tmpTickReset(1)
<<
Expand Down Expand Up @@ -1248,7 +1288,8 @@ template representationArrayNameTypePostfix(Type type_) ::=
case T_INTEGER(__)
case T_ENUMERATION(__) then "I"
case T_BOOL(__) then "B"
case T_REAL(__) then ""
case T_REAL(__) then ""
case T_STRING(__) then "S"
else "BAD_ARRAY_NAME_POSTFIX"
end representationArrayNameTypePostfix;

Expand Down Expand Up @@ -2223,6 +2264,7 @@ template expTypeShort(DAE.Type it) ::=
case T_REAL(__) then "double"
case T_STRING(__) then "string"
case T_BOOL(__) then "bool"
case T_ENUMERATION(__) then "int"
case T_UNKNOWN(__) then "UNKNOWN_TYPE_NOT_SUPPORTED"
case T_ANYTYPE(__) then "ANYTYPE_TYPE_NOT_SUPPORTED"
case T_ARRAY(__) then expTypeShort(ty)
Expand Down
16 changes: 8 additions & 8 deletions SimulationRuntime/c/simulation/solver/model_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -918,51 +918,51 @@ void setZCtol(double relativeTol)
INFO1(LOG_EVENTS, "Set tolerance for zero-crossing hysteresis to: %e", tolZC);
}

inline
extern inline
modelica_boolean LessZC(double a, double b, modelica_boolean direction)
{
double eps = tolZC*fabs(a-b)+tolZC;
return (direction)? (a - b <= eps):(a - b <= -eps);
}

inline
extern inline
modelica_boolean LessEqZC(double a, double b, modelica_boolean direction)
{
return (!GreaterZC(a, b, !direction));
}

inline
extern inline
modelica_boolean GreaterZC(double a, double b, modelica_boolean direction)
{
double eps = tolZC*fabs(a-b)+tolZC;
return (direction)? (a - b >= -eps ):(a - b >= eps);
}

inline
extern inline
modelica_boolean GreaterEqZC(double a, double b, modelica_boolean direction)
{
return (!LessZC(a, b, !direction));
}

inline
extern inline
modelica_boolean Less(double a, double b)
{
return a < b;
}

inline
extern inline
modelica_boolean LessEq(double a, double b)
{
return a <= b;
}

inline
extern inline
modelica_boolean Greater(double a, double b)
{
return a > b;
}

inline
extern inline
modelica_boolean GreaterEq(double a, double b)
{
return a >= b;
Expand Down

0 comments on commit 48a0ffd

Please sign in to comment.