I have fit an exponential function to some data, and now I want to use this exponential function with T, the solution to my finite element simulation, as an input. However, I am encountering the following error:
File "target-spotsize-fixedP.py", line 47, in exponenial_func return a*exp(-b/x) ufl.log.UFLValueError: Invalid type conversion: [...] can not be converted to any UFL type
However I cannot see where my problem is, is there something wrong with using Project() in this case to output the value of this exponential function across my whole mesh?
Below is my simplified code:
from __future__ import print_function from fenics import * import numpy as np import matplotlib.pyplot as plt from dolfin import * from ufl import as_tensor from ufl import Index import math from scipy.optimize import curve_fit from mpi4py import MPI mesh = UnitSquareMesh(16,16) x = [0.01,10,20,30,40,50,60,80,100,1000,10000] #T range y = [0,0.1,0.36,0.61,0.72,0.78,0.82,0.84,0.87,0.99,0.99999] # y to fit def exponenial_func(x, a, b): return a*np.exp(-b/x) popt1, pcov1 = curve_fit(exponenial_func, x, y ,p0 = [2, 10]) Space = FunctionSpace(mesh,'P', 1) T = project(Expression("x+0.1*x", degree=2), Space) vp_space = FunctionSpace(mesh, 'CG',1) vp_out = Function(vp_space, name = '$T$') vp_ = exponenial_func(T,*popt1) vp_out = project(vp_, vp_space,solver_type='cg')