|
| 1 | +"""pytest benchmark configurations.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Callable |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from sectionproperties.pre import Geometry, Material |
| 10 | +from sectionproperties.pre.library import ( |
| 11 | + circular_hollow_section, |
| 12 | + circular_section, |
| 13 | + concrete_column_section, |
| 14 | + rectangular_section, |
| 15 | +) |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture |
| 19 | +def concrete() -> Material: |
| 20 | + """Creates a concrete material object. |
| 21 | +
|
| 22 | + Returns: |
| 23 | + Concrete |
| 24 | + """ |
| 25 | + return Material( |
| 26 | + name="Concrete", |
| 27 | + elastic_modulus=30.1e3, |
| 28 | + poissons_ratio=0.2, |
| 29 | + yield_strength=32, |
| 30 | + density=2.4e-6, |
| 31 | + color="lightgrey", |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +@pytest.fixture |
| 36 | +def steel() -> Material: |
| 37 | + """Creates a steel material object. |
| 38 | +
|
| 39 | + Returns: |
| 40 | + Steel |
| 41 | + """ |
| 42 | + return Material( |
| 43 | + name="Steel", |
| 44 | + elastic_modulus=200e3, |
| 45 | + poissons_ratio=0.3, |
| 46 | + yield_strength=500, |
| 47 | + density=7.85e-6, |
| 48 | + color="grey", |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +@pytest.fixture |
| 53 | +def rect_geom() -> Geometry: |
| 54 | + """Creates a rectangular geometry. |
| 55 | +
|
| 56 | + Returns: |
| 57 | + Geometry |
| 58 | + """ |
| 59 | + return rectangular_section(d=100, b=50) |
| 60 | + |
| 61 | + |
| 62 | +@pytest.fixture |
| 63 | +def chs_geom() -> Geometry: |
| 64 | + """Creates a rectangular geometry. |
| 65 | +
|
| 66 | + Returns: |
| 67 | + Geometry |
| 68 | + """ |
| 69 | + return circular_hollow_section(d=100, t=3, n=128) |
| 70 | + |
| 71 | + |
| 72 | +@pytest.fixture |
| 73 | +def concrete_column_with_hole(concrete, steel) -> Callable: |
| 74 | + """Creates a concrete column with a hole at its centre. |
| 75 | +
|
| 76 | + Args: |
| 77 | + concrete: Concrete material |
| 78 | + steel: Steel material |
| 79 | +
|
| 80 | + Returns: |
| 81 | + Generator function |
| 82 | + """ |
| 83 | + |
| 84 | + def _generate_geom() -> Geometry: |
| 85 | + geom = concrete_column_section( |
| 86 | + d=600, |
| 87 | + b=300, |
| 88 | + dia_bar=25, |
| 89 | + area_bar=500, |
| 90 | + n_x=3, |
| 91 | + n_y=6, |
| 92 | + cover=35, |
| 93 | + n_circle=4, |
| 94 | + filled=False, |
| 95 | + conc_mat=concrete, |
| 96 | + steel_mat=steel, |
| 97 | + ) |
| 98 | + hole = circular_section(d=100, n=32).shift_section(x_offset=150, y_offset=300) |
| 99 | + |
| 100 | + return geom - hole |
| 101 | + |
| 102 | + return _generate_geom |
| 103 | + |
| 104 | + |
| 105 | +@pytest.fixture |
| 106 | +def analysis_geometry() -> Callable: |
| 107 | + """Create a geometry to be used for analysis. |
| 108 | +
|
| 109 | + Returns: |
| 110 | + Generator function |
| 111 | + """ |
| 112 | + |
| 113 | + def _generate_geom(num_elements: int) -> Geometry: |
| 114 | + mat_a = Material("a", 1, 0, 1, 1, color="b") |
| 115 | + mat_b = Material("b", 10, 0, 1, 1, color="g") |
| 116 | + mat_c = Material("c", 5, 0, 1, 1, color="r") |
| 117 | + mat_d = Material("d", 2, 0, 1, 1, color="y") |
| 118 | + |
| 119 | + a = rectangular_section(20, 20, mat_a) |
| 120 | + b = rectangular_section(20, 20, mat_b).align_to(a, "right") |
| 121 | + c = rectangular_section(20, 20, mat_c).align_to(a, "top") |
| 122 | + d = rectangular_section(20, 20, mat_d).align_to(a, "top").align_to(a, "right") |
| 123 | + geom = a + b + c + d |
| 124 | + mesh_area = geom.calculate_area() / num_elements * 1.6 |
| 125 | + return geom.create_mesh([mesh_area]) |
| 126 | + |
| 127 | + return _generate_geom |
0 commit comments