Borrar filtros
Borrar filtros

Problem in my script to generate random spheres with Comsol matlab

13 visualizaciones (últimos 30 días)
sadedbouta
sadedbouta el 22 de Abr. de 2020
Comentada: Pattawee Chutimasakul el 23 de Oct. de 2021
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 comentarios
Pattawee Chutimasakul
Pattawee Chutimasakul el 23 de Oct. de 2021
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...

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Mathematics and Optimization en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by