根据comsol上的奶酪模型(即在三维空间内生成小孔模型),想进一步控制生成的小孔互不重叠,但是运行不出来,大神们能帮我看看错误吗。
代码是循环体部分的:
%奶酪中的小孔初始化参数
number_of_hols = 80; %初始化并定义奶酪内的小孔总数
ind = 0; %初始化并定义用于后续步骤的索引计数器
Pos = zeros(1,3);
%定义奶酪的高度、半径、环线粗细以及小孔的最大和最小半径
h_cheese = 10.0;
r_cheese = 25.0;
thickness = 0.2;
rmin_hole = 1.5;
rmax_hole = 1.4;
model.component('comp1').geom('geom1').lengthUnit('mm'); %将几何的长度单位设置为 mm
model.component('comp1').geom('geom1').selection().create('csel1', 'CumulativeSelection'); %创建一个新选择集,并添加标签 csel 和名CumulativeSelection。
Pos(1) = (2.0*rand-1.0)*r_cheese; %通过调用随机方法和缩放输出来定义小孔 坐标,使小孔位于奶酪模型的外部界限之内。
Pos(2) = (2.0*rand-1.0)*r_cheese;
Pos(3) = rand*h_cheese;
hr = rand*(rmax_hole-rmin_hole)+rmin_hole; %在规定的限值范围内定义小孔半径
A = Pos';
while (ind < number_of_hols) %初始化 while 循环,创建指定数量的孔
while ((any((A(1,:)-Pos(1)).^2+(A(2,:)-Pos(2)).^2+(A(3,:)-Pos(3)).^2 )< 4*hr*hr))
Pos(1) = (2.0*rand-1.0)*r_cheese; %通过调用随机方法和缩放输出来定义小孔 坐标,使小孔位于奶酪模型的外部界限之内。
Pos(2) = (2.0*rand-1.0)*r_cheese;
Pos(3) = rand*h_cheese;
end
if ((sqrt(Pos(1)^2+Pos(2)^2)+hr) > r_cheese-thickness)
continue;
end %检查小孔的位置和尺寸是否会使其脱离奶酪。
if (((Pos(3)-hr) < thickness) || ((Pos(3)+hr) > h_cheese-thickness))
continue;
end
sph = ['sph',num2str(ind)];
model.component('comp1').geom('geom1').create(sph, 'Sphere'); %创建一个球体,使其名称基于当前的索引值
model.component('comp1').geom('geom1').feature(sph).set('r', hr); %指定新创建球体的半径和位置。
model.component('comp1').geom('geom1').feature(sph).set('pos', Pos);
model.component('comp1').geom('geom1').feature(sph).set('contributeto', 'csel1'); %指定此球体特征属于名为 csel1 的选择集的一部分
A = [A,Pos(ind)'];
ind = ind + 1;
end