Chi-Tech
general.cc
Go to the documentation of this file.
1#include "diffusion_solver.h"
2
7
8#include "chi_runtime.h"
9#include "chi_log.h"
10
11#include "chi_mpi.h"
12
13
14//###################################################################
15/**Gets material properties various sources.*/
17 const chi_mesh::Cell& cell,
18 int cell_dofs,
19 std::vector<double>& diffCoeff,
20 std::vector<double>& sourceQ,
21 std::vector<double>& sigmaa,
22 int group,
23 int moment)
24{
25 uint64_t cell_glob_index = cell.global_id_;
26 bool cell_is_local = (cell.partition_id_ == Chi::mpi.location_id);
27 uint64_t cell_local_id = cell.local_id_;
28 int mat_id = cell.material_id_;
29
30 if (mat_id<0)
31 {
33 << "Cell encountered with no material id. ";
34 Chi::Exit(EXIT_FAILURE);
35 }
36
37 if (mat_id>= Chi::material_stack.size())
38 {
40 << "Cell encountered with material id pointing to "
41 "non-existing material.";
42 Chi::Exit(EXIT_FAILURE);
43 }
44
45 auto property_map_D = basic_options_("property_map_D").IntegerValue();
46 auto property_map_q = basic_options_("property_map_q").IntegerValue();
47 auto property_map_sigma = basic_options_("property_map_sigma").IntegerValue();
48
49 auto material =
50 Chi::GetStackItemPtr(Chi::material_stack, mat_id, __FUNCTION__);
51
52 //====================================== Process material properties
53 diffCoeff.resize(cell_dofs,1.0);
54 sourceQ.resize(cell_dofs,0.0);
55 sigmaa.resize(cell_dofs,0.0);
56
57 //####################################################### REGULAR MATERIAL
59 {
60 //We absolutely need the diffusion coefficient so process error
61 if ((property_map_D < 0) || (property_map_D >= material->properties_.size()))
62 {
64 << "Solver diffusion coefficient mapped to property index "
65 << property_map_D << " is not a valid index for material \""
66 << material->name_ <<"\" id " << mat_id;
67 Chi::Exit(EXIT_FAILURE);
68 }
69
70 //For now, we can only support scalar values so lets check that
71 if (std::dynamic_pointer_cast<chi_physics::ScalarValue>
72 (material->properties_[property_map_D]))
73 {
74 diffCoeff.assign(cell_dofs,
75 material->properties_[property_map_D]->GetScalarValue());
76 }
77 else
78 {
80 << "Solver diffusion coefficient mapped to property index "
81 << property_map_D << " is not a valid property type"
82 << " for material \""
83 << material->name_ <<"\" id " << mat_id
84 << ". Currently SCALAR_VALUE and THERMAL_CONDUCTIVITY are the "
85 << "only supported types.";
86 Chi::Exit(EXIT_FAILURE);
87 }
88
89
90 if ((property_map_q < material->properties_.size()) &&
91 (property_map_q >= 0))
92 {
93 if (std::dynamic_pointer_cast<chi_physics::ScalarValue>
94 (material->properties_[property_map_q]))
95 {
96 sourceQ.assign(cell_dofs,
97 material->properties_[property_map_q]->GetScalarValue());
98 }
99 else
100 {
102 << "Source value mapped to property index "
103 << property_map_q << " is not a valid property type"
104 << " for material \""
105 << material->name_ <<"\" id " << mat_id
106 << ". Currently SCALAR_VALUE is the "
107 << "only supported type.";
108 Chi::Exit(EXIT_FAILURE);
109 }
110 }
111
112 if (not ((property_map_sigma < 0) ||
113 (property_map_sigma >= material->properties_.size())))
114 {
115 sigmaa.assign(cell_dofs,
116 material->properties_[property_map_sigma]->GetScalarValue());
117 }
118 }//regular
119
120 //####################################################### TRANSPORT XS D
121 // TRANSPORT XS SIGA
122 // SCALAR Q
124 {
125 //====================================== Setting D and Sigma_a
126 bool transportxs_found = false;
127 for (int p=0; p<material->properties_.size(); p++)
128 {
129 if (std::dynamic_pointer_cast<chi_physics::MultiGroupXS>
130 (material->properties_[p]))
131 {
132 auto xs = std::static_pointer_cast<
133 chi_physics::MultiGroupXS>(material->properties_[p]);
134
135 diffCoeff.assign(cell_dofs, xs->DiffusionCoefficient()[group]);
136 sigmaa.assign(cell_dofs, xs->SigmaRemoval()[group]);
137 transportxs_found = true;
138 }
139 }//for properties
140
141 if (!transportxs_found)
142 {
144 << "Diffusion Solver: Material encountered with no tranport xs"
145 " yet material mode is DIFFUSION_MATERIALS_FROM_TRANSPORTXS.";
146 Chi::Exit(EXIT_FAILURE);
147 }
148
149 //====================================== Setting Q
150 if ((property_map_q < material->properties_.size()) &&
151 (property_map_q >= 0))
152 {
153 if (std::dynamic_pointer_cast<chi_physics::ScalarValue>
154 (material->properties_[property_map_q]))
155 {
156 sourceQ.assign(cell_dofs,
157 material->properties_[property_map_q]->GetScalarValue());
158 }
159 else
160 {
162 << "Source value mapped to property index "
163 << property_map_q << " is not a valid property type"
164 << " for material \""
165 << material->name_ <<"\" id " << mat_id
166 << ". Currently SCALAR_VALUE is the "
167 << "only supported type.";
168 Chi::Exit(EXIT_FAILURE);
169 }
170 }
171 }//transport xs TTR
172 else
173 {
175 << "Diffusion Solver: Invalid material mode.";
176 Chi::Exit(EXIT_FAILURE);
177 }
178
179
180}
181
182
183//###################################################################
184/**Update the field functions with the latest data.*/
186{
187 Chi::log.LogAll() << "Updating field functions" << std::endl;
188 auto& ff = *field_functions_.front();
189 const auto& OneDofPerNode = discretization_->UNITARY_UNKNOWN_MANAGER;
190
191 std::vector<double> data_vector;
192 discretization_->LocalizePETScVector(x_, data_vector, OneDofPerNode);
193
194 ff.UpdateFieldVector(data_vector);
195}
static std::vector< chi_physics::MaterialPtr > material_stack
Definition: chi_runtime.h:90
static void Exit(int error_code)
Definition: chi_runtime.cc:342
static chi::ChiLog & log
Definition: chi_runtime.h:81
static std::shared_ptr< T > & GetStackItemPtr(std::vector< std::shared_ptr< T > > &stack, const size_t handle, const std::string &calling_function_name="Unknown")
Definition: chi_runtime.h:258
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
LogStream LogAllError()
Definition: chi_log.h:239
LogStream Log0Error()
Definition: chi_log.h:232
LogStream LogAll()
Definition: chi_log.h:237
const int & location_id
Current process rank.
Definition: mpi_info.h:26
void UpdateFieldFunctions()
Definition: general.cc:185
void GetMaterialProperties(const chi_mesh::Cell &cell, int cell_dofs, std::vector< double > &diffCoeff, std::vector< double > &sourceQ, std::vector< double > &sigmaa, int group=0, int moment=0)
Definition: general.cc:16
uint64_t local_id_
Definition: cell.h:76
int material_id_
Definition: cell.h:79
uint64_t partition_id_
Definition: cell.h:77
uint64_t global_id_
Definition: cell.h:75
BasicOptions basic_options_
Definition: chi_solver.h:57
#define DIFFUSION_MATERIALS_REGULAR
#define DIFFUSION_MATERIALS_FROM_TRANSPORTXS_TTR