compas-dev / compas-dev/compas

Compas_assembly DEM Viewer division by zero error

Open
#1,100 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
386
Forks
122
Avg merge
11d 46m
Merged PRs (30d)
1

Description

**Describe the bug**
The DEM Viewer throws an error when loading an assembly with null forces, with both CRA solvers.
```

Traceback (most recent call last):
File "d:\10_DEV\CompasWorkshop\mcneel22\RandomWall\02_collectRHgeometry.py", line 88, in
viewer.add_assembly(assembly)
File "C:\Users\Filipe\anaconda3\envs\mcneel22\lib\site-packages\compas_assembly\viewer\app.py", line 224, in add_assembly
resultants += interface.resultantforce
File "C:\Users\Filipe\anaconda3\envs\mcneel22\lib\site-packages\compas_assembly\datastructures\interface.py", line 176, in resultantforce
position = Point(*centroid_points_weighted(self.points, normalcomponents))
File "C:\Users\Filipe\anaconda3\envs\mcneel22\lib\site-packages\compas\geometry\_core\centroids.py", line 163, in centroid_points_weighted
vector = scale_vector(sum_vectors(vectors), 1.0 / sum(weights))
ZeroDivisionError: float division by zero
```

**To Reproduce**
Steps to reproduce the behavior:
1. Creating a block assembly with horizontal interfaces between the blocks in the same row. The sample script assumes a pyramid with 6 bricks.

A sample script that reproduces the error:

```
import os
import compas
from compas.colors import Color
from compas.geometry import Translation
from compas.datastructures import Mesh
from compas_assembly.datastructures import Block
from compas_assembly.datastructures import Assembly
from compas_assembly.algorithms import assembly_interfaces
#from compas_view2.app import App
from compas_assembly.viewer import DEMViewer
from compas_cra.equilibrium import cra_solve

# =============================================================================
# Import
# =============================================================================

filepath = os.path.join(os.path.dirname(__file__), "test.json")

data = compas.json_load(filepath)

boxes = data["blocks"]

# =============================================================================
# Assembly
# =============================================================================

assembly = Assembly()

for box in boxes:
assembly.add_block_from_mesh(Mesh.from_shape(box))

# =============================================================================
# Identify interfaces
# =============================================================================

# inputs = the assembly, maximum distance and minimum area
assembly_interfaces(assembly, tmax=0.001, amin=1e-4)

# =============================================================================
# Boundary conditions
# =============================================================================

assembly.unset_boundary_conditions()

nodes = sorted(assembly.nodes(), key=lambda node: assembly.node_point(node).z)
for node in nodes[:3]:
assembly.set_boundary_condition(node)

# =============================================================================
# Equilibrium
# =============================================================================

cra_solve(assembly)

# =============================================================================
# Viz
# =============================================================================

viewer = DEMViewer()
viewer.view.camera.position = [0, -5, 5]
viewer.view.camera.look_at([0, 0, 3])

viewer.add_assembly(assembly)

viewer.run()
```

3. Sample data

```
{
"blocks": [
{
"dtype": "compas.geometry/Box",
"value": {
"ysize": 0.11,
"xsize": 0.22500000000000001,
"frame": {
"yaxis": [
0.0,
1.0,
0.0
],
"xaxis": [
1.0,
0.0,
0.0
],
"point": [
0.1125,
0.055,
0.040000000000000001
]
},
"zsize": 0.080000000000000002
},
"guid": "4a5f13d4-b563-4aca-83d5-b29437820e82"
},
{
"dtype": "compas.geometry/Box",
"value": {
"ysize": 0.11,
"xsize": 0.22500000000000001,
"frame": {
"yaxis": [
0.0,
1.0,
0.0
],
"xaxis": [
1.0,
0.0,
0.0
],
"point": [
0.33750000000000002,
0.055,
0.040000000000000001
]
},
"zsize": 0.080000000000000002
},
"guid": "d47b2b74-b0b4-4fe0-8516-ffe9572554b3"
},
{
"dtype": "compas.geometry/Box",
"value": {
"ysize": 0.11,
"xsize": 0.22500000000000003,
"frame": {
"yaxis": [
0.0,
1.0,
0.0
],
"xaxis": [
1.0,
0.0,
0.0
],
"point": [
0.22500000000000001,
0.055,
0.12
]
},
"zsize": 0.080000000000000002
},
"guid": "6d213422-febb-4a1d-8b3d-4222198c3fe7"
},
{
"dtype": "compas.geometry/Box",
"value": {
"ysize": 0.11,
"xsize": 0.22500000000000003,
"frame": {
"yaxis": [
0.0,
1.0,
0.0
],
"xaxis": [
1.0,
0.0,
0.0
],
"point": [
0.5625,
0.055,
0.040000000000000001
]
},
"zsize": 0.080000000000000002
},
"guid": "0b1183b1-8490-494f-bc01-e7da073acdab"
},
{
"dtype": "compas.geometry/Box",
"value": {
"ysize": 0.11,
"xsize": 0.22500000000000001,
"frame": {
"yaxis": [
0.0,
1.0,
0.0
],
"xaxis": [
1.0,
0.0,
0.0
],
"point": [
0.33750000000000002,
0.055,
0.20000000000000001
]
},
"zsize": 0.079999999999999988
},
"guid": "744d59fa-0d83-4c0b-a973-64983f601bf4"
},
{
"dtype": "compas.geometry/Box",
"value": {
"ysize": 0.11,
"xsize": 0.22499999999999998,
"frame": {
"yaxis": [
0.0,
1.0,
0.0
],
"xaxis": [
1.0,
0.0,
0.0
],
"point": [
0.45000000000000001,
0.055,
0.12000000000144742
]
},
"zsize": 0.080000000000000016
},
"guid": "c37b7266-8459-4562-aa10-1e980b51bf4e"
}
]
}
```

**Expected behavior**
Zero forces should not be displayed

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: Windows / Mac
- Python version: 3.9.13
- Python package manager: pip

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.