I am calculating the needed mass flow from a source to heat up water from 10°C to 35°C from the heat demand at any given moment.
Introducing this model to my simulation increased the simulation time a lot!
model m_flow_calc
"A simple model to calculated the primary mass flow needed to heat up space heating water "
import SI = Modelica.SIunits;
parameter SI.Temperature T_SHW_out = 30+273.15 "Temperature of the space heating water supply temperature";
parameter SI.Temperature T_SHW_in = 10+273.15 "Temperature of the space heating water return temperature";
Modelica.Blocks.Interfaces.RealInput Q_demand;
equation
m_flow =-Q_demand/(4120*(T_SHW_out-T_SHW_in)); //"Calculating the primary mass flow for a given Heating demand to heat the space heating water to the set temperature"
end m_flow_calc;
With the calculated mass flow a boundary draws the mass flow through a heat exchanger. The Temperature after the HEX is then carried over to another boundary that "pushes" out the same mass flow like in the first boundary.
Is there something i am missing that is slowing down the simulation?
Related
I’m developing a model to describe the behavior of a two-pipe network. The network is connected to a tank where heat is injected or extracted from the system depending on external mass flow rates. The mass flow rates for both heating and cooling are arbitrarily assumed to vary over time.
The initial value of PipeTemp is associated with the parameter StartTemp. However, at different time points PipeTemp is computed from a max function.
The problem is that because the variable PipeTemp depends on other time varying variables that are computed using the value of PipeTemp, Dymola terminates the simulation and produces the following error: Failed to solve nonlinear system using Newton solver.
This simple model can be easily simulated in Excel because it’s capable of handling interdependency between cell variables. What could be the workaround for this model in Dymola in order to avoid the nonlinear system of equations?
model FullyMixedTemperature
parameter Real StartTemp = 20; //Assumed mixed temperature in the pipes
parameter Real dTpipe = 10; //Temperature difference between the two pipes
parameter Real TankVol = 150; //Total volume
Real DecreasingTemp; //Mixed temperature in the pipe due to additional cooling mass flow rate
Real IncreasingTemp; //Mixed temperature in the pipe due to additional heating mass flow rate
Real PipeTemp(start=StartTemp); //Mixed temperature in the pipe
Real CoolFlowRate; //Additional cooling flow rate from external sources
Real HeatFlowRate; //Additional heating flow rate from external sources
equation
CoolFlowRate=0.5*time;
HeatFlowRate=2*time;
PipeTemp = max(DecreasingTemp, IncreasingTemp);
DecreasingTemp= PipeTemp-(dTpipe*CoolFlowRate/TankVol);
IncreasingTemp= PipeTemp+(dTpipe*HeatFlowRate/TankVol);
end FullyMixedTemperature;
The model as written doesn't make sense.
Since dTPipe, HeatFlowRate, CoolFlowRate and TankVol are all non-negative IncreasingTemp is greater than DecreasingTemp, and thus the equation collapses to:
PipeTemp=PipeTemp+dTPipe*HeatFlowRate/TankVol;
and you cannot compute PipeTemp from that.
The closest variant would be that in each sampling point we compute a new PipeTemp, and that would be:
model FullyMixedTemperature
parameter Real StartTemp = 20; //Assumed mixed temperature in the pipes
parameter Real dTpipe = 10; //Temperature difference between the two pipes
parameter Real TankVol = 150; //Total volume
Real DecreasingTemp; //Mixed temperature in the pipe due to additional cooling mass flow rate
Real IncreasingTemp; //Mixed temperature in the pipe due to additional heating mass flow rate
Real PipeTemp(start=StartTemp); //Mixed temperature in the pipe
Real CoolFlowRate; //Additional cooling flow rate from external sources
Real HeatFlowRate; //Additional heating flow rate from external sources
equation
CoolFlowRate=0.5*time;
HeatFlowRate=2*time;
when sample(1,1) then
PipeTemp = max(pre(DecreasingTemp), pre(IncreasingTemp));
end when;
DecreasingTemp= PipeTemp-(dTpipe*CoolFlowRate/TankVol);
IncreasingTemp= PipeTemp+(dTpipe*HeatFlowRate/TankVol);
end FullyMixedTemperature;
But to me it seems more likely you want a differential equation where both flows contribute:
model FullyMixedTemperature
parameter Real StartTemp = 20; //Assumed mixed temperature in the pipes
parameter Real dTpipe = 10; //Temperature difference between the two pipes
parameter Real TankVol = 150; //Total volume
Real PipeTemp(start=StartTemp); //Mixed temperature in the pipe
Real CoolFlowRate; //Additional cooling flow rate from external sources
Real HeatFlowRate; //Additional heating flow rate from external sources
equation
CoolFlowRate=0.5*time;
HeatFlowRate=2*time;
der(PipeTemp) =(dTpipe*HeatFlowRate/TankVol)-(dTpipe*CoolFlowRate/TankVol);
end FullyMixedTemperature;
I am working on steering wheel angle sensor that measures absolute angle of steering wheel. As steering angle sensors uses gears and several joints which is totally hardware related so in spite of calibration in start with the passage of time due to usage of mechanical parts and also due to some environmental and road conditions some errors occurs in the values of sensors (e.g. offset, phase change, flattening of signal, delay).
In short due to these errors in the measurements our aim gets distracted means If I am viewing velocity vs time curve so if in the original or calibrated sensor in short close to ideal condition sensor my velocity shows a peak in amplitude but due to error (hysteresis) in measured signal I am not getting peak in velocity curve or I am getting flattening of curve so it will affect my final task.
I have a tolerance let say 1.20 degree for hysteresis so that’s why I am having detailed idea about my signal and want to observe my signal if some changes means offset, delay, lowering has occurred in my signal or not. This will not only provide me an idea that whether to lessen the amount of sensors used for my task or made some changes in hardware of sensor to lessen the amount of hysteresis or do some other actions to reduce it.
What I have done uptill now in which uptill now I am not sure that whether I am right or wrong. I am getting some values for hysteresis but I have few questions regarding one of the technique I am using. If someone provides me an idea about it how to improve this technique or provide me a better approach then it will be nice and great guidance.
I have an ideal sensor signal (under ideal conditions which we want) and values from 1 sensor I have data of 6 different drives from car. I am explaining just 1 example of my first drive and its relation with my reference sensor data.
Given the data reference signal and sensor signal data of size 1x1626100 and 1 x 1626100 double for one reading from sensor but in all readings values from Ideal and measured signal w.r.t to time are same.
In short I want to find out the Hysteresis difference of sensor signal from measured signal.
In this method I have applied Regression lines Technique (On upper and lower values of difference signal).
I took difference of my signals (Ref – measured value of signal after applying my limitation on signal).
Applied regression technique by putting a threshold by myself above and below the difference signal means on upper values and on lower values separately and difference between upper and lower values regression lines is called as Hysteresis (Loss). Please have a look at figure 3 and 4 for clear view.
The Problem here with this technique is that I define the values for upper and lower regression line by myself after looking into data like up= 0.4, low= -0.4.
Question:
IS it possible that I could be able to write a program which decides the best line of fit by itself rather than giving a threshold?
Means is there any way that my code draw the best regression line for above values and best regression line for lower values and calculate Hysteresis.
I shall be really grateful to you all as I remained unable to find solution for this problem.
Thanks in anticipation.
clear all
clc
drv(6)=load('20170420__142024.mat');
t=drv(6).q_T0;
ref=drv(6).Pos;
lws_7=drv(6).SteeringWheelAngle;
swav=drv(6).SteeringWhellRotSpd;
vel=drv(6).KBI_angez_Geschw;
sig_diff=ref-lws_7;
mean_sig_diff = mean(sig_diff);
offset_removed_sig_diff = detrend(sig_diff ,'constant' );
offset_removed_mean_sig_diff = detrend(mean_sig_diff ,'constant');
figure(1)
ax11=subplot(321);
histfit(sig_diff)
dum=['Drive ' num2str(i) ': Differnce Signal With offset Removed for drive '];
title(dum)
hold on
plot([mean_sig_diff mean_sig_diff],[0 10000],'r')
hold off
ax12=subplot(322);
histfit(offset_removed_sig_diff)
dum=['Drive ' num2str(i) ': Differnce Signal With offset Removed'];
title(dum)
hold on
plot([offset_removed_mean_sig_diff offset_removed_mean_sig_diff],[0 10000],'r')
hold off
swvel_thres=20;
vehvel=60;
SAmax=90;
t_lim=t(((lws_7<SAmax)&(lws_7>-SAmax)&(swav<swvel_thres)&(vel>vehvel)));
sig_diff_lim = sig_diff((lws_7<SAmax)&(lws_7>-SAmax)& (swav<swvel_thres)&(vel>vehvel));
offset_rem_sig_diff_lim = detrend(sig_diff_lim,'constant');
mean_sig_diff_lim = mean(sig_diff_lim);
offsetmean_sig_diff_lim = detrend(mean_sig_diff_lim,'constant');
figure(2)
ax21=subplot(321);
histfit(sig_diff_lim)
dum=['Drive ' num2str(i) ': Limited Differnce Signal With offset Removed for drive '];
title(dum)
hold on
plot([ mean_sig_diff_lim mean_sig_diff_lim],[0 10000],'r')
hold off
ax22=subplot(322);
histfit(offset_rem_sig_diff_lim )
dum=['Drive ' num2str(i) ': Limited Differnce Signal With offset Removed'];
title(dum)
hold on
plot([offsetmean_sig_diff_lim offsetmean_sig_diff_lim],[0 10000],'r')
hold off
up=0.4;
low=-up;
stats_up = regstats(offset_rem_sig_diff_lim((offset_rem_sig_diff_lim>up)),t_lim((offset_rem_sig_diff_lim>up)), 'linear', {'beta'}); %calculate linear regression for upper values
intercept_up=stats_up.beta(1);
slope_up=stats_up.beta(2);
stats_low = regstats(offset_rem_sig_diff_lim((offset_rem_sig_diff_lim<low)),t_lim((offset_rem_sig_diff_lim<low)), 'linear', {'beta'}); %calculate linear regression for upper values
intercept_low=stats_low.beta(1);
slope_low=stats_low.beta(2);
Hysteresis_LinReg = abs(intercept_low)+abs(intercept_up);
figure(4)
% ax31=subplot(321);
plot(t_lim, offset_rem_sig_diff_lim ,t_lim, t_lim*slope_up+intercept_up, t_lim ,t_lim*slope_low+intercept_low);grid
legend('diff','reg up','reg low')
title(' Limited Differnce Signal With offset Removed with regression lines for drive ')
figure(5)
histfit(offset_rem_sig_diff_lim)
dum=['Drive ' num2str(i) ':Offset Removed Limited Difference Signal with Regression Lines for drive '];
title(dum)
hold on
plot([ intercept_up intercept_up],[0 12000],'r')
hold off
hold on
plot([intercept_low intercept_low],[0 12000],'r')
hold off
You can try a 1D version of the k-means algorithm. k-means divides the data set into k sets (called clusters) - in your case k = 3 (middle points, upper points, lower points) - in terms of how close they are to each other.
You can use the kmeans() function provided by Matlab. It is a 2D version AFAIK, but you can reduce the dimensionality of your problem by setting the first (i.e. time) coordinate of each point to 0, leaving only the "y" (i.e. signal) values.
After k-means is done just select the points, whose mean value is the lowest and the highest, which would give you upper and lower points. You can get the means of each cluster by using this version of the function (see the linked docs):
[idx,C] = kmeans(___)
Matrix C will contain the means, and idx shows which point belongs to which set (cluster).
Then just fit lines to your chosen sets of points.
I want to measure the low pulse length of a signal and then plot it to see if the pwm ratio changes during run time of that signal.
The signal it self was acquired using an oscilloscope and stored as a cvs file, channel 2 is a pulse signal where i want to evaluate in which boundaries the pulses are steady or not.
with d = dutycycle(CH2)
i could get the duty cycle from my signal
How can i plot the dutycycle or low pulse time as a graphical line or field to see its changes over time?
Both Files for Testing are here:
First
Second
Your signal is quite clean, so you could just use simple thresholding. If you needed to handle a little more noise, here's one way.
The basic approach is to decompose the signal piecewise (into a sequence of constant segments). Changepoint identification gives you the start and end time as well as magnitude of each segment.
Then, all the even times are rising edges and odd times are falling edges (or vice versa). The differences between these two vectors give high and low duration of each pulse, and differences between rising edges gives per-pulse duration.
rising = TIME(1+est.time(2:2:end));
falling = TIME(1+est.time(1:2:end));
hightime = falling(2:end) - rising(1:end-1);
lowtime = rising(2:end) - falling(2:end);
plot([lowtime hightime diff(rising)])
legend('Low Time', 'High Time', 'Pulse Duration')
Duty cycle is then hightime ./ diff(rising), and you can proceed with your jitter calculations.
For performing the segmentation, I used code from my thesis, but this simple case (piecewise constant) was already solved by Killick et. al (2012)
R. Killick, P. Fearnhead, and I. A. Eckley. Optimal detection of changepoints with a linear computational cost. Journal of the American Statistical Association, 107(500):1590–1598, Dec 2012. doi: 10.1080/01621459.2012.737745.
I am trying to implement Kalman filter for vehicle tracking in MATLAB. A Vehicle is moving in X direction with constant velocity. Initial state for vehicle =[x(t) v(t)].
I have to find position of vehicle after t=2 sec. Position of vehicle from GPS is corrupted by noise.
My question is: if I consider that there is no process noise, then will initial prediction matrix be equal to measurement noise matrix? I don't know how to initialise prediction matrix.
Any part of your state that is initialized from a measurement can have the corresponding variance initialized from the measurement variance. If your state has other variables (e.g. velocity) which aren't directly measured, then you'll have to put in educated guesses about how far wrong you could be. Variance has units of "state unit squared" (because variance is the square of standard deviation). So if your velocity estimate has a 68% chance (see: normal distribution) of being within +/-7mph, then the initial variance would be 49 miles^2/hour^2.
What is the fitness function used to solve an inverted pendulum ?
I am evolving neural networks with genetic algorithm. And I don't know how to evaluate each individual.
I tried minimize the angle of pendulum and maximize distance traveled at the end of evaluation time (10 s), but this won't work.
inputs for neural network are: cart velocity, cart position, pendulum angular velocity and pendulum angle at time (t). The output is the force applied at time (t+1)
thanks in advance.
I found this paper which lists their objective function as being:
Defined as:
where "Xmax = 1.0, thetaMax = pi/6, _X'max = 1.0, theta'Max =
3.0, N is the number of iteration steps, T = 0.02 * TS and Wk are selected positive weights." (Using specific values for angles, velocities, and positions from the paper, however, you will want to use your own values depending on the boundary conditions of your pendulum).
The paper also states "The first and second terms determine the accumulated sum of
normalised absolute deviations of X1 and X3 from zero and the third term when minimised, maximises the survival time."
That should be more than enough to get started with, but i HIGHLY recommend you read the whole paper. Its a great read and i found it quite educational.
You can make your own fitness function, but i think the idea of using a position, velocity, angle, and the rate of change of the angle the pendulum is a good idea for the fitness function. You can, however, choose to use those variables in very different ways than the way the author of the paper chose to model their function.
It wouldn't hurt to read up on harmonic oscillators either. They take the general form:
mx" + Bx' -kx = Acos(w*t)
(where B, or A may be 0 depending on whether or not the oscillator is damped/undamped or driven/undriven respectively).