Plot along line from. PDE solution

4 次查看(过去 30 天)
John McGrath
John McGrath 2025-4-4
编辑: Torsten 2025-4-11
The code below solves a 1-D, transient heat transfer problem set up as in general PDE format. The solution is plotted in color across the domain from 0 to 0.1 after 10 seconds have elapsed. What is the best way to plot the temperature across the length of this domain at this final time?
Thanks
clear all;
%% Create transient thermal model
thermalmodel = createpde(1);
R1= [3,4,0,0.1,0.1,0,0,0,1,1]';
gd= [R1];
sf= 'R1';
ns = char('R1');
ns = ns';
dl = decsg(gd,sf,ns);
%% Create & plot geometry
geometryFromEdges(thermalmodel,dl);
pdegplot(thermalmodel,"EdgeLabels","on","FaceLabels","on")
xlim([0 0.1])
ylim([-1 1])
% axis equal
%% Generate and plot mesh
generateMesh(thermalmodel)
ans =
FEMesh with properties: Nodes: [2x361 double] Elements: [6x152 double] MaxElementSize: 0.0402 MinElementSize: 0.0201 MeshGradation: 1.5000 GeometricOrder: 'quadratic'
figure
pdemesh(thermalmodel)
title("Mesh with Quadratic Triangular Elements")
%% Apply BCs
% Edge 4 is left edge; Edge 2 is right side
applyBoundaryCondition(thermalmodel, "dirichlet",Edge=[4],u=100);
applyBoundaryCondition(thermalmodel, "dirichlet",Edge=[2],u=20);
%% Apply thermal properties [copper]
rho= 8933 %
rho = 8933
cp= 385 %
cp = 385
rhocp= rho*cp %
rhocp = 3439205
k= 401 % W/mK
k = 401
%% Define uniform volumetric heat generation rate
Qgen= 0 % W/m3
Qgen = 0
%% Define coefficients for generic Governing Equation to be solved
m= 0
m = 0
a= 0
a = 0
d= rhocp
d = 3439205
c= [k]
c = 401
f= [Qgen]
f = 0
specifyCoefficients(thermalmodel, m=0, d=rhocp, c=k, a=0, f=f);
%% Apply initial condition
setInitialConditions(thermalmodel, 20);
%% Define time limits
tlist= 0: 1: 10;
thermalresults= solvepde(thermalmodel, tlist);
% Plot results
sol = thermalresults.NodalSolution;
subplot(2,2,1)
pdeplot(thermalmodel,"XYData",sol(:,11), ...
"Contour","on",...
"ColorMap","jet")
  13 个评论
John McGrath
John McGrath 2025-4-11
What is Octave?
thanks for your continued support

请先登录,再进行评论。

回答(1 个)

Karanjot
Karanjot 2025-4-8
Hi John,
In response to your latest comment, MATLAB returns the following error,as 'plotAlongLine' is not a standard function that is part of MATLAB. It's a custom function defined by another user.
Unrecognized function or variable 'plotAlongLine'.
In order to resolve the error, you may copy the function definition into your codebase, from the link attached below:
function plotAlongLine(p, u, xy1, xy2, numpts)
x = linspace(xy1(1),xy2(1),numpts);
y = linspace(xy1(2),xy2(2),numpts);
F = TriScatteredInterp(p(1,:)', p(2,:)', u);
uxy = F(x,y);
figure; plot(x, uxy);
end
As also suggested by Torsten, Feel free to go through the following beginner courses on MATLAB basics:
I hope this helps!
  1 个评论
John McGrath
John McGrath 2025-4-8
Hi Karanjot,
Thank you very much for your suggestions. I have completed some of these courses and will continue to work on them.
I tried to implement your suggestion for code- but unsuccessfully. Furthermore, when I searched for documentation regarding the TriScatteredInterp function, the MatLab documentation indicates that this function is not recommended and that the function scatteredInterpolant should be used instead. [The original code taht incldued this functoin dates abck to 2012 or something like that.
I initially defined my heat transfer model in terms of a thermal model. I ran into problems when I tried to implement time-varying convective boundary conditions. I was told that to avoid that issue, I should define my heat transfer problem as a general pde problem- which is what I am trying to do now.
I recognize that I do not understand the details of how my pde solution for the temperatures [1D or 2D] [steady or transient] are mapped onto the grid that is generated by the generateMesh function. I therefore don't have a clear picture of how to query the vectors or matrices that are being generated so as to produce values at defined locations or to produce desired plots.
Thanks again
john

请先登录,再进行评论。

标签

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by