diff --git a/__pycache__/particle.cpython-312.pyc b/__pycache__/particle.cpython-312.pyc index 077ed3f..7b0d7c1 100644 Binary files a/__pycache__/particle.cpython-312.pyc and b/__pycache__/particle.cpython-312.pyc differ diff --git a/__pycache__/sensor.cpython-312.pyc b/__pycache__/sensor.cpython-312.pyc index ba68a55..3093b47 100644 Binary files a/__pycache__/sensor.cpython-312.pyc and b/__pycache__/sensor.cpython-312.pyc differ diff --git a/__pycache__/slider.cpython-312.pyc b/__pycache__/slider.cpython-312.pyc index ca00cce..3bc5507 100644 Binary files a/__pycache__/slider.cpython-312.pyc and b/__pycache__/slider.cpython-312.pyc differ diff --git a/main.py b/main.py index 3c20a5d..cb37ebf 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import pygame import numpy as np import matplotlib.pyplot as plt +import math from particle import Particle from sensor import Sensor from slider import Slider @@ -11,42 +12,67 @@ SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 SENSOR_DISTANCE = 200 +REST_MEDIUM = 180000 y_lim = 40000 +y_lim2 = 0.000000000005 screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) sensor = Sensor(width = 50, distance = SENSOR_DISTANCE, space = 300) +sensor.inputVoltage(5, -5) -silica = Particle(speed = 1, size = 60, perm = 4) + + +silica = Particle(speed = 1, size = 60, perm = 4, rest = pow(10, 12)) time = .1 time_data = [] volume_data = [] - +sensor_data = [] +rest_data = [] +current1_data = [] +current2_data = [] plt.ion() -fig, ax = plt.subplots() +fig, (ax, ax2) = plt.subplots(2, 1, figsize=(10, 10)) line, = ax.plot([], [], 'r-') -ax.set_xlim(0, 800) -ax.set_ylim(-1000, y_lim) +line2, = ax.plot([], [], 'g-') +line3, = ax2.plot([], [], 'b-') +line4, = ax2.plot([], [], 'g-') +ax.set_xlim(0, 900) +ax.set_ylim(-0.01, y_lim) ax.set_xlabel('Time (s)') ax.set_ylabel('Volume') ax.set_title('Volume/time') +ax2.set_xlim(0, 900) +ax2.set_ylim(-1 * y_lim2, y_lim2) +ax2.set_xlabel('Time (s)') +ax2.set_ylabel('Current') +ax2.set_title('Current/time') + slider1 = Slider(20, 20, 100, 20, 20, SENSOR_DISTANCE / 2, 80) +slider2 = Slider(20, 50, 100, 20, .1, 10, 1) +slider3 = Slider(20, 80, 100, 20, 1, 100, 10) run = True while run: + timeScale = slider2.value + sensor.inputVoltage(slider3.value, -1 * slider3.value) distance = silica.move(time) if distance > SCREEN_WIDTH + (silica.size * 2): time =.1 time_data = [] volume_data = [] + sensor_data = [] + rest_data = [] + current1_data = [] + current2_data = [] screen.fill((0,0,0)) @@ -56,6 +82,8 @@ while run: pygame.draw.circle(screen, (0,255,0), (distance - silica.size, 300), 10) slider1.draw(screen) + slider2.draw(screen) + slider3.draw(screen) silica.updateSize(slider1.value) @@ -63,26 +91,77 @@ while run: if event.type == pygame.QUIT: run = False slider1.handle_event(event) + slider2.handle_event(event) + slider3.handle_event(event) volume = sensor.getParticleVolume(distance, silica) + + sensor_data_volume = sensor.volume - volume + sensor_data.append(sensor_data_volume) + + sensor_resistance = REST_MEDIUM * ((pow(sensor.distance, 2) * pow(10, -18)) / (sensor_data_volume * pow(10, -27))) + nom_sens_res = REST_MEDIUM * ((sensor.distance * pow(10, -9)) / (sensor.width * sensor.distance * pow(10, -18))) + + if volume: + particle_resistance = silica.rest * pow((3/(16 * pow(math.pi, 2) * volume * pow(10, -9))), 1/3) + total_resistance_inv = (1 / particle_resistance) + (1 / sensor_resistance) + else: + particle_resistance = 0 + total_resistance_inv = 1 / sensor_resistance + + total_resistance = 1 / total_resistance_inv + + current1 = 0 + current2 = 0 + + + which_sensor = sensor.whichSensor(distance, silica) + if which_sensor == 1: + current1 = sensor.voltage1 / total_resistance + current2 = sensor.voltage2 / nom_sens_res + elif which_sensor == 2: + current2 = sensor.voltage2 / total_resistance + current1 = sensor.voltage1 / nom_sens_res + else: + current1 = sensor.voltage1 / nom_sens_res + current2 = sensor.voltage2 / nom_sens_res + + current1_data.append(current1) + current2_data.append(current2) + print(f"{current1} = {sensor.voltage1} / {total_resistance}") + rest_data.append(total_resistance) if (volume > y_lim): y_lim = volume + (volume * 1.2) ax.set_ylim(-1000, y_lim) + + if (current1 > y_lim2): + y_lim2 = current1 + (current1 * 1.2) + ax2.set_ylim(-1 * y_lim2, y_lim2) + + time_data.append(time) volume_data.append(volume) line.set_xdata(time_data) line.set_ydata(volume_data) + line2.set_xdata(time_data) + line2.set_ydata(sensor_data) + line3.set_xdata(time_data) + line3.set_ydata(current1_data) + line4.set_xdata(time_data) + line4.set_ydata(current2_data) ax.relim() ax.autoscale_view() + ax2.relim() + ax2.autoscale_view() plt.draw() plt.pause(0.01) pygame.display.update() - time = time + 1 + time = timeScale + time pygame.quit() diff --git a/particle.py b/particle.py index 6977c62..338b020 100644 --- a/particle.py +++ b/particle.py @@ -1,10 +1,11 @@ import math class Particle: - def __init__(self, speed, size, perm): + def __init__(self, speed, size, perm, rest): self.speed = speed self.size = size self.perm = perm + self.rest = rest self.volume = (4/3.0) * math.pi * size * size * size def move(self, time): diff --git a/pics/Figure_1.png b/pics/Figure_1.png new file mode 100644 index 0000000..c6aa4f5 Binary files /dev/null and b/pics/Figure_1.png differ diff --git a/sensor.py b/sensor.py index d30499a..6e53002 100644 --- a/sensor.py +++ b/sensor.py @@ -5,6 +5,7 @@ class Sensor: self.width = width self.distance = distance self.space = space + self.volume = width * pow(distance, 2) def generate(self, screenWidth, screenHeight, screen): self.sensor1_x = (screenWidth / 2) - (self.space / 2) - self.width @@ -34,45 +35,18 @@ class Sensor: pygame.draw.rect(screen, (0, 0, 255), sensor2b) def testSensor1(self, partCenter, particle): - - particle_x = partCenter - particle.size - particle_right = particle_x + particle.size - particle_left = particle_x - particle.size - # Sensor lines on one half of sphere center - if particle_right > self.outer1 and particle_x < self.inner1: - volume = particle.partialVol(self.width + (particle_right - self.outer1)) - particle.partialVol(particle_right - self.outer1) - print("On right half") - print(volume) + if (particle.size >= abs(self.inner1 - (partCenter - particle.size))) and (particle.size >= abs(self.outer1 - (partCenter - particle.size))): + volume = ((particle.volume / 2) - (particle.partialVol(particle.size - ((partCenter - particle.size) - self.inner1)))) + ((particle.volume / 2) - particle.partialVol(particle.size - (self.outer1 - (partCenter - particle.size)))) return volume - # if Sensor is on left half of sphere center - elif particle_left < self.inner1 and particle_x > self.outer1: - volume = particle.partialVol(self.width + (self.inner1 - particle_left)) - particle.partialVol(self.inner1 - particle_left) - print("On left half") - print(volume) + elif particle.size >= abs(self.inner1 - (partCenter - particle.size)): + volume = particle.partialVol(particle.size - (self.inner1 - (partCenter - particle.size))) return volume - # On bolth halves - elif (particle_x >= self.inner1 and particle_x <= self.outer1) and particle_left < self.inner1 and particle_right > self.outer1: - volume_left = particle.partialVol(self.inner1 - particle_left) - volume_right = particle.partialVol(particle_right - self.outer1) - volume = particle.volume - (volume_left + volume_right) - print("On both halves") - print(volume_left) - print(volume_right) + elif particle.size >= abs(self.outer1 - (partCenter - particle.size)): + volume = particle.volume - particle.partialVol(particle.size - (self.outer1 - (partCenter - particle.size))) return volume - elif (particle_right > self.inner1 and particle_right < self.outer1) and particle_x <= self.inner1: - volume = particle.partialVol(particle_right - self.inner1) - print("Approaching from left") - print(volume) + elif ((partCenter - particle.size) >= self.inner1 and (partCenter - particle.size) <= self.outer1): + volume = particle.volume return volume - elif (particle_left > self.inner1 and particle_left < self.outer1) and particle_x >= self.outer1: - volume = particle.partialVol(self.outer1 - particle_left) - print("Leaving from left") - print(volume) - return volume - elif (particle_right > self.inner1 and particle_right <= self.outer1) and (particle_left >= self.inner1 and particle_left < self.outer1): - print("in between") - print(particle.volume) - return particle.volume else: return 0 @@ -94,6 +68,7 @@ class Sensor: def getParticleVolume(self, partCenter, particle): volume1 = self.testSensor1(partCenter, particle) + #volume1 = 0 volume2 = self.testSensor2(partCenter, particle) if volume1: @@ -102,3 +77,19 @@ class Sensor: return volume2 else: return 0 + + def whichSensor(self, partCenter, particle): + volume1 = self.testSensor1(partCenter, particle) + #volume1 = 0 + volume2 = self.testSensor2(partCenter, particle) + + if volume1: + return 1 + elif volume2: + return 2 + else: + return 0 + + def inputVoltage(self, voltage1, voltage2): + self.voltage1 = voltage1 + self.voltage2 = voltage2