Skip to content

Commit

Permalink
hide tqdm in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
HelgeGehring committed Oct 10, 2023
1 parent b89f81f commit 5c11f19
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions docs/electronics/examples/capacitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# jupytext:
# text_representation:
# extension: .py
# format_name: light
# format_name: percent
# format_version: '1.5'
# jupytext_version: 1.15.2
# kernelspec:
Expand All @@ -12,6 +12,7 @@
# name: python3
# ---

# %% [markdown]
# # Lumped capacitor
#
# The capacitance $C$ of a system given a potential difference $\Delta V$ between two conductors can be calculated from
Expand All @@ -28,7 +29,7 @@
#
# First, we parametrize a simple geometry:

# +
# %%
from collections import OrderedDict

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -63,8 +64,7 @@
from femwell.maxwell.waveguide import compute_modes
from femwell.visualization import plot_domains, plot_subdomain_boundaries

# -

# %%
# Define some parameters for the capacitor:

dielectric_epsilon = 16
Expand All @@ -73,6 +73,7 @@
delta_voltage = 1


# %% [markdown]
# Make a mesh
#
# <div class="alert alert-success">
Expand Down Expand Up @@ -155,10 +156,11 @@ def parallel_plate_capacitor_mesh(
plot_subdomain_boundaries(mesh)


# %% [markdown]
# Since the electric field inside a metal is zero, we define the voltage on the boundary of the metal, and exclude the metal from the mesh:


# +
# %%
def potential(mesh, dV=delta_voltage, dielectric_epsilon=16):
basis_epsilon = Basis(mesh, ElementTriP0())
epsilon = basis_epsilon.ones()
Expand All @@ -180,16 +182,16 @@ def potential(mesh, dV=delta_voltage, dielectric_epsilon=16):


basis_u, u, basis_epsilon, epsilon = potential(mesh, dV=delta_voltage)
# -

# %%
fig, ax = plt.subplots()
for subdomain in basis_epsilon.mesh.subdomains.keys() - {"gmsh:bounding_entities"}:
basis_epsilon.mesh.restrict(subdomain).draw(ax=ax, boundaries_only=True)
basis_u.plot(u, ax=ax, shading="gouraud", colorbar=True)
# basis_vec.plot(-u_grad, ax=ax)
plt.show()

# +
# %%
for subdomain in basis_epsilon.mesh.subdomains.keys() - {"gmsh:bounding_entities"}:
basis_epsilon.mesh.restrict(subdomain).draw(ax=ax, boundaries_only=True)
basis_grad = basis_u.with_element(ElementDG(basis_u.elem))
Expand All @@ -205,9 +207,7 @@ def potential(mesh, dV=delta_voltage, dielectric_epsilon=16):
plt.show()


# -


# %%
def capacitance(
width=2,
separation=separation,
Expand Down Expand Up @@ -241,7 +241,7 @@ def W(w):
return C


# +
# %% tags=["hide-stderr"]
import tqdm

widths = np.linspace(1, 50, 11)
Expand Down Expand Up @@ -279,7 +279,7 @@ def W(w):

plt.legend(title="Dielectric")

# +
# %%
colors = ["tab:blue", "tab:orange", "tab:green"]

for dielectric_epsilon, color in zip([1, 3.9, 16], colors):
Expand All @@ -296,6 +296,7 @@ def W(w):
plt.ylabel(r"Relative error in capacitance per unit length / $\epsilon_0$ (a.u.)")

plt.legend(title="Dielectric")
# -


# %% [markdown]
# The solver reproduces the parallel-plate capacitor result. For small widths, there is a greater discrepancy between the theoretical parallel plate and the simulated due to the higher relative impact of fringe fields. There is also a constant offset that persists at large widths due to the fringe field contribution. The relative importance of the fringe fields is reduced with increasing dielectric constant which forces more field lines between the two electrodes, as expected.

0 comments on commit 5c11f19

Please sign in to comment.