Skip to content

Commit

Permalink
Complete refactor (#46)
Browse files Browse the repository at this point in the history
* Added some test meshes

* reading nastran BC from bdf file

* Big file reorganisation

* Moving things around

* Increase max file size limit

* add meshio as dependency

* rename nastranMeshReader file for consistency

* Start on model class

* Made a start on the model class

* Started on a new element base class

* array dimensions are confusing

* A little progress on the model class

* More element development

* Starting to write down some theory

* Testing more things

* Finished example runscript

* Modify model class to use baseclasses

* Added some more TODO's

* defining DOF and assembling K matrix

* small updates

* Add some assembly utility functions

* Adding functionality to AssembleUtils

* Alis work

* create output mesh object - modifications

* Some more element work

* New element tests are passing

* Ali + Jasmin's work

* Some more of Jasmin's work

* Started on base constitutive class

* Jasmin work

* Alis work

* Alis work

* Sajas work

* Minor updates

* Element residual computation done (maybe)

* New changes

* ISO stress functions

* Strain sensitivities and test functions

* Alis work

* Make linAlg routines work with arbitrary size arrays

* Fix error in routines for getting gauss integration points/weights

* Lot's of fixes, residual computation is correctly returning zeros

* Jasmin's work

* Rejigged the residual computation

* Jasmin's work

* fix some bugs in the model class

* Fix some more bugs in the model class

* Jacobian product

* Jasmin's work and Quad L Beam mesh

* testing model

* Trying to figure out Residual Jacobian computation

* Fix faulty einsum in stress calculation

* Stiffness matrix calculation seems to be working!

* Removing old element and constitutive classes

* add TODO

* It runs, but I don't know if it's right

* Trying to make BC application faster

* Revert "Trying to make BC application faster"

This reverts commit d07995f.

* Fix some errors in BC, add tests for basic problem setup and solution

* Add Residual Jacobian tests to element test

* Got example runscript working

* Remove some old files

* Implemented 2D triangular element, closest point search not working properly, removed some old files

* [pre-commit.ci lite] apply automatic fixes

* remove python 3.7 support

* Fix some testing issues

* update code climate settings

* SMall fix for IsoPlaneStrain Von Mises calculation

* Fix bug in 2nd order Tri element node ordering

* Fix tri element ascii art

* Fix 9 node quad element node ordering

* Add 3d lagrange polynomials

* Fix 3rd order quad node ordering

* Add test for element coordinate interpolation

* un-comment getClosestPoints test

* Comment out model tests that don't work yet

* re-enable the get closest points test

* Run example problem with Tri elements

* Fix ordering of higher order tri element nodes, to match meshio

* Rejig model test, rename testAssembly to testProblem

* Jasmin's work, element/problem computeFunctions

* [pre-commit.ci lite] apply automatic fixes

* Jasmin's work - test for computeFunction

* [pre-commit.ci lite] apply automatic fixes

* Add constitutive model functions to solution file

* Remove unneeded mesh processing stuff

* Remove a bunch of stuff so that the docs build

* Trying to fix docs build

* more fixes

* Add density to IsoPlaneStrain

* Updating IPE figures

* Jasmin's work - presentation live demo jupyter notebook

* Jasmin's work - Presentation Live Demo jupyter notebook

* More presentation figures

* Some inconsequential changes

* Adding more docstrings

* Lets be very strict about docstrings

* Fix interrogate settings in pre-commit

* Ignore flake8 config file

* Trying to address some code climate complaints

* Cleaning up some docstrings

* Switch back from code climate to codecov

* covergae fix

* Cleanup examples

* Add CI jobs for benchmarks and examples

* oops, numba doesn't like python 3.11

* typos

* Fix non-editable install

* Change example output

* Add testflo dependency for benchmarks action

* Add constitutive model unit tests

* Getting some documentation working again

* FOrmatting comments for the docs

* Cleaning up some docstrings for documentation

* Improved efficiency of boundary condition application

* make problem solve method return timing data

* Turn LinAlg benchmarks into separate cases

* Add quad mesh benchmark case

* Remove plotting imports from quad mesh benchmark

* Import paramaterized for benchmarking github action

* Would be great if I could spell

* Print some nice output after benchmarking

* Got 3D hex elements working!

* add hex elements to docs

* Remove hydrofoil example from repo

* So much speeeeeeed!

* More performance optimization

* Jasmin's work - scaling study on new FEMpy

* [pre-commit.ci lite] apply automatic fixes

* Extremely important modification

* More parallelisation

* Jasmin's work - scaling study

* [pre-commit.ci lite] apply automatic fixes

* Jasmin's work - scaling study

* [pre-commit.ci lite] apply automatic fixes

* Updating theory figures used in NERS report

* Add 3D constitutive model to unit tests

* mesh convergence study for a cantilever beam

* mesh convergence study minor edits

* minor fix

* removing matplotlib

* removing niceplots

* minor error fix in the code

* Fix some docstrings

* Update readme

* Update docs homepage

* Add von mises figure to readme

* typo

* Remove a bunch of stuff from the Benchmarks folder

* Update quad mesh scaling plotting script

* Readme tweak

* Don't need requirements.txt files any more

* Hopefully now we don't need requiremenets.txt

* Switch to using numpy's default_rng for consistent random number generation in tests

* Include cantilever benchmark in CI

* Make validation separate step

Co-authored-by: arshsaja <[email protected]>
Co-authored-by: jasminlim-simba <[email protected]>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed Dec 15, 2022
1 parent f0f4d4a commit e29ffd3
Show file tree
Hide file tree
Showing 124 changed files with 89,476 additions and 2,810 deletions.
28 changes: 0 additions & 28 deletions .codeclimate.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
codecov:
disable_default_path_fixes: false

coverage:
status:
project:
default:
threshold: 1%
patch:
default:
target: auto
comment:
require_changes: true
8 changes: 0 additions & 8 deletions .deepsource.toml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/Benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run benchmarks

on:
push:
branches: [ main ]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- python-version: "3.8"
- python-version: "3.9"
- python-version: "3.10"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: setup.py
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Run performance benchmarks
run: |
cd Examples/Benchmarks
testflo -n 1 -v --benchmark .
python formatBenchmarkData.py
python CantileverValidation.py
- name: Run validation benchmarks
run: |
cd Examples/Benchmarks
python CantileverValidation.py
34 changes: 34 additions & 0 deletions .github/workflows/Examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Run examples

on:
push:
branches: [ main ]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- python-version: "3.8"
- python-version: "3.9"
- python-version: "3.10"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: setup.py
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
- name: Run examples
run: |
set -e
cd Examples
for f in *.py; do python "$f"; done
14 changes: 7 additions & 7 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
strategy:
matrix:
include:
- python-version: "3.7"
- python-version: "3.8"
- python-version: "3.9"
- python-version: "3.10"
Expand All @@ -22,6 +21,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: setup.py
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -36,12 +36,12 @@ jobs:
run: |
export NUMBA_DISABLE_JIT=1
testflo -n 1 -v --coverage --coverpkg FEMpy .
coverage xml
- name: Upload coverage to Code Climate
- name: Upload coverage to Codecov
if: ${{ matrix.python-version == 3.10}}
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_COVERAGE_ID }}
uses: codecov/codecov-action@v3
with:
debug: true
coverageCommand: coverage xml
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: setup.py
- run: |
python -m pip install --upgrade pip
python3 -m pip install -r ./requirements.txt
python3 -m pip install -e .
python3 -m pip install -e .[docs]
- name: Build Docs
run: mkdocs build -f docs/mkdocs.yml
Expand Down
20 changes: 18 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Gauss quadrature pkl files
Gauss*.pkl
# Ignore images, except those in the docs
*.png
*.pdf
!docs/docs/Images/**.png
!docs/docs/Images/**.pdf
**.autosave.ipe

# Ignore examples results files
Examples/ExampleOutput
*.vtk
*.vtu
*.dat

# Ignore testflo benchmark data
**benchmark_data.csv

# Ignore flake 8 config
.flake8

# Profiling files
*.prof
Expand Down
15 changes: 9 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
args: ['--maxkb=5000']
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-added-large-files
- id: mixed-line-ending
- id: check-merge-conflict
- id: debug-statements
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3
args: ["-l", "120", "--target-version", "py37", "--target-version", "py38", "--target-version", "py39", "--target-version", "py310"]
args: ["-l", "120", "--target-version", "py38", "--target-version", "py39", "--target-version", "py310"]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/econchick/interrogate
rev: 1.5.0
hooks:
- id: interrogate
args: ["-I", "--fail-under=100", "--ignore-nested-functions", "-vv"]
exclude: ^(docs|setup.py|tests|Examples|.*__init__.py)
7 changes: 0 additions & 7 deletions Dockerfile

This file was deleted.

107 changes: 107 additions & 0 deletions Examples/Benchmarks/CantileverValidation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""
==============================================================================
FEMpy cantilever beam validation case
==============================================================================
@Description : This file contains a simple 2D validation case where we compare
FEMpy against the analytical solution for a cantilevel beam subject to a uniform
load.
"""

# ==============================================================================
# Standard Python modules
# ==============================================================================

from numba import njit

# ==============================================================================
# External Python modules
# ==============================================================================
import numpy as np
import FEMpy as fp


# ==============================================================================
# Extension modules
# ==============================================================================


@njit(cache=True)
def warpFunc(x, y):
return x, 0.02 * y


# @njit( cache=True)
def createGridMesh(nx, ny, warpFunc=None):
xNodes = np.tile(np.linspace(0.0, 1.0, nx + 1), ny + 1)
yNodes = np.repeat(np.linspace(0.0, 1.0, ny + 1), nx + 1)

# Warp the mesh
if warpFunc is not None:
xNodes, yNodes = warpFunc(xNodes, yNodes)

# Create Connectivity matrix
numEl = nx * ny
conn = np.zeros((numEl, 4), dtype=int)
conn[:, 0] = np.tile(np.arange(nx), ny) + np.repeat((nx + 1) * np.arange(ny), nx) # Lower left
conn[:, 1] = conn[:, 0] + 1 # lower right
conn[:, 2] = conn[:, 1] + nx + 1 # upper right
conn[:, 3] = conn[:, 2] - 1 # upper left

return np.array([xNodes, yNodes]).T, conn


if __name__ == "__main__":
refineVal = [1, 2, 4, 8, 16, 32, 64]
Error = []
numDOF = []
meshSize = []
for refine in refineVal:

# create constitutive model
con = fp.Constitutive.IsoPlaneStrain(E=70e9, nu=0.0, t=1.0, rho=2700.0)

# create mesh
nodeCoords, conn = createGridMesh(10 * refine, 1 * refine, warpFunc=warpFunc)
conn = {"quad": conn}

# create model
model = fp.FEMpyModel(con, nodeCoords=nodeCoords, connectivity=conn, options={"outputFormat": ".dat"})
prob = model.addProblem("Static")

# Find the right, left and top edges
rightEdgeNodeInds = np.argwhere(nodeCoords[:, 0] == 1.0).flatten()
topEdgeNodeInds = np.argwhere(nodeCoords[:, 1] == np.max(nodeCoords[:, 1])).flatten()
leftEdgeNodeInds = np.argwhere(nodeCoords[:, 0] == 0.0).flatten()

# apply BCs
prob.addFixedBCToNodes("Fixed", leftEdgeNodeInds, dof=[0, 1], value=0.0)
prob.addLoadToNodes("Load", topEdgeNodeInds, dof=[1], value=-(10**3), totalLoad=True)

# Calculate analytic displacement
momInertia = 1 / 12 * 0.02**3
dmax_analytic = 10**3 / (8 * 70e9 * momInertia)

# solve the problem
prob.solve()
prob.writeSolution(baseName="mesh%s.dat" % refine)

# average the vertical displacements along the tip of the beam and compute the error
averageDisplacement = np.average(prob.states[rightEdgeNodeInds, 1])
Error.append(np.abs(-averageDisplacement - dmax_analytic))
numDOF.append(prob.numDOF)
meshSize.append(1 / np.sqrt(numDOF[-1]))

# Print the results
Error = np.array(Error)
numDOF = np.array(numDOF)
meshSize = np.array(meshSize)
print("======================================")
print("Cantilever Beam Validation Results")
print("======================================")
print("| num DOF | Error |")
for i in range(len(Error)):
print(f"|{numDOF[i]:>10} | {Error[i]:11.6e} |")
print("=====================================")

logFitCoeff = np.polyfit(np.log(meshSize[-3:]), np.log(Error[-3:]), 1)
print(f"Displacement error convergence Rate: {logFitCoeff[0]}")
45 changes: 0 additions & 45 deletions Examples/Benchmarks/LinAlg.py

This file was deleted.

Loading

0 comments on commit e29ffd3

Please sign in to comment.