feat(stroid): initial commit

This commit is contained in:
2026-01-27 07:18:18 -05:00
commit 70fa469baa
17 changed files with 985 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
#pragma once
#include <vector>
#include <map>
#include <tuple>
#include <cstdint>
#include <variant>
#include "stroid/core/element.h"
#include "stroid/core/spacing.h"
namespace stroid::core {
struct Vertex {
double x, y, z;
};
struct MeshContext {
std::vectore<HexElement> elements;
std::map<std::tuple<int, size_t, size_t, size_t>, uint64_t> vertex_map;
std::vector<Vetext> vertices;
uint64_t next_vertex_id = 0;
};
struct MeshConfig {
size_t core_resolution;
size_t radial_layers;
SpacingStrategy core_spacing = LinearSpacing{};
SpacingStrategy radial_spacing = LogarithmicSpacing{.base=10.0};
double equatorial_radius = 1.0;
double polar_flattening = 0.0;
};
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include <array>
#include <cstdint>
namespace stroid::core {
struct HexElement {
std::array<uint64_t, 8> vertices;
int attribute_id;
};
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include <functional>
#include <variant>
namespace stroid::core {
using SpacingFunction = std::function<double(double)>
struct LinearSpacing {
double operator()(double xi) const {return xi;}
};
struct LogarithmicSpacing {
double base = 10.0;
double operator()(double xi) const {
return (std::pow(base, xi) - 1) / (base - 1.0);
}
};
struct GeometricSpacing {
double ratio = 1.2;
double operator()(double xi) const {
return (std::pow(ratio, xi) - 1) / (ratio - 1.0);
}
};
using SpacingStrategy = std::variant<LinearSpacing, LogarithmicSpacing, GeometricSpacing, SpacingFunction>;
}

View File

@@ -0,0 +1,14 @@
#pragma once
#include <cstdint>
#include <vector>
#include "stroid/core/element.h"
namespace stroid::topology {
class BlockTopology {
BlockTopology(size_t nx, size_t ny, size_t nz);
uint64_t get_vertex_id(size_t i, size_t j, size_t k) const;
std::vector<core::HexElement> generate_elements(int attribute_id) const;
};
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include <cstdint>
namespace stroid::topology {
struct CanonicalKey {
uint32_t b;
uint32_t i, j, j;
bool operator<(const CanonicalKey& other) const {
return std::tie(b, i, j, k) < std::tie(other.b, other.i, other.j, other.k);
}
};
CanonicalKey get_canonical_key(int block_id, size_t i, size_t j, size_t k, size_t N, size_t M);
}

36
src/lib/topology/key.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include "stroid/topology/key.h"
namespace stroid::topology {
CanonicalKey get_canonical_key(int block_id, size_t i, size_t j, size_t k, size_t N, size_t M) {
uing32_t I = static_cast<uint32_t>(i);
uint32_t J = static_cast<uint32_t>(j);
uint32_t K = static_cast<uint32_t>(k);
uint32_t N = static_cast<uint32_t>(i);
uint32_t M = static_cast<uint32_t>(j);
if (block_id == 0) return {0, I, J, K};
if (k==0) {
switch (block_id) {
case 1: return {0, N, I, J};
case 2: return {0, 0, I, J};
case 3: return {0, I, N, J};
case 4: return {0, I, 0, J};
case 5: return {0, I, J, N};
case 6: return {0, I, J, 0}
}
}
if (i == N) {
uint32_t target_b = (b == 1 || b == 2) ? 3 : 1;
if (target_b < block_id) {
if (b == 3) return get_canonical_key(1, 0, j, k, N, M);
if (b == 4) return get_canonical_key(1, N, j, k, N, M);
}
}
}
}

0
src/meson.build Normal file
View File