ENH: Format solver

This commit is contained in:
David Allemang
2023-02-07 15:52:18 -05:00
parent 01e734ff00
commit f1bcac17fa
2 changed files with 45 additions and 15 deletions

View File

@@ -13,7 +13,9 @@
/**
* Produce a list of all generators for the group context. The range [0..group.rank()).
*/
std::vector<size_t> generators(const tc::Group &context) {
std::vector<size_t> _generators(
const tc::Group &context
) {
std::vector<size_t> g_gens(context.rank());
std::iota(g_gens.begin(), g_gens.end(), 0);
return g_gens;
@@ -24,7 +26,12 @@ std::vector<size_t> generators(const tc::Group &context) {
*
* For example if g_gens contains {a, b, c, d} and sg_gens contains {b, d, a} then the result is {1, 3, 0}
*/
std::vector<size_t> recontext_gens(std::vector<size_t> g_gens, std::vector<size_t> sg_gens) {
std::vector<size_t> _recontext_gens(
std::vector<size_t> g_gens,
std::vector<size_t> sg_gens
) {
auto orig = sg_gens;
for (size_t &gen: sg_gens) {
gen = std::distance(
g_gens.begin(),
@@ -39,9 +46,13 @@ std::vector<size_t> recontext_gens(std::vector<size_t> g_gens, std::vector<size_
*/
template<unsigned N>
[[nodiscard]]
Indices<N> recontext(Indices<N> prims, const tc::Group &context, const std::vector<size_t> &g_gens,
const std::vector<size_t> &sg_gens) {
const auto proper_sg_gens = recontext_gens(g_gens, sg_gens);
Indices<N> recontext(
Indices<N> prims,
const tc::Group &context,
const std::vector<size_t> &g_gens,
const std::vector<size_t> &sg_gens
) {
const auto proper_sg_gens = _recontext_gens(g_gens, sg_gens);
const auto table = context.sub(g_gens).solve({});
const auto cosets = context.sub(sg_gens).solve({});
@@ -65,7 +76,9 @@ Indices<N> recontext(Indices<N> prims, const tc::Group &context, const std::vect
* Union several meshes of the same dimension
*/
template<unsigned N>
Indices<N> merge(const std::vector<Indices<N>> &meshes) {
Indices<N> merge(
const std::vector<Indices<N>> &meshes
) {
size_t cols = 0;
for (const auto &mesh: meshes) {
cols += mesh.cols();
@@ -84,10 +97,14 @@ Indices<N> merge(const std::vector<Indices<N>> &meshes) {
template<unsigned N>
[[nodiscard]]
std::vector<Indices<N>> tile(Indices<N> prims, const tc::Group &context, const std::vector<size_t> &g_gens,
const std::vector<size_t> &sg_gens) {
std::vector<Indices<N>> tile(
Indices<N> prims,
const tc::Group &context,
const std::vector<size_t> &g_gens,
const std::vector<size_t> &sg_gens
) {
Indices<N> base = recontext<N>(prims, context, g_gens, sg_gens);
const auto proper_sg_gens = recontext_gens(g_gens, sg_gens);
const auto proper_sg_gens = _recontext_gens(g_gens, sg_gens);
const auto &table = context.sub(g_gens).solve({});
const auto &cosets = context.sub(g_gens).solve(proper_sg_gens);
@@ -111,7 +128,10 @@ std::vector<Indices<N>> tile(Indices<N> prims, const tc::Group &context, const s
*/
template<unsigned N>
[[nodiscard]]
Indices<N + 1> fan(Indices<N> prims, int root) {
Indices<N + 1> fan(
Indices<N> prims,
int root
) {
Indices<N + 1> res(N + 1, prims.cols());
res.topRows(1) = Indices<1>::Constant(1, prims.cols(), root);
@@ -124,7 +144,10 @@ Indices<N + 1> fan(Indices<N> prims, int root) {
* Produce a mesh of primitives that fill out the volume of the subgroup generated by generators g_gens within the group context
*/
template<unsigned N>
Indices<N> triangulate(const tc::Group &context, const std::vector<size_t> &g_gens) {
Indices<N> triangulate(
const tc::Group &context,
const std::vector<size_t> &g_gens
) {
if (g_gens.size() + 1 != N) // todo make static assert
throw std::logic_error("g_gens size must be one less than N");
@@ -148,7 +171,10 @@ Indices<N> triangulate(const tc::Group &context, const std::vector<size_t> &g_ge
* Single-index primitives should not be further triangulated.
*/
template<>
Indices<1> triangulate<1>(const tc::Group &context, const std::vector<size_t> &g_gens) {
Indices<1> triangulate<1>(
const tc::Group &context,
const std::vector<size_t> &g_gens
) {
if (not g_gens.empty()) // todo make static assert
throw std::logic_error("g_gens must be empty for a trivial Mesh");
@@ -156,9 +182,13 @@ Indices<1> triangulate<1>(const tc::Group &context, const std::vector<size_t> &g
}
template<unsigned N, class T>
auto hull(const tc::Group &group, T all_sg_gens, const std::vector<std::vector<size_t>> &exclude) {
auto hull(
const tc::Group &group,
T all_sg_gens,
const std::vector<std::vector<size_t>> &exclude
) {
std::vector<Indices<N>> parts;
auto g_gens = generators(group);
auto g_gens = _generators(group);
for (const std::vector<size_t> &sg_gens: all_sg_gens) {
bool excluded = false;
for (const auto &test: exclude) {