Skip to content

Commit

Permalink
activate sparse colored jacobians for dassl as default solver
Browse files Browse the repository at this point in the history
 - SimulationRuntime/c/simulation/solver/*
    - update jacobian functions for dassl
    - minor bugfixes

 - SimulationRuntime/c/math-support/matrix.h
    - bug fixed in extrapolation function for non-linear system solving

 - SimulationRuntime/c/simulation/simulation_runtime.cpp
    - activate time measurement for flag LOG_STATS
    - update solver methods output

 - Compiler/BackEnd/BackendDAEOptimize.mo
    - activation of coloring for sparse structure
 
 - testsuite/*
    - minor test updates
 


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13904 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Nov 15, 2012
1 parent 983e45b commit bccc80f
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 169 deletions.
12 changes: 6 additions & 6 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -7146,10 +7146,10 @@ algorithm
Debug.fcall(Flags.JAC_DUMP,print,"analytical Jacobians[SPARSE] -> translated to DAE.ComRefs\n");
sparsetuple = List.threadTuple(diffCompRefs, translated);

/*

Debug.fcall(Flags.JAC_DUMP,print,"analytical Jacobians[SPARSE] -> build sparse graph.");
// build up a graph of pattern
nodesList = List.intRange2(1,sparseLength);
nodesList = List.intRange2(1,adjSize);
sparseGraph = Graph.buildGraph(nodesList,createBipartiteGraph,sparseArray);
sparseGraphT = Graph.buildGraph(nodesList,createBipartiteGraph,sparseArrayT);
Debug.fcall(Flags.JAC_DUMP2,print,"sparse graph: \n");
Expand All @@ -7159,8 +7159,8 @@ algorithm

Debug.fcall(Flags.JAC_DUMP,print,"analytical Jacobians[SPARSE] -> builded graph for coloring.");
// color sparse bipartite graph
forbiddenColor = arrayCreate(sparseLength,NONE());
colored = arrayCreate(sparseLength,0);
forbiddenColor = arrayCreate(adjSize,NONE());
colored = arrayCreate(adjSize,0);
arraysparseGraph = listArray(sparseGraph);
colored1 = Graph.partialDistance2colorInt(sparseGraphT, forbiddenColor, nodesList, arraysparseGraph, colored);

Expand All @@ -7176,9 +7176,9 @@ algorithm
Debug.fcall(Flags.JAC_DUMP2, BackendDump.dumpSparsePattern, coloredlist);

coloring = List.mapList1_1(coloredlist, List.getIndexFirst, diffCompRefs);
*/

//without coloring
coloring = List.transposeList({diffCompRefs});
//coloring = List.transposeList({diffCompRefs});
Debug.fcall(Flags.JAC_DUMP, print, "analytical Jacobians[SPARSE] -> ready! " +& realString(clock()) +& "\n");
then ((sparsetuple, (diffCompRefs, diffedCompRefs)), coloring);
else
Expand Down
3 changes: 2 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -614,7 +614,8 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
"removeUnusedFunctions",
"simplifyTimeIndepFuncCalls",
"inputDerivativesUsed",
// "detectJacobianSparsePattern",
"detectJacobianSparsePattern",
// "generateSymbolicJacobian",
"removeConstants",
"optimizeInitialSystem"
}),
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/math-support/matrix.h
Expand Up @@ -99,7 +99,7 @@ _omc_dgesv_(&n,&nrhs,&A[0],&lda,ipiv,&b[0],&ldb,&info); \
free(ipiv); \
} while (0) /* (no trailing ; ) */

#define extraPolate(v,old1,old2) (data->localData[1]->timeValue == data->localData[2]->timeValue ) ? v: \
#define extraPolate(v,old1,old2) (data->localData[1]->timeValue == data->localData[2]->timeValue ) ? old1: \
(((old1)-(old2))/(data->localData[1]->timeValue-data->localData[2]->timeValue)*data->localData[0]->timeValue \
+(data->localData[1]->timeValue*(old2)-data->localData[2]->timeValue*(old1))/ \
(data->localData[1]->timeValue-data->localData[2]->timeValue))
Expand Down
28 changes: 22 additions & 6 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -152,6 +152,7 @@ void setGlobalVerboseLevel(int argc, char**argv)

if(!flags)
{
/* default activated */
useStream[LOG_STDOUT] = 1;
useStream[LOG_ASSERT] = 1;
return; // no lv flag given.
Expand All @@ -172,9 +173,14 @@ void setGlobalVerboseLevel(int argc, char**argv)
useStream[i] = 0;
}
}
/* default activated */
useStream[LOG_STDOUT] = 1;
useStream[LOG_ASSERT] = 1;

/* print states if LOG_SOLVER if active */
if (useStream[LOG_SOLVER] == 1)
useStream[LOG_STATS] = 1;

delete flags;
}

Expand Down Expand Up @@ -268,16 +274,17 @@ void initializeOutputFilter(MODEL_DATA *modelData, modelica_string variableFilte
int startNonInteractiveSimulation(int argc, char**argv, DATA* data)
{
int retVal = -1;
int measureSimTime = 0;

/* linear model option is set : <-l lintime> */
int create_linearmodel = flagSet("l", argc, argv);
string* lintime = (string*) getFlagValue("l", argc, argv);

/* mesure time option is set : -mt */
if(flagSet("mt", argc, argv))
/* activated measure time option with LOG_STATS */
if(DEBUG_STREAM(LOG_STATS) && !measure_time_flag)
{
fprintf(stderr, "Error: The -mt was replaced by the simulate option measureTime, which compiles a simulation more suitable for profiling.\n");
return 1;
measure_time_flag = 1;
measureSimTime = 1;
}

function_initMemoryState();
Expand Down Expand Up @@ -360,6 +367,15 @@ int startNonInteractiveSimulation(int argc, char**argv, DATA* data)
rt_accumulate(SIM_TIMER_LINEARIZE);
cout << "Linear model is created!" << endl;
}
/* disable measure_time_flag to prevent producing
* all profiling files, since measure_time_flag
* was not activated while compiling, it was
* just used for measure simulation time for LOG_STATS.
*/
if (measureSimTime){
measure_time_flag = 0;
}


if(retVal == 0 && measure_time_flag)
{
Expand Down Expand Up @@ -448,8 +464,8 @@ int callSolver(DATA* simData, string result_file_cstr, string init_initMethod,
simData->simulationInfo.numSteps, simData->simulationInfo.tolerance, 3);
#endif
} else {
INFO1(LOG_SOLVER, " | Unrecognized solver: %s.", simData->simulationInfo.solverMethod);
INFO(LOG_SOLVER, " | valid solvers are: dassl, euler, rungekutta, inline-euler, inline-rungekutta, dasslwort, dasslSymJac, dasslNumJac, dasslColorSymJac, dasslColorNumJac, qss.");
INFO1(LOG_STDOUT, " | Unrecognized solver: %s.", simData->simulationInfo.solverMethod);
INFO(LOG_STDOUT, " | valid solvers are: dassl, euler, rungekutta, inline-euler, inline-rungekutta, dasslwort, dasslSymJac, dasslNumJac, dasslColorSymJac, dasslInternalNumJac, qss.");
retVal = 1;
}

Expand Down

0 comments on commit bccc80f

Please sign in to comment.