mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Ability to compute material volume fractions over mesh elements (#2802)
This commit is contained in:
parent
2c5b740738
commit
187160d082
8 changed files with 360 additions and 39 deletions
|
|
@ -105,6 +105,9 @@ int openmc_mesh_filter_get_translation(int32_t index, double translation[3]);
|
|||
int openmc_mesh_filter_set_translation(int32_t index, double translation[3]);
|
||||
int openmc_mesh_get_id(int32_t index, int32_t* id);
|
||||
int openmc_mesh_set_id(int32_t index, int32_t id);
|
||||
int openmc_mesh_get_n_elements(int32_t index, size_t* n);
|
||||
int openmc_mesh_material_volumes(int32_t index, int n_sample, int bin,
|
||||
int result_size, void* result, int* hits, uint64_t* seed);
|
||||
int openmc_meshsurface_filter_get_mesh(int32_t index, int32_t* index_mesh);
|
||||
int openmc_meshsurface_filter_set_mesh(int32_t index, int32_t index_mesh);
|
||||
int openmc_new_filter(const char* type, int32_t* index);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "hdf5.h"
|
||||
#include "pugixml.hpp"
|
||||
#include "xtensor/xtensor.hpp"
|
||||
#include <gsl/gsl-lite.hpp>
|
||||
|
||||
#include "openmc/error.h"
|
||||
#include "openmc/memory.h" // for unique_ptr
|
||||
|
|
@ -69,6 +70,12 @@ extern const libMesh::Parallel::Communicator* libmesh_comm;
|
|||
|
||||
class Mesh {
|
||||
public:
|
||||
// Types, aliases
|
||||
struct MaterialVolume {
|
||||
int32_t material; //!< material index
|
||||
double volume; //!< volume in [cm^3]
|
||||
};
|
||||
|
||||
// Constructors and destructor
|
||||
Mesh() = default;
|
||||
Mesh(pugi::xml_node node);
|
||||
|
|
@ -159,9 +166,28 @@ public:
|
|||
|
||||
virtual std::string get_mesh_type() const = 0;
|
||||
|
||||
//! Determine volume of materials within a single mesh elemenet
|
||||
//
|
||||
//! \param[in] n_sample Number of samples within each element
|
||||
//! \param[in] bin Index of mesh element
|
||||
//! \param[out] Array of (material index, volume) for desired element
|
||||
//! \param[inout] seed Pseudorandom number seed
|
||||
//! \return Number of materials within element
|
||||
int material_volumes(int n_sample, int bin, gsl::span<MaterialVolume> volumes,
|
||||
uint64_t* seed) const;
|
||||
|
||||
//! Determine volume of materials within a single mesh elemenet
|
||||
//
|
||||
//! \param[in] n_sample Number of samples within each element
|
||||
//! \param[in] bin Index of mesh element
|
||||
//! \param[inout] seed Pseudorandom number seed
|
||||
//! \return Vector of (material index, volume) for desired element
|
||||
vector<MaterialVolume> material_volumes(
|
||||
int n_sample, int bin, uint64_t* seed) const;
|
||||
|
||||
// Data members
|
||||
int id_ {-1}; //!< User-specified ID
|
||||
int n_dimension_; //!< Number of dimensions
|
||||
int id_ {-1}; //!< User-specified ID
|
||||
int n_dimension_ {-1}; //!< Number of dimensions
|
||||
};
|
||||
|
||||
class StructuredMesh : public Mesh {
|
||||
|
|
|
|||
|
|
@ -1,18 +1,23 @@
|
|||
#ifndef OPENMC_VOLUME_CALC_H
|
||||
#define OPENMC_VOLUME_CALC_H
|
||||
|
||||
#include <algorithm> // for find
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "openmc/array.h"
|
||||
#include "openmc/openmp_interface.h"
|
||||
#include "openmc/position.h"
|
||||
#include "openmc/tallies/trigger.h"
|
||||
#include "openmc/vector.h"
|
||||
|
||||
#include "pugixml.hpp"
|
||||
#include "xtensor/xtensor.hpp"
|
||||
|
||||
#include <gsl/gsl-lite.hpp>
|
||||
#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
namespace openmc {
|
||||
|
||||
|
|
@ -89,6 +94,35 @@ extern vector<VolumeCalculation> volume_calcs;
|
|||
// Non-member functions
|
||||
//==============================================================================
|
||||
|
||||
//! Reduce vector of indices and hits from each thread to a single copy
|
||||
//
|
||||
//! \param[in] local_indices Indices specific to each thread
|
||||
//! \param[in] local_hits Hit count specific to each thread
|
||||
//! \param[out] indices Reduced vector of indices
|
||||
//! \param[out] hits Reduced vector of hits
|
||||
template<typename T, typename T2>
|
||||
void reduce_indices_hits(const vector<T>& local_indices,
|
||||
const vector<T2>& local_hits, vector<T>& indices, vector<T2>& hits)
|
||||
{
|
||||
const int n_threads = num_threads();
|
||||
|
||||
#pragma omp for ordered schedule(static, 1)
|
||||
for (int i = 0; i < n_threads; ++i) {
|
||||
#pragma omp ordered
|
||||
for (int j = 0; j < local_indices.size(); ++j) {
|
||||
// Check if this material has been added to the master list and if
|
||||
// so, accumulate the number of hits
|
||||
auto it = std::find(indices.begin(), indices.end(), local_indices[j]);
|
||||
if (it == indices.end()) {
|
||||
indices.push_back(local_indices[j]);
|
||||
hits.push_back(local_hits[j]);
|
||||
} else {
|
||||
hits[it - indices.begin()] += local_hits[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void free_memory_volume();
|
||||
|
||||
} // namespace openmc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue