Пример #1
0
    def __apply_tension(self):
        """Inspiration from:
        U{http://www.ee.ucl.ac.uk/~rjames/modelling/constant-order/oned/}."""

        try:
            from scikits.bvp1lg import colnew
        except ImportError:
            warning("bvp module not found.")
            raise

        boundary_points = numpy.array([0, 0, 0, 1, 1, 1])
        tol = 1e-6 * numpy.ones_like(boundary_points)
        degrees = numpy.array([2, 2, 2])

        solution = colnew.solve(boundary_points,
                                degrees,
                                self.__ode_3k,
                                self.__bc_nosplay,
                                is_linear=False,
                                initial_guess=self.__ic_nosplay,
                                tolerances=tol,
                                vectorized=True,
                                maximum_mesh_size=1000)

        self.bvp_solution = solution
Пример #2
0
    def __apply_tension(self):
        """Inspiration from:
        U{http://www.ee.ucl.ac.uk/~rjames/modelling/constant-order/oned/}."""

        try:
            from scikits.bvp1lg import colnew
        except ImportError:
            warning("bvp module not found.")
            raise

        boundary_points = numpy.array([0, 0, 0, 1, 1, 1])
        tol = 1e-6 * numpy.ones_like(boundary_points)
        degrees = numpy.array([2, 2, 2])

        solution = colnew.solve(
            boundary_points, degrees, self.__ode_3k, self.__bc_nosplay,
            is_linear=False, initial_guess=self.__ic_nosplay,
            tolerances=tol, vectorized=True,
            maximum_mesh_size=1000)

        self.bvp_solution = solution
Пример #3
0
    return z, fsub(t,z)
    

# Initial guess for the solution
N = 5
degrees = [1, 1, 1]
boundary_points = [0, S, T]
#tin = [0, .4, .8, 1.5, T]
tin = np.linspace(0, T, N)

# solve the boundary value problem
tol = [1e-5, 1e-5, 1e-5]
solution = colnew.solve(
    boundary_points, degrees, fsub, gsub,
    dfsub=dfsub, dgsub=dgsub,
    is_linear=False, tolerances=tol, initial_guess=guess,
    #extra_fixed_points=[0.800],
    collocation_points=3, initial_mesh=tin,
    vectorized=True, maximum_mesh_size=50, verbosity=2)

print ('grid used within colnew')
tc = solution.mesh
n = solution.nmesh
print (n)
print (tc)
# refine the grid (doubling)
t = np.zeros(2*n-1)
for i in range(n-1):
    t[2*i] = tc[i]
    t[2*i+1] = .5*(tc[i]+tc[i+1])
t[-1] = tc[-1]
Пример #4
0
# Initial guess for the solution
N = 5
degrees = [1, 1]
boundary_points = [0, 1]
tin = np.linspace(0, 1, N)

# solve the boundary value problem
tol = [1e-5, 1e-5]
solution = colnew.solve(boundary_points,
                        degrees,
                        fsub,
                        gsub,
                        dfsub=None,
                        dgsub=None,
                        is_linear=False,
                        tolerances=tol,
                        initial_guess=None,
                        collocation_points=3,
                        initial_mesh=tin,
                        vectorized=True,
                        maximum_mesh_size=30,
                        verbosity=0)

t = solution.mesh
x = solution(t)[:, 0]
p = solution(t)[:, 1]

# Calculate u(t) from x,p
u = x - p / 2.
# Calculate the cost
w = (u - x)**2
Пример #5
0
    j = -2*x
    z = np.array([x,p,q1,q2,j])
    return z, fsub(t,z)
    

# Initial guess for the solution
N = 10
degrees = [1, 1, 1, 1, 1]
boundary_points = [0, 0, S[0], S[1], T] 
tin = [0., 0.2, 0.4, S[0], 0.5, S[1], 1.4, T] 

# solve the boundary value problem
tol = [1e-6, 1e-6, 1e-5, 1e-5, 0] # change
solution = colnew.solve(
    boundary_points, degrees, fsub, gsub,
    dfsub=None, dgsub=dgsub,
    is_linear=False, tolerances=tol, initial_guess=guess,
    collocation_points = 5, initial_mesh=tin, adaptive_mesh_selection=True,
    vectorized=False, maximum_mesh_size=50, verbosity=2)

print ('grid used within colnew')
tc = solution.mesh
n = solution.nmesh
print (n)
print (tc)

# refine the grid (doubling)
t = np.zeros(2*n-1)
for i in range(n-1):
    t[2*i] = tc[i]
    t[2*i+1] = .5*(tc[i]+tc[i+1])
t[-1] = tc[-1]
Пример #6
0
boundary_points = np.array([0,np.pi])
tol=1.0e-8*np.ones_like(boundary_points)

def fsub(x,Z):
    """The equations"""
    u,du=Z
    return np.array([-u])

def gsub(Z):
    """The boundary conditions"""
    u,du=Z
    return np.array([u[0]-0.0,du[1]-1])

solution=colnew.solve(
    boundary_points,degrees,fsub,gsub,
    is_linear=True,tolerances=tol,
    vectorized=True,
    maximum_mesh_size=300
    )



plt.ion()

x=solution.mesh

u_exact=-np.sin(x)

plt.plot(x,solution(x)[:,0],'b.')
plt.plot(x,u_exact,'g-')

plt.show()