Problem in my script to generate random spheres with Comsol matlab

조회 수: 13 (최근 30일)
sadedbouta
sadedbouta 2020년 4월 22일
댓글: Pattawee Chutimasakul 2021년 10월 23일
Hey, I have a script qui marche avec Comsol-Matlab, when i run this script i get an error every time after the modification
Can you help me to correct this script matlab with Comsol:
The dots ... mean the special lines of the Comsol code
function out = packing_spheres
%
% packing_spheres.m
...
...
...
%%%%%% Algorith to generate random positions%%%%%%%%%%%%
blk_size = 1 % Length Of Block (cube)
...
n = 100;
Vsum = 0;
% Generate position vectors
Pos = zeros(n,3) ; % XYZ
R = zeros(n,3);
idx = 1; % index for sphere
flag = 0;
while (Vsum < Vsq * vf)
r = abs( normrnd(miu,sigma) );
% generates a random number from the normal distribution with mean parameter mu and
% standard deviation parameter sigma.
pos = [blk_size * rand(1,1) blk_size * rand(1,1) blk_size * rand(1,1)];
for k = 1:idx %Check the distance between the randomly generated sphere and all existing spheres.
Distance = sqrt((pos(1)-Pos(k,1))^2+(pos(2)-Pos(k,2))^2+(pos(3)-Pos(k,3))^2);
%rsum = r
rsum = r+R(k);
if Distance < 2*rsum
flag = 1;
break;
end
end
if flag == 1 % If the newly generated sphere overlaps an existing sphere, it enters the next loop cycle, abandoning the generated sphere this time.
flag = 0;
continue;
end
if (pos(1)-r < 0) || (pos(1)+r > blk_size)
continue;
end
if (pos(2)-r < 0) || (pos(2)+r > blk_size)
continue;
end
if (pos(3)-r < 0) || (pos(3)+r > blk_size)
continue;
end
V = Vsum + 3/4 * pi * r * r * r;
if V > vf * Vsq %Evaluation of the volume fraction condition
break;
end
sph = ['sph',num2str(idx)];% N° of sphere
model.component('comp1').geom('geom1').create(sph, 'Sphere'); %Create a sphere based on its current index value
model.component('comp1').geom('geom1').feature(sph).set('r', r); %Specify the radius and position of the newly created sphere.
Pos(idx,:) = pos;
R(idx) = r;
idx = idx +1;
Vsum = Vsum + 3/4 * pi * r * r * r;
end
....
....
  댓글 수: 10
Pattawee Chutimasakul
Pattawee Chutimasakul 2021년 10월 23일
At moment , I have problem to create RVE model with sphere in cube with not overlapping sphere. I do the code in comsol application, so can you send me the code via email wee34402@gmail.com Thank you...

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by