fini
This commit is contained in:
1 parent
1cadeecff2
commit
14d38cc163
3 files changed
+24
-38
No files matched your search
+3
-1
@@ -20,7 +20,9 @@ function plotProfiles(x_coords, profiles_data, labels)
|
||||
xlabel('Position along bar, x (m)');
|
||||
ylabel('Temperature, T (^oC)');
|
||||
title('Temperature Profiles Over Time');
|
||||
legend('Location', 'southeast');
|
||||
if length(profiles_data) <= 15
|
||||
legend('Location', 'ne');
|
||||
end
|
||||
ylim([0 100]); % Set y-limits to reasonable temperature range
|
||||
hold off;
|
||||
end
|
||||
@@ -3,14 +3,19 @@ thermal_cond.Tg = 100; thermal_cond.Td = 50; thermal_cond.T0 = 0;
|
||||
steps.dx = 0.01; steps.dt = 0.5;
|
||||
|
||||
t_final_s_sim = 2000; % Total simulation time
|
||||
plot_points = [0, 10, 50, 100, 200, 500, 1000, 2000]; % Specific times to capture profiles
|
||||
% plot_points = [0, 10, 50, 100, 200, 500, 2000]; % Specific times to capture profiles
|
||||
specific_early_points = [0, 5, 10, 20];
|
||||
mid = [50:50:750];
|
||||
bar = [750:250:1250];
|
||||
quux = [t_final_s_sim];
|
||||
plot_points = unique([specific_early_points, mid, bar, quux]);
|
||||
|
||||
% Call the solver function
|
||||
[x_coords, final_T_profile, midpoint_T_series, time_vec, all_temp_profiles, profile_labels] = ...
|
||||
solveHeatEquation(material, thermal_cond, steps, t_final_s_sim, plot_points);
|
||||
|
||||
% Create and populate the figure with subplots
|
||||
figure('Color', 'white', 'Position', [100, 100, 1000, 400]);
|
||||
figure('Color', 'white', 'Position', [100, 100, 1920, 1080]);
|
||||
|
||||
subplot(1, 2, 1);
|
||||
plotProfiles(x_coords, all_temp_profiles, profile_labels);
|
||||
|
||||
+14
-35
@@ -49,20 +49,15 @@ function [x, T_final_profile, T_time_series, time_vector, all_profiles, all_prof
|
||||
T_time_series = zeros(1, Nt);
|
||||
T_time_series(1) = T_current(mid_index);
|
||||
|
||||
% Store profiles for plotting (initialization, before the main loop)
|
||||
all_profiles = cell(size(plot_time_points)); % Pre-allocate
|
||||
all_profile_times = cell(size(plot_time_points));
|
||||
% Store profiles for plotting
|
||||
all_profiles = cell(length(plot_time_points), 1);
|
||||
all_profile_times = cell(length(plot_time_points), 1);
|
||||
|
||||
% Track if a profile for a given plot_time_point has been captured
|
||||
% This ensures each target time is captured only once and correctly.
|
||||
captured_flags = false(size(plot_time_points));
|
||||
|
||||
% Capture initial profile (t=0) - this should always be the first plot point
|
||||
% Assuming plot_time_points(1) is 0
|
||||
all_profiles{1} = T_current;
|
||||
all_profile_times{1} = sprintf('t = %.0f s', plot_time_points(1));
|
||||
captured_flags(1) = true; % Mark t=0 as captured
|
||||
|
||||
% Capture initial profile (t=0)
|
||||
if ismembertol(0, plot_time_points, dt/2, 'DataScale', 1)
|
||||
all_profiles{1} = T_current;
|
||||
all_profile_times{1} = sprintf('t = %.0f s', 0); % Using sprintf for consistent formatting
|
||||
end
|
||||
% Main Time Loop
|
||||
for n = 1:Nt-1
|
||||
T_next = T_current; % Initialize T_next. Boundary conditions are retained.
|
||||
@@ -77,30 +72,14 @@ function [x, T_final_profile, T_time_series, time_vector, all_profiles, all_prof
|
||||
% Store midpoint temperature
|
||||
T_time_series(n+1) = T_current(mid_index);
|
||||
|
||||
% Store full profiles at specified plot times
|
||||
% Iterate through plot_time_points to find matches
|
||||
for p_idx = 1:length(plot_time_points)
|
||||
if ~captured_flags(p_idx) % Only try to capture if not already captured
|
||||
% Check if current simulation time (time_vector(n+1)) is at or just past the target plot time
|
||||
% Use a small tolerance relative to dt to account for floating point
|
||||
if time_vector(n+1) >= plot_time_points(p_idx) - dt/2 && time_vector(n+1) < plot_time_points(p_idx) + dt/2
|
||||
all_profiles{p_idx} = T_current;
|
||||
all_profile_times{p_idx} = sprintf('t = %.0f s', plot_time_points(p_idx)); % Use the *target time* for label
|
||||
captured_flags(p_idx) = true; % Mark as captured
|
||||
end
|
||||
% Store full profiles at specified plot times
|
||||
% Use a small tolerance for floating point comparison to match plot_time_points
|
||||
[is_plot_time, idx_to_store] = ismembertol(time_vector(n+1), plot_time_points, dt/2, 'DataScale', 1);
|
||||
if is_plot_time
|
||||
all_profiles{idx_to_store} = T_current;
|
||||
all_profile_times{idx_to_store} = sprintf('t = %.0f s', time_vector(n+1));
|
||||
end
|
||||
end
|
||||
|
||||
% Add a check at the very end of the simulation to ensure the final plot_time_point is captured
|
||||
% if t_final_s matches one of the plot_time_points and it wasn't captured exactly during the loop
|
||||
[is_final_plot_time, idx_final_plot] = ismembertol(t_final_s, plot_time_points, dt/2);
|
||||
if is_final_plot_time && ~captured_flags(idx_final_plot)
|
||||
all_profiles{idx_final_plot} = T_current;
|
||||
all_profile_times{idx_final_plot} = sprintf('t = %.0f s', t_final_s);
|
||||
captured_flags(idx_final_plot) = true;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
T_final_profile = T_current; % The profile at the very end of the simulation
|
||||
end
|
||||
Reference in new issue
Block a user