from fenics import *
import matplotlib.pyplot as plt
import numpy as np
path = "/mnt/c/Files/modlab/code/"
"""
Dimensions of mesh
"""
mesh_side = 600e-6
"""
Creating a mesh
"""
cells_x, cells_y, cells_z = 20,20,20
outer_mesh = BoxMesh(Point(-mesh_side/2.0,-mesh_side/2.0,-mesh_side/2.0),
Point(mesh_side/2.0, mesh_side/2.0, mesh_side/2.0),
cells_x, cells_y, cells_z)
# Define function space
V = FunctionSpace(outer_mesh, 'P', 1) # For electric potential Phi and electric field E
# Define trial and test functions
phi = TrialFunction(V)
q = TestFunction(V)
# Define the dimensions of the cuboid
bot_x, bot_y, bot_z = 300e-6, 200e-6, 10e-6
#Dimensions of pads
#length, breadth, thickness
pad_x, pad_y, pad_z = 50e-6, 50e-6, 10e-6
# Define the center of the cuboid
center = Point(0, 0, 0)
# Define the center of pads
p1_center = Point(bot_x/4.0, bot_y/4.0, 0)
# Define separate subdomains for pads and cuboid
class Pad1(SubDomain):
def inside(self, x, on_boundary):
return (abs(x[0] - p1_center[0]) <= pad_x/2) and \
(abs(x[1] - p1_center[1]) <= pad_y/2) and \
(abs(x[2] - p1_center[2]) <= pad_z/2) and \
(x[0] > 0) and (x[1] > 0)
class Cuboid(SubDomain):
def inside(self, x, on_boundary):
return (abs(x[0] - center[0]) <= bot_x/2) and \
(abs(x[1] - center[1]) <= bot_y/2) and \
(abs(x[2] - center[2]) <= bot_z/2) and \
not any([Pad1().inside(x, on_boundary)])
# Initialize mesh function for the subdomains
markers = MeshFunction("size_t", outer_mesh, outer_mesh.topology().dim())
markers.set_all(0)
# Mark the subdomains for the pads
pad1 = Pad1()
pad1.mark(markers, 1)
# Mark the subdomain for the cuboid as 5
cuboid = Cuboid()
cuboid.mark(markers, 5)
# Define new measures for integration over each pad and rest of the bot
dx_pad1 = Measure("dx", domain=outer_mesh, subdomain_data=markers, subdomain_id=1)
dx_bot = Measure("dx", domain=outer_mesh, subdomain_data=markers, subdomain_id=5)
# Define boundary conditions for the pads and the bot
V_pad1 = 4
V_surface_value = 4
bc_pad1 = [DirichletBC(V, Constant(V_pad1), pad1)]
bc_bot = [DirichletBC(V, Constant(V_surface_value), cuboid)]
# Define weak forms
DX = dx_pad1 + dx_bot
a_phi = inner(grad(phi), grad(q)) * DX
L_phi = Constant(0) * q * DX # Assuming no source term in this case
# Solve for Phi and Apply multiple boundary conditions
Phi = Function(V)
BCS = bc_pad1 + bc_bot
solve(a_phi == L_phi, Phi, BCS)
print("File Executed")