Changes between Initial Version and Version 2 of Ticket #3419


Ignore:
Timestamp:
2015-08-25T07:48:58Z (9 years ago)
Author:
Rüdiger Franke
Comment:

In the model m I want to create a kind of a closure that holds the additional argument v and provides an operator() that calls func:

    class _Closure_func
    {
      double &v;
     public:
      _Closure_func(double &v)
        : v(v)
      {}
      double operator()(double u) {
        return func(u, v);
      }
    };

This way the code for the function call in model m can look like:

  y = feval(_Closure_func(2.0), 1.0 + u);

The code for the function feval can look like

template <class _fnptr_part>
double feval(_fnptr_part f, double u)
{
  double y;
  y = f(u);
  return y;
}

The problem is the missing type information for for u and v (at least for u) in PARTEVALFUNC when generating code the closure. The function itself can be implemented with template, because Modelica does not enforce inheritance of func from part. But a specific name containing the interface function part should be used -- this is not known in the current FUNTION_PTR.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #3419 – Description

    initial v2  
    1010
    1111function func
    12   extends part;
     12  input Real u;
    1313  input Real v;
     14  output Real y;
    1415algorithm
    1516  y := u + v;
     
    1819function feval
    1920  input part f;
     21  input Real u;
    2022  output Real y;
    2123algorithm
    22   y := f(1);
     24  y := f(u);
    2325end feval;
    2426
    2527model m
    26   Real y = feval(function func(v = 2));
     28  input Real u = 0; // prevent presolving
     29  Real y = feval(function func(v = 2), u + 1);
    2730end m;
    2831}}}