models.grain¶
Grain geometry and regression model. The Grain class is a container that holds one or more GrainSegment instances (potentially of different geometries) and aggregates burn area, propellant mass, CoG, and moment of inertia across all segments at any web regression distance.
Each segment exposes a common interface: get_burn_area(), get_port_area(), get_volume(), get_web_thickness(), get_center_of_gravity(), and get_moment_of_inertia(). Surface inhibition is controlled per-segment via InhibitedSurfaces.
Submodules:
- geometries — Concrete grain segment types (BATES, tubular, star, D-grain, conical, etc.)
- fmm — Fast Marching Method base classes for complex cross-sections
machwave.models.grain
¶
Grain
¶
Source code in machwave/models/grain/base.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
segment_count
property
¶
Returns the number of segments in the grain.
:rtype: int
total_length
property
¶
Calculates total length of the grain.
Example: - 1 segment of 0.5 m length -> total length = 0.5 m - 2 segments of 0.5 m length with 0.1 m spacing -> total length = 1.1 m - 3 segments of 0.5 m length with 0.1 m spacing -> total length = 1.7 m
:rtype: float
__init__(spacing=0.0)
¶
Initialize a grain assembly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spacing
|
float
|
Distance between segments in meters. Default is 0.0 (no spacing). |
0.0
|
Source code in machwave/models/grain/base.py
add_segment(new_segment)
¶
Adds a new segment to the grain.
:param GrainSegment new_segment: The new segment to be added :rtype: None :raises Exceptiom: If the new_segment is not valid
Source code in machwave/models/grain/base.py
get_burn_area(web_distance)
¶
Calculates the BATES burn area given the web distance.
:param float web_distance: Instant web thickness value :return float: Instant burn area, in m^2 and in function of web :rtype: float
Source code in machwave/models/grain/base.py
get_center_of_gravity(web_distance)
¶
Calculates the center of gravity of the grain.
Takes the mass-weighted average of all segment centers of gravity, accounting for varying density ratios and spacing between segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_distance
|
float
|
Web distance traveled [m]. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
A 1D array of shape (3,) representing the [x, y, z] coordinates |
NDArray[float64]
|
of the center of gravity [m]. Origin is at the port of the grain |
NDArray[float64]
|
(closest to nozzle), with positive x pointing toward bulkhead. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no segments are found in the grain. |
Source code in machwave/models/grain/base.py
get_effective_density_ratio(*, web_distance)
¶
Return an effective (burn-area weighted) density ratio.
Used for gas generation terms where \(\dot{m} \propto A_b r \rho_p\).
Source code in machwave/models/grain/base.py
get_mass_flux_per_segment(burn_rate, ideal_density, web_distance)
¶
Returns a numpy multidimensional array with the mass flux for each grain.
Source code in machwave/models/grain/base.py
get_moment_of_inertia(ideal_density, web_distance=0.0)
¶
Combines the inertia tensors of all grain segments using the parallel axis theorem, accounting for varying density ratios and spacing between segments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ideal_density
|
float
|
Propellant ideal density [kg/m^3]. |
required |
web_distance
|
float
|
Web distance traveled [m]. |
0.0
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
A 3x3 inertia tensor [kg-m^2] at the grain's center of gravity: [[Ixx, Ixy, Ixz], [Ixy, Iyy, Iyz], [Ixz, Iyz, Izz]] |
NDArray[float64]
|
Coordinate system: Origin at grain's center of gravity, with: |
NDArray[float64]
|
|
NDArray[float64]
|
|
NDArray[float64]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no segments are found in the grain. |
Source code in machwave/models/grain/base.py
get_propellant_mass(*, web_distance, ideal_density)
¶
Return remaining propellant mass [kg] at a given web distance.
Source code in machwave/models/grain/base.py
get_propellant_volume(web_distance)
¶
Calculates the BATES grain volume given the web distance.
:param float web_distance: Instant web thickness value :return: Instant propellant volume, in m^3 and in function of web :rtype: float
Source code in machwave/models/grain/base.py
get_real_density(*, web_distance, ideal_density)
¶
Return grain effective real propellant density [kg/m^3].
Source code in machwave/models/grain/base.py
get_segment_mismatches()
¶
Return per-attribute descriptions of where segments diverge. Uses first segment as a reference.
Returns:
| Type | Description |
|---|---|
list[str]
|
One description per divergent (segment, attribute) pair. |
Source code in machwave/models/grain/base.py
GrainSegment
¶
Bases: ABC
Represents a grain segment.
Source code in machwave/models/grain/base.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
get_burn_area(web_distance)
abstractmethod
¶
Calculates burn area in function of the web distance traveled.
:param float web_distance: Web distance traveled :return: Burn area in function of the web distance traveled :rtype: float
Source code in machwave/models/grain/base.py
get_center_of_gravity(*args, **kwargs)
abstractmethod
¶
Calculates the center of gravity of the segment.
The coordinate system origin is at the port, closest to the nozzle, with positive x-direction pointing toward the bulkhead.
:return: The center of gravity of the segment [x, y, z] in meters :rtype: np.typing.NDArray[np.float64]
Source code in machwave/models/grain/base.py
get_mass(web_distance, ideal_density)
¶
Calculates the mass of the segment at a given web distance.
:param float web_distance: Web distance traveled [m] :param float ideal_density: Ideal propellant density [kg/m^3] :return: Mass of the segment at the given web distance [kg] :rtype: float
Source code in machwave/models/grain/base.py
get_moment_of_inertia(*args, **kwargs)
abstractmethod
¶
Calculates the moment of inertia tensor of the segment at its center of gravity.
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
A 3x3 array representing the inertia tensor [kg-m^2] with components: [[Ixx, Ixy, Ixz], [Iyx, Iyy, Iyz], [Izx, Izy, Izz]] |
Source code in machwave/models/grain/base.py
get_port_area(web_distance, *args, **kwargs)
abstractmethod
¶
Calculates the port area as a function of the web distance traveled.
This method assumes a 2D or simplified model where the port area can be represented by a single scalar value at a given web distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_distance
|
float
|
Distance traveled into the grain web. |
required |
*args
|
Any
|
Additional positional arguments. |
()
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
float
|
A float representing the port area. |
Source code in machwave/models/grain/base.py
get_volume(web_distance)
abstractmethod
¶
Calculates volume in function of the web distance traveled.
:param float web_distance: Web distance traveled :return: Segment volume in function of the instant web thickness :rtype: float
Source code in machwave/models/grain/base.py
get_web_thickness()
abstractmethod
¶
Calculates the total web thickness of the segment.
:return: The total web thickness of the segment :rtype: float
validate()
¶
Validates grain geometry. For every attribute that a child class adds, it must be validated here.
Source code in machwave/models/grain/base.py
GrainSegment2D
¶
Bases: GrainSegment, ABC
Class that represents a 2D grain segment.
A 2D grain segment is a segment that has the same cross sectional geometry throughout its length.
Some examples of 2D grain geometries: - BATES - Tubular - Pseudo-finocyl
Source code in machwave/models/grain/base.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
get_core_area(web_distance)
abstractmethod
¶
Calculates the core area in function of the web distance traveled.
Example: In a simple tubular geometry, the core area would be equal to the instant length of the segment times the instant core area.
Not to be confused with port area!
:param float web_distance: Web distance traveled :return: Core area in function of the web distance traveled :rtype: float
Source code in machwave/models/grain/base.py
get_face_area(web_distance)
abstractmethod
¶
Calculates the face area in function of the web distance traveled.
Example: In a simple tubular geometry, the face area would be equal to the outer diameter area minus the instantaneous core diameter area.
:param float web_distance: Web distance traveled :return: Face area in function of the web distance traveled :rtype: float
Source code in machwave/models/grain/base.py
GrainSegment3D
¶
Bases: GrainSegment, ABC
Class that represents a 3D grain segment.
Some examples of 3D grain geometries: - Conical - Finocyl
Source code in machwave/models/grain/base.py
get_length(web_distance)
¶
NOTE: Modify later.
Source code in machwave/models/grain/base.py
get_port_area(web_distance, z)
abstractmethod
¶
Calculates the port area as a function of the web distance traveled and a specified height (z).
NOTE: This method is not implemented.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_distance
|
float
|
The distance traveled into the grain web. |
required |
z
|
float
|
The axial position (height) along the grain. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The port area at the given web distance and height. |
Source code in machwave/models/grain/base.py
InhibitedSurfaces
dataclass
¶
Describes which surfaces of a grain segment are inhibited.
Attributes:
| Name | Type | Description |
|---|---|---|
outer_surface |
bool
|
If True, the outer cylindrical surface is inhibited. |
inner_surface |
bool
|
If True, the inner surface is inhibited. |
upper_end |
bool
|
If True, the upper end (towards bulkhead) face is inhibited. |
lower_end |
bool
|
If True, the lower end (towards nozzle) face is inhibited. |