3 from matplotlib
import pyplot
as plt
5 from matplotlib2tikz
import save
as tikz_save
7 import matplotlib
as mpl
9 mpl.rcParams[
'svg.fonttype'] =
"none" 10 mpl.rcParams[
'font.size'] = 16
13 mpl.rc(
'font', **{
'family':
'serif',
'serif': [
'Computer Modern']})
14 mpl.rc(
'text', usetex=
True)
20 from yaml
import CLoader
as Loader, CDumper
as Dumper
22 from yaml
import Loader, Dumper
26 def __init__(self, run_name = "", comparison_name = "", numeric_method = "_midpoint_"):
31 if(comparison_name ==
""):
38 print(
"Only pullings springs in input.")
41 print(
"Only neighbor springs in input.")
44 print(
"Can only run test 1 if no fiction, neighbor springs, \ 45 damper is activated and the pad behaves as it's fastened to the roof surface. ")
46 print(
"Can only run test 2 if no friction, stationary springs \ 47 damper is activated and the pad behaves as it's fastened to the roof surface. ")
65 print(
"Can only run test 1 if no fiction, neighbor springs, \ 66 damper is activated and the pad behaves as it's fastened to the roof surface. ")
67 print(
"Can only run test 2 if no friction, stationary springs \ 68 damper is activated and the pad behaves as it's fastened to the roof surface. ")
75 self.
results_path = os.path.dirname(os.path.realpath(__file__)) +
"/../../../results/" 76 results_folder =
"/results/" 78 stream = open(self.
results_path + run_name +
"/doc/yaml/parameters.yaml",
'r') 83 self.
block_position = np.loadtxt(self.
results_path + run_name + results_folder + shared_names + numeric_method +
"block_position.csv", delimiter=
",")
84 self.
block_velocity = np.loadtxt(self.
results_path + run_name + results_folder + shared_names + numeric_method +
"block_velocity.csv", delimiter=
",")
87 print(
"Remember, this code assumes that the only difference between the two runs is the stepsize.")
89 results_folder =
"/results/" 109 self.
x = np.linspace(start = start, stop = stop, num = len(self.
block_position[0]))
134 no_neighbor_springs = self.
run_parameters[
"Debug"][
"debug_no_neighbor_springs"]
138 self.
only_pulling_springs = all(value ==
True for value
in [no_friction, no_neighbor_springs, no_damper, no_pad])
142 no_stationary_springs = self.
run_parameters[
"Debug"][
"debug_no_stationary_springs"]
146 self.
only_neighbor_springs = all(value ==
True for value
in [no_friction, no_stationary_springs, no_damper, no_pad])
157 m_u = m_scale_mass*m_mass_x/N
158 k_p = m_scale_P*m_k_P0/N
160 energy_only_pulling_springs_test = 1/2 * m_u * np.sum(np.power(block_velocity, 2), axis=0) + \
161 1/2 * k_p * np.sum(np.power(block_position, 2), axis = 0)
162 return(energy_only_pulling_springs_test)
171 m_u = m_scale_mass*m_mass_x/N
172 k_c = m_scale_C*m_k_P0*N
174 last_energy_ledd = block_position[1:,] - block_position[:-1,]
176 energy_only_neighbor_springs_test = 1/2 * m_u * np.sum(np.power(block_velocity, 2), axis=0) + \
177 1/2 * k_c * np.sum(np.power(last_energy_ledd, 2), axis = 0)
179 return(energy_only_neighbor_springs_test)
182 plt.plot(self.
x, energy_test_result, label =
"Energy")
185 plt.ylim(0, np.max(energy_test_result)*(1.10))
193 plt.plot(self.
x, energy_test_result, label = str(self.
step_size))
197 plt.ylim(0, np.max([np.max(energy_test_result), np.max(energy_test_result_comparison)])*(1.10))
205 tikz_save(self.
results_path +
'mytikz.tex', figureheight=
'8cm', figurewidth=
'8cm')
211 if(len(sys.argv) > 2):
212 checkEnergy =
CheckEnergy(sys.argv[1], sys.argv[2])
213 elif(len(sys.argv) == 2):
218 if __name__ ==
"__main__":
one_block_boolean_comparison
def checkOnlyNeighborEnergyTest(self)
def onlyNeighborSpringsEnergyTest(self, block_velocity, block_position)
def onlyPullingSpringsEnergyTest(self, block_velocity, block_position)
def plotEnergyTestComparison(self, energy_test_result, energy_test_result_comparison, zoom=True)
def checkOnlyPullingEnergyTest(self)
def loadFiles(self, run_name, numeric_method)
def __init__(self, run_name="", comparison_name="", numeric_method="_midpoint_")
block_position_comparison
def loadComparisonFiles(self, comparison_name, numeric_method)
def checkPossibleEnergytests(self)
def setUpPlotComparison(self)
block_velocity_comparison
def plotEnergyTest(self, energy_test_result, zoom=True)
def comparisonResult(self, comparison_name, numeric_method)
def saveAsTikz(self, filename)