123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- import os, cmath
- import numpy as np
- from scattnlay import fieldnlay
- from fieldplot import fieldplot
- if __name__ == '__main__':
- import argparse
- parser = argparse.ArgumentParser()
- parser.add_argument("dirnames", nargs='*', default='.', help="read all data from DIR(S)")
- parser.add_argument("-f", "--filename", dest="fname", nargs='?', default=None,
- help="name of 'n' file")
- parser.add_argument("-w", "--wavelength", dest="wl", default=3.75, type=float,
- help="wavelength of electromagnetic wave")
- parser.add_argument("-r", "--radius", dest="rad", default=None, type=float,
- help="radius of PEC sphere")
- parser.add_argument("-t", "--thickness", dest="tc", default=0.8, type=float,
- help="thickness of cloaking layer")
- parser.add_argument("-n", "--npoints", dest="npts", default=101, type=int,
- help="number of points for the grid")
- args = parser.parse_args()
- for dirname in args.dirnames:
- print "Calculating spectra for data file(s) in dir '%s'..." % (dirname)
- wl = args.wl
- if (args.rad is None):
- Rs = 0.75*wl
- else:
- Rs = args.rad
- tc = args.tc
- if (args.fname is None):
- files = [x for x in os.listdir('%s/' % (dirname)) if x.endswith('.dat')]
- files.sort()
- else:
- files = [args.fname]
- npts = args.npts
- if not os.path.exists('%s/flow-results/' % (dirname)):
- os.makedirs('%s/flow-results/' % (dirname))
- Rt = Rs + tc
- print "Wl = %.2f, Rs = %.2f, tc = %.2f, Rt = %.2f" % (wl, Rs, tc, Rt)
- ms = 1.0 + 40.0j
- for i, fname in enumerate(files):
- print "Calculating spectra for file '%s'..." % (fname)
- basename = os.path.splitext(fname)[0]
- nvalues = np.loadtxt('%s/%s' % (dirname, fname))*1.0 + 1e-11j
- tl = tc/len(nvalues)
- r = [Rs]
- for i in range(len(nvalues)):
- r += [r[i] + tl]
- x = np.ones((len(nvalues) + 1), dtype = np.float64)
- m = np.ones((len(nvalues) + 1), dtype = np.complex128)
- x = 2.0*np.pi*np.array(r, dtype = np.float64)/wl
- m = np.array([ms] + nvalues[:, 1].tolist(), dtype = np.complex128)
- print(x,m)
- factor = 2.91*x[0]/x[-1]
- print factor
- comment='PEC-'+basename
- WL_units=''
-
-
- flow_total = 24
-
-
- crossplane='XYZ'
-
-
-
-
-
-
- field_to_plot='angleEx'
-
- print "x =", x
- print "m =", m
- import matplotlib.pyplot as plt
- plt.rcParams.update({'font.size': 16})
- fig, axs = plt.subplots(1,1)
- fig.tight_layout()
- fieldplot(fig, axs, x,m, wl, comment, WL_units, crossplane, field_to_plot, npts, factor, flow_total,
- subplot_label=' ',is_flow_extend=False
- , outline_width=1.5
- , pl=0
- )
-
-
-
-
-
- fig.subplots_adjust(hspace=0.3, wspace=-0.1)
- plt.savefig(comment+"-R"+str(int(round(x[-1]*wl/2.0/np.pi)))+"-"+crossplane+"-"
- +field_to_plot+".pdf",pad_inches=0.02, bbox_inches='tight')
- plt.draw()
- plt.clf()
- plt.close()
- print "Done!!"
|