Scripting in Agros2D is based on scripting language Python.
Print Agros2D version.
Print string to console (Python command).
Show message box.
Show input box.
Set mode.
Zoom best fit.
Zoom in.
Zoom out.
Zoom region from [x1, y1] to [x2, y2].
Solve problem.
Mesh geometry.
Print name of file for saving solution.
Print name of file for saving mesh.
Save image to file.
Quit Agros2D.
Create new document.
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)
Open document.
Save document.
Add new node with coordinates [x, y].
Add new edge with from coordinates [x1, y1] to [x2, y2], angle and marker.
Add new label with coordinates [x, y], area of triangle and marker.
Unselect elements.
Select all elements.
Select nodes with given index.
Select edges with given index.
Select labels with given index.
Select the closest node with coordinates [x, y].
Select the closest edge with coordinates [x, y].
Select the closest label with coordinates [x, y].
Delete selected objects.
Move selected objects.
Rotate selected objects.
Scale selected objects.
Add boundary marker.
addboundary(name, type, value)
addboundary(name, type, value)
addboundary(name, type, value)
addboundary(name, type, value)
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.
Modify boundary marker with marker name.
Add label marker.
addmaterial(name, rightside, constant)
addmaterial(name, charge_density, permittivity)
addmaterial(name, current_density, permeability, density, specificheat)
addmaterial(name, conductivity)
addmaterial(name, volume_heat, thermal_conductivity)
Modify label marker with marker name.
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"]))
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"]))
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"]))
Show grid.
- show = {True, False}
Show geometry.
- show = {True, False}
Show initial mesh.
- show = {True, False}
Show solution mesh.
- show = {True, False}
Show contours.
- show = {True, False}
Show vectrors.
- show = {True, False}
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.
Set time level of transient problem.
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.
Add semicircle with center coordinates [x0, y0], radius, marker and label.
Add circle with center coordinates [x, y], radius, marker and label.
Add rect with starting coordinates [x0, y0], width, height, marker and label.
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)
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.