Skip to content

Commit 7d5fd4e

Browse files
committed
Initial Implementation of virtual lattice, with contributions by Li Ruihan
1 parent cff247e commit 7d5fd4e

8 files changed

Lines changed: 550 additions & 20 deletions

File tree

include/openmc/cell.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Universe {
6060
public:
6161
int32_t id_; //!< Unique ID
6262
vector<int32_t> cells_; //!< Cells within this universe
63+
int filled_with_triso_base_ = -1;
6364

6465
//! \brief Write universe information to an HDF5 group.
6566
//! \param group_id An HDF5 group id.
@@ -212,6 +213,15 @@ class Cell {
212213
int32_t fill_; //!< Universe # filling this cell
213214
int32_t n_instances_ {0}; //!< Number of instances of this cell
214215
GeometryType geom_type_; //!< Geometric representation type (CSG, DAGMC)
216+
bool virtual_lattice_; //!< If the cell is the base of a virtual triso lattice
217+
bool triso_particle_;
218+
219+
220+
// Specification of the viryual lattice
221+
vector<double> vl_lower_left_;
222+
vector<double> vl_pitch_;
223+
vector<int32_t> vl_shape_;
224+
vector<vector<int32_t>> vl_triso_distribution_;
215225

216226
//! \brief Index corresponding to this cell in distribcell arrays
217227
int distribcell_index_ {C_NONE};

include/openmc/surface.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class Surface {
8888
std::shared_ptr<BoundaryCondition> bc_ {nullptr}; //!< Boundary condition
8989
GeometryType geom_type_; //!< Geometry type indicator (CSG or DAGMC)
9090
bool surf_source_ {false}; //!< Activate source banking for the surface?
91+
int triso_base_index_;
92+
int triso_particle_index_ = -1;
93+
bool is_triso_surface_ = false;
9194

9295
explicit Surface(pugi::xml_node surf_node);
9396
Surface();
@@ -126,6 +129,11 @@ class Surface {
126129
//! exactly on the surface.
127130
virtual double distance(Position r, Direction u, bool coincident) const = 0;
128131

132+
virtual bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const { return {}; };
133+
virtual void connect_to_triso_base(int triso_index, std::string key) {};
134+
virtual vector<double> get_center() const { return {}; };
135+
virtual double get_radius() const { return {}; };
136+
129137
//! Compute the local outward normal direction of the surface.
130138
//! \param r A 3D Cartesian coordinate.
131139
//! \return Normal direction
@@ -164,6 +172,7 @@ class SurfaceXPlane : public CSGSurface {
164172
double distance(Position r, Direction u, bool coincident) const;
165173
Direction normal(Position r) const;
166174
void to_hdf5_inner(hid_t group_id) const;
175+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
167176
BoundingBox bounding_box(bool pos_side) const;
168177

169178
double x0_;
@@ -182,6 +191,7 @@ class SurfaceYPlane : public CSGSurface {
182191
double distance(Position r, Direction u, bool coincident) const;
183192
Direction normal(Position r) const;
184193
void to_hdf5_inner(hid_t group_id) const;
194+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
185195
BoundingBox bounding_box(bool pos_side) const;
186196

187197
double y0_;
@@ -200,6 +210,7 @@ class SurfaceZPlane : public CSGSurface {
200210
double distance(Position r, Direction u, bool coincident) const;
201211
Direction normal(Position r) const;
202212
void to_hdf5_inner(hid_t group_id) const;
213+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
203214
BoundingBox bounding_box(bool pos_side) const;
204215

205216
double z0_;
@@ -218,6 +229,7 @@ class SurfacePlane : public CSGSurface {
218229
double distance(Position r, Direction u, bool coincident) const;
219230
Direction normal(Position r) const;
220231
void to_hdf5_inner(hid_t group_id) const;
232+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
221233

222234
double A_, B_, C_, D_;
223235
};
@@ -237,6 +249,7 @@ class SurfaceXCylinder : public CSGSurface {
237249
Direction normal(Position r) const;
238250
void to_hdf5_inner(hid_t group_id) const;
239251
BoundingBox bounding_box(bool pos_side) const;
252+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
240253

241254
double y0_, z0_, radius_;
242255
};
@@ -256,6 +269,7 @@ class SurfaceYCylinder : public CSGSurface {
256269
Direction normal(Position r) const;
257270
void to_hdf5_inner(hid_t group_id) const;
258271
BoundingBox bounding_box(bool pos_side) const;
272+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
259273

260274
double x0_, z0_, radius_;
261275
};
@@ -275,6 +289,7 @@ class SurfaceZCylinder : public CSGSurface {
275289
Direction normal(Position r) const;
276290
void to_hdf5_inner(hid_t group_id) const;
277291
BoundingBox bounding_box(bool pos_side) const;
292+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
278293

279294
double x0_, y0_, radius_;
280295
};
@@ -291,11 +306,16 @@ class SurfaceSphere : public CSGSurface {
291306
explicit SurfaceSphere(pugi::xml_node surf_node);
292307
double evaluate(Position r) const;
293308
double distance(Position r, Direction u, bool coincident) const;
309+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
310+
vector<double> get_center() const;
311+
double get_radius() const;
312+
void connect_to_triso_base(int triso_index, std::string key);
294313
Direction normal(Position r) const;
295314
void to_hdf5_inner(hid_t group_id) const;
296315
BoundingBox bounding_box(bool pos_side) const;
297316

298317
double x0_, y0_, z0_, radius_;
318+
//int triso_base_index_ = -1;
299319
};
300320

301321
//==============================================================================
@@ -312,6 +332,7 @@ class SurfaceXCone : public CSGSurface {
312332
double distance(Position r, Direction u, bool coincident) const;
313333
Direction normal(Position r) const;
314334
void to_hdf5_inner(hid_t group_id) const;
335+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
315336

316337
double x0_, y0_, z0_, radius_sq_;
317338
};
@@ -330,6 +351,7 @@ class SurfaceYCone : public CSGSurface {
330351
double distance(Position r, Direction u, bool coincident) const;
331352
Direction normal(Position r) const;
332353
void to_hdf5_inner(hid_t group_id) const;
354+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
333355

334356
double x0_, y0_, z0_, radius_sq_;
335357
};
@@ -348,6 +370,7 @@ class SurfaceZCone : public CSGSurface {
348370
double distance(Position r, Direction u, bool coincident) const;
349371
Direction normal(Position r) const;
350372
void to_hdf5_inner(hid_t group_id) const;
373+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
351374

352375
double x0_, y0_, z0_, radius_sq_;
353376
};
@@ -366,6 +389,7 @@ class SurfaceQuadric : public CSGSurface {
366389
double distance(Position r, Direction u, bool coincident) const;
367390
Direction normal(Position r) const;
368391
void to_hdf5_inner(hid_t group_id) const;
392+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
369393

370394
// Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0
371395
double A_, B_, C_, D_, E_, F_, G_, H_, J_, K_;
@@ -384,6 +408,7 @@ class SurfaceXTorus : public CSGSurface {
384408
double distance(Position r, Direction u, bool coincident) const;
385409
Direction normal(Position r) const;
386410
void to_hdf5_inner(hid_t group_id) const;
411+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
387412

388413
double x0_, y0_, z0_, A_, B_, C_;
389414
};
@@ -401,6 +426,7 @@ class SurfaceYTorus : public CSGSurface {
401426
double distance(Position r, Direction u, bool coincident) const;
402427
Direction normal(Position r) const;
403428
void to_hdf5_inner(hid_t group_id) const;
429+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
404430

405431
double x0_, y0_, z0_, A_, B_, C_;
406432
};
@@ -417,6 +443,7 @@ class SurfaceZTorus : public CSGSurface {
417443
double evaluate(Position r) const;
418444
double distance(Position r, Direction u, bool coincident) const;
419445
Direction normal(Position r) const;
446+
bool triso_in_mesh(vector<double> mesh_center, vector<double> lattice_pitch) const;
420447
void to_hdf5_inner(hid_t group_id) const;
421448

422449
double x0_, y0_, z0_, A_, B_, C_;

openmc/cell.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ def __init__(self, cell_id=None, name='', fill=None, region=None):
112112
self._num_instances = None
113113
self._volume = None
114114
self._atoms = None
115+
self._triso_particle = False
116+
self.virtual_lattice = False
117+
self.lower_left = None
118+
self.pitch = None
119+
self.shape = None
120+
115121

116122
def __contains__(self, point):
117123
if self.region is None:
@@ -572,6 +578,14 @@ def create_xml_subelement(self, xml_element, memo=None):
572578
"""
573579
element = ET.Element("cell")
574580
element.set("id", str(self.id))
581+
if self._triso_particle:
582+
element.set("triso_particle", 'true')
583+
if self.virtual_lattice:
584+
element.set("virtual_lattice", str(self.virtual_lattice))
585+
element.set("lower_left", ' '.join(map(str, self.lower_left)))
586+
element.set("pitch", ' '.join(map(str, self.pitch)))
587+
element.set("shape", ' '.join(map(str, self.shape)))
588+
575589

576590
if len(self._name) > 0:
577591
element.set("name", str(self.name))

openmc/model/triso.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class TRISO(openmc.Cell):
5555

5656
def __init__(self, outer_radius, fill, center=(0., 0., 0.)):
5757
self._surface = openmc.Sphere(r=outer_radius)
58+
self._triso_particle = False
5859
super().__init__(fill=fill, region=-self._surface)
5960
self.center = np.asarray(center)
6061

@@ -800,7 +801,7 @@ def repel_spheres(self, p, q, d, d_new):
800801
q[:] = (q - c)*ll[0]/r + c
801802

802803

803-
def create_triso_lattice(trisos, lower_left, pitch, shape, background):
804+
def create_triso_lattice(trisos, lower_left, pitch, shape, background, virtual=False):
804805
"""Create a lattice containing TRISO particles for optimized tracking.
805806
806807
Parameters
@@ -824,9 +825,16 @@ def create_triso_lattice(trisos, lower_left, pitch, shape, background):
824825
825826
"""
826827

828+
if virtual:
829+
real_pitch = copy.deepcopy(pitch)
830+
real_shape = copy.deepcopy(shape)
831+
pitch = [real_pitch[i]*real_shape[i] for i in range(len(real_pitch))]
832+
shape = [1 for i in range(len(real_shape))]
833+
827834
lattice = openmc.RectLattice()
828835
lattice.lower_left = lower_left
829836
lattice.pitch = pitch
837+
830838

831839
indices = list(np.broadcast(*np.ogrid[:shape[2], :shape[1], :shape[0]]))
832840
triso_locations = {idx: [] for idx in indices}
@@ -843,6 +851,8 @@ def create_triso_lattice(trisos, lower_left, pitch, shape, background):
843851
y0=t._surface.y0,
844852
z0=t._surface.z0)
845853
t_copy.region = -t_copy._surface
854+
if virtual:
855+
t_copy._triso_particle = True
846856
triso_locations[idx].append(t_copy)
847857
else:
848858
warnings.warn('TRISO particle is partially or completely '
@@ -857,6 +867,13 @@ def create_triso_lattice(trisos, lower_left, pitch, shape, background):
857867
else:
858868
background_cell = openmc.Cell(fill=background)
859869

870+
if virtual:
871+
background_cell.virtual_lattice = True
872+
background_cell.pitch = real_pitch
873+
background_cell.shape = real_shape
874+
background_cell.lower_left = [-pitch[i]/2 for i in range(len(pitch))]
875+
876+
860877
u = openmc.Universe()
861878
u.add_cell(background_cell)
862879
for t in triso_list:

0 commit comments

Comments
 (0)