Integrating pump curve in Modellica.Fluid.Machines.ControlledPump - modelica

I'm a new user of OpenModelica. I'm trying to initialise variable-speed hydraulic pump curves in Modelica. I have 15 volumetric flow rates (m3/h) and 15 pump heads (m) for each pump speed (rev/min). I have been trying to use the following code for inputting these values into my model.
redeclare function flowCharacteristic =
Modelica.Fluid.Machines.BaseClasses.PumpCharacteristics.quadraticFlow (V_flow_nominal={},head_nominal={})
I encounter a translation error because the read-only system library only allows 3 elements in the V_flow_nominal and head_nominal array.
How do I obviate the error and still enter all data points I have?
How do I convert to SI units (m3/s and Pa)?

Setting the flowCharacteristic to Modelica.Fluid.Machines.BaseClasses.PumpCharacteristics.polynomialFlow should solve your problem for one speed. Values for other speeds are interpolated from this set of values. If you want to enter different values for other speeds you need a map-based model.

Related

How to use old value of variable with new value of variable in closed cycle in Openmodellica

I want to adjust the mass flow rate of a pump by using similarities laws so if I want to head and flow rate equation. I need to use old value and new value of head so that I can calculate new value of mass flow rate.
Can anybody tell me how can I write this in program in OpenModellica.
Generally Modelica is not designed to access "old values" of a continuous variable, as this is usually not necessary to model physical behavior. For discrete events there is the pre() operator, for clocks previous() but none of them is useful in continuous modeling.
What is common in continuous modeling, is to have relations based on the derivative der() of a variable, but not "old values". Personally I would double-check if you really need an old value or if that is just a form of abstraction chosen due to limitations of other software...
Still you can use the delay() operator as shown below to delay a signal by a fixed or a variable amount of time.
model DelayExample
Real x, y_fix, y_var;
equation
x = time;
y_fix = delay(x, 100e-3);
y_var = delay(x, min(time/2,0.2), 0.2);
end DelayExample;
The result is the following:
If you want to do use graphical modeling, you can use blocks from Modelica.Blocks.Nonlinear, namely
Modelica.Blocks.Nonlinear.FixedDelay
Modelica.Blocks.Nonlinear.PadeDelay
Modelica.Blocks.Nonlinear.VariableDelay

Difference in Workspace and Simulink step response. Why this difference?

I had as primary objective to make a controller for the transfer function (5.551* s^2), using root locus I made the controller shown below. Analyzing the step response in the Workspace using the step () function I had a satisfactory answer but when I try to transfer this answer to Simulink the response behaves differently, at steady state for example I wish to have the smallest possible error as it was obtained in Workspace but in Simulink there is a big error and for some reason at 8 seconds time (Simulink simulation time) there is a "jump" as shown on the display and when I change the simulation time there is a change in this "jump" too and I do not know why these changes between one environment and another.
Step response in Workspace
Step response in Simulink with 8s of simulation
Step response in Simulink with 12s of simulation
Simulink controller
Simulink transfer function
I expected to make a controller that has an error less than 5% and an overshoot smaller than 25%, so I first made a controller with two integrators to nullify the effects of zeros on the source, after that I added two more integrators on the source to try decrease the error, the zero at -0.652 I used the angular condition for this and the gain of 0.240251 I used the modular condition.
I wasn't expecting the most optimized behavior possible, just that it has minimum conditions that satisfy the imposed conditions, so I didn't worry for example about the four integrators at the source.
I tried use the sisotool() command thinking that I had done something wrong, but the result changed a lot when I was simulating Simulink so I discarded this option and kept the controller I made using root locus.
Your MATLAB code and your Simulink model are not the same, and hence the different results.
MATLAB allows you to define the non-causal plant model P_ball, then form the causal closed loop CL, which can have its step response generated.
Simulink does not allow you to model non-causal blocks (even if the overall model is causal) and hence will not allow you to implement s^2, which I assume is why you have used two differentiation blocks. But a numerical differentiation is not the same as a Laplace s operator.
You would have to make the plant causal by incorporating two poles that are large enough to not adversely effect the overall simulation. So your plant model needs to be something like 5.551*s^2/((s/1000 + 1)(s/1000 + 1)) which can be implemented using a Transfer Function block with a numerator of 5.551*1000*1000*[1 0 0] and a denominator of [1 2*1000 1000*1000].
Alternatively you could just implement PID * P_ball (where you manually do the 2 zero/pole cancellations) which is causal.

How I could make a temperature sweep in comsol?

