forked from ZakayZ/FermiBreakUp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dependency injection with FermiBreakUp and Configurations
- Loading branch information
Showing
27 changed files
with
460 additions
and
146 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
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,64 @@ | ||
// | ||
// Created by Artem Novikov on 24.05.2023. | ||
// | ||
|
||
#include "CachedFermiConfigurations.h" | ||
#include "ConfigurationProperties.h" | ||
#include "Randomizer.h" | ||
|
||
CachedFermiConfigurations::CachedFermiConfigurations(NucleiData nuclei_data, FermiFloat total_energy) { | ||
CachedFermiConfigurations::GenerateSplits(nuclei_data, total_energy); | ||
} | ||
|
||
VFermiConfigurations& CachedFermiConfigurations::GenerateSplits(NucleiData nuclei_data, FermiFloat total_energy) { | ||
auto max_fragments_count = FermiUInt(nuclei_data.mass_number); | ||
if (nuclei_data != last_nuclei_) { | ||
last_nuclei_ = nuclei_data; | ||
cached_configurations_.clear(); | ||
|
||
for (uint32_t particle_count = 2; particle_count <= max_fragments_count; particle_count++) { | ||
for (auto& split : FermiSplit(nuclei_data, particle_count)) { | ||
cached_configurations_.emplace_back(std::move(split)); /// split is moved! | ||
} | ||
} | ||
} | ||
|
||
configurations_.clear(); | ||
weights_.clear(); | ||
|
||
FermiFloat total_weight = 0; | ||
for(size_t i = 0; i < cached_configurations_.size(); ++i) { | ||
auto split_weight = ConfigurationProperties::DecayProbability(cached_configurations_[i], nuclei_data.mass_number, total_energy); | ||
|
||
if (split_weight != 0) { | ||
total_weight += split_weight; | ||
|
||
weights_.push_back(split_weight); | ||
configurations_.emplace_back(i); | ||
} | ||
} | ||
|
||
std::transform(weights_.begin(), weights_.end(), | ||
weights_.begin(), std::bind(std::divides<FermiFloat>(), std::placeholders::_1, total_weight)); | ||
|
||
return *this; | ||
} | ||
|
||
std::optional<FragmentVector> CachedFermiConfigurations::ChooseSplit() { | ||
if (configurations_.empty()) { | ||
return {}; | ||
} | ||
|
||
FermiFloat wheel_result = Randomizer::UniformRealDistribution(); | ||
FermiFloat accumulated_weight = 0; | ||
|
||
for (size_t i = 0; i < weights_.size(); ++i) { | ||
accumulated_weight += weights_[i]; | ||
|
||
if (accumulated_weight >= wheel_result) { | ||
return cached_configurations_[configurations_[i]]; | ||
} | ||
} | ||
|
||
throw std::runtime_error("No split chosen, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Created by Artem Novikov on 24.05.2023. | ||
// | ||
|
||
#ifndef FERMIBREAKUP_MYFERMIBREAKUP_CACHEDFERMICONFIGURATIONS_H_ | ||
#define FERMIBREAKUP_MYFERMIBREAKUP_CACHEDFERMICONFIGURATIONS_H_ | ||
|
||
#include "FermiSplit.h" | ||
#include "VFermiConfigurations.h" | ||
|
||
class CachedFermiConfigurations : public VFermiConfigurations { | ||
public: | ||
CachedFermiConfigurations() = default; | ||
|
||
CachedFermiConfigurations(NucleiData nuclei_data, FermiFloat total_energy); | ||
|
||
VFermiConfigurations& GenerateSplits(NucleiData nuclei_data, FermiFloat total_energy) override; | ||
|
||
std::optional<FragmentVector> ChooseSplit() override; | ||
|
||
private: | ||
std::vector<size_t> configurations_; | ||
std::vector<FermiFloat> weights_; | ||
|
||
std::vector<FragmentVector> cached_configurations_; | ||
NucleiData last_nuclei_{}; | ||
}; | ||
|
||
#endif //FERMIBREAKUP_MYFERMIBREAKUP_CACHEDFERMICONFIGURATIONS_H_ |
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
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
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
Oops, something went wrong.