Surface Evolver Documentation

Surface Evolver syntax

Both the datafile and user commands follow a common general syntax described in this file, with a few differences as noted.
Return to top of Surface Evolver documentation.

Lexical format

For those who know about such things, the datafile and commands are read with a lexical analyzer generated by the lex program. The specification is in datafile.lex. Commands are further parsed by a yacc-generated parser.

In parsing an expression, the longest legal expression is used. This permits coordinates to be specified by several consecutive expressions with no special separators.


Comments

Comments may be enclosed in /* */ pairs (as in C) and may span lines. // indicates the rest of the line is a comment, as in C++.

Lines and line splicing

The file is made up of lines. Line breaks are significant. The next physical line can be spliced onto the current line by having \ be the last character of the current line. Line splicing is not effective in // comments. Blank lines and comment lines may be placed freely anywhere. The various combinations of CR and NL that various computer systems use are all recognized

Case

Case is not significant in the datafile. All letters are converted to lower case on input. In commands, case is only significant for single-letter commands.

Whitespace

In the datafile, whitespace consists of spaces, tabs, commas, colons, and semicolons. So it's fine if you want to use commas to separate coordinate values, and colons to prettify constraint definitions. In commands, whitespace consists of spaces and tabs. CTRL-Z is also whitespace, for the benefit of files imported from DOS.

Identifiers

Identifiers follow standard C rules (composed of alphanumeric characters and '_' with the leading character not a digit) and must not be keywords. Identifiers are used for macro names (in the datafile) and user-defined variables and commands. Identifiers must have at least two characters, since single characters can be confused with commands. To find out if a name is already in use as a keyword or user-defined name, use the is_defined function, which has the syntax
 is_defined(stringexpr)
The stringexpr must be a quoted string or other string expression. The return value is 0 if the name is undefined, 1 if defined. This function is evaluated at parse-time, not run-time, so a command like if is_defined(newvar) then newvar := 1 else newvar := 0 will give newvar the value 0 if this is its first appearance.

Numbers

Constant values may be in any of the usual forms. This includes integers, fixed point, and scientific notation such as
      2    -3    .5    23.    5e-10    +0.7D2
Hexadecimal integers starting with Ox, as in 0x12Af, are also accepted. Color names are interpreted as integers.

Colors

The colors of edges and facets are recorded as integers in the range -1 through 15. How these integers translate to colors on the screen is determined by how Evolver's graphics drivers are written. The following synonyms are supplied, and it is hoped that the graphics drivers will be written to display these correctly:
-1 CLEAR
0 BLACK
1 BLUE
2 GREEN
3 CYAN
4 RED
5 MAGENTA
6 BROWN
7 LIGHTGRAY
8 DARKGRAY
9 LIGHTBLUE
10 LIGHTGREEN
11 LIGHTCYAN
12 LIGHTRED
13 LIGHTMAGENTA
14 YELLOW
15 WHITE
The special color value CLEAR (-1) makes a facet transparent. These tokens are simply translated to integer values wherever they occur, so these are reserved words. Edge and facet colors may be set in the datafile or by the set command.

Arithmetic expressions

Arithmetic expressions evaluate to real numbers. Boolean expressions are a subclass, with zero as false and nonzero as true; true results evaluate as 1. Ordinary algebraic notation is used.

Constant expressions

Constant expressions are evaluated when parsed. They are denoted by constexpr in various syntax definitions. They occur mostly in the datafile. Although they may contain variables, changing the variable value after parsing has no effect. Variable expressions (denoted by expr in syntax definitions) are recorded as parse trees and are re-evaluated each time needed. For using compiled functions in certain places, you may be able to use a dynamic load library.

Atomic values

The following evaluate to single numbers in expressions:
number
An integer, real, or hexadecimal constant. Hex numbers begin with 0x.
e, pi
Special mathematical constants.
x1,x2,...; x,y,z,w
Depending on context, space coordinates, vertex coordinates, edge vector components, or facet normal components.
p1,p2,...
Parameters of vertices on boundaries.
G
Current gravitational constant for calculating gravitational energy.
user-defined variables
Arbitrary variables defined in the datafile or at runtime.
internal variables
Special pre-defined variables.
element attributes
Things like vertex coordinates, edge length facet area, colors.
named quantity attributes
Including modulus, target, value, pressure.
method instance attributes
Including modulus, value.
toggle name
Any toggle command name may be used as a Boolean variable in an expression (full word toggles, not single letters). But beware the ambiguity in interpreting a toggle as a command or a value. You may have to force the toggle to be interpreted as a value. "ad := autodisplay" sets ad as a command synonym for autodisplay, while "ad := (autodisplay)" records the current boolean value.

