Skip to content

Commit 1905f0a

Browse files
committed
Fix in cpp template in mixed systems discrete vars iteration
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10994 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 8057771 commit 1905f0a

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

Compiler/susan_codegen/SimCode/SimCodeCpp.tpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,17 +3513,18 @@ case SES_MIXED(__) then
35133513
bool restart<%num%> = true;
35143514
int iter<%num%>=0;
35153515
int max_iter<%num%> = <%valuesLenStr%> / <%numDiscVarsStr%>;
3516-
while(restart<%num%> && !(iter<%num%>++ > max_iter<%num%>))
3516+
while(restart<%num%> && !(iter<%num%> > max_iter<%num%>))
35173517
{
35183518
<%discVars |> SIMVAR(__) hasindex i0 => 'pre_disc_vars<%num%>[<%i0%>] = <%cref(name)%>;' ;separator="\n"%>
35193519
<%contEqs%>
35203520
checkConditions(0,true);
35213521
<%preDisc%>
35223522
<%discvars2%>
35233523
bool* cur_disc_vars<%num%>[<%numDiscVarsStr%>]= {<%discVars |> SIMVAR(__) => '&<%cref(name)%>' ;separator=", "%>};
3524-
restart<%num%>=!(_event_handling.CheckDiscreteValues(values<%num%>,pre_disc_vars<%num%>,new_disc_vars<%num%>,cur_disc_vars<%num%>,<%numDiscVarsStr%>,iter<%num%>));
3524+
restart<%num%>=!(_event_handling.CheckDiscreteValues(values<%num%>,pre_disc_vars<%num%>,new_disc_vars<%num%>,cur_disc_vars<%num%>,<%numDiscVarsStr%>,iter<%num%>,<%valuesLenStr%>));
3525+
iter<%num%>++;
35253526
}
3526-
if(iter<%num%>>max_iter<%num%>)
3527+
if(iter<%num%>>max_iter<%num%> && (restart<%num%> == true) )
35273528
{
35283529
throw std::runtime_error("Number of iteration steps exceeded for discrete varibales check . ");
35293530
}

SimulationRuntime/cpp/Source/SettingsFactory/Implementation/GlobalSettings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
GlobalSettings::GlobalSettings()
77
: _startTime (0.0)
8-
, _endTime (10.0)
9-
, _hOutput (0.02)
8+
, _endTime (1)
9+
, _hOutput (1e-4)
1010
, _resultsOutput (true)
1111
, _infoOutput (true)
1212
, selected_solver("Euler")

SimulationRuntime/cpp/Source/Solver/Euler/Implementation/EulerSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
EulerSettings::EulerSettings(IGlobalSettings* globalSettings)
66
: SolverSettings (globalSettings)
7-
, _method (EULERFORWARD)
7+
, _method (EULERBACKWARD)
88
, _zeroSearchMethod (BISECTION)
99
, _denseOutput (true)
1010
, _useSturmSequence (false)

SimulationRuntime/cpp/Source/Solver/Implementation/SolverSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SolverSettings::SolverSettings( IGlobalSettings* globalSettings)
88
, _hUpperLimit (globalSettings->getEndTime() - globalSettings->getStartTime())
99
, _hLowerLimit (10*UROUND)
1010
, _endTimeTol (1e-6)
11-
, _zeroTol (1e-8)
11+
, _zeroTol (1e-6)
1212
, _zeroTimeTol (1e-6)
1313
,_zeroRatio(1.0)
1414

SimulationRuntime/cpp/Source/System/Implementation/EventHandling.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void EventHandling::addTimeEvents( event_times_type times)
195195
}
196196

197197
}
198-
bool EventHandling::CheckDiscreteValues(bool* values,bool* pre_values,bool* next_values, bool** cur_values,unsigned int size,unsigned int cur_index)
198+
bool EventHandling::CheckDiscreteValues(bool* values,bool* pre_values,bool* next_values, bool** cur_values,unsigned int size,unsigned int cur_index,unsigned int num_values)
199199
{
200200

201201
bool found=true;
@@ -204,8 +204,12 @@ bool EventHandling::CheckDiscreteValues(bool* values,bool* pre_values,bool* nex
204204
{
205205
for (int i = 0; i < size; i++)
206206
{
207-
208-
*cur_values[i] = values[cur_index * size + i];
207+
int index = cur_index * size + i;
208+
209+
if(index < (num_values-1))
210+
*cur_values[i] = values[index];
211+
else
212+
break;
209213
}
210214
}
211215
return found;
@@ -220,6 +224,7 @@ event_times_type EventHandling::makePeriodeEvents(double ts,double te,double int
220224
double val = ts;
221225
while(val < te)
222226
{
227+
223228
periode.insert(make_pair(real_cast<double>(val),index));
224229
val += interval;
225230
}

SimulationRuntime/cpp/Source/System/Implementation/EventHandling.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class BOOST_EXTENSION_EVENTHANDLING_DECL EventHandling
5353
///returns the vector with all time events
5454
event_times_type& getTimeEvents();
5555
resetHelpVar_type resetHelpVar;
56-
bool CheckDiscreteValues(bool* values,bool* pre_values,bool* next_values, bool** cur_values,unsigned int size,unsigned int cur_index);
56+
bool CheckDiscreteValues(bool* values,bool* pre_values,bool* next_values, bool** cur_values,unsigned int size,unsigned int cur_index,unsigned int num_values);
5757
private:
5858
//Stores all varibales occured before an event
5959
unordered_map<string,double> _pre_vars;

0 commit comments

Comments
 (0)