Beispiel #1
0
 def test_model(self):
     np.testing.assert_array_less(
         SurfaceGuidedMassSystem(
             surface=EllipticParaboloid(1.0, 2.0),
             s0=nprand((4,)),
             solid=1.0,
             forces=[
                 Gravity(1.0, [0, 0, -10.0]),
                 SpringForce(1.0, [0.0, 0.0, 0.0]),
                 ViscousFriction(2.0),
             ],
         ).solve(time=np.linspace(0, 20, 1000))[-1,:],
         1e-5*np.ones((4,))
     )
Beispiel #2
0
from gsurface import Plan, SurfaceGuidedMassSystem, build_s0
from gsurface.forces import CenterDirectedViscousFriction, ConstantDirectedViscousFriction
from gsurface.forces import SpringDampingForce
from gsurface.plotter import mayavi_plot_surfaces, SurfacePlot, Tyi

# simulate a 2D spring damping system, we notice that the radial speed tends to 0 where rotational speed still constant

plan = Plan(a=0.0, c=1.0)
surface = plan.build_surface(*plan.mesh(50, 50))

model = SurfaceGuidedMassSystem(surface=plan,
                                s0=build_s0(u0=0.5, du0=0.0, dv0=5),
                                m=1.0,
                                forces=[
                                    ConstantDirectedViscousFriction(
                                        1.0, np.array([1.0, 0.0, 0.0])),
                                    CenterDirectedViscousFriction(1.0),
                                    SpringDampingForce(100.0, 1.0, None, 1.0)
                                ])

time = np.linspace(0, 10, 3000)

data = model.solve(time)

solutions = model.solutions(data, time)

mayavi_plot_surfaces([SurfacePlot(surface, trajectory=solutions[Tyi])])

from gsurface.serialize import save_attached
Beispiel #3
0
import numpy as np

# model

sphere = Sphere(1.0)

m = 1.0
g = np.array([-1.0, 0.0, 0.0])
k = 1.0
clip = np.array([0.0, 0.0, 1.0])

system = SurfaceGuidedMassSystem(
    surface=sphere,
    s0=np.array([np.pi/2, 1.0, np.pi/2, 0.0]),
    m=m,
    forces=[
        Gravity(m=m, g=g),
        SpringForce(stiffness=k, clip=clip),
        # ViscousFriction(mu=0.2),
    ]
)

# simulate
time = np.linspace(0, 20, 5000)

states = system.solve(time)

# build (todo opti)
mesh = sphere.build_surface(*sphere.mesh(50, 50))

physics = system.solutions(states, time)
# initial values
x0, vx0 = 2.0, 0.0

y0, vy0 = 0.0, 4.0

# model
plan = Plan.from_xz_rotation(angle=0.0).setlims(-2, 2.5, -3.5, 5).multlims(1)

m = 1.0

system = SurfaceGuidedMassSystem(
    surface=plan,
    s0=np.array([x0, vx0, y0, vy0]),
    m=m,
    forces=[
        Gravity(m=m, g=np.array([0.0, 0.0, -9.81])),
        LengthedSpringForce(stiffness=1.0,
                            clip=np.array([0.0, 0.0, 0.0]),
                            l0=1.0),
        ViscousFriction(mu=0.15),  # test for mu=0.2 and 0.8
    ])

# simulation
time = np.linspace(0, 60, 6000)

states = system.solve(time)

physics = system.solutions(states, time)

trajectory = physics[:, Pi]
speed = physics[:, Vi]
Beispiel #5
0
import numpy as np

from gsurface import SurfaceGuidedMassSystem, build_s0
from gsurface.forces import Gravity, SpringForce, ViscousFriction
from gsurface.plotter import mayavi_plot_surfaces, SurfacePlot, Tyi
from gsurface.surface import Cylinder

mass = 1.0  # kg

system = SurfaceGuidedMassSystem(
    surface=Cylinder(R=1.0).setlims(v_ll=-1, v_ul=1),
    solid=mass,
    forces=Gravity(mass, g=np.array([0.0, 0.0, -1.0])) +
    SpringForce(stiffness=1.0, clip=np.array([-0.5, 0.0, 0.0])) +
    ViscousFriction(0.1),
    s0=build_s0(0, 0.5, 0, 0),
)

time = np.linspace(0, 50.0, 1000)

data = system.solve(time)

solutions = system.solutions(data, time)

smesh = system.surface.build_surface(*system.surface.mesh(40, 40))

mayavi_plot_surfaces(
    [SurfacePlot(smesh, showSurface=True, trajectory=solutions[Tyi])])
Beispiel #6
0
from gsurface import Plan, NewtonGravity, SurfaceGuidedMassSystem, Tyi, build_s0, ViscousFriction
from gsurface.plotter import mayavi_plot_surfaces, SurfacePlot, matplotlib_plot_solutions

import numpy as np

# simulate a planet rotating around a fixed massive system

