Example #1
0
def run_array(outdir, jobs, NS, cp, time, nn, np, descr):
    job = path.join(outdir, 'array' + descr + '.job')
    with open(job, 'w') as f:
        f.write('''#!/bin/bash
# mem directive is per node.
#SBATCH --nodes ''' + str(nn) + '''
#SBATCH --cpus-per-task 1
#SBATCH --ntasks-per-node ''' + str(np) + '''
#SBATCH --mem ''' + str(cp['mem'] * np / cp['np']) + '''
#SBATCH --time ''' + time + '''
#SBATCH --workdir ''' + outdir + '''
#SBATCH --mail-type=END
#SBATCH --mail-type=FAIL
#SBATCH [email protected]
#SBATCH --share
''')
        if NS > 0:
            f.write('#SBATCH --array=0-' + str(len(jobs) - 1) + '%' + str(NS) +
                    '\n')
        else:
            f.write('#SBATCH --array=0-' + str(len(jobs) - 1) + '\n')
        f.write('case "$SLURM_ARRAY_TASK_ID" in\n')
        for i, j in enumerate(jobs):
            wd = path.dirname(j)
            f.write('\t' + str(i) + ')\n')
            f.write('\t\tcd ' + wd + '\n')
            f.write('\t\tchmod +x ' + j + '\n')
            f.write('\t\t' + j + '\n')
            f.write('\t\t;;\n')
        f.write('\t*) ;;\n')
        f.write('esac\n')
    print '\n\nSubmitting array job with', len(jobs), 'jobs...'
    utility.run_cmd_screen(['sbatch', job])
Example #2
0
def run_abq(inp, outdir, np, descr):
    wd = path.join(outdir, path.splitext(path.basename(inp))[0])
    if descr != "": wd += '-' + descr
    print '\n'
    print '--------------------------------------------------------------------------------'
    print '-- RUNNING ABAQUS:', inp, descr, '(' + str(np) + ' processors)'
    print '--             IN:', wd
    print '--------------------------------------------------------------------------------'
    if path.exists(wd): shutil.rmtree(wd)
    if not inp.endswith('.inp'):
        utility.print_error('Input file must be a .inp Abaqus run file.',
                            False)
        return 0
    # Prepare the directories.
    os.makedirs(wd)
    inpNEW = path.join(wd, 'job.inp')
    if not utility.safe_hardlink(inp, inpNEW):
        shutil.rmtree(wd)
        return 0
    create_env(np, wd)
    # Run the simulation.
    rootdir = os.getcwd()
    os.chdir(wd)
    tstart = time.time()
    cmd = [ABAQUS, 'job=job', 'input=job.inp', 'interactive']
    try:
        utility.run_cmd_screen(cmd)
    except Exception:
        utility.print_error(sys.exc_info()[0], False)
        return 0
    finally:
        print 'TIME ELAPSED: ', utility.time_elapsed(tstart)
        os.chdir(rootdir)
    return 1
Example #3
0
def run_post(inp,outdir,descr):
    wd = path.join(outdir,path.splitext(path.basename(inp))[0])
    if descr!="": wd+='-'+descr
    print '\n'
    print '--------------------------------------------------------------------------------'
    print '-- RUNNING POSTPROCESSOR:',path.join(wd,'job.odb')
    print '--------------------------------------------------------------------------------'
    # Run the extraction.
    rootdir = os.getcwd()
    try:
        os.chdir(wd)
    except Exception:
        utility.print_error(sys.exc_info()[0],False)
        return 0
    tstart = time.time()
    script = utility.find_file('python/abq_extract_data.py')
    cmd=[ABAQUS,'cae','noGUI='+script,'--','job.odb','data.rpt']
    try:
        utility.run_cmd_screen(cmd)
        with open('data.tmp','w') as of, open('data.rpt','r') as f:
            for line in f:
                line = line.rstrip()    # Remove newline/carriage-return.
                if line.find('NoValue') < 0: of.write(line+'\n')
        shutil.move('data.tmp','data.rpt')
    except Exception:
        utility.print_error(sys.exc_info()[0],False)
        print 'TIME ELAPSED: ',utility.time_elapsed(tstart)
        os.chdir(rootdir)
        return 0
    try:
        import create_result_plots, numpy
        from matplotlib import pyplot
        pyplot.rc('mathtext',default='regular') # Don't use italics for mathmode.
        fig,ax = pyplot.subplots()
        create_result_plots.plot_fem_data(ax,'data.rpt')
        lgd = ax.legend(loc='best',frameon=False,framealpha=0)
        pyplot.savefig('plot.png',bbox_extra_artists=(lgd,), bbox_inches='tight')
        pyplot.close()
        if path.exists('data-energy.rpt'):
            fig,ax = pyplot.subplots()
            create_result_plots.plot_fem_energy(ax,'data-energy.rpt')
            lgd = ax.legend(loc='best',frameon=False,framealpha=0)
            pyplot.savefig('plot-energy.png',bbox_extra_artists=(lgd,), bbox_inches='tight')
            pyplot.close()
        if path.exists('data-strain.csv'):
            fig,ax = pyplot.subplots()
            data = numpy.loadtxt('data-strain.csv',delimiter=',')
            ax.plot(data[:,0],data[:,1],'o-',label='Nominal Strain')
            ax.set_xlabel('Time (meaningless units)')
            ax.set_ylabel('Nominal Strain')
            ax.grid()
            pyplot.savefig('plot-strain.png', bbox_inches='tight')
            pyplot.close()
    except Exception:
        utility.print_error('Failed to create result plots.',False)
    print 'TIME ELAPSED: ',utility.time_elapsed(tstart)
    os.chdir(rootdir)
    return 1
