models.propulsion.grain.fmm¶
machwave.models.propulsion.grain.fmm
¶
This module contains classes that model grain geometries using the Fast Marching Method (FMM). Both 2D and 3D geometries are supported, along with STL files.
References: https://math.berkeley.edu/~sethian/2006/Explanations/fast_marching_explain.html
FMMGrainSegment
¶
Bases: GrainSegment, ABC
Fast Marching Method (FMM) implementation of a grain segment.
This class was inspired by the Andrew Reilley's software openMotor, in particular the fmm module. openMotor's repository can be accessed at: https://github.com/reilleya/openMotor
Source code in machwave/models/propulsion/grain/fmm/base.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 181 182 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 | |
denormalize(value)
¶
Converts a normalized input value into an actual dimension based on the object's outer diameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int | float | NDArray[float64]
|
A numeric value representing a normalized quantity. |
required |
Returns:
| Type | Description |
|---|---|
float | NDArray[float64]
|
The denormalized value as a float, calculated by scaling |
float | NDArray[float64]
|
the object's outer diameter. |
Source code in machwave/models/propulsion/grain/fmm/base.py
get_cell_size()
¶
Return the size of each grid cell in normalized coordinates.
The value is derived by taking 1 divided by the map dimension.
get_contours(web_distance, *args, **kwargs)
abstractmethod
¶
Return the contours of the regression map after a specified web distance.
This method must be implemented by a subclass to compute the contour data based on the given web distance and any additional parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_distance
|
float
|
The depth of regression into the grain web. |
required |
*args
|
Additional positional arguments. |
()
|
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
list[NDArray[float64]]
|
An array representing the computed contours of the grain regression. |
Source code in machwave/models/propulsion/grain/fmm/base.py
get_empty_face_map()
¶
Return a new face map consisting entirely of ones.
The shape of the array matches the first element in the object's stored maps.
Source code in machwave/models/propulsion/grain/fmm/base.py
get_face_map(web_distance)
¶
Returns a matrix representing the grain face based on the given web distance.
The returned array can contain: -1 for masked or invalid points, 0 for points below the threshold, 1 for points above the threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_distance
|
float
|
The distance traveled into the grain web. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int64]
|
A NumPy array with -1, 0, or 1 indicating the grain face at the specified web distance. |
Source code in machwave/models/propulsion/grain/fmm/base.py
get_initial_face_map()
abstractmethod
¶
get_maps()
abstractmethod
¶
get_mask()
abstractmethod
¶
get_masked_face()
¶
Return a masked representation of the face map.
The mask is circular and normalized to the map dimensions. If a mask has not been created yet, it is generated by combining the initial face map with the circular mask.
Source code in machwave/models/propulsion/grain/fmm/base.py
get_regression_map()
¶
Calculate and return the distance map for grain regression.
This uses the fast marching method (scikit-fmm) on the masked face. Each value represents the distance from the initial face along the cross-section of the grain.
Source code in machwave/models/propulsion/grain/fmm/base.py
get_web_thickness()
¶
Return the maximum thickness of the grain web in real units.
The web thickness is the largest distance from the center of the grain segment, derived from the distance map and converted to a real-world measurement.
Source code in machwave/models/propulsion/grain/fmm/base.py
map_to_area(value)
¶
Convert a pixel-area value into square meters.
The conversion is based on the ratio of this object's outer diameter (squared) to the total pixel map dimension (squared).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float | NDArray[float64]
|
The area in pixel units. |
required |
Returns:
| Type | Description |
|---|---|
float | NDArray[float64]
|
The corresponding area in square meters. |
Source code in machwave/models/propulsion/grain/fmm/base.py
map_to_length(value)
¶
Convert a pixel-distance value into meters.
The conversion is based on the ratio of this object's outer diameter to its total map dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float | NDArray[float64]
|
The distance in pixel units. |
required |
Returns:
| Type | Description |
|---|---|
float | NDArray[float64]
|
The corresponding distance in meters. |
Source code in machwave/models/propulsion/grain/fmm/base.py
normalize(value)
¶
Converts a raw dimensional value into a normalized scale based on the object's outer diameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int | float
|
The dimensional value (e.g., length) to normalize. |
required |
Returns:
| Type | Description |
|---|---|
float
|
A float representing the dimension as a fraction of the object's |
float
|
half-diameter. |
Source code in machwave/models/propulsion/grain/fmm/base.py
validate()
¶
Validates the internal geometry of the grain.
This method ensures the grain map dimension meets the minimum required size. If validation fails, a GrainGeometryError is raised.
Raises:
| Type | Description |
|---|---|
GrainGeometryError
|
If the grain map dimension is below the valid threshold. |
Source code in machwave/models/propulsion/grain/fmm/base.py
FMMGrainSegment2D
¶
Bases: FMMGrainSegment, GrainSegment2D, ABC
Fast Marching Method (FMM) implementation for 2D grain segment.
This class was inspired by Andrew Reilley's openMotor software, in particular the fmm module. See: https://github.com/reilleya/openMotor
Source code in machwave/models/propulsion/grain/fmm/_2d.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 181 182 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 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 | |
get_burn_area(web_distance)
¶
Return burn area [m^2] at a given web distance.
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_burn_area_interp_func()
¶
Return a cached interpolator for burn area [m^2] vs normalized web.
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_center_of_gravity(web_distance)
¶
Calculates the center of gravity of a 2D FMM grain segment at a web distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_distance
|
float
|
Web distance traveled [m]. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Center of gravity [x, y, z] in meters from the port of the segment. |
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_contours(web_distance)
¶
Return a list of contour arrays for the given web distance. Each contour is typically an (N,2) array of (row, col) points.
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_core_area(web_distance)
¶
Calculate the core (internal) area at the given web distance by multiplying perimeter by grain segment length (a 2D approximation).
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_core_perimeter(web_distance)
¶
Return the perimeter of the open core at the given web distance.
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_face_area(web_distance)
¶
Return the face area at the given web distance.
get_face_area_interp_func()
¶
Build and return an interpolation function that, given a normalized web distance, returns the face area in square meters.
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_maps()
¶
Return a tuple of two 2D arrays (map_x, map_y). Each is of shape (map_dim, map_dim), ranging from -1 to 1.
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_mask()
¶
Return a boolean mask indicating which points lie outside the unit circle.
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_moment_of_inertia(ideal_density, web_distance=0.0)
¶
Calculate the moment of inertia tensor at the segment's its center of gravity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_distance
|
float
|
Web distance traveled [m]. |
0.0
|
ideal_density
|
float
|
Propellant ideal density [kg/m³]. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
A 3x3 inertia tensor [kg-m^2]. |
Source code in machwave/models/propulsion/grain/fmm/_2d.py
get_port_area(web_distance)
¶
Return the grain's port area (open cross-sectional area) at the given web distance. Could be a scalar or array, depending on how the computations are done.
Source code in machwave/models/propulsion/grain/fmm/_2d.py
FMMGrainSegment3D
¶
Bases: FMMGrainSegment, GrainSegment3D, ABC
Fast Marching Method (FMM) implementation for 3D grain segment.
This class was inspired by the Andrew Reilley's software openMotor, in particular the fmm module. openMotor's repository can be accessed at: https://github.com/reilleya/openMotor
Source code in machwave/models/propulsion/grain/fmm/_3d.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 181 182 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
get_burn_area_interp_func()
¶
Return a cached interpolator for burn area [m^2] vs normalized web.
Source code in machwave/models/propulsion/grain/fmm/_3d.py
get_center_of_gravity(web_distance)
¶
Calculates the center of gravity of a 3D FMM grain segment at a web distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_distance
|
float
|
Web distance traveled [m]. |
required |
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
Center of gravity [z, x, y] in meters from the port of the segment. |
Raises:
| Type | Description |
|---|---|
GrainGeometryError
|
If web distance exceeds the web thickness, or if no active material is found. |
Source code in machwave/models/propulsion/grain/fmm/_3d.py
get_moment_of_inertia(ideal_density, web_distance=0.0)
¶
Calculate the moment of inertia tensor at the segment's its center of gravity.
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]. |
Raises:
| Type | Description |
|---|---|
GrainGeometryError
|
If web distance exceeds web thickness or if no active material is found. |
Source code in machwave/models/propulsion/grain/fmm/_3d.py
get_port_area(web_distance, z)
¶
Calculates the port area at a given web distance and axial height z.
This method extracts a single 2D slice from the 3D face map by converting the physical height z into an integer index, and then computes the port area for that slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_distance
|
float
|
The distance traveled into the grain web. |
required |
z
|
float
|
Axial position (in meters) along the grain, where z=0 is the top and z=self.length is the bottom (or vice versa, depending on geometry setup). |
required |
Returns:
| Type | Description |
|---|---|
float
|
A float representing the port area at the specified z slice, in m². |
Source code in machwave/models/propulsion/grain/fmm/_3d.py
FMMSTLGrainSegment
¶
Bases: FMMGrainSegment3D, ABC
Fast Marching Method (FMM) implementation for a grain segment obtained from an STL file.
Source code in machwave/models/propulsion/grain/fmm/stl.py
get_initial_face_map()
¶
Generate a map by voxelizing an STL file. Uses trimesh library.
NOTE: Still needs to convert boolean matrix to masked array.
Source code in machwave/models/propulsion/grain/fmm/stl.py
get_voxel_size()
¶
NOTE: Only returns correct voxel size if map_dim is an odd number.
:return: the voxel edge size. :rtype: float