Skip to content

Commit 14dcb32

Browse files
committed
Initial commit
0 parents  commit 14dcb32

19 files changed

+1390
-0
lines changed

.github/.workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Python FastAPI CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
# Check out the code from the repository
17+
- name: Check out code
18+
uses: actions/checkout@v3
19+
20+
# Set up Python environment
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.7' # Or whichever version your project requires
25+
26+
# Install dependencies
27+
- name: Install dependencies
28+
run: |
29+
python -m venv venv
30+
source venv/bin/activate
31+
pip install --upgrade pip
32+
pip install -r requirements.txt
33+
34+
# Run tests
35+
- name: Run tests
36+
run: |
37+
source venv/bin/activate
38+
PYTHONPATH=./ pytest

.gitignore

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Virtual Environment
10+
venv/
11+
env/
12+
ENV/
13+
.venv/
14+
15+
# VS Code settings
16+
.vscode/
17+
.code-workspace
18+
19+
# Test cache, coverage, and logs
20+
.pytest_cache/
21+
.coverage
22+
coverage.xml
23+
*.cover
24+
*.log
25+
.cache
26+
nosetests.xml
27+
coverage/
28+
htmlcov/
29+
.tox/
30+
.junit/
31+
32+
# Distribution / packaging
33+
.Python
34+
build/
35+
develop-eggs/
36+
dist/
37+
downloads/
38+
eggs/
39+
.eggs/
40+
lib/
41+
lib64/
42+
parts/
43+
sdist/
44+
var/
45+
wheels/
46+
pip-wheel-metadata/
47+
share/python-wheels/
48+
*.egg-info/
49+
.installed.cfg
50+
51+
# Installer logs
52+
pip-log.txt
53+
pip-delete-this-directory.txt
54+
55+
# MacOS specific files
56+
.DS_Store
57+
58+
# Temporary files and backups
59+
*.bak
60+
*.swp
61+
*.tmp
62+
*~
63+
64+
# Python virtual environment
65+
# Ignore this folder since you already have venv
66+
venv/
67+
68+
# Environment Variables
69+
.env
70+
.env.*
71+
72+
# Fastlane
73+
fastlane/report.xml
74+
fastlane/Preview.html
75+
fastlane/screenshots/**/*.png
76+
fastlane/test_output/
77+
78+
# JetBrains IDEs (optional, if using)
79+
.idea/
80+
*.iml

