Chi-Tech
CBC_AngleSet.cc
Go to the documentation of this file.
1#include "CBC_AngleSet.h"
2
3#include "CBC_AsyncComm.h"
4#include "CBC_SPDS.h"
8
9#include "chi_runtime.h"
10#include "chi_log.h"
11
12namespace lbs
13{
14
16 size_t id,
17 size_t num_groups,
19 std::shared_ptr<chi_mesh::sweep_management::FLUDS>& fluds,
20 const std::vector<size_t>& angle_indices,
21 std::map<uint64_t, SweepBndryPtr>& sim_boundaries,
22 size_t in_ref_subset,
23 const chi::ChiMPICommunicatorSet& comm_set)
24 : chi_mesh::sweep_management::AngleSet(id,
25 num_groups,
26 spds,
27 fluds,
28 angle_indices,
29 sim_boundaries,
30 in_ref_subset),
31 cbc_spds_(dynamic_cast<const CBC_SPDS&>(spds_)),
32 async_comm_(id, *fluds, comm_set)
33{
34}
35
38{
41}
42
45 const std::vector<size_t>& timing_tags,
47{
49
50 if (executed_) return Status::FINISHED;
51
52
53 if (current_task_list_.empty())
55
56 sweep_chunk.SetAngleSet(*this);
57
58 auto tasks_who_received_data = async_comm_.ReceiveData();
59
60 for (const uint64_t task_number : tasks_who_received_data)
61 --current_task_list_[task_number].num_dependencies_;
62
64
65 // Check if boundaries allow for execution
66 for (auto& [bid, bndry] : ref_boundaries_)
67 if (not bndry->CheckAnglesReadyStatus(angles_, ref_group_subset_))
68 return Status::NOT_FINISHED;
69
70 bool all_tasks_completed = true;
71 bool a_task_executed = true;
72 while (a_task_executed)
73 {
74 a_task_executed = false;
75 for (auto& cell_task : current_task_list_)
76 {
77 if (not cell_task.completed_) all_tasks_completed = false;
78 if (cell_task.num_dependencies_ == 0 and not cell_task.completed_)
79 {
81 sweep_chunk.SetCell(cell_task.cell_ptr_, *this);
82 sweep_chunk.Sweep(*this);
83
84 for (uint64_t local_task_num : cell_task.successors_)
85 --current_task_list_[local_task_num].num_dependencies_;
87
88 cell_task.completed_ = true;
89 a_task_executed = true;
91 }
92 } // for cell_task
94 }
95 //for (auto& cell_task : current_task_list_)
96 //{
97 // if (not cell_task.completed_) all_tasks_completed = false;
98 // if (cell_task.num_dependencies_ == 0 and not cell_task.completed_)
99 // {
100 // Chi::log.LogEvent(timing_tags[0], chi::ChiLog::EventType::EVENT_BEGIN);
101 // sweep_chunk.SetCell(cell_task.cell_ptr_, *this);
102 // sweep_chunk.Sweep(*this);
103 //
104 // for (uint64_t local_task_num : cell_task.successors_)
105 // --current_task_list_[local_task_num].num_dependencies_;
106 // Chi::log.LogEvent(timing_tags[0], chi::ChiLog::EventType::EVENT_END);
107 //
108 // cell_task.completed_ = true;
109 // async_comm_.SendData();
110 // }
111 //} // for cell_task
112
113 const bool all_messages_sent = async_comm_.SendData();
114
115 if (all_tasks_completed and all_messages_sent)
116 {
117 // Update boundary readiness
118 for (auto& [bid, bndry] : ref_boundaries_)
119 bndry->UpdateAnglesReadyStatus(angles_, ref_group_subset_);
120 executed_ = true;
121 return Status::FINISHED;
122 }
123
124 return Status::NOT_FINISHED;
125}
126
127// ###################################################################
128/**Resets the sweep buffer.*/
130{
131 current_task_list_.clear();
133 fluds_->ClearLocalAndReceivePsi();
134 executed_ = false;
135}
136
137// ###################################################################
138/**Returns a pointer to a boundary flux data.*/
139const double* CBC_AngleSet::PsiBndry(uint64_t bndry_map,
140 unsigned int angle_num,
141 uint64_t cell_local_id,
142 unsigned int face_num,
143 unsigned int fi,
144 int g,
145 size_t gs_ss_begin,
146 bool surface_source_active)
147{
148 if (ref_boundaries_[bndry_map]->IsReflecting())
149 return ref_boundaries_[bndry_map]->HeterogeneousPsiIncoming(
150 cell_local_id, face_num, fi, angle_num, g, gs_ss_begin);
151
152 if (not surface_source_active) return ref_boundaries_[bndry_map]->ZeroFlux(g);
153
154 return ref_boundaries_[bndry_map]->HeterogeneousPsiIncoming(
155 cell_local_id, face_num, fi, angle_num, g, gs_ss_begin);
156}
157
158// ###################################################################
159/**Returns a pointer to outbound boundary flux data.*/
161 unsigned int angle_num,
162 uint64_t cell_local_id,
163 unsigned int face_num,
164 unsigned int fi,
165 size_t gs_ss_begin)
166{
167 return ref_boundaries_[bndry_map]->HeterogeneousPsiOutgoing(
168 cell_local_id, face_num, fi, angle_num, gs_ss_begin);
169}
170
171} // namespace lbs
static chi::ChiLog & log
Definition: chi_runtime.h:81
@ EVENT_BEGIN
Signals the begin of an event.
@ EVENT_END
Signals the end of an event.
void LogEvent(size_t ev_tag, EventType ev_type, const std::shared_ptr< EventInfo > &ev_info)
Definition: chi_log.cc:204
std::map< uint64_t, SweepBndryPtr > & ref_boundaries_
Definition: AngleSet.h:80
std::shared_ptr< FLUDS > fluds_
Definition: AngleSet.h:78
const std::vector< size_t > angles_
Definition: AngleSet.h:79
virtual void SetCell(chi_mesh::Cell const *cell_ptr, chi_mesh::sweep_management::AngleSet &angle_set)
virtual void SetAngleSet(AngleSet &angle_set)
virtual void Sweep(AngleSet &angle_set)
std::vector< uint64_t > ReceiveData()
CBC_AngleSet(size_t id, size_t num_groups, const chi_mesh::sweep_management::SPDS &spds, std::shared_ptr< chi_mesh::sweep_management::FLUDS > &fluds, const std::vector< size_t > &angle_indices, std::map< uint64_t, SweepBndryPtr > &sim_boundaries, size_t in_ref_subset, const chi::ChiMPICommunicatorSet &comm_set)
Definition: CBC_AngleSet.cc:15
double * ReflectingPsiOutBoundBndry(uint64_t bndry_map, unsigned int angle_num, uint64_t cell_local_id, unsigned int face_num, unsigned int fi, size_t gs_ss_begin) override
void ResetSweepBuffers() override
CBC_ASynchronousCommunicator async_comm_
Definition: CBC_AngleSet.h:63
chi_mesh::sweep_management::AsynchronousCommunicator * GetCommunicator() override
Definition: CBC_AngleSet.cc:37
const double * PsiBndry(uint64_t bndry_map, unsigned int angle_num, uint64_t cell_local_id, unsigned int face_num, unsigned int fi, int g, size_t gs_ss_begin, bool surface_source_active) override
const CBC_SPDS & cbc_spds_
Definition: CBC_AngleSet.h:61
std::vector< chi_mesh::sweep_management::Task > current_task_list_
Definition: CBC_AngleSet.h:62
chi_mesh::sweep_management::AngleSetStatus AngleSetAdvance(chi_mesh::sweep_management::SweepChunk &sweep_chunk, const std::vector< size_t > &timing_tags, chi_mesh::sweep_management::ExecutionPermission permission) override
Definition: CBC_AngleSet.cc:43
const std::vector< chi_mesh::sweep_management::Task > & TaskList() const
Definition: CBC_SPDS.cc:151