Beispiel #1
0
def test_convert_tangent_euclidean_to_stereo():
    solver = kmap.Solver()
    n_steps = 10
    s3_map = map_sens.Sensitivity(solver, n_steps)
    n_runup = 10
    u_init = solver.u_init
    s0 = solver.s0
    u_init = solver.primal_step(u_init, s0, n_runup)
    u_trj = s3_map.solve_primal(solver,\
               u_init, n_steps, solver.s0)
    u_trj = u_trj.T
    q = rand(2, n_steps)
    q[0] = 0.
    q[1] = 1.

    q_euclidean = solver.convert_tangent_stereo_to_euclidean(u_trj, q)
    q_euclidean = vstack(q_euclidean)
    q_spherical = solver.convert_tangent_euclidean_to_spherical(u_trj,\
                   q_euclidean)
    q_spherical = vstack(q_spherical)
    p_euclidean = solver.convert_tangent_spherical_to_euclidean(
        u_trj, q_spherical)
    p_euclidean = vstack(p_euclidean)
    p_stereo = solver.convert_tangent_euclidean_to_stereo(u_trj, p_euclidean)
    p_stereo = vstack(p_stereo)
    print(p_stereo)
    assert (norm(p_stereo - q) < 1.e-10)
    return
Beispiel #2
0
def test_step_primal():
    holes = array([1./sqrt(2.),0,1./sqrt(2.0),\
                   -1./sqrt(2.),0,1./sqrt(2.0), \
                    1./sqrt(2.),0,-1./sqrt(2.0), \
                    -1./sqrt(2.),0,-1./sqrt(2.0)])
    holes = holes.reshape(4, 3)
    solver_map = kmap.Solver()
    u_init = solver_map.u_init
    n_map = solver_map.n_poincare
    n_steps = 500
    s0 = solver_map.s0
    sens_object = map_sens.Sensitivity()
    solve_primal = sens_object.solve_primal
    u = solve_primal(solver_map,\
            u_init,n_steps,s0)
    flag = 1
    epsi = 1.e-1
    for i in range(1, n_steps):
        if (not (flag)):
            break
        for j in range(holes.shape[0]):
            if (norm(u[i, :3] - holes[j]) < epsi):
                flag = 0
            if (norm(u[i, :3]) > 1.0 + epsi):
                flag = 0
    assert (i == n_steps - 1)
Beispiel #3
0
def visualize_poincare_primal():
    solver_map = kmap.Solver()
    u_init = solver_map.u_init
    n_steps = 500
    s0 = solver_map.s0
    sens_object = map_sens.Sensitivity()
    solve_primal = sens_object.solve_primal
    u_map = solve_primal(solver_map,\
            u_init,n_steps,s0)
    stereo_real, stereo_imag = \
        solver_map.stereographic_projection(u_map.T)
    figure()
    plot(stereo_real, stereo_imag, '.')
    savefig('st_proj_poincare_attractor.png')
Beispiel #4
0
def visualize_tangent_stereographic(u, v, c1="black"):
    EPS = 1E-8
    u_plus, u_minus = u + v * EPS, u - v * EPS
    stereographic_projection = kmap.Solver().stereographic_projection
    stereo_real, stereo_imag = stereographic_projection(u.T)
    stereo_real_plus, stereo_imag_plus = stereographic_projection(u_plus.T)
    stereo_real_minus, stereo_imag_minus = stereographic_projection(u_minus.T)
    stereo_real_plus = extrapolate(stereo_real, stereo_real_plus, 1E6)
    stereo_real_minus = extrapolate(stereo_real, stereo_real_minus, 1E6)
    stereo_imag_plus = extrapolate(stereo_imag, stereo_imag_plus, 1E6)
    stereo_imag_minus = extrapolate(stereo_imag, stereo_imag_minus, 1E6)
    plot([stereo_real_plus, stereo_real_minus],
         [stereo_imag_plus, stereo_imag_minus],
         color=c1,
         ms=10)
Beispiel #5
0
def visualize_unstable_direction():
    solver_map = kmap.Solver()
    u_init = solver_map.u_init
    n_map = solver_map.n_poincare
    n_steps = 500
    s0 = solver_map.s0
    sens_object = map_sens.Sensitivity()
    solve_primal = sens_object.solve_primal
    u_map = solve_primal(solver_map,\
            u_init,n_steps,s0)
    solve_unstable_direction = sens_object.\
            solve_unstable_direction
    v = solve_unstable_direction(solver_map,\
        u_map, rand(solver_map.state_dim),n_steps,\
        s0)
    visualize_tangent_stereographic(u_map,\
            v)
