Skip to content

Commit

Permalink
- Fixed bug in state selection. If StateSelect.always is set but vari…
Browse files Browse the repository at this point in the history
…able does not appears differentiated among equations, it was previously not selected as state.

- Fixed bug in printing error message for non-linear system solving.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2704 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Feb 12, 2007
1 parent 67b5bc2 commit cedceaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
26 changes: 16 additions & 10 deletions Compiler/DAELow.mo
Expand Up @@ -4509,7 +4509,7 @@ algorithm
name_1 = Exp.crefStripLastSubs(name);
origname = Exp.printComponentRefStr(name_1);
newname = Exp.CREF_IDENT(origname,subs);
kind_1 = lowerVarkind(kind, tp, newname, dir, flow_, states);
kind_1 = lowerVarkind(kind, tp, newname, dir, flow_, states,dae_var_attr);
bind_1 = lowerBinding(bind);
start_1 = lowerBinding(start);
then
Expand Down Expand Up @@ -4636,46 +4636,52 @@ protected function lowerVarkind "function: lowerVarkind
input DAE.VarDirection inVarDirection;
input DAE.Flow inFlow;
input BinTree inBinTree;
input option<DAE.VariableAttributes> daeAttr;
output VarKind outVarKind;
algorithm
outVarKind:=
matchcontinue (inVarKind,inType,inComponentRef,inVarDirection,inFlow,inBinTree)
matchcontinue (inVarKind,inType,inComponentRef,inVarDirection,inFlow,inBinTree,daeAttr)
local
Exp.ComponentRef v,cr;
BinTree states;
DAE.VarDirection dir;
DAE.Flow flow_;
case (DAE.VARIABLE(),_,v,_,_,states)
// States appear differentiated among equations
case (DAE.VARIABLE(),_,v,_,_,states,daeAttr)
equation
_ = treeGet(states, v);
then
STATE();
case (DAE.VARIABLE(),DAE.BOOL(),cr,dir,flow_,_)
// Or states have StateSelect.always
case (DAE.VARIABLE(),_,v,_,_,states,SOME(DAE.VAR_ATTR_REAL(_,_,_,_,_,_,_,SOME(DAE.ALWAYS()))))
then STATE();

case (DAE.VARIABLE(),DAE.BOOL(),cr,dir,flow_,_,_)
equation
failure(topLevelInput(cr, dir, flow_));
then
DISCRETE();
case (DAE.DISCRETE(),DAE.BOOL(),cr,dir,flow_,_)
case (DAE.DISCRETE(),DAE.BOOL(),cr,dir,flow_,_,_)
equation
failure(topLevelInput(cr, dir, flow_));
then
DISCRETE();
case (DAE.VARIABLE(),DAE.INT(),cr,dir,flow_,_)
case (DAE.VARIABLE(),DAE.INT(),cr,dir,flow_,_,_)
equation
failure(topLevelInput(cr, dir, flow_));
then
DISCRETE();
case (DAE.DISCRETE(),DAE.INT(),cr,dir,flow_,_)
case (DAE.DISCRETE(),DAE.INT(),cr,dir,flow_,_,_)
equation
failure(topLevelInput(cr, dir, flow_));
then
DISCRETE();
case (DAE.VARIABLE(),_,cr,dir,flow_,_)
case (DAE.VARIABLE(),_,cr,dir,flow_,_,_)
equation
failure(topLevelInput(cr, dir, flow_));
then
VARIABLE();
case (DAE.DISCRETE(),_,cr,dir,flow_,_)
case (DAE.DISCRETE(),_,cr,dir,flow_,_,_)
equation
failure(topLevelInput(cr, dir, flow_));
then
Expand Down Expand Up @@ -6908,7 +6914,7 @@ algorithm
(dae,m,mt,nv,nf,deqns) = differentiateEqns(dae, m, mt, nv, nf, eqns_1);
(state,stateno) = selectDummyState(states, stateindx, dae, m, mt);
//print("Selected ");print(Exp.printComponentRefStr(state));print(" as dummy state\n");
// print(" From candidates:");print(Util.stringDelimitList(Util.listMap(states,Exp.printComponentRefStr),", "));print("\n");
//print(" From candidates:");print(Util.stringDelimitList(Util.listMap(states,Exp.printComponentRefStr),", "));print("\n");
dae = propagateDummyFixedAttribute(dae, eqns_1, state, stateno);
(dummy_der,dae) = newDummyVar(state, dae) ;
//print("Chosen dummy: ");print(Exp.printComponentRefStr(dummy_der));print("\n");
Expand Down
4 changes: 2 additions & 2 deletions c_runtime/matrix.h
Expand Up @@ -110,8 +110,8 @@ void * hybrj_(void(*) (int *,double*,double*,double *,int*, int*),
int i; \
modelErrorCode=ERROR_NONLINSYS; \
printf("error solving nonlinear system nr. %d at time %f\n",no,time); \
if (sim_verbose& LOG_NONLIN_SYS) { \
for (i = 0; i<no; i++) { \
if (sim_verbose & LOG_NONLIN_SYS) { \
for (i = 0; i<n; i++) { \
printf(" residual[%d] = %f\n",i,nls_fvec[i]); \
printf(" x[%d] = %f\n",i,nls_x[i]); \
} \
Expand Down

0 comments on commit cedceaf

Please sign in to comment.