universe_def = Plan(c=1.0).setlims(u_ul=2.5, v_ul=2)
universe = universe_def.build_surface(*universe_def.mesh(50, 50))

model = SurfaceGuidedMassSystem(
    surface=universe_def,
    s0=build_s0(u0=1.0, dv0=0.5, du0=1.0),
    m=1.0,
    forces=[
        NewtonGravity(m=1.0, M=100.0, G=1.0, clip=np.zeros((3, ))),
        # DistanceGravity(m=1.0, M=100.0, G=1.0, clip=np.array([1.0, 0.0, 0.0])),  # 2 mass objects
        # ViscousFriction(0.1)  # friction
    ])

time = np.linspace(0, 20, 3000)

data = model.solve(time)

solutions = model.solutions(data, time)

matplotlib_plot_solutions(time, data, solutions)
mayavi_plot_surfaces([SurfacePlot(universe, trajectory=solutions[Tyi])])
Beispiel #7
0
sphere = Sphere(0.5).multlims(0.5).translate(np.array([1.0, 2.0, 0.0])).rotate(
    Rotation.from_rotvec([0.0, 1.0, 2.0]).as_matrix())
tore = Tore()
cat = Catenoid()

forces = [
    StaticFieldElectroMagneticForce(1.0, np.array([1.0, 2.0, 3.0])),
    SpringForce(),
    ViscousFriction(),
    Gravity(),
    Gravity() + NewtonGravity()
]

model1 = SurfaceGuidedMassSystem(surface=sphere,
                                 forces=forces,
                                 solid=23.0,
                                 s0=build_s0(1.0, 2.0, 3.0, 4.0))

structure = TriangleStructure(23.0, 1.0, 23.0, 4.3)
structure[0, 2].mu = 2.0
structure[0, 1].mu = 3.0
structure[1, 2].mu = 4.0
model2 = SurfaceGuidedStructureSystem(sphere,
                                      structure,
                                      structureForces=forces)

objects = model1

# print(surfaces)
save(filename, objects, 4)
# saveB64(filename + "b64", objects)
Beispiel #8
0
# queue of N solids, attached with a spring

SYSTEMS = 8

stiffness = 10

tore = Tore(0.5, 1.0)
tore_mesh = tore.build_surface(*tore.mesh(50, 50))

# build model
joint_sim = SurfaceGuidedInteractedMassSystems([
    SurfaceGuidedMassSystem(surface=tore,
                            s0=build_s0(0, 2 * j, 0.0, 1 + j),
                            m=1.0,
                            forces=[
                                ViscousFriction(0.2),
                                Gravity(1.0, np.array([0.0, 0.0, -1.0]))
                            ]) for j in range(SYSTEMS)
], {(i, i + 1): SpringInteraction(1.0)
    for i in range(SYSTEMS - 1)})

time = np.linspace(0, 25, 2000)

data = joint_sim.solve(time)

solutions = joint_sim.solutions(data, time)

colors = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 0), (1, 0, 1), (0, 1, 0),
          (0, 1, 1), (1, 1, 1)]
Beispiel #9
0
import numpy as np
from mayavi import mlab

from gsurface import SurfaceGuidedMassSystem, SpringForce, Gravity, \
    ViscousFriction, build_s0
from gsurface.indexes import *
from gsurface.plotter import matplotlib_plot_solutions, mayavi_animate_surface_trajectory
from gsurface.surface import Tore

m = 1.0
system = SurfaceGuidedMassSystem(
    surface=Tore(0.5, 1.0),
    s0=build_s0(u0=0.0, du0=0.5, v0=1.0, dv0=0.0),
    m=m,
    forces=[
        SpringForce(stiffness=5.0, clip=np.array([0.0, 0.0, 0.0])),
        Gravity(m=m, g=np.array([0.0, 0.0, -2.0])),
        # LengthedSpringForce(stiffness=5.0, clip=np.array([1.0, 1.0, 0.0]), l0=1.0),
        ViscousFriction(mu=0.5),
    ])

# simulate
time = np.linspace(0, 10, 5000)

states = system.solve(time)

mesh = system.surface.mesh(100, 100)

smesh = system.surface.build_surface(*mesh)

physics = system.solutions(states, time)
Beispiel #10
0
            dvvz=-u * np.sin(u - v),
        )


surface = NewSurface().multlims(1.5)

surface.check_verbose(20, 20)

from gsurface import SurfaceGuidedMassSystem, Tyi, build_s0
from gsurface.forces import ViscousFriction, SpringForce

model = SurfaceGuidedMassSystem(
    surface=surface,
    s0=build_s0(u0=2.5, du0=-8.0, dv0=5.0),
    m=1.0,
    forces=[
        SpringForce(10.0),
        ViscousFriction(1.0)
    ]
)

from gsurface.plotter import mayavi_plot_surfaces, SurfacePlot

surface = NewSurface()

surface_mesh = surface.build_surface(*surface.mesh(50, 50))

time = np.linspace(0, 10, 1000)

data = model.solve(time)