Skip to content

Commit

Permalink
Added support for automatic number of output steps by using intermedi…
Browse files Browse the repository at this point in the history
…ate-output model in DASSL. This can be used by setting a negative value on output step size.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2665 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jan 12, 2007
1 parent 6376a7f commit c2e2576
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion c_runtime/simulation_input.cpp
Expand Up @@ -79,8 +79,12 @@ void read_commented_value(ifstream &f, string *str);
read_commented_value(file,stop);
read_commented_value(file,stepSize);

// Calculate outputSteps from stepSize, start and stop
if (stepSize < 0) { // stepSize < 0 => Automatic number of outputs
*outputSteps = -1;
} else {
// Calculate outputSteps from stepSize, start and stop
*outputSteps = (long)(int(*stop-*start) /(*stepSize));
}
read_commented_value(file,method);
int nxchk,nychk,npchk;
read_commented_value(file,&nxchk);
Expand Down
9 changes: 8 additions & 1 deletion c_runtime/simulation_result.cpp
Expand Up @@ -115,7 +115,14 @@ int initializeResult(long numpoints,long nx, long ny, long np)
{
maxPoints = numpoints;

simulationResultData = new double[numpoints*(nx*2+ny+1)];
if (numpoints < 0 ) { // Automatic number of output steps
cerr << "Warning automatic output steps not supported in OpenModelica yet." << endl;
cerr << "Attempt to solve this by allocating large amount of result data." << endl;
numpoints = abs(numpoints);
maxPoints = abs(numpoints);
}

simulationResultData = new double[numpoints*(nx*2+ny+1)];
if (!simulationResultData) {
cerr << "Error allocating simulation result data of size " << numpoints *(nx*2+ny)
<< endl;
Expand Down
6 changes: 5 additions & 1 deletion c_runtime/solver_dasrt.cpp
Expand Up @@ -119,9 +119,13 @@ int dassl_main(int argc, char**argv,double &start, double &stop, double &step,
atol = tolerance;
rtol = tolerance;
}
if (outputSteps != 0) { // Use outputSteps if set, otherwise use step size.
if (outputSteps > 0) { // Use outputSteps if set, otherwise use step size.
numpoints = outputSteps;
step = (stop-start)/outputSteps;
} if (outputSteps < 0) { // Negative outputSteps means use automatic stepsize
info[2]=1; // INFO(3) =1 => intermediate-output mode
numpoints = - (long((stop-start)*10000)+2); // Try to estimate how many points will be used.
step = stop-start; // Only take one step
} else {
if (step == 0) { // outputsteps not defined and zero step, use default 1e-3
step = 1e-3;
Expand Down

0 comments on commit c2e2576

Please sign in to comment.