问题描述
我尝试通过多个滚筒系统模拟墨水流动未成功.随着每个辊的转动,墨水将根据给定的比例(例如0.5)进行分配.我已经设法通过获取一些用户数据来绘制系统中的滚筒,但现在我完全陷入了如何进行的过程中!这些辊中的一些将与一个以上的辊接触,因此,墨水将被平均分配,然后在到达生产线中的下一个辊时再次减半.
I'm trying unsuccessfully to simulate a flow of ink through a system of many rollers. As each roller turns the ink is split depending on a given ratio (say 0.5).I have managed to get the rollers in the system plotted by taking some user data but i'm now completely stuck on how to proceed! Some of these rollers will be in contact with more than one roller and as such the ink will be split equally and then halved again as it reaches the next roller in the line.
有人能建议一个函数来声明这些连接位置并跟踪一定次数的系统旋转后墨水分裂吗?...虽然我似乎无法翻译此文章,但我已经在python中使用字典对其进行了尝试对matlab特别好.
can anyone suggest a function for declaring these connecting positions and keeping track of the ink split after a certain number of system revolutions?...I've tried this in python using the dictionaries although I can't seem to translate this to matlab particularly well.
到目前为止,我使用的是Python:
What I have thus far is in Python:
for i in range(num_rollers):
roller_data()
for i in range(0,num_rollers):
for j in range(Rollers[i]['segments']):
Rollers[i]['ink'].append(0)
# Initialise nips
Nips = [{} for i in range(num_nips)]
Nips[0] = {'rollers': [0, 1], 'locations': []}
Nips[1] = {'rollers': [1, 2], 'locations': []}
Nips[2] = {'rollers': [2, 3], 'locations': []}
推荐答案
由于您未指定辊子的确切模型,因此我将在极坐标中将它们表示为 ie 点和半径.每个滚筒上的墨水将由一个附加值表示,例如:
Since you didn't specify the exact model of your rollers, I'll represent them in polar coordinations, i.e. with a center point and a radius. The ink on each roller will be represented by an additional value, for example:
% # Initial state
C = [0, 0; -0.8, -0.6; 1, 0]; % # Roller centers (x, y)
R = [0.5, 0.5, 0.5]; % # Roller radii (r)
ink = [1, 0, 0]; % # Amount of ink on each roller
N = numel(R); % # Amount of rollers
这里仅在#1滚筒上有墨水(我随意选择了这些值,因此可以更改它们).为了方便起见,您可以像这样绘制滚筒:
Here there's ink only on roller #1 (I chose these values arbitrarily, so they can be changed, of course). For your convenience, you can draw the rollers like so:
% # Draw the rollers
figure, hold on
ang = 0:0.1:(2 * pi);
for i = 1:N
plot(C(i, 2) + R(i) * cos(ang), C(i, 1) + R(i) * sin(ang))
text(C(i, 2), C(i, 1), num2str(i))
end
title('Ink rollers'), axis image
这应该产生以下图像:
我将由您自己来在每个滚筒上绘制墨水:P
I'll leave it up to you to draw the ink on each roller :P
现在开始营业:
1)首先,我们找到所有连接的滚筒:
1) First we find all connected rollers:
% # Find connected rollers
isconn = @(m, n)(sum(([1, -1] * C([m, n], :)) .^ 2) - sum(R([m, n])) .^ 2 < eps);
[Y, X] = meshgrid(1:N, 1:N);
conn = reshape(arrayfun(isconn, X(:), Y(:)), N, N) - eye(N);
如果辊 i 和辊,则生成一个矩阵,其中位置( i , j )中的每个元素为1 j 已连接,否则为0.在此示例中,我们得到:
This produces a matrix in which each element in the position (i, j) is 1 if roller i and roller j are connected, and 0 if not. In this example, we get:
conn =
0 1 1
1 0 0
1 0 0
2)下一步是通过运行预定的迭代次数来模拟墨水流.在每次迭代中,我们模拟每个滚筒旋转一圈,即,我们越过每个滚筒并将墨水均匀地分配在其各个滚筒与相邻滚筒之间.
2) The next step is to simulate the ink flow by running a predetermined amount of iterations. In each iteration we simulate one revolution of each roller, i.e. we go over each roller and split the ink equally between itself and its neighbors.
% # Simulate ink flow for a number of revolutions
disp([sprintf('Initial state:\t\t'), '[', num2str(ink), ']'])
revolutions = 3;
for ii = 1:revolutions
new_ink = zeros(size(ink));
% # Iterate over each roller
for jj = 1:N
if (ink(jj) > 0)
delta_ink = ink(jj) / (sum(conn(jj, :)) + 1);
idx = [jj, find(conn(jj, :))]; % # roller jj and its neighbors
new_ink(idx) = new_ink(idx) + delta_ink;
end
end
ink = new_ink;
disp([sprintf('Revolution #%d:\t\t', ii), '[', num2str(ink), ']'])
end
很抱歉,我没有花太多精力通过矢量化来优化这些循环.无论如何,这些是每转中每个滚筒上的墨水量:
I apologize that I haven't put much effort into optimizing these loops by vectorization. Anyway, these are the amounts of ink on each roller in each revolution:
很显然,您可以轻松地将此代码放入返回辊的最后状态或您选择的任何其他输出的函数中.此外,您还可以修改算法,以根据辊子的半径处理不同的分光比.祝你好运!
Obviously, you can easily put this code into a function that returns the last state of the rollers, or any other output of your choice. Moreover, you can also revise the algorithm to handle different splitting ratios depending on the radii of the rollers. Good luck!
这篇关于将流体从一个气缸转移到另一个气缸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!