<commit_before>import rsf
import numpy as np
import matplotlib.pyplot as plt
import sys

def error():
    print "Error! Valid test types are step and shs"
    sys.exit()

if len(sys.argv)<2:
    error()

test = sys.argv[1]

if test=='step':

    model = rsf.RateState()

    # Set model initial conditions
    model.mu0 = 0.6
    model.a = 0.005
    model.b = 0.01
    model.dc = 10.
    model.k = 1e-3
    model.v = 1.
    model.vlp = 10.

    # We want to solve for 30 seconds at 100Hz
    model.model_time = np.arange(0,40.01,0.01)

    # We want to slide at 1 um/s for 10 s, then at 10 um/s for 31
    lp_velocity = np.ones_like(model.model_time)
    lp_velocity[10*100:] = 10. # duplicate chris' step

    # This makes an interesting case for sure. Different linear acceleartion profiles
    #lp_velocity[10*100:11*100] = np.linspace(1,10,100) # ramp over 1 second
    #lp_velocity[10*100:15*100] = np.linspace(1,10,500) # ramp over 5 seconds

    # Set the model load point velocity, must be same shape as model.model_time
    model.loadpoint_velocity = lp_velocity

    results = model.solve()

    velocity = results.slider_velocity
    friction = results.friction
    state = results.state1

    print np.shape(model.model_time)
    print np.shape(velocity)
    print np.shape(friction)
    print np.shape(state)

    t = np.arange(0,30,0.01)

    # Read in <NAME>'s Solutions
    cjm_disp, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_model.dis',skiprows=2,unpack=True)
    cjm_time, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_model.tim',skiprows=2,unpack=True)
    cjm_state = np.loadtxt('cjm_model_comparison/cjm_model.sta',skiprows=2,unpack=True,usecols=[1])
    cjm_vel,cjm_mu2 = np.loadtxt('cjm_model_comparison/cjm_model.vel',skiprows=2,unpack=True)
    cjm_vel = np.exp(cjm_vel)*1.

    fig = plt.figure(1)
    plt.title('Slider Velocity')
    plt.plot(velocity,color='k',label='JRL')
    plt.plot(cjm_vel,color='r',label='CJM')
    #plt.plot(velocities,color='b')

    fig = plt.figure(2)
    plt.title('Friction')
    plt.plot(model.model_time-10.,friction,color='k',label='JRL')
    plt.plot(cjm_time,cjm_mu,color='r',label='CJM')

    fig = plt.figure(3)
    plt.title('State Variable')
    plt.plot(model.model_time-10.,state,color='k',label='JRL')
    plt.plot(cjm_time,cjm_state,color='r',label='CJM')

    fig = plt.figure(4)
    plt.title('Phase')
    #ln(v/v0),mu
    plt.plot(np.log(model.results.slider_velocity/model.vref),model.results.friction,color='k',label='JRL')
    plt.plot(np.log(cjm_vel/1.),cjm_mu2,color='r',label='CJM')

    fig = plt.figure(5)
    plt.title('Loading Velocity Profile')
    plt.plot(model.model_time-10., model.loadpoint_velocity)

    plt.show()


if test == 'shs':
    ## SHS EXAMPLE

    model = rsf.RateState()

    # Set model initial conditions
    model.mu0 = 0.6
    model.a = 0.005
    model.b = 0.01
    model.dc = 10.
    model.k = 1e-3
    model.v = 1.
    model.vlp = 10.

    # We want to solve for 30 seconds at 100Hz
    model.model_time = np.arange(0,310.01,0.01)

    # We want to slide at 1 um/s for 10 s, then at 10 um/s for 31
    lp_velocity = np.ones_like(model.model_time)
    lp_velocity[10*100:110*100] = 0.0#1e-10 # duplicate chris' step

    # Set the model load point velocity, must be same shape as model.model_time
    model.loadpoint_velocity = lp_velocity

    results = model.solve()

    velocity = results.slider_velocity
    friction = results.friction
    state = results.state1

    print np.shape(model.model_time)
    print np.shape(velocity)
    print np.shape(friction)
    print np.shape(state)

    # Read in <NAME>'s Solutions
    cjm_disp, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_shs.dis',skiprows=2,unpack=True)
    cjm_time, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_shs.tim',skiprows=2,unpack=True)
    cjm_state = np.loadtxt('cjm_model_comparison/cjm_shs.sta',skiprows=2,unpack=True,usecols=[1])
    cjm_vel,cjm_mu2 = np.loadtxt('cjm_model_comparison/cjm_shs.vel',skiprows=2,unpack=True)
    cjm_vel = np.exp(cjm_vel)*1.

    fig = plt.figure(1)
    plt.title('Slider Velocity')
    plt.plot(velocity,color='k',label='JRL')
    plt.plot(cjm_vel,color='r',label='CJM')
    #plt.plot(velocities,color='b')

    fig = plt.figure(2)
    plt.title('Friction')
    plt.plot(model.model_time-10.,friction,color='k',label='JRL')
    plt.plot(cjm_time,cjm_mu,color='r',label='CJM')

    fig = plt.figure(3)
    plt.title('State Variable')
    plt.plot(model.model_time-10.,state,color='k',label='JRL')
    plt.plot(cjm_time,cjm_state,color='r',label='CJM')

    fig = plt.figure(4)
    plt.title('Phase')
    #ln(v/v0),mu
    plt.plot(np.log(model.results.slider_velocity/model.vref),model.results.friction,color='k',label='JRL')
    plt.plot(np.log(cjm_vel/1.),cjm_mu2,color='r',label='CJM')

    fig = plt.figure(5)
    plt.title('Loading Velocity Profile')
    plt.plot(model.model_time-10., model.loadpoint_velocity)

    plt.show()