String expressions

A string expression evaluates to a string of characters. At present, the only ways to produce strings are:

Arithmetic operators

These are the arithmetic operators that may appear in expressions:
+,-,*,/
Usual real arithmetic. NOTE: A '+' or '-' preceded by whitespace and followed by a number is taken to be a signed number. Thus "3 - 5" and "3-5" are single expressions, but "3 -5" is not. This is for convenience in separating multiple expressions listed on the same line for vertex coordinates, metric components, etc. in the datafile.
idiv
Integer divide. Rounds toward zero, then does integer division. Ex: -3.5 idiv 2.1 is -3 idiv 2 is -1.
%, mod
Real arithmetic modulus, x % y = x - floor(x/y)*y.
imod
Integer arithmetic modulus, x imod y = floor(x) - floor(floor(x)/floor(y))*floor(y).
=
NOT an assignment operator. Treated as low-precedence '-' so level-set constraint formulas like x^2 + y^2 - R^2 may be written naturally as x^2 + y^2 = R^2.
(,)
Parentheses for grouping and functional notation.
^,**
Raise to real power.
? :
Conditional expression, as in the C language. x ? y : z evaluates to y if x is nonzero and to z if x is zero.

Boolean operators

Boolean expressions are a subclass of arithmetic expressions, with zero as false and nonzero as true; true results evaluate as 1.
==,>,<,>=,<=,!= Numerical or boolean comparison.
NOT, ! Boolean NOT
AND, && Boolean AND, with short-circuit evaluation.
OR, || Boolean OR, with short-circuit evaluation.

Operator precedences

Here is the order of operator precedence, listed from high to low with equal precedence on same line, with associativity.
Operator Associativity
^,** left associative
unary - right associative
*,/,%,IMOD,IDIV left associative
+,- left associative
on_boundary nonassociative
on_constraint nonassociative
hit_constraint nonassociative
==,>,<,>=,<=,!= right associative
NOT, ! right associative
AND, && left associative
OR, || left associative
? : left associative
= left associative

Math functions

These are the math functions available in expressions. They take one argument in parentheses, except where noted.
abs
absolute value
sqr
square
sqrt
square root (leeway of -1e-10 on sqrt(0))
sin,cos,tan
trig functions
acos,asin,atan
inverse trig functions (acos, asin arguments clamped to [-1,1])
atan2
inverse tangent, atan2(y,x)
log,exp
natural log, exponentiation base e
sinh,cosh,tanh
hyperbolic functions
asinh,acosh,atanh
inverse hyperbolic functions
pow
pow(x,y): raise x to real power y
ceil,floor
round up or down to integer
minimum,maximum
of two arguments, i.e. minimum(a,b)
wrap_inverse(w)
inverse of symmetry group element w
wrap_compose(w1,w2)
composition of symmetry group elements w1, w2
usrn
user-defined functions

Miscellaneous functions

sizeof

Returns dimension of an extra attribute. Syntax:
  SIZEOF(name)
where name is the name of the extra attribute, not in quotes.

is_defined

To find out if a name is already in use as a keyword or user-defined name, use the is_defined function, which has the syntax
 is_defined(stringexpr)
The stringexpr must be a quoted string or other string expression. The return value is 0 if the name is undefined, 1 if defined.

User-defined built-in functions

User-defined functions can be defined in C in userfunc.c. They are meant for situations where expression interpretation is too slow, or functions such as elliptic integrals are wanted. Currently, they are automatically functions of the coordinates. Do not give any arguments in the expression; for example "(usr1 + usr3)/usr10".

Aggregate functions

The maximum, minimum, sum, or average of an expression over a set of elements may be done with aggregate functions. The syntax is
   aggregate(generator,expr)
where aggregate is max, min, sum, or avg, and generator is an element generator. Example: this prints the total area of all green facets:
   print sum(facet where color == green, area)
"Count" is an aggregate function that gives the number of elements generated, regardless of the expression.

Element attribute values in expressions

The value of any element attribute may be used in an expression. The attribute name alone may be used if there is a default element active. Example:
   foreach facet do print area
Otherwise the attribute is referred to as a field of the element:
   foreach facet ff do print ff.area
Indexed extra attributes need an index in square brackets:
   foreach facet ff do print ff.something[3]
