Commands

Scripting in Agros2D is based on scripting language Python.

General Commands

  • version()

    Print Agros2D version.

  • print( string )

    Print string to console (Python command).

  • message( string )

    Show message box.

  • variable = input( string )

    Show input box.

  • mode( mode )

    Set mode.

    • mode = {“node”, “edge”, “label”, “postprocessor”}
  • zoombestfit()

    Zoom best fit.

  • zoomin()

    Zoom in.

  • zoomout()

    Zoom out.

  • zoomregion( x1, y1, x2, y2 )

    Zoom region from [x1, y1] to [x2, y2].

  • solve()

    Solve problem.

  • mesh()

    Mesh geometry.

  • solutionfilename()

    Print name of file for saving solution.

  • meshfilename()

    Print name of file for saving mesh.

  • saveimage( filename )

    Save image to file.

  • quit()

    Quit Agros2D.

Document Commands

  • newdocument( name, type, physicfield, numberofrefinements, polynomialorder, adaptivitytype, adaptivitysteps, adaptivitytolerance, frequency, analysistype, timestep, totaltime, initialcondition )

    Create new document.

    • type = {“planar”, “axisymmetric”}
    • physicfield = {“general”, “electrostatic”, “magnetic”, “current”, “heat”}
    • numberofrefinements >= 0
    • polynomialorder = 1 to 10
    • adaptivitytype = {“disabled”, “h-adaptivity”, “p-adaptivity”, “hp-adaptivity”}
    • adaptivitysteps >= 0
    • adaptivitytolerance >= 0
    • frequency >= 0 (only for harmonic magnetic field)
    • analysistype = {“steadystate”, “transient”, “harmonic”}
    • timestep > 0
    • totaltime > 0

    Key words that match a problem types, physic fields, adaptivity types and analysis types can be found in the Keyword List.

An example:

newdocument("Electrostatic Axisymmetric Capacitor", "axisymmetric", "electrostatic", 0, 3, "disabled", 1, 1, 0, "steadystate", 0, 0, 0)
newdocument("Heat Transfer Axisymmetric Actuator", "axisymmetric", "heat", 0, 1, "hp-adaptivity", 5, 15, 0, "transient", 500, 15e3, 20)
  • opendocument( filename )

    Open document.

  • savedocument( filename )

    Save document.

Geometry Commands

  • addnode( x, y )

    Add new node with coordinates [x, y].

  • addedge( x1, y1, x2, y2, angle = 0, marker = “none” )

    Add new edge with from coordinates [x1, y1] to [x2, y2], angle and marker.

  • addlabel( x, y, area = 0, marker = “none” )

    Add new label with coordinates [x, y], area of triangle and marker.

  • selectnone()

    Unselect elements.

  • selectall()

    Select all elements.

  • selectnode( index, ... )

    Select nodes with given index.

  • selectedge( index, ... )

    Select edges with given index.

  • selectlabel( index, ... )

    Select labels with given index.

  • selectnodepoint( x, y )

    Select the closest node with coordinates [x, y].

  • selectedgepoint( x, y )

    Select the closest edge with coordinates [x, y].

  • selectlabelpoint( x, y )

    Select the closest label with coordinates [x, y].

  • deleteselection()

    Delete selected objects.

  • moveselection( dx, dy, copy = False )

    Move selected objects.

    • copy = {True, False}
  • rotateselection( x, y, angle, copy = False )

    Rotate selected objects.

    • copy = {True, False}
  • scaleselection( x, y, scale, copy = False )

    Scale selected objects.

    • copy = {True, False}

Materials and Boundaries Commands

  • addboundary( name, type, value, ... )

    Add boundary marker.

    • General field

      addboundary(name, type, value)

    • Electrostatic field

      addboundary(name, type, value)

    • Magnetic field

      addboundary(name, type, value)

    • Current field

      addboundary(name, type, value)

    • Heat transfer

      addboundary(name, type, temperature) addboundary(name, type, heat_flux, h, external_temperature)

    Key words that match a boundary condition types can be found in the Keyword List.

  • modifyboundary( name, type, value, ... )

    Modify boundary marker with marker name.

  • addmaterial( name, type, value, ... )

    Add label marker.

    • General field

      addmaterial(name, rightside, constant)

    • Electrostatic field

      addmaterial(name, charge_density, permittivity)

    • Magnetic field

      addmaterial(name, current_density, permeability, density, specificheat)

    • Current field

      addmaterial(name, conductivity)

    • Heat transfer

      addmaterial(name, volume_heat, thermal_conductivity)

  • modifymaterial( name, type, value, ... )

    Modify label marker with marker name.

Postprocessor Commands

  • result = pointresult( x, y )

    Local variables at point [x, y]. Key words that match a point results can be found in the Keyword List.

An example:

result = pointresult(0.1, 0.1)
print("Potential = " + str(result["V"]))
  • result = volumeintegral( index, ... )

    Volume integral in areas with given index. Key words that match a volume integrals can be found in the Keyword List.

An example:

result = volumeintegral(0.1, 0.1)
print("Volume = " + str(result["V"]))
  • result = surfaceintegral( index, ... )

    Surface integral in edges with given index. Key words that match a surface integrals can be found in the Keyword List.

An example:

result = surfaceintegral(0.1, 0.1)
print("Charge = " + str(result["V"]))
  • showgrid( show )

    Show grid.

    • show = {True, False}
  • showgeometry( show )

    Show geometry.

    • show = {True, False}
  • showinitialmesh( show )

    Show initial mesh.

    • show = {True, False}
  • showsolutionmesh( show )

    Show solution mesh.

    • show = {True, False}
  • showcontours( show )

    Show contours.

    • show = {True, False}
  • showvectors( show )

    Show vectrors.

    • show = {True, False}
  • showscalar( type, variable, component, rangemin, rangemax )

    Set view to type and show variable with component and in range (rangemin, rangemax).

    • type = {“none”, “scalar”, “scalar3d”, “order”}

    Key words that match a view types, physic field variables and components can be found in the Keyword List.

  • timestep( timeStep )

    Set time level of transient problem.

Mathematical Operations

You can use full of basic mathematical operations in Python. When dividing you must use a float type in the the denominator. For example: x/2.0.

Predefined User Functions

  • addsemicircle( x0, y0, radius, marker = “none”, label )

    Add semicircle with center coordinates [x0, y0], radius, marker and label.

  • addcircle( x0, y0, radius, marker = “none”, label )

    Add circle with center coordinates [x, y], radius, marker and label.

  • addrect( x0, y0, width, height, marker = “none”, label )

    Add rect with starting coordinates [x0, y0], width, height, marker and label.

Examples

Electrostatic Axisymmetric Capacitor

This script is detailed describe in example Electrostatic Axisymmetric Capacitor.

# 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)

Tips

You can run single commands and user functions. Select “Run command...” in the menu “Tools”, or by pressing Alt+C and enter command, or user function.

You can use the full possibilities of Python while writing your scripts. For example, you can draw graphs, or perform other calculations.

You can be found all keywords of the command parameters in Keyword List.