Skip to content

Commit

Permalink
improved extrapolation of non-linear initial guess
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun committed Oct 24, 2015
1 parent b04f8ee commit d5a8183
Show file tree
Hide file tree
Showing 10 changed files with 479 additions and 4 deletions.
1 change: 1 addition & 0 deletions SimulationRuntime/c/Makefile.common
Expand Up @@ -55,6 +55,7 @@ RUNTIMESIMSOLVER_HEADERS = ./simulation/solver/delay.h \
./simulation/solver/model_help.h \
./simulation/solver/mixedSearchSolver.h \
./simulation/solver/nonlinearSystem.h \
./simulation/solver/nonlinearValuesList.h \
./simulation/solver/nonlinearSolverHomotopy.h \
./simulation/solver/nonlinearSolverHybrd.h \
./simulation/solver/stateset.h \
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/c/Makefile.objs
Expand Up @@ -36,7 +36,7 @@ UTIL_HFILES=base_array.h boolean_array.h division.h generic_array.h omc_error.h
MATH_OBJS=pivot$(OBJ_EXT)
MATH_HFILES = blaswrap.h

SOLVER_OBJS_FMU=delay$(OBJ_EXT) linearSystem$(OBJ_EXT) linearSolverLapack$(OBJ_EXT) linearSolverTotalPivot$(OBJ_EXT) mixedSystem$(OBJ_EXT) mixedSearchSolver$(OBJ_EXT) nonlinearSystem$(OBJ_EXT) nonlinearSolverHybrd$(OBJ_EXT) nonlinearSolverHomotopy$(OBJ_EXT) omc_math$(OBJ_EXT) model_help$(OBJ_EXT) stateset$(OBJ_EXT) synchronous$(OBJ_EXT)
SOLVER_OBJS_FMU=delay$(OBJ_EXT) linearSystem$(OBJ_EXT) linearSolverLapack$(OBJ_EXT) linearSolverTotalPivot$(OBJ_EXT) mixedSystem$(OBJ_EXT) mixedSearchSolver$(OBJ_EXT) nonlinearSystem$(OBJ_EXT) nonlinearValuesList$(OBJ_EXT) nonlinearSolverHybrd$(OBJ_EXT) nonlinearSolverHomotopy$(OBJ_EXT) omc_math$(OBJ_EXT) model_help$(OBJ_EXT) stateset$(OBJ_EXT) synchronous$(OBJ_EXT)
ifeq ($(OMC_FMI_RUNTIME),)
SOLVER_OBJS_MINIMAL=$(SOLVER_OBJS_FMU) events$(OBJ_EXT) external_input$(OBJ_EXT) solver_main$(OBJ_EXT)
else
Expand All @@ -47,7 +47,7 @@ SOLVER_OBJS=$(SOLVER_OBJS_MINIMAL) kinsolSolver$(OBJ_EXT) linearSolverLis$(OBJ_E
else
SOLVER_OBJS=$(SOLVER_OBJS_MINIMAL)
endif
SOLVER_HFILES = dassl.h delay.h epsilon.h events.h external_input.h linearSystem.h mixedSystem.h model_help.h nonlinearSystem.h radau.h sym_imp_euler.h solver_main.h stateset.h
SOLVER_HFILES = dassl.h delay.h epsilon.h events.h external_input.h linearSystem.h mixedSystem.h model_help.h nonlinearSystem.h nonlinearValuesList.h radau.h sym_imp_euler.h solver_main.h stateset.h

INITIALIZATION_OBJS = initialization$(OBJ_EXT)
INITIALIZATION_HFILES = initialization.h
Expand Down
26 changes: 24 additions & 2 deletions SimulationRuntime/c/simulation/solver/nonlinearSystem.c
Expand Up @@ -36,6 +36,7 @@

#include "util/omc_error.h"
#include "nonlinearSystem.h"
#include "nonlinearValuesList.h"
#if !defined(OMC_MINIMAL_RUNTIME)
#include "kinsolSolver.h"
#include "nonlinearSolverHybrd.h"
Expand Down Expand Up @@ -366,6 +367,9 @@ int initializeNonlinearSystems(DATA *data, threadData_t *threadData)
nonlinsys[i].nlsxExtrapolation = (double*) malloc(size*sizeof(double));
nonlinsys[i].nlsxOld = (double*) malloc(size*sizeof(double));

/* allocate value list*/
nonlinsys[i].oldValueList = (void*) allocValueList(sizeof(VALUE));

nonlinsys[i].nominal = (double*) malloc(size*sizeof(double));
nonlinsys[i].min = (double*) malloc(size*sizeof(double));
nonlinsys[i].max = (double*) malloc(size*sizeof(double));
Expand Down Expand Up @@ -476,6 +480,7 @@ int freeNonlinearSystems(DATA *data, threadData_t *threadData)
free(nonlinsys[i].nominal);
free(nonlinsys[i].min);
free(nonlinsys[i].max);
freeValueList(nonlinsys[i].oldValueList);

#if !defined(OMC_MINIMAL_RUNTIME)
if (data->simulationInfo.nlsCsvInfomation)
Expand Down Expand Up @@ -563,6 +568,18 @@ int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber)

rt_ext_tp_tick(&nonlinsys->totalTimeClock);

/* value extrapolation */
infoStreamPrint(LOG_NLS_EXTRAPOLATE, 1, "############ Start new iteration for system %d at time at %g ############", sysNumber, data->localData[0]->timeValue);
printValuesListTimes((VALUES_LIST*)nonlinsys->oldValueList);
/* if list is empty put current element in */
if (listLen(((VALUES_LIST*)nonlinsys->oldValueList)->valueList)==0)
{
addListElement((VALUES_LIST*)nonlinsys->oldValueList,
createValueElement(nonlinsys->size, data->localData[0]->timeValue, nonlinsys->nlsx));
}
/* get extrapolated values */
getValues((VALUES_LIST*)nonlinsys->oldValueList, data->localData[0]->timeValue, nonlinsys->nlsxExtrapolation);

if(data->simulationInfo.discreteCall)
{
double *fvec = malloc(sizeof(double)*nonlinsys->size);
Expand Down Expand Up @@ -647,10 +664,15 @@ int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber)
default:
throwStreamPrint(threadData, "unrecognized nonlinear solver");
}


nonlinsys->solved = success;

/* write solution to oldValue list for extrapolation */
if (nonlinsys->solved){
addListElement((VALUES_LIST*)nonlinsys->oldValueList,
createValueElement(nonlinsys->size, data->localData[0]->timeValue, nonlinsys->nlsx));
}
infoStreamPrint(LOG_NLS_EXTRAPOLATE, 0, "########################", data->localData[0]->timeValue);
messageClose(LOG_NLS_EXTRAPOLATE);

#ifndef OMC_EMCC
/*catch */
Expand Down

0 comments on commit d5a8183

Please sign in to comment.