|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <string> |
| 4 | +#include <vector> |
| 5 | +#include <tuple> |
| 6 | +#include <array> |
| 7 | +#include <utility> |
| 8 | +#include <stdexcept> |
| 9 | + |
| 10 | +// Uses your existing types |
| 11 | +// enum class BoundaryCondition { Zero, Symmetric, AntiSymmetric }; |
| 12 | +// class Boundaries { public: BoundaryCondition left, right, top, bottom; ... }; |
| 13 | + |
| 14 | +class ModeLabeler { |
| 15 | +public: |
| 16 | + ModeLabeler() = default; |
| 17 | + |
| 18 | + std::string get(const Boundaries& boundaries, const size_t mode_number) const |
| 19 | + { |
| 20 | + const BoundaryCondition x_parity = get_parity(boundaries.left, boundaries.right); |
| 21 | + const BoundaryCondition y_parity = get_parity(boundaries.top, boundaries.bottom); |
| 22 | + |
| 23 | + const std::vector<ModeTuple> filtered_modes = get_filtered_mode_list(x_parity, y_parity); |
| 24 | + |
| 25 | + if (mode_number >= filtered_modes.size()) { |
| 26 | + throw std::out_of_range( |
| 27 | + "Mode number " + std::to_string(mode_number) + |
| 28 | + " exceeds available modes. Max allowed: " + |
| 29 | + (filtered_modes.empty() ? std::string("none") : std::to_string(filtered_modes.size() - 1)) |
| 30 | + ); |
| 31 | + } |
| 32 | + |
| 33 | + const auto& [azimuthal, radial, sub_label] = filtered_modes[mode_number]; |
| 34 | + return "LP" + std::to_string(azimuthal) + std::to_string(radial) + sub_label; |
| 35 | + } |
| 36 | + |
| 37 | +private: |
| 38 | + using ModeTuple = std::tuple<int, int, std::string>; |
| 39 | + |
| 40 | + struct ModeEntry { |
| 41 | + int azimuthal; |
| 42 | + int radial; |
| 43 | + std::string sub_label; |
| 44 | + BoundaryCondition x_parity; |
| 45 | + BoundaryCondition y_parity; |
| 46 | + }; |
| 47 | + |
| 48 | +private: |
| 49 | + static BoundaryCondition get_parity( |
| 50 | + const BoundaryCondition boundary_1, |
| 51 | + const BoundaryCondition boundary_2 |
| 52 | + ) { |
| 53 | + if (boundary_1 == BoundaryCondition::Symmetric || boundary_2 == BoundaryCondition::Symmetric) |
| 54 | + return BoundaryCondition::Symmetric; |
| 55 | + |
| 56 | + if (boundary_1 == BoundaryCondition::AntiSymmetric || boundary_2 == BoundaryCondition::AntiSymmetric) |
| 57 | + return BoundaryCondition::AntiSymmetric; |
| 58 | + |
| 59 | + return BoundaryCondition::Zero; |
| 60 | + } |
| 61 | + |
| 62 | + static const std::vector<std::pair<int, int>>& get_azimuthal_radial_pairs() |
| 63 | + { |
| 64 | + static const std::vector<std::pair<int, int>> pairs = { |
| 65 | + {0, 1}, {1, 1}, {2, 1}, {0, 2}, {3, 1}, {1, 2}, {4, 1}, |
| 66 | + {2, 2}, {0, 3}, {5, 1}, {3, 2}, {1, 3}, {6, 1}, |
| 67 | + }; |
| 68 | + return pairs; |
| 69 | + } |
| 70 | + |
| 71 | + static const std::vector<ModeEntry>& get_mode_catalog() |
| 72 | + { |
| 73 | + static const std::vector<ModeEntry> catalog = []() { |
| 74 | + std::vector<ModeEntry> entries; |
| 75 | + entries.reserve(64); |
| 76 | + |
| 77 | + for (const auto& [azimuthal, radial] : get_azimuthal_radial_pairs()) |
| 78 | + { |
| 79 | + std::vector<std::array<BoundaryCondition, 2>> parities; |
| 80 | + std::vector<std::string> sublabels; |
| 81 | + |
| 82 | + if (azimuthal == 0) { |
| 83 | + parities = { {BoundaryCondition::Symmetric, BoundaryCondition::Symmetric} }; |
| 84 | + sublabels = { "" }; |
| 85 | + } |
| 86 | + else if (azimuthal % 2 == 1) { |
| 87 | + parities = { |
| 88 | + {BoundaryCondition::AntiSymmetric, BoundaryCondition::Symmetric}, |
| 89 | + {BoundaryCondition::Symmetric, BoundaryCondition::AntiSymmetric}, |
| 90 | + }; |
| 91 | + sublabels = { "_a", "_b" }; |
| 92 | + } |
| 93 | + else { |
| 94 | + parities = { |
| 95 | + {BoundaryCondition::Symmetric, BoundaryCondition::Symmetric}, |
| 96 | + {BoundaryCondition::AntiSymmetric, BoundaryCondition::AntiSymmetric}, |
| 97 | + }; |
| 98 | + sublabels = { "_a", "_b" }; |
| 99 | + } |
| 100 | + |
| 101 | + for (size_t i = 0; i < parities.size(); ++i) |
| 102 | + { |
| 103 | + ModeEntry entry; |
| 104 | + entry.azimuthal = azimuthal; |
| 105 | + entry.radial = radial; |
| 106 | + entry.sub_label = sublabels[i]; |
| 107 | + entry.x_parity = parities[i][0]; |
| 108 | + entry.y_parity = parities[i][1]; |
| 109 | + entries.push_back(std::move(entry)); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + return entries; |
| 114 | + }(); |
| 115 | + |
| 116 | + return catalog; |
| 117 | + } |
| 118 | + |
| 119 | + static std::vector<ModeTuple> get_filtered_mode_list( |
| 120 | + const BoundaryCondition x_parity, |
| 121 | + const BoundaryCondition y_parity |
| 122 | + ) { |
| 123 | + const auto& catalog = get_mode_catalog(); |
| 124 | + |
| 125 | + std::vector<ModeTuple> filtered_modes; |
| 126 | + filtered_modes.reserve(catalog.size()); |
| 127 | + |
| 128 | + for (const ModeEntry& entry : catalog) |
| 129 | + { |
| 130 | + const bool x_ok = (x_parity == BoundaryCondition::Zero) || (x_parity == entry.x_parity); |
| 131 | + const bool y_ok = (y_parity == BoundaryCondition::Zero) || (y_parity == entry.y_parity); |
| 132 | + |
| 133 | + if (x_ok && y_ok) |
| 134 | + filtered_modes.emplace_back(entry.azimuthal, entry.radial, entry.sub_label); |
| 135 | + } |
| 136 | + |
| 137 | + return filtered_modes; |
| 138 | + } |
| 139 | +}; |
0 commit comments