Failed to expand block containing connect - modelica

I´m trying to set a connection with a conditional on the temperature, to represent a temperature-sensible charging pipe that works inside a stratified heat storage tank, with the following for loop reading the several volumes of the tank,
`for i in 2:nSeg loop
if (sensor_T_inflow.T > vol[i].T) and (sensor_T_inflow.T < vol[i-1].T) then
connect(feedPort, vol[i].ports[3])
annotation (Line(points={{-50,-60},{6,-60},{6,
-16},{16,-16}}, color={0,127,255}));
end if;
end for;`
However I get the errors such as this one for the volume 2:
Failed to expand block containing connect:
if (sensor_T_inflow.T > vol[2].T and sensor_T_inflow.T < vol[1].T) then connect(feedPort, vol[2].ports[3]); end if;
The model contained invalid connect statements.
Check aborted.
This might have a silly solution but I checked the names of all my elements and their temperature properties and they match with this code snippet, and I confirmed the error comes specially from the if conditional. Here is my model If you could take a look at it.
I tried commenting out the conditional and the check was succesful, only that I have a misbalance of about 40 variables to equations. If you got any advice on how to solve those misbalances I´d be much grateful as well.
Thanks a lot in advance.

The connect-statements may not depend on time-varying variables.
(The technical statement is first in the list in https://specification.modelica.org/master/connectors-and-connections.html#restrictions-of-connections-and-connectors )
A solution would be to turn that into an array of valve-components, and have them controlled in a similar way.

Related

Cimplicity Screen - one object/button that is dependent on hundreds of points

So I have created a huge screen that essentially just shows the robot status for every robot in this factory (individually)… At the very end of the project, they decided they want one object on the screen that blinks if any of the 300 robots fault. I am trying to think of a way to make this work. Maybe a global script of some kind? Problem is, I do not do much scripting in Cimplicity, so any help is appreciated.
All the points that are currently used on this screen (to indicate a fault) have very similar names… as in, the beginning is the same… so I was thinking of a script that could maybe recognize if a bit is high based on PART of it's string name characteristic. The end will change a little each time, but I am sure there is a way to only look for part of a string and negate the rest. If the end has to be hard coded, that's fine.
You can use a Python script in Cimplicity.
I will not go into detail on the use of python in Cimplicity, which is well described in the documentation indicated above.
Here's an example of what can be done... note that I don't have a way to test it and, of course, this will work if the name of your robots in the declaration follows the format Robot_1, Robot_2, Robot_3 ... Robot_10 ... Robot_300 and it also depends on the Name and the Type of the fault variable... as you didn't define it, I imagine it can be an integer, with ZERO indicating no error. But if you use something other than that, you can easily change it.
import cimplicity
(...)
OneRobotWithFault = False
# Here you get the values and check for fault
for i in range(0, 300):
pointName = f'MyFactory.Robot_{i}.FaultCode'
robotFaultCode = cimplicity.point_get(pointName)
if robotFaultCode > 0:
OneRobotWithFault = True
break
# Set the status to the variable "WeHaveRobotWithFault"
cimplicity.point_set("WeHaveRobotWithFault", OneRobotWithFault)

Error about C_outflow[] when using FluidPort

i'm noob for modelica and developing the Heat Exchanger model.
I did input
air_in.X_outflow[1]=1;
air_out.X_outflowp[1]=1;
coolant_in.X_outflow[1]=1;
coolant_out.X_outflow[1]=1;
but I encountered some errors like captures below.
First, I don't know what is the physical meaning of C_outflow. I could find that C_outflow = c_i/m
and m is the mass of the fluid, but couldn't find the meaning of c_i.
Second, I've just tried to input the value 0~1 as the description said, but encountered the error message above. I think the value has not been input to the C_outflow array but I'm not sure.
Please reply to anyone who can figure out these problems... Thank you to all of you.
model Staggered_HX
A complete model would be helpful - but attempting to answer anyway:
The C-array is an array of trace substances, and there are normally no trace substances; whereas the X-array is the array of normal substances - which must contain some elements.
For the C-array it would thus be: air_in.C_outflow=zeros(0); (where zeros(0) creates an empty vector - corresponding to no trace substabces), but I don't see how that relates to the equations above with air_in.X_outflow[1]=1;

Retrieve Bloomberg Historical Data - API

From the below code, I was attempting to retrieve 250 observations rather than 177. The gap is due to the fact that the call only considers trading days which is fine to me.
s='SX5E INDEX';
f='LAST_PRICE'
t= datestr(today()-250,'mm/dd/yy');
T= datestr(today(),'mm/dd/yy');
[dt,~]=history(con,s,f,t,T)
However, is there a way of retrieving the last 250 observations from today(), whatever the starting date t is ?
Best
EDIT
#Daniel : Based on your suggestion, and Going forward with while loop, I've ended up with the below way around which is free from any Matlab default calendar setting. Thanks
while l~=p
n=p-l;
t=t-n;
[dt,~]=history(con,s,f,t,T);
l=length(dt);
end
Maybe my idea to use isbusday wasn't well explained in the comments. Here is what I would try:
n=250;
m=n;
while(sum(isbusday(today()-n:today()))<m)
missing=m-sum(isbusday(today()-n:today()));
n=n+missing;
end
Count the number of missing days, add the missing days and check again (in case you added a holiday)
You should end up with n the total number of days you have to query.
(Lacking the toolbox, I was unable to test the code)

Create ordinal array with multiple groups

I need to categorize a dataset according to different age groups. The categorization depends on whether the Sex is Male or Female. I first subset the data by gender and then use the ordinal function (dataset is from a Matlab example). The following code crashes on the last line when I try to vertically concatenate the subsets:
load hospital;
subset_m=hospital(hospital.Sex=='Male',:);
subset_f=hospital(hospital.Sex=='Female',:);
edges_f=[0 20 max(subset_f.Age)];
edges_m=[0 30 max(subset_m.Age)];
labels_m = {'0-19','20+'};
labels_f = {'0-29','30+'};
subset_m.AgeGroup= ordinal(subset_m.Age,labels_m,[],edges_m);
subset_f.AgeGroup = ordinal(subset_f.Age,labels_f,[],edges_f);
vertcat(subset_m,subset_f);
Error using dataset/vertcat (line 76)
Could not concatenate the dataset variable 'AgeGroup' using VERTCAT.
Caused by:
Error using ordinal/vertcat (line 36)
Ordinal levels and their ordering must be identical.
Edit
It seems that a vital part was missing in the question, here is the answer to the corrected question. You need to use join rather than vertcat, for example:
joinFull = join(subset_f,subset_m,'LeftKeys','LastName','RightKeys','LastName','type','rightouter','mergekeys',true)
Solution of original problem
It seems like you are actually trying to work with the wrong variable. If I change all instances of hospitalCopy into hospital then everything works fine for me.
Perhaps you copied hospital and edited it, thus losing the validity of the input.
If you really need to have hospitalCopy make sure to assign to it directly after load hospital.
If this does not help, try using clear all before running the code and make sure there is no file called 'hospital' in your current directory.

Debugging a for loop in matlab

I've been looking throught the documentation, but can't seem to find the bit I want.
I have a for loop and I would like to be able to view every value in the for loop.
for example here is a part of my code:
for d = 1 : nb
%for loop performs blade by blade averaging and produces a column vector
for cc = navg : length(atbmat);
atb2 = (sum(atbmat((cc-(navg-1):cc),d)))/navg;
atbvec2(:,cc) = atb2;
end
%assigns column vector 'atbvec2' to the correct column of the matrix 'atbmat2'
atbmat2(d,1:length(atbvec2)) = atbvec2;
end
I would like to view every value of atb2. I'm a python user(new to MATLAB) and would normally use a simple print statement to find this.
I'm sure there is a way to do it, but I can't quite find how.
Thankyou in advance.
you can use disp in Matlab to print to the screen but you might want to use sprintf first to format it nicely. However for debugging you're better off using a break point and then inspect the variable in the workspace browser graphically. To me, this is one of Matlab's best features.
Have a look at the "Examine Values" section of this article
The simplest way to view it everywhere is to change this line:
atb2 = (sum(atbmat((cc-(navg-1):cc),d)))/navg;
Into this, without semicolon:
atb2 = (sum(atbmat((cc-(navg-1):cc),d)))/navg
That being said, given the nature of your calculation, you could get the information you need as well by simply storing every value of abt2 and observing them afterwards. This may be done in atbmat2 already?
If you want to look at each value at the time it happens, consider setting a breakpoint or conditional breakpoint after the line where abt2 is assigned.