Opened 11 years ago

Closed 6 years ago

Last modified 6 years ago

#2318 closed defect (fixed)

Strange tuple in initial equation in Modelica.Blocks.Examples.Filter

Reported by: Peter Aronsson Owned by: Lennart Ochel
Priority: normal Milestone: Future
Component: Backend Version: trunk
Keywords: Cc: Willi Braun

Description (last modified by Martin Sjölund)

Modelica.Blocks.Examples.Filter returns this equation in the flat model:

(CriticalDamping.r, {}, {}, {}) = Modelica.Blocks.Continuous.Internal.Filter.roots.lowPass({CriticalDamping.cr[1], CriticalDamping.cr[2], CriticalDamping.cr[3]}, {}, {}, CriticalDamping.f_cut);

Shouldn't this instead be:

(CriticalDamping.r, , , ) = Modelica.Blocks.Continuous.Internal.Filter.roots.lowPass({CriticalDamping.cr[1], CriticalDamping.cr[2], CriticalDamping.cr[3]}, {}, {}, CriticalDamping.f_cut);

Change History (21)

comment:1 by Adrian Pop, 11 years ago

Owner: changed from somebody to Adrian Pop
Status: newassigned

I'll have a look.

comment:2 by Adrian Pop, 11 years ago

Is not strange.
It comes from equation:

        if filterType == Modelica.Blocks.Types.FilterType.LowPass then
          (r, a, b, ku) = Internal.Filter.roots.lowPass(cr, c0, c1, f_cut);

and for component:

        Modelica.Blocks.Continuous.Filter CriticalDamping(
          analogFilter = Modelica.Blocks.Types.AnalogFilter.CriticalDamping, 
          normalized = normalized, 
          init = init, filterType = filterType, 
          order = order, 
          f_cut = f_cut, 
          f_min = 0.8 * f_cut);

filterType is LowPass which means that equation will be selected.

components a, b, ku are arrays of 0 size, which mean they disappear from the DAE.

        parameter Real[na] a(each fixed = false);
        parameter Real[na] b(each fixed = false);
        parameter Real[na] ku(each fixed = false);

I don't know if it would be better to put them as empty instead of {}.

comment:3 by Peter Aronsson, 11 years ago

Priority: highnormal

Yes, I realized that when I wrote the ticket, but wouldn't it be nicer from a backend perspective if those were rewritten to "empty slots" instead, which is standard Modelica? That way, the backend doesn't have to deal with all possible empty arrays that could be in there, e.g.

{}, {{}}, {{{}}}

And the backend still needs to take care of the case


(a,,) = foo(b,c)

, so it would simplify the backend alot.

This is not supercritical for us right now, since I've made a workaround for now, but all attempts at simplifying stuff are good, I think ;-)

Last edited 11 years ago by Peter Aronsson (previous) (diff)

comment:4 by Adrian Pop, 11 years ago

I think that we should actually keep all zero size components and zero size equations/algorithms in the DAE and they can be removed by the back-end.
What do you think about this?

comment:5 by Martin Sjölund, 11 years ago

Milestone: 1.9.01.9.1

Postponed until 1.9.1

comment:6 by Martin Sjölund, 10 years ago

Description: modified (diff)

comment:7 by Martin Sjölund, 10 years ago

Component: FrontendBackend
Owner: changed from Adrian Pop to Lennart Ochel

