Skip to content

Commit e677a10

Browse files
fix: Reaction calculation (#7)
1 parent 45a6c10 commit e677a10

13 files changed

Lines changed: 99 additions & 163 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,34 @@ name: Python package
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [master]
99
pull_request:
10-
branches: [ master ]
10+
branches: [master]
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615
strategy:
1716
matrix:
18-
python-version: ["^3.6", "^3.7", "^3.8", "^3.9", "^3.10"]
17+
python-version: ['^3.9', '^3.10', '^3.11', '^3.12']
1918

2019
steps:
21-
- uses: actions/checkout@v2
22-
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
24-
with:
25-
python-version: ${{ matrix.python-version }}
26-
- name: Install dependencies
27-
run: |
28-
python -m pip install --upgrade pip
29-
pip install flake8 pytest
30-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31-
- name: Lint with flake8
32-
run: |
33-
# stop the build if there are Python syntax errors or undefined names
34-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
35-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
36-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
37-
- name: Test with pytest
38-
run: |
39-
pytest
20+
- uses: actions/checkout@v2
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install flake8
29+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
30+
- name: Lint with flake8
31+
run: |
32+
# stop the build if there are Python syntax errors or undefined names
33+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
34+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
35+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
36+
- name: Test with unittest
37+
run: |
38+
python -m unittest discover -p '*_test.py'

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ __pycache__/
77

88
# truss structure solution
99
result.svg
10-
result.txt
10+
result.txt
11+
12+
node_modules/
13+
.svelte-kit

.vscode/settings.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
"[python]": {
44
"editor.defaultFormatter": "charliermarsh.ruff",
55
"editor.codeActionsOnSave": {
6-
"source.fixAll": true,
7-
"source.organizeImports": true
6+
"source.fixAll": "explicit",
7+
"source.organizeImports": "explicit"
88
}
9-
}
9+
},
10+
"python.testing.unittestArgs": ["-v", "-s", ".", "-p", "*_test.py"],
11+
"python.testing.pytestEnabled": false,
12+
"python.testing.unittestEnabled": true
1013
}

geom2d/vector.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ def __eq__(self, other):
216216
def __str__(self):
217217
return f"({self.u}, {self.v}) with norm {self.norm}"
218218

219+
def __repr__(self):
220+
return str(self)
221+
219222
def to_formatted_str(self, decimals: int):
220223
"""
221224
Returns a string of the form: '(u, v) with norm N', where

graphic/simulation/draw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import reduce
22
from tkinter import Canvas
33

4-
from geom2d import Circle, Polygon, Segment, Rect, AffineTransform
4+
from geom2d import AffineTransform, Circle, Polygon, Rect, Segment
55

66

77
class CanvasDrawing:

run_tests.sh

100644100755
File mode changed.

structures/model/bar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from eqs import Matrix
22
from geom2d import Segment
3-
from .node import StrNode
3+
from structures.model.node import StrNode
44

55

66
class StrBar:

structures/model/structure.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
from eqs import Vector as EqVector
66
from eqs import cholesky_solve
77
from geom2d import Vector
8+
from structures.model.bar import StrBar
9+
from structures.model.node import StrNode
810
from structures.solution.bar import StrBarSolution
911
from structures.solution.node import StrNodeSolution
1012
from structures.solution.structure import StructureSolution
1113

12-
from .bar import StrBar
13-
from .node import StrNode
14-
1514

1615
class Structure:
1716
"""

structures/solution/node.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ def is_constrained(self):
4444
self.__original_node.dx_constrained or self.__original_node.dy_constrained
4545
)
4646

47+
@property
48+
def dx_constrained(self) -> bool:
49+
return self.__original_node.dx_constrained
50+
51+
@property
52+
def dy_constrained(self) -> bool:
53+
return self.__original_node.dy_constrained
54+
4755
@property
4856
def loads(self):
4957
"""

structures/solution/structure.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def bounds_rect(self, margin: float, scale=1):
3535
d_pos = [node.displaced_pos_scaled(scale) for node in self.nodes]
3636
return make_rect_containing_with_margin(d_pos, margin)
3737

38-
def reaction_for_node(self, node: StrNodeSolution):
38+
def reaction_for_node(self, node: StrNodeSolution) -> Vector:
3939
"""
4040
Computes the external reaction force for a given node.
4141
@@ -57,4 +57,10 @@ def reaction_for_node(self, node: StrNodeSolution):
5757
if node.is_loaded:
5858
forces.append(node.net_load.opposite())
5959

60-
return reduce(operator.add, forces)
60+
net_force = reduce(operator.add, forces)
61+
62+
# The reaction can only have the components of the constrained directions
63+
return Vector(
64+
u=net_force.u if node.dx_constrained else 0.0,
65+
v=net_force.v if node.dy_constrained else 0.0,
66+
)

0 commit comments

Comments
 (0)