示例#1
0
def test_negativeDensityFix(safeargs):
    manager = hydep.Manager(*safeargs)
    vec = numpy.ones((10, 1), dtype=int)

    N_NEGS = 2
    vec[:N_NEGS] = -1
    threshold = N_NEGS / (10 - N_NEGS)

    with pytest.warns(hydep.NegativeDensityWarning):
        manager._checkFixNegativeDensities(vec)
    assert (vec >= 0).all()

    vec[:N_NEGS] = -1
    manager.negativeDensityWarnPercent = 2 * threshold

    with pytest.warns(None) as record:
        manager._checkFixNegativeDensities(vec)
    assert (vec >= 0).all()
    assert len(record) == 0

    vec[:N_NEGS] = -1
    manager.negativeDensityWarnPercent = 0
    manager.negativeDensityErrorPercent = 0.95 * threshold

    with pytest.raises(hydep.NegativeDensityError):
        manager._checkFixNegativeDensities(vec)
示例#2
0
def test_external(runInTempDir, endfChain, pincell):
    datadir = os.environ.get("SERPENT_DATA")
    if not datadir:
        pytest.skip("Need SERPENT_DATA environment variable")
    serpent = hdserpent.CoupledSerpentSolver()
    simplerom = hydep.simplerom.SimpleROSolver()

    manager = hydep.Manager(endfChain, [50], 1e3, substepDivision=2)
    integrator = hydep.PredictorIntegrator(pincell, serpent, simplerom, manager)

    integrator.configure(
        {
            "hydep": {
                "boundary conditions": "reflective",
                "basedir": runInTempDir,
                "rundir": None,
                "use temp dir": True,
            },
            "hydep.serpent": {
                "seed": 123456789,
                "executable": PATCHED_EXE,
                "particles": 100,
                "generations per batch": 10,
                "active": 2,
                "inactive": 5,
                "acelib": "sss_endfb7u.xsdata",
                "declib": "sss_endfb7.dec",
                "nfylib": "sss_endfb7.nfy",
                "datadir": datadir,
            },
        }
    )

    tester = HdfResultCompare()
    tester.main(integrator)
示例#3
0
def manager(simpleChain):
    daysteps = numpy.array([5, 10])
    powers = [6e6, 10e6]
    divisions = 1

    manager = hydep.Manager(simpleChain,
                            daysteps,
                            powers,
                            divisions,
                            numPreliminary=1)
    assert manager.timesteps == pytest.approx(daysteps *
                                              hydep.constants.SECONDS_PER_DAY)
    return manager
示例#4
0
def mockProblem():
    fuel = hydep.BurnableMaterial("fuel", mdens=10.4, volume=1.0, U235=1e-5)
    univ = hydep.InfiniteMaterial(fuel)
    model = hydep.Model(univ)

    # manager
    chain = hydep.DepletionChain(fuel.keys())
    manager = hydep.Manager(chain, [10], 1e6, 1)

    return hydep.PredictorIntegrator(
        model,
        MockHFSolver(),
        MockROMSolver(),
        manager,
        MockStore(),
    )
示例#5
0
def depletionHarness(endfChain, depletionModel):

    burnable = tuple(depletionModel.root.findBurnableMaterials())
    N_BURNABLE = len(burnable)
    N_GROUPS = 1

    # Get microscopic cross sections, flux

    datadir = pathlib.Path(__file__).parent
    fluxes = numpy.loadtxt(datadir / "fluxes.dat").reshape(
        N_BURNABLE, N_GROUPS)

    fissionYields = hydep.internal.FakeSequence(
        buildFissionYields(endfChain, ene=THERMAL_ENERGY, fallbackIndex=0),
        N_BURNABLE)

    microxs = hydep.internal.MaterialDataArray(
        endfChain.reactionIndex,
        numpy.zeros((N_BURNABLE, len(endfChain.reactionIndex))))

    for ix in range(N_BURNABLE):
        mxsfile = datadir / "mxs{}.dat".format(ix + 1)
        assert mxsfile.is_file()
        flux = fluxes[ix] / burnable[ix].volume
        mxsdata = numpy.loadtxt(mxsfile)

        for z, r, m in zip(
                mxsdata[:, 0].astype(int),
                mxsdata[:, 1].astype(int),
                flux * mxsdata[:, 2:2 + 1 + N_GROUPS],
        ):
            microxs.data[ix, endfChain.reactionIndex(z, r)] = m

    timestep = 50
    power = 6e6
    divisions = 1
    manager = hydep.Manager(endfChain, [timestep], [power], divisions)
    manager.beforeMain(depletionModel)

    yield DepBundle(manager, microxs, fissionYields)
示例#6
0
def test_negativeDensityAttrs(safeargs):
    man = hydep.Manager(*safeargs,
                        negativeDensityWarnPercent=0.1,
                        negativeDensityErrorPercent=0.5)
    assert man.negativeDensityWarnPercent == 0.1
    assert man.negativeDensityErrorPercent == 0.5
    man.negativeDensityWarnPercent = 0
    man.negativeDensityErrorPercent = 1
    assert man.negativeDensityWarnPercent == 0
    assert man.negativeDensityErrorPercent == 1

    man.negativeDensityWarnPercent = 0.1

    with pytest.raises(ValueError):
        man.negativeDensityErrorPercent = 0.05

    man.negativeDensityErrorPercent = 0.8

    with pytest.raises(ValueError):
        man.negativeDensityWarnPercent = 0.85

    with pytest.raises(ValueError):
        man.negativeDensityWarnPercent = -0.1

    with pytest.raises(ValueError):
        man.negativeDensityErrorPercent = 1.2

    # Test that values are not changed due to previous errors
    assert man.negativeDensityWarnPercent == 0.1
    assert man.negativeDensityErrorPercent == 0.8

    # Test that values can be identical low or high
    man.negativeDensityWarnPercent = 0
    man.negativeDensityErrorPercent = 0
    assert man.negativeDensityErrorPercent == 0.0

    man.negativeDensityErrorPercent = 1
    man.negativeDensityWarnPercent = 1
    assert man.negativeDensityWarnPercent == 1
