<commit_before>"""
Created on Sat Oct 22 21:02:33 2016
@authors: <NAME> & <NAME>  
History:
    22/10/2016: WJ - Created file, replicating matlab script collisiontrial.m
    26/10/2016: LM - Fixed array-making bugs, animated properly
    1/11/2016: WJ - Added collision code back in, currently not working properly
    3/11/2016: WJ - Fixed looping code - would collide regardless after each 
        loop. Added momentum to collisions so different masses work. Added 
        size_arr, collisions working but not animation.
    8/11/2016: LM - Made marker size vary according to ball size Balls are 
        overlapping walls and sometimes each other
    9/11/2016: LM - Made box class and walls use this class, added energy check
    10/11/2016: LM - Put in pressure read for animation
    22/11/2016: WJ - Updated collision code with vectorised t_collide 
        subroutine. Still won't run properly for me (plot opens and immediately 
        closes). No error message or debugging.
    23/11/2016: WJ - Fixed new collision code, vectorised wall code. Separated
        functions to brownian_tools module.
    24/11/2016: WJ - Added in new collision routine for walls, incomplete.
    6/12/2016: WJ - Added new wall class with initialisation routines.
    6/12/2016: LM - Added sawtooth function with trigger wall on tooth side.
        Needs assimilating to rest of new code.
    
Variable naming convention:
    w_... Wall related variable (should probably make class)
    n_... # of ...
    p_... position of ...
    v_... velocity of ...
    ..._n normal vector of ...
    ..._p parallel vector of ...
"""

import sys
import numpy as np
import scipy as sp
from scipy import signal
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from brownian_tools import *

"""
Define # of dimensions
"""
nd = 2

"""
Define wall class
[move to different file?]
"""
class Wall:
    """
    Initialise with coordinate 0,0,...
    """
    def __init__(self, nd):
        #no. of dimensions
        self.nd = nd
        #corner co-ords
        self.co = np.full([1,self.nd],0)
        #Limits of box
        self.x_v = np.array([0,0])
        self.y_v = np.array([0,0])
        #no. of walls (# of co-ords -1)
        self.n = 0
        """TODO: add check for corresponding periodic boundary"""
        #Periodic boundary flag
        self.pb_flag = 0
        #Index of corresponding opposite boundary
        self.pb_ind = 0
        #Roughness value (randomly rotates wall vector for collision)
        self.rb = 0
        #Friction value (proportionally reduces parallel v)
        self.fb = 0

    """Get normalised wall vector for each wall"""
    def get_v(self):
        self.v = np.full([self.n,self.nd],np.nan)
        for i in np.arange(self.n):
            self.v[i] = self.co[i+1] - self.co[i]
        
        self.v = self.v / (np.sum(self.v**2, axis=1))**0.5

    """Get perpendicular normal vector for each wall (2d)"""
    def get_n(self):
        if nd == 2:
            self.n = np.concatenate((-self.v[:,1],self.v[:,0]), axis=1)
    
    """Set wall coords and find vectors for 2d case"""
    def set_2d(self):
        if np.sum(self.co[-1] != self.co[0]) >= 1:
            self.co = np.concatenate((self.co, self.co[-1]), axis=0)
        
        self.x_v = np.array([np.nanmin(self.co[:,0]),np.nanmax(self.co[:,0])])
        self.y_v = np.array([np.nanmin(self.co[:,1]),np.nanmax(self.co[:,1])])
        self.n = np.size(self.co)[0] - 1
        self.get_v()
        self.get_n()
        
    #def check_inside(pos,vel):
        
 

"""
Set # of balls, radii and masses
Define as arrays for multiple different balls
"""
n_balls = np.array([100,5,1])
radii = np.array([0.025,0.1,0.2])
m_balls = np.array([5,100,400])

"""
Define number of steps (for plotting) and step length, find max time
"""
n_steps = 100
l_step = 0.01

t_max = l_step*n_steps

