Need some clarity on parfor loop.
Show older comments
I am try to create a FEM code in matlab using parallel processing. The following is my code.
%% bar Problem
% E - Youngs Modulus; l - length of the bar; A - Cross sectional area
% k local stiffness matrix; and K - Global stiffness matrix
clear();
clc;
tic;
syms x
l = 300; % mm
E = 210*10^3; % Mpa
A = 100 ; % sqmm
p = 100 ; % N/mm
ne = 3;
nn = 4;
n_dof = 1;
ne_dof = 2;
nd = nn*n_dof;
le = l/ne;
N = [(le - x)/le , x/le];
Nx = diff(N,x);
k =double(int(E*A*Nx.'*Nx,x,0,le));
f = double(int(p*N.',x,0,le));
% initalize global stiffness matrixs and Force matrix to zero
% connectivity matrix
c = [1,2;2,3;3,4;4,5;5,6];
K = zeros(nd);
F = zeros(nd,1);
parfor e = 1:ne
for i =1:ne_dof
for j = 1:ne_dof
K(c(e,i),c(e,j)) = K(c(e,i),c(e,j)) + k(i,j);
end
F(c(e,i)) = F(c(e,i)) + f(i);
end
end
% apply boundary condtion
% when x = 0, u1 = 0
K1 = K(2:end,2:end);
F1 = F(2:end);
X = linsolve(K1,F1);
toc;
I am geting "valid indices for 'K' are restricted in parfor" error on the statement inside the inner most and the outer one. I have tried multiple way to rectify it, but not so successful.
Kindly guide me to sort this out.
Regards
kavi
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!