{"id":15716335,"url":"https://github.com/matheuscavini/fem-modalanalysis","last_synced_at":"2025-05-13T00:07:34.117Z","repository":{"id":248317455,"uuid":"828354904","full_name":"MatheusCavini/FEM-ModalAnalysis","owner":"MatheusCavini","description":"MatLab code for running modal analysis of truss and beam structures.","archived":false,"fork":false,"pushed_at":"2024-07-13T23:16:39.000Z","size":9,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-13T00:07:03.884Z","etag":null,"topics":["beam-analysis","computational-mechanics","fem","finite-element-methods","matlab","modal-analysis","structure-analysis","truss-analysis"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatheusCavini.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-13T22:08:50.000Z","updated_at":"2025-02-20T10:20:28.000Z","dependencies_parsed_at":"2024-07-20T11:03:39.416Z","dependency_job_id":null,"html_url":"https://github.com/MatheusCavini/FEM-ModalAnalysis","commit_stats":null,"previous_names":["matheuscavini/fem-modalanalysis"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatheusCavini%2FFEM-ModalAnalysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatheusCavini%2FFEM-ModalAnalysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatheusCavini%2FFEM-ModalAnalysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatheusCavini%2FFEM-ModalAnalysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatheusCavini","download_url":"https://codeload.github.com/MatheusCavini/FEM-ModalAnalysis/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843215,"owners_count":21972873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beam-analysis","computational-mechanics","fem","finite-element-methods","matlab","modal-analysis","structure-analysis","truss-analysis"],"created_at":"2024-10-03T21:45:06.586Z","updated_at":"2025-05-13T00:07:34.088Z","avatar_url":"https://github.com/MatheusCavini.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Finite Elements Method: Modal Analysis\n## Introduction\nThe code presented in this repository implements the functionalities needed to perform a modal analysis of mechanical structures made of trusses and beams in 2D space.\u003cbr\u003e\nThe code was developed based on theorical concepts of Finite Elements Methods (FEM) presented in the discipline \"Computational Mechanics\" (PMR3401) as part of my Mechatronics Engineering course at Escola Politécnica da Universidade de São Paulo (USP).\n\n## Classes\n- **Node**: an object from the class `Node()` represents a node on 2D plane, that is part of a truss or beam. It takes only its X and Y coordinates.\n- **Link**: an object from the class `Link()` represents a truss element. It takes its lenght `L`, Young's module `E`, area `A`, density `rho` and angle relative to the x axis `a`. On the backstages, it calculates the mass and stiffness matrices for the element.\n- **Portic**: an object from the class `Portic()` represents a beam element. It takes its lenght `L`, Young's module `E`, area `A`, moment of inertia `I`, density `rho` and angle relative to the x axis `a`. On the backstages, it calculates the mass and stiffness matrices for the element.\n\n## Usage example\n\nExample on how to use the code provided to solve a modal analysis for the structure below, where 1 is a beam and 2 is a truss.\n\n![image](https://github.com/user-attachments/assets/40ac5de0-133e-495f-ad95-e7a7efa4070a)\n\n1. Instantiate the nodes that are part of the structure in a list:\n```matlab\n   %List of nodes\n   Nodes = {Node(0,0), Node(2,0), Node(0, 2*sqrt(3))};\n```\n\n2. Define functions for calculating the distance and angle between 2 nodes:\n```matlab\n    %Function that calculates the distance between two nodes\n    function dist = Dist(nodeA, nodeB)\n      dist = sqrt((nodeB.x - nodeA.x)^2 + (nodeB.y - nodeA.y)^2);\n    end\n    \n    %Function that calculates the angle between two nodes\n    function angle = Angle(nodeA, nodeB)\n      angleRad = atan2(nodeB.y - nodeA.y, nodeB.x - nodeA.x);\n      angle = rad2deg(angleRad);\n    end\n```\n3. Define the numerical properties for the elements (be consistent on units):\n```matlab\n  %Materials properties\n  E = 10; %Pa\n  rho1 = 3 ;\n  rho2 = 2;     %Kg/m³\n  \n  %Sections properties\n  A1 = 1;         %m²\n  A2 = 2;\n  I1 = 1;\n```\n4. Instantiate each element that is part of the structure:\n```matlab\n  %Instantiate elements\n  portic1 = Portic(Dist(Nodes{1},Nodes{2}), E, A1, I1, rho1, Angle(Nodes{1},Nodes{2}));\n  link1 = Link(Dist(Nodes{2},Nodes{3}), E, A2, rho2, Angle(Nodes{2},Nodes{3}));\n```\n\n5. Put the elements in a list. Create a connectivity matrix that obbey the order of the elements in the list, relating each one to its nodes:\n```matlab\n  %Elements list and connectivity matrix\n  elements = {portic1, link1};\n  connectivity = [1 2; 2 3];\n```\n\n6. Assemble the global mass and stiffness matrices from the local ones:\n```matlab\n  % Assemble the global mass and stiffness matrices\n  num_nodes = length(Nodes);\n  num_dof = 3 * num_nodes;   %3 DOFs por nó\n  K_global = zeros(num_dof);\n  M_global = zeros(num_dof);\n  \n  for i = 1:length(elements)\n      element = elements{i};\n      nodes = connectivity(i, :);\n      K_element = element.K;\n      M_element = element.M;\n  \n      % Compute global indexes and explode matrices\n       for r = 1:length(nodes)\n          for s = 1:length(nodes)\n              indices_r = (3*(nodes(r)-1)+1):(3*(nodes(r)-1)+3);\n              indices_s = (3*(nodes(s)-1)+1):(3*(nodes(s)-1)+3);\n  \n              K_global(indices_r, indices_s) += ...\n                  K_element(3*(r-1)+1:3*(r-1)+3, 3*(s-1)+1:3*(s-1)+3);\n  \n              M_global(indices_r, indices_s) += ...\n                  M_element(3*(r-1)+1:3*(r-1)+3, 3*(s-1)+1:3*(s-1)+3);\n          end\n      end\n  end\n```\n\n7. Apply the boundary conditions of the structure by removing the rows and columns of the matrices relative to the constrained degrees of freedom (DOF). Do the same to the 3rd degree of freedom of each truss-only node:\n```matlab\n  %Function to apply the boundary conditions\n  function [K_constrained, M_constrained] = apply_constraints(K, M, constrained_dofs)\n      % Get the total number of DOFs\n      total_dofs = size(K, 1);\n  \n      % Create a logical mask for free DOFs\n      free_dofs_mask = true(total_dofs, 1);\n      free_dofs_mask(constrained_dofs) = false;\n  \n      % Apply the mask to the global matrices to get the constrained matrices\n      K_constrained = K(free_dofs_mask, free_dofs_mask);\n      M_constrained = M(free_dofs_mask, free_dofs_mask);\n  end\n  \n  %Encastre on node 1, support on 2 and revolute joint on 3 (besides, remove rotation of node 3 since is truss-only)\n  constrained_dofs = [1, 2, 3, 5, 7, 8, 9];\n  \n  % Apply constraints\n  [K_constrained, M_constrained] = apply_constraints(K_global, M_global, constrained_dofs);\n```\n8. Solve the Eigenvectors and Eigenvalues problem to the mass and stiffness matrices, and display the results:\n```matlab\n  function [frequencies, mode_shapes] = modal_analysis(K_constrained, M_constrained)\n      % Solve the generalized eigenvalue problem\n      [V, D] = eigs(K_constrained, M_constrained);\n  \n      % Extract eigenvalues and eigenvectors\n      eigenvalues = diag(D);\n      frequencies = sort(sqrt(eigenvalues));\n      mode_shapes = V;\n  end\n  \n  [frequencies, mode_shapes] = modal_analysis(K_constrained, M_constrained);\n  \n  % Display results\n  disp('Natural Frequencies (ras/d):');\n  disp(frequencies);\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatheuscavini%2Ffem-modalanalysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatheuscavini%2Ffem-modalanalysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatheuscavini%2Ffem-modalanalysis/lists"}