else:
    error()<commit_msg>Add negative velocity example to test<commit_after>import rsf
import numpy as np
import matplotlib.pyplot as plt
import sys

def error():
    print "Error! Valid test types are step and shs"
    sys.exit()

if len(sys.argv)<2:
    error()

test = sys.argv[1]

if test=='step':

    model = rsf.RateState()

    # Set model initial conditions
    model.mu0 = 0.6
    model.a = 0.005
    model.b = 0.01
    model.dc = 10.
    model.k = 1e-3
    model.v = 1.
    model.vlp = 10.

    # We want to solve for 30 seconds at 100Hz
    model.model_time = np.arange(0,40.01,0.01)

    # We want to slide at 1 um/s for 10 s, then at 10 um/s for 31
    lp_velocity = np.ones_like(model.model_time)
    lp_velocity[10*100:] = 10. # duplicate chris' step

    # This makes an interesting case for sure. Different linear acceleartion profiles
    #lp_velocity[10*100:11*100] = np.linspace(1,10,100) # ramp over 1 second
    #lp_velocity[10*100:15*100] = np.linspace(1,10,500) # ramp over 5 seconds

    # Set the model load point velocity, must be same shape as model.model_time
    model.loadpoint_velocity = lp_velocity

    results = model.solve()

    velocity = results.slider_velocity
    friction = results.friction
    state = results.state1

    print np.shape(model.model_time)
    print np.shape(velocity)
    print np.shape(friction)
    print np.shape(state)

    t = np.arange(0,30,0.01)

    # Read in <NAME>'s Solutions
    cjm_disp, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_model.dis',skiprows=2,unpack=True)
    cjm_time, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_model.tim',skiprows=2,unpack=True)
    cjm_state = np.loadtxt('cjm_model_comparison/cjm_model.sta',skiprows=2,unpack=True,usecols=[1])
    cjm_vel,cjm_mu2 = np.loadtxt('cjm_model_comparison/cjm_model.vel',skiprows=2,unpack=True)
    cjm_vel = np.exp(cjm_vel)*1.

    fig = plt.figure(1)
    plt.title('Slider Velocity')
    plt.plot(velocity,color='k',label='JRL')
    plt.plot(cjm_vel,color='r',label='CJM')
    #plt.plot(velocities,color='b')

    fig = plt.figure(2)
    plt.title('Friction')
    plt.plot(model.model_time-10.,friction,color='k',label='JRL')
    plt.plot(cjm_time,cjm_mu,color='r',label='CJM')

    fig = plt.figure(3)
    plt.title('State Variable')
    plt.plot(model.model_time-10.,state,color='k',label='JRL')
    plt.plot(cjm_time,cjm_state,color='r',label='CJM')

    fig = plt.figure(4)
    plt.title('Phase')
    #ln(v/v0),mu
    plt.plot(np.log(model.results.slider_velocity/model.vref),model.results.friction,color='k',label='JRL')
    plt.plot(np.log(cjm_vel/1.),cjm_mu2,color='r',label='CJM')

    fig = plt.figure(5)
    plt.title('Loading Velocity Profile')
    plt.plot(model.model_time-10., model.loadpoint_velocity)

    plt.show()


