Skip to content

Commit

Permalink
add a brute-force approach for DASSL with synchronous event handling
Browse files Browse the repository at this point in the history
 + usage with method=dassl2
 + rename solver_euler* to solver_main
 + add s-stage runge-kutta method

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5636 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Jun 10, 2010
1 parent 25f8749 commit 8fbc772
Show file tree
Hide file tree
Showing 8 changed files with 568 additions and 312 deletions.
4 changes: 2 additions & 2 deletions c_runtime/Makefile.common
Expand Up @@ -15,13 +15,13 @@ daux.o dlamch.o dpmpar.o hybrd.o lsame.o newuob.o r1mpyq.o update.o
java_interface.o meta_modelica.o meta_modelica_builtin.o ModelicaUtilities.o $(EXTRA_OBJS)

SIMOBJS = $(FOBJS) simulation_runtime.o simulation_init.o simulation_input.o simulation_events.o \
solver_dasrt.o solver_euler.o simulation_result.o simulation_delay.o tables.o options.o dgesv_aux.o $(EXTRA_SIMOBJS)
solver_dasrt.o solver_main.o simulation_result.o simulation_delay.o tables.o options.o dgesv_aux.o $(EXTRA_SIMOBJS)

HFILES = blaswrap.h f2c.h integer_array.h memory_pool.h modelica_string.h \
base_array.h inline.h real_array.h string_array.h boolean_array.h \
index_spec.h matrix.h \
modelica.h read_write.h simulation_runtime.h simulation_events.h utility.h division.h \
simulation_init.h simulation_input.h solver_dasrt.h solver_euler.h simulation_result.h \
simulation_init.h simulation_input.h solver_dasrt.h solver_main.h simulation_result.h \
meta_modelica.h meta_modelica_builtin.h sendData/sendData.h sendData/humbug.h \
java_interface.h jni.h jni_md.h jni_md_solaris.h jni_md_windows.h \
simulation_delay.h fortran_types.h ModelicaUtilities.h
Expand Down
2 changes: 1 addition & 1 deletion c_runtime/interactive/omi_ServiceInterface.cpp
Expand Up @@ -23,7 +23,7 @@
#include "simulation_runtime.h"
#include "simulation_input.h"
#include "solver_dasrt.h"
#include "solver_euler.h"
#include "solver_main.h"
#include "options.h"

//Global Data Mutex
Expand Down
26 changes: 7 additions & 19 deletions c_runtime/simulation_events.cpp
Expand Up @@ -630,7 +630,6 @@ void EventHandle(){
else if (zeroCrossingEnabled[event_id] == -1){
zeroCrossingEnabled[event_id] = 1;}

if (sim_verbose) { emit();}
saveall();
function_updateDepend();
if (sim_verbose) { emit();}
Expand Down Expand Up @@ -771,40 +770,29 @@ int CheckZeroCrossings(long int *eventid) {
}

void InitialZeroCrossings() {
int i;

if (sim_verbose) {
cout << "checkForIntialZeroCrossings" << endl;
}
//Enable all Events
for (int i = 0; i < globalData->nZeroCrossing; i++) {
zeroCrossingEnabled[i] = 1;
}

function_onlyZeroCrossings(gout,&globalData->timeValue);
for (i = 0; i < globalData->nZeroCrossing; i++) {
for (int i = 0; i < globalData->nZeroCrossing; i++) {
if (gout[i] < 0) {
zeroCrossingEnabled[i] = -1;
if (sim_verbose) { cout << "Zero-Crossing [" << i << "] = " << gout[i] << " so it's set to 1" << endl;}
} else {
} else if (gout[i] > 0) {
zeroCrossingEnabled[i] = 1;
if (sim_verbose) { cout << "Zero-Crossing [" << i << "] = " << gout[i] << " so it's set to -1" << endl;}
} else {
if (sim_verbose) { cout << "Could not initialize all Zero-Crossing!" << endl;}
}
//if gout[i] == 0 then ZC[i] will step in next step
// TODO: check where ZC will move to handle correct
}
function_onlyZeroCrossings(gout,&globalData->timeValue);
for (i = 0; i < globalData->nZeroCrossing; i++) {
if (sim_verbose) { cout << "Zero-Crossing [" << i << "] = " << gout[i] << endl;}
if (gout[i] < 0 ) {
if (sim_verbose) {
cout << "adding initial event : " << i << endl;
}
AddEvent(i);
}
}
EventHandle();

if (sim_verbose) {
cout << "checkForIntialZeroCrossings done." << endl;
}
}


14 changes: 9 additions & 5 deletions c_runtime/simulation_runtime.cpp
Expand Up @@ -38,7 +38,7 @@
#include "simulation_runtime.h"
#include "simulation_input.h"
#include "solver_dasrt.h"
#include "solver_euler.h"
#include "solver_main.h"
#include "options.h"
#include "omi_ServiceInterface.h"

Expand Down Expand Up @@ -270,11 +270,12 @@ int startNonInteractiveSimulation(int argc, char**argv){

/**
* Calls the solver which is selected in the parameter string "method"
* This funktion is used for interactive and non-interactive simulation
* This function is used for interactive and non-interactive simulation
* Parameter method:
* "" & "dassl" calls a DASSL Solver
* "euler" calls an Euler solver
* "rungekutta" calls a fourth-order Runge–Kutta Solver
* "rungekutta" calls a fourth-order Runge-Kutta Solver
* "dassl2" calls a DASSL Solver with synchronous event handling
*/
int callSolver(int argc, char**argv, string method, double start, double stop, double stepSize,
long outputSteps, double tolerance) {
Expand All @@ -286,10 +287,13 @@ int callSolver(int argc, char**argv, string method, double start, double stop, d
retVal = dassl_main(argc,argv,start,stop,stepSize,outputSteps,tolerance);
} else if (method == std::string("euler")) {
if (sim_verbose) { cout << "Recognized solver: "<< method <<"." << endl; }
retVal = euler_main(argc,argv,start,stop,stepSize,outputSteps,tolerance,1);
retVal = solver_main(argc,argv,start,stop,stepSize,outputSteps,tolerance,1);
} else if (method == std::string("rungekutta")) {
if (sim_verbose) { cout << "Recognized solver: "<< method <<"." << endl; }
retVal = euler_main(argc,argv,start,stop,stepSize,outputSteps,tolerance,2);
retVal = solver_main(argc,argv,start,stop,stepSize,outputSteps,tolerance,2);
} else if (method == std::string("dassl2")) {
if (sim_verbose) { cout << "Recognized solver: "<< method <<"." << endl; }
retVal = solver_main(argc,argv,start,stop,stepSize,outputSteps,tolerance,2);
} else if (method == std::string("dassl")) {
if (sim_verbose) { cout << "Recognized solver: "<< method <<"." << endl; }
retVal = dassl_main(argc,argv,start,stop,stepSize,outputSteps,tolerance);
Expand Down
239 changes: 0 additions & 239 deletions c_runtime/solver_euler.cpp

This file was deleted.

0 comments on commit 8fbc772

Please sign in to comment.