Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Failed to allocate Variables - Using real inputs

Failed to allocate Variables - Using real inputs

If anyone has any insight into my problem I would greatly appreciate it. I've stared at it for hours and hours and I think I've just about reached my limit current/sad.

Below is a simplified code that demonstrates my error.

Problem Description:
The program checks to see if the input box is true or false indicating that input data will be given to the program. If false the code generates its own data.
Now, from the data that is either inputed or created internally (nodeVal or nodeVal_Internal) I want to do a simple manipulation of the data and create a new array called edgeVal which is one node fewer than nodeVal /nodeVal _Internal. This edgeVal is a simple average of the values of i and i+1.

Error:
The code as contained below gives errors 'failed to allocate variables' when I try to simulate, but is fine during a 'check'. However, if I change the 'i+1' term in edgeVal to 'i' then the code works, but I'm no longer calculating an average!
Related point, the variable blah seems to be required to use the last value of nodeVal_Internal. If I have that 'i+1' term be 'i' and comment out blah, I get the failed to allocate variables error again but no warning with a simple 'check'.

Question:
What modification to the code below is required for it to run? This is likely related to not understanding what the error really means and perhaps as well to how the input variables and check for on/off is used.

Thank you so very much in advance.
Using Dymola 2016 - failed allocation error
OM v1.9.3 - doesn't solve no matter what. says too many equations for the # of variables (over determined system)

*******

model blarg

  parameter Integer nodes = 4;

  parameter Boolean use_nodeVal = false
    annotation(Evaluate=true, HideResult=true, choices(checkBox=true));

  Modelica.Blocks.Interfaces.RealInput[nodes] nodeVal if use_nodeVal
    annotation (Placement(transformation(extent={{-140,-60},{-100,-20}},
          rotation=0), iconTransformation(extent={{7.25,-7.25},{-7.25,7.25}},
        rotation=180,
        origin={-17.75,-79.75})));

  Real edgeVal[1,nodes-1];
//   Real blah;
protected
     Modelica.Blocks.Interfaces.RealInput[nodes] nodeVal_Internal
    "Needed to connect to conditional connector";

equation
  connect(nodeVal_Internal, nodeVal);
  if not use_nodeVal then
    nodeVal_Internal = 2000 * ones(nodes);
  end if;

//   blah = nodeVal_Internal[nodes];
  edgeVal[1,1:nodes-1] = {(nodeVal_Internal[i] + nodeVal_Internal[i])/2 for i in 1:nodes - 1};

end blarg;

*****

Edited by: greenwom - Oct-29-15 18:53:28

Re: Failed to allocate Variables - Using real inputs

Bump. Still no solution...

Re: Failed to allocate Variables - Using real inputs

For those who care:

A solution to the problem is to introduce a variable that is equivalent variable wanting to be looped (i.e. nodeVal_Internal) and loop over that instead. I think the issue is that the nodeVal_Internal is 'protected' though it's still a bit fuzzy to me about why exactly that matters. But the solution is good enough for me for now.

I removed 'blah' and replaced nodeVal_Internal with temp in edgeVal and changed one instance of  temp[i] to temp[i+1].

Hope that helps someone.

********

model blarg

  parameter Integer nodes = 4;

  parameter Boolean use_nodeVal = false
    annotation(Evaluate=true, HideResult=true, choices(checkBox=true));

  Modelica.Blocks.Interfaces.RealInput[nodes] nodeVal if use_nodeVal
    annotation (Placement(transformation(extent={{-140,-60},{-100,-20}},
          rotation=0), iconTransformation(extent={{7.25,-7.25},{-7.25,7.25}},
        rotation=180,
        origin={-17.75,-79.75})));

  Real edgeVal[1,nodes-1];
  Real temp[nodes];
protected
     Modelica.Blocks.Interfaces.RealInput[nodes] nodeVal_Internal
    "Needed to connect to conditional connector";

equation
  connect(nodeVal_Internal, nodeVal);
  if not use_nodeVal then
    nodeVal_Internal = 2000 * ones(nodes);
  end if;
  temp = nodeVal_Internal;
  edgeVal[1,1:nodes-1] = {(temp[i] + temp[i+1])/2 for i in 1:nodes - 1};

end blarg;

There are 0 guests and 0 other users also viewing this topic
You are here: