![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1758214/image.png)
How to display temperature at location x,y in command window for 2D heat transfer
38 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
John McGrath
le 22 Août 2024 à 20:27
Commenté : John McGrath
le 22 Août 2024 à 22:43
Below is code that produces the steady state temperature field in a square with consatnt temperature bounday conditions. I want to add code that would define the temperature at any location x,y of interest and display it in the command window. For example, what is the temperature at x= -10, y= 0?
thermalmodel = createpde("thermal","steadystate");
R2= [3,4,-15,15,15,-15,-15,-15,15,15]';
geom=[R2]
g=decsg(geom)
model= createpde
geometryFromEdges(thermalmodel,g);
pdegplot(thermalmodel,"EdgeLabels","on")
xlim([-20 20])
axis equal
thermalProperties(thermalmodel,"ThermalConductivity",1);
thermalBC(thermalmodel,"Edge",1,"Temperature",100);
thermalBC(thermalmodel,"Edge",2,"Temperature",100);
thermalBC(thermalmodel,"Edge",3,"Temperature",100);
thermalBC(thermalmodel,"Edge",4,"Temperature",400);
generateMesh(thermalmodel);
figure
pdemesh(thermalmodel)
title("Mesh with Quadratic Triangular Elements")
thermalresults = solve(thermalmodel)
title("Temperature In The Plate, Steady State Solution")
xlabel("X-coordinate, meters")
ylabel("Y-coordinate, meters")
axis equal
0 commentaires
Réponse acceptée
Sahas
le 22 Août 2024 à 20:55
As per my understanding, you would like to get the temperature at any point of interest in the steady state thermal model and display it in the command window.
This can be accomplished by using MATLAB's "interpolateTemperature" function. Below is a version of the code that meets the requirement.
%Previous code
thermalmodel = createpde("thermal","steadystate");
R2= [3,4,-15,15,15,-15,-15,-15,15,15]';
geom=[R2]
g=decsg(geom)
model= createpde
geometryFromEdges(thermalmodel,g);
pdegplot(thermalmodel,"EdgeLabels","on")
xlim([-20 20])
axis equal
thermalProperties(thermalmodel,"ThermalConductivity",1);
thermalBC(thermalmodel,"Edge",1,"Temperature",100);
thermalBC(thermalmodel,"Edge",2,"Temperature",100);
thermalBC(thermalmodel,"Edge",3,"Temperature",100);
thermalBC(thermalmodel,"Edge",4,"Temperature",400);
generateMesh(thermalmodel);
figure
pdemesh(thermalmodel)
title("Mesh with Quadratic Triangular Elements")
thermalresults = solve(thermalmodel)
pdeplot(thermalresults.Mesh,XYData=thermalresults.Temperature,ColorMap="jet")
title("Temperature In The Plate, Steady State Solution")
xlabel("X-coordinate, meters")
ylabel("Y-coordinate, meters")
axis equal
%%%%% Code for getting the temperature at the given point %%%%%
% Define the point of interest
x = -10;
y = 0;
% Interpolate the temperature at the point of interest
temperatureAtPoint = interpolateTemperature(thermalresults, x, y);
% Display the temperature in the Command Window
fprintf('The temperature at (x = %.1f, y = %.1f) is %.2f degrees.\n', x, y, temperatureAtPoint);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1758214/image.png)
You can also run the following command in the MATLAB Command Window to get the temperature at the required point:
>> interpolateTemperature(thermalresults, -10, 0)
For further information on MATLAB's "interpolateTemperature" function, refer to the following MathWorks documentation link:
I hope this is beneficial!
4 commentaires
Sahas
le 22 Août 2024 à 22:18
To incorporate the temporal domain, we can specify the time at which to evaluate the temperature in the "interpolateTemperature" function as given below.
%Previous code
thermalmodel = createpde("thermal","transient");
R1= [3,4,0,3,3,0,0,0,10,10]';
R2= [3,4,3,6,6,3,-5,-5,5,5]';
gd= [R1 R2];
sf= 'R1+R2';
ns = char('R1','R2');
ns = ns';
dl = decsg(gd,sf,ns);
geometryFromEdges(thermalmodel,dl);
pdegplot(thermalmodel,"EdgeLabels","on","FaceLabels","on")
xlim([-1 7])
ylim([-6 11])
axis equal
thermalProperties(thermalmodel,"ThermalConductivity",1,...
"MassDensity",1,...
"SpecificHeat",1);
thermalProperties(thermalmodel,"ThermalConductivity",10,...
"MassDensity",10,...
"SpecificHeat",10);
thermalBC(thermalmodel,"Edge",3,"HeatFlux",1000);
%thermalBC(thermalmodel,"Edge",3,"Temperature",100);
thermalBC(thermalmodel,"Edge",5,"Temperature",20);
thermalIC(thermalmodel,20);
generateMesh(thermalmodel);
figure
pdemesh(thermalmodel)
title("Mesh with Quadratic Triangular Elements")
% tlist = 0:0.01:0.1;
tlist = 0:5:50;
thermalresults = solve(thermalmodel,tlist)
pdeplot(thermalmodel,"XYData",thermalresults.Temperature(:,end), ...
"Contour","on",...
"ColorMap","jet")
%%%%% Including temporal interpolation %%%%%
% Define the points of interest
pointsOfInterest = [2, 5;
5, 4];
% Specify the time of interest
timeOfInterest = 50;
% Find the index of the time step closest to the desired time
[~, timeIndex] = min(abs(tlist - timeOfInterest));
% Interpolate the temperature at the points of interest
temperatures = interpolateTemperature(thermalresults, pointsOfInterest(:,1), pointsOfInterest(:,2), timeIndex);
% Display
for i = 1:size(pointsOfInterest, 1)
fprintf('The temperature at (x = %.1f, y = %.1f) at t = %.1f is %.2f degrees.\n', ...
pointsOfInterest(i, 1), pointsOfInterest(i, 2), tlist(timeIndex), temperatures(i));
end
Refer to the following example given in the MathWorks documentation of a transient "interpolateTemperature" function: https://www.mathworks.com/help/pde/ug/pde.steadystatethermalresults.interpolatetemperature.html
I hope this is also helpful!
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!