![]() |
OpenPFC
0.1.4
Phase Field Crystal simulation framework
|
Demonstration of strong type aliases for geometric quantities. More...
#include <iomanip>#include <iostream>#include <openpfc/core/strong_types.hpp>#include <openpfc/core/types.hpp>
Functions | |
| void | print_domain_info (GridSize size, GridSpacing spacing, PhysicalOrigin origin) |
| Print domain information using strong types. | |
| IndexBounds | calculate_subdomain_bounds (GridSize total_size, LocalOffset local_offset, GridSize local_size) |
| Calculate subdomain bounds using strong types. | |
| PhysicalCoords | index_to_physical (Int3 index, PhysicalOrigin origin, GridSpacing spacing) |
| Map index to physical coordinates. | |
| int | main () |
Demonstration of strong type aliases for geometric quantities.
This example shows how strong types make code more self-documenting and catch argument order mistakes at compile time.
Problem: Raw Int3 and Real3 types don't distinguish between different kinds of geometric quantities:
Solution: Strong types make the distinction explicit:
| IndexBounds calculate_subdomain_bounds | ( | GridSize | total_size, |
| LocalOffset | local_offset, | ||
| GridSize | local_size | ||
| ) |
Calculate subdomain bounds using strong types.
This function demonstrates type safety - you cannot accidentally pass spacing where offset is expected.
| void print_domain_info | ( | GridSize | size, |
| GridSpacing | spacing, | ||
| PhysicalOrigin | origin | ||
| ) |
Print domain information using strong types.
Function signature is self-documenting - no need to check docs to understand what each parameter means.
| size | Grid dimensions |
| spacing | Physical spacing between grid points |
| origin | Physical origin of coordinate system |
