- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Finite Element, Modelica, and Sparse...
Finite Element, Modelica, and Sparse Matrices
Finite Element, Modelica, and Sparse Matrices
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
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.
Re: Finite Element, Modelica, and Sparse Matrices
You might be interested in this paper:
http://dx.doi.org/10.3384/ecp15118459
https://github.com/casella/ScalableTestSuite
Re: Finite Element, Modelica, and Sparse Matrices
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!
Re: Finite Element, Modelica, and Sparse Matrices
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;
Re: Finite Element, Modelica, and Sparse Matrices
If you are using an equation section, note that all loops need to have constant ranges. I suspect you want to use an algorithm section here, or declaring rid as a constant.
- sjoelund.se
- 1700 Posts
Re: Finite Element, Modelica, and Sparse Matrices
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
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Finite Element, Modelica, and Sparse...