Skip to content

Commit 309841e

Browse files
author
skywalker_cn
committed
Merge branch 'virtual_lattice' into virtual_lattice_0.15.2
2 parents 00edc77 + 4c1c604 commit 309841e

11 files changed

Lines changed: 818 additions & 4 deletions

File tree

include/openmc/cell.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,15 @@ class Cell {
319319
Fill type_; //!< Material, universe, or lattice
320320
int32_t universe_; //!< Universe # this cell is in
321321
int32_t fill_; //!< Universe # filling this cell
322+
bool virtual_lattice_; //!< If the cell is the base of a virtual triso lattice
323+
bool triso_particle_;
322324

325+
326+
//! \brief Specification of the virtual lattice
327+
vector<double> vl_lower_left_;
328+
vector<double> vl_pitch_;
329+
vector<int32_t> vl_shape_;
330+
vector<vector<int32_t>> vl_triso_distribution_;
323331
//! \brief Index corresponding to this cell in distribcell arrays
324332
int distribcell_index_ {C_NONE};
325333

include/openmc/surface.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Surface {
3939
std::string name_; //!< User-defined name
4040
unique_ptr<BoundaryCondition> bc_; //!< Boundary condition
4141
bool surf_source_ {false}; //!< Activate source banking for the surface?
42+
int triso_base_index_;
43+
int triso_particle_index_ = -1;
44+
bool is_triso_surface_ = false;
4245

4346
explicit Surface(pugi::xml_node surf_node);
4447
Surface();
@@ -78,6 +81,15 @@ class Surface {
7881
//! exactly on the surface.
7982
virtual double distance(Position r, Direction u, bool coincident) const = 0;
8083

84+
virtual bool triso_in_mesh(
85+
vector<double> mesh_center, vector<double> lattice_pitch) const
86+
{
87+
return {};
88+
};
89+
virtual void connect_to_triso_base(int triso_index, std::string key) {};
90+
virtual vector<double> get_center() const { return {}; };
91+
virtual double get_radius() const { return {}; };
92+
8193
//! Compute the local outward normal direction of the surface.
8294
//! \param r A 3D Cartesian coordinate.
8395
//! \return Normal direction
@@ -116,6 +128,8 @@ class SurfaceXPlane : public Surface {
116128
double distance(Position r, Direction u, bool coincident) const override;
117129
Direction normal(Position r) const override;
118130
void to_hdf5_inner(hid_t group_id) const override;
131+
bool triso_in_mesh(
132+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
119133
BoundingBox bounding_box(bool pos_side) const override;
120134

121135
double x0_;
@@ -134,6 +148,8 @@ class SurfaceYPlane : public Surface {
134148
double distance(Position r, Direction u, bool coincident) const override;
135149
Direction normal(Position r) const override;
136150
void to_hdf5_inner(hid_t group_id) const override;
151+
bool triso_in_mesh(
152+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
137153
BoundingBox bounding_box(bool pos_side) const override;
138154

139155
double y0_;
@@ -152,6 +168,8 @@ class SurfaceZPlane : public Surface {
152168
double distance(Position r, Direction u, bool coincident) const override;
153169
Direction normal(Position r) const override;
154170
void to_hdf5_inner(hid_t group_id) const override;
171+
bool triso_in_mesh(
172+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
155173
BoundingBox bounding_box(bool pos_side) const override;
156174

157175
double z0_;
@@ -169,6 +187,8 @@ class SurfacePlane : public Surface {
169187
double evaluate(Position r) const override;
170188
double distance(Position r, Direction u, bool coincident) const override;
171189
Direction normal(Position r) const override;
190+
bool triso_in_mesh(
191+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
172192
void to_hdf5_inner(hid_t group_id) const override;
173193

174194
double A_, B_, C_, D_;
@@ -188,6 +208,8 @@ class SurfaceXCylinder : public Surface {
188208
double distance(Position r, Direction u, bool coincident) const override;
189209
Direction normal(Position r) const override;
190210
void to_hdf5_inner(hid_t group_id) const override;
211+
bool triso_in_mesh(
212+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
191213
BoundingBox bounding_box(bool pos_side) const override;
192214

193215
double y0_, z0_, radius_;
@@ -207,6 +229,8 @@ class SurfaceYCylinder : public Surface {
207229
double distance(Position r, Direction u, bool coincident) const override;
208230
Direction normal(Position r) const override;
209231
void to_hdf5_inner(hid_t group_id) const override;
232+
bool triso_in_mesh(
233+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
210234
BoundingBox bounding_box(bool pos_side) const override;
211235

212236
double x0_, z0_, radius_;
@@ -226,6 +250,8 @@ class SurfaceZCylinder : public Surface {
226250
double distance(Position r, Direction u, bool coincident) const override;
227251
Direction normal(Position r) const override;
228252
void to_hdf5_inner(hid_t group_id) const override;
253+
bool triso_in_mesh(
254+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
229255
BoundingBox bounding_box(bool pos_side) const override;
230256

231257
double x0_, y0_, radius_;
@@ -245,9 +271,12 @@ class SurfaceSphere : public Surface {
245271
double distance(Position r, Direction u, bool coincident) const override;
246272
Direction normal(Position r) const override;
247273
void to_hdf5_inner(hid_t group_id) const override;
274+
bool triso_in_mesh(
275+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
248276
BoundingBox bounding_box(bool pos_side) const override;
249277

250278
double x0_, y0_, z0_, radius_;
279+
// int triso_base_index_ = -1;
251280
};
252281

253282
//==============================================================================
@@ -264,6 +293,8 @@ class SurfaceXCone : public Surface {
264293
double distance(Position r, Direction u, bool coincident) const override;
265294
Direction normal(Position r) const override;
266295
void to_hdf5_inner(hid_t group_id) const override;
296+
bool triso_in_mesh(
297+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
267298

268299
double x0_, y0_, z0_, radius_sq_;
269300
};
@@ -282,6 +313,8 @@ class SurfaceYCone : public Surface {
282313
double distance(Position r, Direction u, bool coincident) const override;
283314
Direction normal(Position r) const override;
284315
void to_hdf5_inner(hid_t group_id) const override;
316+
bool triso_in_mesh(
317+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
285318

286319
double x0_, y0_, z0_, radius_sq_;
287320
};
@@ -300,6 +333,8 @@ class SurfaceZCone : public Surface {
300333
double distance(Position r, Direction u, bool coincident) const override;
301334
Direction normal(Position r) const override;
302335
void to_hdf5_inner(hid_t group_id) const override;
336+
bool triso_in_mesh(
337+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
303338

304339
double x0_, y0_, z0_, radius_sq_;
305340
};
@@ -318,6 +353,8 @@ class SurfaceQuadric : public Surface {
318353
double distance(Position r, Direction u, bool coincident) const override;
319354
Direction normal(Position r) const override;
320355
void to_hdf5_inner(hid_t group_id) const override;
356+
bool triso_in_mesh(
357+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
321358

322359
// Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0
323360
double A_, B_, C_, D_, E_, F_, G_, H_, J_, K_;
@@ -336,6 +373,8 @@ class SurfaceXTorus : public Surface {
336373
double distance(Position r, Direction u, bool coincident) const override;
337374
Direction normal(Position r) const override;
338375
void to_hdf5_inner(hid_t group_id) const override;
376+
bool triso_in_mesh(
377+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
339378

340379
double x0_, y0_, z0_, A_, B_, C_;
341380
};
@@ -353,6 +392,8 @@ class SurfaceYTorus : public Surface {
353392
double distance(Position r, Direction u, bool coincident) const override;
354393
Direction normal(Position r) const override;
355394
void to_hdf5_inner(hid_t group_id) const override;
395+
bool triso_in_mesh(
396+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
356397

357398
double x0_, y0_, z0_, A_, B_, C_;
358399
};
@@ -370,6 +411,8 @@ class SurfaceZTorus : public Surface {
370411
double distance(Position r, Direction u, bool coincident) const override;
371412
Direction normal(Position r) const override;
372413
void to_hdf5_inner(hid_t group_id) const override;
414+
bool triso_in_mesh(
415+
vector<double> mesh_center, vector<double> lattice_pitch) const override;
373416

374417
double x0_, y0_, z0_, A_, B_, C_;
375418
};

openmc/cell.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ def __init__(self, cell_id=None, name='', fill=None, region=None):
114114
self._num_instances = None
115115
self._volume = None
116116
self._atoms = None
117+
self._triso_particle = False
118+
self.virtual_lattice = False
119+
self.lower_left = None
120+
self.pitch = None
121+
self.shape = None
117122

118123
def __contains__(self, point):
119124
if self.region is None:
@@ -593,6 +598,13 @@ def create_xml_subelement(self, xml_element, memo=None):
593598
"""
594599
element = ET.Element("cell")
595600
element.set("id", str(self.id))
601+
if self._triso_particle:
602+
element.set("triso_particle", 'true')
603+
if self.virtual_lattice:
604+
element.set("virtual_lattice", str(self.virtual_lattice))
605+
element.set("lower_left", ' '.join(map(str, self.lower_left)))
606+
element.set("pitch", ' '.join(map(str, self.pitch)))
607+
element.set("shape", ' '.join(map(str, self.shape)))
596608

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

openmc/model/triso.py

Lines changed: 16 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

@@ -802,7 +803,7 @@ def repel_spheres(self, p, q, d, d_new):
802803
q[:] = (q - c)*ll[0]/r + c
803804

804805

805-
def create_triso_lattice(trisos, lower_left, pitch, shape, background):
806+
def create_triso_lattice(trisos, lower_left, pitch, shape, background, virtual=False):
806807
"""Create a lattice containing TRISO particles for optimized tracking.
807808
808809
Parameters
@@ -826,6 +827,12 @@ def create_triso_lattice(trisos, lower_left, pitch, shape, background):
826827
827828
"""
828829

830+
if virtual:
831+
real_pitch = copy.deepcopy(pitch)
832+
real_shape = copy.deepcopy(shape)
833+
pitch = [real_pitch[i]*real_shape[i] for i in range(len(real_pitch))]
834+
shape = [1 for i in range(len(real_shape))]
835+
829836
lattice = openmc.RectLattice()
830837
lattice.lower_left = lower_left
831838
lattice.pitch = pitch
@@ -845,6 +852,8 @@ def create_triso_lattice(trisos, lower_left, pitch, shape, background):
845852
y0=t._surface.y0,
846853
z0=t._surface.z0)
847854
t_copy.region = -t_copy._surface
855+
if virtual:
856+
t_copy._triso_particle = True
848857
triso_locations[idx].append(t_copy)
849858
else:
850859
warnings.warn('TRISO particle is partially or completely '
@@ -859,6 +868,12 @@ def create_triso_lattice(trisos, lower_left, pitch, shape, background):
859868
else:
860869
background_cell = openmc.Cell(fill=background)
861870

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

0 commit comments

Comments
 (0)