Advertisement
Guest User

Untitled

a guest
Oct 24th, 2024
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. clc
  2. clear
  3. %Number of nodes in bike
  4.  
  5. properties = struct;
  6.  
  7. properties.E = 2.1e5; %Youngs Modulus
  8. properties.halfArea = 5;
  9. properties.fullArea = 10;
  10. properties.Dof = 3; %Degrees of Freedom at each node
  11.  
  12.  
  13. %The location of each node.
  14. properties.nodeLocation = [410,0;0, 74;276.51, 450.65;836.51, 450.65;1004, 74];
  15. numberOfNodesPreMesh = length(properties.nodeLocation);
  16.  
  17. Force = zeros(3 .* numberOfNodesPreMesh,1);
  18.  
  19.  
  20. %Matrix for the elements connecting to which node
  21. elementConnections = [1,2;2,3;3,1;3,4;4,1;4,5];
  22.  
  23. %How many extra nodes we want putting in on each element
  24. meshSize = [6,2,2,2,2,2];
  25.  
  26. %Creating the matrix which will hold all nodes and extra nodes created
  27. %from meshing
  28. P = zeros(0,2);
  29.  
  30. for i=1:size(elementConnections,1) %%%%%% Repeat for every line in L
  31. L_p = elementConnections(i,:); %%%%%% Picking a line, row i (counter)
  32. S = (0:meshSize(i))'/meshSize(i); %%%%%% Generate the scaling series
  33. N_c = properties.nodeLocation(L_p,:); %%%%%% Extracting Starting and Ending Nodal Coordinates
  34. V = N_c(2,:) - N_c(1,:); %%%%%% Generating the line directional Vector
  35. %Repmat removes the need of a for loop, decreasing time taken
  36. S = repmat(S,1,size(V,2)); %%%%%% Conforming the scaling series to V
  37. V = repmat(V,size(S,1),1); %%%%%% Conforming the directional vector to the number of scales
  38. V_s = S.*V; %%%%%% Generating the scaling vectors
  39. P_i = repmat(N_c(1,:),size(V_s,1),1) + V_s; %%%%% Nodes on line segement
  40. P = [P;P_i];
  41. end
  42.  
  43.  
  44.  
  45. duplicates = [];
  46. % Loop through each element in P
  47. for i = 1:length(P)
  48. current = P(i,1); % Current element of P
  49. duplicateLoc = find(P(:,1) == current); % Find all locations of this element
  50.  
  51. % Only add the locations if there is more than one occurrence
  52. if length(duplicateLoc) > 1
  53. % Check if these duplicate locations are already in the duplicates matrix
  54. for j = 1:length(duplicateLoc)
  55. if isempty(find(duplicates == duplicateLoc(j), 1)) % If location not already stored
  56. % Append to duplicates matrix and add original node number
  57. duplicates = [duplicates; duplicateLoc(j), i]
  58. end
  59. end
  60. end
  61. end
  62.  
  63. % Loop through each element in P
  64. i = 1;
  65. while i <= length(P)
  66. current = P(i,1); % Current element of P
  67. duplicateLoc = find(P(:,1) == current); % Find all locations of this element
  68.  
  69. % If there are duplicates
  70. if length(duplicateLoc) > 1
  71. % Keep the first occurrence and remove the rest
  72. duplicateLoc(1) = []; % Retain the first instance, remove the rest
  73.  
  74. % Remove the duplicates from P by deleting the corresponding rows
  75. P(duplicateLoc, :) = [];
  76. else
  77. % Move to the next element only if no duplicates were removed
  78. i = i + 1;
  79. end
  80. end
  81.  
  82.  
  83.  
  84. %% PLOT
  85. for j = 1:size(elementConnections,1)
  86. plot(properties.nodeLocation(elementConnections(j,:),1),properties.nodeLocation(elementConnections(j,:),2),'LineWidth',2,'Color','r')
  87. xlabel('x(mm)')
  88. ylabel('y(mm)')
  89. hold on
  90.  
  91. end
  92. %Plot Mesh nodes
  93. plot(P(:,1),P(:,2),'bo','MarkerFaceColor',[1 1 1],'MarkerSize',10);
  94.  
  95. % Add node IDs next to each node
  96. for i = 1:size(P, 1)
  97. text(P(i, 1) + 40, P(i, 2) + 30, num2str(i), 'FontSize', 10, 'Color', 'k'); % Adjust offset and color as needed
  98. end
  99.  
  100. hold off;
  101. %%
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement