How to generate code in MATLAB for randomly oriented short fibers?

I need to generate an input file in MATLAB and run in ABAQUS.
wrote some input accordingly as follows:
%% Monte Carlo style script for random placement of fibres
%% Block 1: Define RVE Space
RVE_Length = 100; %Length
RVE_Width = 100; %Width
D = 15; %Fibre Diameter
VolFract = 30; %Percentage volume fraction
%Define RVE
figure('Name','RVE with random fibres','NumberTitle','off')
rveBox = axes('Box','on');
xlim([0 RVE_Length]);
ylim([0 RVE_Width]);
xlabel('RVE Length, L (\mum)')
ylabel('RVE Width, W (\mum)')
title('Random positioned fibres RVE')
%% Block 2: Determine total number of fibres, N_total
Ntotal = round( (0.01*VolFract*RVE_Length*RVE_Width)/(pi*D^2) );
disp(['Total Number of Fibre, Ntotal = ',num2str(Ntotal)]);
%% Block 3: Generate random position of first fibre
XYALL(:,:) = zeros; % A hold-all variable for all fibre coordinates
XYALL(1,1) = rand*RVE_Length; %Random x-position for 1st fibre
XYALL(1,2) = rand*RVE_Width; %Random y-position for 1st fibre
Dmin=0.1; R=D/2; Ncurrent = 0.1;
%% Block 4: Check overlap criteria
phi = 20; %Percentage of R parameter
for Ni = 2:Ntotal
while Dmin < 2*R*(1+phi)
%Create a test position [xtest, ytest] to see if it overlaps
xtest = rand*RVE_Length; %Random x-position for next fibre
ytest = rand*RVE_Width; %Random y-position for next fibre
for i = 1:Ncurrent
% Include codes here to test for overlap
% for all current fibre existing in RVE
end
end
% Accept into XYALL the tested coordinate position
% when they pass the overlap test
XYALL(Ni,1) = xtest;
XYALL(Ni,2) = ytest;
end
%% Block 6: Implementation of periodicity of material
b = cell(1);
for m = 1:length(xEdgeFibres) %For xEdge Fibres Only
if XYALL(xEdgeFibre(m),1)<R
b(m) = [XYALL(xEdgeFibres(m),1)+RVE_Length XYALL(xEdgeFibres(m),2) ];
else
b(m) = [XYALL(xEdgeFibres(m),1)-RVE_Width XYALL(xEdgeFibres(m),2) ];
end
end
%Repeat similar coding for yEdgeFibres and cornerFibres
Unfortunately code is not able to run as desired. Kindly help with above code how to generate input files and run into MATLAB and ABAQUS.

2 Comments

Why do you think code is unable to run? What problem you are facing? You need to specify your error exactly.
I am not able to generate short fibre on plot, Kindly help.

Sign in to comment.

 Accepted Answer

while Dmin < 2*R*(1+phi)
%Create a test position [xtest, ytest] to see if it overlaps
xtest = rand*RVE_Length; %Random x-position for next fibre
ytest = rand*RVE_Width; %Random y-position for next fibre
for i = 1:Ncurrent
% Include codes here to test for overlap
% for all current fibre existing in RVE
end
end
Your while tests a relationship between Dmin and R and phi . The while loop body might not be entered at all (depending on the initial values), but if it is entered, then the while loop will continue until the condition stops holding or until there is a break statement encountered. In order for the condition to stop holding, at least one of the variables involved in the relationship being tested, must change inside the loop. If all of the variables involved in the relationship are constants inside the loop body and there is no break then the value of the relationship cannot change, so if the loop body were ever entered then it could not possibly be exited.

12 Comments