Index values are rounded down to integer values. Indexing starts with 1.

Most attributes are numerical or boolean, but some are element generators.

The following attributes are available (for details, see elements):

X1,X2,...,X,Y,Z,W
Coordinates of vertices, components of edge vector or facet normal
P1,P2
Parameters for boundaries
ID
Element identifying number
OID
Oriented element identifying number
ORIGINAL
Number of parent datafile element
COLOR
Integer representing color of facet (color of front if back different) or edge
FRONTCOLOR
Color of front of facet
BACKCOLOR
Color of back of facet
VALENCE
Number of edges on a vertex, facets on edge, edges on a facet, or facets, or on a body
AREA
Area of facet
LENGTH
Length of edge
VOLUME
Actual volume of body
TARGET
Target fixed volume of body
VOLCONST
Constant added to calculated volume of body
DENSITY
Density of edge, facet, or body
DIHEDRAL
Dihedral angle of facets on an edge
ORIENTATION
Sign for oriented integrals of edges or facets
ON_CONSTRAINT n
True if element on given constraint
HIT_CONSTRAINT n
True if element is exacty on a constraint. Useful for one-sided constraints.
ON_BOUNDARY n
True if element on given boundary
WRAP
numerical edge wrap in torus model or other quotient space
quantity_name
contribution of an element to a named quantity
instance_name
contribution of an element to a named method instance
extra_attribute[expr]
name of user-defined extra attribute, with subscript if needed.
VERTEX
Generator of edge or facet vertices.
MIDV
Id of edge midpoint in quadratic model.
EDGE
Generator of edges attached to vertex, or edges around a facet.
FACET
Generator of facets around a vertex or an edge.
BODY
Generator of bodies that a facet is on.

Variables

The Evolver command language has its own version of the user-defined variables common to most programming languages. Variables are typed according to the types of the values assigned to them: numeric or string. Users may define numeric variables either by variable declarations in the datafile, or both types by assigning a value to an identifier in a command. A variable may be subjected to optimization by declaring it an optimizing_parameter in the datafile.

Internal variables

