I'm trying to solve heat governing equation using finite element method but i'm having error that I can't figure it out.

1 回表示 (過去 30 日間)
Can anybody help me to figure out this,
Im trying to solve this equation
This is the error I am getting.
Index exceeds the number of array elements. Index must not exceed 9.
Error in decsg (line 172)
a=atan2(diff(gdc([3+gdc(2):2+2*gdc(2),3+gdc(2)])),...
Error in FEM_Temp (line 14)
g = decsg(gm,sf,ns);
This in my code:
FEM_Temp
Index exceeds the number of array elements. Index must not exceed 9.

Error in decsg (line 172)
a=atan2(diff(gdc([3+gdc(2):2+2*gdc(2),3+gdc(2)])),...

Error in solution>FEM_Temp (line 15)
g = decsg(gm,sf,ns);
function FEM_Temp
% variables
rho = 1234.2;
Cp = 2.195;
k = 0.054;
% Geometry & Mesh
model = createpde(3);
R1 = [3 4 -1 1 0 1 0 0 0]';
R2 = [3 4 0 1 0 1 0 0 0]';
gm = [R1 R2];
sf = 'R1+R2';
ns = (char('R1','R2'))';
g = decsg(gm,sf,ns);
geometryFromEdges(model,g);
hmax = 0.1; % Max element size
generateMesh(model,'Hmax',hmax);
% initial conditions
T0 = 100*ones(size(model.Mesh.Nodes,1), 1);
T0(abs(model.Mesh.Nodes(:,1)-0.5) < 0.1 & abs(model.Mesh.Nodes(:,2)-0.5) < 0.1 & abs(model.Mesh.Nodes(:,3)-0.5) < 0.1) = 200;
%boundary conditions
specifyCoefficients(model,'m',0,'d',1,'c',k/(rho*Cp),'a',0,'f',0);
applyBoundaryCondition(model,'face',[1,2],'h',@h_bc);
applyBoundaryCondition(model,'face',3,'q',-10);
specifyCoefficients(model,'Face',3,'h',0,'q',-10);
% Define boundary condition functions
function [pl,ql,pr,qr] = h_bc(~, ~, state)
pl = state.ux;
ql = 0;
pr = 0;
qr = 1;
end
% time-dependent set up
tlist = linspace(0,10,101);
result = solvepde(model,tlist,'InitialConditions',T0);
% Plot Temp vs Time
u = result.NodalSolution(:, end);
pdeplot3D(model.Mesh.Nodes,model.Mesh.Elements,'ColorMapData',u,'FaceAlpha',0.5);
colorbar;
xlabel('x');
ylabel('y');
zlabel('z');
title('Temperature Distribution');
end % Main function end

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 4 月 7 日
decsg documentation says
For a rectangle, the first row contains 3, and the second row contains 4. The next four rows contain the x-coordinates of the starting points of the edges, and the four rows after that contain the y-coordinates of the starting points of the edges.
That is a total of 10 rows but you are only passing 9 rows
  3 件のコメント
Walter Roberson
Walter Roberson 2023 年 4 月 7 日
No the problem is that you did pass 9 rows but those rows encode rectangles which require 10 rows to encode.
Stark Volt
Stark Volt 2023 年 4 月 8 日
Thanks I will try and modify to see if it will work thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGeometry and Mesh についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by