示例#7
0
def test_managerSubsteps(simpleChain):
    ntimesteps = 3
    safeargs = SafeManagerArgs(simpleChain, (1, ) * ntimesteps, 6e6, 1)

    m1 = hydep.Manager(*safeargs)

    assert len(m1.substeps) == ntimesteps
    assert all(s == safeargs.divisions for s in m1.substeps)

    scaled = list(safeargs.divisions * x for x in range(1, ntimesteps + 1))
    m2 = hydep.Manager(
        safeargs.chain,
        safeargs.timesteps,
        safeargs.power,
        scaled,
    )

    assert len(m2.substeps) == ntimesteps
    assert all(a == r
               for a, r in zip(m2.substeps, scaled)), (scaled, m2.substeps)

    # Test number of divisions must be positive integer
    with pytest.raises(ValueError):
        hydep.Manager(safeargs.chain, safeargs.timesteps, safeargs.power, 0)

    with pytest.raises(TypeError):
        hydep.Manager(safeargs.chain, safeargs.timesteps, safeargs.power, 1.5)

    with pytest.raises(ValueError):
        hydep.Manager(safeargs.chain, safeargs.timesteps, safeargs.power, -1)

    with pytest.raises(ValueError):
        hydep.Manager(safeargs.chain, safeargs.timesteps, safeargs.power, [-1])

    baddivisions = [safeargs.divisions] * (ntimesteps - 1) + [1.5]
    with pytest.raises(TypeError):
        hydep.Manager(safeargs.chain, safeargs.timesteps, safeargs.power,
                      baddivisions)

    baddivisions[-1] = -1
    with pytest.raises(ValueError):
        hydep.Manager(safeargs.chain, safeargs.timesteps, safeargs.power,
                      baddivisions)

    # Test that divisions must be orderable
    divset = {safeargs.divisions * x for x in range(1, ntimesteps + 1)}
    assert len(divset) == ntimesteps

    # Test that numpy arrays are good
    arraySubs = hydep.Manager(
        safeargs.chain,
        safeargs.timesteps,
        safeargs.power,
        numpy.arange(1, ntimesteps + 1),
    )
    assert arraySubs.substeps == tuple(range(1, ntimesteps + 1))

    with pytest.raises(TypeError):
        hydep.Manager(safeargs.chain, safeargs.timesteps, safeargs.power,
                      divset)

    # Test number of provided divisions equal to number of active steps
    with pytest.raises(ValueError):
        hydep.Manager(
            safeargs.chain,
            [1, 1, 1],
            safeargs.power,
            [safeargs.divisions],
            numPreliminary=1,
        )
示例#8
0
def test_managerConstruct(safeargs):
    """Test manager construction"""

    # Test that chain must be provided
    with pytest.raises(TypeError):
        hydep.Manager(None, [1], safeargs.power, safeargs.divisions)

    # Test that timesteps must be 1D
    with pytest.raises(TypeError):
        hydep.Manager(safeargs.chain, [[1, 1], [2, 2]], safeargs.power,
                      safeargs.divisions)

    # Test that power must be > 0
    with pytest.raises(ValueError):
        hydep.Manager(safeargs.chain, safeargs.timesteps, 0,
                      safeargs.divisions)

    with pytest.raises(ValueError):
        hydep.Manager(
            safeargs.chain,
            safeargs.timesteps,
            [safeargs.power, 0],
            safeargs.divisions,
        )

    with pytest.raises(ValueError):
        hydep.Manager(
            safeargs.chain,
            [1, 1],
            [safeargs.power, -safeargs.power],
            safeargs.divisions,
        )

    # Test that number of time steps == number of powers
    with pytest.raises(ValueError):
        hydep.Manager(safeargs.chain, [1], [safeargs.power] * 3,
                      safeargs.divisions)

    # Test that power must be sequence (orderable)
    with pytest.raises(TypeError):
        hydep.Manager(
            safeargs.chain,
            [1, 1],
            {safeargs.power, 2 * safeargs.power},
            safeargs.divisions,
        )

    # Test that number of preliminary must be non-negative integer
    with pytest.raises(TypeError):
        hydep.Manager(
            safeargs.chain,
            safeargs.timesteps,
            safeargs.power,
            safeargs.divisions,
            numPreliminary=[1],
        )

    with pytest.raises(ValueError):
        hydep.Manager(
            safeargs.chain,
            [1, 1, 1, 1],
            safeargs.power,
            safeargs.divisions,
            numPreliminary=-1,
        )

    # Test that number of preliminary < number of provided time steps
    with pytest.raises(ValueError):
        hydep.Manager(
            safeargs.chain,
            [1, 1, 1, 1],
            safeargs.power,
            safeargs.divisions,
            numPreliminary=4,
        )
示例#9
0
def manager(clearIsotopes):
    dep = hydep.Manager(buildDepletionChain(), [5 / SECONDS_PER_DAY], [1.0],
                        [1])

    return dep