|  | 
|  | 1 | +import openmc | 
|  | 2 | + | 
|  | 3 | + | 
|  | 4 | +def test_get_tally_filter_type(run_in_tmpdir): | 
|  | 5 | +    """Test various ways of retrieving tallies from a StatePoint object.""" | 
|  | 6 | + | 
|  | 7 | +    mat = openmc.Material() | 
|  | 8 | +    mat.add_nuclide("H1", 1.0) | 
|  | 9 | +    mat.set_density("g/cm3", 10.0) | 
|  | 10 | + | 
|  | 11 | +    sphere = openmc.Sphere(r=10.0, boundary_type="vacuum") | 
|  | 12 | +    cell = openmc.Cell(fill=mat, region=-sphere) | 
|  | 13 | +    geometry = openmc.Geometry([cell]) | 
|  | 14 | + | 
|  | 15 | +    settings = openmc.Settings() | 
|  | 16 | +    settings.particles = 10 | 
|  | 17 | +    settings.batches = 2 | 
|  | 18 | +    settings.run_mode = "fixed source" | 
|  | 19 | + | 
|  | 20 | +    reg_mesh = openmc.RegularMesh().from_domain(cell) | 
|  | 21 | +    tally1 = openmc.Tally(tally_id=1) | 
|  | 22 | +    mesh_filter = openmc.MeshFilter(reg_mesh) | 
|  | 23 | +    tally1.filters = [mesh_filter] | 
|  | 24 | +    tally1.scores = ["flux"] | 
|  | 25 | + | 
|  | 26 | +    tally2 = openmc.Tally(tally_id=2, name="heating tally") | 
|  | 27 | +    cell_filter = openmc.CellFilter(cell) | 
|  | 28 | +    tally2.filters = [cell_filter] | 
|  | 29 | +    tally2.scores = ["heating"] | 
|  | 30 | + | 
|  | 31 | +    tallies = openmc.Tallies([tally1, tally2]) | 
|  | 32 | +    model = openmc.Model( | 
|  | 33 | +        geometry=geometry, materials=[mat], settings=settings, tallies=tallies | 
|  | 34 | +    ) | 
|  | 35 | + | 
|  | 36 | +    sp_filename = model.run() | 
|  | 37 | + | 
|  | 38 | +    sp = openmc.StatePoint(sp_filename) | 
|  | 39 | + | 
|  | 40 | +    tally_found = sp.get_tally(filter_type=openmc.MeshFilter) | 
|  | 41 | +    assert tally_found.id == 1 | 
|  | 42 | + | 
|  | 43 | +    tally_found = sp.get_tally(filter_type=openmc.CellFilter) | 
|  | 44 | +    assert tally_found.id == 2 | 
|  | 45 | + | 
|  | 46 | +    tally_found = sp.get_tally(filters=[mesh_filter]) | 
|  | 47 | +    assert tally_found.id == 1 | 
|  | 48 | + | 
|  | 49 | +    tally_found = sp.get_tally(filters=[cell_filter]) | 
|  | 50 | +    assert tally_found.id == 2 | 
|  | 51 | + | 
|  | 52 | +    tally_found = sp.get_tally(scores=["heating"]) | 
|  | 53 | +    assert tally_found.id == 2 | 
|  | 54 | + | 
|  | 55 | +    tally_found = sp.get_tally(name="heating tally") | 
|  | 56 | +    assert tally_found.id == 2 | 
|  | 57 | + | 
|  | 58 | +    tally_found = sp.get_tally(name=None) | 
|  | 59 | +    assert tally_found.id == 1 | 
|  | 60 | + | 
|  | 61 | +    tally_found = sp.get_tally(id=1) | 
|  | 62 | +    assert tally_found.id == 1 | 
|  | 63 | + | 
|  | 64 | +    tally_found = sp.get_tally(id=2) | 
|  | 65 | +    assert tally_found.id == 2 | 
0 commit comments