From baa92194ef488b8fe44bdb41f5936cae5a30a0d2 Mon Sep 17 00:00:00 2001 From: shriwise Date: Sat, 11 Aug 2018 08:30:12 -0500 Subject: [PATCH] Making Position/Direction structs more friendly for array-based signatures. --- include/openmc/position.h | 4 +--- src/cell.cpp | 8 ++------ src/surface.cpp | 6 ++---- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/include/openmc/position.h b/include/openmc/position.h index 56d01ba0a6..eff76dbca0 100644 --- a/include/openmc/position.h +++ b/include/openmc/position.h @@ -57,9 +57,7 @@ struct Position { } // Data members - double x = 0.; - double y = 0.; - double z = 0.; + union{ double xyz[3]; struct{ double x,y,z; }; }; }; // Binary operators diff --git a/src/cell.cpp b/src/cell.cpp index 1d71ff4da7..c544c5b3d9 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -599,12 +599,10 @@ CADCell::CADCell() : Cell{} {}; std::pair CADCell::distance(Position p, Direction u, int32_t on_surface) const { - double xyz[3] = {p.x, p.y, p.z}; - double uvw[3] = {u.x, u.y, u.z}; moab::EntityHandle vol = dagmc_ptr->entity_by_id(3, id); moab::EntityHandle hit_surf; double dist; - dagmc_ptr->ray_fire(vol, xyz, uvw, hit_surf, dist); + dagmc_ptr->ray_fire(vol, p.xyz, u.xyz, hit_surf, dist); int surf_idx = dagmc_ptr->index_by_handle(hit_surf); @@ -615,12 +613,10 @@ std::pair CADCell::distance(Position p, Direction u, int32_t on bool CADCell::contains(Position p, Direction u, int32_t on_surface) const { - double xyz[3] = {p.x, p.y, p.z}; - double uvw[3] = {u.x, u.y, u.z}; moab::EntityHandle vol = dagmc_ptr->entity_by_id(3, id); int result = 0; - dagmc_ptr->point_in_volume(vol, xyz, result, uvw); + dagmc_ptr->point_in_volume(vol, p.xyz, result, u.xyz); return bool(result); } diff --git a/src/surface.cpp b/src/surface.cpp index 5c05d9d403..18947a86bf 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -262,11 +262,9 @@ double CADSurface::distance(Position p, Direction u, bool coincident) const { Direction CADSurface::normal(Position p) const { - double xyz[3] = {p.x, p.y, p.z}; - double uvw[3]; + Direction u; moab::EntityHandle surf = dagmc_ptr->entity_by_id(2, id); - dagmc_ptr->get_angle(surf, xyz, uvw); - Direction u = {uvw}; + dagmc_ptr->get_angle(surf, p.xyz, u.xyz); return u; }