Skip to content

Commit

Permalink
- added dependecy of hysteresis tolerance to relative tolerance
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15378 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Feb 28, 2013
1 parent 1a049d1 commit 36a8fcb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
32 changes: 19 additions & 13 deletions SimulationRuntime/c/simulation/solver/model_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,53 +910,59 @@ void deInitializeDataStruc(DATA *data)
* Less is for case LESS and GREATEREQ
* Greater is for case LESSEQ and GREATER
*/
static const double tolZC = 1e-10;
static double tolZC = 1e-10;

void setZCtol(double relativeTol)
{
tolZC = 1e-4*relativeTol;
INFO1(LOG_EVENTS, "Set tolerance for zero-crossing hysteresis to: %e", tolZC);
}

inline
modelica_boolean LessZC(double a, double b, modelica_boolean direction)
{
modelica_boolean retVal;
double eps = (direction)? tolZC*fabs(b)+tolZC : tolZC*fabs(a)+tolZC;
/*INFO4(LOG_EVENTS, "Relation LESS: %.20e < %.20e = %c (%c)", a, b, (a < b)?'t':'f' , direction?'t':'f');*/
retVal = (direction)? (a < b + eps):(a + eps < b);
/*INFO1(LOG_EVENTS, "Result := %c", retVal?'t':'f');*/
return retVal;
double eps = tolZC*fabs(a-b)+tolZC;
return (direction)? (a - b <= eps):(a - b <= -eps);
}

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

inline
modelica_boolean GreaterZC(double a, double b, modelica_boolean direction)
{
modelica_boolean retVal;
double eps = (direction)? tolZC*fabs(a)+tolZC : tolZC*fabs(b)+tolZC;
/*INFO4(LOG_EVENTS, "Relation GREATER: %.20e > %.20e = %c (%c)", a, b, (a > b)?'t':'f' , direction?'t':'f');*/
retVal = (direction)? (a + eps > b ):(a > b + eps);
/*INFO1(LOG_EVENTS, "Result := %c", retVal?'t':'f');*/
return retVal;
double eps = tolZC*fabs(a-b)+tolZC;
return (direction)? (a - b >= -eps ):(a - b >= eps);
}

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

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

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

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

inline
modelica_boolean GreaterEq(double a, double b)
{
return a >= b;
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/solver/model_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ modelica_boolean checkRelations(DATA *data);
void printHysteresisRelations(DATA *data);
void activateHysteresis(DATA* data);
void updateHysteresis(DATA* data);
void setZCtol(double relativeTol);

double getNextSampleTimeFMU(DATA *data);

Expand Down
2 changes: 2 additions & 0 deletions SimulationRuntime/c/simulation/solver/solver_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ int initializeModel(DATA* data, const char* init_initMethod,
/* allocate memory for state selection */
initializeStateSetJacobians(data);

/* set tolerance for ZeroCrossings */
setZCtol(simInfo->tolerance);

if(initialization(data, init_initMethod, init_optiMethod, init_file, init_time, lambda_steps))
{
Expand Down
3 changes: 3 additions & 0 deletions SimulationRuntime/fmi/export/fmu_model_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ fmiStatus fmiInitialize(fmiComponent c, fmiBoolean toleranceControlled, fmiReal
toleranceControlled, relativeTolerance);
*eventInfo = comp->eventInfo;

/* set zero-crossing tolerance */
setZCtol(relativeTolerance);

setStartValues(comp);
copyStartValuestoInitValues(comp->fmuData);
/* read input vars */
Expand Down

0 comments on commit 36a8fcb

Please sign in to comment.