Chi-Tech
adjoint_src_function.cc
Go to the documentation of this file.
2
5
6namespace lbs
7{
8
9//###################################################################
10/**Constructor for an adjoint source function.*/
12 AdjointSourceFunction(const LBSSolver &lbs_solver) :
13 SourceFunction(lbs_solver)
14{}
15
16//###################################################################
17/**Adds Quantities of Interest to the nodal sources.*/
20 std::vector<double>& destination_q,
21 const std::vector<double>&,
22 SourceFlags source_flags)
23{
24 const std::string fname = "AdjointSourceFunction::AddVolumetricQOISources";
25
26 typedef const DiscreteOrdinatesAdjointSolver CAdjointSolver;
27 const auto adjoint_solver_ptr = dynamic_cast<CAdjointSolver*>(&lbs_solver_);
28 if (not adjoint_solver_ptr)
29 throw std::logic_error(fname + ": Failed to cast lbs_solver_ to adjoint.");
30
31 const auto& adjoint_solver = *adjoint_solver_ptr;
32
33 const auto& response_functions = adjoint_solver.GetResponseFunctions();
34 const auto& basic_options = adjoint_solver.GetBasicOptions();
35 const auto& cell_transport_views = adjoint_solver.GetCellTransportViews();
36 const auto& grid = adjoint_solver.Grid();
37 const auto num_groups = adjoint_solver.NumGroups();
38
39 const bool apply_fixed_src = (source_flags & APPLY_FIXED_SOURCES);
40
41 const auto gs_i = static_cast<size_t>(groupset.groups_.front().id_);
42 const auto gs_f = static_cast<size_t>(groupset.groups_.back().id_);
43
44 if (apply_fixed_src)
45 for (const auto& qoi_data : response_functions)
46 {
47 const auto& qoi_designation = qoi_data.first;
48 const auto& qoi_cell_subscription = qoi_data.second;
49
50 if (qoi_designation.name == basic_options("REFERENCE_RF").StringValue())
51 {
52 for (size_t local_id : qoi_cell_subscription)
53 {
54 const auto& full_cell_view = cell_transport_views[local_id];
55 const auto& cell = grid.local_cells[local_id];
56 const auto& response = qoi_designation.GetMGResponse(cell, num_groups);
57 const int num_nodes = full_cell_view.NumNodes();
58 for (int i = 0; i < num_nodes; ++i)
59 {
60 size_t uk_map = full_cell_view.MapDOF(i, 0, 0); //unknown map
61 for (size_t g = gs_i; g <= gs_f; ++g)
62 destination_q[uk_map + g] += response[g];
63 }//for node
64 }//for local cell-id of qoi
65 }//if ref-qoi
66 }//for qoi
67}
68
69}//namespace lbs
AdjointSourceFunction(const LBSSolver &lbs_solver)
void AddVolumetricQOISources(LBSGroupset &groupset, std::vector< double > &destination_q, const std::vector< double > &phi, SourceFlags source_flags)
std::vector< LBSGroup > groups_
Definition: lbs_groupset.h:41
const LBSSolver & lbs_solver_
SourceFlags
Definition: lbs_structs.h:88
@ APPLY_FIXED_SOURCES
Definition: lbs_structs.h:90