Skip to content

Commit

Permalink
- attempt to fix interactive mode
Browse files Browse the repository at this point in the history
   - basic functions like start, pause, change parameter should work now

 - splitted solver_main therefore in smaller parts



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15179 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Feb 15, 2013
1 parent 73857c3 commit 90dce96
Show file tree
Hide file tree
Showing 10 changed files with 492 additions and 296 deletions.
43 changes: 29 additions & 14 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -498,6 +498,33 @@ int startNonInteractiveSimulation(int argc, char**argv, DATA* data)
return retVal;
}

/*! \fn initializeResultData(DATA* simData, int cpuTime)
*
* \param [ref] [simData]
* \param [int] [cpuTime]
*
* This function initializes result object to emit data.
*/
int initializeResultData(DATA* simData, string result_file_cstr, int cpuTime)
{
int retVal = 0;
long maxSteps = 4 * simData->simulationInfo.numSteps;
if(isInteractiveSimulation() || sim_noemit || 0 == strcmp("empty", simData->simulationInfo.outputFormat)) {
sim_result = new simulation_result_empty(result_file_cstr.c_str(), maxSteps, simData, cpuTime);
} else if(0 == strcmp("csv", simData->simulationInfo.outputFormat)) {
sim_result = new simulation_result_csv(result_file_cstr.c_str(), maxSteps, simData, cpuTime);
} else if(0 == strcmp("mat", simData->simulationInfo.outputFormat)) {
sim_result = new simulation_result_mat(result_file_cstr.c_str(), simData->simulationInfo.startTime, simData->simulationInfo.stopTime, simData, cpuTime);
} else if(0 == strcmp("plt", simData->simulationInfo.outputFormat)) {
sim_result = new simulation_result_plt(result_file_cstr.c_str(), maxSteps, simData, cpuTime);
} else {
cerr << "Unknown output format: " << simData->simulationInfo.outputFormat << endl;
retVal = 1;
}
INFO2(LOG_SOLVER,"Allocated simulation result data storage for method '%s' and file='%s'", sim_result->result_type(), result_file_cstr.c_str());
return retVal;
}

/**
* Calls the solver which is selected in the parameter string "method"
* This function is used for interactive and non-interactive simulation
Expand All @@ -514,20 +541,8 @@ int callSolver(DATA* simData, string result_file_cstr, string init_initMethod,
int retVal = -1;
const char* outVars = (outputVariablesAtEnd.size() == 0) ? NULL : outputVariablesAtEnd.c_str();

long maxSteps = 4 * simData->simulationInfo.numSteps;
if(isInteractiveSimulation() || sim_noemit || 0 == strcmp("empty", simData->simulationInfo.outputFormat)) {
sim_result = new simulation_result_empty(result_file_cstr.c_str(), maxSteps, simData, cpuTime);
} else if(0 == strcmp("csv", simData->simulationInfo.outputFormat)) {
sim_result = new simulation_result_csv(result_file_cstr.c_str(), maxSteps, simData, cpuTime);
} else if(0 == strcmp("mat", simData->simulationInfo.outputFormat)) {
sim_result = new simulation_result_mat(result_file_cstr.c_str(), simData->simulationInfo.startTime, simData->simulationInfo.stopTime, simData, cpuTime);
} else if(0 == strcmp("plt", simData->simulationInfo.outputFormat)) {
sim_result = new simulation_result_plt(result_file_cstr.c_str(), maxSteps, simData, cpuTime);
} else {
cerr << "Unknown output format: " << simData->simulationInfo.outputFormat << endl;
return 1;
}
INFO2(LOG_SOLVER,"Allocated simulation result data storage for method '%s' and file='%s'", sim_result->result_type(), result_file_cstr.c_str());
if (initializeResultData(simData, result_file_cstr, cpuTime))
return -1;

if(simData->simulationInfo.solverMethod == std::string("")) {
INFO(LOG_SOLVER, " | No solver is set, using dassl.");
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/simulation_runtime.h
Expand Up @@ -65,6 +65,7 @@ extern simulation_result *sim_result;
int callSolver(DATA* simData, std::string result_file_cstr, std::string init_initMethod,
std::string init_optiMethod, std::string init_file, double init_time, int lambda_steps, std::string outputVariablesAtEnd, int cpuTime);

int initializeResultData(DATA* simData, std::string result_file_cstr, int cpuTime);

#endif /* cplusplus */

Expand Down
7 changes: 6 additions & 1 deletion SimulationRuntime/c/simulation/solver/dassl.c
Expand Up @@ -123,6 +123,8 @@ dasrt_initial(DATA* simData, SOLVER_INFO* solverInfo, DASSL_DATA *dasslData){
int i;
SIMULATION_INFO *simInfo = &(simData->simulationInfo);

dasslData->dasslMethod = 0;

for(i=0; i< DASSL_MAX;i++){
if(!strcmp((const char*)simInfo->solverMethod, dasslMethodStr[i])){
dasslData->dasslMethod = i;
Expand Down Expand Up @@ -167,6 +169,8 @@ dasrt_initial(DATA* simData, SOLVER_INFO* solverInfo, DASSL_DATA *dasslData){
dasslData->dasslStatisticsTmp = (unsigned int*) calloc(numStatistics, sizeof(unsigned int));
ASSERT(dasslData->dasslStatisticsTmp,"out of memory");

dasslData->idid = 0;

dasslData->sqrteps = sqrt(DBL_EPSILON);
dasslData->ysave = (double*) malloc(simData->modelData.nStates*sizeof(double));
dasslData->delta_hh = (double*) malloc(simData->modelData.nStates*sizeof(double));
Expand Down Expand Up @@ -222,6 +226,7 @@ dasrt_deinitial(DASSL_DATA *dasslData){
free(dasslData->info);
free(dasslData->dasslStatistics);
free(dasslData->dasslStatisticsTmp);
free(dasslData);
return 0;
}

Expand Down Expand Up @@ -256,6 +261,7 @@ int dasrt_step(DATA* simData, SOLVER_INFO* solverInfo)
dasslData->idid = 0;
}


/* Calculate time steps until TOUT is reached
* (DASSL calculates beyond TOUT unless info[6] is set to 1!) */
tout = solverInfo->currentTime + solverInfo->currentStepSize;
Expand Down Expand Up @@ -383,7 +389,6 @@ int dasrt_step(DATA* simData, SOLVER_INFO* solverInfo)
} while(dasslData->idid == 1 ||
(dasslData->idid == -1 && solverInfo->currentTime <= simData->simulationInfo.stopTime));

/* at the of one step evaluate the system again */
sData->timeValue = solverInfo->currentTime;

if(ACTIVE_STREAM(LOG_DDASRT))
Expand Down

0 comments on commit 90dce96

Please sign in to comment.