Example #4
0
def run_ACT(act,test,dist_to_force,geomcmd,i):
    PROCS = 8
    try: U.run_cmd_screen(geomcmd)                              # Create the test.
    except Exception:
        U.print_error('Failed to create geometry! Non-physical dimensions?',False)
        return dict()
    results = dict()
    RT.run_abq('test_geom-'+act+test+'.inp','.',PROCS,str(i))   # Run the test.
    if RT.run_post('test_geom-'+act+test+'.inp','.',str(i)):    # Postprocess the test.
        try:
            data = np.loadtxt(path.join('test_geom-'+act+test+'-'+str(i),'data.rpt'),skiprows=4)
        except Exception:
            U.print_error('Failed to load data.rpt file, skipping dataset.',False)
            return dict()
        if len(data.shape)==1: return dict()
        if act=='lin' and test=='U':
            data = data[:,[1,4]]              # Pressure, Z-displacement.
            data[:,1] = -1.0*data[:,1]
        elif act=='bnd' and test=='U':
            L = data[0,-1] - data[0,-2]       # Initial length of the actuator.
            angles = np.degrees(np.arctan(-data[:,3]/(L-data[:,4])))
            angles[angels<0.0] = angles[angles<0.0] + 180
            data = data[:,[1,2]]
            data[:,1] = angles
        elif act=='lin' and test=='F': data= data[:,[1,4]]  # Pressure, Z-Force.
        elif act=='bnd' and test=='F':
            # Need to calculate the force perpendicular to the plate.
            alpha = np.radians(dist_to_force)
            beta = np.radians(90 - dist_to_force)
            f_normal = np.abs(data[:,3]*np.cos(alpha)) + np.abs(data[:,4]*np.cos(beta))
            data = data[:,[1,2]]
            data[:,1] = f_normal     # Pressure, Normal-Force.
        results[act+test] = data
        try:
            # strains are time (same indices as pressure), nominal strain.
            strains = np.loadtxt(path.join('test_geom-'+act+test+'-'+str(i),'data-strain.csv'),delimiter=',')
            strains[:,0] = data[:,0]
            results[act+test+'--strain'] = strains
        except: pass
    return results
Example #5
0
    # Bubble actuators.
    #------------------------------------------------------------------------------------
    if args.cmd == 'bubble':
        acg_args = [
            cae_file, args.test, args.mesh_size, args.press, args.time,
            str(args.diameter),
            str(args.thickness),
            str(args.inlet), mat_file
        ]
        cmd = [ABAQUS, 'cae', 'noGUI=' + acg_file, '--'] + acg_args

    #------------------------------------------------------------------------------------
    # Attempt to run Abaqus to create the geometry.
    #------------------------------------------------------------------------------------
    try:
        utility.run_cmd_screen(cmd)
    except Exception:
        utility.print_error(sys.exc_info()[0], False)
        print 'Check above to see if Abaqus printed an error. Otherwise, check the Abaqus log files.'
        print 'Tried to run command:'
        print ' '.join(cmd)
        print 'In directory:', caedir
        print
    else:
        # Cleanup.
        os.remove('abaqus.rpy')
        os.remove(path.splitext(cae_file)[0] + '.jnl')
        # Read .inp file to determine number of elements and nodes.
        with open(inp_file + '.tmp', 'w') as of, open(inp_file, 'r') as f:
            countN = False
            countE = False