Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hexagonal mesh model #3279

Draft
wants to merge 53 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
fb0f124
WIP: initial setup of hexmesh
ebknudsen Jan 20, 2025
7e6689e
WIP initial work on headers
ebknudsen Jan 20, 2025
f4ded95
placeholder constructor
ebknudsen Jan 21, 2025
9188fca
sampling from index code
ebknudsen Jan 21, 2025
cd911ab
get index from coordinates
ebknudsen Jan 21, 2025
95b674e
get index from coordinates
ebknudsen Jan 21, 2025
9cd628a
Merge branch 'hexagonal_mesh' of github.com:ebknudsen/openmc into hex…
ebknudsen Jan 21, 2025
a108d47
fix silly typo
ebknudsen Jan 21, 2025
f3f3fa9
fix to use length of hex-lattice basis vector
ebknudsen Jan 21, 2025
95406ce
Merge branch 'openmc-dev:develop' into hexagonal_mesh
ebknudsen Jan 24, 2025
7171e8d
fix naming
ebknudsen Jan 27, 2025
13f3d39
fix silly typo
ebknudsen Jan 21, 2025
150bcb5
fix to use length of hex-lattice basis vector
ebknudsen Jan 21, 2025
dbe5490
Tweak To Sphinx Install Documentation (#3271)
jtramm Jan 21, 2025
f6b1d92
fix naming
ebknudsen Jan 27, 2025
731d54e
Merge branch 'hexagonal_mesh' of github.com:ebknudsen/openmc into hex…
ebknudsen Jan 27, 2025
ca963bd
xml-reading mostly borrowed from reg. mesh
ebknudsen Feb 4, 2025
f91e156
fix up code for better index representation
ebknudsen Feb 4, 2025
ced2082
in pricniple correct find distance code
ebknudsen Feb 4, 2025
f68e3d3
remove unused code
ebknudsen Feb 4, 2025
a2f699f
mark for removal
ebknudsen Feb 4, 2025
90ce4c7
placeholder
ebknudsen Feb 4, 2025
455cf6f
add methods to compute hex-distaces
ebknudsen Feb 6, 2025
ee2860b
fix the hex count calculation
ebknudsen Feb 6, 2025
d06751f
fix mislabeled method
ebknudsen Feb 6, 2025
057a8b8
whitespace
ebknudsen Feb 6, 2025
725ae9a
include xtensor norm + update comments
ebknudsen Feb 17, 2025
f7c021a
add basis vectors and plane normals
ebknudsen Feb 17, 2025
fd7273e
WIP - have realized we need a special raytracer for this siutation
ebknudsen Feb 17, 2025
741b439
placeholder comments
ebknudsen Feb 17, 2025
8633f5d
rewrote the distance_to_hex_boundary algorithm
ebknudsen Mar 19, 2025
9c600c8
fix logic to figure out if we're inside mesh
ebknudsen Mar 19, 2025
b9073ec
now has algorithm for outside mesh
ebknudsen Mar 19, 2025
2ff8aac
extra ;
ebknudsen Mar 19, 2025
2868bc0
remove unused function
ebknudsen Mar 19, 2025
b82ee14
going through all syntax errors
ebknudsen Mar 20, 2025
02a10be
fix naming and call of hexindex->xyz
ebknudsen Mar 21, 2025
73c0e76
apply clang-formatting
ebknudsen Mar 21, 2025
c72c7cb
apply clang-format
ebknudsen Mar 21, 2025
e194e31
add dummy functions
ebknudsen Mar 25, 2025
2e65f46
add the tracking tally helpers
ebknudsen Mar 25, 2025
efcf8cc
fix some mistakens ni method call namings
ebknudsen Mar 25, 2025
dbe7d3f
rename method to avoid conf.
ebknudsen Mar 26, 2025
0290b48
swithc to use only 3 surfaces instead of 6
ebknudsen Mar 26, 2025
45d119e
hex indices refer to hex basis vector i.e. plane normals
ebknudsen Mar 26, 2025
4a1846c
should round, otherwise we get wrong hex
ebknudsen Mar 26, 2025
6feea29
have to check if in mesh
ebknudsen Mar 27, 2025
4d554d9
fix the distance calculation
ebknudsen Mar 27, 2025
a9fd6a3
check that the number of hexes is sane
ebknudsen Mar 28, 2025
05044f7
actually compute the enclosing radius
ebknudsen Mar 28, 2025
11ae59f
fix the hexindex computation
ebknudsen Mar 28, 2025
0c8f476
WIP edits to the logic when outside mesh
ebknudsen Mar 28, 2025
5091202
fix indexing mistake
ebknudsen Mar 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ list(APPEND libopenmc_SOURCES
src/finalize.cpp
src/geometry.cpp
src/geometry_aux.cpp
src/hex_mesh.cpp
src/hdf5_interface.cpp
src/initialize.cpp
src/lattice.cpp
Expand Down
179 changes: 179 additions & 0 deletions include/openmc/hex_mesh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
//! \file hex_mesh.h
//! \brief Mesh types used for tallies, Shannon entropy, CMFD, etc.

#ifndef OPENMC_HEX_MESH_H
#define OPENMC_HEX_MESH_H

#include <cmath>
#include <unordered_map>

#include "hdf5.h"
#include "pugixml.hpp"
#include "xtensor/xtensor.hpp"
#include <gsl/gsl-lite.hpp>

#include "openmc/error.h"
#include "openmc/memory.h" // for unique_ptr
#include "openmc/mesh.h"
#include "openmc/particle.h"
#include "openmc/position.h"
#include "openmc/vector.h"
#include "openmc/xml_interface.h"

#ifdef DAGMC
#include "moab/AdaptiveKDTree.hpp"
#include "moab/Core.hpp"
#include "moab/GeomUtil.hpp"
#include "moab/Matrix3.hpp"
#endif

#ifdef LIBMESH
#include "libmesh/bounding_box.h"
#include "libmesh/dof_map.h"
#include "libmesh/elem.h"
#include "libmesh/equation_systems.h"
#include "libmesh/exodusII_io.h"
#include "libmesh/explicit_system.h"
#include "libmesh/libmesh.h"
#include "libmesh/mesh.h"
#include "libmesh/point.h"
#endif

namespace openmc {

//==============================================================================
// Constants
//==============================================================================

//==============================================================================
// Global variables
//==============================================================================

extern "C" const bool LIBMESH_ENABLED;

class HexagonalMesh : public PeriodicStructuredMesh {
public:
// Constructors
HexagonalMesh() = default;
HexagonalMesh(pugi::xml_node node);

using HexMeshIndex = std::array<int, 4>;

using SpiralHexMeshIndex = std::array<int, 3>;

struct HexMeshDistance {
HexMeshDistance() = default;
HexMeshDistance(int _index, bool _max_surface, double _distance)
: next_index {_index}, max_surface {_max_surface}, distance {_distance}
{}
HexMeshIndex next_index {0, 0, 0, 0};
bool max_surface {true};
double distance {INFTY};
bool operator<(const HexMeshDistance& o) const
{
return distance < o.distance;
}
};

HexMeshIndex get_hexindices_from_bin(const int32_t) const;

int32_t get_bin_from_hexindices(const HexMeshIndex& ijkl) const;

HexMeshIndex rotate_hexindex(const HexMeshIndex& ijkl, int steps) const;

int get_hexindex_in_direction(const Position& r, int i) const;

int get_index_in_direction(double r, int i) const;

virtual std::string get_mesh_type() const override;

static const std::string mesh_type;

Position sample_element(int32_t bin, uint64_t* seed) const override
{
return sample_element(get_hexindices_from_bin(bin), seed);
};

Position sample_element(const HexMeshIndex& ijkl, uint64_t* seed) const;

HexMeshDistance distance_to_grid_boundary(const HexMeshIndex& ijk, int i,
const Position& r0, const Direction& u, double l) const;

StructuredMesh::MeshDistance distance_to_grid_boundary(const MeshIndex& ijk, int i,
const Position& r0, const Direction& u, double l) const override;

std::pair<vector<double>, vector<double>> plot(
Position plot_ll, Position plot_ur) const override;

void to_hdf5_inner(hid_t group) const override;

Position get_position_from_hexindex(HexMeshIndex ijkl) const;

HexMeshIndex get_hexindices(Position r, bool& in_mesh) const;

bool in_hexmesh(HexMeshIndex& ijkl) const;

double volume(const StructuredMesh::MeshIndex& ijk) const;

// Data members
double size_ {0};
int hex_radius_ {0};
int hex_count_ {0};
double r_encl_ {0};

double element_volume_ {0};
double volume_frac_ {0};

xt::xtensor<double, 1> width_;

template<class T>
void raytrace_mesh(
Position r0, Position r1, const Direction& u, T tally) const;

double find_surface_crossing(const Position& r, const Direction& u) const;

int find_surface_crossing_index(
const Position& r, const Direction& u, double l) const;

double find_r_crossing(const Position& r, const Direction& u, double l) const;

HexMeshDistance distance_to_hex_boundary(const HexMeshIndex& ijkl, int i,
const Position& r0, const Direction& u, double l) const;

Position get_hex_center(HexMeshIndex ijkl) const;

double volume(const HexMeshIndex& ijkl) const;

void bins_crossed(Position r0, Position r1, const Direction& u,
vector<int>& bins, vector<double>& lengths) const override;

void surface_bins_crossed(Position r0, Position r1, const Direction& u,
vector<int>& bins) const override;

private:
int init_plane_normals();

int scale_grid_vectors(double s);
// needed data members:
// size_ length of basis vectors
// hex-basis vectors r_,q_,s_
// surface normal vectors n0_, n1_, n2_
// max-index of hex-rings meaning indices run from -max,...,0,...,max
// - this means:
// the width of a hexagon is sqrt(3)*size_

Position r_ {0, -1, 0};
Position q_ {sqrt(3.0) * 0.5, 0.5, 0};
Position s_ {-sqrt(3.0) * 0.5, 0.5, 0};

Position n0_ {0, 0, 0};
Position n1_ {0, 0, 0};
Position n2_ {0, 0, 0};

int hex_radius(const HexMeshIndex& ijkl) const;

int hex_distance(const HexMeshIndex& ijkl0, const HexMeshIndex& ijkl1) const;
};

} // namespace openmc
#endif // OPENMC_HEX_MESH_H
Loading
Loading