Exemplo n.º 1
0
def run_example():

    def residual(t,y,yd):

        res_0 = yd[0]-y[2]
        res_1 = yd[1]-y[3]
        res_2 = yd[2]+y[4]*y[0]
        res_3 = yd[3]+y[4]*y[1]+9.82
        res_4 = y[2]**2+y[3]**2-y[4]*(y[0]**2+y[1]**2)-y[1]*9.82

        return np.array([res_0,res_1,res_2,res_3,res_4])
    
    #The initial conditons
    t0  = 0.0 #Initial time
    y0  = [1.0, 0.0, 0.0, 0.0, 0.0] #Initial conditions
    yd0 = [0.0, 0.0, 0.0, -9.82, 0.0] #Initial conditions
    print (residual(t0,y0,yd0))

    model = Implicit_Problem(residual, y0, yd0, t0)             #Create an Assimulo problem
    model.name = 'Pendulum'        #Specifies the name of problem (optional)

    sim = IDA(model) #Create the IDA solver
        
    tfinal = 10.0        #Specify the final time
    ncp = 500            #Number of communcation points (number of return points)

    t,y,yd = sim.simulate(tfinal, ncp) #Use the .simulate method to simulate and provide the final time and ncp (optional)
    
    sim.plot()
Exemplo n.º 2
0
 def solve_squeezer(self):
     model = Implicit_Problem(self.squeezer_func, self.y, self.yp, self.t)
     sim = IDA(model)
     tfinal = 10.0
     ncp = 1000
     sim.atol = 1.0e-6
     sim.suppress_alg = True
     for i in range(sim.algvar.size):
         if i > 14:
             sim.algvar[i] = 0
     print(sim.algvar)
     t, y, yd = sim.simulate(tfinal, ncp)
     sim.plot()
Exemplo n.º 3
0
def run_example(index="ind1", with_plots=True, with_test=False):
    my_pend_sys = pendulum()
    my_pend = my_pend_sys.generate_problem(index)
    my_pend.name = 'Index = {}'.format(index)
    dae_pend = IDA(my_pend) if index not in ('ovstab2',
                                             'ovstab1') else ODASSL(my_pend)
    dae_pend.atol = 1.e-6
    dae_pend.rtol = 1.e-6
    dae_pend.suppress_alg = True
    t, y, yd = dae_pend.simulate(10., 100)
    final_residual = my_pend.res(0., dae_pend.y, dae_pend.yd)

    print(my_pend.name + "  Residuals after the integration run\n")
    print(final_residual, 'Norm:  ', sl.norm(final_residual))

    if with_test:
        assert (sl.norm(final_residual) < 1.5e-1)
    if with_plots:
        dae_pend.plot(mask=[1, 1] + (len(my_pend.y0) - 2) * [0])
    return my_pend, dae_pend
Exemplo n.º 4
0
# -*- coding: utf-8 -*-
from  __future__  import division
from  scipy       import *
from  matplotlib.pyplot import *
import numpy as np

from assimulo.problem import Implicit_Problem
from assimulo.solvers import IDA
import squeezer

y0,yp0=squeezer.init_squeezer() # Initial values
t0 = 0 # Initial time

squeezemodel = Implicit_Problem(squeezer.squeezer, y0, yp0, t0)

algvar = 7*[1.]+13*[0.]
sim = IDA(squeezemodel) # Create solver instance
sim.algvar = algvar
sim.suppress_alg=True
sim.atol = 1e-7
tf = .03 # End time for simulation

t, y, yd = sim.simulate(tf)

sim.plot(mask=7*[1]+13*[0])
grid(1)
axis([0, .03, -1.5, 1.5])
xlabel('Time, t [s]')
ylabel('Angle, [rad]')
Exemplo n.º 5
0
    resid13 = (x1 * du[6] + x1_dot**2) + (y1 * du[7] + y1_dot**2) - du[8]
    resid14 = (x1 * du[9] + x1_dot**2) + (y1 * du[10] + y1_dot**2) - du[11]
    resid15 = (x1 - x2) * (du[6] - du[9]) + (x1_dot - x2_dot) * (x1_dot -
                                                                 x2_dot)
    resid16 = (y1 - y2) * (du[7] - du[10]) + (y1_dot - y2_dot) * (y1_dot -
                                                                  y2_dot)
    resid17 = (z1 - z2) * (du[8] - du[11]) + (z1_dot - z2_dot) * (z1_dot -
                                                                  z2_dot)

    return np.array([
        resid1, resid2, resid3, resid4, resid5, resid6, resid7, resid8, resid9,
        resid10, resid11, resid12, resid13, resid14, resid15, resid16, resid17
    ])


#initial conditions
t0 = 0.0
u0 = [1.0, 1.0, 1.0, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0, 0, 0]
du0 = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0, 0, 0]

model = Implicit_Problem(residual, u0, du0, t0)
model.name = 'masses linked on surface'

sim = IDA(model)
tfinal = 10.0  #Specify the final time
ncp = 500  #Number of communication points (number of return points)

t, y, yd = sim.simulate(tfinal, ncp)
sim.plot()