if test == 'shs':
    ## SHS EXAMPLE

    model = rsf.RateState()

    # Set model initial conditions
    model.mu0 = 0.6
    model.a = 0.005
    model.b = 0.01
    model.dc = 10.
    model.k = 1e-3
    model.v = 1.
    model.vlp = 10.

    # We want to solve for 30 seconds at 100Hz
    model.model_time = np.arange(0,310.01,0.01)

    # We want to slide at 1 um/s for 10 s, then at 10 um/s for 31
    lp_velocity = np.ones_like(model.model_time)
    lp_velocity[10*100:110*100] = 0.0#1e-10 # duplicate chris' step

    # Set the model load point velocity, must be same shape as model.model_time
    model.loadpoint_velocity = lp_velocity

    results = model.solve()

    velocity = results.slider_velocity
    friction = results.friction
    state = results.state1

    print np.shape(model.model_time)
    print np.shape(velocity)
    print np.shape(friction)
    print np.shape(state)

    # Read in <NAME>'s Solutions
    cjm_disp, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_shs.dis',skiprows=2,unpack=True)
    cjm_time, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_shs.tim',skiprows=2,unpack=True)
    cjm_state = np.loadtxt('cjm_model_comparison/cjm_shs.sta',skiprows=2,unpack=True,usecols=[1])
    cjm_vel,cjm_mu2 = np.loadtxt('cjm_model_comparison/cjm_shs.vel',skiprows=2,unpack=True)
    cjm_vel = np.exp(cjm_vel)*1.

    fig = plt.figure(1)
    plt.title('Slider Velocity')
    plt.plot(velocity,color='k',label='JRL')
    plt.plot(cjm_vel,color='r',label='CJM')
    #plt.plot(velocities,color='b')

    fig = plt.figure(2)
    plt.title('Friction')
    plt.plot(model.model_time-10.,friction,color='k',label='JRL')
    plt.plot(cjm_time,cjm_mu,color='r',label='CJM')

    fig = plt.figure(3)
    plt.title('State Variable')
    plt.plot(model.model_time-10.,state,color='k',label='JRL')
    plt.plot(cjm_time,cjm_state,color='r',label='CJM')

    fig = plt.figure(4)
    plt.title('Phase')
    #ln(v/v0),mu
    plt.plot(np.log(model.results.slider_velocity/model.vref),model.results.friction,color='k',label='JRL')
    plt.plot(np.log(cjm_vel/1.),cjm_mu2,color='r',label='CJM')

    fig = plt.figure(5)
    plt.title('Loading Velocity Profile')
    plt.plot(model.model_time-10., model.loadpoint_velocity)

    plt.show()

if test == 'exp':
    ## SHS EXAMPLE

    model = rsf.RateState()

    # Set model initial conditions
    model.mu0 = 0.6
    model.a = 0.005
    model.b = 0.01
    model.dc = 10.
    model.k = 1e-3
    model.v = 1.
    model.vlp = 10.

    # We want to solve for 30 seconds at 100Hz
    model.model_time = np.arange(0,310.01,0.01)

    # We want to slide at 1 um/s for 10 s, then at 10 um/s for 31
    lp_velocity = np.ones_like(model.model_time)
    lp_velocity[8*100:10*100] = -1.
    lp_velocity[10*100:110*100] = 0.0#

    # Set the model load point velocity, must be same shape as model.model_time
    model.loadpoint_velocity = lp_velocity

    results = model.solve()

    velocity = results.slider_velocity
    friction = results.friction
    state = results.state1

    print np.shape(model.model_time)
    print np.shape(velocity)
    print np.shape(friction)
    print np.shape(state)

    # Read in <NAME>'s Solutions
    cjm_disp, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_shs.dis',skiprows=2,unpack=True)
    cjm_time, cjm_mu = np.loadtxt('cjm_model_comparison/cjm_shs.tim',skiprows=2,unpack=True)
    cjm_state = np.loadtxt('cjm_model_comparison/cjm_shs.sta',skiprows=2,unpack=True,usecols=[1])
    cjm_vel,cjm_mu2 = np.loadtxt('cjm_model_comparison/cjm_shs.vel',skiprows=2,unpack=True)
    cjm_vel = np.exp(cjm_vel)*1.

    fig = plt.figure(1)
    plt.title('Slider Velocity')
    plt.plot(velocity,color='k',label='JRL')
    plt.plot(cjm_vel,color='r',label='CJM')
    #plt.plot(velocities,color='b')

    fig = plt.figure(2)
    plt.title('Friction')
    plt.plot(model.model_time-10.,friction,color='k',label='JRL')
    plt.plot(cjm_time,cjm_mu,color='r',label='CJM')

    fig = plt.figure(3)
    plt.title('State Variable')
    plt.plot(model.model_time-10.,state,color='k',label='JRL')
    plt.plot(cjm_time,cjm_state,color='r',label='CJM')

    fig = plt.figure(4)
    plt.title('Phase')
    #ln(v/v0),mu
    plt.plot(np.log(model.results.slider_velocity/model.vref),model.results.friction,color='k',label='JRL')
    plt.plot(np.log(cjm_vel/1.),cjm_mu2,color='r',label='CJM')

    fig = plt.figure(5)
    plt.title('Loading Velocity Profile')
    plt.plot(model.model_time-10., model.loadpoint_velocity)

    plt.show()

else:
    error()
{'fraction_non_alphanumeric': 0.14825106243870545, 'fraction_numerical': 0.036858450474011116, 'mean_word_length': 3.5917448405253283, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6909194', 'n_tokens_mistral': 5226, 'n_tokens_neox': 4716, 'n_words': 794}