Hello, i’ve been attempting to calculate the Electrostatic force at the boundaries of a problem, given the electric field at the point, using Maxwell’s tensor in 2D.
Where E is the Electric Field calculated and n s the outer unit normal vector of the surface S. However I haven’t been succesfull. My approach was to calculate the electric potential using Poisson’s equation, which I’ve done successfully, and then take its negative gradient to get the electric field (Proyected into an appropriate space). I’m having trouble operating FacetNormal() in order to perform the integral needed. Here is the code in which I attempt to perform the integrals, failing, due to the following mistake:
epsilon = 1E-12
E = project(-grad(u), VectorFunctionSpace(mesh, 'P', 1)) #Proyección para llegar a un E apropiado, evaluado nodalmente
EX, EY = E.split(deepcopy=True) # extract components
boundary_mesh = BoundaryMesh(mesh, "exterior", True)
n = FacetNormal(boundary_mesh)
T1 = epsilon * assemble(dot(E,n)*E)
T2 = -0.5 * assemble(dot(E**2,n))
The mistake I get is:
TypeError: Invalid form type <class 'ufl_legacy.tensors.ComponentTensor'>
The issue here is that E is a vector, meaning that dot(E,n)*E is a vector. Dolfin only supports assembling of scalar quantities, i.e. you would have to compute
T1 = [epsilon * assemble(dot(E,n)*E[i]) for i in range(mesh.geometry().dim())]
To get a vector result. Similarly, you would have to rewrite T2, as that is also a vector-valued result.
Something I missed in your previous code is that you have not specified an integration domain in:
You would have do use either dx or ds depending on what you are trying to integrate over. Not really sure why you need a boundary mesh in your code, if you are just trying to integrate over the exterior boundary, as n=FacetNormal(mesh) with the ds measure makes more sense to me.