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
  • Index
  • » Users
  • » greenwom
  • » Profile

Posts

Posts

Hmm...

In reference to my previous post, within the following loop:

for i in 1:n_nodes loop
**do stuff**
end for;

There are three separate for loops. Each of these loops must update the range of 'j' for each new 'i' loop. These are therefore constant for any given 'i' loop but not between 'i' loops.

When I have no time dependency (e.g. Temp references)  to simply ensure the balance of the problem functions I can move the problem to an algorithm section and things run great. However, the addition of the time dependent portions, as I understand it, require placement in an equation block. In reality not only does Temp depend on time but C, K, and H all depend on Temp and therefore time as well.

To help illustrate I attached a zip file with the files required to run the problem. I included a desired model (Test) and a model (Test_passcheck) that will pass a check and simulate but I don't believe is solving the problem correctly... (maybe I'm wrong and it is?).

The supporting files are titled. CK, Hh, and find_all. They should all be fine and not require any examination though feel free to explore.

I am using Dymola 2016 (32-bit) but am not using any Dymola specific additions.

If you have any pointers I would appreciate it.

CRS-TestFiles.zip

Pulling on the the subjects of hash tables and compressed spare row storage (CRS) etc. I am currently attempting to remove the requirement for Modelica to solve a full sparse matrix.

So far C and S are now compressed to a fraction of the full NxN size referenced previously and are stored in triplet format or CRS where the row and column index (i,j) of each nonzero entry and the entry itself are stored in three separate vectors (rid, cid, s).

The next hurdle appears to be in solving the ODE. Below is the code associated with the loop.

**Problem!!! **
When I go to 'check' this portion it states that it is unable to expand the for-statement 'since it was impossible to expand the loop-indices'.
Is it possible that the for loop is too complicated or is having the der() operator causing a problem?

Feel free to opine.


For reference a sample of what rid, cid, and C/K look like are (fictitious values):
rid = {1,1,1,2,2,3,3,3,3,4,4,0,0,0,0}
cid = {1,3,4,2,1,3,4,1,2,2,3,0,0,0,0}
C/K = {10,22,15,1,3,6,8,9,1,2,2,0,0,0,0}
  for i in 1:n_nodes loop
    for j in Vectors.find(i,rid):(if i+1>n_nodes then Vectors.find(0,rid)-1 else Vectors.find(i+1,rid)-1) loop
      PartA[i] = PartA[i] + C[j]*der(Temp[cid[j]]) + K[j]*Temp[cid[j]];
    end for;

    for j in Vectors.find(i,rid):(if i+1>n_nodes then Vectors.find(0,rid)-1 else Vectors.find(i+1,rid)-1) loop
      PartB[i] = PartB[i] + K[j]*Temp[cid[j]];
    end for;

    for j in Vectors.find(i,H_rid):(if i+1>n_nodes then Vectors.find(0,H_rid)-1 else Vectors.find(i+1,H_rid)-1) loop
      PartC[i] = PartC[i] + H[j]*Temp[H_cid[j]];
    end for;

    PartA[i] + PartB[i] + PartC[i] = g[i] + qs[i] + Htinf[i];
  end for;

Thanks for the references. Interesting. I've come across some papers from some of the past international modelica conferences I believe that similarly indicate the shortcoming of modelica in the sparse solution space. Improved solvers seem to be a ripe area for advancement.

So far there still seems to be no good solution directly supported but the best bet, for my problem at least, is to attempt to avoid sparse matrices altogether and create a matrix in triplet format directly.  Hopefully I can figure that out!

I have implemented a 2D finite element method (for thermal conduction in my case) into Modelica successfully. (*pats himself on the back*)

Now the question comes... how can I speed it up (order of magnitude or more preferably (e.g. double matrix size causes order of magnitude time penalty).

Forgive the reference to Matlab as I'm going through a conversion process to Modelica current/smile

Take the problem below:

C*der(T) + S*T = R

where T and R are vectors of length N, C and S are sparse matrices of NxN

As I now understand it given the number of variables message window when run, Modelica does not recognize the sparsity and therefore defines and carries out calculations for each value of the NxN matrices (i.e. this can be thousands of variables though >90% are trivial (=0)). Clearly this is inefficient.

Now I thought of attempting to condense the sparse matrices similar to Matlab approach (i.e. storing only nonzero values in i,j,s format --- see Matlab's sparse documentation) and then use for loops in the identifying der(T) values.  Perhaps this will be faster, perhaps not. I haven't tried it yet and wanted some community involvement if possible as I am clearly not the first to come across to this issue.

So that's my question to those with more experience...
-What exactly is this sparse solver capability?
-Is there a recognized solution yet to this common sparse matrix problem?

Thanks folks.

Nov-04-15 21:32:27
Error 'failed to allocate variables' occurs during simulation but not 'check'
Category: Developer

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;

Nov-02-15 23:05:03
Error 'failed to allocate variables' occurs during simulation but not 'check'
Category: Developer

Bump. Still no solution...

Oct-29-15 18:33:04
Error 'failed to allocate variables' occurs during simulation but not 'check'
Category: Developer

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;

*****

  • Index
  • » Users
  • » greenwom
  • » Profile
You are here: