Hello all!
I am attempting to model the Laplacian of electric potential across a solid electrolyte, with an equation that is just the Laplacian of phi = 0. I have implemented this in two dimensions (4x2 rectangle), but I am struggling to create a 3D mesh that will accept the domain of a 4x2x2 box. How can I create this 3D mesh? Also, when I would be ‘solving’ the equation, would it be solving for just the faces of the box or actually within the box itself (which is what I want)?
Here is my current code implementation of the 2D Laplacian.
from fenics import *
from mshr import *
import numpy as np
# Create mesh and define function space
domain = Rectangle(Point(0, 0), Point(4, 2))
mesh = generate_mesh(domain, 64) # The higher the value the more resolved the mesh is
V = FunctionSpace(mesh, 'P', 1) # 1st order FEM
# Define boundaries
boundary_markers = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
boundary_markers.set_all(0)
# Neumann conditions are already 0 if I don't include them, they should be 0 for my problem.
Voltage = 1.0 # Applied voltage
# Dirichlet conditions
phi_anode = Constant(0.0) # Potential at the anode, which can be set to zero
phi_cathode = Constant(Voltage) # Potential at the cathode, where Voltage is the applied voltage
# Apply Dirichlet conditions at the left and right boundaries of the domain
boundaries = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
left_boundary = CompiledSubDomain('near(x[0], 0)')
right_boundary = CompiledSubDomain('near(x[0], 4)')
left_boundary.mark(boundaries, 1)
right_boundary.mark(boundaries, 2)
bc_anode = DirichletBC(V, phi_anode, boundaries, 1)
bc_cathode = DirichletBC(V, phi_cathode, boundaries, 2)
bcs = [bc_anode, bc_cathode] # List of Dirichlet boundary conditions
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
a = dot(grad(u), grad(v))*dx
L = Constant(0.0)*v*dx # Since the right-hand side of Poisson's equation is zero
Thanks for the help!
George