Exemple #1
0
def main():
    import exodus as exo
    import numpy as np
    import os
    import pymef90
    options = parse()
    
    if  os.path.exists(options.outputfile):
        if options.force:
            os.remove(options.outputfile)
        else:
            if pymef90.confirm("ExodusII file {0} already exists. Overwrite?".format(options.outputfile)):
                os.remove(options.outputfile)
            else:
                print ('\n\t{0} was NOT generated.\n'.format(options.outputfile))
                return -1
    exoin  = exo.exodus(options.inputfile,mode='r',array_type='numpy')
    exoout = exoin.copy(options.outputfile)
    exoin.close()
    exoformat(exoout)
    
    T = np.linspace(options.time_min,options.time_max,options.time_numstep)
    x0 = np.linspace(options.initialPos[0],options.finalPos[0],options.time_numstep)
    y0 = np.linspace(options.initialPos[1],options.finalPos[2],options.time_numstep)
    z0 = np.linspace(options.initialPos[2],options.finalPos[2],options.time_numstep)
    for step in range(options.time_numstep):
        print("Processing time step {0} (t={1:.2e}, x0=[{2},{3},{4})".format(step,T[step],x0[step],y0[step],z0[step]))
        exoout.put_time(step+1,T[step])
        for cs in options.cs:
            theta = beamProfile(exoout,options.Wabs,options.r0,[x0[step],y0[step],z0[step]],cs)
            exoout.put_element_variable_values(cs,"Heat_Flux",step+1,theta)
    exoout.close()
Exemple #2
0
def main():
    import exodus as exo
    import numpy as np
    import os
    import pymef90
    options = parse()
    
    if  os.path.exists(options.outputfile):
        if options.force:
            os.remove(options.outputfile)
        else:
            if pymef90.confirm("ExodusII file {0} already exists. Overwrite?".format(options.outputfile)):
                os.remove(options.outputfile)
            else:
                print ('\n\t{0} was NOT generated.\n'.format(options.outputfile))
                return -1
    exoin  = exo.exodus(options.inputfile,mode='r')
    exoout = exoin.copy(options.outputfile)
    exoin.close()
    exoformat(exoout)
    
    T = np.linspace(options.time_min,options.time_max,options.time_numstep)
    for step in range(options.time_numstep):
        exoout.put_time(step+1,T[step])
    for cs in options.cs:
        theta = beamProfile(exoout,options.Wabs,options.r0,options.initialPos,cs)
        step = 0
        for step in range(options.time_numstep):
            exoout.put_element_variable_values(cs,"Heat_Flux",step+1,theta)
            step += 1
    exoout.close()
Exemple #3
0
def main():
    import numpy as np
    import os
    import pymef90
    options = parse()

    if os.path.exists(options.outputfile):
        if options.force:
            os.remove(options.outputfile)
        else:
            if pymef90.confirm(
                    "ExodusII file {0} already exists. Overwrite?".format(
                        options.outputfile)):
                os.remove(options.outputfile)
            else:
                print('\n\t{0} was NOT generated.\n'.format(
                    options.outputfile))
                return -1
    exoin = exo.exodus(options.inputfile, mode='r')
    exoout = exoin.copy(options.outputfile)
    exoout.close()
    exoout = exo.exodus(options.outputfile, mode='a', array_type='numpy')
    ### Adding a QA record, needed until visit fixes its exodus reader
    import datetime
    import os.path
    import sys
    QA_rec_len = 32
    QA = [
        os.path.basename(sys.argv[0]),
        os.path.basename(__file__),
        datetime.date.today().strftime('%Y%m%d'),
        datetime.datetime.now().strftime("%H:%M:%S")
    ]
    exoout.put_qa_records([
        [q[0:31] for q in QA],
    ])

    exoformat(exoout, options.plasticity)

    dim = exoout.num_dimensions()
    step = 0
    for t in np.linspace(options.time_min, options.time_max,
                         options.time_numstep):
        print("writing step {0}, t = {1:0.4f}".format(step + 1, t))
        exoout.put_time(step + 1, t)
        U = surfingBC(exoout, t, options.initialpos, options.cs, options.vs,
                      options.E, options.nu, options.ampl)
        X, Y, Z = exoout.get_coords()
        exoout.put_node_variable_values("Displacement_X", step + 1, U[0, :])
        exoout.put_node_variable_values("Displacement_Y", step + 1, U[1, :])
        if dim == 3:
            exoout.put_node_variable_values("Displacement_Z", step + 1,
                                            U[2, :])
        step += 1
    exoout.close()
