I need to solve following equation
\frac{\partial \left( y \times f^{-1}(y) \right) }{\partial y} = 0 , where function f(x) is a complicated nonlinear function. One of the terms inside function f(x) is imaginary error function. So, it is not possible to determine inverse function analytically. I have used “Pynverse” to find inverse numerically. Now, when I try to define my equilibrium equation I am getting error “ValueError: setting an array element with a sequence.”
I guess I should some how change the format of finv(x) to a format readable for fenics but I do not know how. Anyone know how I can solve this problem?
Here is my code
from dolfin import *
import numpy as np
from pynverse import inversefunc #will be used to find inverse func
from scipy import special # will be use to encode imaginary error function
mesh = RectangleMesh(Point(0,0),Point(1,1),20, 20)
V = FunctionSpace(mesh,'CG', 1)
y_test = TestFunction(V)
y = Function(V)
# Calculating function f
def f(x):
return -1/2 - 1/(2*x) + (np.exp((3*x)/2)*np.sqrt(3/(2*np.pi)))/(np.sqrt(x)*special.erfi(np.sqrt(3/2)*np.sqrt(x)));
# Calculating Inverse of f
def finv(x):
InverseArray = inversefunc(f,domain=[0.0001,500],open_domain=[True,True])
return float(InverseArray(x))
# Energy functional
Psi = y*finv(y) #this is where I am getting error
# Equilibriuim equation
Func = derivative(Psi, y, y_test)
# initial guess
y.assign(Constant(0.5))
solve(Func == 0, up, bcs,form_compiler_parameters=ffc_options,solver_parameters={"newton_solver":{"relaxation_parameter":0.1,"relative_tolerance":1e-6 ,"maximum_iterations":200,} })#form_compiler_parameters=ffc_options)