Within Cubit™ there is support for a programming language called APREPRO (An Algebraic Preprocessor for Parameterizing Finite Element Analyses). Included here is a summary of the APREPRO functionality included within Cubit. This is a summary of the full https://github.com/gsjaardema/seacas/tree/master/docs.
Note: APREPRO variables can be created and modified from the GUI. Enable/disable the editor from the View/Aprepro editor menu option. The editor is a docking window and can be placed anywhere in the GUI.
15.2.1APREPRO Additional Functionality
15.2.1.11. File Inclusion
APREPRO can read input from multiple files using the include() and cinclude() functions. If a line of the form:
{include(" filename")}
{include(string_variable)}
is read, APREPRO will open and begin reading from the file filename. A string variable can be used as the argument instead of a literal string value. When the end of the file is reached, it will be closed and APREPRO will continue reading from the previous file. The difference between include and cinclude is that if filename does not exist, include will terminate APREPRO with a fatal error, but cinclude will just write a warning message and continue with the current file. The cinclude function can be thought of as a conditional include, that is, include the file if it exists. Multiple include files are allowed and an included file can also include additional files. Approximately 16 levels of file inclusion can be used. This option can be used to set variables globally in several files. For example, if two or more input files share common points or dimensions, those dimensions can be set in one file that is included in the other files.
15.2.1.22. Conditionals
Portions of an input file can be conditionally processed through the use of the {ifdef(variable)} or ifndef(variable)} constructs. The syntax is:
#{ifdef(variable)}
...Lines processed if ’variable’ is not equal to 0
#{else}
...Lines processed if ’variable’ is equal to 0 or undefined
#{endif}
#{ifndef(variable)}
...Lines processed if ’variable’ is equal to 0 or undefined
#{else}
...Lines processed if ’variable’ is not equal to 0
#{endif}
The
{else}
is optional. Note that if variable is undefined, its value is equal to zero. ifdef constructs can be nested up to approximately 16 levels. A warning message will be printed if improper nesting is detected. ifdef(variable)}, {ifndef(variable)}, {else}, and {endif} are the only text parsed on a line. Text following these on the same line is ignored.
15.2.1.33. Loops
Repeated processing of a group of lines can be controlled with the {loop( control)}, {endloop} commands. The syntax is:
{loop(variable)}
...Process these lines ’variable’ times
{endloop}
Loops can be nested. A numerical variable or constant must be specified as the loop control specifier. You currently cannot use an algebraic expression such as {loop(3+5)}.
A loop may also be exited before running the specified number of times using a #{break} statement. As soon as a #{break} statement is encountered, the loop is exited and the rest of the statements in the loop will not execute. Additional iterations of the loop will not be executed either. For example, the following commands will create 3 bricks:
#{x=1} #{Loop(10)} brick x 1 #{If(x==2)} #{Break} #{EndIf} #{x++} brick x 1 #{EndLoop}
When a #{break} statement executes, anything in the loop following the #{break} statement will be skipped, including the #{endif}. For this reason, a #{break} statement not only exits the loop, but also terminates the most recent #{if} statement exactly as #{endif} would do. #{break} statements should not be used outside of #{if} statements.
15.2.2APREPRO Functions
Several mathematical, Cubit and string functions are implemented in APREPRO.
To cause a function to be used, you enter the name of the function followed by a list of zero or more arguments in parentheses. For example
sqrt(min(a,b*3))
uses the two functions sqrt() and min(). The arguments a and b*3 are passed to min(). The result is then passed as an argument to sqrt(). The functions in APREPRO are listed below along with the number of arguments and a short description of their effect.
15.2.2.11. Mathematical Functions
The following mathematical functions are available in APREPRO. Check current APREPRO documentation for any updates to this list of functions.
Table 1. Mathematical Functions
Syntax
Description
abs(x)
Calculates the absolute value of x. |x|
acos(x)
Calculates the inverse cosine of x, returns radians
acosd(x)
Calculates the inverse cosine of x, returns degrees
acosh(x)
Calculates the inverse hyperbolic cosine of x
asin(x)
Calculates the inverse sine of x, returns radians
asind(x)
Calculates the inverse sine of x, returns degrees
asinh(x)
Calculates the inverse hyperbolic sine of x
atan(x)
Calculates the inverse tangent of x, returns radians
atan2(y,x)
Calculates the inverse tangent of y/x, returns radians
atan2d(y,x)
Calculates the inverse tangent of y/x, returns degrees
atand(x)
Calculates the inverse tangent of x, returns degrees
atanh(x)
Calculates the inverse hyperbolic tangent of x
ceil(x)
Calculates the smallest integer not less than x
cos(x)
Calculates the cosine of x, with x in radians
cosd(x)
Calculates the cosine of x, with x in degrees
cosh(x)
Calculates the hyperbolic cosine of x
d2r(x)
Converts degrees to radians.
dim(x,y)
Calculates x - min(x,y).
The following Cubit Functions are available: Table 2. Cubit Functions
Syntax
Description
BlockAttributeName(id, index)
Returns the name for the specified attribute index in the block within the given id
BlockAttributeValue(id, index)
Returns the value for the specified attribute index in the block within the given id
NumBlocks
Returns the number of blocks defined in the model
NumSidesets
Returns the number of sidesets defined in the model
NumNodesets
Returns the number of nodesets defined in the model
FileExists(filename)
Checks if the given file exists. Returns non-zero if it does
GeometryEngineVersion(engine name)
Get the geometry version for the specified geometry engine
get_error_count()
Gets the current error count in Cubit
set_error_count(val)
Sets the error count in Cubit to given value
get_warning_count()
Gets the current warning count in Cubit
HasFeature(feature_name)
Checks if the feature "feature_name" is available and returns nonzero if the feature is enabled
set_warning_count(val)
Sets the warning count in Cubit to value
Id("type")
Returns the ID of the entity most recently created with the specified type. Acceptable types include: "body", "volume", "surface", "curve", "vertex", "group", "node", "edge", "quad", "face", "tri", "hex", "tet", or "pyramid".
GroupMemberId("group_name", "entity_type", index)
Returns the ID of "entity_type" in group "group_name" at the specified index. If the group contains multiple entity types the index will only be relevant for the entity type specified and will behave as if the group only contained that entity type.
IntNum(id)
Returns the number of intervals on a curve with the given id.
IntNum(x, y, z, ord)
Returns the number of intervals on a curve identified by the given center point coordinates and ordinal value.
IntSize(id)
Returns the interval size on a curve with the given id.
IntSize(x, y, z, ord)
Returns the interval size on a curve identified by the given center point coordinates and ordinal value.
Volume(id)
Gets the geometric volume of the volume with the given id.
Volume(x, y, z, ord)
Gets the geometric volume of the volume identified by the given center point coordinates and ordinal value.
SurfaceArea(id)
Returns the surface area of the surface with the given id.
SurfaceArea(x, y, z, ord)
Returns the surface area of the surface identified by the given center point coordinates and ordinal value.
Length(id)
Returns the length of the curve with the given id.
Length(x, y, z, ord)
Returns the length of the curve identified by the given center point coordinates and ordinal value.
Radius(id)
Returns the radius of the curve at its midpoint.
Radius(x, y, z, ord)
Returns the radius of the curve identified by the given center point coordinates and ordinal value.
MinVolumeMeshQuality(id, "metric")
Returns the worst value of the specified element quality metric of all elements in the volume with the given id. Acceptable metrics include:
shape
aspect ration bet
aspect ratio gam
aspect ratio
condition no
diagonal ratio
dimension
distortion
element volume
jacobian
relative size
scaled jacobian
shape and size
shear and size
shear
skew
stretch
taper
MinVolumeMeshQuality(x, y, z, ord, "metric")
Returns the worst value of the specified element quality metric of all elements in the volume identified by the given center point coordinates and ordinal value.
Acceptable metrics include:
shape
aspect ration bet
aspect ratio gam
aspect ratio
condition no
diagonal ratio
dimension
distortion
element volume
jacobian
relative size
scaled jacobian
shape and size
shear and size
shear
skew
stretch
taper
MinSurfaceMeshQuality(id, "metric")
Returns the worst value of the specified element quality metric of all elements on the given surface. Acceptable metrics include:
shape
aspect ratio
condition no
distortion
element area
jacobian
maximum angle
minimum angle
relative size
scaled jacobian
shape and size
shear and size
shear
skew
stretch
taper
warpage
MinSurfaceMeshQuality(x, y, z, ord, "metric")
Returns the worst value of the specified element quality metric of all elements on the surface identified by the given center point coordinates and ordinal value. Acceptable metrics include:
shape
aspect ratio
condition no
distortion
element area
jacobian
maximum angle
minimum angle
relative size
scaled jacobian
shape and size
shear and size
shear
skew
stretch
taper
warpage
MeshVolume(id)
Returns the total volume of all mesh elements in the volume with the given id. This will vary from the actual geometric volume since the mesh approximates curved boundaries with linear mesh edges.
MeshVolume(x, y, z, ord)
Returns the total volume of all mesh elements in the volume identified by the given center point coordinates and ordinal value. This will vary from the actual geometric volume since the mesh approximates curved boundaries with linear mesh edges.
HexVolume(id)
Returns the volume of the hex with the given id.
HexVolume(x, y, z, ord)
Returns the volume of the hex identified by the given center point coordinates and ordinal value.
TetVolume(id)
Returns the volume of the tet with the given id.
TetVolume(x, y, z, ord)
Returns the volume of the tet identified by the given center point coordinates and ordinal value.
FaceArea(id)
Returns the area of the face with the given id.
FaceArea(x, y, z, ord)
Returns the area of the face identified by the given center point coordinates and ordinal value.
TriArea(id)
Returns the area of the tri with the given id.
TriArea(x, y, z, ord)
Returns the area of the tri identified by the given center point coordinates and ordinal value. .
MeshSurfaceArea(id)
Returns the total area of all triangle or quadrilateral elements on the surface with the given id. This will vary from the geometric surface area since the mesh approximates the boundary with linear mesh edges.
MeshSurfaceArea(x, y, z, ord)
Returns the total area of all triangle or quadrilateral elements on the surface identified by the given center point coordinates and ordinal value. This will vary from the geometric surface area since the mesh approximates the boundary with linear mesh edges.
EdgeLength(id)
Returns the length of the edge with the given id.
EdgeLength(x, y, z, ord)
Returns the length of the edge identified by the given center point coordinates and ordinal value.
MeshLength(id)
Gets the length of the meshed curve with the given id.
MeshLength(x, y, z, ord)
Gets the length of the meshed curve identified by the given center point coordinates and ordinal value.
Nx(id), Ny(id), Nz(id)
Gets the x, y or z coordinate of node with the given id.
Nx(x, y, z, ord)Ny(x, y, z, ord)Nz(x, y, z, ord)
Gets the x, y or z coordinate of node identified by the given center point coordinates and ordinal value.
Vx(id), Vy(id), Vz(id)
Gets the x, y or z coordinate of vertex with the given id.
Vx(x, y, z, ord)Vy(x, y, z, ord)Vz(x, y, z, ord)
Gets the x, y or z coordinate of vertex identified by the given center point coordinates and ordinal value.
NumInGrp("groupname")
Returns the number of entities in the given group.
NumTypeInGroup("group_name", "entity_type")
Returns the number of "entity_type" in group "group_name".
NumEdgesOnCurve(id)
Returns the number of edges on the curve with the given id.
NumEdgesOnCurve(x, y, z, ord)
Returns the number of edges on the curve identified by the given center point coordinates and ordinal value.
NumElemsOnSurface(id)
Returns the number of elements on the surface with the given id.
NumElemsOnSurface(x, y, z, ord)
Returns the number of elements on the surface identified by the given center point coordinates and ordinal value.
NumElemsInVolume(id)
Returns the number of elements in the volume with the given id.
NumElemsInVolume(x, y, z, ord)
Returns the number of elements in the volume identified by the given center point coordinates and ordinal value.
NumVolumes()
Returns the number of volumes in the model.
NumSurfaces()
Returns the number of surfaces in the model.
NumCurves()
Returns the number of curves in the model.
NumVertices()
Returns the number of vertices in the model.
NumVolsInPart("part_name")
Returns the number of volumes assigned to the part with the specified name.
PartInVol(id)
Returns the name and instance number of the part that the volume has been assigned to.
SessionId()
Returns a unique ID for each Cubit session.
DUMP()
Returns a list of all APREPRO variables with their values.
delete("var")
Deletes the APREPRO variable with the name var.
GeomCentroid_X("type", id)
Returns the x coordinate of the centroid of the specified geometric entity. "type" can be "volume" or "group". If "volume" it calculates the centroid for the volume with the given id (single volume). If "group" it must be a group of volumes and it will calculate the combined centroid for the whole group with the given id.
GeomCentroid_Y("type", id)
Returns the y coordinate of the centroid of the specified geometric entity. "type" can be "volume" or "group". If "volume" it calculates the centroid for the volume with the given id (single volume). If "group" it must be a group of volumes and it will calculate the combined centroid for the whole group with the given id.
GeomCentroid_Z("type", id)
Returns the z coordinate of the centroid of the specified geometric entity. "type" can be "volume" or "group". If "volume" it calculates the centroid for the volume with the given id (single volume). If "group" it must be a group of volumes and it will calculate the combined centroid for the whole group with the given id.
MeshCentroid_X("type", id)
Returns the x coordinate of the centroid of the specified mesh entity. "type" can be "volume", "block", or "group". If "volume" it calculates the centroid of the 3D elements in the volume with the given id. If "block" it calculates the centroid of the elements in the block with the given id. If "group" it must be a group of volumes and it calculates the centroid of the group with the given id.
MeshCentroid_Y("type", id)
Returns the y coordinate of the centroid of the specified mesh entity. "type" can be "volume", "block", or "group". If "volume" it calculates the centroid of the 3D elements in the volume with the given id. If "block" it calculates the centroid of the elements in the block with the given id. If "group" it must be a group of volumes and it calculates the centroid of the group with the given id.
MeshCentroid_Z("type", id)
Returns the z coordinate of the centroid of the specified mesh entity. "type" can be "volume", "block", or "group". If "volume" it calculates the centroid of the 3D elements in the volume with the given id. If "block" it calculates the centroid of the elements in the block with the given id. If "group" it must be a group of volumes and it calculates the centroid of the group with the given id.
BBox_XMin("type", id)
Returns the xmin value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
BBox_XMax("type", id)
Returns the xmax value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
BBox_YMin("type", id)
Returns the ymin value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
BBox_YMax("type", id)
Returns the ymax value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
BBox_ZMin("type", id)
Returns the zmin value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
BBox_ZMax("type", id)
Returns the zmax value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
NodeAt(x, y, z)
Returns the id of the node closest to the xyz location.
NodeAt(x, y, z, ordinal)
Returns the id of the Node with the idless reference, x,y,z,ordinal.
EdgeAt(x, y, z, ordinal)
Returns the id of the edge with the idless reference, x,y,z,ordinal.
FaceAt(x, y, z, ordinal)
Returns the id of the quad face with the idless reference, x,y,z,ordinal.
TriAt(x, y, z, ordinal)
Returns the id of the triangle with the idless reference, x,y,z,ordinal.
HexAt(x, y, z, ordinal)
Returns the id of the hexahedra element with the idless reference, x,y,z,ordinal.
TetAt(x, y, z, ordinal)
Returns the id of the tetraheral element with the idless reference, x,y,z,ordinal.
WedgeAt(x, y, z, ordinal)
Returns the id of the wedge element with the idless reference, x,y,z,ordinal.
PyramidAt(x, y, z, ordinal)
Returns the id of the pyramid element with the idless reference, x,y,z,ordinal.
VertexAt(x, y, z, ordinal)
Returns the id of the vertex with the idless reference, x,y,z,ordinal.
CurveAt(x, y, z, ordinal)
Returns the id of the curve with the idless reference, x,y,z,ordinal.
SurfaceAt(x, y, z, ordinal)
Returns the id of the surface with the idless reference, x,y,z,ordinal.
VolumeAt(x, y, z, ordinal)
Returns the id of the volume with the idless reference, x,y,z,ordinal.
15.2.2.22. Cubit Functions
The following Cubit Functions are available:
Table 2. Cubit Functions
Syntax
Description
blockattributename(id, index)
Returns the name for the specified attribute index in the block within the given id
blockattributevalue(id, index)
Returns the value for the specified attribute index in the block within the given id
numblocks
Returns the number of blocks defined in the model
numsidesets
Returns the number of sidesets defined in the model
numnodesets
Returns the number of nodesets defined in the model
fileexists(filename)
Checks if the given file exists. Returns non-zero if it does
geometryengineversion(engine name)
Get the geometry version for the specified geometry engine
get_error_count()
Gets the current error count in Cubit
set_error_count(val)
Sets the error count in Cubit to given value
get_warning_count()
Gets the current warning count in Cubit
hasfeature(feature_name)
Checks if the feature "feature_name" is available and returns nonzero if the feature is enabled
set_warning_count(val)
Sets the warning count in Cubit to value
id("type")
Returns the ID of the entity most recently created with the specified type. Acceptable types include: "body", "volume", "surface", "curve", "vertex", "group", "node", "edge", "quad", "face", "tri", "hex", "tet", or "pyramid".
groupmemberid("group_name", "entity_type", index)
Returns the ID of "entity_type" in group "group_name" at the specified index. If the group contains multiple entity types the index will only be relevant for the entity type specified and will behave as if the group only contained that entity type.
intnum(id)
Returns the number of intervals on a curve with the given id.
intnum(x, y, z, ord)
Returns the number of intervals on a curve identified by the given center point coordinates and ordinal value.
intsize(id)
Returns the interval size on a curve with the given id.
intsize(x, y, z, ord)
Returns the interval size on a curve identified by the given center point coordinates and ordinal value.
volume(id)
Gets the geometric volume of the volume with the given id.
volume(x, y, z, ord)
Gets the geometric volume of the volume identified by the given center point coordinates and ordinal value.
surfacearea(id)
Returns the surface area of the surface with the given id.
surfacearea(x, y, z, ord)
Returns the surface area of the surface identified by the given center point coordinates and ordinal value.
length(id)
Returns the length of the curve with the given id.
length(x, y, z, ord)
Returns the length of the curve identified by the given center point coordinates and ordinal value.
radius(id)
Returns the radius of the curve at its midpoint.
radius(x, y, z, ord)
Returns the radius of the curve identified by the given center point coordinates and ordinal value.
minvolumemeshquality(id, "metric")
Returns the worst value of the specified element quality metric of all elements in the volume with the given id.
Acceptable metrics include: shape aspect ration bet aspect ratio gam aspect ratio condition no diagonal ratio dimension distortion element volume jacobian relative size scaled jacobian shape and size shear and size shear skew stretch taper
minvolumemeshquality(x, y, z, ord, "metric")
Returns the worst value of the specified element quality metric of all elements in the volume identified by the given center point coordinates and ordinal value.
Acceptable metrics include: shape aspect ration bet aspect ratio gam aspect ratio condition no diagonal ratio dimension distortion element volume jacobian relative size scaled jacobian shape and size shear and size shear skew stretch taper
minsurfacemeshquality(id, "metric")
Returns the worst value of the specified element quality metric of all elements on the given surface.
Acceptable metrics include: shape aspect ratio condition no distortion element area jacobian maximum angle minimum angle relative size scaled jacobian shape and size shear and size shear skew stretch taper warpage
minsurfacemeshquality(x, y, z, ord, "metric")
Returns the worst value of the specified element quality metric of all elements on the surface identified by the given center point coordinates and ordinal value.
Acceptable metrics include: shape aspect ratio condition no distortion element area jacobian maximum angle minimum angle relative size scaled jacobian shape and size shear and size shear skew stretch taper warpage
meshvolume(id)
Returns the total volume of all mesh elements in the volume with the given id. This will vary from the actual geometric volume since the mesh approximates curved boundaries with linear mesh edges.
meshvolume(x, y, z, ord)
Returns the total volume of all mesh elements in the volume identified by the given center point coordinates and ordinal value. This will vary from the actual geometric volume since the mesh approximates curved boundaries with linear mesh edges.
hexvolume(id)
Returns the volume of the hex with the given id.
hexvolume(x, y, z, ord)
Returns the volume of the hex identified by the given center point coordinates and ordinal value.
tetvolume(id)
Returns the volume of the tet with the given id.
tetvolume(x, y, z, ord)
Returns the volume of the tet identified by the given center point coordinates and ordinal value.
facearea(id)
Returns the area of the face with the given id.
facearea(x, y, z, ord)
Returns the area of the face identified by the given center point coordinates and ordinal value.
triarea(id)
Returns the area of the tri with the given id.
triarea(x, y, z, ord)
Returns the area of the tri identified by the given center point coordinates and ordinal value. .
meshsurfacearea(id)
Returns the total area of all triangle or quadrilateral elements on the surface with the given id. This will vary from the geometric surface area since the mesh approximates the boundary with linear mesh edges.
meshsurfacearea(x, y, z, ord)
Returns the total area of all triangle or quadrilateral elements on the surface identified by the given center point coordinates and ordinal value. This will vary from the geometric surface area since the mesh approximates the boundary with linear mesh edges.
edgelength(id)
Returns the length of the edge with the given id.
edgelength(x, y, z, ord)
Returns the length of the edge identified by the given center point coordinates and ordinal value.
meshlength(id)
Gets the length of the meshed curve with the given id.
meshlength(x, y, z, ord)
Gets the length of the meshed curve identified by the given center point coordinates and ordinal value.
nx(id), ny(id), nz(id)
Gets the x, y or z coordinate of node with the given id.
Nx(x, y, z, ord)ny(x, y, z, ord)nz(x, y, z, ord)
Gets the x, y or z coordinate of node identified by the given center point coordinates and ordinal value.
vx(id), vy(id), vz(id)
Gets the x, y or z coordinate of vertex with the given id.
vx(x, y, z, ord)vy(x, y, z, ord)vz(x, y, z, ord)
Gets the x, y or z coordinate of vertex identified by the given center point coordinates and ordinal value.
numingrp("groupname")
Returns the number of entities in the given group.
numtypeingroup("group_name", "entity_type")
Returns the number of "entity_type" in group "group_name".
numedgesoncurve(id)
Returns the number of edges on the curve with the given id.
numedgesoncurve(x, y, z, ord)
Returns the number of edges on the curve identified by the given center point coordinates and ordinal value.
numelemsonsurface(id)
Returns the number of elements on the surface with the given id.
numelemsonsurface(x, y, z, ord)
Returns the number of elements on the surface identified by the given center point coordinates and ordinal value.
numelemsinvolume(id)
Returns the number of elements in the volume with the given id.
numelemsinvolume(x, y, z, ord)
Returns the number of elements in the volume identified by the given center point coordinates and ordinal value.
numvolumes()
Returns the number of volumes in the model.
numsurfaces()
Returns the number of surfaces in the model.
numcurves()
Returns the number of curves in the model.
numvertices()
Returns the number of vertices in the model.
numvolsinpart("part_name")
Returns the number of volumes assigned to the part with the specified name.
partinvol(id)
Returns the name and instance number of the part that the volume has been assigned to.
sessionid()
Returns a unique ID for each Cubit session.
DUMP()
Returns a list of all APREPRO variables with their values.
delete("var")
Deletes the APREPRO variable with the name var.
geomcentroid_X("type", id)
Returns the x coordinate of the centroid of the specified geometric entity. "type" can be "volume" or "group". If "volume" it calculates the centroid for the volume with the given id (single volume). If "group" it must be a group of volumes and it will calculate the combined centroid for the whole group with the given id.
geomcentroid_Y("type", id)
Returns the y coordinate of the centroid of the specified geometric entity. "type" can be "volume" or "group". If "volume" it calculates the centroid for the volume with the given id (single volume). If "group" it must be a group of volumes and it will calculate the combined centroid for the whole group with the given id.
geomcentroid_Z("type", id)
Returns the z coordinate of the centroid of the specified geometric entity. "type" can be "volume" or "group". If "volume" it calculates the centroid for the volume with the given id (single volume). If "group" it must be a group of volumes and it will calculate the combined centroid for the whole group with the given id.
meshcentroid_X("type", id)
Returns the x coordinate of the centroid of the specified mesh entity. "type" can be "volume", "block", or "group". If "volume" it calculates the centroid of the 3D elements in the volume with the given id. If "block" it calculates the centroid of the elements in the block with the given id. If "group" it must be a group of volumes and it calculates the centroid of the group with the given id.
meshcentroid_Y("type", id)
Returns the y coordinate of the centroid of the specified mesh entity. "type" can be "volume", "block", or "group". If "volume" it calculates the centroid of the 3D elements in the volume with the given id. If "block" it calculates the centroid of the elements in the block with the given id. If "group" it must be a group of volumes and it calculates the centroid of the group with the given id.
meshcentroid_Z("type", id)
Returns the z coordinate of the centroid of the specified mesh entity. "type" can be "volume", "block", or "group". If "volume" it calculates the centroid of the 3D elements in the volume with the given id. If "block" it calculates the centroid of the elements in the block with the given id. If "group" it must be a group of volumes and it calculates the centroid of the group with the given id.
Bbox_Xmin("type", id)
Returns the xmin value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
Bbox_Xmax("type", id)
Returns the xmax value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
Bbox_Ymin("type", id)
Returns the ymin value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
Bbox_Ymax("type", id)
Returns the ymax value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
Bbox_Zmin("type", id)
Returns the zmin value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
Bbox_Zmax("type", id)
Returns the zmax value of the bounding box of the specified geometric entity. "type" can be "volume", "surface", "curve", "vertex", or "group". If "volume", "surface", "curve", or "vertex" it will calculate the bounding box for the entity with the given id. If "group" it will calculate the combined bounding box for the group. A group can have any of the geometry types (vol, surf, curve, vert) in it and can be of mixed types.
nodeat(x, y, z)
Returns the id of the node closest to the xyz location.
nodeat(x, y, z, ordinal)
Returns the id of the Node with the idless reference, x,y,z,ordinal.
edgeat(x, y, z, ordinal)
Returns the id of the edge with the idless reference, x,y,z,ordinal.
faceat(x, y, z, ordinal)
Returns the id of the quad face with the idless reference, x,y,z,ordinal.
triat(x, y, z, ordinal)
Returns the id of the triangle with the idless reference, x,y,z,ordinal.
hexat(x, y, z, ordinal)
Returns the id of the hexahedra element with the idless reference, x,y,z,ordinal.
tetat(x, y, z, ordinal)
Returns the id of the tetraheral element with the idless reference, x,y,z,ordinal.
wedgeat(x, y, z, ordinal)
Returns the id of the wedge element with the idless reference, x,y,z,ordinal.
pyramidat(x, y, z, ordinal)
Returns the id of the pyramid element with the idless reference, x,y,z,ordinal.
vertexat(x, y, z, ordinal)
Returns the id of the vertex with the idless reference, x,y,z,ordinal.
curveat(x, y, z, ordinal)
Returns the id of the curve with the idless reference, x,y,z,ordinal.
surfaceat(x, y, z, ordinal)
Returns the id of the surface with the idless reference, x,y,z,ordinal.
volumeat(x, y, z, ordinal)
Returns the id of the volume with the idless reference, x,y,z,ordinal.
15.2.2.33.String Functions
A few useful string functions are available:
Table 3. String Functions
Syntax
Description
tolower(svar)
Translates all uppercase characters in svar to lowercase. It modifies svar and returns the resulting string.
toupper(svar)
Translates all lowercase character in svar to uppercase. It modifies svar and returns the resulting string.
execute(svar)
svar is parsed and executed as if it were a line read from the input file. For example,
if svar="b=sqrt(25.0)", then #{execute(svar)}
returns the value 5 and sets b = 5. The expression svar is enclosed in delimiters prior to being executed, and it must be a valid expression or an error message will be printed.
rescan(svar)
Similar to execute(svar), except that svar is not enclosed in delimiters prior to being executed. For example,
if svar = "create vertex {1+5} {sqrt(5)} {sqrt(6)}", then #{rescan(svar)}
would print:
create vertex 6 2.236067977 2.449489743.
The difference between execute(sv1) and rescan(sv2) is that sv1 must be a valid expression, but sv2 can contain zero or more expressions.
getenv(svar)
Returns a string containing the value of the environment variable svar. If the environment variable is not defined, an empty string is returned.
get_word(n,svar,del)
Returns a string containing the nth word of svar. The words are separated by one or more of the characters in the string variable del
word_count(svar,del)
Returns the number of words in svar. Words are separated by one or more of the characters in the string variable del
strtod(svar)
Returns a double-precision floating-point number equal to the value represented by the character string pointed to by svar.
print(msg)
Prints msg
printerror(svar)
Outputs the string svar to stderr.
error(svar)
Outputs the string svar to stderr and then terminates the code with an error exit status
quote(svar)
Returns the string svar, enclosed in single quotes.
timerstart()
Starts the CPU timer
timerstop()
Stops the CPU timer
type(entity name)
Returns the type of the entity with the given name
units(svar)
Sets variables useful for working in a unit system. See APREPRO Units.
The following example shows the use of some of the string functions.
#{t1 = "ATAN2"} {t2 = "(0, -1)"}
#{t3 = tolower(t1//t2)}
...The variable t3 is equal to the string atan2(0, -1)
#{execute(t3)}
...t3 = 3.141592654
The result is the same as executing {atan2(0, -1)}
This is admittedly a very contrived example; however, it does illustrate the workings of several of the functions. In the first example, an expression is constructed by concatenating two strings together and converting the resulting string to lowercase. This string is then executed.
The following example uses the rescan function to illustrate a basic macro capability in APREPRO. The example creates vertices in Cubit equally spaced about the circumference of a 180 degree arc of radius 10. Note that the macro is 5 lines long (3 of the lines start with #, with the exception of the looping constructs - the actual journal file for this would not continue lines but would put each one on one long line).
A few useful string functions are available: Table 3. String Functions
Syntax
Description
tolower(svar)
Translates all uppercase characters in svar to lowercase. It modifies svar and returns the resulting string.
toupper(svar)
Translates all lowercase character in svar to uppercase. It modifies svar and returns the resulting string.
execute(svar)
svar is parsed and executed as if it were a line read from the input file. For example, if svar="b=sqrt(25.0)", then #{execute(svar)} returns the value 5 and sets b = 5. The expression svar is enclosed in delimiters prior to being executed, and it must be a valid expression or an error message will be printed.
rescan(svar)
Similar to execute(svar), except that svar is not enclosed in delimiters prior to being executed. For example, if svar = "Create Vertex {1+5} {sqrt(5)} {sqrt(6)}", then #{rescan(svar)} would print: Create Vertex 6 2.236067977 2.449489743. The difference between execute(sv1) and rescan(sv2) is that sv1 must be a valid expression, but sv2 can contain zero or more expressions.
getenv(svar)
Returns a string containing the value of the environment variable svar. If the environment variable is not defined, an empty string is returned.
get_word(n,svar,del)
Returns a string containing the nth word of svar. The words are separated by one or more of the characters in the string variable del
word_count(svar,del)
Returns the number of words in svar. Words are separated by one or more of the characters in the string variable del
strtod(svar)
Returns a double-precision floating-point number equal to the value represented by the character string pointed to by svar.
Print(msg)
Prints msg
PrintError(svar)
Outputs the string svar to stderr.
error(svar)
Outputs the string svar to stderr and then terminates the code with an error exit status
Quote(svar)
Returns the string svar, enclosed in single quotes.
TimerStart()
Starts the CPU timer
TimerStop()
Stops the CPU timer
Type(entity name)
Returns the type of the entity with the given name
Units(svar)
Sets variables useful for working in a unit system. See APREPRO Units.
#{loop(nloop)}
#{rescan(line)}
#{endloop}
Output:
create vertex 10 0
create vertex 9.510565163 3.090169944
create vertex 8.090169944 5.877852523
create vertex 5.877852523 8.090169944
create vertex 3.090169944 9.510565163
create vertex 6.123233765e-16 10
create vertex -3.090169944 9.510565163
create vertex -5.877852523 8.090169944
create vertex -8.090169944 5.877852523
create vertex -9.510565163 3.090169944
create vertex -10 1.224646753e-15
Note the loop construct to automatically repeat the rescan line. To modify this example to calculate the coordinates of 101 points rather than eleven, the only change necessary would be to set {nintv=100}.
Note the loop construct to automatically repeat the rescan line. To modify this example to calculate the coordinates of 101 points rather than eleven, the only change necessary would be to set {nintv=100}.
15.2.3APREPRO Journaling
When using APREPRO, statements can be echoed to a journal file. To do so, use the following command:
Simply typing "journal aprepro" without an argument will display the current aprepro journaling setting.
For example,
bri x {2*5.0}
is journaled as
brick x {2*5.0}
if aprepro journaling is ON, or
brick x 10
if aprepro journaling is off. The default is ON.
15.2.3.1APREPRO Comments
Comments are also journaled. This is useful for documenting aprepro definitions and descriptions.
Comments on the same line as a command get split into two separate lines in the journal file.
15.2.3.2Significant Figures
When journal aprepro is ON, numbers are journaled exactly as they are entered. The maximum number of significant digits is determined by the command input.
When journal aprepro is off, numeric results of aprepro statements are journaled according to the maximum number of significant digits hard-coded into Cubit, using the value of DBL_DIG.
15.2.3.3Loops and Journaling
Loops are not journaled as loops, per se. For example, the APREPRO expression:
{loop(3)}
bri x {x}
{endloop}
is journaled as:
bri x \{x\}
bri x \{x\}
bri x \{x\}
15.2.3.4Multi-line Strings
Multi-line strings are currently not journaled (both definitions and when they are expanded). For example,
#{line = ’bri x 10
mesh vol 1’}
{line}
will be journaled as
bri x 10
mesh vol 1
Note that bri x 10\n mesh vol 1 was not journaled as {line}
15.2.4APREPRO Operators
The operators recognized by APREPRO are listed below.
In the following table, the letters a and b can represent variables, numbers, functions, or expressions unless otherwise noted. The tables below also list the precedence and associativity of the operators. Precedence defines the order in which operations should be performed. For example, in the expression:
3 * 4 + 6 / 2
the multiplications and divisions are performed first, followed by the addition because multiplication and division have higher precedence than addition. The precedence is listed from 1 to 14 with 1 being the lowest precedence and 14 being the highest.
Associativity defines which side of the expressions should be simplified first. For example the expression: 3 + 4 + 5 would be evaluated as (3 + 4) + 5 for left associativity, the expression a = b / c would be evaluated as a = (b / c) for right associativity.
Note: Operators must not be separated from operands by white space. For example, the expressions x_coord-1 and x_coord -1 will parse correctly, while the expressions x_coord - 1 and x_coord- 1 will not parse correctly.
15.2.4.11. Arithmetic Operators
Arithmetic operators combine two or more algebraic expressions into a single algebraic expression. These have obvious meanings except for the pre- and post- increment and decrement operators. The pre-increment and pre-decrement operators first increment or decrement the value of the variable and then return the value. For example, if a = 1, then b=++a will set both b and a equal to 2. The post-increment and post-decrement operators first return the value of the variable and then increment or decrement the variable. For example, if a = 1, then b=a++ will set b equal to 1 and a equal to 2. The modulus operator % calculates the integer remainder. That is both expressions are truncated an integer value and then the remainder calculated. See the fmod function in Mathematical Functions, for the calculation of the floating point remainder. The tilde character ~ is used as a synonym for multiplication to improve the aesthetics of the APREPRO unit conversion system (however, the unit conversions system is not supported in Cubit). It is more natural for some users to type 12~metre than 12*metre
Table 1. Arithmetic Operators
Syntax
Description
Precedence
Associativity
a+b
Addition
9
left
a-b
Subtraction
9
left
a*b, a~b
Multiplication
10
left
a/b
Division
10
left
a^b, a**b
Exponentiation
12
right
a%b
Modulus (remainder)
10
left
++a, a++
Pre-, post-increment
13
left
–a, a–
Pre-, post-decrement
13
left
15.2.4.22. Assignment Operators
Assignment operators combine a variable and an algebraic expression into a single algebraic expression, and also set the variable equal to the algebraic expression. Only variables can be specified on the left-hand-side of the equal sign.
Table 2. Assignment Operators
Syntax
Description
Precedence
Associativity
a=b
The value of ’a’ is set equal to ’b’
1
right
a+=b
The value of ’a’ is set equal to a + b
2
right
a-=b
The value of ’a’ is set equal to a - b
2
right
a*=b
The value of ’a’ is set equal to a * b
3
right
a/=b
The value of ’a’ is set equal to a / b
3
right
a^=b
The value of ’a’ is set equal to a b
4
right
a**=b
The value of ’a’ is set equal to a b
4
right
15.2.4.33. Relational Operators
Relational operators combine two algebraic expressions into a single relational expression. Relational expressions and operators can only be used before the question mark (?) in a conditional expression.
Table 3. Relational Operators
Syntax
Description
Precedence
Associativity
a<b
true if ’a’ is less than ’b’
8
left
a>b
true if ’a’ is greater than ’b’
8
left
a<=b
true if ’a’ is less than or equal to ’b’
8
left
a>=b
true if ’a’ is greater than or equal to ’b’
8
left
a==b
true if ’a’ is equal to ’b’
8
left
a!=b
true if ’a’ is not equal to ’b’
8
left
15.2.4.44. Boolean Operators
Boolean operators combine one or more relational expressions into a single relational expression. If la and lb are two relational expressions, then:
Table 4. Boolean Operators
Syntax
Description
Precedence
Associativity
1a || 1b
true if either ’la’ or ’lb’ are true.
6
left
1a && 1b
true if both ’la’ and ’lb’ are true.
7
left
!1a
true if ’la’ is false.
11
left
15.2.4.55. String Operators
The only supported string operator at this time is string concatenation, which is denoted by //. If a = "hello" and b = "world", then:
c = a // " " // b
sets c equal to "hello world". Concatenation has precedence 14 and left associativity. Also see String Functions
15.2.5APREPRO Predefined Variables
A few commonly used variables are predefined in APREPRO. These are listed below. The default output format is specified as a C language format string, see your C language documentation for more information. The default format and comment variables are defined with a leading underscore in their name so they can be redefined without generating an error message.
Table 1. Predefined Variables
Name
Value
Description
PI
3.14159265358979323846
PI_2
1.57079632679489661923
SQRT2
1.41421356237309504880
DEG
57.2957795130823208768
RAD
0.01745329251994329576
E
2.71828182845904523536
base of natural logarithm
GAMMA
0.57721566490153286060
Euler-Mascheroni constant1
PHI
1.61803398874989484820
(aka "The Golden Ratio")
CUBIT_VERSION
Varies, string value
current version of Cubit
VERSION
Varies, string value
current version of APREPRO
_ FORMAT
"%.10g"
default output format
_C_
"#"
default comment character
1 The Euler-Mascheroni constant is defined as .
Note that the output format is used to output both integers and floating point numbers. Therefore, it should use the %g format descriptor which will use either the decimal (%d), exponential (%e), or float (%f) format, whichever is shorter, with insignificant zeros suppressed. The table below illustrates the effect of different format specifications on the output of the variable PI and the value 1.0 . See the documentation of your C compiler for
Table 2. Effect of Various Output Format Specifications more information. For most cases, the default value is sufficient.
format
PI output
1.0 output
%.10g
3.141592654
1
%.10e
3.1415926536e+00
1.0000000000e+00
%.10f
3.1415926536
1.0000000000
%.10d
1413754136
0000000000
15.2.6APREPRO Rules
The rules that APREPRO uses when identifying functions, variables, numbers, operators, delimiters, and expressions are described below:
15.2.6.11. Functions
Function names are sequences of letters and digits and underscores (_) that begin with a letter. The function’s arguments are enclosed in parentheses. For example, in the line atan2(a,1.0), atan2 is the function name, and a and 1.0 are the arguments. See APREPRO Functions for a list of the available functions and their arguments.
15.2.6.22. Variables
A variable is a name that references a numeric or string value. A variable is defined by giving it a name and assigning it a value. For example, the expression a = 1.0 defines the variable a with the numeric value 1.0; the expression b= "A string" defines the variable b with the value "A string". Variable names are sequences of letters, digits, and underscores (_) that begin with either a letter or an underscore. Variable names cannot match any function name and they are case-sensitive, that is, abc_de and abC_dE are two distinct variable names. A few variables are predefined, these are listed in APREPRO Predefined Variables. Any variable that is not defined is equal to 0. A warning message is output to the terminal if an undefined variable is used, or if a previously defined variable is redefined. To see a list of all of the current APREPRO variables use the DUMP() command.
A variable is a name that references a numeric or string value. A variable is defined by giving it a name and assigning it a value. For example, the expression a = 1.0 defines the variable a with the numeric value 1.0; the expression b= "A string" defines the variable b with the value "A string". Variable names are sequences of letters, digits, and underscores (_) that begin with either a letter or an underscore. Variable names cannot match any function name and they are case-sensitive, that is, abc_de and AbC_dE are two distinct variable names. A few variables are predefined, these are listed in APREPRO Predefined Variables. Any variable that is not defined is equal to 0. A warning message is output to the terminal if an undefined variable is used, or if a previously defined variable is redefined. To see a list of all of the current APREPRO variables use the DUMP() command.
15.2.6.33. Numbers
Numbers can be integers like 1234, decimal numbers like 1.234, or in scientific notation like 1.234E-26. All numbers are stored internally as floating point numbers.
15.2.6.44. Strings
Strings are sequences of numbers, characters, and symbols that are delimited by either single quotes (’this is a string’) or double quotes ("this is another string"). Strings that are delimited by one type of quote can include the other type of quote. For example, {’This is a valid "string"’}. Strings delimited by single quotes can span multiple lines; strings delimited by double quotes must terminate on a single line or a parsing error message will be issued.
15.2.6.55. Operators
Operators are any of the symbols defined in APREPRO Operators. Examples are + (addition), - (subtraction), * (multiplication), / (division), = (assignment), and ^ (exponentiation).
15.2.6.66. Delimiters
The delimiters recognized by APREPRO are: the comma (,) which separates arguments in function lists, the left curly brace ({) which begins an expression, the right curly brace (}) which ends an expression, the left parenthesis ( which begins a function argument list, the right parenthesis ) which ends a function argument list, the single quote (’) which delimits a multi-line string, and the double quote (") which delimits a single-line string.
15.2.6.77. Expressions
An expression consists of any combination of numeric and string constants, variables, operators, and functions. Four types of expressions are recognized in APREPRO: algebraic, string, relational, and conditional.
15.2.6.88. Algebraic Expressions
Almost any valid FORTRAN or C algebraic expression can be recognized and evaluated by APREPRO. An expression of the form a=b+10/37.5 will evaluate the expression on the right-hand-side of the equals sign and assign the value to the variable a. An expression of the form b+10/37.5 will simply evaluate the expression. Variables can also be set on the command line prior to playing any journal files using the ’var=val’ syntax. Only a single expression is allowed within the { } delimiters. For example, {x = sqrt(y^2 + sin(z))}, {x=y=z}, and {x=y} {a=z} are valid expressions, but {x=y a=z} is invalid because it contains two expressions within a single set of delimiters.
15.2.6.99. String Expressions
APREPRO has very limited string support. The only supported operations are assigning a variable equal to a string (a = "this is a string") or a function that returns a string, and concatenating two strings into another string (a = "hello" // " " // "world").
15.2.6.1010. Relational Expressions
Relational expressions are expressions that return the result of comparing two expressions. A relational expression is either true or false. Relational expressions can only be used on the left-hand side of a conditional expression. A relational expression is simply two expressions of any kind separated by a relational operator. See Relational Operators.
15.2.6.1111. Conditional Expressions
APREPRO recognizes a conditional expression of the form::
relational_expression ? true_exp : false_exp
where relational_expression can be any valid relational expression, and true_exp and false_exp are two algebraic expressions. If the relational expression is true, then the result of true_exp is returned, otherwise the result of false_exp is returned. For example, if the following command were entered:
#{a = (sind(20.0) > cosd(20.0) ? 1 : -1)}
then, a would be assigned the value -1 since the relational expression to the left of the question mark is false. Both true_exp and false_exp are always evaluated prior to valuating the relational expression. Therefore, you should not write an equation such as
White space in APREPRO can be important. For example, the following expressions will parse correctly:
x_coord-1 and x_coord -1
The following expressions will not parse:
x_coord- 1 and x_coord - 1
The operator must not be separated from the operand by white space.
15.2.6.1313. Switch Statements
Please refer to the current APREPRO documentation for details.
a = 10*PIswitch(10*PI + sin(0))... This is ignored since it is after the switch, but before any case() statementscase(1)... This is not executed since 1 is not equal to 10*PI+sin(0)case(a)... This is executed since a matches the value of 10*PI+sin(0)case(10*PI+sin(0))... This is not executed since a previous case was executed.default... This is not executed since a previous case was executed. endswitch ... This is executed since the switch constructis finished.
15.2.6.1414. Conditionals and Loops
As of Cubit 15.0, ’ifdef’ and ’ifndef’ are deprecated. Use if(expression) and if (!expression) instead
As of Cubit 15.0, elseif(expression) is valid
{abortloop} will terminate all nested loops without expanding the loop . This is useful when typing in a loop at the command line and you make a mistake.
A warning is issued to indicate to the user that they have started an APREPRO loop and that all subsequent commands will have no effect until the corresponding {endloop} or {abortloop} has been reached.