My Project
plotFrictionLaw.py
Go to the documentation of this file.
1 import numpy as np
2 from matplotlib import pyplot as plt
3 
4 import matplotlib as mpl
5 
6 plt.rcParams["svg.fonttype"] = "none"
7 plt.rcParams['font.size'] = 16
8 
9 mpl.rcParams["savefig.directory"] = "../../Figures"
10 
11 #plt.style.use('classic')
12 
13 import sys
14 
16 
17  def __init__(self):
18  self.sigma = 0.01
19  self.F_0 = 0.1
20  self.y = np.linspace(start = -10, stop = 10, num =1000)
21 
22  def frictionLaw(self):
23  self.phi = self.F_0 * ((1 - self.sigma)/(1 + np.abs(self.y)/(1 - self.sigma)) * np.sign(self.y))
24  self.setMidPointsToOne()
25 
26  def setMidPointsToOne(self):
27  length_of_phi = len(self.phi)
28  if(length_of_phi % 2 == 0):
29  self.phi[int(length_of_phi/2 - 1)] = -1*self.F_0
30  self.phi[int(length_of_phi/2)] = 1*self.F_0
31 
32  self.y[int(length_of_phi/2 - 1)] = 0
33  self.y[int(length_of_phi/2)] = 0
34  else:
35  self.phi[int((length_of_phi-1)/2) -1] = -1*self.F_0
36  self.phi[int((length_of_phi-1)/2)] = 1*self.F_0
37 
38  self.y[int((length_of_phi-1)/2 - 1)] = 0
39  self.y[int((length_of_phi - 1)/2)] = 0
40 
41  def frictionLawCarlson(self):
42  sigma = 0.1
43  y_bigger_than_zero = np.linspace(start = 0.001, stop = 10, num = 1000)
44  y = np.hstack((np.array([0,0]), y_bigger_than_zero))
45  phi = np.hstack((np.array([-2, 1]), ((1 - sigma)/(1 + np.abs(y_bigger_than_zero)/(1 - sigma)) * np.sign(y_bigger_than_zero))))
46 
47  fig, ax = plt.subplots()
48  ax.axhline(y=0, color = 'k')
49  ax.axvline(x=0, color = 'k')
50  ax.plot(y, phi, label = "Friction Law")
51  ax.set_ylim(-1, 1.5)
52  ax.set_xlim(-3, 3)
53  if('-l' in sys.argv):
54  plt.xscale('log')
55  ax.set_xlim(0, 1)
56  ax.set_ylabel("$\phi(y)$")
57  ax.set_xlabel("$y$")
58  ax.legend()
59  plt.show()
60 
61 
62  def plotFrictionLaw(self):
63  self.frictionLaw()
64 
65  plt.plot(self.y, self.phi)
66  plt.ylabel("\$\phi(y)\$")
67  plt.xlabel("\$y\$")
68  plt.axes()
69  plt.savefig("../../Figures/Master/Friction_law_demo.svg", format="svg")
70  plt.show()
71 
72 
74  friction = FrictionLaw()
75  friction.plotFrictionLaw()
76  friction.frictionLawCarlson()
77 
78 if __name__ == "__main__":