@@ -112,6 +112,21 @@ double Cell::density_mult(int32_t instance) const
112
112
}
113
113
}
114
114
115
+ double Cell::density (int32_t instance) const
116
+ {
117
+ const int32_t mat_index = material (instance);
118
+ if (mat_index == MATERIAL_VOID)
119
+ return 0.0 ;
120
+
121
+ if (instance >= 0 ) {
122
+ double rho =
123
+ rho_mult_.size () == 1 ? rho_mult_.at (0 ) : rho_mult_.at (instance);
124
+ return rho * model::materials[mat_index]->density_gpcc ();
125
+ } else {
126
+ return rho_mult_[0 ];
127
+ }
128
+ }
129
+
115
130
void Cell::set_temperature (double T, int32_t instance, bool set_contained)
116
131
{
117
132
if (settings::temperature_method == TemperatureMethod::INTERPOLATION) {
@@ -162,7 +177,7 @@ void Cell::set_temperature(double T, int32_t instance, bool set_contained)
162
177
}
163
178
}
164
179
165
- void Cell::set_density_mult (double rho, int32_t instance, bool set_contained)
180
+ void Cell::set_density (double rho, int32_t instance, bool set_contained)
166
181
{
167
182
if (type_ != Fill::MATERIAL && !set_contained) {
168
183
fatal_error (
@@ -172,17 +187,21 @@ void Cell::set_density_mult(double rho, int32_t instance, bool set_contained)
172
187
}
173
188
174
189
if (type_ == Fill::MATERIAL) {
190
+ const int32_t mat_index = material (instance);
191
+ if (mat_index == MATERIAL_VOID)
192
+ return ;
193
+
175
194
if (instance >= 0 ) {
176
195
// If density multiplier vector is not big enough, resize it first
177
196
if (rho_mult_.size () != n_instances ())
178
197
rho_mult_.resize (n_instances (), rho_mult_[0 ]);
179
198
180
199
// Set density multiplier for the corresponding instance
181
- rho_mult_.at (instance) = rho;
200
+ rho_mult_.at (instance) = rho / model::materials[mat_index]-> density_gpcc () ;
182
201
} else {
183
202
// Set density multiplier for all instances
184
203
for (auto & Rho_ : rho_mult_) {
185
- Rho_ = rho;
204
+ Rho_ = rho / model::materials[mat_index]-> density_gpcc () ;
186
205
}
187
206
}
188
207
} else {
@@ -192,7 +211,7 @@ void Cell::set_density_mult(double rho, int32_t instance, bool set_contained)
192
211
assert (cell->type_ == Fill::MATERIAL);
193
212
auto & instances = entry.second ;
194
213
for (auto instance : instances) {
195
- cell->set_density_mult (rho, instance);
214
+ cell->set_density (rho, instance);
196
215
}
197
216
}
198
217
}
@@ -1243,18 +1262,8 @@ extern "C" int openmc_cell_set_density(
1243
1262
1244
1263
int32_t instance_index = instance ? *instance : -1 ;
1245
1264
try {
1246
- if (model::cells[index]->type_ != Fill::MATERIAL) {
1247
- fatal_error (
1248
- fmt::format (" Cell {}, instance {} is not filled with a material." ,
1249
- model::cells[index]->id_ , instance_index));
1250
- }
1251
-
1252
- int32_t mat_index = model::cells[index]->material (instance_index);
1253
- if (mat_index != MATERIAL_VOID) {
1254
- model::cells[index]->set_density_mult (
1255
- rho / model::materials[mat_index]->density_gpcc (), instance_index,
1256
- set_contained);
1257
- }
1265
+ model::cells[index]->set_density (
1266
+ rho, instance_index, set_contained);
1258
1267
} catch (const std::exception& e) {
1259
1268
set_errmsg (e.what ());
1260
1269
return OPENMC_E_UNASSIGNED;
0 commit comments