Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ Before considering a change complete, the project should pass:
ruff format --check .
ruff check .
mypy src
python -m pytest
python -m pytest
```
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:
- name: Upgrade pip
run: python -m pip install --upgrade pip

- name: Install PyTorch
- name: Install PyTorch
run: >
python -m pip install torch
--index-url https://download.pytorch.org/whl/cpu

- name: Install CalculiX
run: |
sudo apt-get update
Expand Down
505 changes: 373 additions & 132 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/ai_assisted_development.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ The accepted implementation was verified using:
ruff format --check .
ruff check .
mypy src
python -m pytest
python -m pytest
```
9 changes: 9 additions & 0 deletions src/bodysimpy/analysis/stochastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class DistributionSummary:
percentile_5: float
percentile_95: float

@property
def coefficient_of_variation_percent(self) -> float:
"""Return the sample coefficient of variation as a percentage."""

if self.mean == 0.0:
raise ValueError("Coefficient of variation is undefined for a zero mean.")

return abs(self.standard_deviation / self.mean) * 100.0


@dataclass(frozen=True, slots=True)
class SensitivityCoefficient:
Expand Down
4 changes: 2 additions & 2 deletions src/bodysimpy/domain/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def __post_init__(self) -> None:
if self.youngs_modulus_pa <= 0.0:
raise ValueError("Young's modulus must be positive.")

if not 0.0 < self.poisson_ratio < 0.5:
raise ValueError("Poisson ratio must be between 0 and 0.5.")
if not -1.0 < self.poisson_ratio < 0.5:
raise ValueError("Poisson ratio must be between -1.0 and 0.5.")

if self.density_kg_m3 <= 0.0:
raise ValueError("Density must be positive.")
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_crossmember_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,33 @@ def test_build_crossmember_model() -> None:
assert model.material.youngs_modulus_pa == pytest.approx(210e9)
assert model.tip_force_n == pytest.approx(1000.0)
assert model.mesh_elements == 20


def test_build_crossmember_model_accepts_valid_negative_poisson_ratio() -> None:
config = SimulationConfig.model_validate(
{
"project": {"name": "auxetic_crossmember"},
"geometry": {
"type": "rectangular_hollow_section",
"length_m": 1.0,
"width_m": 0.080,
"height_m": 0.040,
"thickness_m": 0.0015,
},
"material": {
"youngs_modulus_pa": 210e9,
"poisson_ratio": -0.20,
"density_kg_m3": 7850.0,
},
"loading": {"tip_force_n": 1000.0},
"mesh": {"elements": 20},
"analysis": {
"static": True,
"modal": {"modes": 10},
},
}
)

model = build_crossmember_model(config)

assert model.material.poisson_ratio == pytest.approx(-0.20)
19 changes: 19 additions & 0 deletions tests/unit/test_stochastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ def test_distribution_summary() -> None:

assert summary.percentile_95 > summary.mean

assert summary.coefficient_of_variation_percent == pytest.approx(
summary.standard_deviation / summary.mean * 100.0
)


def test_distribution_summary_rejects_zero_mean_cov() -> None:
values = np.array(
[
-1.0,
1.0,
],
dtype=float,
)

summary = summarize_distribution(values)

with pytest.raises(ValueError, match="zero mean"):
_ = summary.coefficient_of_variation_percent


def test_stochastic_inputs_are_reproducible() -> None:
config = build_stochastic_config()
Expand Down