A Python-based finite element analysis tool for simulating mechanical behavior of composite materials with periodic boundary conditions.
- 2D linear elastic analysis
- Periodic boundary conditions
- Multi-phase material support
- Adaptive mesh generation
- Numerical stability handling
- Visualization of results
- Python 3.8+
- Rye package manager
Clone repository git clone https://github.com/yourusername/finite-element-composite.git cd finite-element-composite Install dependencies rye sync Structure
├── src/
│ ├── mechanics/ # Material properties and constitutive models
│ │ └── material.py
│ ├── mesh/ # Mesh generation and processing
│ │ └── mesh_generator.py
│ └── solver/ # Finite element solver implementation
│ └── fem_solver.py
├── main.py # Main simulation workflow
├── CONFIG # Simulation parameters
└── requirements.txt # Dependency list
Edit main.py to modify simulation parameters:
CONFIG = {
"length": 1.0, # Domain size (meters)
"nx": 60, # Mesh density (elements per side)
"inclusions": 2, # Number of inclusions
"radius": 0.2, # Inclusion radius (meters)
"material_props": {
"E": [1e9, 50e9], # Young's modulus values (Pa)
"nu": [0.25, 0.3] # Poisson's ratios
},
"applied_force": 5e4, # Applied tensile force (N)
"plane_stress": True # Analysis type
}# Run main simulation
python main.py
# Expected output:
# - Material phase visualization
# - Displacement contour plot
# - Deformed mesh visualization
# - Console output with numerical diagnostics- Implements plane stress/strain constitutive laws
- Validates material properties
- Calculates Lame parameters
- Generates constitutive matrices
- Generates structured quadrilateral meshes
- Calculates element areas and centroids
- Identifies boundary nodes
- Creates degree-of-freedom mapping
- Assembles global stiffness matrix
- Implements periodic boundary conditions
- Solves linear systems with regularization
- Handles numerical stability issues
The simulation generates three plots:
- Material phase distribution
- Displacement magnitude contour
- Deformed mesh configuration
Common issues and solutions:
Q: Getting NaN values in displacement results
- Verify material properties are physically valid
- Check boundary condition constraints
- Reduce applied load magnitude
Q: Mesh quality warnings
- Increase mesh density (
nxin CONFIG) - Check inclusion radius vs domain size
Q: Singular matrix errors
- Confirm proper boundary constraints
- Enable plane stress condition
- Increase regularization in solver
MIT License - See LICENSE for details.
