Пример #1
0
from gsurface.surface import Tore, Plan, Sphere
from gsurface.model import SurfaceGuidedMassSystem
from gsurface.forces import SpringForce, ViscousFriction, Gravity

from scipy.integrate import odeint

from time import time

import numpy as np

tore = Tore(0.5, 1.0)

model = SurfaceGuidedMassSystem(surface=tore,
                                s0=np.array([1.0, 1.0, 1.0, 1.0]),
                                m=1.0,
                                forces=[
                                    SpringForce(1.0, np.array([0.0, 0.0,
                                                               0.0])),
                                    ViscousFriction(0.01),
                                    Gravity(1.0, np.array([0.0, 0.0, -1.0]))
                                ])

T = np.linspace(0, 100, 100000)

begin = time()
data = model.solve(T, solver=odeint)
end = time()

delta = end - begin

print(f"Time : {delta:.3f} s")
Пример #2
0
from scipy.spatial.transform import Rotation

from gsurface import SurfaceGuidedMassSystem, build_s0
from gsurface.advanced.structure import TriangleStructure, SurfaceGuidedStructureSystem
from gsurface.forces import StaticFieldElectroMagneticForce, SpringForce, ViscousFriction, Gravity, NewtonGravity
from gsurface.serialize import save, load
from gsurface.surface import Plan, Tore, Sphere, Catenoid

filename = "../_tmp/serialized_plan.txt"

plan = Plan(1, 2, 3, 1)
plan.translate(np.array([1.0, 2.0, 0.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))
Пример #3
0
import numpy as np

from gsurface.forces import Gravity, ViscousFriction, SpringForce, LengthedSpringForce
from gsurface.model import SurfaceGuidedMassSystem, build_s0
from gsurface.advanced.structure import SurfaceGuidedStructureSystem, TriangleStructure, BowStructure, CarStructure, SnakeStructure
from gsurface.surface import Sphere, Tore

# setup simulation for tore
tore = Tore(r=0.5, R=1.0).translate(np.array([3.0, 0.0, 0.0]))

tore_sim = SurfaceGuidedMassSystem(
    surface=tore,
    s0=build_s0(du0=10.0),
    m=1.0,
    forces=[Gravity(1.0, np.array([0.0, 0.0, -9.0])),
            ViscousFriction(0.5)])

# setup simulation for sphere
sphere = Sphere(1.0)

sphere_sim = SurfaceGuidedMassSystem(
    surface=sphere,
    s0=build_s0(u0=1.5, du0=10.0, v0=1.5),
    m=1.0,
    forces=[Gravity(1.0, np.array([0.0, 0.0, 9.0])),
            ViscousFriction(0.5)])

tore_sim2 = SurfaceGuidedMassSystem(
    surface=Tore(0.5, 1.0),
    s0=build_s0(u0=0.0, du0=0.5, v0=1.0, dv0=0.0),
    m=1.0,
Пример #4
0
from gsurface.surface import Tore, EggBox
from gsurface.forces import SpringInteraction, Gravity, ViscousFriction
from gsurface.plotter import mayavi_plot_surfaces, matplotlib_plot_solutions, SurfacePlot
from gsurface import SurfaceGuidedInteractedMassSystems, SurfaceGuidedMassSystem, Tyi, build_s0

import numpy as np

# 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)
Пример #5
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)
Пример #6
0
import numpy as np

from gsurface import Tyi
from gsurface.advanced.structure import BowStructure, SurfaceGuidedStructureSystem
from gsurface.forces import ViscousFriction
from gsurface.plotter import mayavi_plot_surfaces, SurfacePlot
from gsurface.plotter.colors import rgb
from gsurface.surface import Tore

from gsurface.serialize import save_attached

from gsurface.tools import nprand

SIZE = 5

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

snake = BowStructure(SIZE, 1.0, stiffness=1000.0, mu=10.0, l0=1.0)

snake.interactions[(0, SIZE - 1)].stiffness = 100.0

sim = SurfaceGuidedStructureSystem(surface, snake, s0=nprand(4*SIZE), structureForces=[
    ViscousFriction(0.01)
])

sim.s0[1::4] = 1.0

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

data = sim.solve(time)
Пример #7
0
import time as timelib

from gsurface.forces import Gravity, ViscousFriction
from gsurface.forces.interaction import OneSideSpringInteraction
from gsurface.imodel import *
from gsurface.indexes import Tyi
from gsurface.model import build_s0
from gsurface.plotter.mayavi import mlab, mayavi_plot_surfaces, SurfacePlot
from gsurface.surface import Sphere, Tore, Plan

# objects
sphere = Sphere(0.8).translate(np.array([0.0, 0.0, 0.0]))
mesh_sphere = sphere.build_surface(*sphere.mesh(50, 50))

tore = Tore(r=0.5, R=2.0).translate(np.array([0.0, 0.0, 0.0]))
mesh_tore = tore.build_surface(*tore.mesh(50, 50))

plan_shift = np.array([0.0, 0.0, -1.0])
plan = Plan.from_xz_rotation(np.pi / 2 * 0.1).translate(plan_shift).setlims(
    v_ll=-4, v_ul=4, u_ll=-4, u_ul=4)
mesh_plan = plan.build_surface(*plan.mesh(50, 50))

gravity_vector = np.array([0.0, 0.0, -10.0])

tore_sim = SurfaceGuidedMassSystem(surface=tore,
                                   s0=build_s0(v0=np.pi / 2, du0=3.0),
                                   m=1.0)

sphere_sim = SurfaceGuidedMassSystem(
    surface=sphere,
    s0=build_s0(v0=np.pi / 2, dv0=2),
Пример #8
0
import numpy as np
from scipy.spatial.transform import Rotation

from gsurface.surface.transformations import RotTransformationStrategy, ShiftTransformationStrategy, NoTransformationStrategy, RotShiftTransformationStrategy
from gsurface.surface import Tore

tore = Tore(0.25, 1.0)

S, J, H = tore.eval(np.pi / 4, np.pi / 4)

M = Rotation.from_rotvec([1, 2, 3]).as_matrix()

transf = RotTransformationStrategy(M)

rS, rJ, rH = transf.apply(S, J, H)

print(S, rS)
print(J, rJ)
print(H, rH)