Borrar filtros
Borrar filtros

Thermal distribution - Problem with horzcat and dimensions of a plate

7 visualizaciones (últimos 30 días)
I want to design a single heat sink plate and show the thermal distribution. Refering to this Heat Transfer - MATLAB & Simulink - MathWorks Nordic. The goal is to get a single plate (such as the circle defined) which show the termal distribution. I once got an example of a colored circle but with white space outside which is wrong and I can't fix it.
This is the first example:
clc
clear all
close all
% Parameters
numCells = 1; % Number of cells
cellDiameter = 9e-3; % Diameter of each cell in meters
cellRadius = cellDiameter / 2; % Radius of each cell
powerSource = 0.8; % Power in watts for the heated cell
plateLength = 0.1; % Length of the plate in meters
plateWidth = 0.1; % Width of the plate in meters
thermalConductivity = 10; % Thermal conductivity in W/(m*K)
initialTemp = 298; % Initial temperature in Kelvin
% Create a PDE model for thermal analysis
thermalModel = createpde('thermal', 'transient');
% Define the geometry: rectangular plate with circular cells
gdm = [3 4 0 plateLength plateLength 0 0 0 plateWidth plateWidth]';
ns = 'plate';
sf = 'plate';
% Add circular cells
x = plateLength/2;
y = plateWidth/2;
C = [1 x y cellRadius]';
gdm = [gdm; C];
ns = [ns, 'cell'];
sf = [sf, 'cell'];
dl = decsg(gdm, sf, ns);
geometryFromEdges(thermalModel, dl);
% Plot the geometry (optional)
figure;
pdegplot(thermalModel, 'EdgeLabels', 'on');
title('Geometry with Battery Cells');
axis equal;
% Specify thermal properties of the material
thermalProperties(thermalModel, 'ThermalConductivity', thermalConductivity);
% Apply boundary condition: internal heat source to one random cell
heatCellIndex = 1;
internalHeatSource(thermalModel, powerSource, 'Cell', heatCellIndex);
% Set initial temperature of the plate
thermalIC(thermalModel, initialTemp);
% Generate mesh
generateMesh(thermalModel, 'Hmax', cellRadius/2);
% Define solution times
tlist = linspace(0, 100, 50); % Simulate for 100 seconds
% Solve the model
thermalResults = solve(thermalModel, tlist);
% Get the temperature distribution at the final time step
T = thermalResults.Temperature;
% Plot the temperature distribution at the final time step
figure;
pdeplot(thermalModel, 'XYData', T(:, end), 'Contour', 'on', 'ColorMap', 'jet');
title('Temperature Distribution in the Battery Plate at Final Time Step');
xlabel('X (m)');
ylabel('Y (m)');
colorbar;
And this is the second example
clc
clear all
close all
% Parameters
numCells = 1; % Number of cells
cellDiameter = 9e-3; % Diameter of each cell in meters
cellRadius = cellDiameter / 2; % Radius of each cell
powerSource = 0.8; % Power in watts for the heated cell
plateLength = 0.1; % Length of the plate in meters
plateWidth = 0.1; % Width of the plate in meters
thermalConductivity = 10; % Thermal conductivity in W/(m*K)
initialTemp = 298; % Initial temperature in Kelvin
% Create a PDE model for thermal analysis
thermalModel = createpde('thermal', 'transient');
% Define the geometry: rectangular plate with a single circular cell
gdm_plate = [3 4 0 plateLength plateLength 0 0 0 plateWidth plateWidth]';
gdm_cell = [1 plateLength/2 plateWidth/2 cellRadius]';
gdm = [gdm_plate, gdm_cell];
ns = char('plate', 'cell');
sf = 'plate + cell';
dl = decsg(gdm, sf, ns);
geometryFromEdges(thermalModel, dl);
% Plot the geometry (optional)
figure;
pdegplot(thermalModel, 'EdgeLabels', 'on');
title('Geometry with Battery Cell');
axis equal;
% Specify thermal properties of the material
thermalProperties(thermalModel, 'ThermalConductivity', thermalConductivity);
% Apply boundary condition: internal heat source to the cell
internalHeatSource(thermalModel, powerSource, 'Face', 2);
% Set initial temperature of the plate
thermalIC(thermalModel, initialTemp);
% Generate mesh
generateMesh(thermalModel, 'Hmax', cellRadius/2);
% Define solution times
tlist = linspace(0, 100, 50); % Simulate for 100 seconds
% Solve the model
thermalResults = solve(thermalModel, tlist);
% Get the temperature distribution at the final time step
T = thermalResults.Temperature;
% Plot the temperature distribution at the final time step
figure;
pdeplot(thermalModel, 'XYData', T(:, end), 'Contour', 'on', 'ColorMap', 'jet');
title('Temperature Distribution in the Battery Plate at Final Time Step');
xlabel('X (m)');
ylabel('Y (m)');
colorbar;
I get nearly the same errors for both of them and I cant solve it.
This the error for example 1:
Error using decsg (line 138)
Nonzero value in the geometry description matrix after polygon definition.
Error in plate2 (line 32)
dl = decsg(gdm, sf, ns);
And this is the error for example 2:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in plate3 (line 21)
gdm = [gdm_plate, gdm_cell];
I have tried to redefine the geometry but the same issue persist.

