Collocation least squares method library for solving PDE systems.
From source:
pip install git+https://github.com/ANever/cls.git
Dependencies: numpy, matplotlib
- Determine problem parameters
power = 4
params = {
'n_dims': 2,
'dim_sizes': np.array([2, 2]),
'area_lims': np.array([[0,1], [0,1]]),
'power': power,
'basis': Basis(power),
'n_funcs': 2,
}
- Initiate solution
sol = Solution(**params)
- Initiate equations e.g.
colloc_left_operators = [lambda u_loc, u_bas, x, x_loc: (u_bas([1,0],0)-eps*u_bas([0,2],0)
-(u_bas([0,1],0)*u_loc([0,1],1)
+u_bas([0,0],0)*u_loc([0,2],1))
)*colloc_weight,
...
]
colloc_right_operators = [lambda u_loc, u_nei, x, x_loc: (0) * w**2*colloc_weight,
...
]
colloc_ops = [colloc_left_operators, colloc_right_operators]
or with parser:
function_list = ['m', 'v']
variable_list = ['t','x']
from clspde.solution import lp as l
def lp(line, function_list=function_list, variable_list = variable_list):
res = l(line, function_list, variable_list)
return lambda u_loc, u_bas, x, x_loc: eval(res)
colloc_left_operators = [lp('(d/dt) m - eps * (d/dx)^2 m - '+
'( (d/dx) m * (d/dx) &v + (d/dx) &m * (d/dx) v +' +
' m + (d/dx)^2 &v + &m + (d/dx)^2 v )'
),
...
]
...
what is equivalent to
u_loc(derivatives, func_number) - funcitons(x,x_loc), evaluates
IMPORTANT! left operators must be linear combination of u_bas functions!
- Determine collocation points e.g.
connect_points = np.array([[-1, 0.5], [1, 0.5],
[0.5, -1], [0.5, 1],
[-1, -0.5], [1, -0.5],
[-0.5, -1], [-0.5, 1],
[-1, 0], [1, 0],
[0, -1], [0, 1],
])
- Collect all points and equations
points=[colloc_points, connect_points ,border_points]
iteration_dict = {'points':points,
'colloc_ops':colloc_ops,
'border_ops':border_ops,
'connect_ops':connect_ops,
}
- Run solve procedures
generate and solve global system of equations
sol.global_solve(**iteration_dict)
iterate through cells and generate and solve local systems in every cell
sol.solve(**iteration_dict)
- Plot results
For 2d functions
sol.plot2d()
- add various basises (Legandre polynomial, sin, cos, exp)
- add iteration speedup with Galerkin method
- rewrite in C