Beispiel #6
0
def test_convert_tangent_euclidean_to_spherical():
    solver = kmap.Solver()
    n_steps = 10
    s3_map = map_sens.Sensitivity(solver, n_steps)
    n_runup = 10
    u_init = solver.u_init
    s0 = solver.s0
    u_init = solver.primal_step(u_init, s0, n_runup)
    u_trj = s3_map.solve_primal(solver,\
               u_init, n_steps, solver.s0)
    q = rand(2, n_steps)
    q_euclidean = solver.convert_tangent_spherical_to_euclidean(u_trj.T, q)
    q_euclidean = vstack(q_euclidean)
    q_spherical = solver.convert_tangent_euclidean_to_spherical(u_trj.T,\
                   q_euclidean)
    assert (norm(q - q_spherical) < 1.e-10)
    return
Beispiel #7
0
def test_convert_tangent_stereo_to_euclidean():
    solver = kmap.Solver()
    n_steps = 10
    s3_map = map_sens.Sensitivity(solver, n_steps)
    n_runup = 10
    u_init = solver.u_init
    s0 = solver.s0
    u_init = solver.primal_step(u_init, s0, n_runup)
    u_trj = s3_map.solve_primal(solver,\
               u_init, n_steps, solver.s0)
    p1 = solver.convert_tangent_stereo_to_euclidean(u_trj.T,\
               vstack((ones(n_steps),zeros(n_steps))))
    p2 =  solver.convert_tangent_stereo_to_euclidean(u_trj.T,\
               vstack((zeros(n_steps),ones(n_steps))))
    p1 = vstack(p1)
    p2 = vstack(p2)
    dot_product_p1_p2 = sum(p1 * p2, axis=0)
    print(norm(dot_product_p1_p2))
    assert (norm(dot_product_p1_p2) <= 1.e-10)
    return
Beispiel #8
0
def test_convert_tangent_spherical_to_euclidean():
    solver = kmap.Solver()
    n_steps = 10
    s3_map = map_sens.Sensitivity(solver, n_steps)
    n_runup = 10
    u_init = solver.u_init
    s0 = solver.s0
    u_init = solver.primal_step(u_init, s0, n_runup)
    u_trj = s3_map.solve_primal(solver,\
               u_init, n_steps, solver.s0)
    q1 = solver.convert_tangent_spherical_to_euclidean(u_trj.T,\
               vstack((ones(n_steps),zeros(n_steps))))
    q2 = solver.convert_tangent_spherical_to_euclidean(u_trj.T,\
               vstack((zeros(n_steps),ones(n_steps))))
    q1 = array(q1)
    q2 = array(q2)
    dot_product_q1_q2 = sum(q1 * q2, axis=0)
    print(norm(dot_product_q1_q2))
    assert (norm(dot_product_q1_q2) <= 1.e-10)
    return
import sys
sys.path.insert(0, '../examples/')
import kuznetsov_poincare as kmap
import kuznetsov as kode
import map_sens as map_sens
import flow_sens as flow_sens
from time import clock
if __name__ == "__main__":
    solver_ode = kode.Solver()
    solver_map = kmap.Solver()
    n_map = solver_ode.n_poincare
    n_steps_map = 50
    n_steps = n_map * n_steps_map
    plykin = flow_sens.Sensitivity(solver_ode, n_steps)
    t0 = clock()
    u_ode = plykin.solve_primal(solver_ode,solver_ode.u_init,\
            n_steps,
            solver_ode.s0)
    t1 = clock()
    print('{:<60s}{:>16.10f}'.format(\
            "Time to solve primal: ",\
        t1-t0))

    t2 = clock()
    plykin.precompute_sources(solver_ode, u_ode)
    t3 = clock()
    print('{:<60s}{:>16.10f}'.format(\
            "Time for flow precomputations: ",\
        t3-t2))

    poincare_plykin = map_sens.Sensitivity(solver_map, n_steps_map)
import sys
sys.path.insert(0, '../examples/')
import kuznetsov_poincare as kp
from objective import *
import scipy
from scipy.interpolate import griddata
import alt_map_sens as map_sens
from time import clock
from pylab import *
from mpl_toolkits.mplot3d import Axes3D

#def compute_sensitivity():
if __name__ == "__main__":
    solver = kp.Solver()
    n_steps = 5
    s3_map = map_sens.Sensitivity(solver,n_steps)
    n_runup = s3_map.n_runup
    n_runup_forward_adjoint = 10

    u_init = solver.u_init
    s0 = solver.s0
    state_dim = solver.state_dim
    param_dim = s0.size
    u_init = solver.primal_step(u_init, s0, n_runup)
    u_trj = s3_map.solve_primal(solver,\
            u_init, n_steps, solver.s0)
    ds0 = zeros(param_dim)
    ds1 = copy(ds0)
    ds1[0] = 1.0
    dJ0 = zeros(state_dim)
    detJac = s3_map.compute_jacobian_determinant(solver,\