Skip to content

Commit 3bb2604

Browse files
committed
notebooks
1 parent f2d069f commit 3bb2604

File tree

5 files changed

+577
-0
lines changed

5 files changed

+577
-0
lines changed

notebooks/dem_arch.ipynb

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# DEM of a Semi-circular Arch"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"## Block Model from Arch Template"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 20,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"from compas_dem.models import BlockModel\n",
24+
"from compas_dem.templates import ArchTemplate\n",
25+
"\n",
26+
"template = ArchTemplate(rise=3, span=10, thickness=0.3, depth=0.5, n=30)\n",
27+
"\n",
28+
"model = BlockModel.from_template(template)"
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"## Contacts and Supports"
36+
]
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"metadata": {},
41+
"source": [
42+
"In an arch, every block can have at most two contacts."
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": 21,
48+
"metadata": {},
49+
"outputs": [],
50+
"source": [
51+
"model.compute_contacts(k=2)"
52+
]
53+
},
54+
{
55+
"cell_type": "markdown",
56+
"metadata": {},
57+
"source": [
58+
"The nodes with only one contact are the supports at the ends of the arch."
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 22,
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"from compas_dem.elements import BlockElement\n",
68+
"\n",
69+
"element: BlockElement\n",
70+
"\n",
71+
"for element in model.elements():\n",
72+
" if model.graph.degree(element.graphnode) == 1:\n",
73+
" element.is_support = True"
74+
]
75+
},
76+
{
77+
"cell_type": "markdown",
78+
"metadata": {},
79+
"source": [
80+
"## Visualisation"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": 23,
86+
"metadata": {},
87+
"outputs": [
88+
{
89+
"data": {
90+
"application/vnd.jupyter.widget-view+json": {
91+
"model_id": "d6c18ea737fa4d3e95d09cd82e86f1ea",
92+
"version_major": 2,
93+
"version_minor": 0
94+
},
95+
"text/plain": [
96+
"VBox(children=(HBox(children=(Button(icon='search-plus', layout=Layout(height='32px', width='48px'), style=But…"
97+
]
98+
},
99+
"metadata": {},
100+
"output_type": "display_data"
101+
}
102+
],
103+
"source": [
104+
"from compas.colors import Color\n",
105+
"from compas_notebook import Viewer\n",
106+
"\n",
107+
"viewer = Viewer()\n",
108+
"\n",
109+
"for element in model.elements():\n",
110+
" viewer.scene.add(\n",
111+
" element.modelgeometry,\n",
112+
" show_faces=True if element.is_support else False,\n",
113+
" show_edges=True,\n",
114+
" facecolor=Color.red() if element.is_support else None,\n",
115+
" edgecolor=Color.black()\n",
116+
" )\n",
117+
"\n",
118+
"for contact in model.contacts():\n",
119+
" viewer.scene.add(contact.polygon, color=Color.cyan())\n",
120+
"\n",
121+
"viewer.show()\n",
122+
"\n",
123+
"viewer.camera3.position = [-3, -7, 5]\n",
124+
"viewer.camera3.lookAt([0, 0, 1])"
125+
]
126+
}
127+
],
128+
"metadata": {
129+
"kernelspec": {
130+
"display_name": "masonry",
131+
"language": "python",
132+
"name": "python3"
133+
},
134+
"language_info": {
135+
"codemirror_mode": {
136+
"name": "ipython",
137+
"version": 3
138+
},
139+
"file_extension": ".py",
140+
"mimetype": "text/x-python",
141+
"name": "python",
142+
"nbconvert_exporter": "python",
143+
"pygments_lexer": "ipython3",
144+
"version": "3.10.14"
145+
}
146+
},
147+
"nbformat": 4,
148+
"nbformat_minor": 2
149+
}

