![]() |
OpenPFC
0.1.4
Phase Field Crystal simulation framework
|
Example: Defining custom coordinate systems without modifying OpenPFC. More...

Classes | |
| struct | PolarTag |
| Tag for polar coordinate system. More... | |
| struct | PolarCoordinateSystem |
| Polar coordinate system parameters. More... | |
| struct | SphericalTag |
| Tag for spherical coordinate system. More... | |
| struct | SphericalCoordinateSystem |
| Spherical coordinate system parameters. More... | |
Functions | |
| Real3 | polar_to_coords (const PolarCoordinateSystem &cs, const Int3 &indices, const Int3 &size) |
| Int3 | polar_to_indices (const PolarCoordinateSystem &cs, const Real3 &coords, const Int3 &size) |
| Convert Cartesian coordinates to grid indices (Cartesian → Polar) | |
| Real3 | spherical_to_coords (const SphericalCoordinateSystem &cs, const Int3 &indices, const Int3 &size) |
| Spherical → Cartesian coordinate transformation. | |
| Int3 | spherical_to_indices (const SphericalCoordinateSystem &cs, const Real3 &coords, const Int3 &size) |
| Cartesian → Spherical coordinate transformation. | |
| void | example_polar_coordinates () |
| Demonstrate polar coordinate system usage. | |
| void | example_spherical_coordinates () |
| Demonstrate spherical coordinate system usage. | |
| void | show_extension_pattern () |
| Summary of the extension pattern. | |
| int | main () |
Variables | |
| constexpr double | M_PI = 3.14159265358979323846 |
Example: Defining custom coordinate systems without modifying OpenPFC.
This example demonstrates OpenPFC's extensibility by showing how to add custom coordinate systems without modifying the library source code.
We implement two complete coordinate systems:
OpenPFC uses ADL to find coordinate transformation functions. You define functions in your namespace (or pfc namespace), and ADL ensures they're found automatically.
This example proves you can extend OpenPFC without forking or modifying its source code. This is the "laboratory" philosophy in action.
| void example_polar_coordinates | ( | ) |
Demonstrate polar coordinate system usage.
Shows:

| void example_spherical_coordinates | ( | ) |
Demonstrate spherical coordinate system usage.
Shows complete 3D spherical coordinate transformations with verification.

|
inline |
Convert Cartesian coordinates to grid indices (Cartesian → Polar)
Inverse transformation of polar_to_coords().
Given Cartesian coordinates (x, y, z):
| cs | Polar coordinate system |
| coords | Cartesian coordinates (x, y, z) |
| size | Grid dimensions [n_r, n_θ, 1] |

| void show_extension_pattern | ( | ) |
Summary of the extension pattern.
Shows the complete recipe for adding custom coordinate systems.
|
inline |
Spherical → Cartesian coordinate transformation.
Transforms grid indices in spherical coordinates to Cartesian (x,y,z).
Transformation:
| cs | Spherical coordinate system |
| indices | Grid indices (i_r, i_theta, i_phi) |
| size | Grid dimensions [n_r, n_θ, n_φ] |
Special points:

|
inline |
Cartesian → Spherical coordinate transformation.
Inverse of spherical_to_coords().
Transformation:
| cs | Spherical coordinate system |
| coords | Cartesian coordinates (x, y, z) |
| size | Grid dimensions [n_r, n_theta, n_phi] |
