6#include <boost/serialization/export.hpp>
14#include "../Scheduler/Scheduler.h"
18#include "../Global/SimulationContext.h"
19#include <boost/archive/binary_oarchive.hpp>
20#include <boost/archive/binary_iarchive.hpp>
21#include "../Global/PEOutput.h"
25namespace fs = std::filesystem;
56 p->calculateProbability();
63 int num_subfolder, branch_no, branch_no1, num_of_child;
64 string full_file_name, branch_name;
69 for(branch_no = 0; branch_no < this->
all_branch.size(); branch_no++){
70 current_branch_pt = this->
all_branch.at(branch_no).get();
78 std::ostringstream oss;
83 oss << branch_name <<
' '
91 << this->
all_branch.at(0)->getIDOfThisBranch() <<
'\n';
95 num_of_child = current_branch_pt->
child_IDs.size();
96 oss << num_of_child <<
' ';
98 for(branch_no1 = 0; branch_no1 < num_of_child; branch_no1++){
102 oss << num_of_child <<
' ';
103 for(branch_no1 = 0; branch_no1 < num_of_child; branch_no1++){
104 oss << current_branch_pt->
child_IDs.at(branch_no1) <<
' ';
110 for(branch_no1 = 0; branch_no1 < this->
all_branch.size(); branch_no1++){
111 oss << this->
all_branch.at(branch_no1)->getProbability() <<
' ';
113 oss <<
'\n' << this->
all_branch.size() <<
'\n';
114 for(branch_no1 = 0; branch_no1 < this->
all_branch.size(); branch_no1++){
115 this->
all_branch.at(branch_no1)->saveInfoToFile(oss);
129 for(branch_no1 = 0; branch_no1 < this->
all_branch.size(); branch_no1++){
130 oss << this->
all_branch.at(branch_no1)->getProbability() <<
' ';
132 oss <<
'\n' << this->
all_branch.size() <<
'\n';
133 for(branch_no1 = 0; branch_no1 < this->
all_branch.size(); branch_no1++){
134 this->
all_branch.at(branch_no1)->saveInfoToFile(oss);
143 const std::string content = oss.str();
144 const std::pair<size_t, size_t> sig{content.size(), std::hash<std::string>{}(content)};
147 if (state_it->second == sig)
continue;
148 state_it->second = sig;
160 full_file_name = strDirName;
161 full_file_name +=
"PEFolder_";
163 full_file_name += to_string(num_subfolder);
165 _mkdir(full_file_name.c_str());
168 if (fs::create_directories(full_file_name.c_str()) == -1)
169 cerr <<
"Error : " << strerror(errno) << endl;
172 full_file_name +=
"//ZPENode_";
174 full_file_name +=
".txt";
175 ofstream fout(full_file_name.c_str(), ios::out);
183 string full_file_name;
265 while(all_branch_ritr !=
all_branch.rend() && !found){
266 if((*all_branch_ritr)->getIDOfThisBranch() == _id){
268 branch_pt = all_branch_ritr->get();
273 ofstream fout(
"err messages.txt", ios::app);
274 cout <<
r5pars_.timesno <<
"\tBranchProbability* BranchCluster::findBranch Branch_ID:" << _id
276 fout <<
r5pars_.timesno <<
"\tBranchProbability* BranchCluster::findBranch Branch_ID:" << _id
291 for(i = 0; i < num; i++){
292 this->
all_branch.at(i)->saveBranchProbabilityToFile(fout);
305 for(i = 0; i < num; i++){
306 auto all_branch_pt = make_unique<BranchProbability>();
307 all_branch_pt->retrieveBranchProbabilityFromFile(fin);
308 this->
all_branch.push_back(std::move(all_branch_pt));
315 auto ab_pt = make_unique<BranchProbability>();
316 ab_pt->copyBranchProbability(*src);
A branching point in the DET, holding its branch alternatives.
Central dynamic event tree data structure: the branch clusters, the end states and the forks that are...
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
int getNCountForRestartRELAP5()
void setIDOfTheMotherBranch(int)
Sets the ID of the branch (PE node) this cluster hangs from.
int getIDOfMotherCluster()
void copyBranchCluster(BranchCluster &)
Deep-copies the alternatives and all scalar fields of another cluster. The copies are appended to all...
BranchProbability * findBranch(int)
Finds the alternative with the given branch ID, searching from the last alternative.
int getIDOfThisBranchCluster()
void setNCountForRestartRELAP5(long)
Stores the RELAP5 restart count (r5pars_.cncount) recorded at this branching point.
BranchCluster()
Constructs an empty cluster: mother branch and mother cluster IDs 0, cluster ID, current branch numbe...
void clearBranchCluster()
Destroys all alternatives held in all_branch.
int ID_of_the_mother_branch
void calBranchProbability()
Recomputes the conditional probability of every alternative (BranchProbability::calculateProbability ...
int ID_of_the_mother_cluster
void saveBranchClusterToFile(std::ofstream &)
Writes the cluster as text: the five ID fields, the alternative count, every alternative,...
void setIDOfThisBranchCluster(int)
void retrieveInfoFromFile(std::ifstream &)
Does nothing; the stream is not read.
void setIDOfMotherCluster(int)
Sets the ID of the cluster that contains the mother branch.
int getCurrentBranchNum()
int ID_of_this_branch_cluster
void setCurrentBranchNum(int)
Sets the index (within all_branch) of the most recently started alternative. Alternatives with a larg...
long n_count_for_restart_RELAP5
void savePENodeToFile()
Writes the PE nodes of this cluster under the scheduler's PE directory (Scheduler::getPEDirectory()).
int getIDOfTheMotherBranch()
void retrieveBranchClusterFromFile(std::ifstream &)
Reads the text layout written by saveBranchClusterToFile and appends the alternatives it reads to all...
std::vector< std::unique_ptr< BranchProbability > > all_branch
The alternatives of this branching point; index 0 is the one the generating sequence continues on.
One alternative of a BranchCluster, i.e. one PE node of the DET.
int getIDOfTheChildBranchCluster()
std::vector< int > child_IDs
void copyProbability(Probability &)
void saveProbabilityToFile(std::ofstream &)
void retrieveProbabilityFromFile(std::ifstream &)
std::string getPEDirectory()
double getTimeAtWhichThisEventHappen() const
void saveTimeToFile(std::ofstream &)
void retrieveTimeFromFile(std::ifstream &)
void append_record(const std::string &pe_dir, int branch_id, const std::string &content)
Append one node record to <pe_dir>ZPENodes_agg.txt.
Scheduler SScheduler
Simulation scheduling, parses CLI options.
std::map< int, std::pair< size_t, size_t > > pe_file_state
PE id -> (size, hash) last written by this process; an unchanged node is not rewritten.
BranchRecord Branch_center
Dynamic event tree state.