Skip to content

Commit

Permalink
add deltaX flag and pass it to the linearization
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun committed Oct 19, 2016
1 parent 620a9df commit 5d9af84
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions SimulationRuntime/c/linearization/linearize.cpp
Expand Up @@ -33,6 +33,7 @@
#include "openmodelica_func.h"
#include "simulation/solver/external_input.h"
#include "simulation/options.h"
#include "simulation/solver/model_help.h"
#include "linearize.h"
#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -111,7 +112,7 @@ int functionODE_residual(DATA* data, threadData_t *threadData, double *dx, doubl
/* Calculate the jacobian matrix by numerical finite difference */
int functionJacAC_num(DATA* data, threadData_t *threadData, double *matrixA, double *matrixC, double *matrixCz)
{
const double delta_h = sqrt(DBL_EPSILON*2e1);
const double delta_h = numericalDifferentiationDeltaX;
double delta_hh;
double xsave;

Expand Down Expand Up @@ -202,7 +203,7 @@ int functionJacAC_num(DATA* data, threadData_t *threadData, double *matrixA, dou

int functionJacBD_num(DATA* data, threadData_t *threadData, double *matrixB, double *matrixD, double *matrixDz)
{
const double delta_h = sqrt(DBL_EPSILON*2e1);
const double delta_h = numericalDifferentiationDeltaX;
double delta_hh;
double usave;
double* u;
Expand Down
9 changes: 9 additions & 0 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -508,6 +508,15 @@ int startNonInteractiveSimulation(int argc, char**argv, DATA* data, threadData_t
infoStreamPrint(LOG_STDOUT, 0, "Linearization will performed at point of time: %f", data->simulationInfo->stopTime);
}

/* set delta x */
if(omc_flag[FLAG_DELTA_X]) {
numericalDifferentiationDeltaX = atof(omc_flagValue[FLAG_DELTA_X]);
infoStreamPrint(LOG_SOLVER, 0, "Set delta x for numerical differentiation to %f", numericalDifferentiationDeltaX);
}else{
numericalDifferentiationDeltaX = sqrt(DBL_EPSILON*2e1);
}


if(omc_flag[FLAG_S]) {
if (omc_flagValue[FLAG_S]) {
data->simulationInfo->solverMethod = GC_strdup(omc_flagValue[FLAG_S]);
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -57,6 +57,7 @@ double newtonXTol = 1e-12;
double newtonFTol = 1e-12;
const size_t SIZERINGBUFFER = 3;
int compiledInDAEMode = 0;
double numericalDifferentiationDeltaX = 1e-8;

static double tolZC;

Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/solver/model_help.h
Expand Up @@ -81,6 +81,7 @@ extern double newtonXTol;
extern double newtonFTol;
extern const size_t SIZERINGBUFFER;
extern int compiledInDAEMode;
extern double numericalDifferentiationDeltaX;

void initializeDataStruc(DATA *data, threadData_t *threadData);

Expand Down
5 changes: 5 additions & 0 deletions SimulationRuntime/c/util/simulation_options.c
Expand Up @@ -39,6 +39,7 @@ const char *FLAG_NAME[FLAG_MAX+1] = {
/* FLAG_CPU */ "cpu",
/* FLAG_CSV_OSTEP */ "csvOstep",
/* FLAG_DAE_MODE */ "daeMode",
/* FLAG_DELTA_X */ "deltaX",
/* FLAG_EMBEDDED_SERVER */ "embeddedServer",
/* FLAG_EMIT_PROTECTED */ "emit_protected",
/* FLAG_F */ "f",
Expand Down Expand Up @@ -118,6 +119,7 @@ const char *FLAG_DESC[FLAG_MAX+1] = {
/* FLAG_CPU */ "dumps the cpu-time into the result file",
/* FLAG_CSV_OSTEP */ "value specifies csv-files for debuge values for optimizer step",
/* FLAG_DAE_MODE */ "flag to let the integrator use daeResiduals",
/* FLAG_DELTA_X */ "value specifies the delta x value for numerical differentiation, used by linearization or integrator",
/* FLAG_EMBEDDED_SERVER */ "enables an embedded server. Valid values: none, opc-da [broken], opc-ua [experimental], or the path to a shared object.",
/* FLAG_EMIT_PROTECTED */ "emits protected variables to the result-file",
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
Expand Down Expand Up @@ -205,6 +207,8 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
" Value specifies csv-files for debuge values for optimizer step",
/* FLAG_DAE_MODE */
" Enables daeMode simulation if the model was compiled with the omc flag --daeMode and the IDA integrator is used.",
/* FLAG_DELTA_X */
"value specifies the delta x value for numerical differentiation, used by linearization or integrator",
/* FLAG_EMBEDDED_SERVER */
" Enables an embedded server. Valid values:\n\n"
" * none - default, run without embedded server\n"
Expand Down Expand Up @@ -403,6 +407,7 @@ const int FLAG_TYPE[FLAG_MAX] = {
/* FLAG_CPU */ FLAG_TYPE_FLAG,
/* FLAG_CSV_OSTEP */ FLAG_TYPE_OPTION,
/* FLAG_DAE_SOLVING */ FLAG_TYPE_FLAG,
/* FLAG_DELTA_X */ FLAG_TYPE_OPTION,
/* FLAG_EMBEDDED_SERVER */ FLAG_TYPE_OPTION,
/* FLAG_EMIT_PROTECTED */ FLAG_TYPE_FLAG,
/* FLAG_F */ FLAG_TYPE_OPTION,
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/util/simulation_options.h
Expand Up @@ -47,6 +47,7 @@ enum _FLAG
FLAG_CPU,
FLAG_CSV_OSTEP,
FLAG_DAE_MODE,
FLAG_DELTA_X,
FLAG_EMBEDDED_SERVER,
FLAG_EMIT_PROTECTED,
FLAG_F,
Expand Down

0 comments on commit 5d9af84

Please sign in to comment.