Skip to content

Latest commit

 

History

18 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Beam Bending Analysis Project

Beam Bending Analysis is a classic strength-of-materials problem. The beam has a length of 25 units and is subjected to distributed loads, concentrated forces, and moments. It is supported by pin, fixed, and elastic supports at specified points. Two independent approaches are implemented:

  • Analytical solution – written in SageMath using the initial parameters method with Heaviside functions.
  • Numerical solution – a finite element method (FEM) implemented in C++ (stiffness matrix assembly and solving a linear system).

Results from both methods are compared and visualised with a Python script.

Project Structure

beam-bending-analysis/
├── data/ # Input data
│ ├── parameters.txt # Physical parameters (P, M, Q1, Q2, K, E, J)
│ ├── coordinates.txt # Coordinates of characteristic points
│ └── Балка_2025.xlsx # Loading scheme (Excel file)
├── src/
│ ├── sage/ # Analytical solution (Sage)
│ │ ├── beams_bending.sage
│ │ └── beams_bending.py
│ ├── fem/ # Finite element method (C++)
│ │ └── beams_bending.cpp
│ └── plotting/ # Visualisation
│ └── paint.py
├── results/ # Output data
│ ├── sage_res_*.txt # Deflections, angles, moments, forces (Sage)
│ ├── FEM_res_*.txt # Same for FEM
│ └── result_plot.png # Comparative plots
├── parameters.txt → data/parameters.txt # Symlinks for convenience
├── coordinates.txt → data/coordinates.txt
├── README.md
├── README.html
└── .gitignore

Requirements

Component Required software / versions
Sage solution SageMath ≥ 9.0 (supports symbolic computation and desolve)
C++ FEM C++17 compiler (g++, clang), standard library
Python plotting Python 3, matplotlib, numpy

Quick Start

The easiest way to run the entire pipeline (analytical solution, FEM, and plotting) is to use the provided Makefile in the project root.

Using Make (recommended)

make all

This will compile the C++ FEM program (if needed), run the Sage analytical solution, execute the FEM simulation, and finally generate the comparison plot. All results will be saved in the results/ folder.

Other useful Make targets:

  • make sage – only the analytical solution
  • make fem – compile and run the FEM code
  • make plot – generate the plot (runs Sage and FEM if necessary)
  • make clean – remove all generated files (results, executable)
  • make rebuild – clean + all

Manual run (step by step)

If you prefer to run each component separately, follow these steps from the project root:

  1. Sage (analytical solution)
    cd src/sage
    sage beams_bending.sage

    Output files (sage_res_*.txt) will appear in results/.

  2. C++ FEM (numerical solution)
    cd src/fem
    g++ -std=c++11 -Wall -O2 beams_bending.cpp -o beams_bending
    ./beams_bending

    The executable expects parameters.txt and coordinates.txt to be present (symlinks in the project root point to data/). Results are saved as FEM_res_*.txt in results/.

  3. Plotting (Python)
    cd src/plotting
    python3 paint.py

    This script reads the generated sage_res_*.txt and FEM_res_*.txt files from results/ and produces result_plot.png comparing deflection, rotation, moment, and shear force.

Results

After a successful run, the results/ directory will contain:

  • sage_res_*.txt – arrays of (x, W, θ, M, Q) from the analytical solution. The exact filename includes a timestamp or run identifier.
  • FEM_res_*.txt – similar data from the finite element method.
  • result_plot.png – a comparative plot showing both solutions for deflections, slopes, bending moments, and shear forces. This allows you to visually assess the accuracy and convergence of the FEM approach.

All text files are space-separated and can be easily imported into other tools (e.g., Excel, MATLAB, or further Python analysis).

Results

Below is a sample comparison plot generated by the Python script. It shows deflection, slope, bending moment, and shear force from both methods.

Comparison of analytical and FEM results

The plot clearly demonstrates the agreement between the analytical solution (Sage) and the finite element method (C++).

License

This project is distributed under the MIT License. See the LICENSE file in the repository for full details. Feel free to use, modify, and redistribute the code for educational or commercial purposes.

Author

@g30613740 (GitHub)
For questions or suggestions, please open an issue in the repository.

Releases

Packages

Contributors

Languages