3D Heat Equation in PDE Solver
Show older comments
Hello. I have a code that solves my heat equation. However, when I interpolate temperatures at a specific point, I get an error:
Error using pde.ThermalResults.interpolateSolutionInternal
Incorrect number of input arguments.
Error in pde.TransientThermalResults/interpolateTemperature (line 208)
Tintrp = pde.ThermalResults.interpolateSolutionInternal(obj,varargin{:});
Error in untitled8 (line 42)
T_center = interpolateTemperature(results, 5,5,0.5);
I have the following code:
% Create a PDE model
model = createpde("thermal", "transient");
% Import the geometry from the STL file
g = importGeometry(model, "Plate10x10x1.stl");
% Plot the geometry with face labels and transparency
pdegplot(g, 'FaceLabels', 'on', 'FaceAlpha', 0.5);
% Customize the plot as needed
xlabel('x');
ylabel('y');
zlabel('z');
title('Cake Geometry');
% Define the boundary conditions
T_oven = 350; % Oven temperature (in Fahrenheit)
T_initial = 80; % Initial temperature of the cake (in Fahrenheit)
% Convert temperatures to Celsius for PDE Toolbox
T_oven = (T_oven - 32) * 5/9;
T_initial = (T_initial - 32) * 5/9;
% Define the thermal properties
thermalProperties(model, 'ThermalConductivity', 0.2, 'MassDensity', 1000, 'SpecificHeat', 4.2);
% Define the boundary conditions
thermalBC(model, 'Face', [1 2 3 4 5 6], 'Temperature', T_oven);
% Set the initial temperature distribution
thermalIC(model, T_initial);
% Generate the mesh
generateMesh(model);
tlist = 0:0.5:5;
% Solve the PDE
results = solve(model, tlist);
% Extract the temperature at the center of the cake
T_center = interpolateTemperature(results, 5,5,0.5);
% Convert the temperature back to Fahrenheit for plotting
T_center = T_center * 9/5 + 32;
% Plot the temperature of the center of the cake against time
t = results.Mesh.Nodes(4, :);
plot(t, T_center);
xlabel('Time');
ylabel('Temperature (°F)');
title('Temperature of the Center of the Cake');
% Convert the temperature to Celsius for display
T_center_celsius = (T_center - 32) * 5/9;
fprintf('Final temperature of the center of the cake: %.2f°C\n', T_center_celsius(end));
Answers (1)
T_center = interpolateTemperature(results, 5,5,0.5);
You didn't specify the times at which you want the temperature to be supplied. It's the fifth argument to "interpolateTemperature" that is missing.
Read the documentation for "interpolateTemperature" carefully:
9 Comments
uk
on 2 Jul 2023
uk
on 2 Jul 2023
Do you think the central temperature is supposed to be decreasing over time in this model? I was expecting it to increase over time.
T_center should be >= T_initial for all x,y,z and t. But if T_center is slightly below T_initial, this can also happen due to numerical errors.
Thus I suggest you set rho and cp to 1 and lambda to a high value and see how temperature develops in the center point of your plate. It should approach the wall temperature quite quickly.
uk
on 2 Jul 2023
Torsten
on 2 Jul 2023
lambda in the usual notation is Thermal Conductivity. You named it k.
uk
on 2 Jul 2023
Torsten
on 2 Jul 2023
I don't know. You might want to compare with your Euler-code. It was slow, but correct.
uk
on 2 Jul 2023
Categories
Find more on Geometry and Mesh 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!