Skip to content

Commit

Permalink
Merge pull request #680 from gonuke/660_uwuw_tally
Browse files Browse the repository at this point in the history
Addressing a number of miscellaneous changes from #660
  • Loading branch information
pshriwise authored Jun 29, 2020
2 parents 0adc4d5 + a81ae53 commit bbc7785
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#*
# vscode settings
.vscode
*.code-workspace

# Ignore built documentation
gh-build
Expand Down
5 changes: 2 additions & 3 deletions misc/tests/test_uwuw_preproc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ def test_model_material():
# group_list is the final list of group names found on the CAD h5m file
for k in pseudo_list:
if ("mat:" in k):
index = k.index('\n')
k = k[0:index]
group_list.append(k.rstrip("\n"))
idx = k.index('\n')
group_list.append(k[0:idx].rstrip("\n"))
# tag_list is the list of group names obtained by running get_tag_values
# function
tag_list = gtag.get_tag_values(filename, output_filename)
Expand Down
18 changes: 18 additions & 0 deletions news/PR-0680.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
**Added:** None

**Changed:**
* a few small fixes prompted by PullRequest review #660
* only changed files in
* `uwuw`
* `tally`
* `overlap_check`
* `build_obb`
* `misc/tests`

**Deprecated:** None

**Removed:** None

**Fixed:** None

