Fluid distribution in inclined rectangle

3 views (last 30 days)
Laia
Laia on 5 Jul 2024
Commented: Umar on 5 Jul 2024
I'm working on a MATLAB code that simulates fluid distribution in an inclined rectangle. I'm encountering an issue with the fluid volume. It seems like the simulation is treating the rectangle as if it were still horizontal, limited by its original dimensions.
Here's the specific problem:
  • At low fill levels, the fluid doesn't lower past a certain point.
  • Similarly, at high fill levels, the fluid doesn't fill the entire inclined rectangle, stopping again at the dashed blue line.
  • The maximum volume is 4.3L given the dimensions. I've attached the resulting plots of very low fill volume (0.01L) and high (4.2L).
How can I fix this?
Clarifications: the "dashed blue line" represents the non-inclined rectangle, the "brigth blue color" represents the fluid, the "black line" represents the tilted rectangle.

Answers (1)

Umar
Umar on 5 Jul 2024

Hi Laia,

After analyzing your code, I made some minor modifications. Afterwards, executed the modified code in matlab, at high fill levels, the fluid did fill the entire inclined rectangle.

% Define the dimensions of the rectangle length = 0.315; % length in meters height = 0.06; % height in meters width = 0.23; % width in meters

% Define the fill volume and calculate the fluid height fill_volume = 4.2; % fill volume in liters fill_volume_m3 = fill_volume * 1e-3; % convert liters to cubic meters fluid_height_upright = fill_volume_m3 / (length * width); % fluid height in meters if upright

% Calculate the maximum volume maximum_volume = height * length * width;

% Define the angle of rotation in degrees theta = 10; % angle of rotation

% Convert angle to radians for rotation matrix theta_rad = deg2rad(theta);

% Define the four corners of the rectangle x = [-length/2, length/2, length/2, -length/2]; y = [-height/2, -height/2, height/2, height/2];

% Create a rotation matrix R = [cos(theta_rad), -sin(theta_rad); sin(theta_rad), cos(theta_rad)];

% Rotate the corners of the rectangle rotated_corners = R * [x; y];

% Calculate the effective height of the fluid in the rotated frame fluid_height_inclined = fluid_height_upright / cos(theta_rad);

% Calculate the new fluid surface intersection points in the rotated frame fluid_surface_y_inclined = fluid_height_inclined - height/2;

% Inline calculation for intersections intersection_points = []; for i = 1:4 j = mod(i, 4) + 1; if (rotated_corners(2,i) <= fluid_surface_y_inclined && rotated_corners(2,j) >= fluid_surface_y_inclined) ... (rotated_corners(2,i) >= fluid_surface_y_inclined && rotated_corners(2,j) <= fluid_surface_y_inclined) t = (fluid_surface_y_inclined - rotated_corners(2,i)) / (rotated_corners(2,j) - rotated_corners(2,i)); intersection = rotated_corners(:,i) + t * (rotated_corners(:,j) - rotated_corners(:,i)); intersection_points = [intersection_points, intersection]; end end

% Determine the fluid polygon vertices based on the fill height if fill_volume_m3 <= maximum_volume % Fluid fills the entire rectangle fluid_polygon = rotated_corners; elseif fluid_height_upright <= height / 2 % Fluid forms a triangle fluid_polygon = [rotated_corners(:,1), rotated_corners(:,2), intersection_points]; else % Fluid forms a polygon (could be pentagon or other) fluid_polygon = [intersection_points, rotated_corners(:,3), rotated_corners(:,4), rotated_corners(:,1), rotated_corners(:,2)]; end

% Plot the original rectangle (for reference) figure; plot([x, x(1)], [y, y(1)], 'b--', 'LineWidth', 1.5); % dashed blue line hold on;

% Plot the rotated rectangle plot([rotated_corners(1,:), rotated_corners(1,1)], [rotated_corners(2,:), rotated_corners(2,1)], 'r-', 'LineWidth', 2); % solid red line

% Plot the fluid surface fill(fluid_polygon(1,:), fluid_polygon(2,:), 'cyan', 'FaceAlpha', 0.5, 'EdgeColor', 'none');

% Set plot limits axis equal; xlim([-length, length]); ylim([-height, height]);

% Add labels and title xlabel('X'); ylabel('Y'); legend('Original Position', 'Rotated Position', 'Fluid Level', 'Location', 'Best');

% Display grid grid on; hold off;

Please see the attached plot.

Feel free to adjust the parameters based on your preferences. Hope this will help resolve your issue.

  2 Comments
Laia
Laia on 5 Jul 2024
Hi Umar,
With this modification, all possible fill volumes (>0 to 4.3L (maximum fill volume)) are displayed as if the liquid completely fills the entire rectangle, regardless of the actual volume. For instance, a volume of 4.2L should leave some empty space in the top right corner, similar to lower volumes. Ideally, I want the simulation to realistically depict the fluid's behavior at different fill levels, taking into account the rectangle's angle. It seems the initial code performed well for mid-range volumes but struggled with very low and high fill levels, where the fluid wouldn't remain confined within the original rectangle's boundaries.
Umar
Umar on 5 Jul 2024
Hi Laia,
Maybe I interpreted reading this statement posted by you ‘at high fill levels, the fluid doesn't fill the entire inclined rectangle’. So, I experimented with code and tried to accomplish this objective. Now, after reading your recent comments, please let me know how can I help you.

Sign in to comment.

Categories

Find more on Fluid Dynamics 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!