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

Add an intermediate PeriodicStructuredMesh class to separate the origin attribute from StructuredMesh #6

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 26 additions & 4 deletions include/openmc/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class Mesh {

// Methods

//! Update a position to the local coordinates of the mesh
virtual void local_coords(Position& r) const {};

//! Return a position in the local coordinates of the mesh
virtual Position local_coords(const Position& r) const { return r; };

//! Determine which bins were crossed by a particle
//
//! \param[in] r0 Previous position of the particle
Expand Down Expand Up @@ -160,7 +166,7 @@ class StructuredMesh : public Mesh {
}
};

int get_bin(Position r) const override;
virtual int get_bin(Position r) const;

int n_bins() const override;

Expand Down Expand Up @@ -241,11 +247,27 @@ class StructuredMesh : public Mesh {
xt::xtensor<double, 1> lower_left_; //!< Lower-left coordinates of mesh
xt::xtensor<double, 1> upper_right_; //!< Upper-right coordinates of mesh
std::array<int, 3> shape_; //!< Number of mesh elements in each dimension
Position origin_ {0.0, 0.0, 0.0};

protected:
};

class PeriodicStructuredMesh : public StructuredMesh {

public:
PeriodicStructuredMesh() = default;
PeriodicStructuredMesh(pugi::xml_node node) : StructuredMesh {node} {};

void local_coords(Position& r) const override { r -= origin_; };

Position local_coords(const Position& r) const override
{
return r - origin_;
};

// Data members
Position origin_ {0.0, 0.0, 0.0}; //!< Origin of the mesh
};

//==============================================================================
//! Tessellation of n-dimensional Euclidean space by congruent squares or cubes
//==============================================================================
Expand Down Expand Up @@ -336,7 +358,7 @@ class RectilinearMesh : public StructuredMesh {
int set_grid();
};

class CylindricalMesh : public StructuredMesh {
class CylindricalMesh : public PeriodicStructuredMesh {
public:
// Constructors
CylindricalMesh() = default;
Expand Down Expand Up @@ -390,7 +412,7 @@ class CylindricalMesh : public StructuredMesh {
}
};

class SphericalMesh : public StructuredMesh {
class SphericalMesh : public PeriodicStructuredMesh {
public:
// Constructors
SphericalMesh() = default;
Expand Down
14 changes: 8 additions & 6 deletions src/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ void StructuredMesh::raytrace_mesh(

// translate start and end positions,
// this needs to come after the get_indices call because it does its own translation
r0 -= origin_;
r1 -= origin_;
local_coords(r0);
local_coords(r1);

// Calculate initial distances to next surfaces in all three dimensions
std::array<MeshDistance, 3> distances;
Expand Down Expand Up @@ -952,7 +952,8 @@ void RectilinearMesh::to_hdf5(hid_t group) const
// CylindricalMesh implementation
//==============================================================================

CylindricalMesh::CylindricalMesh(pugi::xml_node node) : StructuredMesh {node}
CylindricalMesh::CylindricalMesh(pugi::xml_node node)
: PeriodicStructuredMesh {node}
{
n_dimension_ = 3;

Expand All @@ -976,7 +977,7 @@ std::string CylindricalMesh::get_mesh_type() const
StructuredMesh::MeshIndex CylindricalMesh::get_indices(
Position r, bool& in_mesh) const
{
r -= origin_;
local_coords(r);

Position mapped_r;
mapped_r[0] = std::hypot(r.x, r.y);
Expand Down Expand Up @@ -1189,7 +1190,8 @@ void CylindricalMesh::to_hdf5(hid_t group) const
// SphericalMesh implementation
//==============================================================================

SphericalMesh::SphericalMesh(pugi::xml_node node) : StructuredMesh {node}
SphericalMesh::SphericalMesh(pugi::xml_node node)
: PeriodicStructuredMesh {node}
{
n_dimension_ = 3;

Expand All @@ -1213,7 +1215,7 @@ std::string SphericalMesh::get_mesh_type() const
StructuredMesh::MeshIndex SphericalMesh::get_indices(
Position r, bool& in_mesh) const
{
r -= origin_;
local_coords(r);

Position mapped_r;
mapped_r[0] = r.norm();
Expand Down