Exemple #4
0
def main():
    import numpy as np
    import os
    import pymef90
    options = parse()

    if os.path.exists(options.outputfile):
        if options.force:
            os.remove(options.outputfile)
        else:
            if pymef90.confirm(
                    "ExodusII file {0} already exists. Overwrite?".format(
                        options.outputfile)):
                os.remove(options.outputfile)
            else:
                print('\n\t{0} was NOT generated.\n'.format(
                    options.outputfile))
                return -1
    exoin = exo.exodus(options.inputfile, mode='r')
    exoout = exoin.copy(options.outputfile)
    exoout.close()
    exoout = exo.exodus(options.outputfile, mode='a', array_type='numpy')
    ### Adding a QA record, needed until visit fixes its exodus reader
    import datetime
    import os.path
    import sys
    QA_rec_len = 32
    QA = [
        os.path.basename(sys.argv[0]),
        os.path.basename(__file__),
        datetime.date.today().strftime('%Y%m%d'),
        datetime.datetime.now().strftime("%H:%M:%S")
    ]
    exoout.put_qa_records([
        [q[0:31] for q in QA],
    ])

    exoformat(exoout)

    if not exoout.num_dimensions() == 3:
        print("This program only makes sense in 3D")
        return (-1)

    T = np.linspace(options.time_min, options.time_max, options.time_numstep)
    for step in range(options.time_numstep):
        t = T[step]
        print "writing step", step + 1, t
        exoout.put_time(step + 1, t)
        U = displacementBC(exoout, t, options)
        exoout.put_node_variable_values("Displacement_X", step + 1, U[0, :])
        exoout.put_node_variable_values("Displacement_Y", step + 1, U[1, :])
        exoout.put_node_variable_values("Displacement_Z", step + 1, U[1, :])
    exoout.close()
    return (0)
Exemple #5
0
def main():
    import exodus as exo
    import numpy as np
    import os
    import pymef90
    options = parse()

    if os.path.exists(options.outputfile):
        if options.force:
            os.remove(options.outputfile)
        else:
            if pymef90.confirm(
                    "ExodusII file {0} already exists. Overwrite?".format(
                        options.outputfile)):
                os.remove(options.outputfile)
            else:
                print('\n\t{0} was NOT generated.\n'.format(
                    options.outputfile))
                return -1
    exoin = exo.exodus(options.inputfile, mode='r')
    exoout = exoin.copy(options.outputfile)
    exoout.close()
    exoout = exo.exodus(options.outputfile, mode='a', array_type='numpy')
    ### Adding a QA record, needed until visit fixes its exodus reader
    import datetime
    import os.path
    import sys
    QA_rec_len = 32
    QA = [
        os.path.basename(sys.argv[0]),
        os.path.basename(__file__),
        datetime.date.today().strftime('%Y%m%d'),
        datetime.datetime.now().strftime("%H:%M:%S")
    ]
    exoout.put_qa_records([
        [q[0:31] for q in QA],
    ])

    exoformat(exoout)

    T = np.linspace(options.time_min, options.time_max, options.time_numstep)
    x0 = np.linspace(options.initialPos[0], options.finalPos[0],
                     options.time_numstep)
    y0 = np.linspace(options.initialPos[1], options.finalPos[2],
                     options.time_numstep)
    z0 = np.linspace(options.initialPos[2], options.finalPos[2],
                     options.time_numstep)

    cellCenters = {}
    for cs in options.cs:
        print("Computing cell center coordinates for set {0}".format(cs))
        cellCenters[cs] = cellCenter(exoout, cs)
    for step in range(options.time_numstep):
        print(
            "Processing time step {0}  (t={4:.2e}, x0=[{1:.2e},{2:.2e},{3:.2e}])"
            .format(step, x0[step], y0[step], z0[step], T[step]))
        exoout.put_time(step + 1, T[step])
        for cs in options.cs:
            theta = beamProfile(exoout, options.Wabs, options.r0,
                                [x0[step], y0[step], z0[step]], cs,
                                cellCenters[cs])
            exoout.put_element_variable_values(cs, "Heat_Flux", step + 1,
                                               theta)
    exoout.close()
