Hello, I am new to Devsim. I tried to make a test problem simulating current flow across 1d device with given conductivity. On one side (contact1), I would like to set the current density entering the device. On the other side (contact2), I set the potential to zero. So, it is a problem with one Neumann and one Dirichlet boundary condition. I get the correct linear function for the potential, but the current density is one half of the required value (set by the contact1 equation). I might have done something wrong in the problem setup, but I cannot figure out what, although I have read the manual and examples thoroughly. Can anybody help me, please? I attach my script.
dev = 'device'
reg = 'region'
msh = 'mesh1'
length = 1.0
resistivity = 1.0
ds.create_1d_mesh(mesh=msh)
ds.add_1d_mesh_line(mesh=msh, pos=0.0, ps=0.1, tag='contact1')
ds.add_1d_mesh_line(mesh=msh, pos=length, ps=0.1, tag='contact2')
ds.add_1d_contact(mesh=msh, name='contact1', tag='contact1', material='metal')
ds.add_1d_contact(mesh=msh, name='contact2', tag='contact2', material='metal')
ds.add_1d_region(mesh=msh, material='Si', region=reg, tag1='contact1', tag2='contact2')
ds.finalize_mesh(mesh=msh)
ds.create_device(mesh=msh, device=dev)
ds.set_parameter(device=dev, region=reg, name='sigma', value=1./resistivity)
# potential variable
ds.node_solution(device=dev, region=reg, name='V')
ds.edge_from_node_model(device=dev, region=reg, node_model='V')
# electric field
ds.edge_model(device=dev, region=reg, name='E', equation='(V@n0 - V@n1)*EdgeInverseLength')
ds.edge_model(device=dev, region=reg, name='E:V@n0', equation='EdgeInverseLength')
ds.edge_model(device=dev, region=reg, name='E:V@n1', equation='-EdgeInverseLength')
# current density
ds.edge_model(device=dev, region=reg, name='j', equation='sigma*E')
ds.edge_model(device=dev, region=reg, name='j:V@n0', equation='sigma*EdgeInverseLength')
ds.edge_model(device=dev, region=reg, name='j:V@n1', equation='-sigma*EdgeInverseLength')
# main equation: div(j) = div(-sigma*grad(phi)) = 0 (j = current density, sigma = conductivity, phi = potential)
ds.equation(device=dev, region=reg, name='PotentialEquation', variable_name='V', edge_model='j',
variable_update='default')
# left boundary condition, set incoming current density equal to 1
ds.set_parameter(device=dev, region=reg, name='current', value=1.0)
ds.contact_edge_model(device=dev, contact='contact1', name='contact1_bc', equation='j-current')
ds.contact_edge_model(device=dev, contact='contact1', name='contact1_bc:V@n0', equation='sigma*EdgeInverseLength')
ds.contact_edge_model(device=dev, contact='contact1', name='contact1_bc:V@n1', equation='-sigma*EdgeInverseLength')
# right boundary condition, set potential to 0
ds.contact_node_model(device=dev, contact='contact2', name='contact2_bc', equation='V')
ds.contact_node_model(device=dev, contact='contact2', name='contact2_bc:V', equation='1')
# contact equations
ds.contact_equation(device=dev, contact='contact1', name='PotentialEquation', edge_model='contact1_bc',
edge_current_model='j')
ds.contact_equation(device=dev, contact='contact2', name='PotentialEquation', node_model='contact2_bc',
edge_current_model='j')
ds.solve(type='dc', absolute_error=1.0e-6, relative_error=1.0e-10)
print(ds.get_node_model_values(device=dev, region=reg, name='V'))
print(ds.get_edge_model_values(device=dev, region=reg, name='j'))
print(ds.get_edge_model_values(device=dev, region=reg, name='contact1_bc'))
print(ds.get_node_model_values(device=dev, region=reg, name='contact2_bc'))
Results:
V = [0.5, 0.45, 0.4, 0.35, 0.3, 0.25, 0.2, 0.15000000000000002, 0.10000000000000003, 0.050000000000000044, 0.0]
j = [0.4999999999999999, 0.4999999999999999, 0.5000000000000002, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]
contact1_bc = [-0.5000000000000001, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
contact2_bc = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]