Skip to content

Commit

Permalink
Fix in cpp template in mixed systems discrete vars iteration
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10994 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Feb 1, 2012
1 parent 8057771 commit 1905f0a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
7 changes: 4 additions & 3 deletions Compiler/susan_codegen/SimCode/SimCodeCpp.tpl
Expand Up @@ -3513,17 +3513,18 @@ case SES_MIXED(__) then
bool restart<%num%> = true;
int iter<%num%>=0;
int max_iter<%num%> = <%valuesLenStr%> / <%numDiscVarsStr%>;
while(restart<%num%> && !(iter<%num%>++ > max_iter<%num%>))
while(restart<%num%> && !(iter<%num%> > max_iter<%num%>))
{
<%discVars |> SIMVAR(__) hasindex i0 => 'pre_disc_vars<%num%>[<%i0%>] = <%cref(name)%>;' ;separator="\n"%>
<%contEqs%>
checkConditions(0,true);
<%preDisc%>
<%discvars2%>
bool* cur_disc_vars<%num%>[<%numDiscVarsStr%>]= {<%discVars |> SIMVAR(__) => '&<%cref(name)%>' ;separator=", "%>};
restart<%num%>=!(_event_handling.CheckDiscreteValues(values<%num%>,pre_disc_vars<%num%>,new_disc_vars<%num%>,cur_disc_vars<%num%>,<%numDiscVarsStr%>,iter<%num%>));
restart<%num%>=!(_event_handling.CheckDiscreteValues(values<%num%>,pre_disc_vars<%num%>,new_disc_vars<%num%>,cur_disc_vars<%num%>,<%numDiscVarsStr%>,iter<%num%>,<%valuesLenStr%>));
iter<%num%>++;
}
if(iter<%num%>>max_iter<%num%>)
if(iter<%num%>>max_iter<%num%> && (restart<%num%> == true) )
{
throw std::runtime_error("Number of iteration steps exceeded for discrete varibales check . ");
}
Expand Down
Expand Up @@ -5,8 +5,8 @@

GlobalSettings::GlobalSettings()
: _startTime (0.0)
, _endTime (10.0)
, _hOutput (0.02)
, _endTime (1)
, _hOutput (1e-4)
, _resultsOutput (true)
, _infoOutput (true)
, selected_solver("Euler")
Expand Down
Expand Up @@ -4,7 +4,7 @@

EulerSettings::EulerSettings(IGlobalSettings* globalSettings)
: SolverSettings (globalSettings)
, _method (EULERFORWARD)
, _method (EULERBACKWARD)
, _zeroSearchMethod (BISECTION)
, _denseOutput (true)
, _useSturmSequence (false)
Expand Down
Expand Up @@ -8,7 +8,7 @@ SolverSettings::SolverSettings( IGlobalSettings* globalSettings)
, _hUpperLimit (globalSettings->getEndTime() - globalSettings->getStartTime())
, _hLowerLimit (10*UROUND)
, _endTimeTol (1e-6)
, _zeroTol (1e-8)
, _zeroTol (1e-6)
, _zeroTimeTol (1e-6)
,_zeroRatio(1.0)

Expand Down
Expand Up @@ -195,7 +195,7 @@ void EventHandling::addTimeEvents( event_times_type times)
}

}
bool EventHandling::CheckDiscreteValues(bool* values,bool* pre_values,bool* next_values, bool** cur_values,unsigned int size,unsigned int cur_index)
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)
{

bool found=true;
Expand All @@ -204,8 +204,12 @@ bool EventHandling::CheckDiscreteValues(bool* values,bool* pre_values,bool* nex
{
for (int i = 0; i < size; i++)
{

*cur_values[i] = values[cur_index * size + i];
int index = cur_index * size + i;

if(index < (num_values-1))
*cur_values[i] = values[index];
else
break;
}
}
return found;
Expand All @@ -220,6 +224,7 @@ event_times_type EventHandling::makePeriodeEvents(double ts,double te,double int
double val = ts;
while(val < te)
{

periode.insert(make_pair(real_cast<double>(val),index));
val += interval;
}
Expand Down
Expand Up @@ -53,7 +53,7 @@ class BOOST_EXTENSION_EVENTHANDLING_DECL EventHandling
///returns the vector with all time events
event_times_type& getTimeEvents();
resetHelpVar_type resetHelpVar;
bool CheckDiscreteValues(bool* values,bool* pre_values,bool* next_values, bool** cur_values,unsigned int size,unsigned int cur_index);
bool CheckDiscreteValues(bool* values,bool* pre_values,bool* next_values, bool** cur_values,unsigned int size,unsigned int cur_index,unsigned int num_values);
private:
//Stores all varibales occured before an event
unordered_map<string,double> _pre_vars;
Expand Down

0 comments on commit 1905f0a

Please sign in to comment.