3 The 'mechsim.inc' include file
This part of the Sim-POV documentation describes the 'mechsim.inc' include file that comes with Sim-POV and contains various macros simplifying the use of Sim-POV features.
The 'mechsim.inc' include file contains several macros so simplify the generation of simulation topologies as well as macros building POV-Ray objects representing the simulation data.
3.1 general aspects
At the beginning of the file there are various declarations of textures and other things that are used by the macros. In most cases you can override the default values by declaring the identifiers differently before including the file.
MSIM_INCLUDE_VERSION
The version number of the 'mechsim.inc' include file.
No_Trans
A dummy transform that can be used in the topology generation macros if no transform is supposed to be used.
MSim_File_Decimals
The number of decimal places to be written to files for coordinates.
Default value is 12
.
MSim_Test_Render
If true
reflection is turned off for the textures in
this include file. Default value is false
.
MSim_Tex_N
Texture to be used for texturing the nodes (masses) of the simulation topology. A grey metallic texture by default.
MSim_Tex_C
Texture to be used for texturing the connections of the simulation topology. A gold metallic texture by default.
MSim_Tex_Mesh
Texture to be used for texturing the faces of the simulation topology. A bluish metallic texture by default.
fn_Stress_CM
Color map function to use for visualizing the stress in simulation topologies. A color (pigment) function is used here. It is evaluated in x-direction between 0 and 1.
3.2 The Object generation macros
These macros generate POV-Ray objects from the simulation data. Currently there are macros for general topology visualization and specific macros for generating meshes from patch topologies created with the patch generation macros.
3.2.1 MechSim_Show_Objects()
This macro generates POV-Ray shapes for all masses and connections or faces from a certain range of the simulation data.
Depending on the value of the Show_Faces
parameter the macro will
either generate a union of cylinders and spheres representing the masses and
connections or a mesh with triangles representing the faces.
parameters:
Start_Mass_Index,
- the starting indices of the range of simulation elements that should be displayed by the macro.
Start_Connection_Index,
Start_Face_Index,End_Mass_Index,
- the end indices of the range of simulation elements that should be displayed by the macro. If one of this values is
End_Connection_Index,
End_Face_Index,<0
all elements until the last one are displayed.Connect_Rad
- the radius to use for the connections. If this value is<0
the macro uses0.4*
the mass radius for this. If this value is 0 no cylinders are generated for the connections.Show_Faces
- iftrue
only a mesh representing the faces is generated. Iffalse
connections are represented by cylinders and masses by spheres.Stress_Fact
- if>0
the connections are textured to visualize the stress. Thefn_Stress_CM
function is used for the colors. The extension from relaxed length is scaled with this factor. If this value is<0
the connections are textured withMSim_Tex_C
.File_Name
- file name string. If its length is zero file writing is turned off, otherwise the geometry is written to a file with that name in addition.
example:
// show all masses and connections
MechSim_Show_Objects(0, 0, 0, -1, -1, -1, -1, false, -1, "")
// declare an object of all faces
#declare Obj=MechSim_Show_Objects(0, 0, 0, -1, -1, -1, -1, true, -1, "")
// show a subset of connections and faces, texture connections
// to visualize stress, write objects to file
MechSim_Show_Objects(0, 0, 0, 100, 300, 0, -1, false, 120, "sim01.inc")
3.2.2 MechSim_Show_All_Objects()
Variation of the MechSim_Show_Objects() macro displaying all elements of the current simulation data.
parameters:
Connect_Rad
- the radius to use for the connections. If this value is<0
the macro uses0.4*
the mass radius for this. If this value is 0 no cylinders are generated for the connections.Show_Faces
- iftrue
only a mesh representing the faces is generated. Iffalse
connections are represented by cylinders and masses by spheres.Stress_Fact
- if>0
the connections are textured to visualize the stress. Thefn_Stress_CM
function is used for the colors. The extension from relaxed length is scaled with this factor. If this value is<0
the connections are textured withMSim_Tex_C
.File_Name
- file name string. If its length is zero file writing is turned off, otherwise the geometry is written to a file with that name in addition.
example:
// show all masses and connections
MechSim_Show_All_Objects(-1, false, -1, "")
// declare an object of all faces
#declare Obj=MechSim_Show_All_Objects(-1, true, -1, "")
3.2.3 MechSim_Show_Patch()
This macro generates a mesh from the patch topology created with the
MechSim_Generate_Patch() macro. The mesh
is generated in form of the new mesh2
type and optionally includes
uv- and normal data depending on the parameters.
parameters:
Start_Face_Index
- the index of the first face that is part of the patch. This should be stored when the patch is generated. The other starting indices are calculated internally.XSize, YSize
- size of the patch, number of nodes in x- and y-direction.Smooth
- iftrue
normal vectors are generated so the mesh is smoothed.UV
- iftrue
uv-coordinates are generated ranging from 0 to 1 in x-Direction (range in y-Direction depends on the ratio of XSize to YSize).Stress_Fact
- if>0
the triangles of the mesh are textured on per vertex basis to visualize the stress. Thefn_Stress_CM
function is used for the colors. The connection's extension from relaxed length is scaled with this factor. If this value is<0
the whole mesh is textured withMSim_Tex_Mesh
.File_Name
- file name string. If its length is zero file writing is turned off, otherwise the geometry is written to a file with that name in addition.
example:
// show a 50x50 patch with smoothing
MechSim_Show_Patch(0, 50, 50, true, false, -1, )
// declare an object for the patch, generate uv coordinates
// and normal vectors, write the results to a file
#declare Obj=MechSim_Show_Patch(0, 50, 50, true, true, -1, sim01.inc)
Here a comparison between the different methods and variations:
cylinders and spheres | face triangles | patch macro (stress visualization) |
---|---|---|
no smooth, no uv | smooth | uv mapped |
3.3 The topology generation macros
These macros are supposed to be placed in the topology{}
block of the
mechsim{}
section. They generate the masses, connections and faces for
certain geometries.
3.3.1 explanation of the 'Connect_Arr' parameter
Most of the macros have a parameter named Connect_Arr
. This is an
array
containing weighting factors for the different connections in.
The objects generated by the macros have different types of connections: axis-parallel connections, 2D and 3D diagonal connections and possibly bending connections. How these connections are weighted influences the properties of the object and can be controlled by the values in this array. Which value refers to which type of connection depends on the macro and is mentioned in the macro description.
3.3.3 MechSim_Generate_Grid_Fn()
This macro generates 3D rectangular grid of masses with connections and optionally faces on the outside. The density of the masses as well as the stiffness and damping of the connections can be varied with functions.
The generated box starts at the origin and extends in positive x, y and z-direction.
parameters:
Velocity
- vector defining the starting velocity of all masses.Radius
- radius of all masses.fn_Density
- user defined function controlling the density of the masses. x, y and z are evaluated in [0..1] range.fn_Stiffness
- user defined function controlling the stiffness of the connections.fn_Damping
- user defined function controlling the damping of the connections.Faces
- iftrue
faces are generated on the outside shape.Cube_Scale
- 3D vector controlling the distances in the grid. It defines the size of an elementary cell.Grid_Size
- 3D vector containing the number of masses in all three directions.Transf
- Transform to be applied to all mass positions.Connect_Arr
- Array containing weights for connection stiffness and damping. Meaning of the array fields is described below.
meaning of the 'Connect_Arr' entries:
See a description of this array in general. If the first entry is 0 no connections are generated. The individual entries are used for the following connections. Only connections up to the size of the array are generated.
0
- axis-parallel connections.1
- the first diagonal connection in each grid rectangle.2
- the second diagonal connection in each grid rectangle.3
- the 3d diagonal connections
The following pictures illustrate the different sizes of the array:
0 (first element zero) | array size 1 | array size 2 |
---|---|---|
array size 3 | array size 4 |
example code:
// generate a 4x4x4 masses grid with double diagonal connections
// and increasing stiffness and damping in x-direction
#declare Con_Array=array[3]
#declare Con_Array[0]=1;
#declare Con_Array[1]=1;
#declare Con_Array[2]=1;
#declare fn_Density=function(x, y, z) { 32000 }
#declare fn_Stiffness=function(x, y, z) { 1000 + x*1500 }
#declare fn_Damping=function(x, y, z) { 2000 + x*1500 }
MechSim_Generate_Grid_Fn(<0, 0, 0>, 0.08, fn_Density, fn_Stiffness, fn_Damping,
true, <0.4, 0.4, 0.4>, <4, 4, 4>, No_Trans, Con_Array)
3.3.4 MechSim_Generate_Grid()
This macro generates 3D rectangular grid of masses with connections and optionally faces on the outside. In contrast to the MechSim_Generate_Grid_Fn() macro the density stiffness and damping values are fixed.
parameters:
Velocity
- vector defining the starting velocity of all masses.Radius
- radius of all masses.Density
- density of the masses.Stiffness
- stiffness of the connections.Damping
- damping of the connections.Faces
- iftrue
faces are generated on the outside shape.Cube_Scale
- 3D vector controlling the distances in the grid. It defines the size of an elementary cell.Grid_Size
- 3D vector containing the number of masses in all three directions.Transf
- Transform to be applied to all mass positions.Connect_Arr
- Array containing weights for connection stiffness and damping. Meaning of the array fields in described in the MechSim_Generate_Grid_Fn() section.
example code:
// generate a 4x4x4 masses grid with double diagonal connections
#declare Con_Array=array[3]
#declare Con_Array[0]=1;
#declare Con_Array[1]=1;
#declare Con_Array[2]=1;
MechSim_Generate_Grid(<0, 0, 0>, 0.08, 32000, 1000, 2000,
true, <0.4, 0.4, 0.4>, <4, 4, 4>, No_Trans, Con_Array)
3.3.5 MechSim_Generate_Grid_Std()
This macro generates 3D rectangular grid of masses with connections and optionally faces on the outside. In contrast to the MechSim_Generate_Grid() macro all connections all have the same stiffness and damping.
parameters:
Velocity
- vector defining the starting velocity of all masses.Radius
- radius of all masses.Density
- density of the masses.Stiffness
- stiffness of the connections.Damping
- damping of the connections.Faces
- iftrue
faces are generated on the outside shape.Cube_Scale
- 3D vector controlling the distances in the grid. It defines the size of an elementary cell.Grid_Size
- 3D vector containing the number of masses in all three directions.Transf
- Transform to be applied to all mass positions.Diagonal
- A number controlling which diagonal connections are generated in the grid It corresponds to the array size in the MechSim_Generate_Grid() macro.
example code:
// generate a 4x4x4 masses grid with double diagonal connections
MechSim_Generate_Grid_Std(<0, 0, 0>, 0.08, 32000, 1000, 2000,
true, <0.4, 0.4, 0.4>, <4, 4, 4>, No_Trans, 3)
3.3.6 MechSim_Generate_Box()
Variation of the MechSim_Generate_Grid_Std() macro where instead of the density of the individual masses the mass of the whole grid is given.
parameters:
Velocity
- vector defining the starting velocity of all masses.Radius
- radius of all masses.Mass
- mass of the whole grid.Stiffness
- stiffness of the connections.Damping
- damping of the connections.Faces
- iftrue
faces are generated on the outside shape.Cube_Scale
- 3D vector controlling the distances in the grid. It defines the size of an elementary cell.Grid_Size
- 3D vector containing the number of masses in all three directions.Transf
- Transform to be applied to all mass positions.Diagonal
- A number controlling which diagonal connections are generated in the grid It corresponds to the array size in the MechSim_Generate_Grid() macro.
example code:
// generate a 4x4x4 masses grid with double diagonal connections
// and a total mass of 20 kg
MechSim_Generate_Box(<0, 0, 0>, 0.08, 20, 1000, 2000,
true, <0.4, 0.4, 0.4>, <4, 4, 4>, No_Trans, 3)
3.3.7 MechSim_Generate_Patch()
This macro generates a rectangular patch of masses with connections and optionally faces forming the surface. The masses can be fixed with help of a function
parameters:
Velocity
- vector defining the starting velocity of all masses.Radius
- radius of all masses.Density
- density of the masses.Stiffness
- stiffness of the connections.Damping
- damping of the connections.Faces
- iftrue
faces are generated for the surface of the patch.Rect_Scale
- 2D vector controlling the distances in the grid. It defines the size of an elementary rectangle.Grid_Size
- 2D vector containing the number of masses in x and y direction.Transf
- Transform to be applied to all mass positions.fn_Fixed
- user defined function controlling whether the masses are fixed or not. The function is evaluated in the x-y-plane between 0 and 1. If the function value at a mass position is >0 the mass is fixed.Connect_Arr
- Array containing weights for connection stiffness and damping. Meaning of the array fields in described below.
meaning of the 'Connect_Arr' entries:
See a description of this array in general. The following picture shows which entries in the array weight which connections. Only connections up to the size of the array are generated.
example code:
// generate a 50x50 patch with bending and shearing stiffness
// no masses are fixed
#declare fn_Fixed=function { -1 }
#declare Con_Array=array[3]
#declare Con_Array[0]=1;
#declare Con_Array[1]=1;
#declare Con_Array[2]=1;
MechSim_Generate_Patch(<0, 0, 0>, 0.065, 8000, 10000, 0,
true, <0.055, 0.055>, <50, 50>, No_Trans, fn_Fixed, Con_Array)
3.3.8 MechSim_Generate_Patch_Std()
This macro generates a rectangular patch of masses with connections and optionally faces forming the surface. In contrast to the MechSim_Generate_Patch() macro all connections all have the same stiffness and damping. Also none of the masses is fixed.
parameters:
Velocity
- vector defining the starting velocity of all masses.Radius
- radius of all masses.Density
- density of the masses.Stiffness
- stiffness of the connections.Damping
- damping of the connections.Faces
- iftrue
faces are generated for the surface of the patch.Rect_Scale
- 2D vector controlling the distances in the grid. It defines the size of an elementary rectangle.Grid_Size
- 2D vector containing the number of masses in x and y direction.Transf
- Transform to be applied to all mass positions.Connect
- A number controlling which connections are generated in the grid It corresponds to the array size in the MechSim_Generate_Patch() macro.
example code:
// generate a 50x50 with bending and shearing stiffness
MechSim_Generate_Patch_Std(<0, 0, 0>, 0.065, 8000, 10000, 0,
true, <0.055, 0.055>, <50, 50>, No_Trans, 3)
3.3.9 MechSim_Generate_Line()
This macro generates a line of connected masses and can be used for simulating things like ropes, chains, etc. The masses of the line can be fixed with help of a function
parameters:
Velocity
- vector defining the starting velocity of all masses.Radius
- radius of all masses.Density
- density of the masses.Stiffness
- stiffness of the connections.Damping
- damping of the connections.Spacing
- distance between two neighboring masses.Count
- total number of masses.Direction
- 3D vector defining the direction of the line from the origin.Transf
- Transform to be applied to all mass positions.fn_Fixed
- user defined function controlling whether the masses are fixed or not. The function is evaluated in the x-direction between 0 and 1. If the function value at a mass position is >0 the mass is fixed.Connect_Arr
- Array containing weights for connection stiffness and damping. Meaning of the array fields in described below.
meaning of the 'Connect_Arr' entries:
See a description of this array in general. The first element of the array weights the direct connections between two neighboring masses. Further values in the array weight the more distant connections that introduce bending stiffness to the line. Only connections up to the size of the array are generated.
example code:
// generate a 10 masses line with bending stiffness
// no masses are fixed
#declare fn_Fixed=function { -1 }
#declare Con_Array=array[2]
#declare Con_Array[0]=1;
#declare Con_Array[1]=1;
MechSim_Generate_Line(<0, 0, 0>, 0.09, 8000, 10000, 0,
0.45, 10, <1, 1, 1>, No_Trans, fn_Fixed, Con_Array)
3.3.10 MechSim_Generate_Line_Std()
This macro generates a line of connected masses and can be used for simulating things like ropes, chains, etc.. In contrast to the MechSim_Generate_Line() macro only shortest distance connections are generated. Also none of the masses is fixed.
parameters:
Velocity
- vector defining the starting velocity of all masses.Radius
- radius of all masses.Density
- density of the masses.Stiffness
- stiffness of the connections.Damping
- damping of the connections.Spacing
- distance between two neighboring masses.Count
- total number of masses.Direction
- 3D vector defining the direction of the line from the origin.Transf
- Transform to be applied to all mass positions.
example code:
// generate a 10 masses line
MechSim_Generate_Line(<0, 0, 0>, 0.09, 8000, 10000, 0,
0.45, 10, <1, 1, 1>, No_Trans)