notebooks/dem_barrelvault.ipynb

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# DEM of a Barrel Vault"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"## Block Model from a Barrel Vault Template"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 1,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"from compas_dem.models import BlockModel\n",
24+
"from compas_dem.templates import BarrelVaultTemplate\n",
25+
"\n",
26+
"template = BarrelVaultTemplate()\n",
27+
"model = BlockModel.from_barrelvault(template)"
28+
]
29+
},
30+
{
31+
"cell_type": "markdown",
32+
"metadata": {},
33+
"source": [
34+
"## Contacts and Supports"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 2,
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"model.compute_contacts()"
44+
]
45+
},
46+
{
47+
"cell_type": "markdown",
48+
"metadata": {},
49+
"source": [
50+
"## Visualisation"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 3,
56+
"metadata": {},
57+
"outputs": [
58+
{
59+
"data": {
60+
"application/vnd.jupyter.widget-view+json": {
61+
"model_id": "2e2749041fa8464189f51416604aa75b",
62+
"version_major": 2,
63+
"version_minor": 0
64+
},
65+
"text/plain": [
66+
"VBox(children=(HBox(children=(Button(icon='search-plus', layout=Layout(height='32px', width='48px'), style=But…"
67+
]
68+
},
69+
"metadata": {},
70+
"output_type": "display_data"
71+
}
72+
],
73+
"source": [
74+
"from compas.colors import Color\n",
75+
"from compas_notebook import Viewer\n",
76+
"\n",
77+
"viewer = Viewer()\n",
78+
"\n",
79+
"for element in model.elements():\n",
80+
" viewer.scene.add(\n",
81+
" element.modelgeometry,\n",
82+
" show_faces=True if element.is_support else False,\n",
83+
" show_edges=True,\n",
84+
" facecolor=Color.red() if element.is_support else None,\n",
85+
" edgecolor=Color.black()\n",
86+
" )\n",
87+
"\n",
88+
"for contact in model.contacts():\n",
89+
" viewer.scene.add(contact.polygon, color=Color.cyan())\n",
90+
"\n",
91+
"viewer.show()"
92+
]
93+
}
94+
],
95+
"metadata": {
96+
"kernelspec": {
97+
"display_name": "masonry",
98+
"language": "python",
99+
"name": "python3"
100+
},
101+
"language_info": {
102+
"codemirror_mode": {
103+
"name": "ipython",
104+
"version": 3
105+
},
106+
"file_extension": ".py",
107+
"mimetype": "text/x-python",
108+
"name": "python",
109+
"nbconvert_exporter": "python",
110+
"pygments_lexer": "ipython3",
111+
"version": "3.10.14"
112+
}
113+
},
114+
"nbformat": 4,
115+
"nbformat_minor": 2
116+
}

notebooks/dem_crossvault.ipynb

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import pathlib\n",
10+
"\n",
11+
"from compas.datastructures import Mesh\n",
12+
"from compas.files import OBJ\n",
13+
"\n",
14+
"# =============================================================================\n",
15+
"# Data\n",
16+
"# =============================================================================\n",
17+
"\n",
18+
"FILE = pathlib.Path().cwd().parent / \"data\" / \"crossvault.obj\"\n",
19+
"\n",
20+
"obj = OBJ(FILE)\n",
21+
"obj.read()\n",
22+
"\n",
23+
"meshes = []\n",
24+
"for name in obj.objects:\n",
25+
" vertices, faces = obj.objects[name]\n",
26+
" mesh: Mesh = Mesh.from_vertices_and_faces(vertices, faces)\n",
27+
" mesh.scale(0.025, 0.025, 0.025)\n",
28+
" mesh.name = name\n",
29+
" meshes.append(mesh)\n"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"from compas_dem.elements import BlockElement\n",
39+
"from compas_dem.models import BlockModel\n",
40+
"\n",
41+
"model = BlockModel.from_boxes(meshes)"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": null,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"model.compute_contacts(tolerance=1e-3, minimum_area=1e-2)\n",
51+
"\n",
52+
"element: BlockElement\n",
53+
"\n",
54+
"for element in model.elements():\n",
55+
" if model.graph.degree(element.graphnode) == 1:\n",
56+
" element.is_support = True"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"from compas.colors import Color\n",
66+
"from compas_notebook import Viewer\n",
67+
"\n",
68+
"color_support = Color.red()\n",
69+
"color_contact = Color.green()\n",
70+
"\n",
71+
"viewer = Viewer()\n",
72+
"\n",
73+
"for element in model.supports():\n",
74+
" viewer.scene.add(\n",
75+
" element.modelgeometry,\n",
76+
" show_faces=True,\n",
77+
" show_edges=True,\n",
78+
" facecolor=color_support,\n",
79+
" edgecolor=color_support.contrast,\n",
80+
" )\n",
81+
"\n",
82+
"for element in model.blocks():\n",
83+
" viewer.scene.add(\n",
84+
" element.modelgeometry,\n",
85+
" show_faces=False,\n",
86+
" show_edges=True,\n",
87+
" facecolor=None,\n",
88+
" edgecolor=Color.black()\n",
89+
")\n",
90+
"\n",
91+
"for contact in model.contacts():\n",
92+
" viewer.scene.add(\n",
93+
" contact.polygon,\n",
94+
" facecolor=color_contact,\n",
95+
" linecolor=color_contact.contrast,\n",
96+
" show_edges=False,\n",
97+
" )\n",
98+
"\n",
99+
"viewer.show()"
100+
]
101+
}
102+
],
103+
"metadata": {
104+
"kernelspec": {
105+
"display_name": "masonry",
106+
"language": "python",
107+
"name": "python3"
108+
},
109+
"language_info": {
110+
"codemirror_mode": {
111+
"name": "ipython",
112+
"version": 3
113+
},
114+
"file_extension": ".py",
115+
"mimetype": "text/x-python",
116+
"name": "python",
117+
"nbconvert_exporter": "python",
118+
"pygments_lexer": "ipython3",
119+
"version": "3.10.14"
120+
}
121+
},
122+
"nbformat": 4,
123+
"nbformat_minor": 2
124+
}

notebooks/dem_dome.ipynb

Whitespace-only changes.

0 commit comments

Comments
 (0)