Skip to content

Commit

Permalink
- add simulation flag -nlsInfo that generates csv files for every no…
Browse files Browse the repository at this point in the history
…n-linear system for detailed analysis propose
  • Loading branch information
Willi Braun committed Jul 15, 2015
1 parent 8b345f0 commit 4a8e668
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SimulationRuntime/c/Makefile.objs
Expand Up @@ -21,7 +21,7 @@ gc/mmc_gc.h
# Files for util functions
UTIL_OBJS_MINIMAL=base_array$(OBJ_EXT) boolean_array$(OBJ_EXT) omc_error$(OBJ_EXT) division$(OBJ_EXT) generic_array$(OBJ_EXT) index_spec$(OBJ_EXT) integer_array$(OBJ_EXT) list$(OBJ_EXT) memory_pool$(OBJ_EXT) modelica_string$(OBJ_EXT) read_write$(OBJ_EXT) write_matlab4$(OBJ_EXT) read_matlab4$(OBJ_EXT) real_array$(OBJ_EXT) ringbuffer$(OBJ_EXT) rtclock$(OBJ_EXT) string_array$(OBJ_EXT) utility$(OBJ_EXT) varinfo$(OBJ_EXT) ModelicaUtilities$(OBJ_EXT) omc_msvc$(OBJ_EXT) simulation_options$(OBJ_EXT) tinymt64$(OBJ_EXT) omc_mmap$(OBJ_EXT) cJSON$(OBJ_EXT)
ifeq ($(OMC_MINIMAL_RUNTIME),)
UTIL_OBJS=$(UTIL_OBJS_MINIMAL) java_interface$(OBJ_EXT) libcsv$(OBJ_EXT) read_csv$(OBJ_EXT) OldModelicaTables$(OBJ_EXT)
UTIL_OBJS=$(UTIL_OBJS_MINIMAL) java_interface$(OBJ_EXT) libcsv$(OBJ_EXT) read_csv$(OBJ_EXT) OldModelicaTables$(OBJ_EXT) write_csv$(OBJ_EXT)
else
UTIL_OBJS=$(UTIL_OBJS_MINIMAL)
endif
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -773,6 +773,7 @@ int initRuntimeAndSimulation(int argc, char**argv, DATA *data)
data->simulationInfo.nlsMethod = getNonlinearSolverMethod(argc, argv);
data->simulationInfo.lsMethod = getlinearSolverMethod(argc, argv);
data->simulationInfo.newtonStrategy = getNewtonStrategy(argc, argv);
data->simulationInfo.nlsCsvInfomation = omc_flag[FLAG_NLS_INFO];

rt_tick(SIM_TIMER_INIT_XML);
read_input_xml(&(data->modelData), &(data->simulationInfo));
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -907,6 +907,7 @@ void initializeDataStruc(DATA *data)
data->simulationInfo.lsMethod = LS_LAPACK;
data->simulationInfo.mixedMethod = MIXED_SEARCH;
data->simulationInfo.newtonStrategy = NEWTON_PURE;
data->simulationInfo.nlsCsvInfomation = 0;

data->simulationInfo.zeroCrossings = (modelica_real*) calloc(data->modelData.nZeroCrossings, sizeof(modelica_real));
data->simulationInfo.zeroCrossingsPre = (modelica_real*) calloc(data->modelData.nZeroCrossings, sizeof(modelica_real));
Expand Down
19 changes: 19 additions & 0 deletions SimulationRuntime/c/simulation/solver/nonlinearSolverHomotopy.c
Expand Up @@ -41,6 +41,7 @@
#include "util/varinfo.h"
#include "model_help.h"
#include "meta/meta_modelica.h"
#include "util/write_csv.h"

#include "nonlinearSystem.h"
#include "nonlinearSolverHomotopy.h"
Expand Down Expand Up @@ -1087,6 +1088,7 @@ static int newtonAlgorithm(DATA_HOMOTOPY* solverData, double* x)

int assert = 1;
threadData_t *threadData = solverData->data->threadData;
NONLINEAR_SYSTEM_DATA* nonlinsys = &(solverData->data->simulationInfo.nonlinearSystemData[solverData->data->simulationInfo.currentNonlinearSystemIndex]);

/* debug information */
debugString(LOG_NLS_V, "******************************************************");
Expand Down Expand Up @@ -1259,6 +1261,23 @@ static int newtonAlgorithm(DATA_HOMOTOPY* solverData, double* x)
countNegativeSteps += (error_f > 10*error_f_old);
error_f_old = error_f;

if (solverData->data->simulationInfo.nlsCsvInfomation){
print_csvLineIterStats(((struct csvStats*) nonlinsys->csvData)->iterStats,
nonlinsys->size,
nonlinsys->numberOfCall+1,
numberOfIterations,
solverData->dy0,
solverData->dxScaled,
solverData->f1,
solverData->fvecScaled,
delta_x,
delta_x_scaled,
error_f,
error_f_scaled,
lambda
);
}

if ((error_f_scaled < 1e-30*error_f) || countNegativeSteps > 20)
{
debugInt(LOG_NLS_V,"UPS! Something happened, NegativeSteps = ", countNegativeSteps);
Expand Down

0 comments on commit 4a8e668

Please sign in to comment.