These are pre-defined names for some of Evolver's internal variables. They may be used in the same way as user-defined variables, except the values of read-only variables may not be changed by the user.
ambient_pressure_value
Internal read-write variable. Value of the external pressure in the ideal gas model.
background
Internal read-write variable. Background color used in certain screen graphics (xgraph and Windows, at the moment).
body_count
Internal read-only variable. Number of bodies.
brightness
Internal read-only variable. Median gray level used in PostScript output and screen graphics.
clock
Internal read-only variable. Total elapsed Evolver execution time in seconds.
constraint_tolerance
Internal read-write variable. When vertices are projected to level-set constraints, projection by Newton's method is repeated until the level-set function is smaller than constraint_tolerance. Default value 1e-12.
datafilename
Internal read-only variable. String containing name of current datafile.
delete_count
Internal read-only variable. Number of elements deleted in last delete command.
edge_count
Internal read-only variable. Number of edges.
facet_count
Internal read-only variable. Number of facets.
facetedge_count
Internal read-only variable. Number of facetedges.
equi_count
Internal read-only variable. Number of edges flipped in last equiangulation.
dissolve_count
Internal read-only variable. Number of elements dissolved in last dissolve command.
eigenpos
Internal read-only variable. Number of positive eigenvalues in last Hessian factoring.
eigenneg
Internal read-only variable. Number of negative eigenvalues in last Hessian factoring.
eigenzero
Internal read-only variable. Number of zero eigenvalues in last Hessian factoring.
gravity_constant
Internal read-write variable. Value of the gravitational constant, which can also be set by the G command.
hessian_epsilon
Internal read-write variable. Magnitude regarded as zero by hessian command when factoring the Hessian matrix. If a zero appears on the diagonal at the pivot during factoring, a check is made to see if the rest of the row is zero. If it is, then a 1 is placed on the diagonal; else an error is reported.
hessian_slant_cutoff
Internal read-write variable. Hessian commands treat vertices whose normal vector is nearly perpendicular to constraints as fixed. hessian_slant_cutoff is the cosine of angle. Works on vertices with one degree of freedom in hessian_normal mode. Default value 0.
instance_name.modulus
Internal read-write variable. Modulus of a named method instance.
instance_name.value
Internal read-only variable. Value of a named method instance.
inverse_periods[expr][expr]
Internal read-only variable. Inverse matrix of the torus_periods matrix. Uses 1-based indexes. Useful for normalizing vertex coordinates to period basis.
integral_order
Internal read-write variable. Order of polynomial done by 1D and 2D Gaussian integration. Much better to set 1D and 2D separately. Synonym: integration_order
integral_order_1d
Internal read-write variable. Order of polynomial done by 1D Gaussian integration. Synonym: integration_order_1D
integral_order_2d
Internal read-write variable. Order of polynomial done by 2D Gaussian integration. Synonym: integration_order_2D
iteration_counter
Internal read-only variable. Loop count of last loop in a command.
jiggle_temperature
Internal read-only variable. Current temperature for jiggling.
lagrange_order
Internal read-only variable. Order of Lagrange model. Set with the lagrange n command.
last_eigenvalue
Internal read-only variable. Eigenvalue from last saddle, ritz, or eigenprobe command.
last_error
Internal read-write variable. Has error number of last error message.
last_hessian_scale
Internal read-only variable. Stepsize from last
saddle or hessian_seek command.
linear_metric_mix
Internal read-write variable. Fraction of linear interpolation in Hessian metric.
memory_arena
Internal read-only variable. Total memory allocated to the program's heap. Available only on SGI and Win32 versions.
memory_used
Internal read-only variable. Total memory used in the program's heap. Available only on SGI and Win32 versions.
notch_count
Internal read-only variable. Number of edges notched in last notch command.
pickvnum
Internal read-write variable. Number of last vertex picked in geomview.
pickenum
Internal read-write variable. Number of last edge picked in geomview.
pickfnum
Internal read-write variable. Number of last facet picked in geomview.
pop_count
Internal read-only variable. Number of items popped in last 'o' or 'O' command.
quadratic_metric_mix
Internal read-write variable. Fraction of linear interpolation in Hessian metric in the quadratic model. Not very useful.
quantity_name.modulus
Internal read-write variable. Modulus of a named quantity.
quantity_name.pressure
Internal read-only variable. Lagrange multiplier for a constrained named quantity.
quantity_name.target
Internal read-write variable. Constrained value of a named quantity.
quantity_name.value
Internal read-only variable. Value of a named quantity.
random
Internal read-only variable. Random number between 0 and 1.
random_seed
Internal read-write variable. Seed for random number generator, used for example in jiggling or in finding random initial vectors in various Hessian eigenvector algorithms. Defaults to 1 at start of datafile.
refine_count
Internal read-only variable. Number of elements refined in last refine command.
rotation_order
Internal read-write variable. Order of rotation group for symmetry groups rotate and flip_rotate.
scale
Internal read-write variable. Current scale factor for multiplying the force to get the motion in the 'g' command.
scale_scale
Internal read-write variable. Multiplier for the scale factor used in the 'g' command. Default value 1.
simplex_representation
Internal read-only variable. Whether the simplex model is in effect.
space_dimension
Internal read-only variable. Dimension of ambient space.
surface_dimension
Internal read-only variable. Dimension of surface.
symmetry_group
Internal read-only variable. Whether any symmetry group is active (Boolean).
target_tolerance
Internal read-write variable. When volume constraints or named quantity constraints are enforced, Newton's method is repeated until the total deviation from target values is less than target_tolerance. Default value 1e-4.
temperature
Internal read-only variable. Amplitude for jigglinge.
thickness
Internal read-only variable. Thickness for thickened surfaces in graphics output in P command. Used when facet frontcolor and backcolor are different. Default value 0.001 times the maximum linear dimension of the surface. If you get backside color showing through, increase the thickness.
torus
Internal read-only variable. Whether the torus model is in effect. (Boolean).
torus_periods[expr][expr]
Internal read-only variable. Current values of the period vectors in the torus model. Torus_periods[i][j] is component j of vector i. Uses 1 based indexes. For changing the torus_periods, define the periods in the datafile with variables, and alter the variables.
total_area
Internal read-only variable. Total area of the surface in soapfilm or simplex models.
total_energy
Internal read-only variable. Total energy of the surface.
total_length
Internal read-only variable. Total length of the surface in the string model.
total_time
Internal read-only variable. Elapsed evolution time in the form of total scale factors.
transform_count
Internal read-only variable. Number of image transforms active, as generated by the transform_expr command.
vertex_count
Internal read-only variable. Number of vertices.
where_count
Internal read-only variable. Number of items satisfying last 'where' condition.

Back to top of Surface Evolver documentation.