Chi-Tech
lbsDO_07_vectorassembly.cc
Go to the documentation of this file.
3
5
6//###################################################################
7/**Scales a flux moment vector. For sweep methods the delayed angular
8 * fluxes will also be scaled.*/
10 ScalePhiVector(PhiSTLOption which_phi, double value)
11{
12 std::vector<double>* y_ptr;
13 switch (which_phi)
14 {
15 case PhiSTLOption::PHI_NEW: y_ptr = &phi_new_local_; break;
16 case PhiSTLOption::PHI_OLD: y_ptr = &phi_old_local_; break;
17 default:
18 throw std::logic_error("SetGSPETScVecFromPrimarySTLvector");
19 }
20
21 chi_math::Scale(*y_ptr, value);
22
23 for (auto& groupset : groupsets_)
24 {
25 switch (which_phi)
26 {
28 {
29 auto psi = groupset.angle_agg_->GetNewDelayedAngularDOFsAsSTLVector();
30 chi_math::Scale(psi, value);
31 groupset.angle_agg_->SetNewDelayedAngularDOFsFromSTLVector(psi);
32 break;
33 }
35 {
36 auto psi = groupset.angle_agg_->GetOldDelayedAngularDOFsAsSTLVector();
37 chi_math::Scale(psi, value);
38 groupset.angle_agg_->SetOldDelayedAngularDOFsFromSTLVector(psi);
39 break;
40 }
41 }
42 }
43}
44//###################################################################
45/**Assembles a vector for a given groupset from a source vector.*/
48 PhiSTLOption which_phi)
49{
50 const std::vector<double>* y_ptr;
51 switch (which_phi)
52 {
53 case PhiSTLOption::PHI_NEW: y_ptr = &phi_new_local_; break;
54 case PhiSTLOption::PHI_OLD: y_ptr = &phi_old_local_; break;
55 default:
56 throw std::logic_error("SetGSPETScVecFromPrimarySTLvector");
57 }
58
59 double* x_ref;
60 VecGetArray(x,&x_ref);
61
62 int gsi = groupset.groups_.front().id_;
63 int gsf = groupset.groups_.back().id_;
64 int gss = gsf-gsi+1;
65
66 int64_t index = -1;
67 for (const auto& cell : grid_ptr_->local_cells)
68 {
69 auto& transport_view = cell_transport_views_[cell.local_id_];
70
71 for (int i=0; i < cell.vertex_ids_.size(); i++)
72 {
73 for (int m=0; m < num_moments_; m++)
74 {
75 size_t mapping = transport_view.MapDOF(i,m,gsi);
76 for (int g=0; g<gss; g++)
77 {
78 index++;
79 x_ref[index] = (*y_ptr)[mapping+g]; //Offset on purpose
80 }//for g
81 }//for moment
82 }//for dof
83 }//for cell
84
85 switch (which_phi)
86 {
88 groupset.angle_agg_->AppendNewDelayedAngularDOFsToArray(index, x_ref);
89 break;
91 groupset.angle_agg_->AppendOldDelayedAngularDOFsToArray(index, x_ref);
92 break;
93 }
94
95 VecRestoreArray(x,&x_ref);
96}
97
98//###################################################################
99/**Assembles a vector for a given groupset from a source vector.*/
102 PhiSTLOption which_phi)
103{
104 std::vector<double>* y_ptr;
105 switch (which_phi)
106 {
107 case PhiSTLOption::PHI_NEW: y_ptr = &phi_new_local_; break;
108 case PhiSTLOption::PHI_OLD: y_ptr = &phi_old_local_; break;
109 default:
110 throw std::logic_error("SetPrimarySTLvectorFromGSPETScVec");
111 }
112
113 const double* x_ref;
114 VecGetArrayRead(x_src,&x_ref);
115
116 int gsi = groupset.groups_.front().id_;
117 int gsf = groupset.groups_.back().id_;
118 int gss = gsf-gsi+1;
119
120 int64_t index = -1;
121 for (const auto& cell : grid_ptr_->local_cells)
122 {
123 auto& transport_view = cell_transport_views_[cell.local_id_];
124
125 for (int i=0; i < cell.vertex_ids_.size(); i++)
126 {
127 for (int m=0; m < num_moments_; m++)
128 {
129 size_t mapping = transport_view.MapDOF(i,m,gsi);
130 for (int g=0; g<gss; g++)
131 {
132 index++;
133 (*y_ptr)[mapping+g] = x_ref[index];
134 }//for g
135 }//for moment
136 }//for dof
137 }//for cell
138
139 switch (which_phi)
140 {
142 groupset.angle_agg_->SetNewDelayedAngularDOFsFromArray(index, x_ref);
143 break;
145 groupset.angle_agg_->SetOldDelayedAngularDOFsFromArray(index, x_ref);
146 }
147
148 VecRestoreArrayRead(x_src,&x_ref);
149}
150
151//###################################################################
152/**Assembles a vector for a given groupset from a source vector.*/
155 PhiSTLOption from_which_phi,
156 PhiSTLOption to_which_phi)
157{
158 std::vector<double>* y_ptr;
159 switch (to_which_phi)
160 {
161 case PhiSTLOption::PHI_NEW: y_ptr = &phi_new_local_; break;
162 case PhiSTLOption::PHI_OLD: y_ptr = &phi_old_local_; break;
163 default:
164 throw std::logic_error("GSScopedCopyPrimarySTLvectors");
165 }
166
167 std::vector<double>* x_src_ptr;
168 switch (from_which_phi)
169 {
170 case PhiSTLOption::PHI_NEW: x_src_ptr = &phi_new_local_; break;
171 case PhiSTLOption::PHI_OLD: x_src_ptr = &phi_old_local_; break;
172 default:
173 throw std::logic_error("GSScopedCopyPrimarySTLvectors");
174 }
175
176 int gsi = groupset.groups_.front().id_;
177 size_t gss = groupset.groups_.size();
178
179 for (const auto& cell : grid_ptr_->local_cells)
180 {
181 auto& transport_view = cell_transport_views_[cell.local_id_];
182
183 for (int i=0; i < cell.vertex_ids_.size(); i++)
184 {
185 for (int m=0; m < num_moments_; m++)
186 {
187 size_t mapping = transport_view.MapDOF(i,m,gsi);
188 for (int g=0; g<gss; g++)
189 {
190 (*y_ptr)[mapping+g] = (*x_src_ptr)[mapping+g];
191 }//for g
192 }//for moment
193 }//for dof
194 }//for cell
195
196 if (from_which_phi == PhiSTLOption::PHI_NEW and
197 to_which_phi == PhiSTLOption::PHI_OLD)
198 groupset.angle_agg_->SetDelayedPsiOld2New();
199 if (from_which_phi == PhiSTLOption::PHI_OLD and
200 to_which_phi == PhiSTLOption::PHI_NEW)
201 groupset.angle_agg_->SetDelayedPsiNew2Old();
202}
203
204//###################################################################
205/**Assembles a PETSc vector from multiple groupsets.*/
207SetMultiGSPETScVecFromPrimarySTLvector(const std::vector<int> &gs_ids,
208 Vec x, PhiSTLOption which_phi)
209{
210 const std::vector<double>* y_ptr;
211 switch (which_phi)
212 {
213 case PhiSTLOption::PHI_NEW: y_ptr = &phi_new_local_; break;
214 case PhiSTLOption::PHI_OLD: y_ptr = &phi_old_local_; break;
215 default:
216 throw std::logic_error("SetMultiGSPETScVecFromPrimarySTLvector");
217 }
218
219 double* x_ref;
220 VecGetArray(x,&x_ref);
221
222 int64_t index = -1;
223 for (int gs_id : gs_ids)
224 {
225 auto& groupset = groupsets_.at(gs_id);
226
227 int gsi = groupset.groups_.front().id_;
228 int gsf = groupset.groups_.back().id_;
229 int gss = gsf-gsi+1;
230
231 for (const auto& cell : grid_ptr_->local_cells)
232 {
233 auto& transport_view = cell_transport_views_[cell.local_id_];
234
235 for (int i=0; i < cell.vertex_ids_.size(); i++)
236 {
237 for (int m=0; m < num_moments_; m++)
238 {
239 size_t mapping = transport_view.MapDOF(i,m,gsi);
240 for (int g=0; g<gss; g++)
241 {
242 index++;
243 x_ref[index] = (*y_ptr)[mapping+g]; //Offset on purpose
244 }//for g
245 }//for moment
246 }//for dof
247 }//for cell
248
249 switch (which_phi)
250 {
252 groupset.angle_agg_->AppendNewDelayedAngularDOFsToArray(index, x_ref);
253 break;
255 groupset.angle_agg_->AppendOldDelayedAngularDOFsToArray(index, x_ref);
256 break;
257 }
258 }//for groupset id
259
260 VecRestoreArray(x,&x_ref);
261}
262
263//###################################################################
264/**Disassembles a multiple Groupset PETSc vector STL vectors.*/
266SetPrimarySTLvectorFromMultiGSPETScVecFrom(const std::vector<int> &gs_ids,
267 Vec x_src,
268 PhiSTLOption which_phi)
269{
270 std::vector<double>* y_ptr;
271 switch (which_phi)
272 {
273 case PhiSTLOption::PHI_NEW: y_ptr = &phi_new_local_; break;
274 case PhiSTLOption::PHI_OLD: y_ptr = &phi_old_local_; break;
275 default:
276 throw std::logic_error("SetPrimarySTLvectorFromMultiGSPETScVecFrom");
277 }
278
279 const double* x_ref;
280 VecGetArrayRead(x_src,&x_ref);
281
282 int64_t index = -1;
283 for (int gs_id : gs_ids)
284 {
285 auto& groupset = groupsets_.at(gs_id);
286
287 int gsi = groupset.groups_.front().id_;
288 int gsf = groupset.groups_.back().id_;
289 int gss = gsf-gsi+1;
290
291 for (const auto& cell : grid_ptr_->local_cells)
292 {
293 auto& transport_view = cell_transport_views_[cell.local_id_];
294
295 for (int i=0; i < cell.vertex_ids_.size(); i++)
296 {
297 for (int m=0; m < num_moments_; m++)
298 {
299 size_t mapping = transport_view.MapDOF(i,m,gsi);
300 for (int g=0; g<gss; g++)
301 {
302 index++;
303 (*y_ptr)[mapping+g] = x_ref[index];
304 }//for g
305 }//for moment
306 }//for dof
307 }//for cell
308
309 switch (which_phi)
310 {
312 groupset.angle_agg_->SetNewDelayedAngularDOFsFromArray(index, x_ref);
313 break;
315 groupset.angle_agg_->SetOldDelayedAngularDOFsFromArray(index, x_ref);
316 }
317 }//for groupset id
318
319 VecRestoreArrayRead(x_src,&x_ref);
320}
void SetGSPETScVecFromPrimarySTLvector(LBSGroupset &groupset, Vec x, PhiSTLOption which_phi) override
void SetPrimarySTLvectorFromGSPETScVec(LBSGroupset &groupset, Vec x_src, PhiSTLOption which_phi) override
void SetMultiGSPETScVecFromPrimarySTLvector(const std::vector< int > &gs_ids, Vec x, PhiSTLOption which_phi) override
void GSScopedCopyPrimarySTLvectors(LBSGroupset &groupset, PhiSTLOption from_which_phi, PhiSTLOption to_which_phi) override
void SetPrimarySTLvectorFromMultiGSPETScVecFrom(const std::vector< int > &gs_ids, Vec x_src, PhiSTLOption which_phi) override
void ScalePhiVector(PhiSTLOption which_phi, double value) override
AngleAggPtr angle_agg_
Definition: lbs_groupset.h:43
std::vector< LBSGroup > groups_
Definition: lbs_groupset.h:41
std::vector< double > phi_new_local_
Definition: lbs_solver.h:95
std::vector< double > phi_old_local_
Definition: lbs_solver.h:95
std::vector< LBSGroupset > groupsets_
Definition: lbs_solver.h:68
void Scale(VecDbl &x, const double &val)
PhiSTLOption
Definition: lbs_structs.h:105
struct _p_Vec * Vec