"""
Define wall coordinates<commit_msg>Adding rect function<commit_after>"""
Created on Sat Oct 22 21:02:33 2016
@authors: <NAME> & <NAME>  
History:
    22/10/2016: WJ - Created file, replicating matlab script collisiontrial.m
    26/10/2016: LM - Fixed array-making bugs, animated properly
    1/11/2016: WJ - Added collision code back in, currently not working properly
    3/11/2016: WJ - Fixed looping code - would collide regardless after each 
        loop. Added momentum to collisions so different masses work. Added 
        size_arr, collisions working but not animation.
    8/11/2016: LM - Made marker size vary according to ball size Balls are 
        overlapping walls and sometimes each other
    9/11/2016: LM - Made box class and walls use this class, added energy check
    10/11/2016: LM - Put in pressure read for animation
    22/11/2016: WJ - Updated collision code with vectorised t_collide 
        subroutine. Still won't run properly for me (plot opens and immediately 
        closes). No error message or debugging.
    23/11/2016: WJ - Fixed new collision code, vectorised wall code. Separated
        functions to brownian_tools module.
    24/11/2016: WJ - Added in new collision routine for walls, incomplete.
    6/12/2016: WJ - Added new wall class with initialisation routines.
    6/12/2016: LM - Added sawtooth function with trigger wall on tooth side.
        Needs assimilating to rest of new code.
    
Variable naming convention:
    w_... Wall related variable (should probably make class)
    n_... # of ...
    p_... position of ...
    v_... velocity of ...
    ..._n normal vector of ...
    ..._p parallel vector of ...
"""

import sys
import numpy as np
import scipy as sp
from scipy import signal
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from brownian_tools import *

"""
Define # of dimensions
"""
nd = 2

"""
Define wall class
[move to different file?]
"""
class Wall:
    """
    Initialise with coordinate 0,0,...
    """
    def __init__(self, nd):
        #no. of dimensions
        self.nd = nd
        #corner co-ords
        self.co = np.full([1,self.nd],0)
        #Limits of box
        self.x_v = np.array([0,0])
        self.y_v = np.array([0,0])
        #no. of walls (# of co-ords -1)
        self.n = 0
        """TODO: add check for corresponding periodic boundary"""
        #Periodic boundary flag
        self.pb_flag = 0
        #Index of corresponding opposite boundary
        self.pb_ind = 0
        #Roughness value (randomly rotates wall vector for collision)
        self.rb = 0
        #Friction value (proportionally reduces parallel v)
        self.fb = 0

    """Get normalised wall vector for each wall"""
    def get_v(self):
        self.v = np.full([self.n,self.nd],np.nan)
        for i in np.arange(self.n):
            self.v[i] = self.co[i+1] - self.co[i]
        
        self.v = self.v / (np.sum(self.v**2, axis=1))**0.5

    """Get perpendicular normal vector for each wall (2d)"""
    def get_n(self):
        if nd == 2:
            self.n = np.concatenate((-self.v[:,1],self.v[:,0]), axis=1)
    
    """Set wall coords and find vectors for 2d case"""
    def set_2d(self):
        if np.sum(self.co[-1] != self.co[0]) >= 1:
            self.co = np.concatenate((self.co, self.co[-1]), axis=0)
        
        self.x_v = np.array([np.nanmin(self.co[:,0]),np.nanmax(self.co[:,0])])
        self.y_v = np.array([np.nanmin(self.co[:,1]),np.nanmax(self.co[:,1])])
        self.n = np.size(self.co)[0] - 1
        self.get_v()
        self.get_n()
        
    def rect(self,x0,y0,x1,y1):
        self.co = np.array([[x0,y0],
                            [x1,y0],
                            [x1,y1],
                            [x0,y1]])
        self.set_2d()
    
    
    
    #def check_inside(pos,vel):
        
 

"""
Set # of balls, radii and masses
Define as arrays for multiple different balls
"""
n_balls = np.array([100,5,1])
radii = np.array([0.025,0.1,0.2])
m_balls = np.array([5,100,400])

"""
Define number of steps (for plotting) and step length, find max time
"""
n_steps = 100
l_step = 0.01

t_max = l_step*n_steps

"""
Define wall coordinates
{'fraction_non_alphanumeric': 0.12272220156191893, 'fraction_numerical': 0.04276682781703235, 'mean_word_length': 2.3283828382838285, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3036184', 'n_tokens_mistral': 2835, 'n_tokens_neox': 2570, 'n_words': 851}