Convert source distributions to C++

This commit is contained in:
Paul Romano 2018-07-17 06:43:35 -05:00
parent 44cb9a990f
commit b92677e70b
31 changed files with 629 additions and 1227 deletions

View file

@ -30,7 +30,6 @@ extern "C" {
int openmc_extend_filters(int32_t n, int32_t* index_start, int32_t* index_end);
int openmc_extend_materials(int32_t n, int32_t* index_start, int32_t* index_end);
int openmc_extend_meshes(int32_t n, int32_t* index_start, int32_t* index_end);
int openmc_extend_sources(int32_t n, int32_t* index_start, int32_t* index_end);
int openmc_extend_tallies(int32_t n, int32_t* index_start, int32_t* index_end);
int openmc_filter_get_id(int32_t index, int32_t* id);
int openmc_filter_get_type(int32_t index, char* type);
@ -57,6 +56,7 @@ extern "C" {
int openmc_material_add_nuclide(int32_t index, const char name[], double density);
int openmc_material_get_densities(int32_t index, int** nuclides, double** densities, int* n);
int openmc_material_get_id(int32_t index, int32_t* id);
int openmc_material_get_fissionable(int32_t index, bool* fissionable);
int openmc_material_get_volume(int32_t index, double* volume);
int openmc_material_set_density(int32_t index, double density);
int openmc_material_set_densities(int32_t index, int n, const char** name, const double* density);
@ -84,7 +84,6 @@ extern "C" {
int openmc_simulation_finalize();
int openmc_simulation_init();
int openmc_source_bank(struct Bank** ptr, int64_t* n);
int openmc_source_set_strength(int32_t index, double strength);
int openmc_spatial_legendre_filter_get_order(int32_t index, int* order);
int openmc_spatial_legendre_filter_get_params(int32_t index, int* axis, double* min, double* max);
int openmc_spatial_legendre_filter_set_order(int32_t index, int order);

View file

@ -36,6 +36,9 @@ public:
//! Sample a value from the distribution
//! \return Sampled value
double sample() const;
const std::vector<double>& x() const { return x_; }
const std::vector<double>& p() const { return p_; }
private:
std::vector<double> x_; //!< Possible outcomes
std::vector<double> p_; //!< Probability of each outcome

View file

@ -73,6 +73,8 @@ public:
Direction sample() const;
};
using UPtrAngle = std::unique_ptr<UnitSphereDistribution>;
} // namespace openmc
#endif // DISTRIBUTION_MULTI_H

View file

@ -1,4 +1,4 @@
#ifndef OPENMC_DISTRIBTUION_SPATIAL_H
#ifndef OPENMC_DISTRIBUTION_SPATIAL_H
#define OPENMC_DISTRIBUTION_SPATIAL_H
#include "pugixml.hpp"
@ -48,10 +48,11 @@ public:
//! Sample a position from the distribution
//! \return Sampled position
Position sample() const;
bool only_fissionable() const { return only_fissionable_; }
private:
Position lower_left_; //!< Lower-left coordinates of box
Position upper_right_; //!< Upper-right coordinates of box
bool only_fissionable {false}; //!< Only accept sites in fissionable region?
bool only_fissionable_ {false}; //!< Only accept sites in fissionable region?
};
//==============================================================================
@ -61,6 +62,7 @@ private:
class SpatialPoint : public SpatialDistribution {
public:
SpatialPoint() : r_{} { };
SpatialPoint(Position r) : r_{r} { };
explicit SpatialPoint(pugi::xml_node node);
//! Sample a position from the distribution
@ -70,6 +72,8 @@ private:
Position r_; //!< Single position at which sites are generated
};
using UPtrSpace = std::unique_ptr<SpatialDistribution>;
} // namespace openmc
#endif // OPENMC_DISTRIBUTION_SPATIAL_H

View file

@ -0,0 +1,17 @@
#ifndef OPENMC_FILE_UTILS_H
#define OPENMC_FILE_UTILS_H
#include <fstream> // for ifstream
#include <string>
namespace openmc {
inline bool file_exists(const std::string& filename)
{
std::ifstream s {filename};
return s.good();
}
}
#endif // OPENMC_FILE_UTILS_H

View file

@ -16,6 +16,7 @@ namespace openmc {
extern std::vector<Mgxs> nuclides_MG;
extern std::vector<Mgxs> macro_xs;
extern "C" int num_energy_groups;
//==============================================================================
// Mgxs data loading interface methods

View file

@ -1,10 +1,15 @@
#ifndef OPENMC_NUCLIDE_H
#define OPENMC_NUCLIDE_H
#include <array>
#include "openmc/constants.h"
namespace openmc {
extern std::array<double, 2> energy_min;
extern std::array<double, 2> energy_max;
//===============================================================================
//! Cached microscopic cross sections for a particular nuclide at the current
//! energy

View file

@ -33,7 +33,7 @@ constexpr double REL_MAX_LOST_PARTICLES {1.0e-6};
//! Particle types
enum class ParticleType {
neutron, photon, electron, positron
neutron = 1, photon = 2, electron = 3, positron = 4
};
extern "C" {

View file

@ -18,8 +18,11 @@ namespace openmc {
// Defined on Fortran side
extern "C" bool openmc_check_overlaps;
extern "C" bool openmc_particle_restart_run;
extern "C" bool openmc_photon_transport;
extern "C" bool openmc_restart_run;
extern "C" bool openmc_run_CE;
extern "C" bool openmc_write_all_tracks;
extern "C" bool openmc_write_initial_source;
// Defined in .cpp
// TODO: Make strings instead of char* once Fortran is gone

View file

@ -2,12 +2,23 @@
#define OPENMC_SIMULATION_H
#include <cstdint>
#include <vector>
namespace openmc {
extern "C" int openmc_current_batch;
extern "C" int openmc_current_gen;
extern "C" int64_t openmc_current_work;
extern "C" int openmc_n_lost_particles;
extern "C" int openmc_total_gen;
extern std::vector<int64_t> work_index;
#pragma omp threadprivate(openmc_current_work)
extern "C" void openmc_simulation_init_c();
void calculate_work();
} // namespace openmc
#endif // OPENMC_SIMULATION_H

54
include/openmc/source.h Normal file
View file

@ -0,0 +1,54 @@
#ifndef OPENMC_SOURCE_H
#define OPENMC_SOURCE_H
#include <memory>
#include <vector>
#include "pugixml.hpp"
#include "openmc/distribution_multi.h"
#include "openmc/distribution_spatial.h"
#include "openmc/capi.h"
#include "openmc/particle.h"
namespace openmc {
//==============================================================================
//! External source distribution
//==============================================================================
class SourceDistribution {
public:
SourceDistribution(UPtrSpace space, UPtrAngle angle, UPtrDist energy);
explicit SourceDistribution(pugi::xml_node node);
Bank sample() const;
double strength() const { return strength_; }
private:
ParticleType particle_ {ParticleType::neutron};
double strength_ {1.0};
UPtrSpace space_;
UPtrAngle angle_;
UPtrDist energy_;
};
//==============================================================================
// Global variables
//==============================================================================
extern std::vector<SourceDistribution> external_sources;
//==============================================================================
// Functions
//==============================================================================
//! Initialize source bank from file/distribution
extern "C" void initialize_source();
//! Sample a site from all external source distributions in proportion to their
//! source strength
extern "C" Bank sample_external_source();
} // namespace openmc
#endif // OPENMC_SOURCE_H