Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 2c5818d

Browse files
lochelOpenModelica-Hudson
authored andcommitted
Add flag to fix the mat file headers every N steps
Belonging to [master]: - #1968
1 parent 0a2dcae commit 2c5818d

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

SimulationRuntime/c/simulation/results/simulation_result_mat4.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef struct mat_data {
5454
size_t nData2;
5555
size_t nSignals;
5656
size_t nEmits;
57+
size_t sync;
5758
void* data_2;
5859
MatVer4Type_t type;
5960
} mat_data;
@@ -622,6 +623,10 @@ void mat4_writeParameterData4(simulation_result *self, DATA *data, threadData_t
622623
matData->nData1 = index1;
623624
matData->nData2 = index2;
624625
matData->nEmits = 0;
626+
matData->sync = 0;
627+
628+
if(omc_flag[FLAG_MAT_SYNC])
629+
matData->sync = atoi(omc_flagValue[FLAG_MAT_SYNC]);
625630

626631
// Name: dataInfo
627632
// Rank: 2
@@ -751,10 +756,15 @@ void mat4_emit4(simulation_result *self, DATA *data, threadData_t *threadData)
751756
if (mData->booleanAlias[i].negate)
752757
WRITE_REAL_VALUE(matData->data_2, cur++, (1-data->localData[0]->booleanVars[mData->booleanAlias[i].nameID]));
753758

754-
//appendMatVer4Matrix_4(matData->pFile, matData->data2HdrPos, "data_2", matData->nData2, 1, matData->data_2, matData->type);
755759
fwrite(matData->data_2, sizeofMatVer4Type(matData->type), matData->nData2, matData->pFile);
756760
matData->nEmits++;
757761

762+
if (matData->sync > 0 && matData->nEmits > matData->sync)
763+
{
764+
updateHeader_matVer4(matData->pFile, matData->data2HdrPos, "data_2", matData->nData2, matData->nEmits, matData->type);
765+
matData->nEmits = 0;
766+
}
767+
758768
rt_accumulate(SIM_TIMER_OUTPUT);
759769
}
760770

@@ -769,7 +779,10 @@ void mat4_free4(simulation_result *self, DATA *data, threadData_t *threadData)
769779
return;
770780
}
771781

772-
updateHeader_matVer4(matData->pFile, matData->data2HdrPos, "data_2", matData->nData2, matData->nEmits, matData->type);
782+
if (matData->nEmits > 0) {
783+
updateHeader_matVer4(matData->pFile, matData->data2HdrPos, "data_2", matData->nData2, matData->nEmits, matData->type);
784+
matData->nEmits = 0;
785+
}
773786

774787
if (matData->data_2) {
775788
free(matData->data_2);

SimulationRuntime/c/util/simulation_options.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const char *FLAG_NAME[FLAG_MAX+1] = {
4343
/* FLAG_DELTA_X_SOLVER */ "deltaXSolver",
4444
/* FLAG_EMBEDDED_SERVER */ "embeddedServer",
4545
/* FLAG_EMBEDDED_SERVER_PORT */ "embeddedServerPort",
46+
/* FLAG_MAT_SYNC */ "mat_sync",
4647
/* FLAG_EMIT_PROTECTED */ "emit_protected",
4748
/* FLAG_F */ "f",
4849
/* FLAG_HELP */ "help",
@@ -91,7 +92,7 @@ const char *FLAG_NAME[FLAG_MAX+1] = {
9192
/* FLAG_LSS_MAX_DENSITY */ "lssMaxDensity",
9293
/* FLAG_LSS_MIN_SIZE */ "lssMinSize",
9394
/* FLAG_LV */ "lv",
94-
/* FLAG_MAX_BISECTION_ITERATIONS */ "mbi",
95+
/* FLAG_MAX_BISECTION_ITERATIONS */ "mbi",
9596
/* FLAG_MAX_EVENT_ITERATIONS */ "mei",
9697
/* FLAG_MAX_ORDER */ "maxIntegrationOrder",
9798
/* FLAG_MAX_STEP_SIZE */ "maxStepSize",
@@ -147,6 +148,7 @@ const char *FLAG_DESC[FLAG_MAX+1] = {
147148
/* FLAG_DELTA_X_SOLVER */ "value specifies the delta x value for numerical differentiation used by integrator. The default values is sqrt(DBL_EPSILON).",
148149
/* FLAG_EMBEDDED_SERVER */ "enables an embedded server. Valid values: none, opc-da [broken], opc-ua [experimental], or the path to a shared object.",
149150
/* FLAG_EMBEDDED_SERVER_PORT */ "[int (default 4841)] value specifies the port number used by the embedded server",
151+
/* FLAG_MAT_SYNC */ "[int (default 0)] syncs the mat file header after emitting every N time-points (default disabled)",
150152
/* FLAG_EMIT_PROTECTED */ "emits protected variables to the result-file",
151153
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
152154
/* FLAG_HELP */ "get detailed information that specifies the command-line flag",
@@ -267,6 +269,8 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
267269
" * filename - path to a shared object implementing the embedded server interface (requires access to internal OMC data-structures if you want to read or write data)",
268270
/* FLAG_EMBEDDED_SERVER_PORT */
269271
" Value specifies the port number used by the embedded server. The default value is 4841.",
272+
/* FLAG_MAT_SYNC */
273+
" Syncs the mat file header after emitting every N time-points.",
270274
/* FLAG_EMIT_PROTECTED */
271275
" Emits protected variables to the result-file.",
272276
/* FLAG_F */
@@ -515,6 +519,7 @@ const int FLAG_TYPE[FLAG_MAX] = {
515519
/* FLAG_DELTA_X_SOLVER */ FLAG_TYPE_OPTION,
516520
/* FLAG_EMBEDDED_SERVER */ FLAG_TYPE_OPTION,
517521
/* FLAG_EMBEDDED_SERVER_PORT */ FLAG_TYPE_OPTION,
522+
/* FLAG_MAT_SYNC */ FLAG_TYPE_OPTION,
518523
/* FLAG_EMIT_PROTECTED */ FLAG_TYPE_FLAG,
519524
/* FLAG_F */ FLAG_TYPE_OPTION,
520525
/* FLAG_HELP */ FLAG_TYPE_OPTION,

SimulationRuntime/c/util/simulation_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ enum _FLAG
5151
FLAG_DELTA_X_SOLVER,
5252
FLAG_EMBEDDED_SERVER,
5353
FLAG_EMBEDDED_SERVER_PORT,
54+
FLAG_MAT_SYNC,
5455
FLAG_EMIT_PROTECTED,
5556
FLAG_F,
5657
FLAG_HELP,

0 commit comments

Comments
 (0)