Bug in optimisations where parameter with fixed=false has start attribute that contains an expression

1 post / 0 new
Mathadon
Offline
Joined: 2014-01-03
Bug in optimisations where parameter with fixed=false has start attribute that contains an expression

I think I found a bug in my fork of JModelica, which is based on rev. 9603.

In model Buildings.Fluid.SolarCollectors.BaseClasses.EN12975HeatLoss we have following code:
parameter Modelica.SIunits.ThermalConductance UA(

fixed = false,

start=QLos_nominal/(dT_nominal))

Coefficient describing heat loss to ambient conditions";

 

In optimisation problems, the casadi parameter value for UA (with fixed=false) is fetched from the start attribute in Model::setUpValAndSymbolVecs(). In this case the start attribute however contains an expression instead of a constant. This is not supported properly by JModelica. More specifically the 'else' part of this piece of code does not support it:
    void Model::setUpValAndSymbolVecs() {
        paramAndConstMXVec.clear();
        paramAndConstValVec.clear();
        for (vector< Variable * >::iterator it = z.begin(); it != z.end(); ++it) {
            if ( ((*it)->getVariability() == Variable::PARAMETER) ||
            ((*it)->getVariability() == Variable::CONSTANT)) {
                if ((*it)->hasAttributeSet("bindingExpression")) {
                    // If it's a parameter with a non constant binding expression it
                    // is a dependent parameter, and its value needs to be calculated.
                    MX bindingExpression = *(*it)->getAttribute("bindingExpression");
                    if (bindingExpression.is_constant()) {
                        paramAndConstMXVec.push_back((*it)->getVar());
                        paramAndConstValVec.push_back(double(bindingExpression));
                    }
                }
                else {
                    paramAndConstValVec.push_back(double(*(*it)->getAttribute("start")));
                    paramAndConstMXVec.push_back((*it)->getVar());
                }
            }
        }
    }

An error is produced by line
paramAndConstValVec.push_back(double(*(*it)->getAttribute("start")));

that looks like:

RuntimeError:  on line 394 of file "/media/psf/Home/Documents/Software/JModelica-9608/JModelica.org/ThirdParty/CasADi/CasADi/casadi/core/mx/mx_node.cpp"
MXNode::to_double not defined for class N6casadi8BinaryMXILb1ELb0EEE