- Index
- » Users
- » SKD
- » Profile
Posts
Posts
Hi,
I just experienced a problem. I defined an array with a variable size:
Real[:, :] TestArray;
Real TestSize;
And later in die equation (or algorithm) part I assigned the value of the array and then tried to read out the size of TestArray:
algorithm
TestArray := {{11,12,13}; {21,22,23}};
TestSize = size(TestArreay, 1);
When I simulated the value of TestSize was 0 all the time. I wasn't using OpenModelica but Wolfram System Modeler. The question that I have is: Is this behaviour normal? Is the size operator only allowed on arrays with a fixed size? In the official Modelica Spec a couldn't find anything...
Thanks!
If you can provide the right number of equations so that everything can be solved in my opinion there shouldn't be a problem!
Hey,
as far as I know, it is not possible to make optional connections with an connect-equation. You can try to overcome this problem by making all the connection equations yourself and setting the if-branch in each of them.
You could try and use the first version with the change that you set a start value for x like this:
Real x(start=2);
Anyhow, does the component work as it should when you set parameters in the text view?
I think it really depends on the situation that you have. Can you give an example?
That seems very strange. I sometime have problems like that as well, but in my case I'm never 100% sure I hadn't changed anything else
Did you save in between and opened it again? Or did you just change parameter values? I have sometimes a feeling that something is changed when I save...
When does the error occur? When you start the simulation or while the simulation is running.
If its on start, you could try to provide start values.
for example
model AUT
Real X(start=1);
.
...
.
end model;
But it doesn't necessarily need to be the variable X, it could also come from another equation, that is transformed in order to solve the system.
Okay, first of all, there are components in the modelica standard library (MSL) that you can use. You don't need to model the engine that drives compressor yourself. At first i would make it constant anyway.
Maybe you should read some Tutorials first.
First you need to create your connector. Think about which Variables you need to communicate between the components. I think you need massflow, pressure as well as temperature and enthalpie is sufficient. The connector Model would look like this
connector Con;
flow Real mFlow;
Real Pressure;
flow Real Enthalpie;
Real Temperature;
end Con;
Then you start with your first component, for example the compressor. For the first model I wouldnt bother with a connection to a motor, just put a constant mass flow rate. You also need two connectors (of type Con). I call them a and b.
model Compressor;
Con a;
Con b;
Real delta_p;
Real VolFlow;
Real T = Temperature;
constant Real R = 287;
equation
a.mFlow = - b.mFlow "What goes in goes out again";
a.mFlow = 5 "your constant flow, you can later set this by an external connector";
a.Pressure - b.Pressure = delta_p;
delta_p * VolFlow = a.mFlow * R * T;
// and so on, actually I don't know alot about thermodynamics myself, so you need to figure out the rest yourself. Hope it helps you to find a first start, though.
end Compressor;
Hey,
Your question isn't very specific, so I will give you only a general answer: Just describe all Components that you have in your System like: Condenser, Compressor and so on. Describe each Component with all the physicial equations that belong to it like p * V = m * R * T, and so on.
But I actually think that there are allready libraries for calculation of cooling Systems. You should do a little google search.
Well, you should try to find out, which variable becomes zeros. The only division in the above model is der(theta) = (-Vx) / X, but that doesn't necessarily mean, that it's that one, since the equations are getting rearranged in the order the computer needs them. You can try to do something like this:
der(thetha) = -(Vx) / (max(1e-5, abs(X))* sign(X))
At least for my calculations this often works well. I can't tell you why Dymola is handling this well why OM doesn't, though.
Well, "Real" is a floating-point number. The one with e-10 has the same number of digits as the other ones because the digits at the beginning do not count, since they are only zeros.
Yes you can. You can use connectors that are not using one flow per each potential variable, the only problem is that the models often won't even out regarding the numbers of equations versus number of unknowns. I have the same problem: If I connect all my components together everything evens out, but the single components don't.
Hi,
I'm trying around myself with the CombiTimeTable at the moment. I managed to get it to work in general. Try this example:
The CombiTimeTable seems to be kinda buggy though, at least in Wolfram SystemModeler. Sometimes I can't open a file that just before worked sweet. And after restart it works fine again. Please report whether you have issues like this, too so I can work out if this problem is WSM- or Modelica-specific.
Hi,
I'm currently working on a model, where I am using an input via a CombiTimeTable via an external file. These are volume flow values for certain times. When the values change, the model linearly interpolates between them. This is working fine so far. The problem is that I also need the derivative of these values. The system should be differentiable 1 time.
Just setting der(input_variable) doesnt work, so I tried to do it with annotation(derivative = function_name). Without the CombiTimeTable it worked well but when using it I allways get an error while compiling:
Warning: Failed to differentiate equation pumpExternal1.inp = combiTimeTable1.offset[1] + Modelica.Blocks.Sources.CombiTimeTable.tableTimeIpo(combiTimeTable1.tableID,combiTimeTable1.columns[1],time)
Warning: Failed to differentiate equation when initial() then
combiTimeTable1.tableID = Modelica.Blocks.Sources.CombiTimeTable.tableTimeInit(if NOT combiTimeTable1.tableOnFile then "NoName" else combiTimeTable1.tableName,if NOT combiTimeTable1.tableOnFile then "NoName" else combiTimeTable1.fileName,{{}},combiTimeTable1.startTime,combiTimeTable1.smoothness,combiTimeTable1.extrapolation)
end when
Error: Failed to reduce the DAE index.
error: No executable generated.C:/temp/sme_1404806824_13977.exe
error: No settings file generated.C:/temp/sme_1404806824_13977_init.sim
Note that I'm using Wolfram System Modeler. I'm not sure whether this behaviour is modelica oder programm specific.
Can't really give you any advice. Until now I only found theoretical papers on stream connectors but not a single real example that works. I'd love to see one!
It often makes sense if you simulate some event that happens at time = 0. It also doesn't make sense to restrict everything for no reason.
I'm still not whether I get the point. So you want to plot y over x without any relation of x to the time? I think this won't be possible since Modelica always simulates over a time. And if you want to do this you would have the problem that there is an infinitely large amount of different values for x for one time step. So there has to be some relation of any variable to the time (or constant values). At least this is what I think about that problem.
In the OMEdit plot window there are two icons showing a little graph, one x(t) and the other x(y). If you select the last one you can plot one variables above another variable.
So you don't need to set x = time.
For the second problem. I'm not quite sure, I guess you have to this from "outside" with commands in the OMShell console.
I'm not quite sure whether I understand this right. So this formula is for the bending of a beam? and y is how much it is of the neutral position?
I guess L ist the length of the beam, so it's also the x-variable. Just set x = time then and simulate as long as your beam is in seconds. After that just plot y.
I've just tried both models in Wolfram System Modeler. Both simulations "work", but in both cases x respectively cpt jump instantly on 11 and don't change after that.
I've also tried in in an older Version of OM but both models didn't compile.
I often have trouble using the pre()-function as well, so I am looking forward to hearing an answer on this
So if you press "Fix errors manually" the message comes again instantly? Without doing anything in between?
I didn't really find a sources that make this possible but you can try to make your own source:
just copy the code from Modelica.Blocks.Sources.Sine and add it into a new model
and then modify the code for example by adding the factor (time - startTime):
block Sine "Generate sine signal"
parameter Real amplitude=1 "Amplitude of sine wave";
parameter Modelica.SIunits.Frequency freqHz(start=1) "Frequency of sine wave";
parameter Modelica.SIunits.Angle phase=0 "Phase of sine wave";
parameter Real offset=0 "Offset of output signal";
parameter Modelica.SIunits.Time startTime=0 "Output = offset for time < startTime";
extends Modelica.Blocks.Interfaces.SO;
protected
constant Real pi=Modelica.Constants.pi;
equation
// y=offset + (if time < startTime then 0 else amplitude*Modelica.Math.sin(2*pi*freqHz*(time - startTime) + phase));
y=offset + (if time < startTime then 0 else Modelica.Math.sin(2*pi*freqHz*(time - startTime)^2 + phase));
end Sine;
To use this as a force you can connect it to Modelica.Mechanics.Translational.Sources.Force
Hi,
It definitely is possible to change parameter values without recompiling. As you suspected, there is an init-file for parameters and start values in xml format. Have a look at this thread for example: https://www.openmodelica.org/index.php/ … pic?id=715
Well, this is a very basic question. I recommend you read the official modelica specification https://www.modelica.org/documents/ModelicaSpec33.pdf or the tutorials of wolfram system modeler (you can use it with openmodelica as well) http://reference.wolfram.com/system-modeler/
I'm using Wolfram System Modeler and tried WSM Models in OpenModelica, what I realised was: annotations seem to be saved in another way, in openmodelica they are allways corrupted. openmodelica seems to be more "strict" regarding syntax. for example if you define a vector with a unit "Real[5] a(unit="m")" openmodelica gives an error or warning and you have to use "each", also sometimes i couldn't get complex systems to run in openmodelica and couldn't find the reason.
also: the format of the txt-file the.mo file) of wsm and om didn't match one was utf-8 and the other something else, not a big problem though...
Ok, I tried a lot, but it seems as if a connector in modelica doesn't work like a normal vector and you can't call them only by number-coordinates as in my example, also I couldn't get the size()-function to work. But what I found out is this:
if you have a matrix like this:
a={{1, 2, 5, 9 ,10},
{3, 4, 4, 1, 2},
{5, 6, 2, 1, 5}};
And you want to build sums columnwise, you can do it like this
b=sum(:,3) for the 3rd colum (b=5+4+2)
Of course you can also do it rowwise by swapping the coordinates.
Just in case anybody is searching the forum for help on the sum() function...
I'm stilling having problems. It seems like the matrix somehow has other dimensions as I thought.
Is it right that my connector con is a vector of size 6, so it's 1 dimension?
and also is it right that a=con[3] has the size [3, 6] (or 6, 3??) and two dimensions?
Ok, thx so far.
Is the order of the elements in the connector-vector the same as in the connector definition?
so if its
connector con
Real x;
Real[3] vector;
Real y;
Real z;
then it is {x, vector[1], vector[2], vector[3], y, z, } and so on?
Hi,
Currently I have a model with a connector "con", which contains a vector (size 4) "vector[3]" and some other values ("x"," y" , "z"), theres a total of 29 values in the connector.
Now there's a model which has more than one of this connector. Since there is a certain number of connectors (for example 2) on one side i did it like this
model test
con a[2];
...
equation
connect("
end test;
the model test is in con a connected to two other models
connect(test2.a,test.a[1]);
connect(test3.a,test.a[2]);
I guess the array as seen from model "test" now has this form:
[x, y, z, vector[1], vector[2], vector[3]] ||<- a[1]
[x, y, z, vector[1], vector[2], vector[3]] ||<- a[2]
so it's a [2, 6] matrix.
What I want to know is, how can I build the sum of the vector[1] of a[1] and vector[1] of a[2]?
I know I can do it with a loop, but is there a nicer way? Is it somehow possible to use the sum function just for a column of a matrix?
What I tried is: sum(a.vector[1], but this isn't working. Since the real matrix is a lot bigger and has a variable size, i dont want to do it by manually adding the values but rather use a sum function...
Thanks!
Hey,
I have a circuit containing one model with different parameters a few times. This components contain a terminate() statement, the time before the terminate is executed depends on the parameters. So when I simulate, and the condition at one component is fullfilled it gives a string like "the component is full". What I wand to do is: "the component "componentname" is full". So is there a command to get the name of the component? and how would I add in the terminate statement?
terminate("The component" + StringVariable + "is full") <- like this?
I don't have the time untill next week, but you could have a look at the built-in examples with the tanksystem, there you have another controll system.
model test
Real[3, 5] Matrix
equation
Matrix={{1,2,7,5,4.3}, {4, 6, 2.5, 90, 66}, {12, 13.333, 6, 9, 25}};
end test;
And if you want to access one value of the matrix it's for example:
a=Matrix[2, 5] (=66)
Is this what you wanted? What exactly do you mean by "even and odd"?
well, an annotation is just the graphical information of a model, for the simulation it isn't really necessary, Here the model obviously has a rectangle as an icon, the numbers {-60,62},{58,-44} are the coordinates of the corner points. the other stuff are color information of the lines and the filling of the rectangle and also about the Pattern of the solid. Don't think to complicated
Ok,
I'm still very new to modelica too although I spent a lot of time with it the last 2 months.
I tried a bit around with the model. The problem is that the numbers of variables and equations don't match.
I got the model to work when I put a component in front of it (dada) which has definded q and t and another component behind of it dada2 which basically does nothing
After that the numbers matched and I could simulate. I also removed the q and T equations IN your model.
Also I changed your q-equation as I said before. Heres the model:
package Nodes
connector FlowInlet
Real T;
flow Real q;
end FlowInlet;
model HEXDuctSection
FlowInlet Port1;
FlowInlet Port2;
equation
Port1.q + Port2.q=0;
Port1.T - Port2.T=1;
end HEXDuctSection;
partial model HEXShell
FlowInlet A1,A2;
end HEXShell;
model HEXn
extends HEXShell;
parameter Integer n(start=3);
HEXDuctSection DuctA[n];
equation
connect(A1,DuctA[1].Port1);
for i in 1:n - 1 loop
connect(DuctA[i].Port2,DuctA[i + 1].Port1);
end for;
connect(DuctA[n].Port2,A2);
end HEXn;
end Nodes;
model dada
Nodes.FlowInlet b;
equation
b.T=50;
b.q=500;
end dada;
model dada2
Nodes.FlowInlet a;;
end dada2;
model testneu
Nodes.HEXn HEXn1 ;
dada2 dada21;
dada dada1;
equation
connect(dada1.b,HEXn1.A1);
connect(HEXn1.A2,dada21.a);
end testneu;
This is not meant to be a fixed model, it is just kind of workaround and maybe gives you some help integrating your code in the simulation you want to run. I hope it helps.
I'd also be very interested in other solutions for the problem.
By the way: I also often have problems with the numbers of equations and variables. Since I often don't have equal numbers of flow and potential variables my models often have problems and I can't simulate the single components. But since I simulate models containing of more than one component it usually equals out somehow.
I know that this is "bad modeling" but often I don't find another way to do it.
Ok, I tried it in Wolfram System Modeler and get strange results, too. I don't really get it but there is an error message:
[error]: Invalid domain. pow(4.0 * (1.0 - fraction ^ (0.5 * b)), 0.5) evaluates to pow(-2e-10,0.5) "
ModelicaSpec3.3 says (p. 122):
Exponentiation "a^b" is defined as pow(double a,double b) in the ANSI C library if both "a" and "b" are Real
scalars. A Real scalar value is returned. If "a" or "b" are Integer scalars, they are automatically promoted to
122 Modelica Language Specification 3.3
"Real". Consequences of exceptional situations, such as (a==0.0 and b<=0.0, a<0 and b is not an integer) or
overflow are undefined
Ok, to be honest, I don't really understand what you did there. Since the model doesnt run (I'm using Wolfram System Modeler), I don't really know what you are trying to simulate nor how to fix it.
What I see is: You're using flow and potential variables in your connector. Flow variables in Modelica are positive for flow inside a model and negative for flow outside a model. So in your model HEXDuctSection, I guess you mean, that the inside flow is same as the outside flow, so it would have to be Port1.q+Port2.q=0.
With potential variables this is different, they are always positive, so Port1.T-Port2.T=1 means, that the inside Temperature is 1 kelvin (or whatever unit) higher than the outgoing, so this element is cooling. Is this the way it should be?
may I ask how your connector is defined? are you using "stream"-prefix for the temperature? can you post the code?
I'm not sure but I think this is what you mean:
https://build.openmodelica.org/Document … MLDAE.html
Ok thanks again. You were right with the session of OMShell. I've tried a few things so far.
Now I have a problem with a model that was created using Wolfram System Modeler. I can load in OMEdit and the check and instantiation works without problems. Only the view is a bit corrupted, but think that shouldn't matter for simulation.
When I try to simulate either in OMEdit or in the shell ( simulate() or buildModel() ), it crashes, without an error. In WSM the model and simulation works fine.
Do you know anything about compability between WSM and OpenModelica?
I also tried to export the simulationname.exe from WSM (which comes with a file named simulationname.sim (simular to the simulationname.xml from OpenModelica, but different) but since I dont have the xml, I can't get it to run (I tried using the "system()" command).
Is there any possibility to load the .exe or the c-code file without this file? Or is it possible to create this file using OpenModelica without buildModel() or simulate() (since this leads to a crash) . Or do you have an idea what the problem at compiling might be?
Ok thanks for the quick answer so far.
So now as my next step I tried a bit with OMShell and got the model built and simulated. However I can't get the results plotted.
Ok, so this is my model (testdatei.mo):
model test
Real x;
Real y;
equation
x = 1;
y = x;
end test;
in OMShell(after loading):
>>simulate(test)
record SimulationResult
resultFile = "test_res.mat",
messages = ""
end SimulationResult;
now i try to plot results:
>>plot({x,y})
{"_omc_PlotResult","C:/Users/wohlera/AppData/Local/Temp/OpenModelica/test_res.mat","Plot by OpenModelica","true","true","plot","false","false","time","","0.0","0.0","0.0","0.0","x","y"}
no window opens, also no "true" appears as should on success (https://build.openmodelica.org/Document … plot.html), I also tried opening it by giving the filename but still no success.
On this screenshot http://www.ida.liu.se/labs/pelab/modeli … enshot.jpg I saw, that they use a plt-file instead. I changed the filetype in the simulate command but I still couldn't open it.
What am I doing wrong?
Hey,
First of all I'm still pretty new in simulating with Modelica / OpenModelica, but I allready made some new models that can be simulated properly. I'm also not very into programming at this point, but might find some help if I have the basic strategy.
Now I would like to simulate my model in a very easy way, so even my mom could use the problem
My plan is to make a small executable with a GUI (where you can set some options/parameters) that reads the compiled code of the model and then simulates it.
As it seems to me, these compiled models still need another executable which contains the solver. Is that right?
My question would be, where can I find the programm part, that "solves" my equation and how would it be possible to interact with it?
I hope I made clear what my problem is since I'm still not that into programming.
Thanks very much in advance!
Stefan
- Index
- » Users
- » SKD
- » Profile