README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# SwiftComp-API
2+
3+
**SwiftComp-API** is a FastAPI-based backend designed to perform calculations related to composite laminate materials. It exposes various endpoints for computing engineering constants, plate properties, 3D laminate properties, and more. This API is suitable for researchers, engineers, and developers working in composite materials and structural analysis.
4+
5+
## Table of Contents
6+
7+
- [Features](#features)
8+
- [Technologies](#technologies)
9+
- [Installation](#installation)
10+
- [API Documentation](#api-documentation)
11+
- [Testing](#testing)
12+
- [Contributing](#contributing)
13+
- [License](#license)
14+
15+
---
16+
17+
## Features
18+
19+
- **Versioned API:** Support for multiple versions of the API, with versioning (v1, v2) for backward compatibility.
20+
- **Material Property Calculations:** Endpoints to calculate various laminate engineering constants and composite properties.
21+
- **Lightweight & Fast:** Built using FastAPI, ensuring high performance and minimal latency.
22+
- **Modular Architecture:** Separation of concerns using routers, services, and utility functions for better maintainability.
23+
- **Extensible:** Easy to add new endpoints and services for additional material computations.
24+
25+
---
26+
27+
## Technologies
28+
29+
- **FastAPI**: A modern, fast (high-performance) web framework for building APIs with Python 3.7+ based on standard Python-type hints.
30+
- **Python 3.7**: Programming language used to implement the logic.
31+
- **Pytest**: A robust testing framework for Python.
32+
- **Uvicorn**: ASGI server used for serving FastAPI applications.
33+
- **Virtual Environment (venv)**: For dependency isolation.
34+
35+
---
36+
37+
## Installation
38+
39+
To set up the project locally, follow these steps:
40+
41+
### Prerequisites
42+
- Python 3.7 or higher.
43+
- Git installed on your system.
44+
45+
### Step-by-Step Guide
46+
47+
1. **Clone the repository**:
48+
```bash
49+
git clone https://github.com/wenbinyugroup/swiftcomp-api.git
50+
cd swiftcomp-api
51+
```
52+
53+
2. **Create and activate a virtual environment**:
54+
```bash
55+
python -m venv venv
56+
source venv/bin/activate # On Windows: venv\Scripts\activate
57+
```
58+
59+
3. **Install the dependencies**:
60+
```bash
61+
pip install -r requirements.txt
62+
```
63+
64+
4. **Run the FastAPI application locally**:
65+
```bash
66+
uvicorn app.main:app --reload
67+
```
68+
69+
This will start the SwiftComp API server at http://127.0.0.1:8000.
70+
71+
## API Documentation
72+
FastAPI automatically generates interactive API documentation using **Swagger** and **Redoc**. Once the server is running, you can access the documentation at:
73+
74+
* Swagger UI: http://127.0.0.1:8000/docs
75+
* ReDoc: http://127.0.0.1:8000/redoc
76+
77+
## Sample Endpoints
78+
* **GET /**: Root endpoint, returns a welcome message.
79+
* **POST /api/v1/lamina_engineering_constants**: Calculates the lamina engineering constants based on the provided material properties.
80+
* **POST /api/v1/laminate_plate_properties**: Calculates the laminate plate properties.
81+
* **POST /api/v1/laminate_3d_properties**: Computes the 3D properties of laminate.
82+
* **POST /api/v1/udfrc_properties**: Calculates UDFRC properties.
83+
84+
## Testing
85+
The repository includes unit tests using `pytest`. To run the tests:
86+
87+
1. Ensure you are in the virtual environment.
88+
2. Run the following command:
89+
```bash
90+
PYTHONPATH=./ pytest
91+
```
92+
93+
## Contributing
94+
We welcome contributions to **SwiftComp-API**! Here's how you can help:
95+
96+
1. **Fork the repository**.
97+
2. **Create a new feature branch**:
98+
```bash
99+
git checkout -b feature/your-feature-name
100+
```
101+
3. **Commit your changes**:
102+
```bash
103+
git commit -m "Add your message"
104+
```
105+
4. **Push to the branch**:
106+
```bash
107+
git push origin feature/your-feature-name
108+
```
109+
5. **Create a pull request**: Describe the changes you’ve made.
110+
111+
112+
## License
113+
This project is licensed under the MIT License. See the LICENSE file for more details.

app/__init__.py

Whitespace-only changes.

app/main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from fastapi import FastAPI
2+
3+
from app.routers.v1.lamina_engineering_constants import router as lamina_engineering_constants_router_v1
4+
from app.routers.v1.laminate_plate_properties import router as laminate_plate_properties_router_v1
5+
from app.routers.v1.laminate_3d_properties import router as laminate_3d_properties_router_v1
6+
from app.routers.v1.UDFRC_properties import router as udfrc_properties_router_v1
7+
8+
app = FastAPI()
9+
10+
@app.get("/")
11+
def read_root():
12+
return {"message": "Hello SwiftComp API"}
13+
14+
app.include_router(lamina_engineering_constants_router_v1, prefix="/api/v1")
15+
app.include_router(laminate_plate_properties_router_v1, prefix="/api/v1")
16+
app.include_router(laminate_3d_properties_router_v1, prefix="/api/v1")
17+
app.include_router(udfrc_properties_router_v1, prefix="/api/v1")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pydantic import BaseModel, Field
2+
3+
# Request Model
4+
class Laminate3DPropertiesInput(BaseModel):
5+
E1: float = Field(..., gt=0, description="Longitudinal modulus of the laminate (must be greater than 0).")
6+
E2: float = Field(..., gt=0, description="Transverse modulus of the laminate (must be greater than 0).")
7+
G12: float = Field(..., gt=0, description="In-plane shear modulus of the laminate (must be greater than 0).")
8+
nu12: float = Field(..., ge=-1, le=0.5, description="Poisson's ratio in the laminate plane (must be between -1 and 0.5).")
9+
nu23: float = Field(..., ge=-1, le=0.5, description="Poisson's ratio in the transverse plane (must be between -1 and 0.5).")
10+
layup_sequence: str = Field(..., description="Layup sequence of the laminate (e.g., '[30/45]2s').")
11+
layer_thickness: float = Field(..., gt=0, description="Thickness of each laminate layer (must be greater than 0).")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pydantic import BaseModel, Field
2+
3+
# Request Model
4+
class LaminatePlatePropertiesInput(BaseModel):
5+
E1: float = Field(..., gt=0, description="Longitudinal modulus of the laminate (must be greater than 0).")
6+
E2: float = Field(..., gt=0, description="Transverse modulus of the laminate (must be greater than 0).")
7+
G12: float = Field(..., gt=0, description="In-plane shear modulus of the laminate (must be greater than 0).")
8+
nu12: float = Field(..., ge=-1, le=0.5, description="Poisson's ratio in the laminate plane (must be between -1 and 0.5).")
9+
layup_sequence: str = Field(..., description="Layup sequence of the laminate (e.g., '[30/45]2s').")
10+
layer_thickness: float = Field(..., gt=0, description="Thickness of each laminate layer (must be greater than 0).")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pydantic import BaseModel, Field
2+
from typing import List
3+
4+
# Model for the engineering constants
5+
class EngineeringConstants(BaseModel):
6+
E1: float
7+
E2: float
8+
E3: float
9+
G12: float
10+
G13: float
11+
G23: float
12+
nu12: float
13+
nu13: float
14+
nu23: float
15+
16+
# Model for Voigt, Reuss, Hybrid rules of mixture
17+
class ThreeDimensionalPropertiesOutput(BaseModel):
18+
Effective_3D_Stiffness_Matrix: List[List[float]] = Field(..., description="Effective 3D stiffness matrix (6x6).")
19+
Effective_3D_Compliance_Matrix: List[List[float]] = Field(..., description="Effective 3D compliance matrix (6x6).")
20+
Engineering_Constants: EngineeringConstants = Field(..., description="Engineering constants.")

0 commit comments

Comments
 (0)