I make a structure using Comsol then I want to make this structure subjected to a temperature variation ( T(begain)=25C then a temperature ramp (100 C/min) till T=250C and it lasts for 30 min then another temperature ramp (-100 C/min) till T=25C ).How could I make these temperature sweep?
You can define a function (e.g foo) that follows exactly your desired temperature with time profile. Then in the place where you specify your temperature (whether it is a boundary condition or domain condition) you insert foo(t), t being COMSOL's exclusive variable name for time.
You can do that for other variables too, space for instance. The easiest way to define foo is through the 1D interpolation option. Unfortunately, I do not currently have a COMSOL license to check it but I think you can simply enter the time and temperature values in the 1D interpolation table, choose a name and the interpolant style and just use it in the later part of the program.
I'am simulating magnetic fields in time domain with moving coils. Time dependent solver is needed for the movement and for temperature ramps as well. I think that you can use something like this, T=T_start+rate_of_change*t. The t variable is available with the time dependent solver and you can simply write the equation I mentioned. However, I think that you need to use time dependent solver three times, one for ramp up second for the constant temperature and third for the ramp down. Set the times for time dependent solvers so that you can made the desired temperatures.
First t=0s->(225/100*60)135s
second t=135s->(135+30*60)1935s
and last one t=1935s->(1935+135)2070s
You might also need to use compile solutions steps as well to add these three solutions together. I can try to do this tomorrow and check it.
Hope that this helped a bit

How to use the value of the variable in the previous interval as an input to the equation....?

Is it possible to use the previous value of the time varying variable
for eg:
Suppose I have pipe whose inlet temperature is 298K with a specified uniform mass flow(m_flow), now suppose i am heating the pipe using a heater of 100 watts.
The outlet temperature will be attain a higher temperature of suppose 302K, now if i have to use this outlet temperature as my inlet temperature (in the sense i am recircuilating the water), how would i be doing it?
is it possible to update the value of the inlet temperature based on the outlet temperature at the previous timestep? so that for the next iteration the inlet temperature will be the same as the oulet temperature in the previous iteration (in other words the fluid would be recirculating).
Thanks
You cannot access the value in the previous time step. The closest you can get in Modelica is using delay(exp,T) to get the value T units of time ago.
The timestep does not enter into it at all. A model that uses information about timestep is just wrong. Nature doesn't know or care about integration time steps, the model should reflect that.
It seems to me what you want to capture is transport delay. Transport delay is the delay introduced by the time it takes for molecules, electrons, etc. through the system. So presumably what you wish to model is the time it takes the inlet fluid to reach the exit. Again, this has nothing to do with the integration timestep but rather the velocity of the fluid and the distance it must travel. Once you know how long that takes (by either a priori knowledge of the system of by looking at the simulation results themselves), you can follow Marco's suggestion of using the delay operator.
In order to setup a proper model for the system you described I suggest you to look at the example :
Modelica.Thermal.FluidHeatFlow.Examples.IndirectCooling
of the modelica standard library ver. 3.2. Instead of one pipe you can put an ambient or control volume component to better suit you needs. Moreover using continous and differentiable equations (the delay function is not) you will benefit from some of the advantages of the Modelica code, e.g. you will be able to reuse your models in a much wider range of cases, solve inverse problems, solve initial value problems, ...
I hope this helps,
Marco

Matlab: How to fit a state space model to data with nlinfit

I've run an experiment and would like to fit a state space model to the data. Unfortunately I have little experience with how to implement this, so was hoping to ask for some help.
In the experiment participants reach towards different targets. The participant receives feedback about their movement via an on screen cursor. This cursor displays their reaching movement, but is rotated by 30 degrees. This means participants initially make large errors, but reduce them with repeated practice.
The following data provides some illustrative results. Each value represents an 'epoch' (average of eight trials):
18.26
13.95
10.92
10.32
8.23
6.57
7.05
5.98
5.99
4.58
4.35
3.72
3.71
3.04
4.47
4.16
I have found a paper that has used a similar experiment and has fit a state space model to their data. The model is composed of two equations:
1) e(n) = p(n) - s(n) + E(n) 2) s(N+1) = s(n) + Ae(n)
Where e(n) = error on trial n (i.e. values above)
p(n) = perturbation applied to movement (i.e. 30 degrees)
s(n) = internal state of system
E(n) = noise
A = rate of adaptation to perturbation
The paper indicates that they used the nlinfit matlab function to implement this model, but I don't understand how I would do this. Any help would be greatly appreciated!
I've just seen your post now, ages later, but I've come accross it while looking for a problem of my own.
From experience, I know that if you have a system that you want to obtain a State Space model for, and you have measured inputs and corresponding measured outputs from your system, you can use the 'pem' function that will build you a state space model based on your measurements.
The 'pem' function is part of the system identification toolbox.