Skip to content

Commit

Permalink
[iss-255]
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 1a5504b
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 21:04:38 2024 -0300

    Updated/fixed advection x test.

commit be1106c
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 21:04:19 2024 -0300

    Fix sym diff in virus replication test model.

commit 9d7550d
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 21:03:47 2024 -0300

    Update/fix virus replication test.

commit 2202618
Merge: 215152f 757f4e1
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 20:35:12 2024 -0300

    Merge branch 'qss-solver-dev' into engine/iss-255-allow-output-state-variables

commit 215152f
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:42:52 2024 -0300

    Update vs code settings file.

commit 807b5dd
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:42:30 2024 -0300

    Added system test.

commit 88b816e
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:31:43 2024 -0300

    Update sample interface.

commit e95480e
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:31:15 2024 -0300

    Upfate file interface for x output.

commit 4ef139c
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:28:17 2024 -0300

    Update qss log interface.

commit 63ad39f
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:27:41 2024 -0300

    Updated qss output interface.

commit 7bf9a25
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:26:53 2024 -0300

    Updated qss step inferface.

commit 41e539e
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:24:54 2024 -0300

    Added gui vs code config file.

commit 2f3f002
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:24:28 2024 -0300

    Updated qss data settings and parameters, code improvement.

commit 6058edf
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:23:34 2024 -0300

    Added checkedFree method to utils.

commit 48f7319
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:23:03 2024 -0300

    Update parameters struct.

commit 5aa67a7
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Aug 27 19:22:00 2024 -0300

    Added x output option to settings.
  • Loading branch information
joaquinffernandez committed Aug 28, 2024
1 parent 757f4e1 commit a85eb22
Show file tree
Hide file tree
Showing 32 changed files with 394 additions and 586 deletions.
2 changes: 1 addition & 1 deletion src/engine/classic/classic_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CLC_data CLC_Data(int states, int discretes, int events, int inputs, int algebra
p->event = SD_EventData(events);
p->params = SD_Parameters(settings->derdelta, settings->zchyst, settings->minstep, settings->symdiff, settings->lps, settings->nodesize,
settings->pm, settings->dt, settings->dtSynch, settings->partitionerOptions, settings->jacobian,
settings->CVODE_max_order);
settings->CVODE_max_order, settings->x_output);
p->scalarEvaluations = 0;
p->zeroCrossings = 0;
p->funEvaluations = 0;
Expand Down
21 changes: 12 additions & 9 deletions src/engine/common/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ void SD_cleanEventData(SD_eventData events, int size)
}

