Skip to content

Commit 607f6ba

Browse files
nuclearkevinpshriwisepaulromano
authored
Add distributed cell densities (#3546)
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com> Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent afd9d06 commit 607f6ba

32 files changed

Lines changed: 607 additions & 52 deletions

docs/source/capi/index.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ Functions
8484
:return: Return status (negative if an error occurred)
8585
:rtype: int
8686
87+
.. c:function:: int openmc_cell_get_density(int32_t index, const int32_t* instance, double* density)
88+
89+
Get the density of a cell
90+
91+
:param int32_t index: Index in the cells array
92+
:param int32_t* instance: Which instance of the cell. If a null pointer is passed, the density
93+
multiplier of the first instance is returned.
94+
:param double* density: Density of the cell in [g/cm3]
95+
:return: Return status (negative if an error occurred)
96+
:rtype: int
97+
8798
.. c:function:: int openmc_cell_set_fill(int32_t index, int type, int32_t n, const int32_t* indices)
8899
89100
Set the fill for a cell
@@ -113,8 +124,22 @@ Functions
113124
:param double T: Temperature in Kelvin
114125
:param instance: Which instance of the cell. To set the temperature for all
115126
instances, pass a null pointer.
116-
:param set_contained: If the cell is not filled by a material, whether to set the temperatures
117-
of all filled cells
127+
:param bool set_contained: If the cell is not filled by a material, whether
128+
to set the temperatures of all filled cells
129+
:type instance: const int32_t*
130+
:return: Return status (negative if an error occurred)
131+
:rtype: int
132+
133+
.. c:function:: int openmc_cell_set_density(index index, double density, const int32_t* instance, bool set_contained)
134+
135+
Set the density of a cell.
136+
137+
:param int32_t index: Index in the cells array
138+
:param double density: Density of the cell in [g/cm3]
139+
:param instance: Which instance of the cell. To set the density multiplier for all
140+
instances, pass a null pointer.
141+
:param bool set_contained: If the cell is not filled by a material, whether
142+
to set the density multiplier of all filled cells
118143
:type instance: const int32_t*
119144
:return: Return status (negative if an error occurred)
120145
:rtype: int

docs/source/io_formats/properties.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Properties File Format
55
======================
66

7-
The current version of the properties file format is 1.0.
7+
The current version of the properties file format is 1.1.
88

99
**/**
1010

@@ -25,6 +25,7 @@ The current version of the properties file format is 1.0.
2525
**/geometry/cells/cell <uid>/**
2626

2727
:Datasets: - **temperature** (*double[]*) -- Temperature of the cell in [K].
28+
- **density** (*double[]*) -- Density of the cell in [g/cm3].
2829

2930
**/materials/**
3031

docs/source/io_formats/summary.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Summary File Format
55
===================
66

7-
The current version of the summary file format is 6.0.
7+
The current version of the summary file format is 6.1.
88

99
**/**
1010

@@ -38,6 +38,7 @@ The current version of the summary file format is 6.0.
3838
is an array if the cell uses distributed materials, otherwise it is
3939
a scalar.
4040
- **temperature** (*double[]*) -- Temperature of the cell in Kelvin.
41+
- **density** (*double[]*) -- Density of the cell in [g/cm3].
4142
- **translation** (*double[3]*) -- Translation applied to the fill
4243
universe. This dataset is present only if fill_type is set to
4344
'universe'.

include/openmc/capi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ int openmc_cell_get_fill(
1717
int openmc_cell_get_id(int32_t index, int32_t* id);
1818
int openmc_cell_get_temperature(
1919
int32_t index, const int32_t* instance, double* T);
20+
int openmc_cell_get_density(
21+
int32_t index, const int32_t* instance, double* rho);
2022
int openmc_cell_get_translation(int32_t index, double xyz[]);
2123
int openmc_cell_get_rotation(int32_t index, double rot[], size_t* n);
2224
int openmc_cell_get_name(int32_t index, const char** name);
@@ -27,6 +29,8 @@ int openmc_cell_set_fill(
2729
int openmc_cell_set_id(int32_t index, int32_t id);
2830
int openmc_cell_set_temperature(
2931
int32_t index, double T, const int32_t* instance, bool set_contained = false);
32+
int openmc_cell_set_density(int32_t index, double rho, const int32_t* instance,
33+
bool set_contained = false);
3034
int openmc_cell_set_translation(int32_t index, const double xyz[]);
3135
int openmc_cell_set_rotation(int32_t index, const double rot[], size_t rot_len);
3236
int openmc_dagmc_universe_get_cell_ids(

include/openmc/cell.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ class Cell {
216216
//! \return Temperature in [K]
217217
double temperature(int32_t instance = -1) const;
218218

219+
//! Get the density multiplier of a cell instance
220+
//! \param[in] instance Instance index. If -1 is given, the density multiplier
221+
//! for the first instance is returned.
222+
//! \return Density multiplier
223+
double density_mult(int32_t instance = -1) const;
224+
225+
//! Get the density of a cell instance in g/cm3
226+
//! \param[in] instance Instance index. If -1 is given, the density
227+
//! for the first instance is returned.
228+
//! \return Density in [g/cm3]
229+
double density(int32_t instance = -1) const;
230+
219231
//! Set the temperature of a cell instance
220232
//! \param[in] T Temperature in [K]
221233
//! \param[in] instance Instance index. If -1 is given, the temperature for
@@ -226,6 +238,16 @@ class Cell {
226238
void set_temperature(
227239
double T, int32_t instance = -1, bool set_contained = false);
228240

241+
//! Set the density of a cell instance
242+
//! \param[in] density Density [g/cm3]
243+
//! \param[in] instance Instance index. If -1 is given, the density
244+
//! for all instances is set.
245+
//! \param[in] set_contained If this cell is not filled with a material,
246+
//! collect all contained cells with material fills and set their
247+
//! densities.
248+
void set_density(
249+
double density, int32_t instance = -1, bool set_contained = false);
250+
229251
int32_t n_instances() const;
230252

231253
//! Set the rotation matrix of a cell instance
@@ -334,6 +356,9 @@ class Cell {
334356
//! T. The units are sqrt(eV).
335357
vector<double> sqrtkT_;
336358

359+
//! \brief Unitless density multiplier(s) within this cell.
360+
vector<double> density_mult_;
361+
337362
//! \brief Neighboring cells in the same universe.
338363
NeighborList neighbors_;
339364

include/openmc/constants.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ constexpr int HDF5_VERSION[] {3, 0};
2828
constexpr array<int, 2> VERSION_STATEPOINT {18, 1};
2929
constexpr array<int, 2> VERSION_PARTICLE_RESTART {2, 0};
3030
constexpr array<int, 2> VERSION_TRACK {3, 0};
31-
constexpr array<int, 2> VERSION_SUMMARY {6, 0};
31+
constexpr array<int, 2> VERSION_SUMMARY {6, 1};
3232
constexpr array<int, 2> VERSION_VOLUME {1, 0};
3333
constexpr array<int, 2> VERSION_VOXEL {2, 0};
3434
constexpr array<int, 2> VERSION_MGXS_LIBRARY {1, 0};
35-
constexpr array<int, 2> VERSION_PROPERTIES {1, 0};
35+
constexpr array<int, 2> VERSION_PROPERTIES {1, 1};
3636
constexpr array<int, 2> VERSION_WEIGHT_WINDOWS {1, 0};
3737

3838
// ============================================================================

include/openmc/geometry_aux.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ void adjust_indices();
3737

3838
void assign_temperatures();
3939

40+
//==============================================================================
41+
//! Finalize densities (compute density multipliers).
42+
//==============================================================================
43+
44+
void finalize_cell_densities();
45+
4046
//==============================================================================
4147
//! \brief Obtain a list of temperatures that each nuclide/thermal scattering
4248
//! table appears at in the model. Later, this list is used to determine the

include/openmc/material.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class Material {
9999
//----------------------------------------------------------------------------
100100
// Accessors
101101

102+
//! Get the atom density in [atom/b-cm]
103+
//! \return Density in [atom/b-cm]
104+
double atom_density(int32_t i, double rho_multiplier = 1.0) const
105+
{
106+
return atom_density_(i) * rho_multiplier;
107+
}
108+
102109
//! Get density in [atom/b-cm]
103110
//! \return Density in [atom/b-cm]
104111
double density() const { return density_; }

include/openmc/particle_data.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ class GeometryState {
389389
const double& sqrtkT() const { return sqrtkT_; }
390390
double& sqrtkT_last() { return sqrtkT_last_; }
391391

392+
// density multiplier of the current and last cell
393+
double& density_mult() { return density_mult_; }
394+
const double& density_mult() const { return density_mult_; }
395+
double& density_mult_last() { return density_mult_last_; }
396+
392397
private:
393398
int64_t id_ {-1}; //!< Unique ID
394399

@@ -417,6 +422,9 @@ class GeometryState {
417422
double sqrtkT_ {-1.0}; //!< sqrt(k_Boltzmann * temperature) in eV
418423
double sqrtkT_last_ {0.0}; //!< last temperature
419424

425+
double density_mult_ {1.0}; //!< density multiplier
426+
double density_mult_last_ {1.0}; //!< last density multiplier
427+
420428
#ifdef OPENMC_DAGMC_ENABLED
421429
moab::DagMC::RayHistory history_;
422430
Direction last_dir_;

openmc/cell.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class Cell(IDManagerMixin):
7272
temperature : float or iterable of float
7373
Temperature of the cell in Kelvin. Multiple temperatures can be given
7474
to give each distributed cell instance a unique temperature.
75+
density : float or iterable of float
76+
Density of the cell in [g/cm3]. Multiple densities can be given to give
77+
each distributed cell instance a unique density. Densities set here will
78+
override the density set on materials used to fill the cell.
7579
translation : Iterable of float
7680
If the cell is filled with a universe, this array specifies a vector
7781
that is used to translate (shift) the universe.
@@ -109,6 +113,7 @@ def __init__(self, cell_id=None, name='', fill=None, region=None):
109113
self._rotation = None
110114
self._rotation_matrix = None
111115
self._temperature = None
116+
self._density = None
112117
self._translation = None
113118
self._paths = None
114119
self._num_instances = None
@@ -141,6 +146,7 @@ def __repr__(self):
141146
if self.fill_type == 'material':
142147
string += '\t{0: <15}=\t{1}\n'.format('Temperature',
143148
self.temperature)
149+
string += '\t{0: <15}=\t{1}\n'.format('Density', self.density)
144150
string += '{: <16}=\t{}\n'.format('\tTranslation', self.translation)
145151
string += '{: <16}=\t{}\n'.format('\tVolume', self.volume)
146152

@@ -257,6 +263,30 @@ def temperature(self, temperature):
257263
else:
258264
self._temperature = temperature
259265

266+
@property
267+
def density(self):
268+
return self._density
269+
270+
@density.setter
271+
def density(self, density):
272+
# Make sure densities are greater than zero
273+
cv.check_type('cell density', density, (Iterable, Real), none_ok=True)
274+
if isinstance(density, Iterable):
275+
cv.check_type('cell density', density, Iterable, Real)
276+
for rho in density:
277+
cv.check_greater_than('cell density', rho, 0.0, True)
278+
elif isinstance(density, Real):
279+
cv.check_greater_than('cell density', density, 0.0, True)
280+
281+
# If this cell is filled with a universe or lattice, propagate
282+
# densities to all cells contained. Otherwise, simply assign it.
283+
if self.fill_type in ('universe', 'lattice'):
284+
for c in self.get_all_cells().values():
285+
if c.fill_type == 'material':
286+
c._density = density
287+
else:
288+
self._density = density
289+
260290
@property
261291
def translation(self):
262292
return self._translation
@@ -525,6 +555,8 @@ def clone(self, clone_materials=True, clone_regions=True, memo=None):
525555
clone.volume = self.volume
526556
if self.temperature is not None:
527557
clone.temperature = self.temperature
558+
if self.density is not None:
559+
clone.density = self.density
528560
if self.translation is not None:
529561
clone.translation = self.translation
530562
if self.rotation is not None:
@@ -650,6 +682,12 @@ def create_surface_elements(node, element, memo=None):
650682
else:
651683
element.set("temperature", str(self.temperature))
652684

685+
if self.density is not None:
686+
if isinstance(self.density, Iterable):
687+
element.set("density", ' '.join(str(t) for t in self.density))
688+
else:
689+
element.set("density", str(self.density))
690+
653691
if self.translation is not None:
654692
element.set("translation", ' '.join(map(str, self.translation)))
655693

@@ -711,10 +749,13 @@ def from_xml_element(cls, elem, surfaces, materials, get_universe):
711749
c.temperature = temperature
712750
else:
713751
c.temperature = temperature[0]
752+
density = get_elem_list(elem, 'density', float)
753+
if density is not None:
754+
c.density = density if len(density) > 1 else density[0]
714755
v = get_text(elem, 'volume')
715756
if v is not None:
716757
c.volume = float(v)
717-
for key in ('temperature', 'rotation', 'translation'):
758+
for key in ('temperature', 'density', 'rotation', 'translation'):
718759
values = get_elem_list(elem, key, float)
719760
if values is not None:
720761
if key == 'rotation' and len(values) == 9:

0 commit comments

Comments
 (0)