Ejemplo n.º 1
0
 def test_add_same_name_subspaces(self):
     mars = self.solar_system.elements['Mars']
     count = 105
     for i in range(count):
         phobos = Space('Phobos')
         mars.add_element(phobos)
     self.assertEqual(phobos.name, 'Phobos %d' % (count - 1))
Ejemplo n.º 2
0
class TestSpace(unittest.TestCase):
    def setUp(self):
        self.solar_system = Space('Solar System')
        mercury = Space('Mercury')
        venus = Space('Venus')
        earth = Space('Earth')
        mars = Space('Mars')
        self.solar_system.add_element(mercury)
        self.solar_system.add_element(venus)
        self.solar_system.add_element(earth)
        self.solar_system.add_element(mars)

    def space_constructor(self):
        self.assertRaises(ValueError, Space, 'xxx', '0')

    def test_add_remove_subspaces(self):
        self.assertFalse(self.solar_system.add_element(self.solar_system))
        self.assertRaises(TypeError, self.solar_system.add_element,
                          'Any object except BDSpace')
        earth = self.solar_system.elements['Earth']
        moon = Space('Moon')
        earth.add_element(moon)
        lunohod = Space('Lunohod')
        moon.add_element(lunohod)
        mars = self.solar_system.elements['Mars']
        phobos = Space('Phobos')
        deimos = Space('Deimos')
        mars.add_element(phobos)
        mars.add_element(deimos)
        self.assertFalse(self.solar_system.add_element(lunohod))
        self.assertRaises(TypeError, self.solar_system.remove_element,
                          'Any object, not BDSpace')

    def test_add_same_name_subspaces(self):
        mars = self.solar_system.elements['Mars']
        count = 105
        for i in range(count):
            phobos = Space('Phobos')
            mars.add_element(phobos)
        self.assertEqual(phobos.name, 'Phobos %d' % (count - 1))

    def test_basis_in_global_coordinates(self):
        print('Basis in GCS:',
              self.solar_system.basis_in_global_coordinate_system())
Ejemplo n.º 3
0
 def setUp(self):
     self.solar_system = Space('Solar System')
     mercury = Space('Mercury')
     venus = Space('Venus')
     earth = Space('Earth')
     mars = Space('Mars')
     self.solar_system.add_element(mercury)
     self.solar_system.add_element(venus)
     self.solar_system.add_element(earth)
     self.solar_system.add_element(mars)
Ejemplo n.º 4
0
 def test_add_remove_subspaces(self):
     self.assertFalse(self.solar_system.add_element(self.solar_system))
     self.assertRaises(TypeError, self.solar_system.add_element,
                       'Any object except BDSpace')
     earth = self.solar_system.elements['Earth']
     moon = Space('Moon')
     earth.add_element(moon)
     lunohod = Space('Lunohod')
     moon.add_element(lunohod)
     mars = self.solar_system.elements['Mars']
     phobos = Space('Phobos')
     deimos = Space('Deimos')
     mars.add_element(phobos)
     mars.add_element(deimos)
     self.assertFalse(self.solar_system.add_element(lunohod))
     self.assertRaises(TypeError, self.solar_system.remove_element,
                       'Any object, not BDSpace')
Ejemplo n.º 5
0
import numpy as np

from BDSpace import Space
from BDSpace.Figure.Sphere import Sphere
from BDSpace.Field import HyperbolicPotentialSphericalConservativeField, SuperposedField

import BDSpaceVis as Visual

from mayavi import mlab

space = Space('Two charged balls')
pos_ball_position = np.array([5.0, 5.0, 0.0], dtype=np.double)
neg_ball_position = np.array([1.0, 1.0, 0.0], dtype=np.double)

pos_ball_charge = 5.0
pos_ball_radius = 1.0
pos_charged_ball = Sphere(name='Pos Charged Ball', r_outer=pos_ball_radius)
pos_charged_ball.coordinate_system.origin = pos_ball_position

neg_ball_charge = -5.0
neg_ball_radius = 1.0
neg_charged_ball = Sphere(name='Neg Charged Ball', r_outer=neg_ball_radius)
neg_charged_ball.coordinate_system.origin = neg_ball_position

space.add_element(pos_charged_ball)
space.add_element(neg_charged_ball)

pos_electrostatic_field = HyperbolicPotentialSphericalConservativeField(name='Pos Charged ball field',
                                                                        field_type='electrostatic',
                                                                        a=pos_ball_charge, r=pos_ball_radius)
pos_charged_ball.add_element(pos_electrostatic_field)
Ejemplo n.º 6
0
import numpy as np

from BDSpace.Coordinates import Cartesian
from BDSpace import Space
from BDSpace.Curve.Parametric import Helix
from BDSpace.Field import HyperbolicPotentialCurveConservativeField

import BDSpaceVis as Visual
from mayavi import mlab

space = Space('Charged helix')
coordinate_system = Cartesian()
coordinate_system.rotate_axis_angle(np.ones(3, dtype=np.double),
                                    np.deg2rad(45))
coordinate_system.origin = np.array([0.0, 0.0, 0.0]) - 2.0

left_helix = Helix(name='Left Helix',
                   coordinate_system=coordinate_system,
                   radius=5,
                   pitch=5,
                   start=0,
                   stop=np.pi * 2,
                   right=False)
helix_r = 1.5
print('Helix length:', left_helix.length())
pos_electrostatic_field = HyperbolicPotentialCurveConservativeField(
    name='Pos Charged Helix field',
    field_type='electrostatic',
    curve=left_helix,
    r=helix_r)
pos_electrostatic_field.a = 1.0
Ejemplo n.º 7
0
from BDSpace import Space

solar_system = Space('Solar System')
mercury = Space('Mercury')
venus = Space('Venus')
earth = Space('Earth')
mars = Space('Mars')

solar_system.add_element(mercury)
solar_system.add_element(venus)
solar_system.add_element(earth)
solar_system.add_element(mars)

moon = Space('Moon')
earth.add_element(moon)
lunohod = Space('Lunohod')
moon.add_element(lunohod)

phobos = Space('Phobos')
phobos2 = Space('Phobos')
phobos3 = Space('Phobos')
deimos = Space('Deimos')
mars.add_element(phobos)
mars.add_element(phobos2)
mars.add_element(phobos3)
mars.add_element(deimos)

phobos.detach_from_parent()
earth.add_element(phobos)
phobos.detach_from_parent()
mars.add_element(phobos)