A repository with a Python implementation of Orthogonal Collocation by Villadsen and Stewart (1967) for solving second order boundary value problems with symmetry.
See two simple examples and a real world problem in the notebook example_collocation.
As it is a very short package, we have not made it available via PyPi. So the user must either clone the repository using git (see code below) or download the files and use in a corresponding directory.
pip install git+https://github.com/bruscalia/collocation
Consider the following system:
First, import the necessary modules to solve it.
import numpy as np
from collocation import OrthogonalCollocation
The user must define a function that returns zeros in internal points and another that returns zeros in the surface boundary.
# Internal function
def fun(x, y, dy, d2y, k):
return np.array([d2y[0] + k1 * y[1] + 1, d2y[1] + k2 * np.log(1 + y[0])])
# Boundary function
def bc(x, y, dy, d2y, k):
return np.array([y[0], y[1] - 1])
k1 = 1.0
k2 = -1.0
Then must instantiate a problem using the OrthogonalCollocation class, define initial estimations and collocate points. The points are available in the y property of the problem and the method interpolate might provide values given x coordinates.
# Create problem
problem = OrthogonalCollocation(fun, bc, 6, 1, x0=0.0, x1=1.0, vectorized=True)
# Initial estimation
y0 = np.zeros([2, n_points + 1])
# Collocation using scipy.optimize.root in backend
problem.collocate(y0, args=(k1, k2), method="hybr", tol=1e-6)
This was developed as a part of the modeling in the styrene reactor simulation project:
The code is uploaded on ResearchGate and can be cited linked to doi:10.13140/RG.2.2.17223.78240.
Villadsen, J. & Stewart, W. E., 1967. Solution of boundary-value problems by orthogonal collocation. Chem. Eng. Sci., 22(11), pp. 1483-1501.
e-mail: bruscalia12@gmail.com