- Project Title: Visualization of Shear Force and Bending Moment Diagrams using Xarray and Plotly
- Organization: Osdag (FOSSEE, IIT Bombay)
- Task Type: Technical Screening Assignment
- Domain: Structural Engineering / Software Development
- Submitted by: Divit Singhania
- Program: B.Tech Computer Science (AI & ML)
- Institution: VIT Bhopal University
A short screen-recorded demonstration of the code execution and generated plots is available below:
π YouTube (Unlisted) Video Link: Click here
This repository contains Python scripts to generate 2D and 3D Shear Force Diagrams (SFD) and Bending Moment Diagrams (BMD) from an Xarray dataset, closely replicating MIDAS Civil post-processing visualizations.
The project demonstrates:
- Correct use of FEM element connectivity
- Accurate node-based geometric reconstruction
- Preservation of sign conventions from the dataset
- Professional-quality 2D and 3D structural plots
xarray-visualization/
β
βββ data/
β βββ screening_task.nc
β βββ node.py
β βββ element.py
β
βββ scripts/
β βββ xarray_usage.py
β βββ task1_2d.py
β βββ task2_3d.py
β
βββ figures/
β βββ dataset_visualization.png
β βββ node_element_connectivity.png
β βββ SDF_2D.png
β βββ BMD_2D.png
β βββ SDF_3D.png
β βββ BMD_3D.png
β
βββ report/
β βββ Report.pdf
β
βββ requirements.txt
βββ README.md
βββ .gitignore
-
Dimensions
-
Elementβ Beam element IDs -
Componentβ Internal force components -
Force Components Used
-
Vy_i,Vy_jβ Shear force at start/end node -
Mz_i,Mz_jβ Bending moment at start/end node
Suffix meaning:
_iβ Start node of element_jβ End node of element
Figure 1: Xarray dataset structure and force components
node.py defines node geometry:
node_id β (x, y, z)
element.py defines FEM connectivity:
element_id β (start_node, end_node)
Figure 2: Node coordinates and element connectivity. All plots use actual geometry β no assumed or artificial coordinates.
Inspects dataset structure
- Identifies force components.
- Extracts tabular force data for verification.
Generates 2D Shear Force (SFD) and Bending Moment (BMD) diagrams for the Central Longitudinal Girder elements: [15, 24, 33, 42, 51, 60, 69, 78, 83].
Plotting Logic:
- SFD: Step-wise (constant per element).
- BMD: Linear interpolation between nodes.
- Sign Convention: Preserved exactly from the dataset.
Figure 3: 2D Shear Force Diagram
Figure 4: 2D Bending Moment Diagram
Generates 3D SFD & BMD for all five longitudinal girders.
Visualization Features:
- X: Bridge length | Z: Bridge width | Y: Force magnitude (vertical extrusion).
- Vertical Hatching: "Fence" style plotting for transparency.
- Heat-map Coloring: Jet colormap (Blue β Red) based on magnitude.
- Global Scaling: Auto-scaled to maintain visual proportions.
Figure 5: 3D Shear Force Diagram (SFD) β All Girders
Figure 6: 3D Bending Moment Diagram (BMD) β All Girders
# 1. Install dependencies
pip install -r requirements.txt
# 2. Navigate to scripts folder
cd scripts
# 3. Run verification script
python xarray_usage.py
# 4. Run Task 1 (2D Plots)
python task1_2d.py
# 5. Run Task 2 (3D Plots)
python task2_3d.py
A detailed PDF report is available, covering dataset inspection, code logic, plot construction, and verification against marking criteria.
π Read the Report
- Python 3.11
- Xarray β Dataset handling
- NumPy β Numerical operations
- Plotly β 2D & 3D visualization
- netCDF4 β Dataset backend
- Pandas - Dataset visualization
| Criterion | Status | Implementation |
|---|---|---|
| Correct node coordinates | β | Imported directly from node.py |
| Correct element connectivity | β | Imported directly from element.py |
| Sign convention preserved | β | No manual flipping; visualization matches raw data |
| Visual clarity & scaling | β | Proper axes labels, 1.5x Z-expansion, auto-scaling |
| MIDAS-style 3D plots | β | Vertical extrusion + vertical hatching + heat-map colors |
xarray_usage.pyβ Dataset inspectiontask1_2d.pyβ 2D SFD & BMDtask2_3d.pyβ 3D MIDAS-style SFD & BMDnode.py,element.pyβ Structural datascreening_task.ncβ Force datasetSFD_BMD_Report.pdfβ Documentation
This project demonstrates how professional structural post-processingβcommonly available in commercial tools like MIDAS Civilβcan be reproduced using open-source Python libraries, while maintaining engineering correctness, geometric fidelity, and visual clarity.
This project is licensed under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license, as required by FOSSEE for screening task submissions.





