diff --git a/include/openmc/geometry_aux.h b/include/openmc/geometry_aux.h index ffcdcf885f..800baef265 100644 --- a/include/openmc/geometry_aux.h +++ b/include/openmc/geometry_aux.h @@ -7,9 +7,15 @@ #include #include #include +#include namespace openmc { +namespace model { + extern std::unordered_map> universe_cell_counts; + extern std::unordered_map universe_level_counts; +} // namespace model + void read_geometry_xml(); //============================================================================== diff --git a/setup.py b/setup.py index aff7834d7b..99db831484 100755 --- a/setup.py +++ b/setup.py @@ -69,7 +69,7 @@ kwargs = { 'pandas', 'lxml', 'uncertainties' ], 'extras_require': { - 'test': ['pytest', 'pytest-cov'], + 'test': ['pytest', 'pytest-cov', 'colorama'], 'vtk': ['vtk'], }, } diff --git a/src/finalize.cpp b/src/finalize.cpp index 3de20d6d09..16ff0fbccb 100644 --- a/src/finalize.cpp +++ b/src/finalize.cpp @@ -135,6 +135,10 @@ int openmc_finalize() int openmc_reset() { + + model::universe_cell_counts.clear(); + model::universe_level_counts.clear(); + for (auto& t : model::tallies) { t->reset(); } diff --git a/src/geometry_aux.cpp b/src/geometry_aux.cpp index d195a9de39..5ebee4aca1 100644 --- a/src/geometry_aux.cpp +++ b/src/geometry_aux.cpp @@ -23,6 +23,21 @@ namespace openmc { +namespace model { + std::unordered_map> universe_cell_counts; + std::unordered_map universe_level_counts; +} // namespace model + + +// adds the cell counts of universe b to universe a +void update_universe_cell_count(int32_t a, int32_t b) { + auto& universe_a_counts = model::universe_cell_counts[a]; + const auto& universe_b_counts = model::universe_cell_counts[b]; + for (const auto& it : universe_b_counts) { + universe_a_counts[it.first] += it.second; + } +} + void read_geometry_xml() { #ifdef DAGMC @@ -395,19 +410,29 @@ prepare_distribcell() void count_cell_instances(int32_t univ_indx) { - for (int32_t cell_indx : model::universes[univ_indx]->cells_) { - Cell& c = *model::cells[cell_indx]; - ++c.n_instances_; - if (c.type_ == FILL_UNIVERSE) { - // This cell contains another universe. Recurse into that universe. - count_cell_instances(c.fill_); + const auto univ_counts = model::universe_cell_counts.find(univ_indx); + if (univ_counts != model::universe_cell_counts.end()) { + for (const auto& it : univ_counts->second) { + model::cells[it.first]->n_instances_ += it.second; + } + } else { + for (int32_t cell_indx : model::universes[univ_indx]->cells_) { + Cell& c = *model::cells[cell_indx]; + ++c.n_instances_; + model::universe_cell_counts[univ_indx][cell_indx] += 1; - } else if (c.type_ == FILL_LATTICE) { - // This cell contains a lattice. Recurse into the lattice universes. - Lattice& lat = *model::lattices[c.fill_]; - for (auto it = lat.begin(); it != lat.end(); ++it) { - count_cell_instances(*it); + if (c.type_ == FILL_UNIVERSE) { + // This cell contains another universe. Recurse into that universe. + count_cell_instances(c.fill_); + update_universe_cell_count(univ_indx, c.fill_); + } else if (c.type_ == FILL_LATTICE) { + // This cell contains a lattice. Recurse into the lattice universes. + Lattice& lat = *model::lattices[c.fill_]; + for (auto it = lat.begin(); it != lat.end(); ++it) { + count_cell_instances(*it); + update_universe_cell_count(univ_indx, *it); + } } } } @@ -529,6 +554,12 @@ distribcell_path(int32_t target_cell, int32_t map, int32_t target_offset) int maximum_levels(int32_t univ) { + + const auto level_count = model::universe_level_counts.find(univ); + if (level_count != model::universe_level_counts.end()) { + return level_count->second; + } + int levels_below {0}; for (int32_t cell_indx : model::universes[univ]->cells_) { @@ -546,6 +577,7 @@ maximum_levels(int32_t univ) } ++levels_below; + model::universe_level_counts[univ] = levels_below; return levels_below; } diff --git a/src/mgxs.cpp b/src/mgxs.cpp index 84381fe77d..bc2aa9c0a3 100644 --- a/src/mgxs.cpp +++ b/src/mgxs.cpp @@ -541,8 +541,7 @@ Mgxs::sample_fission_energy(int gin, int& dg, int& gout) double nu_fission = xs_t->nu_fission(cache[tid].a, gin); // Find the probability of having a prompt neutron - double prob_prompt = - xs_t->prompt_nu_fission(cache[tid].a, gin); + double prob_prompt = xs_t->prompt_nu_fission(cache[tid].a, gin); // sample random numbers double xi_pd = prn() * nu_fission; @@ -557,8 +556,7 @@ Mgxs::sample_fission_energy(int gin, int& dg, int& gout) // sample the outgoing energy group gout = 0; - double prob_gout = - xs_t->chi_prompt(cache[tid].a, gin, gout); + double prob_gout = xs_t->chi_prompt(cache[tid].a, gin, gout); while (prob_gout < xi_gout) { gout++; prob_gout += xs_t->chi_prompt(cache[tid].a, gin, gout); @@ -568,11 +566,9 @@ Mgxs::sample_fission_energy(int gin, int& dg, int& gout) // the neutron is delayed // get the delayed group - dg = 0; - while (xi_pd >= prob_prompt) { - dg++; - prob_prompt += - xs_t->delayed_nu_fission(cache[tid].a, dg, gin); + for (dg = 0; dg < num_delayed_groups; ++dg) { + prob_prompt += xs_t->delayed_nu_fission(cache[tid].a, dg, gin); + if (xi_pd < prob_prompt) break; } // adjust dg in case of round-off error @@ -580,12 +576,10 @@ Mgxs::sample_fission_energy(int gin, int& dg, int& gout) // sample the outgoing energy group gout = 0; - double prob_gout = - xs_t->chi_delayed(cache[tid].a, dg, gin, gout); + double prob_gout = xs_t->chi_delayed(cache[tid].a, dg, gin, gout); while (prob_gout < xi_gout) { gout++; - prob_gout += - xs_t->chi_delayed(cache[tid].a, dg, gin, gout); + prob_gout += xs_t->chi_delayed(cache[tid].a, dg, gin, gout); } } } diff --git a/src/particle_restart.cpp b/src/particle_restart.cpp index 8672ebf840..73e6d5d370 100644 --- a/src/particle_restart.cpp +++ b/src/particle_restart.cpp @@ -79,6 +79,9 @@ void run_particle_restart() int previous_run_mode; read_particle_restart(p, previous_run_mode); + // write track if that was requested on command line + if (settings::write_all_tracks) p.write_track_ = true; + // Set all tallies to 0 for now (just tracking errors) model::tallies.clear(); diff --git a/src/tallies/tally_scoring.cpp b/src/tallies/tally_scoring.cpp index 582e7dced9..a2532c437e 100644 --- a/src/tallies/tally_scoring.cpp +++ b/src/tallies/tally_scoring.cpp @@ -1720,7 +1720,7 @@ score_general_mg(const Particle* p, int i_tally, int start_index, model::tally_filters[i_dg_filt].get())}; // Tally each delayed group bin individually for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { - auto d = filt.groups()[d_bin]; + auto d = filt.groups()[d_bin] - 1; score = p->wgt_absorb_ * flux; if (i_nuclide >= 0) { score *= @@ -1802,7 +1802,7 @@ score_general_mg(const Particle* p, int i_tally, int start_index, model::tally_filters[i_dg_filt].get())}; // Tally each delayed group bin individually for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { - auto d = filt.groups()[d_bin]; + auto d = filt.groups()[d_bin] - 1; if (i_nuclide >= 0) { score = flux * atom_density * get_nuclide_xs(i_nuclide, MG_GET_XS_DELAYED_NU_FISSION, @@ -1842,7 +1842,7 @@ score_general_mg(const Particle* p, int i_tally, int start_index, model::tally_filters[i_dg_filt].get())}; // Tally each delayed group bin individually for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { - auto d = filt.groups()[d_bin]; + auto d = filt.groups()[d_bin] - 1; score = p->wgt_absorb_ * flux; if (i_nuclide >= 0) { score *= @@ -1902,8 +1902,8 @@ score_general_mg(const Particle* p, int i_tally, int start_index, for (auto i = 0; i < p->n_bank_; ++i) { auto i_bank = simulation::fission_bank.size() - p->n_bank_ + i; const auto& bank = simulation::fission_bank[i_bank]; - auto g = bank.delayed_group; - if (g != 0) { + auto g = bank.delayed_group - 1; + if (g != -1) { if (i_nuclide >= 0) { score += simulation::keff * atom_density * bank.wgt * flux * get_nuclide_xs(i_nuclide, MG_GET_XS_DECAY_RATE, p_g, @@ -1923,7 +1923,7 @@ score_general_mg(const Particle* p, int i_tally, int start_index, // Find the corresponding filter bin and then score for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { auto d = filt.groups()[d_bin]; - if (d == g) + if (d == g + 1) score_fission_delayed_dg(i_tally, d_bin, score, score_index); } @@ -1941,7 +1941,7 @@ score_general_mg(const Particle* p, int i_tally, int start_index, model::tally_filters[i_dg_filt].get())}; // Tally each delayed group bin individually for (auto d_bin = 0; d_bin < filt.n_bins(); ++d_bin) { - auto d = filt.groups()[d_bin]; + auto d = filt.groups()[d_bin] - 1; if (i_nuclide >= 0) { score += atom_density * flux * get_nuclide_xs(i_nuclide, MG_GET_XS_DECAY_RATE, diff --git a/tests/regression_tests/mg_tallies/results_true.dat b/tests/regression_tests/mg_tallies/results_true.dat index 50ec653e20..26a062facb 100644 --- a/tests/regression_tests/mg_tallies/results_true.dat +++ b/tests/regression_tests/mg_tallies/results_true.dat @@ -1 +1,1324 @@ -508cd056f2d9409a536e487512df34c683720ea45b9100316efb31c19927890c4cacd92f38817d74fcf491bbe4bdb78a0215a798d5a078e0575e3fd94cedf0bd \ No newline at end of file +k-combined: +9.934975E-01 2.679669E-02 +tally 1: +2.542000E+00 +1.343070E+00 +1.260000E-01 +3.298000E-03 +4.838111E-02 +4.857369E-04 +1.202865E-01 +3.119670E-03 +6.000347E-07 +8.163458E-14 +1.202865E-01 +3.119670E-03 +0.000000E+00 +0.000000E+00 +9.676221E+06 +1.942948E+13 +2.542000E+00 +1.343070E+00 +0.000000E+00 +0.000000E+00 +7.404202E+00 +1.141803E+01 +1.949000E+00 +8.324030E-01 +9.000000E-02 +1.762000E-03 +3.793334E-02 +3.031575E-04 +1.081691E-01 +2.457437E-03 +5.571912E-07 +6.439495E-14 +1.071378E-01 +2.411702E-03 +1.031308E-03 +1.063597E-06 +7.586669E+06 +1.212630E+13 +1.949000E+00 +8.324030E-01 +3.122595E-04 +9.750600E-08 +5.650158E+00 +7.016308E+00 +1.039000E+00 +2.447670E-01 +4.200000E-02 +4.120000E-04 +1.685968E-02 +6.389070E-05 +4.929366E-02 +5.628729E-04 +2.018053E-07 +1.119308E-14 +4.823620E-02 +5.371538E-04 +1.057461E-03 +1.118225E-06 +3.371936E+06 +2.555628E+12 +1.039000E+00 +2.447670E-01 +3.201782E-04 +1.025141E-07 +3.038326E+00 +2.108568E+00 +5.930000E-01 +7.205300E-02 +2.300000E-02 +1.110000E-04 +1.056715E-02 +2.338156E-05 +2.528379E-02 +1.491420E-04 +1.384831E-07 +6.031333E-15 +2.528379E-02 +1.491420E-04 +0.000000E+00 +0.000000E+00 +2.113430E+06 +9.352624E+11 +5.930000E-01 +7.205300E-02 +0.000000E+00 +0.000000E+00 +1.727671E+00 +6.138025E-01 +3.501000E+00 +2.515635E+00 +1.600000E-01 +5.250000E-03 +5.998847E-02 +7.320149E-04 +1.529867E-01 +4.932068E-03 +7.476127E-07 +1.267077E-13 +1.529867E-01 +4.932068E-03 +0.000000E+00 +0.000000E+00 +1.199769E+07 +2.928060E+13 +3.501000E+00 +2.515635E+00 +0.000000E+00 +0.000000E+00 +1.021925E+01 +2.143166E+01 +4.454000E+00 +4.082446E+00 +1.920000E-01 +7.726000E-03 +8.044824E-02 +1.327101E-03 +2.231973E-01 +1.024637E-02 +1.236154E-06 +3.183460E-13 +2.211081E-01 +1.008915E-02 +2.089232E-03 +2.182800E-06 +1.608965E+07 +5.308405E+13 +4.454000E+00 +4.082446E+00 +3.894344E-03 +9.877407E-06 +1.292241E+01 +3.441496E+01 +4.210000E+00 +3.829106E+00 +1.750000E-01 +6.549000E-03 +7.464456E-02 +1.228199E-03 +1.787859E-01 +7.634408E-03 +1.144154E-06 +3.572375E-13 +1.777141E-01 +7.525287E-03 +1.071750E-03 +1.148648E-06 +1.492891E+07 +4.912798E+13 +4.210000E+00 +3.829106E+00 +3.245044E-04 +1.053031E-07 +1.222119E+01 +3.220371E+01 +1.364000E+00 +3.933640E-01 +8.200000E-02 +1.378000E-03 +3.158206E-02 +2.047576E-04 +5.983520E-02 +7.581471E-04 +3.272437E-07 +2.772035E-14 +5.983520E-02 +7.581471E-04 +0.000000E+00 +0.000000E+00 +6.316412E+06 +8.190302E+12 +1.364000E+00 +3.933640E-01 +0.000000E+00 +0.000000E+00 +3.971532E+00 +3.348259E+00 +1.363000E+00 +4.205090E-01 +7.000000E-02 +1.130000E-03 +2.590153E-02 +1.476101E-04 +5.594611E-02 +6.902009E-04 +2.690262E-07 +1.501020E-14 +5.594611E-02 +6.902009E-04 +0.000000E+00 +0.000000E+00 +5.180306E+06 +5.904403E+12 +1.363000E+00 +4.205090E-01 +0.000000E+00 +0.000000E+00 +3.984609E+00 +3.608477E+00 +1.246000E+00 +3.852900E-01 +5.300000E-02 +6.650000E-04 +1.954836E-02 +9.404628E-05 +4.771133E-02 +6.866474E-04 +1.814542E-07 +1.125942E-14 +4.771133E-02 +6.866474E-04 +0.000000E+00 +0.000000E+00 +3.909672E+06 +3.761851E+12 +1.246000E+00 +3.852900E-01 +0.000000E+00 +0.000000E+00 +3.660351E+00 +3.335482E+00 +tally 2: +2.599889E+00 +1.402744E+00 +1.167830E-01 +2.830760E-03 +4.644159E-02 +4.578546E-04 +1.161040E-01 +2.861591E-03 +6.110737E-07 +8.591437E-14 +1.153679E-01 +2.825421E-03 +7.360997E-04 +1.150235E-07 +9.288319E+06 +1.831418E+13 +2.589000E+00 +1.391365E+00 +3.449004E-04 +2.525229E-08 +7.573543E+00 +1.191287E+01 +1.935337E+00 +8.143708E-01 +9.059861E-02 +1.758063E-03 +3.784648E-02 +3.023430E-04 +9.461621E-02 +1.889644E-03 +5.353929E-07 +5.956643E-14 +9.401634E-02 +1.865759E-03 +5.998671E-04 +7.595546E-08 +7.569296E+06 +1.209372E+13 +1.989000E+00 +8.632630E-01 +2.810685E-04 +1.667528E-08 +5.615484E+00 +6.866983E+00 +1.015076E+00 +2.265305E-01 +4.209446E-02 +3.711488E-04 +1.500394E-02 +4.824763E-05 +3.750984E-02 +3.015477E-04 +1.616914E-07 +8.025617E-15 +3.727203E-02 +2.977362E-04 +2.378125E-04 +1.212091E-08 +3.000787E+06 +1.929905E+12 +1.051000E+00 +2.509110E-01 +1.114274E-04 +2.661027E-09 +2.978146E+00 +1.962310E+00 +6.199894E-01 +7.878811E-02 +2.804937E-02 +1.607308E-04 +1.125386E-02 +2.891349E-05 +2.813466E-02 +1.807093E-04 +1.501221E-07 +7.165022E-15 +2.795628E-02 +1.784252E-04 +1.783738E-04 +7.263729E-09 +2.250773E+06 +1.156540E+12 +6.190000E-01 +7.822300E-02 +8.357728E-05 +1.594681E-09 +1.804831E+00 +6.709321E-01 +3.398516E+00 +2.363683E+00 +1.505108E-01 +4.655588E-03 +5.879057E-02 +7.289809E-04 +1.469764E-01 +4.556130E-03 +7.516677E-07 +1.300615E-13 +1.460446E-01 +4.498542E-03 +9.318311E-04 +1.831366E-07 +1.175811E+07 +2.915923E+13 +3.542000E+00 +2.572512E+00 +4.366106E-04 +4.020586E-08 +9.912955E+00 +2.011678E+01 +4.395956E+00 +3.964331E+00 +2.146513E-01 +9.286938E-03 +9.388516E-02 +1.784380E-03 +2.347129E-01 +1.115237E-02 +1.410768E-06 +4.182007E-13 +2.332248E-01 +1.101141E-02 +1.488081E-03 +4.482769E-07 +1.877703E+07 +7.137519E+13 +4.497000E+00 +4.157935E+00 +6.972420E-04 +9.841483E-08 +1.270142E+01 +3.319405E+01 +4.157899E+00 +3.751197E+00 +1.897379E-01 +8.038105E-03 +7.692709E-02 +1.413632E-03 +1.923177E-01 +8.835202E-03 +1.042521E-06 +3.025447E-13 +1.910984E-01 +8.723527E-03 +1.219295E-03 +3.551367E-07 +1.538542E+07 +5.654529E+13 +4.268000E+00 +3.930780E+00 +5.713023E-04 +7.796680E-08 +1.209407E+01 +3.169559E+01 +1.357524E+00 +3.878228E-01 +5.983682E-02 +7.460748E-04 +2.322979E-02 +1.144334E-04 +5.807447E-02 +7.152085E-04 +2.940107E-07 +2.024706E-14 +5.770628E-02 +7.061684E-04 +3.681924E-04 +2.874827E-08 +4.645957E+06 +4.577335E+12 +1.390000E+00 +4.083140E-01 +1.725170E-04 +6.311403E-09 +3.961412E+00 +3.308776E+00 +1.376941E+00 +4.321098E-01 +6.198249E-02 +8.400785E-04 +2.471448E-02 +1.321749E-04 +6.178621E-02 +8.260929E-04 +3.265418E-07 +2.485223E-14 +6.139448E-02 +8.156513E-04 +3.917248E-04 +3.320534E-08 +4.942896E+06 +5.286995E+12 +1.395000E+00 +4.400290E-01 +1.835431E-04 +7.289909E-09 +4.010262E+00 +3.684656E+00 +1.267762E+00 +4.052744E-01 +5.233659E-02 +6.929809E-04 +1.852753E-02 +9.379170E-05 +4.631882E-02 +5.861981E-04 +1.967460E-07 +1.534801E-14 +4.602516E-02 +5.787887E-04 +2.936615E-04 +2.356261E-08 +3.705506E+06 +3.751668E+12 +1.284000E+00 +4.070420E-01 +1.375955E-04 +5.172942E-09 +3.720938E+00 +3.496554E+00 +tally 3: +1.131330E+02 +2.561428E+03 +4.988000E+00 +4.976048E+00 +1.993967E+00 +7.956428E-01 +5.135468E+00 +5.291611E+00 +2.697394E-05 +1.462336E-10 +5.101779E+00 +5.222461E+00 +3.368875E-02 +2.575850E-04 +3.987934E+08 +3.182571E+16 +1.131330E+02 +2.561428E+03 +1.464422E-02 +8.408713E-05 +3.294536E+02 +2.172280E+04 +1.081450E+02 +2.340681E+03 +1.081450E+02 +2.340681E+03 +tally 4: +1.131330E+02 +2.561428E+03 +5.099217E+00 +5.202791E+00 +2.036481E+00 +8.305328E-01 +5.091203E+00 +5.190830E+00 +4.963770E-05 +4.951715E-10 +5.058925E+00 +5.125219E+00 +3.227825E-02 +2.086488E-04 +4.072963E+08 +3.322131E+16 +1.131330E+02 +2.561428E+03 +1.512401E-02 +4.580681E-05 +3.294536E+02 +2.172280E+04 +tally 5: +1.126689E+02 +2.540742E+03 +5.072428E+00 +5.150411E+00 +2.022883E+00 +8.201638E-01 +5.057207E+00 +5.126024E+00 +2.673439E-05 +1.438788E-10 +5.025144E+00 +5.061232E+00 +3.206271E-02 +2.060439E-04 +4.045765E+08 +3.280655E+16 +1.133620E+02 +2.571755E+03 +1.502302E-02 +4.523492E-05 +3.281376E+02 +2.155147E+04 +tally 6: +1.081450E+02 +2.340681E+03 +1.081450E+02 +2.340681E+03 +5.135468E+00 +5.291611E+00 +tally 7: +6.429000E+00 +8.307829E+00 +1.410000E+00 +3.992220E-01 +1.119414E+00 +2.516273E-01 +2.887237E+00 +1.682974E+00 +2.674702E-05 +1.437976E-10 +2.870392E+00 +1.663680E+00 +1.684448E-02 +5.768606E-05 +2.238828E+08 +1.006509E+16 +6.429000E+00 +8.307829E+00 +3.761262E-03 +3.156399E-06 +1.176869E+01 +2.783921E+01 +5.019000E+00 +5.067025E+00 +5.019000E+00 +5.067025E+00 +1.067040E+02 +2.278956E+03 +3.578000E+00 +2.562210E+00 +8.745532E-01 +1.530758E-01 +2.248231E+00 +1.013550E+00 +2.269178E-07 +1.030651E-14 +2.231387E+00 +9.980240E-01 +1.684427E-02 +8.005737E-05 +1.749106E+08 +6.123032E+15 +1.067040E+02 +2.278956E+03 +1.088296E-02 +6.231251E-05 +3.176849E+02 +2.020075E+04 +1.031260E+02 +2.128783E+03 +1.031260E+02 +2.128783E+03 +tally 8: +6.429000E+00 +8.307829E+00 +1.437899E+00 +4.155824E-01 +1.141563E+00 +2.619392E-01 +2.853907E+00 +1.637120E+00 +4.896211E-05 +4.818601E-10 +2.835814E+00 +1.616427E+00 +1.809378E-02 +6.580509E-05 +2.283126E+08 +1.047757E+16 +6.429000E+00 +8.307829E+00 +8.477865E-03 +1.444687E-05 +1.176869E+01 +2.783921E+01 +1.067040E+02 +2.278956E+03 +3.661318E+00 +2.683178E+00 +8.949183E-01 +1.603029E-01 +2.237296E+00 +1.001893E+00 +6.755918E-07 +9.135730E-14 +2.223111E+00 +9.892292E-01 +1.418446E-02 +4.027174E-05 +1.789837E+08 +6.412115E+15 +1.067040E+02 +2.278956E+03 +6.646148E-03 +8.841267E-06 +3.176849E+02 +2.020075E+04 +tally 9: +6.371628E+00 +8.173477E+00 +1.425067E+00 +4.088618E-01 +1.131376E+00 +2.577032E-01 +2.828439E+00 +1.610645E+00 +2.650833E-05 +1.414721E-10 +2.810507E+00 +1.590286E+00 +1.793232E-02 +6.474091E-05 +2.262751E+08 +1.030813E+16 +6.432000E+00 +8.315518E+00 +8.402208E-03 +1.421324E-05 +1.166367E+01 +2.738901E+01 +1.062973E+02 +2.261709E+03 +3.647362E+00 +2.662872E+00 +8.915070E-01 +1.590897E-01 +2.228767E+00 +9.943106E-01 +2.260528E-07 +1.022851E-14 +2.214637E+00 +9.817427E-01 +1.413039E-02 +3.996696E-05 +1.783014E+08 +6.363588E+15 +1.069300E+02 +2.288574E+03 +6.620813E-03 +8.774357E-06 +3.164739E+02 +2.004788E+04 +tally 10: +5.019000E+00 +5.067025E+00 +5.019000E+00 +5.067025E+00 +0.000000E+00 +0.000000E+00 +0.000000E+00 +0.000000E+00 +0.000000E+00 +0.000000E+00 +2.887237E+00 +1.682974E+00 +1.410000E+00 +3.992220E-01 +1.410000E+00 +3.992220E-01 +0.000000E+00 +0.000000E+00 +1.017160E+02 +2.071035E+03 +1.017160E+02 +2.071035E+03 +2.248231E+00 +1.013550E+00 +tally 11: +2.542000E+00 +1.343070E+00 +1.260000E-01 +3.298000E-03 +4.838111E-02 +4.857369E-04 +1.202865E-01 +3.119670E-03 +6.000347E-07 +8.163458E-14 +1.202865E-01 +3.119670E-03 +0.000000E+00 +0.000000E+00 +9.676221E+06 +1.942948E+13 +2.542000E+00 +1.343070E+00 +0.000000E+00 +0.000000E+00 +1.949000E+00 +8.324030E-01 +9.000000E-02 +1.762000E-03 +3.793334E-02 +3.031575E-04 +1.081691E-01 +2.457437E-03 +5.571912E-07 +6.439495E-14 +1.071378E-01 +2.411702E-03 +1.031308E-03 +1.063597E-06 +7.586669E+06 +1.212630E+13 +1.949000E+00 +8.324030E-01 +3.122595E-04 +9.750600E-08 +1.039000E+00 +2.447670E-01 +4.200000E-02 +4.120000E-04 +1.685968E-02 +6.389070E-05 +4.929366E-02 +5.628729E-04 +2.018053E-07 +1.119308E-14 +4.823620E-02 +5.371538E-04 +1.057461E-03 +1.118225E-06 +3.371936E+06 +2.555628E+12 +1.039000E+00 +2.447670E-01 +3.201782E-04 +1.025141E-07 +5.930000E-01 +7.205300E-02 +2.300000E-02 +1.110000E-04 +1.056715E-02 +2.338156E-05 +2.528379E-02 +1.491420E-04 +1.384831E-07 +6.031333E-15 +2.528379E-02 +1.491420E-04 +0.000000E+00 +0.000000E+00 +2.113430E+06 +9.352624E+11 +5.930000E-01 +7.205300E-02 +0.000000E+00 +0.000000E+00 +3.501000E+00 +2.515635E+00 +1.600000E-01 +5.250000E-03 +5.998847E-02 +7.320149E-04 +1.529867E-01 +4.932068E-03 +7.476127E-07 +1.267077E-13 +1.529867E-01 +4.932068E-03 +0.000000E+00 +0.000000E+00 +1.199769E+07 +2.928060E+13 +3.501000E+00 +2.515635E+00 +0.000000E+00 +0.000000E+00 +4.454000E+00 +4.082446E+00 +1.920000E-01 +7.726000E-03 +8.044824E-02 +1.327101E-03 +2.231973E-01 +1.024637E-02 +1.236154E-06 +3.183460E-13 +2.211081E-01 +1.008915E-02 +2.089232E-03 +2.182800E-06 +1.608965E+07 +5.308405E+13 +4.454000E+00 +4.082446E+00 +3.894344E-03 +9.877407E-06 +4.210000E+00 +3.829106E+00 +1.750000E-01 +6.549000E-03 +7.464456E-02 +1.228199E-03 +1.787859E-01 +7.634408E-03 +1.144154E-06 +3.572375E-13 +1.777141E-01 +7.525287E-03 +1.071750E-03 +1.148648E-06 +1.492891E+07 +4.912798E+13 +4.210000E+00 +3.829106E+00 +3.245044E-04 +1.053031E-07 +1.364000E+00 +3.933640E-01 +8.200000E-02 +1.378000E-03 +3.158206E-02 +2.047576E-04 +5.983520E-02 +7.581471E-04 +3.272437E-07 +2.772035E-14 +5.983520E-02 +7.581471E-04 +0.000000E+00 +0.000000E+00 +6.316412E+06 +8.190302E+12 +1.364000E+00 +3.933640E-01 +0.000000E+00 +0.000000E+00 +1.363000E+00 +4.205090E-01 +7.000000E-02 +1.130000E-03 +2.590153E-02 +1.476101E-04 +5.594611E-02 +6.902009E-04 +2.690262E-07 +1.501020E-14 +5.594611E-02 +6.902009E-04 +0.000000E+00 +0.000000E+00 +5.180306E+06 +5.904403E+12 +1.363000E+00 +4.205090E-01 +0.000000E+00 +0.000000E+00 +1.246000E+00 +3.852900E-01 +5.300000E-02 +6.650000E-04 +1.954836E-02 +9.404628E-05 +4.771133E-02 +6.866474E-04 +1.814542E-07 +1.125942E-14 +4.771133E-02 +6.866474E-04 +0.000000E+00 +0.000000E+00 +3.909672E+06 +3.761851E+12 +1.246000E+00 +3.852900E-01 +0.000000E+00 +0.000000E+00 +tally 12: +2.599889E+00 +1.402744E+00 +1.167830E-01 +2.830760E-03 +4.644159E-02 +4.578546E-04 +1.161040E-01 +2.861591E-03 +6.110737E-07 +8.591437E-14 +1.153679E-01 +2.825421E-03 +7.360997E-04 +1.150235E-07 +9.288319E+06 +1.831418E+13 +2.589000E+00 +1.391365E+00 +3.449004E-04 +2.525229E-08 +1.935337E+00 +8.143708E-01 +9.059861E-02 +1.758063E-03 +3.784648E-02 +3.023430E-04 +9.461621E-02 +1.889644E-03 +5.353929E-07 +5.956643E-14 +9.401634E-02 +1.865759E-03 +5.998671E-04 +7.595546E-08 +7.569296E+06 +1.209372E+13 +1.989000E+00 +8.632630E-01 +2.810685E-04 +1.667528E-08 +1.015076E+00 +2.265305E-01 +4.209446E-02 +3.711488E-04 +1.500394E-02 +4.824763E-05 +3.750984E-02 +3.015477E-04 +1.616914E-07 +8.025617E-15 +3.727203E-02 +2.977362E-04 +2.378125E-04 +1.212091E-08 +3.000787E+06 +1.929905E+12 +1.051000E+00 +2.509110E-01 +1.114274E-04 +2.661027E-09 +6.199894E-01 +7.878811E-02 +2.804937E-02 +1.607308E-04 +1.125386E-02 +2.891349E-05 +2.813466E-02 +1.807093E-04 +1.501221E-07 +7.165022E-15 +2.795628E-02 +1.784252E-04 +1.783738E-04 +7.263729E-09 +2.250773E+06 +1.156540E+12 +6.190000E-01 +7.822300E-02 +8.357728E-05 +1.594681E-09 +3.398516E+00 +2.363683E+00 +1.505108E-01 +4.655588E-03 +5.879057E-02 +7.289809E-04 +1.469764E-01 +4.556130E-03 +7.516677E-07 +1.300615E-13 +1.460446E-01 +4.498542E-03 +9.318311E-04 +1.831366E-07 +1.175811E+07 +2.915923E+13 +3.542000E+00 +2.572512E+00 +4.366106E-04 +4.020586E-08 +4.395956E+00 +3.964331E+00 +2.146513E-01 +9.286938E-03 +9.388516E-02 +1.784380E-03 +2.347129E-01 +1.115237E-02 +1.410768E-06 +4.182007E-13 +2.332248E-01 +1.101141E-02 +1.488081E-03 +4.482769E-07 +1.877703E+07 +7.137519E+13 +4.497000E+00 +4.157935E+00 +6.972420E-04 +9.841483E-08 +4.157899E+00 +3.751197E+00 +1.897379E-01 +8.038105E-03 +7.692709E-02 +1.413632E-03 +1.923177E-01 +8.835202E-03 +1.042521E-06 +3.025447E-13 +1.910984E-01 +8.723527E-03 +1.219295E-03 +3.551367E-07 +1.538542E+07 +5.654529E+13 +4.268000E+00 +3.930780E+00 +5.713023E-04 +7.796680E-08 +1.357524E+00 +3.878228E-01 +5.983682E-02 +7.460748E-04 +2.322979E-02 +1.144334E-04 +5.807447E-02 +7.152085E-04 +2.940107E-07 +2.024706E-14 +5.770628E-02 +7.061684E-04 +3.681924E-04 +2.874827E-08 +4.645957E+06 +4.577335E+12 +1.390000E+00 +4.083140E-01 +1.725170E-04 +6.311403E-09 +1.376941E+00 +4.321098E-01 +6.198249E-02 +8.400785E-04 +2.471448E-02 +1.321749E-04 +6.178621E-02 +8.260929E-04 +3.265418E-07 +2.485223E-14 +6.139448E-02 +8.156513E-04 +3.917248E-04 +3.320534E-08 +4.942896E+06 +5.286995E+12 +1.395000E+00 +4.400290E-01 +1.835431E-04 +7.289909E-09 +1.267762E+00 +4.052744E-01 +5.233659E-02 +6.929809E-04 +1.852753E-02 +9.379170E-05 +4.631882E-02 +5.861981E-04 +1.967460E-07 +1.534801E-14 +4.602516E-02 +5.787887E-04 +2.936615E-04 +2.356261E-08 +3.705506E+06 +3.751668E+12 +1.284000E+00 +4.070420E-01 +1.375955E-04 +5.172942E-09 +tally 13: +1.131330E+02 +2.561428E+03 +4.988000E+00 +4.976048E+00 +1.993967E+00 +7.956428E-01 +5.135468E+00 +5.291611E+00 +2.697394E-05 +1.462336E-10 +5.101779E+00 +5.222461E+00 +3.368875E-02 +2.575850E-04 +3.987934E+08 +3.182571E+16 +1.131330E+02 +2.561428E+03 +1.464422E-02 +8.408713E-05 +1.081450E+02 +2.340681E+03 +1.081450E+02 +2.340681E+03 +tally 14: +1.131330E+02 +2.561428E+03 +5.099217E+00 +5.202791E+00 +2.036481E+00 +8.305328E-01 +5.091203E+00 +5.190830E+00 +4.963770E-05 +4.951715E-10 +5.058925E+00 +5.125219E+00 +3.227825E-02 +2.086488E-04 +4.072963E+08 +3.322131E+16 +1.131330E+02 +2.561428E+03 +1.512401E-02 +4.580681E-05 +tally 15: +1.126689E+02 +2.540742E+03 +5.072428E+00 +5.150411E+00 +2.022883E+00 +8.201638E-01 +5.057207E+00 +5.126024E+00 +2.673439E-05 +1.438788E-10 +5.025144E+00 +5.061232E+00 +3.206271E-02 +2.060439E-04 +4.045765E+08 +3.280655E+16 +1.133620E+02 +2.571755E+03 +1.502302E-02 +4.523492E-05 +tally 16: +1.081450E+02 +2.340681E+03 +1.081450E+02 +2.340681E+03 +5.135468E+00 +5.291611E+00 +tally 17: +6.429000E+00 +8.307829E+00 +1.410000E+00 +3.992220E-01 +1.119414E+00 +2.516273E-01 +2.887237E+00 +1.682974E+00 +2.674702E-05 +1.437976E-10 +2.870392E+00 +1.663680E+00 +1.684448E-02 +5.768606E-05 +2.238828E+08 +1.006509E+16 +6.429000E+00 +8.307829E+00 +3.761262E-03 +3.156399E-06 +5.019000E+00 +5.067025E+00 +5.019000E+00 +5.067025E+00 +1.067040E+02 +2.278956E+03 +3.578000E+00 +2.562210E+00 +8.745532E-01 +1.530758E-01 +2.248231E+00 +1.013550E+00 +2.269178E-07 +1.030651E-14 +2.231387E+00 +9.980240E-01 +1.684427E-02 +8.005737E-05 +1.749106E+08 +6.123032E+15 +1.067040E+02 +2.278956E+03 +1.088296E-02 +6.231251E-05 +1.031260E+02 +2.128783E+03 +1.031260E+02 +2.128783E+03 +tally 18: +6.429000E+00 +8.307829E+00 +1.437899E+00 +4.155824E-01 +1.141563E+00 +2.619392E-01 +2.853907E+00 +1.637120E+00 +4.896211E-05 +4.818601E-10 +2.835814E+00 +1.616427E+00 +1.809378E-02 +6.580509E-05 +2.283126E+08 +1.047757E+16 +6.429000E+00 +8.307829E+00 +8.477865E-03 +1.444687E-05 +1.067040E+02 +2.278956E+03 +3.661318E+00 +2.683178E+00 +8.949183E-01 +1.603029E-01 +2.237296E+00 +1.001893E+00 +6.755918E-07 +9.135730E-14 +2.223111E+00 +9.892292E-01 +1.418446E-02 +4.027174E-05 +1.789837E+08 +6.412115E+15 +1.067040E+02 +2.278956E+03 +6.646148E-03 +8.841267E-06 +tally 19: +6.371628E+00 +8.173477E+00 +1.425067E+00 +4.088618E-01 +1.131376E+00 +2.577032E-01 +2.828439E+00 +1.610645E+00 +2.650833E-05 +1.414721E-10 +2.810507E+00 +1.590286E+00 +1.793232E-02 +6.474091E-05 +2.262751E+08 +1.030813E+16 +6.432000E+00 +8.315518E+00 +8.402208E-03 +1.421324E-05 +1.062973E+02 +2.261709E+03 +3.647362E+00 +2.662872E+00 +8.915070E-01 +1.590897E-01 +2.228767E+00 +9.943106E-01 +2.260528E-07 +1.022851E-14 +2.214637E+00 +9.817427E-01 +1.413039E-02 +3.996696E-05 +1.783014E+08 +6.363588E+15 +1.069300E+02 +2.288574E+03 +6.620813E-03 +8.774357E-06 +tally 20: +5.019000E+00 +5.067025E+00 +5.019000E+00 +5.067025E+00 +0.000000E+00 +0.000000E+00 +0.000000E+00 +0.000000E+00 +0.000000E+00 +0.000000E+00 +2.887237E+00 +1.682974E+00 +1.410000E+00 +3.992220E-01 +1.410000E+00 +3.992220E-01 +0.000000E+00 +0.000000E+00 +1.017160E+02 +2.071035E+03 +1.017160E+02 +2.071035E+03 +2.248231E+00 +1.013550E+00 diff --git a/tests/regression_tests/mg_tallies/test.py b/tests/regression_tests/mg_tallies/test.py index e1c19e6b7e..f4e9693f6f 100644 --- a/tests/regression_tests/mg_tallies/test.py +++ b/tests/regression_tests/mg_tallies/test.py @@ -5,7 +5,7 @@ import numpy as np import openmc from openmc.examples import slab_mg -from tests.testing_harness import HashedPyAPITestHarness +from tests.testing_harness import PyAPITestHarness def create_library(): @@ -49,7 +49,7 @@ def create_library(): mg_cross_sections_file.export_to_hdf5('2g.h5') -class MGXSTestHarness(HashedPyAPITestHarness): +class MGXSTestHarness(PyAPITestHarness): def _cleanup(self): super()._cleanup() f = '2g.h5' @@ -144,5 +144,5 @@ def test_mg_tallies(): t.nuclides = nuclides model.tallies.append(t) - harness = HashedPyAPITestHarness('statepoint.10.h5', model) + harness = MGXSTestHarness('statepoint.10.h5', model) harness.main() diff --git a/tests/testing_harness.py b/tests/testing_harness.py index 0d3c4bec00..2266189c05 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -10,9 +10,25 @@ import sys import numpy as np import openmc from openmc.examples import pwr_core +from colorama import Fore, init from tests.regression_tests import config +init() + + +def colorize(diff): + """Produce colored diff for test results""" + for line in diff: + if line.startswith('+'): + yield Fore.RED + line + Fore.RESET + elif line.startswith('-'): + yield Fore.GREEN + line + Fore.RESET + elif line.startswith('^'): + yield Fore.BLUE + line + Fore.RESET + else: + yield line + class TestHarness(object): """General class for running OpenMC regression tests.""" @@ -108,11 +124,17 @@ class TestHarness(object): shutil.copyfile('results_test.dat', 'results_true.dat') def _compare_results(self): - """Make sure the current results agree with the _true standard.""" + """Make sure the current results agree with the reference.""" compare = filecmp.cmp('results_test.dat', 'results_true.dat') if not compare: + expected = open('results_true.dat').readlines() + actual = open('results_test.dat').readlines() + diff = unified_diff(expected, actual, 'results_true.dat', + 'results_test.dat') + print('Result differences:') + print(''.join(colorize(diff))) os.rename('results_test.dat', 'results_error.dat') - assert compare, 'Results do not agree.' + assert compare, 'Results do not agree' def _cleanup(self): """Delete statepoints, tally, and test files.""" @@ -325,11 +347,13 @@ class PyAPITestHarness(TestHarness): """Make sure the current inputs agree with the _true standard.""" compare = filecmp.cmp('inputs_test.dat', 'inputs_true.dat') if not compare: + expected = open('inputs_true.dat', 'r').readlines() + actual = open('inputs_error.dat', 'r').readlines() + diff = unified_diff(expected, actual, 'inputs_true.dat', + 'inputs_error.dat') + print('Input differences:') + print(''.join(colorize(diff))) os.rename('inputs_test.dat', 'inputs_error.dat') - for line in unified_diff(open('inputs_true.dat', 'r').readlines(), - open('inputs_error.dat', 'r').readlines(), - 'inputs_true.dat', 'inputs_error.dat'): - print(line, end='') assert compare, 'Input files are broken.' def _cleanup(self):