BioCMAMC-ST
mcinit.hpp
1#ifndef __MC_INIT_HPP__
2#define __MC_INIT_HPP__
3
4#include <biocma_cst_config.hpp>
5#include <cassert>
6#include <common/execinfo.hpp>
7#include <common/logger.hpp>
8#include <cstdint>
9#include <mc/domain.hpp>
10#include <mc/particles_container.hpp>
11#include <mc/traits.hpp>
12#include <mc/unit.hpp>
13#include <memory>
14#include <span>
15#include <stdexcept>
16#include <utility>
17
18namespace
19{
20 template <ModelType Model>
21 void
22 log_model_info(const std::shared_ptr<IO::Logger>& _logger)
23 {
24 if constexpr (ConstWeightModelType<Model>)
25 {
26 if (_logger)
27 {
28 if constexpr (has_name<Model>)
29 {
30 _logger->print("Model", IO::format(Model::name, " Const Weights"));
31 }
32 else
33 {
34 _logger->print("Model", "Const Weights");
35 }
36 }
37 }
38 }
39} // namespace
40
41namespace MC
42{
43
44 void impl_init(double& total_mass,
45 uint64_t n_particles,
46 MonteCarloUnit& unit,
47 AutoGenerated::ContainerVariant&& container,
48 bool uniform_init);
49
50 void post_init_weight(std::unique_ptr<MonteCarloUnit>& unit,
51 double x0,
52 double total_mass);
67 template <ModelType Model>
68 std::unique_ptr<MonteCarloUnit>
69 init(const std::shared_ptr<IO::Logger>& _logger,
70 uint64_t n_particles,
71 std::size_t n_samples,
72 std::span<double> volumes,
73 std::span<const size_t> _neighbors,
74 bool uniform_mc_init,
75 double& total_mass)
76 {
77 (void)_neighbors; // TODO remove
78 log_model_info<Model>(_logger);
79
80 auto unit = std::make_unique<MonteCarloUnit>();
81 unit->domain = ReactorDomain(volumes);
82
83 auto container = ParticlesContainer<Model>(
84 load_tuning_constant(), n_particles, n_samples);
85 try
86 {
87 impl_init(total_mass,
88 n_particles,
89 *unit,
90 std::move(container),
91 uniform_mc_init);
92 }
93 catch (const std::runtime_error& e)
94 {
95
96 if (_logger)
97 {
98 _logger->error(e.what());
99 }
100
101 return nullptr;
102 }
103
104 return unit;
105 }
106
107} // namespace MC
108
109#endif //__MC_INIT_HPP__
Main owning object for Monte-Carlo particles.
Definition particles_container.hpp:57
Represents the spatial domain where Monte Carlo particles can exist.
Definition domain.hpp:55
Concept to check if a model type has uniform_weight
Definition traits.hpp:201
Definition traits.hpp:51
std::string format(MsgType &&... msgs)
Definition logger.hpp:132
Namespace that contains classes and structures related to Monte Carlo (MC) simulations.
Definition alias.hpp:16
std::unique_ptr< MonteCarloUnit > init(const std::shared_ptr< IO::Logger > &_logger, uint64_t n_particles, std::size_t n_samples, std::span< double > volumes, std::span< const size_t > _neighbors, bool uniform_mc_init, double &total_mass)
Helper function to initialize a MonteCarloUnit.
Definition mcinit.hpp:69
RuntimeParameters load_tuning_constant()
Definition unit.cpp:309
void impl_init(double &total_mass, uint64_t n_particles, MonteCarloUnit &unit, AutoGenerated::ContainerVariant &&container, bool uniform_init)
Definition unit.cpp:260
void post_init_weight(std::unique_ptr< MonteCarloUnit > &unit, double x0, double total_mass)
Definition unit.cpp:233
General-purpose Monte Carlo unit to carry out simulations.
Definition unit.hpp:34