Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear
- %Number of nodes in bike
- properties = struct;
- properties.E = 2.1e5; %Youngs Modulus
- properties.halfArea = 5;
- properties.fullArea = 10;
- properties.Dof = 3; %Degrees of Freedom at each node
- %The location of each node.
- properties.nodeLocation = [410,0;0, 74;276.51, 450.65;836.51, 450.65;1004, 74];
- numberOfNodesPreMesh = length(properties.nodeLocation);
- Force = zeros(3 .* numberOfNodesPreMesh,1);
- %Matrix for the elements connecting to which node
- elementConnections = [1,2;2,3;3,1;3,4;4,1;4,5];
- %How many extra nodes we want putting in on each element
- meshSize = [6,2,2,2,2,2];
- %Creating the matrix which will hold all nodes and extra nodes created
- %from meshing
- P = zeros(0,2);
- for i=1:size(elementConnections,1) %%%%%% Repeat for every line in L
- L_p = elementConnections(i,:); %%%%%% Picking a line, row i (counter)
- S = (0:meshSize(i))'/meshSize(i); %%%%%% Generate the scaling series
- N_c = properties.nodeLocation(L_p,:); %%%%%% Extracting Starting and Ending Nodal Coordinates
- V = N_c(2,:) - N_c(1,:); %%%%%% Generating the line directional Vector
- %Repmat removes the need of a for loop, decreasing time taken
- S = repmat(S,1,size(V,2)); %%%%%% Conforming the scaling series to V
- V = repmat(V,size(S,1),1); %%%%%% Conforming the directional vector to the number of scales
- V_s = S.*V; %%%%%% Generating the scaling vectors
- P_i = repmat(N_c(1,:),size(V_s,1),1) + V_s; %%%%% Nodes on line segement
- P = [P;P_i];
- end
- duplicates = [];
- % Loop through each element in P
- for i = 1:length(P)
- current = P(i,1); % Current element of P
- duplicateLoc = find(P(:,1) == current); % Find all locations of this element
- % Only add the locations if there is more than one occurrence
- if length(duplicateLoc) > 1
- % Check if these duplicate locations are already in the duplicates matrix
- for j = 1:length(duplicateLoc)
- if isempty(find(duplicates == duplicateLoc(j), 1)) % If location not already stored
- % Append to duplicates matrix and add original node number
- duplicates = [duplicates; duplicateLoc(j), i]
- end
- end
- end
- end
- % Loop through each element in P
- i = 1;
- while i <= length(P)
- current = P(i,1); % Current element of P
- duplicateLoc = find(P(:,1) == current); % Find all locations of this element
- % If there are duplicates
- if length(duplicateLoc) > 1
- % Keep the first occurrence and remove the rest
- duplicateLoc(1) = []; % Retain the first instance, remove the rest
- % Remove the duplicates from P by deleting the corresponding rows
- P(duplicateLoc, :) = [];
- else
- % Move to the next element only if no duplicates were removed
- i = i + 1;
- end
- end
- %% PLOT
- for j = 1:size(elementConnections,1)
- plot(properties.nodeLocation(elementConnections(j,:),1),properties.nodeLocation(elementConnections(j,:),2),'LineWidth',2,'Color','r')
- xlabel('x(mm)')
- ylabel('y(mm)')
- hold on
- end
- %Plot Mesh nodes
- plot(P(:,1),P(:,2),'bo','MarkerFaceColor',[1 1 1],'MarkerSize',10);
- % Add node IDs next to each node
- for i = 1:size(P, 1)
- text(P(i, 1) + 40, P(i, 2) + 30, num2str(i), 'FontSize', 10, 'Color', 'k'); % Adjust offset and color as needed
- end
- hold off;
- %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement