Skip to content

Commit

Permalink
Add test and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyikillua committed Aug 15, 2019
1 parent 5835c34 commit 93a994d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 17 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python

python:
- "3.6"

install:
- pip3 install .

script:
- cd test
- pytest --cov ddtruss

after_success:
- codecov
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

This repository provides a Python implementation of the data-driven solver for truss structures described in [Kirchdoerfer, T., & Ortiz, M. (2016). Data-driven computational mechanics. Computer Methods in Applied Mechanics and Engineering, 304, 81-101](https://www.sciencedirect.com/science/article/pii/S0045782516300238).

<p align="center">
<img src="https://user-images.githubusercontent.com/4027283/63096980-9561cb00-bf6f-11e9-88a7-d07081138f19.png" width="800">
</p>
![](https://user-images.githubusercontent.com/4027283/63096980-9561cb00-bf6f-11e9-88a7-d07081138f19.png)

Some notebook examples can be found in `examples`.

Expand Down
2 changes: 1 addition & 1 deletion ddtruss/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def solve(self, A=1, U_dict={}, F_dict={}, n_iterations=100, E_num=None):
Args
----
A : float
A : float or ndarray, shape (n_lines, )
Cross section area
U_dict : dict
Prescribed displacement ``{point_id: (Ux, Uy), ...}``
Expand Down
33 changes: 20 additions & 13 deletions examples/example.ipynb

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions test/test_truss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import numpy as np
import pytest

from ddtruss import Truss, DataDrivenSolver

points = np.array([[0, 0], [1, 0], [0.5, 0.5], [2, 1]])
lines = np.array([[0, 2], [1, 2], [1, 3], [2, 3]], dtype=int)

truss = Truss(points, lines)

E = 1.962e11
A = [2e-4, 2e-4, 1e-4, 1e-4]
U_dict = {0: [0, 0], 1: [0, 0]}
F_dict = {3: [0, -9.81e3]}

u_ref = np.array(
[0, 0, 0, 0, 2.65165043e-4, 8.83883476e-5, 3.47902545e-3, -5.60034579e-3]
)


def test_truss():
u, *_ = truss.solve(A=A, E=E, U_dict=U_dict, F_dict=F_dict)
assert np.allclose(u, u_ref)


@pytest.mark.parametrize(
"n_data", [5000, 10000]
)
def test_data_driven_solver(n_data):
ddsolver = DataDrivenSolver(truss)

eps_max = 1.1e-3
eps = np.linspace(-eps_max, eps_max, n_data)
sig = E * eps
material_data = np.hstack([eps.reshape((-1, 1)), sig.reshape((-1, 1))])
ddsolver.load_material_data(material_data)

u, *_ = ddsolver.solve(A=A, U_dict=U_dict, F_dict=F_dict)
assert np.allclose(u, u_ref, rtol=1e-2)

0 comments on commit 93a994d

Please sign in to comment.