"""gun.py: Class for gun experiment. Goals are: to develop, analyze and understand a procedure for estimating an isentrope on the basis of data and simulations. """ import numpy as np from eos import Go import fit magic = Go( x_i=0.4, # Initial position of projectile / cm' x_f=4.0, # Final/muzzle position of projectile /cm' m=100.0, # Mass of projectile / g area=1e-4, # Projectile cross section in m^2 newton2dyne=1e5, # dynes per newton var=1.0e-0, # Variance attributed to v measurements n_t=500, # Number of ts for t2v spline t_min=-5.0e-6, # Range of times for t2v spline t_max=110.0e-6, # Range of times for t2v spline cm2km=1.0e5, # For conversion from cm/sec to km/sec n_t_sim=1000, # len(vt), simulated velocity time pairs ) magic.add(D_frac=fit.magic.D_frac) # Fractional finite difference for dv/df class Gun: '''Represents an imagined experiment and actual simulations. Section 2 of the document ../juq.tex describes the imagined experiment.
"""fit.py: Coordinates optimization for fitting a model eos to experiments. """ import numpy as np from eos import Go magic = Go( D_frac=2.0e-2, # Fractional finte difference for esimating dv/df fit_dim=50, # Number of x points for EOS fit max_iter=5, # Bound for iterations maximizing likelihood converge=1.0e-5, # Fractional tolerance for cost ) class Opt: def __init__( self, # Opt instance eos, # eos.Spline_eos instance experiment, # Dict of experimental simulation objects data, # Dict of experimental data ): ''' ''' self.eos = eos self.original_eos = eos self.experiment = experiment self.data = data assert set(experiment.keys()) == set(data.keys()) return def step(self, constrain=True, debug=False):
"""stick.py: Class for rate stick experiment. """ import numpy as np from eos import Go # From description of Shot1 in Pemberton's document pemberton = Go( densities=np.array( # g/cc, page4 [1.835, 1.8358, 1.8353, 1.8356, 1.8356, 1.8345]), positions=np.array( # mm, page 8 [25.9, 50.74, 75.98, 101.8, 125.91, 152.04, 177.61]), x_dev=0.02, # mm, position measurement uncertainty (my guess) t_dev=1.0e-9, # sec, time measurement uncertainty (my guess) velocity=8.8132, # Km/sec, page 9 ) import fit class Stick: '''Represents an imagined experiment and simulation that creates data, t, the "measured" times. See the subsection "A Rate Stick" in the section "Experiments" of notes.pdf. Methods: fit_v() Return detonation velocity
def main(argv=None): import argparse import os import os.path if argv is None: # Usual case argv = sys.argv[1:] parser = argparse.ArgumentParser(description='Make plots for notes.pdf') parser.add_argument('--show', action='store_true') parser.add_argument('--fig_dir', type=str, default='figs', help= 'Directory of figures') # Plot requests h_format = lambda s:'File for figure of {0}'.format(s) parser.add_argument('--tx_stick', type=str, help=h_format('t(x)')) parser.add_argument('--C_gun', type=str, help=h_format('d c_v/ d c_p')) parser.add_argument('--vt_gun', type=str, help=h_format('v(t)')) parser.add_argument('--BC_gun', type=str, help=h_format('d v(t)/ d c_p')) parser.add_argument('--opt_result', type=str, help=h_format( 'one optimization step')) parser.add_argument('--big_d', type=str, help=h_format( 'finite difference derivative with 9 subplots')) parser.add_argument('--fve_gun', type=str, help=h_format( 'force, velocity and sequence of errors')) args = parser.parse_args(argv) params = {'axes.labelsize': 18, # Plotting parameters for latex 'font.size': 15, 'legend.fontsize': 15, 'text.usetex': True, 'font.family':'serif', 'font.serif':'Computer Modern Roman', 'xtick.labelsize': 15, 'ytick.labelsize': 15} mpl.rcParams.update(params) if args.show: mpl.rcParams['text.usetex'] = False else: mpl.use('PDF') import matplotlib.pyplot as plt # must be after mpl.use if not os.path.exists(args.fig_dir): os.mkdir(args.fig_dir) # Do quick calculations to create exp and nom import eos import gun import stick t=np.linspace(0, gun.magic.t_max, gun.magic.n_t_sim) exp = Go(eos=eos.Experiment()) nom = Go(eos=eos.Spline_eos(eos.Nominal(), precondition=True)) for go in (exp, nom): go.add(t=t, gun=gun.Gun(go.eos), stick=stick.Stick(go.eos)) go.add(x=np.linspace(go.gun.x_i, go.gun.x_f, 500)) go.add(t2v=go.gun.fit_t2v()) go.add(v=go.t2v(t)) go.add(vt=(go.v, go.t)) go.add(stick_data=stick.data(go.eos)) C=nom.gun.fit_C() B,ep = nom.gun.fit_B_ep(exp.vt) nom.add(C=C, B=B, ep=ep, BC=np.dot(B,C)) # Make requested plots do_show = args.show for key in args.__dict__: if key not in plot_dict: continue if args.__dict__[key] == None: continue print('work on %s'%(key,)) fig = plot_dict[key](exp, nom, plt) file_name = getattr(args, key) if file_name == 'show': do_show = True else: fig.savefig(os.path.join(args.fig_dir, file_name), format='pdf') if do_show: plt.show() return 0