b(m) = [XYALL(xEdgeFibres(m),1)+RVE_Length XYALL(xEdgeFibres(m),2) ];
b is a cell. When you use () indexing, then the right hand side has to be a cell array itself. But the entries inside the [] are clearly numeric values, so the [] is computing a numeric vector. You cannot store a numeric vector as a cell. You can store a numeric vector inside a cell -- which would require using {} indexing instead of () indexing.
b{m} = [XYALL(xEdgeFibres(m),1)+RVE_Length XYALL(xEdgeFibres(m),2) ];
Could you please show me this code, because i changed the code as suggested by you but not able to run the code, i am not gettign any result out it. kindly help!
Could you please send me the code for generating randomly oriented short fibre?
I am not able to get the plot. Kindly help with thw code.
I need to see your updated code. Please posted it as formatted code, not as an image of your screenshot. I cannot run images of code, and your screen shot does not include key parts of the code.
Sorry for inconveniences, Kindly look into it:
function Fiber=Generate_Fiber(x,y,z,L,N)
%input
%x=[x1 x2]: x boundaries of the box
%y=[y1 y2]: y boundaries of the box
%z=[z1 z2]: z boundaries of the box
%L: Length of fibers
%N: Number of fibers
%output
%Fiber: (N,6) matrix of fiber coordinates with (:,1), (:,2) and (:,3) are x,y, and z coordinates of one end
%and (:,4),(:,5) and (:,6) are x,y, and z coordinates of the other end.
for i=1:1:N
while 1
x1=min(x)+(max(x)-min(x))*rand(1);
y1=min(y)+(max(y)-min(y))*rand(1);
z1=min(z)+(max(z)-min(z))*rand(1);
theta=2*pi*rand(1);
v=2*rand(1)-1;
x2=x1+L*sqrt(1-v^2)*cos(theta);
y2=y1+L*sqrt(1-v^2)*sin(theta);
z2=z1+L*v;
if x2<=x(2) && x2>=x(1) && y2<=y(2) && y2>=y(1) && z2<=z(2) && z2>=z(1)
break;
end
end
Fiber(i,1)=x1;
Fiber(i,2)=y1;
Fiber(i,3)=z1;
Fiber(i,4)=x2;
Fiber(i,5)=y2;
Fiber(i,6)=z2;
end
Well that is a start, but we also need RandomFibrePositioningScript
yes sir, so kindly help with it how to for random fiber positoning script, i am basically working on biocomposite, so that i need to generate random fiber positioning of the short friber for beam elements.
I am sending the L.T. HARPER's research paper doi:
You had a script with the 6 "blocks" but no plotting code. That script calculated random fibres itself.
You know have a function Generate_Fiber that generates random fibres (but does not check overlaps), and we can see from the error messages you posted that probably you are calling that function from inside your script. But we cannot tell for sure.
We need your updated RandomFibrePositioningScript -- one that calls GenerateFibre, and that attempts to plot the result (so that we can see what problem you are encountering in the plotting.)
Could please help me for above code, i am getting confused, can you try by some modification, if possible else i will update you the same from my end.
https://www.mathworks.com/matlabcentral/answers/405186-fill-area-with-random-circles-having-different-diameters#comment_1236758 has code for filling space with ellipsoids. Fibres can be modeled as ellipsoids with a long major axes and short minor axes.

Sign in to comment.

More Answers (1)

See if this FEX can help you

8 Comments

Not thick fibers, i need to genarate for thin fiber
yes sir, so kindly help with it how to for random fiber positoning script, i am basically working on biocomposite, so that i need to generate random fiber positioning of the short friber for beam elements.
I am sending the L.T. HARPER's research paper doi:
If you expect us to read the paper and fill in your structural but empty code, that won't happen. Please make an effort and ask specific question if you encount implementation issues.
%% Monte Carlo style script for random placement of fibres
%% Block 1: Define RVE Space
RVE_Length = 100; %Length
RVE_Width = 100; %Width
D = 15; %Fibre Diameter
VolFract = 30; %Percentage volume fraction
%Define RVE
figure('Name','RVE with random fibres','NumberTitle','off')
rveBox = axes('Box','on');
xlim([0 RVE_Length]);
ylim([0 RVE_Width]);
xlabel('RVE Length, L (\mum)')
ylabel('RVE Width, W (\mum)')
title('Random positioned fibres RVE')
%% Block 2: Determine total number of fibres, N_total
Ntotal = round( (0.01*VolFract*RVE_Length*RVE_Width)/(pi*D^2) );
disp(['Total Number of Fibre, Ntotal = ',num2str(Ntotal)]);
%% Block 3: Generate random position of first fibre
XYALL(:,:) = zeros; % A hold-all variable for all fibre coordinates
XYALL(1,1) = rand*RVE_Length; %Random x-position for 1st fibre
XYALL(1,2) = rand*RVE_Width; %Random y-position for 1st fibre
Dmin=0.1; R=D/2; Ncurrent = 0.1;
%% Block 4: Check overlap criteria
phi = 20; %Percentage of R parameter
for Ni = 2:Ntotal
while Dmin < 2*R*(1+phi)
%Create a test position [xtest, ytest] to see if it overlaps
xtest = rand*RVE_Length; %Random x-position for next fibre
ytest = rand*RVE_Width; %Random y-position for next fibre
for i = 1:Ncurrent
% Include codes here to test for overlap
% for all current fibre existing in RVE
end
end
% Accept into XYALL the tested coordinate position
% when they pass the overlap test
XYALL(Ni,1) = xtest;
XYALL(Ni,2) = ytest;
end
%% Block 6: Implementation of periodicity of material
b = cell(1);
for m = 1:length(xEdgeFibres) %For xEdge Fibres Only
if XYALL(xEdgeFibre(m),1)<R
b(m) = [XYALL(xEdgeFibres(m),1)+RVE_Length XYALL(xEdgeFibres(m),2) ];
else
b(m) = [XYALL(xEdgeFibres(m),1)-RVE_Width XYALL(xEdgeFibres(m),2) ];
end
end
%Repeat similar coding for yEdgeFibres and cornerFibres
Kindly look into the code, i am not getting result out of it for random positioning of fiber.
while Dmin < 2*R*(1+phi)
Where inside your loop do you modify at least one of Dmin or phi or R ? Unless you modify at least one of those, you will have an infinite loop.
"Kindly look into the code, i am not getting result out of it for random positioning of fiber."
Sight...
I didnt get you how to modify it can you help me with some examples
Can you suggest me some exmple for random fibre positioning?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!