SD_parameters SD_Parameters(double derDelta, double zcHyst, double minStep, int symDiff, int lps, int nodeSize, SD_PartitionMethod pm,
double dt, SD_DtSynch synch, SD_partitionerOptions partitionerOptions, int jacobian, int CVODE_max_order)
double dt, SD_DtSynch synch, SD_partitionerOptions partitionerOptions, int jacobian, int CVODE_max_order,
int x_output)
{
SD_parameters p = checkedMalloc(sizeof(*p));
p->derDelta = derDelta;
Expand All @@ -186,10 +187,11 @@ SD_parameters SD_Parameters(double derDelta, double zcHyst, double minStep, int
p->partitionerOptions = partitionerOptions;
p->jacobian = jacobian;
p->CVODE_max_order = CVODE_max_order;
p->x_output = x_output;
return p;
}

SD_parameters SD_copyParameters(SD_parameters parameters)
SD_parameters SD_copyParameters(const_SD_parameters parameters)
{
SD_parameters p = checkedMalloc(sizeof(*p));
p->derDelta = parameters->derDelta;
Expand All @@ -200,6 +202,7 @@ SD_parameters SD_copyParameters(SD_parameters parameters)
p->nodeSize = parameters->nodeSize;
p->pm = parameters->pm;
p->dt = parameters->dt;
p->x_output = parameters->x_output;
return p;
}

Expand Down Expand Up @@ -437,8 +440,8 @@ SD_jacMatrix SD_JacMatrix(int variables)

void SD_allocJacMatrix(SD_jacMatrix jac_matrix)
{
int i, variables = jac_matrix->variables;
for (i = 0; i < variables; i++) {
int variables = jac_matrix->variables;
for (int i = 0; i < variables; i++) {
int size = jac_matrix->size[i];
if (size > 0) {
jac_matrix->index[i] = (int *)malloc(size * sizeof(int));
Expand All @@ -453,8 +456,8 @@ void SD_allocJacMatrix(SD_jacMatrix jac_matrix)

void SD_cleanJacMatrix(SD_jacMatrix jac_matrix)
{
int i, variables = jac_matrix->variables;
for (i = 0; i < variables; i++) {
int variables = jac_matrix->variables;
for (int i = 0; i < variables; i++) {
if (jac_matrix->size[i] > 0) {
cleanDoubleVector(jac_matrix->value[i], 0, jac_matrix->size[i]);
}
Expand All @@ -463,13 +466,13 @@ void SD_cleanJacMatrix(SD_jacMatrix jac_matrix)

void SD_freeJacMatrix(SD_jacMatrix jac_matrix)
{
int i, variables = jac_matrix->variables;
int variables = jac_matrix->variables;
free(jac_matrix->size);
for (i = 0; i < variables; i++) {
for (int i = 0; i < variables; i++) {
free(jac_matrix->index[i]);
}
free(jac_matrix->index);
for (i = 0; i < variables; i++) {
for (int i = 0; i < variables; i++) {
free(jac_matrix->value[i]);
}
free(jac_matrix->value);
Expand Down
11 changes: 7 additions & 4 deletions src/engine/common/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <stdio.h>

#include <common/macros.h>
#include "utils.h"

typedef void (*SD_eq)(int, double *, double *, double *, double, double *);
Expand Down Expand Up @@ -158,7 +159,7 @@ void SD_freeEventData(SD_eventData events, int size);

void SD_cleanEventData(SD_eventData events, int size);

typedef struct SD_parameters_ *SD_parameters;
TYPE_DEF(SD_parameters)

struct SD_parameters_ {
double derDelta;
Expand All @@ -173,12 +174,14 @@ struct SD_parameters_ {
SD_PartitionMethod pm; //!< Partition method used to obtain a model partition for parallel simulations.
SD_DtSynch dtSynch; //!< \f $ \delta t $ \f synchronization policy.
SD_partitionerOptions partitionerOptions;
int x_output;
};

SD_parameters SD_Parameters(double derDelta, double zcHyst, double minStep, int symDiff, int lps, int nodeSize, SD_PartitionMethod pm,
double dt, SD_DtSynch synch, SD_partitionerOptions partitionerOptions, int jacobian, int CVODE_max_order);
double dt, SD_DtSynch synch, SD_partitionerOptions partitionerOptions, int jacobian, int CVODE_max_order,
int x_output);

SD_parameters SD_copyParameters(SD_parameters parameters);
SD_parameters SD_copyParameters(const_SD_parameters parameters);

void SD_freeParameters(SD_parameters params);

Expand All @@ -205,7 +208,7 @@ SD_outputVariable SD_OutputVariable(int outputs);

void SD_freeOutputVariable(SD_outputVariable variable);

typedef struct SD_output_ *SD_output;
TYPE_DEF(SD_output)

struct SD_output_ {
char *name;
Expand Down
4 changes: 4 additions & 0 deletions src/engine/common/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ SET_settings SET_Settings(char *fname)
p->BDFPartitionDepth = 1;
p->CVODE_max_order = 0;
p->BDFMaxStep = 0;
p->x_output = 0;
if (config_lookup_float(cf, "minstep", &dres)) {
if (dres == 0) {
p->minstep = MIN_STEP;
Expand Down Expand Up @@ -278,6 +279,9 @@ SET_settings SET_Settings(char *fname)
}
p->partitionerOptions.nMetis = option;
}
if (config_lookup_int(cf, "XOutput", &ires)) {
p->x_output = ires;
}
config_destroy(cf);
return p;
}
Expand Down
10 changes: 4 additions & 6 deletions src/engine/common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once

#ifndef SETTINGS_H_
#define SETTINGS_H_

#include <common/macros.h>
#include "data.h"

typedef struct SET_settings_ *SET_settings;
TYPE_DEF(SET_settings)

struct SET_settings_ {
double minstep;
Expand All @@ -48,10 +47,9 @@ struct SET_settings_ {
SD_DtSynch dtSynch;
SD_partitionerOptions partitionerOptions;
int BDFPart;
int x_output;
};

SET_settings SET_Settings(char *fname);

void freeSettings(SET_settings settings);

#endif /* SETTINGS_H_ */
26 changes: 20 additions & 6 deletions src/engine/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@

#include <common/utils.h>

void checkedFree(void *ptr)
{
if (ptr != NULL) {
free(ptr);
}
}

void *checkedMalloc(unsigned long long len)
{
void *p = malloc(len);
Expand Down Expand Up @@ -158,7 +165,7 @@ double minPosRoot(double *coeff, int order)
mpr = INF;
} else {
mpr = -coeff[0] / coeff[1];
};
}
if (mpr < 0) {
mpr = INF;
}
Expand All @@ -169,7 +176,7 @@ double minPosRoot(double *coeff, int order)
mpr = INF;
} else {
mpr = -coeff[0] / coeff[1];
};
}
if (mpr < 0) {
mpr = INF;
}
Expand All @@ -187,13 +194,13 @@ double minPosRoot(double *coeff, int order)
mpr = r1;
} else {
mpr = INF;
};
}
r1 = (-coeff[1] - sd) / 2 / coeff[2];
if ((r1 > 0) && (r1 < mpr)) {
mpr = r1;
}
};
};
}
}
break;
case 3:
if ((coeff[3] == 0) || (1000 * fabs(coeff[3]) < fabs(coeff[2]))) {
Expand Down Expand Up @@ -234,7 +241,14 @@ double minPosRoot(double *coeff, int order)
}
} else {
// three real roots
double rho, th, rho13, costh3, sinth3, spt, smti32, r1;
double rho;
double th;
double rho13;
double costh3;
double sinth3;
double spt;
double smti32;
double r1;
rho = sqrt(-q * q * q);
th = acos(r / rho);
rho13 = pow(rho, 1.0 / 3);
Expand Down
7 changes: 3 additions & 4 deletions src/engine/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
******************************************************************************/

#ifndef UTILS_H_
#define UTILS_H_
#pragma once

#ifdef _WIN32
#include <sys/time.h>
Expand Down Expand Up @@ -67,6 +66,8 @@ typedef char bool;

typedef char *string;

void checkedFree(void *ptr);

void *checkedMalloc(unsigned long long len);

double minPosRoot(double *coeff, int order) __attribute__((hot));
Expand Down Expand Up @@ -413,5 +414,3 @@ void waitUntil(double until);
void setInitRealTime();

#endif

#endif /* UTILS_H_ */
49 changes: 14 additions & 35 deletions src/engine/qss/qss_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ QSS_reinit QSS_Reinit()
return NULL;
}
QSS_reinit p = checkedMalloc(sizeof(*p));
int i;
for (i = 0; i < QSS_REINIT_BUFFER; i++) {
for (int i = 0; i < QSS_REINIT_BUFFER; i++) {
p->variable[i] = NOT_ASSIGNED;
}
p->time = INF;
Expand Down Expand Up @@ -230,8 +229,8 @@ QSS_LP_dataArray QSS_LP_DataArray(int size)
void QSS_LP_freeDataArray(QSS_LP_dataArray array)
{
if (!QSS_hardCopyStruct) {
int i, size = array->size;
for (i = 0; i < size; i++) {
int size = array->size;
for (int i = 0; i < size; i++) {
if (array->lp[i] != NULL) {
QSS_LP_freeData(array->lp[i]);
}
Expand All @@ -253,36 +252,16 @@ void QSS_LP_freeData(QSS_LP_data data)
if (data == NULL) {
return;
}
if (data->nLPS != NULL) {
free(data->nLPS);
}
if (data->lps != NULL) {
free(data->lps);
}
if (data->qOutMap != NULL) {
free(data->qOutMap);
}
if (data->eOutMap != NULL) {
free(data->eOutMap);
}
if (data->qMap != NULL) {
free(data->qMap);
}
if (data->qInMap != NULL) {
free(data->qInMap);
}
if (data->eMap != NULL) {
free(data->eMap);
}
if (data->eInMap != NULL) {
free(data->eInMap);
}
if (data->iMap != NULL) {
free(data->iMap);
}
if (data->dscMap != NULL) {
free(data->dscMap);
}
checkedFree(data->nLPS);
checkedFree(data->lps);
checkedFree(data->qOutMap);
checkedFree(data->eOutMap);
checkedFree(data->qMap);
checkedFree(data->qInMap);
checkedFree(data->eMap);
checkedFree(data->eInMap);
checkedFree(data->iMap);
checkedFree(data->dscMap);
free(data);
}

Expand Down Expand Up @@ -440,7 +419,7 @@ QSS_data QSS_Data(int states, int discretes, int events, int inputs, int algs, i
}
p->params = SD_Parameters(settings->derdelta, settings->zchyst, settings->minstep, settings->symdiff, settings->lps, settings->nodesize,
settings->pm, settings->dt, settings->dtSynch, settings->partitionerOptions, settings->jacobian,
settings->CVODE_max_order);
settings->CVODE_max_order, settings->x_output);
p->lp = NULL;
if (settings->lps > 0) {
QSS_setReinitBuffer(TRUE);
Expand Down
5 changes: 3 additions & 2 deletions src/engine/qss/qss_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#pragma once

#include <common/data.h>
#include <common/macros.h>
#include <common/utils.h>

#define QSS_REINIT_BUFFER 10000
Expand Down Expand Up @@ -168,7 +169,7 @@ QSS_event SD_Event(QSS_zc zeroCrossing, QSS_hnd handlerPos, QSS_hnd handlerNeg);

void QSS_freeEvent(QSS_event events);

typedef struct QSS_data_ *QSS_data;
TYPE_DEF(QSS_data)

struct QSS_data_ {
double *dQMin;
Expand Down Expand Up @@ -245,7 +246,7 @@ void QSS_cleanData(QSS_data data);

void QSS_allocDataMatrix(QSS_data data);

typedef struct QSS_time_ *QSS_time;
TYPE_DEF(QSS_time)

/**
* @struct QSS_time_
Expand Down
6 changes: 5 additions & 1 deletion src/engine/qss/qss_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ void F_init(LG_log log, QSS_data sim_data, SD_output sim_output)
int i, j, size;
log->state->data = sim_data;
log->state->output = sim_output;
int output_coeffs = sim_data->order;
if (sim_data->params->x_output == 1) {
output_coeffs++;
}
#ifdef QSS_PARALLEL
QSS_LP_data lp = sim_data->lp;
log->state->size = lp->outputs;
Expand Down Expand Up @@ -64,7 +68,7 @@ void F_init(LG_log log, QSS_data sim_data, SD_output sim_output)
sprintf(log->state->fileName, "%s%s.dat", sim_output->variable[i].name, ext);
log->state->files[j] = fopen(log->state->fileName, "w+");
if (sim_output->commInterval == CI_Dense || sim_output->commInterval == CI_Sampled) {
log->state->values[j] = sim_output->nOS[i] * sim_data->order + sim_output->nOD[i];
log->state->values[j] = sim_output->nOS[i] * output_coeffs + sim_output->nOD[i];
}
j++;
#ifdef QSS_PARALLEL
Expand Down
Loading

0 comments on commit a85eb22

Please sign in to comment.