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
Binary file added docs/figures/density_sensitivity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/modal_frequencies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/section_height_sensitivity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/thickness_sensitivity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/figures/youngs_modulus_sensitivity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/validation/density_sensitivity.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameter_value,mode_1_frequency_hz
6280.0,55.23184
7065.0,52.07308
7850.0,49.40086
8635.0,47.10187
9420.0,45.09661
11 changes: 11 additions & 0 deletions docs/validation/modal_frequencies.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mode,frequency_hz
1,49.40086
2,84.15125
3,305.2293
4,506.5651
5,692.4157
6,836.315
7,1292.885
8,1339.754
9,1591.106
10,2078.087
6 changes: 6 additions & 0 deletions docs/validation/section_height_sensitivity.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameter_value,mode_1_frequency_hz
0.032,40.01148
0.036000000000000004,44.74873
0.04,49.40086
0.044000000000000004,53.97453
0.048,58.47559
6 changes: 6 additions & 0 deletions docs/validation/thickness_sensitivity.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameter_value,mode_1_frequency_hz
0.0012000000000000001,49.76519
0.00135,49.58304
0.0015,49.40086
0.0016500000000000002,49.21864
0.0018,49.03639
6 changes: 6 additions & 0 deletions docs/validation/youngs_modulus_sensitivity.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameter_value,mode_1_frequency_hz
168000000000.0,44.18547
189000000000.0,46.86577
210000000000.0,49.40086
231000000000.00003,51.81206
252000000000.0,54.11593
113 changes: 113 additions & 0 deletions scripts/run_modal_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import csv
from pathlib import Path

import matplotlib.pyplot as plt

from bodysimpy.analysis.modal_validation import (
validate_modal_response,
)
from bodysimpy.config.loader import load_config
from bodysimpy.modeling.crossmember import (
build_crossmember_model,
)


def main() -> None:
config = load_config("configs/baseline_crossmember.yaml")

model = build_crossmember_model(config)

result = validate_modal_response(
model,
modes=10,
)

table_path = Path("docs/validation/modal_frequencies.csv")

table_path.parent.mkdir(
parents=True,
exist_ok=True,
)

with table_path.open(
"w",
encoding="utf-8",
newline="",
) as stream:
writer = csv.writer(stream)

writer.writerow(
[
"mode",
"frequency_hz",
]
)

for mode, frequency in enumerate(
result.fea_frequencies_hz,
start=1,
):
writer.writerow(
[
mode,
frequency,
]
)

modes = list(
range(
1,
len(result.fea_frequencies_hz) + 1,
)
)

figure_path = Path("docs/figures/modal_frequencies.png")

figure_path.parent.mkdir(
parents=True,
exist_ok=True,
)

plt.figure(figsize=(8, 5))

plt.plot(
modes,
result.fea_frequencies_hz,
marker="o",
)

plt.xlabel("Mode number")
plt.ylabel("Natural frequency [Hz]")
plt.title("BodySimPy Baseline Natural Frequencies")

plt.xticks(modes)
plt.grid(True)
plt.tight_layout()

plt.savefig(
figure_path,
dpi=200,
)

plt.close()

print()
print("BodySimPy Modal Analysis")
print("-" * 55)

for mode, frequency in enumerate(
result.fea_frequencies_hz,
start=1,
):
print(f"Mode {mode:>2}: {frequency:>12.4f} Hz")

print()
print(f"Analytical mode 1: {result.analytical_mode_1_hz:.4f} Hz")

print(f"FEA mode 1: {result.fea_mode_1_hz:.4f} Hz")

print(f"Mode-1 error: {result.mode_1_error_percent:.4f} %")


if __name__ == "__main__":
main()
145 changes: 145 additions & 0 deletions scripts/run_modal_sensitivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import csv
from pathlib import Path

import matplotlib.pyplot as plt

from bodysimpy.analysis.modal_sensitivity import (
ModalSensitivityPoint,
density_sensitivity,
section_height_sensitivity,
thickness_sensitivity,
youngs_modulus_sensitivity,
)
from bodysimpy.config.loader import load_config
from bodysimpy.modeling.crossmember import (
build_crossmember_model,
)

MULTIPLIERS = (
0.8,
0.9,
1.0,
1.1,
1.2,
)


def write_study(
*,
name: str,
x_label: str,
points: tuple[ModalSensitivityPoint, ...],
scale: float,
) -> None:
csv_path = Path(f"docs/validation/{name}_sensitivity.csv")

csv_path.parent.mkdir(
parents=True,
exist_ok=True,
)

with csv_path.open(
"w",
encoding="utf-8",
newline="",
) as stream:
writer = csv.writer(stream)

writer.writerow(
[
"parameter_value",
"mode_1_frequency_hz",
]
)

for point in points:
writer.writerow(
[
point.parameter_value,
point.mode_1_frequency_hz,
]
)

x_values = [point.parameter_value * scale for point in points]

frequencies = [point.mode_1_frequency_hz for point in points]

figure_path = Path(f"docs/figures/{name}_sensitivity.png")

figure_path.parent.mkdir(
parents=True,
exist_ok=True,
)

plt.figure(figsize=(7, 5))

plt.plot(
x_values,
frequencies,
marker="o",
)

plt.xlabel(x_label)
plt.ylabel("Mode-1 natural frequency [Hz]")

plt.title(f"Mode-1 Sensitivity — {name.replace('_', ' ').title()}")

plt.grid(True)
plt.tight_layout()

plt.savefig(
figure_path,
dpi=200,
)

plt.close()


def main() -> None:
config = load_config("configs/baseline_crossmember.yaml")

model = build_crossmember_model(config)

write_study(
name="thickness",
x_label="Wall thickness [mm]",
points=thickness_sensitivity(
model,
multipliers=MULTIPLIERS,
),
scale=1000.0,
)

write_study(
name="youngs_modulus",
x_label="Young's modulus [GPa]",
points=youngs_modulus_sensitivity(
model,
multipliers=MULTIPLIERS,
),
scale=1e-9,
)

write_study(
name="density",
x_label="Density [kg/m³]",
points=density_sensitivity(
model,
multipliers=MULTIPLIERS,
),
scale=1.0,
)

write_study(
name="section_height",
x_label="Section height [mm]",
points=section_height_sensitivity(
model,
multipliers=MULTIPLIERS,
),
scale=1000.0,
)


if __name__ == "__main__":
main()
Loading