Respuestas (1)

dpb
dpb el 2 de Ag. de 2024
Editada: dpb el 2 de Ag. de 2024
The second is trivial to diagnose; only you will be able to know what is intended in order to fix it correctly for the model you're trying to create...
gdm_plate = [3 4 0 plateLength plateLength 0 0 0 plateWidth plateWidth]';
gdm_cell = [1 plateLength/2 plateWidth/2 cellRadius]';
gdm = [gdm_plate, gdm_cell];
The first is a column vector of 10 elements while the second has only 4; you can't append a 4-vector to a 10-vector;you're short six (6) elements to match.(+)
You really should use the .' transpose operator instead of the complex transpose single dot here....it won't make a difference on the real values here but is a good practice to cultivate using complex transpose only where are sure it is wanted/needed.
As for the first, descg doesn't appear to be a MATLAB builtin function so we're blind with respect to what it may be doing, but from the error it would seem some array that is supposed to be all zero (???) isn't, but that seems like a weird condition; one wonders if it was meant to be "nonfinite" like checking if had a divide by zero error...
You'll have to look into where the error is happening (use the debugger) and see if you can divine what is happening. If that doesn't solve it, you'll have to provide more of a roadmap to the function; I didn't see any reference to it at the link you posted.
ADDENDUM (+): The above assumes that you're trying to build/need a 2D matrix; if the intent is to create a single vector, then the only problem is trying to horizontally catenate two column vectors of different length; in that case you would simply need to catenate them vertically as
gdm_plate = [3 4 0 plateLength plateLength 0 0 0 plateWidth plateWidth].';
gdm_cell = [1 plateLength/2 plateWidth/2 cellRadius].';
gdm = [gdm_plate; gdm_cell];
only the use of array transpose operator instead of complex transpose and the semi-colon to put the second column vector at the tail end of the first is different. And, only the semi-colon instead would be all that would be mandatory. Again, this presupposes the end result is supposed to be a 1D column vector...
  1 comentario
FunkyChicken
FunkyChicken el 13 de Ag. de 2024
Thanks, I gave up on that. Now I'm just trying to get any sort of heat distribution.
This is the code
clc;
clear all;
close all;
% Parameters
radius = 0.1; % Radius of the circular plate (in meters)
thermalConductivity = 0.1; % Further reduced thermal conductivity (W/(m*K))
specificHeat = 500; % Specific heat (J/(kg*K))
massDensity = 7800; % Mass density (kg/m^3)
initialTemp = 298; % Initial temperature (K)
powerSource = 5000; % Increased power source at the center (W)
% Create a PDE model for thermal analysis
thermalModel = createpde('thermal', 'transient');
% Create the geometry: a circle representing the heat sink
g = decsg([1 0 0 radius]','C1',('C1')');
geometryFromEdges(thermalModel, g);
% Plot the geometry (optional)
figure;
pdegplot(thermalModel, 'EdgeLabels', 'on');
title('Circular Heat Sink');
axis equal;
% Specify thermal properties (including specific heat and mass density)
thermalProperties(thermalModel, 'ThermalConductivity', thermalConductivity, ...
'MassDensity', massDensity, 'SpecificHeat', specificHeat);
% Apply boundary condition: internal heat source at the center
internalHeatSource(thermalModel, powerSource, 'Face', 1);
% Set initial temperature of the plate
thermalIC(thermalModel, initialTemp);
% Generate mesh
generateMesh(thermalModel, 'Hmax', radius/30); % Finer mesh
% Define solution times
tlist = linspace(0, 500, 100); % Simulate for 500 seconds
% Solve the model
thermalResults = solve(thermalModel, tlist);
% Get the temperature distribution at the final time step
T = thermalResults.Temperature;
% Plot the temperature distribution at the final time step
figure;
pdeplot(thermalModel, 'XYData', T(:, end), 'Contour', 'on', 'ColorMap', 'jet');
title('Temperature Distribution in the Circular Heat Sink at Final Time Step');
xlabel('X (m)');
ylabel('Y (m)');
colorbar;
% Calculate min and max temperatures for caxis
T_min = min(T(:, end));
T_max = max(T(:, end));
% Adjust the color axis to emphasize the gradient
caxis([T_min, T_max]); % Use the real temperature range
And when you run it, it doesn't work properly. I can't the distribution I only see single colors for the final time stamp etc.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by