Example #1
0
def testAnalytCylDifn(testDir, dirDict):
    """ Analytical test for diffusion in a cylinder """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrode = osp.join(testDir, "params_c.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "profileType", "CV")
    P_s.set("Sim Params", "Vset", "0.10")
    P_s.set("Sim Params", "tend", "1e+6")
    P_s.set("Sim Params", "tsteps", "1800")
    P_s.set("Sim Params", "relTol", "1e-7")
    P_s.set("Sim Params", "tramp", "1e-6")
    P_s.set("Particles", "mean_c", "100e-9")
    P_s.set("Particles", "mean_c", "100e-9")
    P_s.set("Particles", "cs0_c", "0.5")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrode)
    P.set("Particles", "type", "diffn")
    P.set("Particles", "discretization", "3e-10")
    P.set("Particles", "shape", "cylinder")
    P.set("Material", "muRfunc", "testIS_ss")
    P.set("Material", "D", "1e-20")
    P.set("Reactions", "rxnType", "BV_raw")
    P.set("Reactions", "k0", "1e+1")
    IO.write_config_file(P, ptrode)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
Example #2
0
def test017(testDir, dirDict, pflag):
    """ test CV continuation """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrode = osp.join(testDir, "params_c.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "profileType", "CV")
    P_s.set("Sim Params", "Vset", "3.45")
    P_s.set("Sim Params", "tend", "3e3")
    P_s.set("Sim Params", "Nvol_c", "3")
    P_s.set("Sim Params", "Npart_c", "3")
    test008dir = str(osp.join(testDir, "..", "test008", "sim_output"))
    P_s.set("Sim Params", "prevDir", test008dir)
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrode)
    P.set("Particles", "type", "homog_sdn")
    P.set("Material", "muRfunc", "LiFePO4")
    IO.write_config_file(P, ptrode)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        elytePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
        cmpr.bulkpf(testDir, dirDict, "c")
Example #3
0
def test011(testDir, dirDict, pflag):
    """ Graphite-2param CHR sphere """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrode = osp.join(testDir, "params_c.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "Crate", "1e-2")
    P_s.set("Sim Params", "relTol", "1e-7")
    P_s.set("Sim Params", "absTol", "1e-7")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrode)
    P.set("Particles", "type", "CHR2")
    P.set("Particles", "discretization", "2e-9")
    P.set("Particles", "shape", "sphere")
    P.set("Material", "muRfunc", "LiC6")
    P.set("Material", "Dfunc", "lattice")
    P.set("Material", "B", "0.1e9")
    P.set("Material", "kappa", "2.5e-10")
    IO.write_config_file(P, ptrode)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
Example #4
0
def test015(testDir, dirDict, pflag):
    """ testRS homog with CVsegments, bulkCond, partCond """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrode = osp.join(testDir, "params_c.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "profileType", "CVsegments")
    P_s.set("Sim Params", "Npart_c", "3")
    P_s.set("Sim Params", "Nvol_c", "3")
    P_s.set("Sim Params", "segments",
            "[(-0.3, 25), (0., 10), (0.3, 30)]")
    P_s.set("Sim Params", "tramp", "1e+0")
    P_s.set("Sim Params", "absTol", "1e-5")
    P_s.set("Conductivity", "simBulkCond_c", "true")
    P_s.set("Conductivity", "sigma_s_c", "1e-2")
    P_s.set("Conductivity", "simPartCond_c", "true")
    P_s.set("Conductivity", "G_mean_c", "1e-14")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrode)
    P.set("Particles", "type", "homog")
    P.set("Material", "muRfunc", "testRS")
    P.set("Reactions", "rxnType", "BV_raw")
    IO.write_config_file(P, ptrode)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        elytePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
        cmpr.bulkpf(testDir, dirDict, "c")
Example #5
0
def test001(testDir, dirDict, pflag):
    """ LFP ACR C3 """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrode = osp.join(testDir, "params_c.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "Crate", "1e-2")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrode)
    P.set("Particles", "type", "ACR")
    P.set("Material", "muRfunc", "LiFePO4")
    IO.write_config_file(P, ptrode)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
Example #6
0
def test019(testDir, dirDict, pflag):
    """ SM electrolyte with LFP homog, sep + cathode, significant elyte polarization """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrode = osp.join(testDir, "params_c.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "Nvol_c", "3")
    P_s.set("Sim Params", "Nvol_s", "3")
    P_s.set("Geometry", "L_c", "120e-6")
    P_s.set("Geometry", "L_s", "90e-6")
    P_s.set("Electrolyte", "elyteModelType", "SM")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrode)
    P.set("Particles", "type", "homog")
    P.set("Material", "muRfunc", "LiFePO4")
    IO.write_config_file(P, ptrode)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        elytePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
Example #7
0
def test014(testDir, dirDict, pflag):
    """ LFP homog with CCsegments, MHC, Rser """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrode = osp.join(testDir, "params_c.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "profileType", "CCsegments")
    P_s.set("Sim Params", "segments",
            "[(1., 25), (-2., 10), (0., 30)]")
    P_s.set("Sim Params", "tramp", "1e+0")
    P_s.set("Sim Params", "Rser", "1e-3")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrode)
    P.set("Particles", "type", "homog")
    P.set("Material", "muRfunc", "LiFePO4")
    P.set("Reactions", "rxnType", "MHC")
    IO.write_config_file(P, ptrode)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
Example #8
0
def test004(testDir, dirDict, pflag):
    """ LFP CHR sphere with noise  """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrode = osp.join(testDir, "params_c.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "Crate", "1e-2")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrode)
    P.set("Particles", "type", "CHR")
    P.set("Particles", "discretization", "2e-9")
    P.set("Particles", "shape", "sphere")
    P.set("Material", "muRfunc", "LiFePO4")
    P.set("Material", "noise", "true")
    P.set("Material", "numnoise", "100")
    P.set("Material", "Dfunc", "lattice")
    P.set("Material", "dgammadc", "-2e-30")
    IO.write_config_file(P, ptrode)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
Example #9
0
def test008(testDir, dirDict, pflag):
    """ LFP homog_sdn """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrode = osp.join(testDir, "params_c.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "Crate", "1e-2")
    P_s.set("Sim Params", "Nvol_c", "3")
    P_s.set("Sim Params", "Npart_c", "3")
    P_s.set("Particles", "stddev_c", "25e-9")
    P_s.set("Sim Params", "capFrac", "0.6")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrode)
    P.set("Particles", "type", "homog_sdn")
    P.set("Material", "muRfunc", "LiFePO4")
    IO.write_config_file(P, ptrode)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        elytePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
        cmpr.bulkpf(testDir, dirDict, "c")
Example #10
0
def test013(testDir, dirDict, pflag):
    """ Solid solution, diffn cylinder, homog, testIS_ss, LiMn2O4_ss2
    Marcus, BV_raw
    cathode + separator + anode
    """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_a.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrodec = osp.join(testDir, "params_c.cfg")
    ptrodea = osp.join(testDir, "params_a.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "profileType", "CV")
    P_s.set("Sim Params", "Vset", "3.8")
    P_s.set("Sim Params", "tsteps", "25")
    P_s.set("Sim Params", "Nvol_c", "2")
    P_s.set("Sim Params", "Nvol_s", "2")
    P_s.set("Sim Params", "Nvol_a", "2")
    P_s.set("Particles", "cs0_c", "0.2")
    P_s.set("Particles", "cs0_a", "0.95")
    P_s.set("Electrolyte", "elyteModelType", "dilute")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrodec)
    P.set("Particles", "type", "homog")
    P.set("Particles", "shape", "sphere")
    P.set("Material", "muRfunc", "LiMn2O4_ss2")
    P.set("Reactions", "rxnType", "Marcus")
    IO.write_config_file(P, ptrodec)
    P = IO.get_config(ptrodea)
    P.set("Particles", "discretization", "2.5e-9")
    P.set("Particles", "shape", "cylinder")
    P.set("Material", "muRfunc", "testIS_ss")
    P.set("Reactions", "rxnType", "BV_raw")
    IO.write_config_file(P, ptrodea)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        elytePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
        cmpr.bulkpf(testDir, dirDict, "c")
        electrodePlots(testDir, dirDict, "a")
        cmpr.bulkpf(testDir, dirDict, "a")
Example #11
0
def test012(testDir, dirDict, pflag):
    """ Solid solution, diffn sphere, homog, LiC6_coke_ss2, LiMn2O4_ss2
    BV_mod01, BV_mod02
    cathode + anode
    """
    shutil.copy(osp.join(dirDict["baseConfig"], "params_system.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_c.cfg"), testDir)
    shutil.copy(osp.join(dirDict["baseConfig"], "params_a.cfg"), testDir)
    psys = osp.join(testDir, "params_system.cfg")
    ptrodec = osp.join(testDir, "params_c.cfg")
    ptrodea = osp.join(testDir, "params_a.cfg")
    P_s = IO.get_config(psys)
    P_s.set("Sim Params", "Crate", "1e-2")
    P_s.set("Sim Params", "capFrac", "0.67")
    P_s.set("Sim Params", "tsteps", "25")
    P_s.set("Sim Params", "Nvol_c", "2")
    P_s.set("Sim Params", "Nvol_a", "2")
    P_s.set("Sim Params", "Vmin", "2e0")
    P_s.set("Particles", "cs0_c", "0.2")
    P_s.set("Particles", "cs0_a", "0.495")
    P_s.set("Electrolyte", "elyteModelType", "SM")
    IO.write_config_file(P_s, psys)
    P = IO.get_config(ptrodec)
    P.set("Particles", "type", "homog")
    P.set("Particles", "shape", "cylinder")
    P.set("Material", "muRfunc", "LiMn2O4_ss2")
    P.set("Reactions", "rxnType", "BV_mod01")
    IO.write_config_file(P, ptrodec)
    P = IO.get_config(ptrodea)
    P.set("Particles", "discretization", "2.5e-9")
    P.set("Particles", "shape", "sphere")
    P.set("Material", "muRfunc", "LiC6_coke_ss2")
    P.set("Reactions", "rxnType", "BV_mod02")
    IO.write_config_file(P, ptrodea)
    main.main(psys, keepArchive=False)
    shutil.move(dirDict["simOut"], testDir)
    if pflag:
        corePlots(testDir, dirDict)
        elytePlots(testDir, dirDict)
        electrodePlots(testDir, dirDict, "c")
        cmpr.bulkpf(testDir, dirDict, "c")
        electrodePlots(testDir, dirDict, "a")
        cmpr.bulkpf(testDir, dirDict, "a")
Example #12
0
def main(paramfile, keepArchive=True):
    timeStart = time.time()
    # Get the parameters dictionary (and the config instance) from the
    # parameter file
    P_s, P_e = IO.get_configs(paramfile)
    dD_s, ndD_s, dD_e, ndD_e = IO.get_dicts_from_configs(P_s, P_e)

    # Directories we'll store output in.
    outdir_name = time.strftime("%Y%m%d_%H%M%S", time.localtime())
    outdir_path = os.path.join(os.getcwd(), "history")
    outdir = os.path.join(outdir_path, outdir_name)
    # Make sure there's a place to store the output
    try:
        os.makedirs(outdir)
    except OSError as exception:
        if exception.errno == errno.EEXIST:
            print("The output directory, {dirname}, exists. Aborting.".format(dirname=outdir))
            sys.exit()
        else:
            raise
    paramFileName = "input_params_system.cfg"
    paramFile = os.path.join(outdir, paramFileName)
    IO.write_config_file(P_s, filename=paramFile)
    dictFile = os.path.join(outdir, "input_dict_system")
    IO.write_dicts(dD_s, ndD_s, filenamebase=dictFile)
    for trode in ndD_s["trodes"]:
        paramFileName = "input_params_{t}.cfg".format(t=trode)
        paramFile = os.path.join(outdir, paramFileName)
        IO.write_config_file(P_e[trode], filename=paramFile)
        dictFile = os.path.join(outdir, "input_dict_{t}".format(t=trode))
        IO.write_dicts(dD_e[trode], ndD_e[trode], filenamebase=dictFile)

    # Store info about this script
    # mpet.py script directory
    localDir = os.path.dirname(os.path.abspath(__file__))
    commit_hash = ""
    try:
        # Git option, if it works -- commit info and current diff
        branch_name, commit_hash, commit_diff = utils.get_git_info(localDir, shell=False)
    except FileNotFoundError:
        try:
            branch_name, commit_hash, commit_diff = utils.get_git_info(localDir, shell=True)
        except subp.CalledProcessError:
            pass
    except subp.CalledProcessError:
        pass

    fo=open(os.path.join(outdir, 'run_info.txt'), 'w')
    
    #Print mpet version
    print("mpet version:", file=fo)
    print(mpet.__version__+"\n", file=fo)

    #Print git commit info if it exists
    if commit_hash != "":
        # Store commit info to file, as well as how to patch if
        # there's a diff
        print("branch name:", file=fo)
        print(branch_name, file=fo)
        print("commit hash:", file=fo)
        print(commit_hash, file=fo)
        print("to run, from the root repo directory, copy relevant files there,", file=fo)
        print("edit input_params_system.cfg to point to correct material", file=fo)
        print("params files, and:", file=fo)
        print("$ git checkout [commit hash]", file=fo)
        print("$ patch -p1 < commit.diff:", file=fo)
        print("$ python[3] mpetrun.py input_params_system.cfg", file=fo)
        with open(os.path.join(outdir, 'commit.diff'), 'w') as fo:
            print(commit_diff, file=fo)
    else:
        # At least keep a copy of the python files in this directory
        # with the output
        snapshotDir = os.path.join(outdir, "simSnapshot")
        os.makedirs(snapshotDir)
        pyFiles = glob.glob(os.path.join(localDir, "*.py"))
        for pyFile in pyFiles:
            shutil.copy(pyFile, snapshotDir)
    
    fo.close()
    
    # External functions are not supported by the Compute Stack approach.
    # Activate the Evaluation Tree approach if noise, logPad, CCsegments,
    # or CVsegments are used
    cfg = dae.daeGetConfig()
    noise=ndD_e['c']['noise']
    logPad=ndD_e['c']['logPad']
    segments = ndD_s["profileType"] in ["CCsegments","CVsegments"]
    if (noise or logPad or (segments and ndD_s["tramp"]>0)) and cfg.has_key('daetools.core.equations.evaluationMode'):
        cfg.SetString('daetools.core.equations.evaluationMode', 'evaluationTree_OpenMP')
    with open(os.path.join(outdir, "daetools_config_options.txt"), 'w') as fo:
        print(cfg, file=fo)

    #Disable printStats
    cfg.SetString('daetools.activity.printStats','false')

    # Carry out the simulation
    run_simulation(ndD_s, ndD_e, dD_s["td"], outdir)

    # Final output for user
    print("\n\nUsed parameter file ""{fname}""\n\n".format(fname=paramfile))
    timeEnd = time.time()
    tTot = timeEnd - timeStart
    print("Total time:", tTot, "s")
    try:
        with open(os.path.join(outdir, 'run_info.txt'), 'a') as fo:
            print("\nTotal run time:", tTot, "s", file=fo)
    except Exception:
        pass

    # Copy simulation output to current directory
    tmpDir_name = "sim_output"
    tmpDir = os.path.join(os.getcwd(), tmpDir_name)
    try:
        os.makedirs(tmpDir)
    except OSError as exception:
        if exception.errno != errno.EEXIST:
            raise
    for fname in os.listdir(outdir):
        tocopy = os.path.join(outdir, fname)
        if os.path.isfile(tocopy):
            shutil.copy(tocopy, tmpDir)

    if not keepArchive:
        shutil.rmtree(outdir)