Can't complete contour fill graph
3 次查看(过去 30 天)
显示 更早的评论
I'm trying to plot this contour graph predicting melt pool dimensions at different laser power (P) and scan speed (u), and I want the y axis to start at P = 0.5. The problem is, I can't get g (aka the z value) high enough to make that possible. For each combination of P and u, we get a specific value of g2, which is the level I use to find the melt pool dimensions from. The lower the P value, the higher the g2 value. The lowest P I can use is around 40. I've tried adjusting the mesh size (basically zooming in) and no dice. Is there a way to interpolate the data or something so I can include y = 0.5? I've included a picture of what the graph should look like.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1425318/image.png)
Also, since my description probably doesn't make sense without the code, here's what I've got so far:
clear all
close all
clc
%Constant
rho = 4420; %kg/m^3
Cp = 550; %J/kg?K
T0 = 303.15; %K
A = 0.5; %[Absorbtivity]
k = 7.2; %W/m/K
alpha = 2.96*10^-6; %m^2/s
D = alpha;
P = 100; %W
v = 1; %m/s
u = v;
Tm = 1933; %K
d_laser = 0.0001; %m
r_laser = d_laser/2; %m
a = r_laser;
p = D/(u*a);
%Define
n = 100;
x = linspace(-0.00025,0.00125,n);
y = linspace(-0.00025,0.00025,n);
z = linspace(0,0.0005,n);
%Normalized
x_nor = x/a;
y_nor = y/a;
z_nor = z/(D*a/u).^0.5;
%Mesh grid
[x_mesh,y_mesh] = meshgrid(x_nor,y_nor)
z = 0;
% Specify the range of P and u
n = 4
P_range = [50 100 200 300 400]
u_range = [0.5 1 2 3 4]
num_P = length(P_range);
num_u = length(u_range);
melt_pool_length = zeros(num_u, num_P);
melt_pool_width = zeros(num_u, num_P);
melt_pool_depth = zeros(num_u, num_P);
% Calculate melt pool dimensions for different values of P and u
for i = 1:num_u
for j = 1:num_P
u = u_range(i)
P = P_range(j)
% Calculate g for each P and u
fun = @(t) exp((-z^2./(4*t))-((y_mesh.^2+(x_mesh-t).^2)./(4*p.*t+1)))./((4.*p.*t+1).*sqrt(t));
g = integral(fun,0,Inf,'ArrayValued',true);
Ts = (0.5*P)/(pi*rho*Cp*sqrt(D*u*(a^3)))
% Find the contour level where g is equal to the ratio
g2 = Tm/Ts
contourc(x, y, g)
%ind=find(c2(1,:)==max(c_lev)-1);
contourdata = contourc(x_nor, y_nor, g, [g2 g2])
% Initialize arrays to store the boundary coordinates
x_prime = [contourdata(1,2:size(contourdata,2))]
y_prime = [contourdata(2,2:size(contourdata,2))]
% Calculate melt pool dimensions using the extracted boundary coordinates
melt_pool_length(i, j) = max(x_prime) - min(x_prime)
melt_pool_width(i, j) = max(y_prime) - min(y_prime)
end
end
[u_mesh,P_mesh]=meshgrid(u_range,P_range)
transpose(u_mesh)
transpose(P_mesh)
melt_pool_width = melt_pool_width.*10^6.*a
melt_pool_length = melt_pool_length .* 10^6.*a
figure;
levelindex = [90 120 150 180 210 240]
[A,B] = contourf(transpose(u_mesh), transpose(P_mesh), melt_pool_width, levelindex, Color='white');
clabel(A,B,'Color','white')
colorbar;
xlabel('Scanning velocity (m/s)');
ylabel('Laser power (W)');
title('Melt Pool Width (\mum)');
%Plot the contour graph of melt pool dimensions
figure;
contourf(transpose(u_mesh), transpose(P_mesh), melt_pool_length, Color='white');
colorbar;
xlabel('Scanning velocity (m/s)');
ylabel('Laser power (W)');
title('Melt Pool Length');
1 个评论
Mathieu NOE
2023-7-10
according to your image , P starts around 50 and not 0.5 (confusion with u lower limit ?)
so your code has the right min / max u and P limits
but if your code generate another result vs what you expected this maybe comes from another issue
回答(1 个)
Brahmadev
2023-12-20
For interpolating Interpolation for 2-D gridded data in meshgrid format, the 'interp2' function can be used. See example below.
% create an extended range for P values
P_range_ext = [0.5 40 50 100 200 300 400]
% Create an extended meshgrid using the "meshgrid" function
[u_mesh_ext,P_mesh_ext]=meshgrid(u_range,P_range_ext)
% Extrapolate the data using the "interp2" function
melt_pool_width_ext = interp2(u_mesh,P_mesh,melt_pool_width,u_mesh_ext,P_mesh_ext,'makima');
Further, ther data can be normalized according as per need and a contour can be plotted using 'contourf' function.
You can see the MathWorks documentation for the 'interp2' using the following link: https://www.mathworks.com/help/matlab/ref/interp2.html
Hope this helps in resolving your query!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!