**Security:** None
7 changes: 6 additions & 1 deletion src/build_obb/build_obb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ int main(int argc, char* argv[]) {
// sets the output filename if none specified
if (out_file == "") {
int pos = dag_file.find(".h5m");
out_file = dag_file.substr(0, pos) + "_obb.h5m";
if (pos != std::string::npos) {
out_file = dag_file.substr(0, pos);
} else {
out_file = dag_file;
}
out_file = out_file + "_obb.h5m";
std::cout << "Setting default outfile to be " << out_file << std::endl;
}

Expand Down
12 changes: 6 additions & 6 deletions src/overlap_check/ProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ProgressBar.hpp"

#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
Expand All @@ -12,13 +13,10 @@

#define BAR_WIDTH 72

ProgressBar::ProgressBar() {
// initialize bar
set_value(0.0);
}

ProgressBar::~ProgressBar() {
std::cout << "\n";
if (need_final_newline) {
std::cout << std::endl;
}
}

bool ProgressBar::is_terminal() {
Expand Down Expand Up @@ -62,7 +60,9 @@ void ProgressBar::set_value(double val) {

// write the bar to screen
std::cout << '\r' << bar.str() << std::flush;

if (val >= 100.0) {
std::cout << "\n";
need_final_newline = false;
}
}
8 changes: 5 additions & 3 deletions src/overlap_check/ProgressBar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#ifndef DAGMC_PROGRESSBAR_H
#define DAGMC_PROGRESSBAR_H

#include <string>

class ProgressBar {

public:
// constructor
ProgressBar();
ProgressBar() {
// initialize bar
set_value(0.0);
};

// destructor
~ProgressBar();
Expand All @@ -19,6 +20,7 @@ class ProgressBar {

private:
int current {0};
bool need_final_newline {true};
};

#endif // HEADER GUARD
2 changes: 2 additions & 0 deletions src/overlap_check/app/overlap_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ int main(int argc, char* argv[]) {

std::string filename;
int points_per_tri_edge {0};
#ifdef _OPENMP
int n_threads {0};
#endif

po.addRequiredArg<std::string>("dag_file", "Path to DAGMC file to check", &filename);

Expand Down
6 changes: 3 additions & 3 deletions src/overlap_check/overlap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ check_instance_for_overlaps(std::shared_ptr<Interface> MBI,
#pragma omp parallel shared(overlap_map, num_checked)
{
#pragma omp for schedule(auto)
for (int i = 0; i < all_verts.size(); i++) {
for (size_t i = 0; i < all_verts.size(); i++) {

EntityHandle vert = all_verts[i];
CartVect loc;
rval = MBI->get_coords(&vert, 1, loc.array());
MBI->get_coords(&vert, 1, loc.array());

rval = check_location_for_overlap(GQT, all_vols, loc, dir, overlap_map);
MB_CHK_SET_ERR_CONT(rval, "Failed to check location " << loc << " for an overlap");
Expand All @@ -129,7 +129,7 @@ check_instance_for_overlaps(std::shared_ptr<Interface> MBI,
// (curve edges are likely in here too,
// but it isn't hurting anything to check more locations)
#pragma omp for schedule(auto)
for (int i = 0; i < all_edges.size() ; i++) {
for (size_t i = 0; i < all_edges.size() ; i++) {

EntityHandle edge = all_edges[i];
Range edge_verts;
Expand Down
8 changes: 4 additions & 4 deletions src/overlap_check/test/overlap_check_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void OverlapTest::TearDown() {
};

class OverlappingVolumesTest : public OverlapTest {
virtual void SetFilename() { filename = "overlap.h5m"; }
virtual void SetFilename() override { filename = "overlap.h5m"; }
};

TEST_F(OverlappingVolumesTest, test1) {
Expand All @@ -43,7 +43,7 @@ TEST_F(OverlappingVolumesTest, test1) {
}

class NonOverlappingVolumesTest : public OverlapTest {
virtual void SetFilename() { filename = "no_overlap.h5m"; }
virtual void SetFilename() override { filename = "no_overlap.h5m"; }
};

TEST_F(NonOverlappingVolumesTest, test2) {
Expand All @@ -62,7 +62,7 @@ TEST_F(NonOverlappingVolumesTest, test2) {
}

class NonOverlappingImprintedVolumesTest : public OverlapTest {
virtual void SetFilename() { filename = "no_overlap_imp.h5m"; }
virtual void SetFilename() override { filename = "no_overlap_imp.h5m"; }
};

TEST_F(NonOverlappingImprintedVolumesTest, test3) {
Expand All @@ -81,7 +81,7 @@ TEST_F(NonOverlappingImprintedVolumesTest, test3) {
}

class EnclosedVolumeTest : public OverlapTest {
virtual void SetFilename() { filename = "enclosed.h5m"; }
virtual void SetFilename() override { filename = "enclosed.h5m"; }
};

TEST_F(EnclosedVolumeTest, test1) {
Expand Down
4 changes: 2 additions & 2 deletions src/overlap_check/test/overlap_check_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ using namespace moab;

class OverlapTest : public::testing::Test {
protected:
virtual void SetUp();
virtual void TearDown();
virtual void SetUp() override;
virtual void TearDown() override;
virtual void SetFilename() {};

std::string filename;
Expand Down
8 changes: 4 additions & 4 deletions src/tally/KDEMeshTally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ void KDEMeshTally::write_data(double num_histories) {
if (data->has_total_energy_bin())
num_ebins--;

double tally_vect[num_ebins];
double error_vect[num_ebins];
std::vector<double> tally_vect(num_ebins);
std::vector<double> error_vect(num_ebins);

for (unsigned int j = 0; j < num_ebins; ++ j) {
std::pair <double, double> tally_data = data->get_data(point_index, j);
Expand All @@ -210,9 +210,9 @@ void KDEMeshTally::write_data(double num_histories) {
error_vect[j] = rel_error;
}
// set tally and error tag values for this entity
rval = mbi->tag_set_data(tally_tag, &point, 1, tally_vect);
rval = mbi->tag_set_data(tally_tag, &point, 1, tally_vect.data());
MB_CHK_SET_ERR_RET(rval, "Failed to set the tally_tag data");
rval = mbi->tag_set_data(error_tag, &point, 1, error_vect);
rval = mbi->tag_set_data(error_tag, &point, 1, error_vect.data());
MB_CHK_SET_ERR_RET(rval, "Failed to set the error_tag data");
}

Expand Down
13 changes: 6 additions & 7 deletions src/tally/TrackLengthMeshTally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void TrackLengthMeshTally::compute_score(const TallyEvent& event) {
sort_intersection_data(intersections, triangles);

// compute the tracklengths
compute_tracklengths(event, ebin, weight, intersections, triangles);
compute_tracklengths(event, ebin, weight, intersections);

return;
}
Expand Down Expand Up @@ -261,8 +261,8 @@ void TrackLengthMeshTally::write_data(double num_histories) {
if (data->has_total_energy_bin())
num_ebins--;

double tally_vect[num_ebins];
double error_vect[num_ebins];
std::vector<double> tally_vect(num_ebins);
std::vector<double> error_vect(num_ebins);

for (unsigned j = 0; j < num_ebins ; ++j) {
std::pair <double, double> tally_data = data->get_data(tet_index, j);
Expand All @@ -282,9 +282,9 @@ void TrackLengthMeshTally::write_data(double num_histories) {
error_vect[j] = rel_err;
}

rval = mb->tag_set_data(tally_tag, &t, 1, tally_vect);
rval = mb->tag_set_data(tally_tag, &t, 1, tally_vect.data());
MB_CHK_SET_ERR_RET(rval, "Failed to set tally_tag " + std::to_string(rval) + " " + std::to_string(t));
rval = mb->tag_set_data(error_tag, &t, 1, error_vect);
rval = mb->tag_set_data(error_tag, &t, 1, error_vect.data());
MB_CHK_SET_ERR_RET(rval, "Failed to set error_tag " + std::to_string(rval) + " " + std::to_string(t));


Expand Down Expand Up @@ -630,8 +630,7 @@ void TrackLengthMeshTally::sort_intersection_data(std::vector<double>& intersect
// function to compute the track lengths
void TrackLengthMeshTally::compute_tracklengths(const TallyEvent& event,
unsigned int ebin, double weight,
const std::vector<double>& intersections,
const std::vector<EntityHandle>& triangles) {
const std::vector<double>& intersections) {
double track_length; // track_length to add to the tet
CartVect hit_p; //position on the triangular face of the hit
std::vector<CartVect> hit_point; // array of all hit points
Expand Down
4 changes: 1 addition & 3 deletions src/tally/TrackLengthMeshTally.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,11 @@ class TrackLengthMeshTally : public MeshTally {
* \param[in] ebin the energy bin index corresponding to the energy
* \param[in] weight the multiplier value for the score to be tallied
* \param[in] vector<double> intersections list of all the intersections
* \param[in] vector<EntityHandle> triangles list of the triangle entity handles that correspond to the intersections
* \return void
*/
void compute_tracklengths(const TallyEvent& event,
unsigned int ebin, double weight,
const std::vector<double>& intersections,
const std::vector<EntityHandle>& triangles);
const std::vector<double>& intersections);

};

Expand Down
6 changes: 3 additions & 3 deletions src/tally/tests/test_KDEKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class MockEpanechnikovKernel : public KDEKernel {
}

// not implemented
std::string get_kernel_name() const {}
int get_order() const {}
int get_min_quadrature(unsigned int i) const {}
std::string get_kernel_name() const { return std::string(); }
int get_order() const { return 0; }
int get_min_quadrature(unsigned int i) const { return 0; }

// integrates the ith moment function
double integrate_moment(double a, double b, unsigned int i) const {
Expand Down
5 changes: 2 additions & 3 deletions src/uwuw/name_concatenator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
class name_concatenator {
public:
/// constructor
name_concatenator();
name_concatenator() = default;

/// destructor
~name_concatenator();
~name_concatenator() = default;

/// returns the a unique name
std::string make_name_8bytes(std::string name);
Expand Down Expand Up @@ -44,4 +44,3 @@ class name_concatenator {
private:
std::set<std::string> used_b8_names; ///< the collection of names used so far
};

4 changes: 2 additions & 2 deletions src/uwuw/uwuw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::string UWUW::get_full_filepath(std::string filename) {
}

// see if file exists
bool UWUW::check_file_exists(std::string filename) {
bool UWUW::check_file_exists(const std::string& filename) {
// from http://stackoverflow.com/questions/12774207/
// fastest-way-to-check-if-a-file-exist-using-standard-c-c11-c
std::ifstream infile(filename.c_str());
Expand Down Expand Up @@ -151,7 +151,7 @@ int UWUW::get_length_of_table(std::string filename, std::string datapath) {
hid_t arr_space = H5Dget_space(ds);

hsize_t arr_dims[1];
int arr_ndim = H5Sget_simple_extent_dims(arr_space, arr_dims, NULL);
H5Sget_simple_extent_dims(arr_space, arr_dims, NULL);

status = H5Eclear(H5E_DEFAULT);

Expand Down
2 changes: 1 addition & 1 deletion src/uwuw/uwuw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class UWUW {
// turns the filename string into the full file path
std::string get_full_filepath(std::string filename);
// make sure the file, filename exists
bool check_file_exists(std::string filename);
bool check_file_exists(const std::string& filename);

/**
* \brief loads the pyne materials in map of name vs Material
Expand Down
Loading

0 comments on commit bbc7785

Please sign in to comment.