예제 #1
0
def test_UpdateForward():
    test_Particle2.UpdateForward(deltaT=1.0)
    # updates a particle with the euler forward method and checks the position and acceleration is updated correctly
    assert test_Particle2.position == pytest.approx(
        np.array([1000010., 1500100., 2001000.]))
    assert test_Particle2.velocity == pytest.approx(
        np.array([1002500., 1503000., 2003500.]))
예제 #2
0
def test_UpdateCromer():
    test_Particle.UpdateCromer(deltaT=1.0)
    # updates a particle with the euler cromer method and checks the position and acceleration is updated correctly
    assert test_Particle.velocity == pytest.approx(
        np.array([1002500., 1503000., 2003500.]))
    assert test_Particle.position == pytest.approx(
        np.array([1002510., 1503100., 2004500.]))
예제 #3
0
 def __init__(self,
              min_x,
              max_x,
              n,
              population,
              table,
              W=0.6,
              c1=2,
              c2=2,
              generations=100,
              flag_choice=1,
              plt_name='default.txt',
              out_name='coef.txt'):
     # self.particles = np.full(population, Particle(n, max_x, min_x))
     self.particles = []
     [
         self.particles.append(Particle(n=n, min_x=min_x, max_x=max_x))
         for i in range(0, population)
     ]
     self.best_global_value = np.math.inf
     self.g_best_global = np.array([0, 0])
     self.T = table  # Аrray of NASA data for train/ check prog
     self.const = {
         'generations': generations,
         'population': population,
         'n': n,
         'W': W,
         'c1': c1,
         'c2': c2,
         'max_x': max_x,
         'min_x': min_x,
         'starting_value': self.particles,
         'strategy': flag_choice,
         'plot_name': plt_name,
         'coef_output_file': out_name
     }
     self.best_values_plot = []
예제 #4
0
def test_GenerateMagneticField():
    # check that a magnetic field can be created by a particle and is the correct vector at a distance
    assert test_Particle.magneticField.GenerateField(
        affectedParticle=test_Particle2) == pytest.approx(
            np.array([3.64049352e-09, -7.28098705e-09, 3.64049352e-09]))
예제 #5
0
def test_GenerateElectricField():
    # check that an electric field can be created by a particle and is the correct vector at a distance
    assert test_Particle.electricField.GenerateField(
        affectedParticle=test_Particle2) == pytest.approx(
            np.array([-1090.63746886, -1308.76496263, -1526.8924564]))
예제 #6
0
def test_Momentum():
    # checks momentum is calculated correctly
    assert test_Particle.Momentum() == pytest.approx(
        np.array([3000121.00801467, 4500181.51202201, 6000242.01602934]))
예제 #7
0
from Particle import Particle, np, math, const, PointElectricFieldClass, PointMagneticFieldClass
import pytest
import re

test_Particle = Particle(position=np.array([10, 100, 1000]),
                         velocity=np.array([1e6, 1.5e6, 2e6]),
                         acceleration=np.array([2.5e3, 3e3, 3.5e3]),
                         name='test_Particle',
                         restMass=3.0,
                         charge=7.0)

test_Particle2 = Particle(position=np.array([10, 100, 1000]),
                          velocity=np.array([1e6, 1.5e6, 2e6]),
                          acceleration=np.array([2.5e3, 3e3, 3.5e3]),
                          name='test_Particle2',
                          restMass=3.0,
                          charge=7.0)


def test_Particle__repr__():
    # checks the repr function works
    assert re.findall("Name: test_Particle",
                      test_Particle.__repr__()) == ["Name: test_Particle"]


def test_RestEnergy():
    # checks that rest energy is calculated correctly
    assert test_Particle.RestEnergy() == pytest.approx(2.6962655362104528e+17)


def test_BetaVelocity():