Skip to content

Commit ab384a6

Browse files
committed
added back some of the analysis scripts
1 parent 3021509 commit ab384a6

File tree

5 files changed

+217
-0
lines changed

5 files changed

+217
-0
lines changed

scripts/dem_arch_cra.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Compute the equilibrium of an arch structure using the CRA method.
2+
3+
To run this script, install `compas_dem` and its dependencies using the preconfigured
4+
"dem-dev" environment in the `compas_dem` repo.
5+
6+
$ conda env create -f environment.yml
7+
$ conda activate dem-dev
8+
9+
"""
10+
11+
from compas_dem.analysis.cra import cra_penalty_solve
12+
from compas_dem.models import BlockModel
13+
from compas_dem.templates import ArchTemplate
14+
from compas_dem.viewer import DEMViewer
15+
16+
# =============================================================================
17+
# Template
18+
# =============================================================================
19+
20+
template = ArchTemplate(rise=3, span=10, thickness=0.25, depth=0.5, n=50)
21+
22+
# =============================================================================
23+
# Model and interactions
24+
# =============================================================================
25+
26+
model = BlockModel.from_template(template)
27+
28+
model.compute_contacts(tolerance=0.001)
29+
30+
# =============================================================================
31+
# Supports
32+
# =============================================================================
33+
34+
for element in model.elements():
35+
if model.graph.degree(element.graphnode) == 1:
36+
element.is_support = True
37+
38+
# =============================================================================
39+
# Equilibrium
40+
# =============================================================================
41+
42+
cra_penalty_solve(model)
43+
44+
# =============================================================================
45+
# Viz
46+
# =============================================================================
47+
48+
viewer = DEMViewer(model)
49+
viewer.setup()
50+
viewer.show()

scripts/dem_dome.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import pathlib
2+
3+
import compas
14
from compas.datastructures import Mesh
25
from compas.geometry import SphericalSurface
36

@@ -56,6 +59,8 @@
5659
# Export
5760
# =============================================================================
5861

62+
compas.json_dump(model, pathlib.Path(__file__).parent / "dome.json")
63+
5964
# =============================================================================
6065
# Viz
6166
# =============================================================================

scripts/dem_dome_cra.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Compute the equilibrium of an arch structure using the CRA method.
2+
3+
To run this script, install `compas_dem` and its dependencies using the preconfigured
4+
"dem-dev" environment in the `compas_dem` repo.
5+
6+
$ conda env create -f environment.yml
7+
$ conda activate dem-dev
8+
9+
To generate the input file, run the `dem_dome.py` script first.
10+
11+
"""
12+
13+
import pathlib
14+
15+
import compas
16+
17+
# from compas_dem.analysis.cra import cra_penalty_solve
18+
from compas_dem.analysis.cra import rbe_solve
19+
from compas_dem.elements import Block
20+
from compas_dem.models import BlockModel
21+
from compas_dem.viewer import DEMViewer
22+
23+
# =============================================================================
24+
# Import
25+
# =============================================================================
26+
27+
model: BlockModel = compas.json_load(pathlib.Path(__file__).parent / "dome.json") # type: ignore
28+
29+
# =============================================================================
30+
# Supports
31+
# =============================================================================
32+
33+
bottom: list[Block] = sorted(model.elements(), key=lambda e: e.point.z)[:16]
34+
for block in bottom:
35+
block.is_support = True
36+
37+
# =============================================================================
38+
# Equilibrium
39+
# =============================================================================
40+
41+
# cra_penalty_solve(model)
42+
rbe_solve(model)
43+
44+
# =============================================================================
45+
# Viz
46+
# =============================================================================
47+
48+
viewer = DEMViewer(model)
49+
viewer.setup()
50+
viewer.show()

scripts/dem_stack_cra.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""Compute the equilibrium of an arch structure using the CRA method.
2+
3+
To run this script, install `compas_dem` and its dependencies using the preconfigured
4+
"dem-dev" environment in the `compas_dem` repo.
5+
6+
$ conda env create -f environment.yml
7+
$ conda activate dem-dev
8+
9+
"""
10+
11+
import math
12+
import random
13+
14+
from compas.geometry import Box
15+
16+
from compas_dem.analysis.cra import cra_penalty_solve
17+
from compas_dem.models import BlockModel
18+
from compas_dem.viewer import DEMViewer
19+
20+
# =============================================================================
21+
# Block Geometry
22+
# =============================================================================
23+
24+
box = Box.from_corner_corner_height([0, 0, 0], [1, 1, 0], 1)
25+
26+
blocks: list[Box] = []
27+
for i in range(10):
28+
block: Box = box.copy()
29+
block.translate(
30+
[
31+
random.choice([-0.1, +0.1]) * random.random(),
32+
random.choice([-0.1, +0.1]) * random.random(),
33+
i * box.zsize,
34+
]
35+
)
36+
block.rotate(math.radians(random.choice([-5, +5])), box.frame.zaxis, box.frame.point)
37+
blocks.append(block)
38+
39+
# =============================================================================
40+
# Model and interactions
41+
# =============================================================================
42+
43+
model = BlockModel.from_boxes(blocks)
44+
45+
model.compute_contacts()
46+
47+
# =============================================================================
48+
# Supports
49+
# =============================================================================
50+
51+
bottom = sorted(model.elements(), key=lambda e: e.point.z)[0]
52+
bottom.is_support = True
53+
54+
# =============================================================================
55+
# Equilibrium
56+
# =============================================================================
57+
58+
cra_penalty_solve(model)
59+
60+
for contact in model.contacts():
61+
print(contact.forces)
62+
63+
# =============================================================================
64+
# Viz
65+
# =============================================================================
66+
67+
viewer = DEMViewer(model)
68+
viewer.setup()
69+
viewer.show()

scripts/dem_vault_barrel_cra.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Compute the equilibrium of an arch structure using the CRA method.
2+
3+
To run this script, install `compas_dem` and its dependencies using the preconfigured
4+
"dem-dev" environment in the `compas_dem` repo.
5+
6+
$ conda env create -f environment.yml
7+
$ conda activate dem-dev
8+
9+
"""
10+
11+
from compas_dem.analysis.cra import cra_penalty_solve
12+
from compas_dem.models import BlockModel
13+
from compas_dem.templates import BarrelVaultTemplate
14+
from compas_dem.viewer import DEMViewer
15+
16+
# =============================================================================
17+
# Template
18+
# =============================================================================
19+
20+
template = BarrelVaultTemplate()
21+
22+
# =============================================================================
23+
# Model and interactions
24+
# =============================================================================
25+
26+
model = BlockModel.from_barrelvault(template)
27+
28+
model.compute_contacts(tolerance=0.001)
29+
30+
# =============================================================================
31+
# Equilibrium
32+
# =============================================================================
33+
34+
cra_penalty_solve(model)
35+
36+
# =============================================================================
37+
# Viz
38+
# =============================================================================
39+
40+
viewer = DEMViewer(model)
41+
42+
viewer.setup()
43+
viewer.show()

0 commit comments

Comments
 (0)