Exemple #6
0
def main():
    import numpy as np
    import os
    import pymef90
    import sys
    if sys.version_info.major == 3:
        import exodus3 as exo
    else:
        import exodus2 as exo

    options = parse()

    if options.skip == 0:
        if os.path.exists(options.outputfile):
            if options.force:
                os.remove(options.outputfile)
            else:
                if pymef90.confirm(
                        "ExodusII file {0} already exists. Overwrite?".format(
                            options.outputfile)):
                    os.remove(options.outputfile)
                else:
                    print('\n\t{0} was NOT generated.\n'.format(
                        options.outputfile))
                    return -1
        exoin = exo.exodus(options.inputfile, mode='r')
        exoout = exoin.copy(options.outputfile)
        exoformat(exoout)
        exoout.close()
    exoout = exo.exodus(options.outputfile, mode='a', array_type='numpy')
    ### Adding a QA record, needed until visit fixes its exodus reader
    import datetime
    import os.path
    import sys
    QA_rec_len = 32
    QA = [
        os.path.basename(sys.argv[0]),
        os.path.basename(__file__),
        datetime.date.today().strftime('%Y%m%d'),
        datetime.datetime.now().strftime("%H:%M:%S")
    ]
    exoout.put_qa_records([
        [q[0:31] for q in QA],
    ])

    cellCenters = {}
    for cs in options.cs:
        print("Computing cell center coordinates for set {0}".format(cs))
        cellCenters[cs] = cellCenter(exoout, cs)

    print("Using a space rescaling factor of {0:.4e} in the file".format(
        options.x0))
    print("Using a time rescaling factor of {0:.4e} in the file".format(
        options.t0))
    beamPath = np.loadtxt(options.pathfile)
    beamLoc = open("beam.txt", "w")
    beamLoc.write("# step   t   x   y   I   t~   x~   y~   I~\n")

    absCoef = 1. - np.exp(-options.alpha * options.d)
    x0 = options.x0
    t0 = options.t0

    substep = 0
    for step in range(beamPath.shape[0] - 1):
        print(
            "Processing path line {0} (t={1:.4e}-{2:.4e},  x={3:.4e}-{4:.4e},  y={5:.4e}-{6:.4e},  W={7:.4e}-{8:.4e})"
            .format(step, beamPath[step][0], beamPath[step + 1][0],
                    beamPath[step][1], beamPath[step + 1][1],
                    beamPath[step][2], beamPath[step + 1][2],
                    beamPath[step][3], beamPath[step + 1][3]))
        print(
            "                       (t~={1:.4e}-{2:.4e}, x~={3:.4e}-{4:.4e}, y~={5:.4e}-{6:.4e}, W~={7:.4e}-{8:.4e})"
            .format(step, beamPath[step][0] / t0, beamPath[step + 1][0] / t0,
                    beamPath[step][1], beamPath[step + 1][1] / x0,
                    beamPath[step][2] / x0, beamPath[step + 1][2] / x0,
                    beamPath[step][3] / x0, beamPath[step + 1][3] * absCoef))
        beamLoc.write(
            "# path line {0} (t={1:.4e}-{2:.4e},  x={3:.4e}-{4:.4e},  y={5:.4e}-{6:.4e},  W={7:.4e}-{8:.4e})\n"
            .format(step, beamPath[step][0], beamPath[step + 1][0],
                    beamPath[step][1], beamPath[step + 1][1],
                    beamPath[step][2], beamPath[step + 1][2],
                    beamPath[step][3], beamPath[step + 1][3]))
        beamLoc.write(
            "#             (t~={1:.4e}-{2:.4e}, x~={3:.4e}-{4:.4e}, y~={5:.4e}-{6:.4e}, W~={7:.4e}-{8:.4e})\n"
            .format(step, beamPath[step][0] / t0, beamPath[step + 1][0] / t0,
                    beamPath[step][1], beamPath[step + 1][1] / x0,
                    beamPath[step][2] / x0, beamPath[step + 1][2] / x0,
                    beamPath[step][3] / x0, beamPath[step + 1][3] * absCoef))

        nstep = int(
            (beamPath[step + 1][0] - beamPath[step][0]) / options.dt) + 1
        if step == 0:
            skip = 0
        else:
            skip = 1
        T = np.linspace(beamPath[step][0], beamPath[step + 1][0], nstep)[skip:]
        X = np.linspace(beamPath[step][1], beamPath[step + 1][1], nstep)[skip:]
        Y = np.linspace(beamPath[step][2], beamPath[step + 1][2], nstep)[skip:]
        W = np.linspace(beamPath[step][3], beamPath[step + 1][3], nstep)[skip:]
        for t, x, y, w in zip(T, X, Y, W):
            substep += 1
            if substep > options.skip:
                print(
                    "   time step {4}: \t t~={0:.4e}, x~={1:.4e}, y~={2:.4e}, W~={3:.4e}"
                    .format(t / t0, x / x0, y / x0, w * absCoef, substep))
                print(
                    "                     \t t ={0:.4e}, x ={1:.4e}, y ={2:.4e}, W ={3:.4e}"
                    .format(t, x, y, w, substep))
                beamLoc.write(
                    "{0} {1:.4e} {2:.4e} {3:.4e} {4:.4e}    {5:.4e} {6:.4e} {7:.4e} {8:.4e}\n"
                    .format(substep, t, x, y, w, t / t0, x / x0, y / x0,
                            w * absCoef))
                exoout.put_time(substep, t / t0)
                for cs in options.cs:
                    theta = beamProfile(exoout, w * absCoef,
                                        options.r0 / options.x0,
                                        [x / x0, y / x0, 0], cs,
                                        cellCenters[cs])
                    exoout.put_element_variable_values(cs, "Heat_Flux",
                                                       substep, theta)
            else:
                print('skipping substep {0}'.format(substep))
    exoout.close()
    beamLoc.close()
