-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Model updates + material volumes and energy spectrum post-processing (#…
…166) *Updated FNR and Nuscale models *A material volumes file is now written when an MPACT model is written *Added post-processing utilities for computing the energy spectrum
- Loading branch information
1 parent
85c53cb
commit ca91953
Showing
8 changed files
with
1,068 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
um2_add_executable(./fnr_heu_2d_single_asy.cpp) | ||
#um2_add_executable(./fnr_heu_2d.cpp) | ||
um2_add_executable(./fnr_leu_2d_variable_grid.cpp) | ||
um2_add_executable(./fnr_leu_2d_advanced_mesh.cpp) |
Large diffs are not rendered by default.
Oops, something went wrong.
144 changes: 70 additions & 74 deletions
144
models/fnr/fnr_heu_2d.cpp → models/fnr/fnr_leu_2d_variable_grid.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include <um2.hpp> | ||
|
||
// NOLINTBEGIN(misc-include-cleaner) | ||
#include <um2/stdlib/algorithm/is_sorted.hpp> | ||
|
||
PURE [[nodiscard]] auto | ||
getSpectrum(um2::String const & filename) -> um2::Vector<Float>; | ||
|
||
template <Int P, Int N> | ||
PURE [[nodiscard]] auto | ||
getSpectrum(um2::PolytopeSoup const & soup) -> um2::Vector<Float>; | ||
|
||
auto | ||
main(int argc, char ** argv) -> int | ||
{ | ||
um2::initialize(); | ||
|
||
// Get the file name from the command line | ||
if (argc != 2) { | ||
um2::String const exec_name(argv[0]); | ||
LOG_ERROR("Usage: ", exec_name, " <filename>"); | ||
return 1; | ||
} | ||
|
||
// Get the spectrum | ||
um2::String const filename(argv[1]); | ||
auto const spectrum = getSpectrum(filename); | ||
|
||
// Write the spectrum to a file | ||
FILE * file = fopen("spectrum.txt", "w"); | ||
if (file == nullptr) { | ||
LOG_ERROR("Could not open file spectrum.txt"); | ||
return 1; | ||
} | ||
|
||
for (Int g = 0; g < spectrum.size(); ++g) { | ||
// Write group number and flux to file | ||
int const ret = fprintf(file, "%d, %.16f\n", g, spectrum[g]); | ||
if (ret < 0) { | ||
LOG_ERROR("Could not write to file spectrum.txt"); | ||
return 1; | ||
} | ||
} | ||
int const ret = fclose(file); | ||
if (ret != 0) { | ||
LOG_ERROR("Could not close file spectrum.txt"); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
PURE [[nodiscard]] auto | ||
getSpectrum(um2::String const & filename) -> um2::Vector<Float> | ||
{ | ||
um2::PolytopeSoup const soup(filename); | ||
// For now, we assume that all the elements are the same type. | ||
auto const elem_types = soup.getElemTypes(); | ||
if (elem_types.size() != 1) { | ||
LOG_ERROR("Expected only one element type, but found ", elem_types.size()); | ||
return {}; | ||
} | ||
switch (elem_types[0]) { | ||
case um2::VTKElemType::Triangle: | ||
LOG_INFO("FSR mesh type: Triangle"); | ||
return getSpectrum<1, 3>(soup); | ||
case um2::VTKElemType::Quad: | ||
LOG_INFO("FSR mesh type: Quad"); | ||
return getSpectrum<1, 4>(soup); | ||
case um2::VTKElemType::QuadraticTriangle: | ||
LOG_INFO("FSR mesh type: QuadraticTriangle"); | ||
return getSpectrum<2, 6>(soup); | ||
case um2::VTKElemType::QuadraticQuad: | ||
LOG_INFO("FSR mesh type: QuadraticQuad"); | ||
return getSpectrum<2, 8>(soup); | ||
default: | ||
LOG_ERROR("Unsupported element type"); | ||
return {}; | ||
} | ||
} | ||
|
||
template <Int P, Int N> | ||
PURE [[nodiscard]] auto | ||
getSpectrum(um2::PolytopeSoup const & soup) -> um2::Vector<Float> | ||
{ | ||
um2::FaceVertexMesh<P, N> const fvm(soup, /*validate=*/false); | ||
Int const num_faces = fvm.numFaces(); | ||
|
||
// Get the area of each face | ||
um2::Vector<Float> face_areas(num_faces); | ||
for (Int i = 0; i < num_faces; ++i) { | ||
face_areas[i] = fvm.getFace(i).area(); | ||
} | ||
|
||
um2::Vector<Float> spectrum; | ||
um2::Vector<Int> ids; | ||
um2::Vector<Float> flux; | ||
um2::String elset_name("flux_001"); | ||
while (true) { | ||
flux.clear(); | ||
soup.getElset(elset_name, ids, flux); | ||
if (flux.empty()) { | ||
break; | ||
} | ||
ASSERT(ids.size() == flux.size()); | ||
ASSERT(ids.size() == num_faces); | ||
ASSERT(um2::is_sorted(ids.cbegin(), ids.cend())); | ||
Float group_flux = 0; | ||
Float local_accum = 0; | ||
for (Int i = 0; i < ids.size(); ++i) { | ||
local_accum += flux[i] * face_areas[i]; | ||
// Increment group flux every 128 faces | ||
if (i % 128 == 127) { | ||
group_flux += local_accum; | ||
local_accum = 0; | ||
} | ||
} | ||
group_flux += local_accum; | ||
spectrum.emplace_back(group_flux); | ||
um2::mpact::incrementASCIINumber(elset_name); | ||
} | ||
return spectrum; | ||
} | ||
|
||
// NOLINTEND(misc-include-cleaner) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import sys | ||
|
||
# Get the file name from the command line | ||
if len(sys.argv) != 2: | ||
print('Usage: python plot_spectrum.py <file_name>') | ||
sys.exit(1) | ||
|
||
file_name = sys.argv[1] | ||
|
||
# Read file with data of the form: group, neutrons/sec | ||
data = np.loadtxt(file_name, delimiter=',') | ||
neutrons = data[:, 1] | ||
|
||
total_neutrons = np.sum(neutrons) | ||
plt.stairs(neutrons/total_neutrons) | ||
plt.xlabel('Group') | ||
plt.ylabel('Normalized Neutrons/sec') | ||
plt.title('Normalized Energy Spectrum') | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters