Example #1
0
def test_capacity_buffer_num():
    output_file_nobuf5 = 'nobuf5.sqlite'
    output_file_yesbuf5 = 'yesbuf5.sqlite'
    input_file_nobuf5 = output_file_nobuf5.replace('.sqlite', '.json')
    input_file_yesbuf5 = output_file_yesbuf5.replace('.sqlite', '.json')
    with open(input_file_nobuf5, 'w') as f:
        json.dump(nobuf_template5, f)
    s = subprocess.check_output(['cyclus',
                                 '-o',
                                 output_file_nobuf5,
                                 input_file_nobuf5],
                                universal_newlines=True,
                                env=ENV)
    with open(input_file_yesbuf5, 'w') as f:
        json.dump(yesbuf_template5, f)
    s = subprocess.check_output(['cyclus',
                                 '-o',
                                 output_file_yesbuf5,
                                 input_file_yesbuf5],
                                universal_newlines=True,
                                env=ENV)

    # check if calculated demand is 20% higher for yesbuf case
    cur_nobuf5 = functions.get_cursor(output_file_nobuf5)
    cur_yesbuf5 = functions.get_cursor(output_file_yesbuf5)
    calcsupply_nobuf5 = cur_nobuf5.execute(
        "select time, value from timeseriescalc_supplyspent_uox").fetchall()
    calcsupply_yesbuf5 = cur_yesbuf5.execute(
        "select time, value from timeseriescalc_supplyspent_uox").fetchall()
    count = 0
    for x in range(2):
        if (3 + calcsupply_nobuf5[x][1]) != calcsupply_yesbuf5[x][1]:
            count += 1

    assert(count == 0)
Example #2
0
def test_supply_buffer_num():
    output_file_nobuf4 = 'nobuf4.sqlite'
    output_file_yesbuf4 = 'yesbuf4.sqlite'
    input_file_nobuf4 = output_file_nobuf4.replace('.sqlite', '.json')
    input_file_yesbuf4 = output_file_yesbuf4.replace('.sqlite', '.json')
    with open(input_file_nobuf4, 'w') as f:
        json.dump(nobuf_template4, f)
    s = subprocess.check_output(['cyclus',
                                 '-o',
                                 output_file_nobuf4,
                                 input_file_nobuf4],
                                universal_newlines=True,
                                env=ENV)
    with open(input_file_yesbuf4, 'w') as f:
        json.dump(yesbuf_template4, f)
    s = subprocess.check_output(['cyclus',
                                 '-o',
                                 output_file_yesbuf4,
                                 input_file_yesbuf4],
                                universal_newlines=True,
                                env=ENV)

    # check if calculated demand is 1000MW higher for yesbuf case
    cur_nobuf4 = functions.get_cursor(output_file_nobuf4)
    cur_yesbuf4 = functions.get_cursor(output_file_yesbuf4)
    calcdemand_nobuf4 = cur_nobuf4.execute(
        "select time, value from timeseriescalc_demandpower").fetchall()
    calcdemand_yesbuf4 = cur_yesbuf4.execute(
        "select time, value from timeseriescalc_demandpower").fetchall()
    count = 0
    for x in range(2):
        if (3 + calcdemand_nobuf4[x][1]) != calcdemand_yesbuf4[x][1]:
            count += 1

    assert(count == 0)
Example #3
0
def test_supply_buffer():
    output_file_share = 'share.sqlite'
    input_file_share = output_file_share.replace('.sqlite', '.json')
    with open(input_file_share, 'w') as f:
        json.dump(share_template, f)

    s = subprocess.check_output(
        ['cyclus', '-o', output_file_share, input_file_share],
        universal_newlines=True,
        env=ENV)

    # check number of reactors deployed
    cur_share = functions.get_cursor(output_file_share)

    reactors = cur_share.execute("select entertime, prototype from " +
                                 "agententry where prototype = " +
                                 "'reactor1' or prototype = " +
                                 "'reactor2'").fetchall()
    j = 0
    count_errors = 0
    for i in range(1, 4):
        count_reactor1 = 0
        count_reactor2 = 0
        while int(reactors[j][0]) <= i:
            if reactors[j][1] == 'reactor1':
                count_reactor1 += 1
            if reactors[j][1] == 'reactor2':
                count_reactor2 += 1
            j += 1
            if j == len(reactors):
                break
        if count_reactor1 != count_reactor2:
            count_errors += 1
    assert (count_errors == 0)
Example #4
0
def test_supply_buffer_two():
    output_file_nobuf3 = 'nobuf3.sqlite'
    output_file_yesbuf3 = 'yesbuf3.sqlite'
    input_file_nobuf3 = output_file_nobuf3.replace('.sqlite', '.json')
    input_file_yesbuf3 = output_file_yesbuf3.replace('.sqlite', '.json')
    with open(input_file_nobuf3, 'w') as f:
        json.dump(nobuf_template3, f)
    s = subprocess.check_output(['cyclus',
                                 '-o',
                                 output_file_nobuf3,
                                 input_file_nobuf3],
                                universal_newlines=True,
                                env=ENV)
    with open(input_file_yesbuf3, 'w') as f:
        json.dump(yesbuf_template3, f)
    s = subprocess.check_output(['cyclus',
                                 '-o',
                                 output_file_yesbuf3,
                                 input_file_yesbuf3],
                                universal_newlines=True,
                                env=ENV)

    # check if calculated demand is 20% higher for yesbuf case
    cur_nobuf3 = functions.get_cursor(output_file_nobuf3)
    cur_yesbuf3 = functions.get_cursor(output_file_yesbuf3)
    calcdemandpower_nobuf3 = cur_nobuf3.execute(
        "select time, value from timeseriescalc_demandpower").fetchall()
    calcdemandpower_yesbuf3 = cur_yesbuf3.execute(
        "select time, value from timeseriescalc_demandpower").fetchall()
    calcdemandfuel_nobuf3 = cur_nobuf3.execute(
        "select time, value from timeseriescalc_demandfuel").fetchall()
    calcdemandfuel_yesbuf3 = cur_yesbuf3.execute(
        "select time, value from timeseriescalc_demandfuel").fetchall()
    count = 0
    for x in range(2):
        if int(
                1.2 *
                calcdemandpower_nobuf3[x][1]) != int(
                calcdemandpower_yesbuf3[x][1]):
            count += 1
    for x in range(2):
        if calcdemandfuel_nobuf3[x][0] != calcdemandfuel_yesbuf3[x][0]:
            count += 1
    assert(count == 0)
Example #5
0
def test_backdeployment():
    output_ = 'test_backdeployment.sqlite'
    input_path = os.path.abspath(__file__)
    find = 'd3ploy/'
    indx = input_path.rfind('d3ploy/')
    input_ = input_path.replace(
        input_path[indx + len(find):], 'input/linear_pow_demand_backdeployment.xml')
    s = subprocess.check_output(['cyclus', '-o', output_, input_],
                                universal_newlines=True, env=ENV)
    cur = functions.get_cursor(output_)
    reactor2_entry = cur.execute('SELECT Prototype FROM agententry WHERE ' +
                                 'prototype == "sink"').fetchall()
    assert (len(reactor2_entry) == 1)
Example #6
0
def test_tech_pref_allreactor1():
    output_file = 'test_tech_pref_allreactor1.sqlite'
    input_file = output_file.replace('.sqlite', '.json')
    with open(input_file, 'w') as f:
        json.dump(tech_pref_allreactor1_template, f)
    s = subprocess.check_output(['cyclus', '-o', output_file, input_file],
                                universal_newlines=True, env=ENV)
    # check if ran successfully and deployed facilities at time step 1 
    cur = functions.get_cursor(output_file)
    agent_entry = cur.execute("select prototype from agententry").fetchall()
    passes = 0 
    for x in range(0,len(agent_entry)): 
        if agent_entry[x][0] == 'reactor2': 
            passes = 1 
            break 
    assert(passes == 0)
Example #7
0
def test_installed_cap():
    """This test will pass if only one reactor agent enter the simulation
    because the deployment of facilities is based on installed capacity"""

    name = "scenario_input_"
    input_file = name + ".json"
    output_file = name + ".sqlite"
    with open(input_file, 'w') as f:
        json.dump(scenario_input, f)

    s = subprocess.check_output(
        ['cyclus', '-o', output_file, input_file],
        universal_newlines=True,
    )
    cursor = functions.get_cursor(output_file)
    agententry = cursor.execute('SELECT entertime FROM agententry WHERE ' +
                                'prototype == "reactor"').fetchall()
    assert (len(agententry) == 1)
Example #8
0
def test_constraint_deploy():
    output_ = 'test_constraint_deploy.sqlite'
    input_path = os.path.abspath(__file__)
    find = 'd3ploy/'
    indx = input_path.rfind('d3ploy/')
    input_ = input_path.replace(input_path[indx + len(find):],
                                'input/test_transition.xml')
    s = subprocess.check_output(['cyclus', '-o', output_, input_],
                                universal_newlines=True,
                                env=ENV)
    cur = functions.get_cursor(output_)
    reactor2_entry = cur.execute('SELECT entertime FROM agententry WHERE ' +
                                 'prototype == "reactor2"').fetchall()
    time_after_constraint = cur.execute(
        'SELECT time FROM timeseriessupplystorageuox ' +
        'WHERE value > 8000').fetchone()[0]
    for row in reactor2_entry:
        assert (row['entertime'] >= time_after_constraint + 1)
Example #9
0
def test_backdeployment_IC():
    """This test will pass if only 1 sink agent enters the simulation
    , 1 sink is added using the initial facility list. So if the deployment
    of facilities is based on installed capacity, no other facilities will be
    deployed """
    output_ = 'test_supplydriven_installedcap.sqlite'
    input_path = os.path.abspath(__file__)
    find = 'd3ploy/'
    indx = input_path.rfind('d3ploy/')
    input_ = input_path.replace(
        input_path[indx + len(find):],
        'input/linear_pow_demand_backdeployment_initialfac.xml')
    s = subprocess.check_output(['cyclus', '-o', output_, input_],
                                universal_newlines=True,
                                env=ENV)
    cur = functions.get_cursor(output_)
    reactor2_entry = cur.execute('SELECT Prototype FROM agententry WHERE ' +
                                 'prototype == "sink"').fetchall()
    assert (len(reactor2_entry) == 1)
def test_d3ploy(calc_method):
    test_input = {
        "simulation": {
            "archetypes": {
                "spec": [{
                    "lib": "agents",
                    "name": "NullRegion"
                }, {
                    "lib": "cycamore",
                    "name": "Source"
                }, {
                    "lib": "cycamore",
                    "name": "Reactor"
                }, {
                    "lib": "cycamore",
                    "name": "Sink"
                }, {
                    "lib": "d3ploy.timeseries_inst",
                    "name": "TimeSeriesInst"
                }]
            },
            "control": {
                "duration": "10",
                "startmonth": "1",
                "startyear": "2000"
            },
            "facility": [{
                "config": {
                    "Source": {
                        "outcommod": "freshfuel",
                        "outrecipe": "fresh_uox",
                        "throughput": "3000"
                    }
                },
                "name": "source"
            }, {
                "config": {
                    "Sink": {
                        "in_commods": {
                            "val": "spent_fuel"
                        },
                        "max_inv_size": "1e6"
                    }
                },
                "name": "sink"
            }, {
                "config": {
                    "Reactor": {
                        "assem_size": "1000",
                        "cycle_time": "18",
                        "fuel_incommods": {
                            "val": "freshfuel"
                        },
                        "fuel_inrecipes": {
                            "val": "fresh_uox"
                        },
                        "fuel_outcommods": {
                            "val": "spent_fuel"
                        },
                        "fuel_outrecipes": {
                            "val": "spent_uox"
                        },
                        "n_assem_batch": "1",
                        "n_assem_core": "3",
                        "power_cap": "1000",
                        "refuel_time": "1"
                    }
                },
                "name": "reactor"
            }],
            "recipe": [{
                "basis":
                "mass",
                "name":
                "fresh_uox",
                "nuclide": [{
                    "comp": "0.711",
                    "id": "U235"
                }, {
                    "comp": "99.289",
                    "id": "U238"
                }]
            }, {
                "basis":
                "mass",
                "name":
                "spent_uox",
                "nuclide": [{
                    "comp": "50",
                    "id": "Kr85"
                }, {
                    "comp": "50",
                    "id": "Cs137"
                }]
            }],
            "region": {
                "config": {
                    "NullRegion": "\n      "
                },
                "institution": {
                    "config": {
                        "TimeSeriesInst": {
                            "calc_method": calc_method,
                            "commodities": {
                                "val": [
                                    "POWER_reactor_1000",
                                    "freshfuel_source_3000"
                                ]
                            },
                            "demand_eq": "1000",
                            "demand_std_dev": "0.0",
                            "record": "1",
                            "steps": "1"
                        }
                    },
                    "name": "source_inst"
                },
                "name": "SingleRegion"
            }
        }
    }

    name = "test_cont_" + calc_method
    input_file = name + ".json"
    output_file = name + ".sqlite"
    with open(input_file, 'w') as f:
        json.dump(test_input, f)

    try:
        subprocess.check_output(['cyclus', '-o', output_file, input_file],
                                universal_newlines=True,
                                env=ENV)
    except subprocess.CalledProcessError as e:
        print(e.output)
    cur = functions.get_cursor(output_file)
    query = 'SELECT COUNT(*) from agententry WHERE Prototype = "_"'

    for prototype in ['reactor', 'source']:
        row_count = cur.execute(query.replace('_', prototype)).fetchone()[0]
        assert (row_count >= 1)