Exemple #7
0
        datetime.date.today().strftime('%Y%m%d'),
        datetime.datetime.now().strftime("%H:%M:%S")
    ]
    eout.put_qa_records([
        [q[0:31] for q in QA],
    ])
    eout.close()
    e.close()


if __name__ == '__main__':
    if not (len(sys.argv) == 3):
        print "usage: {0} <input filename> <output filename>".format(
            sys.argv[0])
        sys.exit(-1)
    fin = sys.argv[-2]
    fout = sys.argv[-1]
    if not os.path.isfile(fin):
        print "usage: {0} <input filename> <output filename>".format(
            sys.argv[0])
        sys.exit(-1)
    if os.path.exists(fout):
        if pymef90.confirm(
                "ExodusII file {0} already exists. Overwrite?".format(fout)):
            os.remove(fout)
        else:
            print "bye!"
            sys.exit(-1)

    exo2exo(fin, fout)
Exemple #8
0
def main():
    import sys
    if sys.version_info.major == 3:
        import exodus3 as exo
    else:
        import exodus2 as exo
    import os
    options = parse()


    exoin  = exo.exodus(options.inputfile,mode='r',array_type='numpy')
    nodalFields = exoin.get_node_variable_names()
    zonalFields = exoin.get_element_variable_names()

    if options.deletevariables == []:
        print('nodal fields: {0}'.format(nodalFields))
        print('zonal fields: {0}'.format(zonalFields))

    keepNodalFields = nodalFields
    for deleteField in options.deletevariables:
        keepNodalFields = [field for field in keepNodalFields if not field.lower().startswith(deleteField.lower())]
    deleteNodalFields = [field for field in nodalFields if not field in keepNodalFields]

    keepZonalFields = zonalFields
    for deleteField in options.deletevariables:
        keepZonalFields = [field for field in keepZonalFields if not field.lower().startswith(deleteField.lower())]
    deleteZonalFields = [field for field in zonalFields if not field in keepZonalFields]

    originalTimes = exoin.get_times()
    if options.deleteafterstep:
        keepTimes = originalTimes[:min(options.deleteafterstep,len(originalTimes))]
    else:
        keepTimes = originalTimes


    if len(deleteNodalFields+deleteZonalFields) > 0 or not len(originalTimes) == len(keepTimes):
        print('\nDeleting the following fields:')
        for f in deleteNodalFields:
            print('\t{0} (nodal)'.format(f))
        for f in deleteZonalFields:
            print('\t{0} (zonal)'.format(f))
        if not len(originalTimes) == len(keepTimes):
            print('\nDeleting steps after {0}'.format(options.deleteafterstep))

        if options.outputfile == None or options.inputfile == options.outputfile:
            if not options.force:
                print('THIS WILL OVERWRITE INPUT FILE {0}'.format(options.inputfile))
                if not pymef90.confirm("Is this OK?"):
                    print('Exiting without writing')
                    sys.exit()
            outputfile = options.inputfile+'.tmp'
        else:
            if (os.path.exists(options.outputfile)):
                if not options.force:
                    print('THIS WILL OVERWRITE OUTPUT FILE {0}'.format(options.outputfile))
                    if not pymef90.confirm("Is this OK?"):
                        print('Exiting without writing')
                        sys.exit()
                if os.path.exists(options.outputfile):
                    os.remove(options.outputfile)
            outputfile = options.outputfile

        print('inputfile: {0}'.format(options.inputfile))
        print('outputfile: {0}'.format(outputfile))

        print("Copying geometry in {0}".format(outputfile))
        try:
            exoout = exo.copy_mesh(options.inputfile,outputfile, array_type='numpy')
        except:
            print('\n\nCopying the background mesh using exodus.copy_mesh failed, trying again using exodus.copy.')
            print('Note that the resulting file may not readable with paraview < 5.8.0 or visit\n\n')
            os.remove(options.outputfile)
            exoin  = exo.exodus(options.inputfile,mode='r')
            exoout = exoin.copy(outputfile)
            ### Adding a QA record, needed until visit fixes its exodus reader
            import datetime
            import os.path
            import sys
            QA_rec_len = 32
            QA = [os.path.basename(sys.argv[0]),os.path.basename(__file__),datetime.date.today().strftime('%Y%m%d'),datetime.datetime.now().strftime("%H:%M:%S")]
            exoout.put_qa_records([[ q[0:31] for q in QA],])

        print("formatting {0}".format(outputfile))
        exoout.set_global_variable_number(0)
        exoout.set_node_variable_number(len(keepNodalFields))
        for i in range(len(keepNodalFields)):
            exoout.put_node_variable_name(keepNodalFields[i],i+1)
        exoout.set_element_variable_number(len(keepZonalFields))
        for i in range(len(keepZonalFields)):
            exoout.put_element_variable_name(keepZonalFields[i],i+1)
        exoout.set_element_variable_truth_table([True] * exoout.numElemBlk.value * len(keepZonalFields))

        step = 1
        for t in keepTimes:
            print("processing time step {0}: t={1:.2e}".format(step,t))
            exoout.put_time(step,t)
            for f in keepNodalFields:
                exoout.put_node_variable_values(f,step,exoin.get_node_variable_values(f,step))
            for f in keepZonalFields:
                for cs in exoin.get_elem_blk_ids():
                    exoout.put_element_variable_values(cs,f,step,exoin.get_element_variable_values(cs,f,step))

            step += 1
        exoout.close()

        if options.outputfile == None:
            os.rename(outputfile,options.inputfile)
    else:
        print('Nothing to delete')
    return 0