From 498fb181d618d8250e9ff4ddc4f058e4556cdf0b Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 23 Apr 2020 09:49:21 -0500 Subject: [PATCH] Change (surface_)bins_crossed to accept const ref instead of pointer --- include/openmc/mesh.h | 16 +++++------ src/mesh.cpp | 44 ++++++++++++++---------------- src/tallies/filter_mesh.cpp | 2 +- src/tallies/filter_meshsurface.cpp | 2 +- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index bb52cd8a5..a7160b0c8 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -53,7 +53,7 @@ public: //! \param[in] p Particle to check //! \param[out] bins Bins that were crossed //! \param[out] lengths Fraction of tracklength in each bin - virtual void bins_crossed(const Particle* p, std::vector& bins, + virtual void bins_crossed(const Particle& p, std::vector& bins, std::vector& lengths) const = 0; //! Determine which surface bins were crossed by a particle @@ -61,7 +61,7 @@ public: //! \param[in] p Particle to check //! \param[out] bins Surface bins that were crossed virtual void - surface_bins_crossed(const Particle* p, std::vector& bins) const = 0; + surface_bins_crossed(const Particle& p, std::vector& bins) const = 0; //! Get bin at a given position in space // @@ -145,10 +145,10 @@ public: // Overriden methods - void bins_crossed(const Particle* p, std::vector& bins, + void bins_crossed(const Particle& p, std::vector& bins, std::vector& lengths) const override; - void surface_bins_crossed(const Particle* p, std::vector& bins) + void surface_bins_crossed(const Particle& p, std::vector& bins) const override; int get_bin(Position r) const override; @@ -207,10 +207,10 @@ public: // Overriden methods - void bins_crossed(const Particle* p, std::vector& bins, + void bins_crossed(const Particle& p, std::vector& bins, std::vector& lengths) const override; - void surface_bins_crossed(const Particle* p, std::vector& bins) + void surface_bins_crossed(const Particle& p, std::vector& bins) const override; int get_bin(Position r) const override; @@ -256,7 +256,7 @@ public: UnstructuredMesh(pugi::xml_node); ~UnstructuredMesh() = default; - void bins_crossed(const Particle* p, + void bins_crossed(const Particle& p, std::vector& bins, std::vector& lengths) const override; @@ -267,7 +267,7 @@ public: // //! \param[in] p Particle to check //! \param[out] bins Surface bins that were crossed - void surface_bins_crossed(const Particle* p, std::vector& bins) const; + void surface_bins_crossed(const Particle& p, std::vector& bins) const; //! Write mesh data to an HDF5 group. // diff --git a/src/mesh.cpp b/src/mesh.cpp index f40ce3085..b76be1ee8 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -508,16 +508,16 @@ bool RegularMesh::intersects_3d(Position& r0, Position r1, int* ijk) const return min_dist < INFTY; } -void RegularMesh::bins_crossed(const Particle* p, std::vector& bins, +void RegularMesh::bins_crossed(const Particle& p, std::vector& bins, std::vector& lengths) const { // ======================================================================== // Determine where the track intersects the mesh and if it intersects at all. // Copy the starting and ending coordinates of the particle. - Position last_r {p->r_last_}; - Position r {p->r()}; - Direction u {p->u()}; + Position last_r {p.r_last_}; + Position r {p.r()}; + Direction u {p.u()}; // Compute the length of the entire track. double total_distance = (r - last_r).norm(); @@ -614,16 +614,16 @@ void RegularMesh::bins_crossed(const Particle* p, std::vector& bins, } } -void RegularMesh::surface_bins_crossed(const Particle* p, +void RegularMesh::surface_bins_crossed(const Particle& p, std::vector& bins) const { // ======================================================================== // Determine if the track intersects the tally mesh. // Copy the starting and ending coordinates of the particle. - Position r0 {p->r_last_current_}; - Position r1 {p->r()}; - Direction u {p->u()}; + Position r0 {p.r_last_current_}; + Position r1 {p.r()}; + Direction u {p.u()}; // Determine indices for starting and ending location. int n = n_dimension_; @@ -899,16 +899,16 @@ RectilinearMesh::RectilinearMesh(pugi::xml_node node) upper_right_ = {grid_[0].back(), grid_[1].back(), grid_[2].back()}; } -void RectilinearMesh::bins_crossed(const Particle* p, std::vector& bins, +void RectilinearMesh::bins_crossed(const Particle& p, std::vector& bins, std::vector& lengths) const { // ======================================================================== // Determine where the track intersects the mesh and if it intersects at all. // Copy the starting and ending coordinates of the particle. - Position last_r {p->r_last_}; - Position r {p->r()}; - Direction u {p->u()}; + Position last_r {p.r_last_}; + Position r {p.r()}; + Direction u {p.u()}; // Compute the length of the entire track. double total_distance = (r - last_r).norm(); @@ -1004,16 +1004,16 @@ void RectilinearMesh::bins_crossed(const Particle* p, std::vector& bins, } } -void RectilinearMesh::surface_bins_crossed(const Particle* p, +void RectilinearMesh::surface_bins_crossed(const Particle& p, std::vector& bins) const { // ======================================================================== // Determine if the track intersects the tally mesh. // Copy the starting and ending coordinates of the particle. - Position r0 {p->r_last_current_}; - Position r1 {p->r()}; - Direction u {p->u()}; + Position r0 {p.r_last_current_}; + Position r1 {p.r()}; + Direction u {p.u()}; // Determine indices for starting and ending location. int ijk0[3], ijk1[3]; @@ -1650,15 +1650,13 @@ UnstructuredMesh::intersect_track(const moab::CartVect& start, } void -UnstructuredMesh::bins_crossed(const Particle* p, +UnstructuredMesh::bins_crossed(const Particle& p, std::vector& bins, std::vector& lengths) const { - - moab::ErrorCode rval; - Position last_r{p->r_last_}; - Position r{p->r()}; - Direction u{p->u()}; + Position last_r{p.r_last_}; + Position r{p.r()}; + Direction u{p.u()}; u /= u.norm(); moab::CartVect r0(last_r.x, last_r.y, last_r.z); moab::CartVect r1(r.x, r.y, r.z); @@ -1772,7 +1770,7 @@ double UnstructuredMesh::tet_volume(moab::EntityHandle tet) const { return 1.0 / 6.0 * (((p[1] - p[0]) * (p[2] - p[0])) % (p[3] - p[0])); } -void UnstructuredMesh::surface_bins_crossed(const Particle* p, std::vector& bins) const { +void UnstructuredMesh::surface_bins_crossed(const Particle& p, std::vector& bins) const { // TODO: Implement triangle crossings here throw std::runtime_error{"Unstructured mesh surface tallies are not implemented."}; } diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index 8b6789cb9..789717386 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -41,7 +41,7 @@ const match.weights_.push_back(1.0); } } else { - model::meshes[mesh_]->bins_crossed(&p, match.bins_, match.weights_); + model::meshes[mesh_]->bins_crossed(p, match.bins_, match.weights_); } } diff --git a/src/tallies/filter_meshsurface.cpp b/src/tallies/filter_meshsurface.cpp index 05aa44081..997fef729 100644 --- a/src/tallies/filter_meshsurface.cpp +++ b/src/tallies/filter_meshsurface.cpp @@ -11,7 +11,7 @@ void MeshSurfaceFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - model::meshes[mesh_]->surface_bins_crossed(&p, match.bins_); + model::meshes[mesh_]->surface_bins_crossed(p, match.bins_); for (auto b : match.bins_) match.weights_.push_back(1.0); }