It's a very small diff to change this, but our backend cannot handle it:

  • Compiler/FrontEnd/InstSection.mo

     
    13771377algorithm
    13781378  outDae := matchcontinue (inExp1,inExp2,inType3, inConst, source,inInitial4)
    13791379    local
    1380       DAE.DAElist dae; DAE.Exp e1,e2;
     1380      DAE.DAElist dae;
     1381      DAE.Exp e,e1,e2;
    13811382      SCode.Initial initial_;
    13821383      DAE.ComponentRef cr;
    13831384      DAE.Type t;
     
    13851386      DAE.Type tt;
    13861387      list<DAE.Exp> exps1,exps2;
    13871388      list<DAE.Type> tys;
     1389      Boolean b;
    13881390
    13891391    case (e1,e2,DAE.T_INTEGER(varLst = _),_,_,initial_)
    13901392      equation
     
    14201422      then dae;
    14211423
    14221424    // tuples
     1425    case (DAE.TUPLE(e::_),e2,DAE.T_TUPLE(tupleType = t::tys),_,_,initial_)
     1426      equation
     1427        b = List.fold(List.map(tys,Types.isEmptyArray),boolAnd,true);
     1428        e1 = Util.if_(b,e,inExp1);
     1429        // e2 = Util.if_(b,DAE.TSUB(inExp2,1,t),inExp2);
     1430        dae = makeDaeEquation(e1, e2, source, initial_);
     1431      then
     1432        dae;
    14231433    case (e1,e2,DAE.T_TUPLE(tupleType = _),_,_,initial_)
    14241434      equation
    14251435        dae = makeDaeEquation(e1, e2, source, initial_);

(The result is the equation is split into 3, but without ASUB. So it is slower, and even if it worked, it would be slower.)

I am reassigning this to backend, to see if we can change the flat code.

comment:8 by Martin Sjölund, 10 years ago

The failing models in the testsuite with those changes:

./simulation/libraries/msl32/Modelica.Blocks.Examples.Filter.mos
./simulation/libraries/msl32/Modelica.Blocks.Examples.FilterWithRiseTime.mos
./simulation/libraries/msl32/Modelica.Electrical.Machines.Examples.SynchronousInductionMachines.SMEE_Rectifier.mos

It seems to also be the only models where this pattern applies.

comment:9 by Martin Sjölund, 10 years ago

Cc: Willi Braun added

comment:10 by Lennart Ochel, 10 years ago

The model from the description works fine as well as the ones Martin listed. Is this just about generating nicer equations in the flat code and maybe simplify back end work or is there a actually defect?

comment:11 by Martin Sjölund, 10 years ago

Yes, it's about making something simpler for the back-end (since it works for us, I guess simpler for WSM).

With my changes, the flattened code is simpler, but we generate bad code:

Modelica.Blocks.Examples.Filter_06inz.c:1154:31: error: assigning to
      'modelica_real' (aka 'double') from incompatible type 'real_array_t' (aka
      'struct base_array_s')
  ...= div_alloc_real_array(sub_alloc_real_array(omc_Modelica_Blocks_Continuous_Internal_Filter_roots_lowPass(threadData, tmp31, _OMC_LIT18, _OMC_LIT19, $PCriticalDamping$Pf_cut, NULL, NULL, NULL), tmp32), _OMC_LIT20);

So there is a bug because if we make things simpler, the back-end does unexpected things.

I will make the commit that changes from empty arrays to DAE.CREF(DAE.WILD()) since our back-end handles that. But I suggest we keep this ticket open until our back-end handles changing the call to simply be:

  CriticalDamping.r = Modelica.Blocks.Continuous.Internal.Filter.roots.lowPass({CriticalDamping.cr[1], CriticalDamping.cr[2], CriticalDamping.cr[3]}, {}, {}, CriticalDamping.f_cut);

Instead of:

  (CriticalDamping.r, _, _, _) = Modelica.Blocks.Continuous.Internal.Filter.roots.lowPass({CriticalDamping.cr[1], CriticalDamping.cr[2], CriticalDamping.cr[3]}, {}, {}, CriticalDamping.f_cut);

comment:12 by Martin Sjölund, 10 years ago

r22700 has the changes suggested for the front-end. Still not optimizing everything away.

comment:13 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:14 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:15 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:16 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:17 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:18 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:19 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:20 by Francesco Casella, 7 years ago

Milestone: 1.12.0Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

comment:21 by Francesco Casella, 6 years ago

Resolution: fixed
Status: assignedclosed

Given comment:12, I guess we can close this. Feel free to reopen if necessary.

Last edited 6 years ago by Francesco Casella (previous) (diff)
Note: See TracTickets for help on using tickets.