Electrostatic Axisymmetric Capacitor

This example demonstrates the basics of scripting in Agros2D. The resulting script can be found if the file /data/scripts/electrostatic_axisymmetric_capacitor.py.

Introduction

A cylindrical capacitor is a special type of a capacitor, which has electrodes in the form of the concentric cylinders.

For more information visit http://en.wikipedia.org/wiki/Capacitor.

Preprocessing

Select “Script editor” in the “Tools” menu, or press key F4 and create new solution by command newDocument in form.

newdocument("Electrostatic Axisymmetric Capacitor", "axisymmetric", "electrostatic", 1, 3, "disabled", 1, 1, 0, "steadystate", 0, 0, 0)

It is useful to use local variables in the script.

r1 = 0.01
r2 = 0.03
r3 = 0.05
r4 = 0.055
l = 0.16
eps1 = 10
eps2 = 3
U = 10
dr = 0.003

Boundary conditions

At first we define boundary conditions. They can be assigned to individual edges in the geometry. The boundary conditions are added with the command addBoundary.

addboundary("Source", "electrostatic_potential", U)
addboundary("Ground", "electrostatic_potential", 0)
addboundary("Border", "electrostatic_surface_charge_density", 0)

Materials

Next, we define materials and then assign them to the individual areas (labels) in the geometry. The addition of material is carried out with the command addMaterial.

addmaterial("Air", 0, 1)
addmaterial("Dielectric 1", 0, eps1)
addmaterial("Dielectric 2", 0, eps2)

Geometry

  • Edges

    Use edges to create the desired geometry. The edges are added with the command addEdge.

    addedge(0, 3/2*l, 0, l/2, 0, "Border")
    addedge(r1, l/2, r1, 0, 0, "Source")
    addedge(r1, 0, r2, 0, 0, "Border")
    addedge(r2, 0, r2, l/2, 0, "none")
    addedge(r2, l/2, r3, l/2, 0, "none")
    addedge(r3, 0, r2, 0, 0, "Border")
    addedge(r3, l/2, r3, 0, 0, "Ground")
    addedge(r4, 0, r4, l/2, 0, "Ground")
    addedge(r3, l/2, r4, l/2, 0, "Ground")
    addedge(r4, 0, 3/2*l, 0, 0, "Border")
    addedge(3/2*l, 0, 0, 3/2*l, 90, "Border")
    addedge(r1, l/2, r2, l/2, 0, "none")
    addedge(r1, l/2, 0, l/2, 0, "Source")
    
  • Labels

    Use labels to define block labels. The block labels addition is carried out with the command addLabel.

    addlabel(0.019, 0.021, 0, 0, "Dielectric 1")
    addlabel(0.0379, 0.051, 0, 0, "Dielectric 2")
    addlabel(0.0284191, 0.123601, 0, 0, "Air")
    

Processing

In this example, we will investigate the dependence of the capacity on the distance of electrodes. For this calculation we will use “do - while” cycle. Type the following code.

C = []
print("C = f(r) (F):")
for i in range(15):
	if i > 0:
		selectedge(6, 7, 8)
		moveselection(dr, 0, False)

	solve()
	result = volumeintegral(0, 1, 2)

	r.append(r1 + (i*dr))
	C.append(2*2*result["We"]/(U^2))
	print(r[-1], C[-1])

# plot chart
try:
	import pylab as pl

	pl.plot(r, C)
	pl.grid(1)
	pl.xlabel("r (m)")
	pl.ylabel("C (F)")
	pl.show()
except ImportError as err:
	print("Script error: " + err.message)

To run the script select “Run” in the menu “Tools”, or by pressing Ctrl+R.

Postprocessing

After the script is finished the dependence of the capacity on the distance of electrodes will be depicted.

../_images/calculation_of_capacity.png

Fig 2.: Calculation of the capacity

Complete script

# model
newdocument("Electrostatic Axisymmetric Capacitor", "axisymmetric", "electrostatic", 1, 3, "disabled", 1, 1, 0, "steadystate", 0, 0, 0)

# variables
r1 = 0.01
r2 = 0.03
r3 = 0.05
r4 = 0.055
l = 0.16
eps1 = 10
eps2 = 3
U = 10
dr = 0.003

# boundaries
addboundary("Source", "electrostatic_potential", U)
addboundary("Ground", "electrostatic_potential", 0)
addboundary("Border", "electrostatic_surface_charge_density", 0)

# materials
addmaterial("Air", 0, 1)
addmaterial("Dielectric 1", 0, eps1)
addmaterial("Dielectric 2", 0, eps2)

# edges
addedge(0, 3/2*l, 0, l/2, 0, "Border")
addedge(r1, l/2, r1, 0, 0, "Source")
addedge(r1, 0, r2, 0, 0, "Border")
addedge(r2, 0, r2, l/2, 0, "none")
addedge(r2, l/2, r3, l/2, 0, "none")
addedge(r3, 0, r2, 0, 0, "Border")
addedge(r3, l/2, r3, 0, 0, "Ground")
addedge(r4, 0, r4, l/2, 0, "Ground")
addedge(r3, l/2, r4, l/2, 0, "Ground")
addedge(r4, 0, 3/2*l, 0, 0, "Border")
addedge(3/2*l, 0, 0, 3/2*l, 90, "Border")
addedge(r1, l/2, r2, l/2, 0, "none")
addedge(r1, l/2, 0, l/2, 0, "Source")

# labels
addlabel(0.019, 0.021, 0, 0, "Dielectric 1")
addlabel(0.0379, 0.051, 0, 0, "Dielectric 2")
addlabel(0.0284191, 0.123601, 0, 0, "Air")

zoombestfit()

# calculation of capacity
r = []
C = []
print("C = f(r) (F):")
for i in range(15):
	if i > 0:
		selectedge(6, 7, 8)
		moveselection(dr, 0, False)

	solve()
	result = volumeintegral(0, 1, 2)

	r.append(r1 + (i*dr))
	C.append(2*2*result["We"]/(U^2))
	print(r[-1], C[-1])

# plot chart
try:
	import pylab as pl

	pl.plot(r, C)
	pl.grid(1)
	pl.xlabel("r (m)")
	pl.ylabel("C (F)")
	pl.show()
except ImportError as err:
	print("Script error: " + err.message)