The fields and parameters of the main configuration file (.spd) of the data tree, are described below.
<PT_data>
Main root field of the .spd file. It contains the version number and the name of the problem type.
PT must be replaced by the problem type name.
version - Internal version number.
e.g. if the problemtype is named 'cmas2d_customlib' the main node will be
<cmas2d_customlib_data version='1.0'>
...
</cmas2d_customlib_data>
<container>
This is the simplest form to group the data for improving its visualization.
On the resulting window, in addition to the inputs there will be the following set of buttons:
It can contain the following fields: <value>, <container>, <condition>, <function>, <dependencies>
The parameters are as follows,
n - Name used to reference the field, especially when writing the .dat file.
pn - Label that will be visualized by the user. It can be translated.
icon - It allows to put an image in .png format in the data tree. The image should be stored inside the images folder of the problem type.
help - It displays a pop-up window of help information related to the task the user is performing.
state - Specifies one of two states for the field: normal, or hidden. Note that hidden <container> field can be used for storing hidden values, that you do not want to show in the user interface. It also permits to handle a Tcl function, by means of square brackets.
update_proc - It calls a TCL procedure, when clicking on the 'Ok' button in the window. Square brackets are not supported.
actualize_tree - Itupdates the information in the whole data tree, and automatically refresh data shown in the user interface. It is a boolean value as a 1 or 0 that indicates if it is activated or deactivated. If the data source is changed, such as new fields have been added or data values and field have been modified, all the user interface will reflect those changes. Furthermore, all the TCL procedures defined in the data tree will be called and the whole data tree will be refreshed. Therefore, this instruction must be carried out only when necessary.
actualize - This only updates a specified field in data tree. Note that only this specified field will be refreshed in the user interface, and not the whole data tree. It is a boolean value as a 1 or 0 that indicates if it is activated or deactivated.
del_cancel_button - It is a boolean value as a 1 or 0 that indicates if the cancel button is removed (1) or not (0). On the resulting window there will be only the 'OK' button, as follows,
Fields to allow customize tree contextual menu:
addcontextualmenu -To add a new option to the menu. Expects a Tcl list of items, each item with subitems "icon text tcl_command"
replacecontextualmenu -To replace a menu option. Expects a Tcl list of items, each item with subitems "old_text icon text tcl_command"
removecontextualmenu -To remove a menu options. Expects a Tcl list of items, each item with subitems "old_text"
Example:
<container n='general_data' pn='General data' icon='general'> <value n='max_iterations' pn='Maximum iterations' value='1e3' help='limit of iterations for iterative solver'/> <value n='stop_tolerance' pn='Stop tolerance' value='1e-8'/> </container>
Example: (customize contextual menu)
<blockdata n="Simulation_type" pn="Simulation data" icon="[icon_simtype]" addcontextualmenu="{advanced-16 {Add option 1} CompassFEM::Test} {advanced-16 {Add option 2} CompassFEM::Test}" replacecontextualmenu="{{Edit} advanced-16 {Edit mod.} CompassFEM::Test} {{View this} advanced-16 {View this mod.} CompassFEM::Test_mod}" removecontextualmenu="{View this} {Edit}"</blockdata>
<value>
It is the main field to store data. This field allows to define an entry, or a combobox in the window.
It can contain the following fields: <function>, <dependencies>, <edit_command>
The parameters are as follows,
n - Name used to reference the field, especially when writing the .dat file.
pn - Label that will be visualized by the user. It can be translated.
v - The value or default value for a 'value' field
state - Specifies one of the four states for the entry: normal, disabled, hidden or readonly. If the entry is readonly, then the value may not be changed using widget commands and no insertion cursor will be displayed, even if the input focus is in the widget; the contents of the widget may still be selected. If the entry is disabled, the entry may not be changed, no insertion cursor will be displayed and the contents will not be selectable. Note that hidden entry can be used for storing hidden values. It also permits to define a Tcl function, by means of square brackets.
values_tree - Permits to define a TCL function, by means of square brackets, and returns a combobox with a list of strings.
values - Comma-separated list of strings.
For instance, values="mech,therm"
dict - Comma-separated list of key,value. This operation places a mapping from the given key to the given value, which is shown in the GUI. Values can be translated.
For instance, dict="mech,Mechanical,therm,Thermal" shows Mechanical and Thermal.
string_is - Tests the validity of various interpretations of a string, as follows,
integer - To test if a string is an integer value.
integer_or_void - To test if a string is an integer value, or empty (not-filled).
double - To test if a string is a double value.
double_or_void - To test if a string is a double value, or empty (not-filled).
% - To test if a string is a percentage (%)
list_of_double - To test if a string is a list of doubles, representing a data structure of doubles in Tcl.
help - It displays a pop-up window of help information related to the task the user is performing.
actualize_tree - Itupdates the information in the whole data tree, and automatically refresh data shown in the user interface. It is a boolean value as a 1 or 0 that indicates if it is activated or deactivated. If the data source is changed, such as new fields have been added or data values and field have been modified, all the user interface will reflect those changes. Furthermore, all the TCL procedures defined in the data tree will be called and the whole data tree will be refreshed. Therefore, this instruction must be carried out only when necessary.
actualize - This only updates a specified field in data tree. Note that only this specified field will be refreshed in the user interface, and not the whole data tree. It is a boolean value as a 1 or 0 that indicates if it is activated or deactivated.
update_proc - It calls a TCL procedure, when clicking on the 'Ok' button in the window or when changing the value of the entry. Square brackets are not supported.
menu_update - It allows to update the menus.Values can be yes or no. It is necessary to define a <dependencies> field, as follows,
<dependencies node="/*/blockdata[@n='General_Data']/value[@n='analysis_type']" att1="menu_update" v1="[TCL_proc]" actualize="1"/>
fieldtype - It creates a box in the user interface in order to introduce a text. It can be:
longtext - A text box is created.
editable - It is a boolean value as a 1 or 0 that indicates if the entry could be changed or not. If it is activated (1) the entry may not be changed, no insertion cursor will be displayed and the contents will not be selectable.
unit_magnitude - Physical quantity (i.e. L, for Length). For more information about this attribute, see the section Description of the units
units - Unit of the physical quantity (i.e. m). For more information about this attribute, see the section Description of the units
function - Contains a Tcl command, which is executed when is called. It permits to create or edit a function for a determined entry.
function_func - Permits to define a TCL function.
values_check - It allows to handle a Tcl function, by means of square brackets.
min_two_pnts - It is a boolean value as a 1 or 0 and indicates that two points or more are required in a linear interpolation.
unit_definition - The fields <value/> used to choose the default units in the GUI are special. They contain the attribute called unit_definition="magnitude" being magnitude the name 'n' to be used in that field. It is important to note that these kind of fields does not contain dependencies.
show_in_window - Can be 1 or 0 (1 by default). It indicates if the value must be shown in the conditions window. If set to 0, the value will be shown in the tree, but will be hidden in the window.
Example:
<value n='units_length' pn='Length' unit_definition='L'/>
<value n='units_mass' pn='Mass' unit_definition='M'/>
<value n='units_force' pn='Force' unit_definition='F'/>
unit_mesh_definition - The field <value/> used to choose the mesh unit is special. It has the attribute unit_mesh_definition="1", and it does not contain any "v" attribute or dependencies.
Example:
<value n="units_mesh" pn="Geometry units" unit_mesh_definition="1"/>
units_system_definition - The field <value/> used to choose the units system is special. It has the attribute units_system_definition="1", it does not contain any "v" attribute, and it contains a unique dependency related to the units fields.
Example:
<value n='units_system' pn='Units system' units_system_definition='1' icon='units-16'>
<dependencies node="//*[@unit_definition or @unit_mesh_definition='1']" att1='change_units_system' v1='{@v}'/>
</value>
<condition>
It contains some inputs with values and can be applied to groups. For each applied group, a dependent set of values will be created that belong to that group, for this condition.
A group is a category that brings together selected entities (points, lines, surfaces and/or volumes) with identical properties. I should be noted that any entity can belong to more than one group (unlike the concept of layer, where any entity cannot belong to more than one layer).
It can contain the following fields: <value>, <dependencies>, <edit_command>
On the resulting window, in addition to the inputs there will be the following set of buttons:
Button 'Select' enables to create a group and choose entities into it.
ov, ovi, i=1,2 - Indicates to which entity types can a 'condition' be applied. Can be one or several of the following values: point, line, surface, volume.
Note: usually a condition is attached to a group, and ov is used, but some special conditions are attached to two groups, then ov1 and ov2 must be used (for example could be used to define master-slave parts)
ovp, ovpi, i=1,2 - Optional, to visually show an string alternative to the ov keyword values
ov_default - Indicates the default entity type selected (used in case of ov with multiple types). Can be one, and only one of the following values: point, line, surface, volume.
ovm, ovmi, i=1,2 - Indicates to which entity can a 'condition' be applied. It can be element, node, face_element or ""
ov_element_types - Optional, to restrict the element types that could be applied. Must be a list of comma separated of the following values: linear, triangle, quadrilateral, tetrahedra, hexahedra, prism, point, pyramid, sphere, circle (by default all element types are allowed)
state - Specifies one of two states for the field: normal, or hidden. Note that hidden <container> field can be used for storing hidden values, that you do not want to show in the user interface. It also permits to handle a Tcl function, by means of square brackets.
groups_icon -It allows to put a custom image when creating groups in the data tree, with .png format. The image should be stored inside the images folder of the problem type.
Example:
<condition n="Point_Weight" pn="Point Weight" icon="constraints" groups_icon="groups-16">
...
</condition>
<symbol>
Every condition can have a symbol, that will be drawn when the user selects Draw symbols in the contextual menu that appears on user interactions such as right-mouse click operation.
The symbol is defined by a field <symbol> inside the condition. The available XML parameters are:
- proc: Includes the name of a TCL proc to be defined in the TCL files of the problemtypes. In that proc, OpenGL is used to make the real drawing.
The procedure must return the id of a OpenGL drawing list (created by GiD_OpenGL draw -genlists 1), or a dict with some required keys depending on the orientation attribute value.
The proc is invoked adding automatically an extra argument: valuesList with a list of key value of the condition values stored in the tree.
- orientation: can be global, local, localLA, free or have some special values section, shell_thickness, loads to invoke internally predefined drawings.
- global means that the symbol defined in the proc will be draw with its axes corresponding to that of the global axes of the model.
- local means that the symbol will be drawn related to a local axes system dependent on the entity.
- For lines, this local axes system will have x' axe parallel to the line. For surfaces, the z' axe will be parallel to the surface normal
(for lines some extra correction of the local axes could be applied) - localLA is similar to local, in this case is compulsory attach local axis to entities, implicit automatic local axis of lines and surfaces are not used (and without the extra correction in case of lines)
- section used for lines to draw bar section profiles in its local axes. (some extra correction of the local axes could be applied)
In this case the proc must return a dict Tcl object with keys named:
- obj the integer representing the opengl list to be drawn.
- shell_thickness to draw the surface with a thickness.
In this case the proc must return a dict Tcl object with keys named:
- thickness with the value of the thickness associated to the surface.
- cdg_pos (optional) with the list of the 3 components of the center position
- loads to represent loads.
In this case the proc must return a dict Tcl object with keys named:
- load_type with possible values global, global projected, local
- load_vector with a list of 3 components of the vector
e.g. return [dict create load_type $load_type load_vector $load_vector]
- free is another special value, in this case the Tcl procedure will be called once by entity with the condition to be draw, instead of only once by group.
The proc is invoked adding automatically some extra arguments: valuesList geom_mesh ov num pnts points ent_type center scale
this allow to know the information of the entity.
geom_mesh: GEOMETRYUSE or MESHUSE
ov: point line surface volume node element
num: <entity id>
pnts: in case of lines integer?, in case of surfaces its boundary lines and orientations <{line_1 SAME1ST|DIFF1ST} ... line_n SAME1ST|DIFF1ST}>
points: in case of lines <{x1 y1 z1} {x2 y2 z2}> start and end coordinates, in case of lines the boundary point coordinates
ent_type: STLINE, ...
center: <x y z>
scale: <scale_to_draw>
The local axes are defined by a special 'classical condition' (point_Local_axes, line_Local_axes, ...) assigned to the entities, or if there is not assigned this 'local axis' then the implicit local axis for lines and surfaces is used (based in its tangent and normal respectively)
There are Tcl predefined procedures to facilitate drawing with OpenGL:
- gid_groups_conds::import_gid_mesh_as_openGL <filename> <color_lines> <color_surfaces>
To automatically import a GiD mesh file to be drawn with OpenGL.
The filename to be read must be a GiD ASCII mesh of lines, triangles and quadrilaterals (with as few elements as as possible). This mesh could be exported from the menu Files->Export->GiD mesh. The procedure read the mesh and invoke GiD_OpenGL draw commands.
The mesh must represent a normalized shape, centered at the origin and contained in a box of size 1 for every of its dimensions (a 2x2x2 cube)
- gid_groups_conds::draw_symbol_image <image> <values_list>
To automatically import in image file to be drawn with OpenGL.
The image must use some valid image format (png, gif, jpg,...), and is expected to be inside a folder named /images of the problemtype
The values_list argument is currently not used.
- gid_groups_conds::draw_symbol_text <txt> <values_list>
To automatically print a text with OpenGL.
The values_list argument is currently not used.
Note: The package gid_draw_opengl also contains some predefined interesting procedures, and some .msh files with common symbols to be used by gid_groups_conds::import_gid_mesh_as_openGL
Example:
<condition n="Point_Weight" pn="Point Weight" ov="point" ovm="node" icon="constraints" help="Concentrated mass"> <value n="Weight" pn="Weight" v="0.0" unit_magnitude="M" units="kg" help="Specify the weight that you want to apply"/> <symbol proc="gid_groups_conds::draw_symbol_image darkorange-weight-18.png" orientation="global"/> </condition>
Example:
<condition n="Point_Weight" pn="Point Weight" ov="point" ovm="node" icon="constraints" help="Concentrated mass"> <value n="Weight" pn="Weight" v="0.0" unit_magnitude="M" units="kg" help="Specify the weight that you want to apply"/> <symbol proc="Cmas2d::DrawSymbolWeight" orientation="global"/> </condition>
And its Tcl drawing procedure, assuming that the mesh file named weight_2d.msh is located in the symbols folder or the problemtype:
proc Cmas2d::DrawSymbolWeight { values_list } { variable _opengl_draw_list if { ![info exists _opengl_draw_list(weight)] } { set _opengl_draw_list(weight) [GiD_OpenGL draw -genlists 1] GiD_OpenGL draw -newlist $_opengl_draw_list(weight) compile set filename_mesh [file join [Cmas2d::GetDir] symbols weight_2d.msh] gid_groups_conds::import_gid_mesh_as_openGL $filename_mesh black blue GiD_OpenGL draw -endlist } set weight_and_unit [lrange [lindex $values_list [lsearch -index 0 $values_list Weight]] 1 2] set weight [lindex $weight_and_unit 0] set scale [expr {$weight*0.1}] set transform_matrix [list $scale 0 0 0 0 $scale 0 0 0 0 $scale 0 0 0 0 1] set list_id [GiD_OpenGL draw -genlists 1] GiD_OpenGL draw -newlist $list_id compile GiD_OpenGL draw -pushmatrix -multmatrix $transform_matrix GiD_OpenGL draw -call $_opengl_draw_list(weight) GiD_OpenGL draw -popmatrix GiD_OpenGL draw -endlist return $list_id }
<blockdata>
Represents a set of properties with some kind of relationship. A 'blockdata' field can copy itself, to duplicate and create several sets. It can contain the following fields: <value>, <container>, <condition>, <function>, <dependencies>, and other <blockdata>
n - Name used to reference the field, especially when writing the .dat file.
name - Label that will be visualized by the user. It can be translated.
sequence - It allows a 'blockdata' field to by duplicated and copied by the user in order to create several sets. Like several load cases with its 'value' and 'condition' included. If it has the 'sequence' parameter activated, it is possible for the user to create consecutive repetitions of the full block data in order to represent, for example, loadcases with all its conditions inside.
sequence_type - It can be:
any - The list can be void (this is the default)
non_void_disabled - At least there needs to be one element. It can be disabled.
non_void_deactivated - At least there needs to be one element. It can be deactivated.
editable_name - can be void '' or 'unique'. The 'unique' means that it is not possible to use the same name ('pn' field), for two different 'sequence' 'blockdata'.
morebutton - It is a boolean value as a 1 or 0 to show a 'More...' button in fields of type 'blockdata'. It is activated by default. For more information about this attribute, see the section Import export materials
can_delete_last_item - A single blockdata could be deleted.
before_update_proc - It allows to call a TCL procedure, when choosing this field in data tree. Square brackets are not supported.
update_proc - It calls a TCL procedure, when clicking on the 'Ok' button in the window. Square brackets are not supported.
icon - It allows to put an image in .png format in the data tree. The image should be stored inside the images folder of the problem type.
help - It displays a pop-up window of help information related to the task the user is performing.
state - Specifies one of two states for the field: normal, or hidden. Note that hidden <container> field can be used for storing hidden values, that you do not want to show in the user interface. It also permits to handle a Tcl function, by means of square brackets.
allow_import - It is a boolean value as a 1 or 0 that allows to add the 'Import/export materials' item in the contextual menu for a specific 'blockdata' field. It is deactivated by default. For more information about this attribute, see the section Import export materials
Data tree fields>PT_data>edit_command
<edit_command>
It adds a button in the window that allows to call a TCL procedure when necessary. The parameters are as follows,
n - Name used to reference the field, especially when writing the .dat file.
pn - Label that will be visualized by the user. It can be translated.
icon - It allows to put an image in .png format in the data tree. The image should be stored inside the images folder of the problem type.
proc - Permits to define a TCL proc. The code will receive an implicit argument with name 'domNode' that represents the TDOM node in the calling field context. Square brackets are not necessary in edit_command field.
help - It displays a pop-up window of help information related to the task the user is performing.
Data tree fields>PT_data>dependencies
<dependencies>
When a field of type 'value' changes its value 'v', the <dependencies> field allows to force a change in other values.
The parameters are as follows,
node - It is the xpath expression to the node that should be updated.
value - Field <value> allows to define a condition to execute a dependence.
att, atti, i=1,2 - Indicates to which attributes of a node affect a change in one value.
v,vi, i=1,2 - Indicates the new value for atti, i=1,2. It can be normal, hidden or disabled.
default - Default value for the condition. It permits to execute a dependence.
actualize - This only updates a specified field in data tree. Note that only this specified field will be refreshed in the user interface, and not the whole data tree. It is a boolean value as a 1 or 0 that indicates if it is activated or deactivated.
actualize_tree - It updates the information in the whole data tree, and automatically refresh data shown in the user interface. It is a boolean value as a 1 or 0 that indicates if it is activated or deactivated. If the data source is changed, such as new fields have been added or data values and field have been modified, all the user interface will reflect those changes. Furthermore, all the TCL procedures defined in the data tree will be called and the whole data tree will be refreshed. Therefore, this instruction must be carried out only when necessary.
Example: when the user select 'No' in the combo 'show_weight' the item value with name='weight' will be hidden, and when select 'Yes' is showed.
Note the use of a relative xpath node="../value[@n='weight']" to specify the xml node to be changed by the dependency:
<value n="show_weight" pn="Show the weight" values="Yes,No" actualize_tree="1">
<dependencies value='Yes' node="../value[@n='weight']" att1="state" v1='normal'/>
<dependencies value='No' node="../value[@n='weight']" att1="state" v1='hidden'/>
</value>
<value n="weight" pn="Weight" v="0.0" unit_magnitude="M" units="kg" help="Specify the weight that you want to apply"/>
Data tree fields>PT_data>groups
<groups>
Initial groups field. It is always an empty field in the .spd file.
Data tree fields>PT_data>groups_types
<groups_types>
Represents the types of groups. It can contain the following fields: <group_type>
The parameters are as follows,
editable - It is a boolean value as a 1 or 0 that indicates if the entry could be changed or not. If it is activated (1) the entry may not be changed.
Data tree fields>PT_data>groups_types>group_type
<group_type>
Main configuration field of the group types.
pn - Label that will be visualized by the user. It can be translated.
default - It is a boolean value as a 1 or 0 that indicates the default group type.
auto_from_bc - It is a boolean value as a 1 or 0 that indicates that the group type is a boundary condition (bc).
Example:
<group_type pn="normal" default="1"/>
<group_type pn="BC" auto_from_bc="1"/>
Data tree fields>PT_data>units
<units>
Main unit field. It can contain the following fields: <unit>
Data tree fields>PT_data>units>unit_magnitude
<unit_magnitude>
It is necessary to add a field of type unit_magnitude to change the priority 'p' for a given unit, together with the values of the priorities, for each 'unit ' considered. It can contain the following fields: <unit>
The parameters are as follows,
n - Name used to reference the field, especially when writing the .dat file.
pn - Label that will be visualized by the user. It can be translated.
default - Default unit for a specific magnitude..
SI_base -Unit based in the international system units for a specific magnitude.
active - It is the default unit shown in the user interface, for a specific magnitude.
Data tree fields>PT_data>units>unit_magnitude>unit
<unit>
n - Name used to reference the field, especially when writing the .dat file.
pn - Label that will be visualized by the user. It can be translated.
p - Priority of the unit, it is regarded as more important than others units. The possible values for 'p' are 1, 2 and 3. For more information about this attribute, see the sectionDescription of the units
factor - The conversion factor used to multiply a quantity when converting from one system of units to another. For more information about this attribute, see the sectionDescription of the units
help - To make easier to the user to identify the unit.
units_system - There are two systems used to define units, the possible values are:
SI - International system
imperial - Imperial system
addend - Conversion number, relation between two units. Example: In order to go from Celsius to Kelvin, 273.15 is added to the temperature in Celsius. Therefore, addend = 273.15.
printable_name - Name used to print the unit. For instance, 'oC' could be the print name of ºC.
Data tree fields>PT_data>function
<function>
Main function field, which contains a function variable field called <functionVariable>.
It permits to create or edit a function defined by points for a determined field.
e.g. for a property variable with the temperature.
It can contain the following fields: <functionVariable>
Data tree fields>PT_data>function>functionVariable
<functionVariable>
It allows to define the default values of a function defined by xy points. The parameters are as follows,
n - Name used to reference the field, especially when writing the .dat file.
pn - Label that will be visualized by the user. It can be translated.
variable - Name of the variable shown in the GUI.
units - Its value is the default unit shown in the GUI, which could be changed, if desired.
Example:
<value n="dens" pn="Density" min_two_pnts="1" help="Density of Steel" unit_magnitude="M/L^3" units="kg/m^3" function="[density_function]" function_func="" v="1.0">
<function>
<functionVariable n="interpolator_func" pn="Interpolation function" variable="x" units="°C">
<value n="point" pn="Point" v="20.0,7830.0"/>
<value n="point" pn="Point" v="600.0,7644.0"/>
</functionVariable>
</function>
</value>
<procs>
<proc n='density_function' args='args'>
<![CDATA[
MyDensityFunction $domNode $args
]]>
</proc>
</procs>
In this example the proc density_function referenced by the 'function' attribute is implemented in the xml .spd file but it is very simple and only invokes another procedure named MyDensityFunction adding some arguments. The body of the tcl procedure could be implemented separatelly in a .tcl file (sourced in the problemtype), this facilitate its edition and debug.
proc MyDensityFunction { domNode args } {
set result [join [list scalar [list interpolator_func x x Temp]] ,]
return $result
}
The proc referenced by the 'function' must return as value something like this:
scalar,interpolator_func x x Temp
where scalar is a keyword,
interpolator_func is the same name used in <functionVariable n="interpolator_func" ...
x is the same variable name used in <functionVariable ... variable="x" ...
Temp is the magnitude accoding to the units used in <functionVariable ... units="°C">
The graphical interface will show something like this and pressing the rigth button will open a window to edit the xy graph:
Interpolation function window
Data tree fields>PT_data>Annex I: Using functions
The following section is of purely practical nature. It contains examples of the most common functions from the areas CustomLib deals with.
Example no. 1: Using functions based on Interpolated Data
The linear interpolation uses two or more pairs of input data points that approximate a function. To define functions based on interpolated data, use the function dialog box, which can be opened from the data tree automatically clicking on the button Σ as follows,
An example of the <value/> node field in the .spd file is the following:
<value n="disc_load" pn="Discrete load" min_two_pnts="1" single_value="1" function="[loads_function_time]" function_func="" state="normal" v="1.0">
<function>
<functionVariable n="interpolator_func" pn="Interpolation function" variable="x" units="s">
<value n="point" pn="Point" v="0.0,0.0"/>
<value n="point" pn="Point" v="10.0,1.0"/>
<value n="point" pn="Point" v="1.0e9,1.0"/>
</functionVariable>
</function>
</value>
<proc n="loads_function_time" args="">
return [cmas2d_CustomLIB::chk_loads_function_time $domNode]
</proc>
proc cmas2d_CustomLIB::chk_loads_function_time { domNode } {
set loads [list [list scalar]]
lappend loads [list interpolator_func x x T]
return [join $loads ,]
}
Notice that both <function/> and <functionVariable/> nodes are required to define an interpolation function.
Note: The nodes of type <value n="point"/> can be omitted to start with an empty table of input data points.
Function dialog box allows to enter pairs of input data points that approximate a function
Example no. 2: Using functions based on Interpolated Data, methods for entering data
It is possible to select automatically the method for entering data (Single value, Linear ramp or Equation). For functions of one variable, you can select between the following interpolation methods by default:
- Single value: The linear interpolation uses two or more pairs of input data points that approximate a function.
- Linear ramp: Calculates two or more 'Linear ramp' pairs of input data points that approximate a function.
- Equation: Calculates two or more pairs of input data points that satisfy a given equation.
Use the function dialog box, which can be opened from the data tree clicking on the button Σ as follows,
Function dialog box allows to calculate input data points that satisfy a given equation.
Function dialog box allows to calculate input data points that satisfy a sinusoidal load equation.
<value n="Factor" pn="Factor" v="1.0" help="This factor, that can be a number or a formula, multiplies the vector load" function="[loads_function Punctual_Load]" function_func="CompassFEM::function_loads"/>
<proc n="loads_function" args="load_name">
return [chk_loads_function $domNode $load_name]
</proc>
_proc function_loads { ftype what n pn frame domNode funcNode _
units_var ov_var } {
switch $ftype {
sinusoidal_load {
_return [function_loads_sinusoidal $what $n $pn $frame $domNode _
$funcNode $units_var $ov_var]
}
custom_editor {
_return [function_custom_editor $what $n $pn $frame $domNode _
$funcNode $units_var $ov_var]
}
}
}
proc chk_loads_function {domNode load_name} {
set loads [list [list scalar]]
lappend loads [list sinusoidal_load t]
return [join $loads ,]
}
_proc function_custom_editor { what n pn f domNode funcNode _
units_var ov_var } {
# Create your own child window implemented in Tcl/Tk..
}
_proc function_loads_sinusoidal { what n pn f domNode funcNode _
units_var ov_var } {
global ProblemTypePriv
switch $what {
create {
set help [= "This is a a sinusoidal load that depends on the time"]
set f1 [ttk::frame $f.f1]
set idx 0
_foreach i [list amplitude circular_frequency phase_angle initial_time end_time] _
_n [list [= "Amplitude (%s)" A] _
_[= "Frequency (%s)" f] [= "Phase angle (%s)" \u3a6] _
_[= "Initial time (%s)" t0] [= "End time (%s)" t1]] _
_m [list - Frequency Rotation T T] _
_u [list - 1/s rad s s] _
v [list 1.0 1.0 0.0 0.0 0.0] {
ttk::label $f1.l$idx -text $n:
gid_groups_conds::register_popup_help $f1.l$idx $help
if { $m ne "-" } {
set ProblemTypePriv($i) $v
set ProblemTypePriv(${i}_units $u
_gid_groups_conds::entry_units $f1.sw$idx _
_-unit_magnitude $m _
_-value_variable ProblemTypePriv($i) _
-units_variable ProblemTypePriv(${i}_units)
} else {
ttk::entry $f1.sw$idx -textvariable ProblemTypePriv($i)
set ProblemTypePriv($i) $v
}
grid $f1.l$idx $f1.sw$idx -sticky w -padx 2 -pady 2
grid configure $f1.sw$idx -sticky ew
incr idx
}
if { ![info exists ProblemTypePriv(l_sin_img)] } {
_set ProblemTypePriv(l_sin_img) [image create photo _
_-file [file join $ProblemTypePriv(problemtypedir) images _
sinusoidal_load.gif]]
}
_ttk::label $f1.l -text "f(t)=A\u00b7sin(2\u00b7\u03C0\u00b7f\u00b7t+\u03a6)" _
_-relief solid -padding 3 -width 20 _
-anchor w
grid $f1.l -sticky w -padx 6 -pady 6
label $f.image -image $ProblemTypePriv(l_sin_img) -bd 1 -relief solid
grid $f1 $f.image -sticky nw -padx 8 -pady 2
grid configure $f.image -sticky new
grid columnconfigure $f 1 -weight 1
grid rowconfigure $f 0 -weight 1
if { $funcNode ne "" } {
set xp {functionVariable[@variable="t" and
@n="sinusoidal_load"]}
set fvarNode [$funcNode selectNodes $xp]
} else { set fvarNode "" }
if { $fvarNode ne "" } {
_foreach i [list amplitude circular_frequency phase_angle initial_time end_time] _
_pn [list [= "Amplitude (%s)" A] _
_[= "Frequency (%s)" f] [= "Phase angle (%s)" \u3a6] _
_[= "Initial time (%s)" t0] [= "End time (%s)" t1]] _
m [list - Frequency Rotation T T] {
set xp [format_xpath {string(value[@n=%s]/@v)} $i]
set ProblemTypePriv($i) [$fvarNode selectNodes $xp]
if { $m ne "-" } {
set xp [format_xpath {string(value[@n=%s]/@units)} $i]
_set ProblemTypePriv(${i}_units) _
[gid_groups_conds::units_to_nice_units [$fvarNode selectNodes $xp]]
}
}
}
return [= "Sinusoidal load"]
}
apply {
set idx 0
set f1 $f.f1
_foreach i [list amplitude circular_frequency phase_angle initial_time end_time] _
_pn [list [= "Amplitude (%s)" A] _
_[= "Frequency (%s)" f] [= "Phase angle (%s)" \u3a6] _
_[= "Initial time (%s)" t0] [= "End time (%s)" t1]] _
m [list - Rotation Rotation T T] {
if { ![string is double -strict $ProblemTypePriv($i)] } {
if { $m ne "-" } { set e $f1.sw$idx.e } else { set e $f1.sw$idx }
tk::TabToWindow $e
error [= "Value %s is not OK" $pn]
}
incr idx
}
set xp {functionVariable[@variable="t"]}
if { [$funcNode selectNodes $xp] eq "" } {
set fvarNode [$funcNode appendChildTag functionVariable]
} else {
set fvarNode [$funcNode selectNodes $xp]
foreach i [$fvarNode childNodes] { $i delete }
}
_$fvarNode setAttribute n sinusoidal_load pn [= "Sinusoidal load"] _
variable "t"
_foreach i [list amplitude circular_frequency phase_angle initial_time end_time] _
_pn [list [= "Amplitude (%s)" A] _
_[= "Frequency (%s)" f] [= "Phase angle (%s)" \u3a6] _
_[= "Initial time (%s)" t0] [= "End time (%s)" t1]] _
m [list - Frequency Rotation T T] {
_set v [$fvarNode appendChildTag value [list attributes() _
n $i pn $pn v $ProblemTypePriv($i)]]
if { $m ne "-" } {
_set newunits [gid_groups_conds::nice_units_to_units _
$ProblemTypePriv(${i}_units)]
_$v setAttribute unit_magnitude $m _
units $newunits
}
}
}
}
}
Example no. 3: Editable multiline text for entering mathematical expressions
The following example allows to enter a numerical or math expression, such as a formula, into an editable multiline text box. CustomLib will display automatically the resulting math expression in the data tree. Moreover, the user will be able to overwrite this expression with a different formula using Ramdebugger editor. The 'Edit' button opens Ramdebugger, the graphical debugger for the scripting lenguage Tcl-Tk.
Editable multiline text box called 'TCL code' and 'Edit' button.
It is possible to create and modify the function inside Ramdebugger editor. The TCL-TK source code is colorized and supports automatic indentation.
The <condition/> node field in the .spd file is as follows,
<condition n="custom_constraints" pn="Custom constraints" ov="point,line,surface,volume" state="normal" ov_default="surface" ovm="" help="A constraint defined by using the TCL extension language">
<dependencies node="value[@n='over_what']" att1="v" v1="node" att2="state" v2="disabled" condition="@ov='point'"/>
<dependencies node="value[@n='over_what']" att1="state" v1="normal" condition="@ov='line' or @ov='surface' or @ov='volume'"/>
<value n="units" pn="Units set" v="N-m-kg" values="N-m-kg,N-cm-kg,N-mm-kg"/>
<value n="tcl_code" pn="TCL code" v="" fieldtype="long text"/>
<value n="over_what" pn="Over" v="node" values="node,element" dict="node,node,element,element" editable="0" help="Condition will be applied to either over every selected element or every selected node"/>
<edit_command n="edit_custom_data" pn="Edit" proc="edit_custom_data constraints" edit_type="callback"/>
</condition>
<proc n="edit_custom_data" args="custom_type callback">
custom_data_edit $domNode $dict $custom_type $callback
</proc>
proc custom_data_edit { domNode dict custom_type callback } {
if { ![interp exists ramdebugger] } { interp create ramdebugger }
_ramdebugger eval [list set argv [list -noprefs -rgeometry 600x500+300+300 _
-onlytext]]
package require RamDebugger
if { [dict exists $dict tcl_code] } {
set data [string trim [dict get $dict tcl_code]]
} else {
set xp {string(value[@n="tcl_code"]/@v)}
set data [string trim [$domNode selectNodes $xp]]
}
if { $data eq "" } {
_set data [format "# %s\n# %s\n" [= "Enter TCL code to define a load"] _
[= "Use menu 'Custom data' for help"]]
}
_interp alias ramdebugger EditEndInRamDebugger "" CompassFEM::custom_data_edit_update _
$callback
_ramdebugger eval [list RamDebugger::OpenFileSaveHandler "custom data" _
$data EditEndInRamDebugger]
set menu ""
set file [file join $::ProblemTypePriv(problemtypedir) scripts custom_bc_examples.txt]
set fin [open $file r]
set data [read $fin]
close $fin
set elms ""
set rex {\s*#\s*type:\s*(\S.\S)\s+name:\s(\S.\S)\s$}
foreach "idxsL idxsType idxsName" [regexp -inline -all -line -indices $rex $data] {
if { $elms ne "" } {
lset elms end end [expr {[lindex $idxsL 0]-1}]
}
set type [eval [list string range $data] $idxsType]
set name [eval [list string range $data] $idxsName]
lappend elms [list $type $name [lindex $idxsL 0] ""]
}
if { $elms ne "" } {
lset elms end end [expr {[string length $data]-1}]
}
set subMenus ""
foreach i $elms {
foreach "type name idx1 idx2" $i break
_lappend subMenus [list command "$name ($type)" {} _
_[= "View example '%s' (%s)" $name $type] "" _
-command [list open_new_window_show $idx1 $idx2]]
}
lappend subMenus [list separator]
set idx2 [expr {[string length $data]-1}]
_lappend subMenus [list command [= "All examples"] {} _
_[= "View all examples"] "" _
-command [list open_new_window_show 0 $idx2]]
lappend menu [list cascad [= Examples] {} examples 0 $subMenus]
set cmd {
set ip [RamDebugger::OpenFileInNewWindow -ask_for_file 0]
set fin [open %FILE r]
set data [read $fin]
close $fin
set d [string range $data $idx1 $idx2]
$ip eval [list $::RamDebugger::text insert insert $d]
$ip eval [list RamDebugger::MarkAsNotModified]
}
set cmd [string map [list %FILE [list $file]] $cmd]
ramdebugger eval [list proc open_new_window_show [list idx1 idx2] $cmd]
lappend menu [list separator]
_foreach "n nargs" [list coords 2 conec 1 nnode 0 elem_num 0 elem_normal 1 _
epsilon 0 facLoad 0] {
set name [= "Insert command '%s'" $n]
set cmd {
set t $::RamDebugger::text
$t insert insert [list %N%]
$t insert insert "("
$t insert insert [string repeat , %NARGS%]
$t insert insert ")"
$t mark set insert "insert-[expr {%NARGS%+1}]c"
}
_set cmd [string map [list %N% $n %NARGS% $nargs] _
$cmd]
lappend menu [list command $name "" "" "" -command $cmd]
}
lappend menu [list separator]
_foreach "n nfull" [list _
_add_to_load_vector "add_to_load_vector ?-substitute? ?-local? nodenum loadvector" _
addload "addload ?-local? pressure|triangular_pressure|punctual_load args"] {
set name [= "Insert command '%s'" $n]
set cmd {
$::RamDebugger::text insert insert [list %NFULL%]
}
set cmd [string map [list %NFULL% $nfull] $cmd]
lappend menu [list command $name "" "" "" -command $cmd]
}
switch $custom_type {
constraints { set title [= "Constraints data"] }
properties { set title [= "Properties data"] }
loads { set title [= "Loads data"] }
default { set title [= "Custom data"] }
}
ramdebugger eval [list RamDebugger::AddCustomFileTypeMenu $title $menu]
}
Example no. 4: Create your own custom editor window for entering mathematical expressions
The user can create any number of custom windows in the user interface. A child window is opened automatically to display information to the user and/or get information from the user. This is a great way to add custom windows for your own purposes.
The Function Editor window can be opened by locating in the data tree the field to modify, and choosing the edit button (e.g. Σ).
Example of equation defined on a field of the data tree using a Function Editor window
This will open the Function Editor window and load the current expression into it, which can be empty.
The <value/> node field in the .spd file is as follows,
<value n="Density" pn="Density" v="" unit_magnitude="M/L^3" units="kg/m^3" help="Density of the fluid" function="[loads_function editor]" pn_function="Density" function_func="function_loads"/>
_proc function_loads { ftype what n pn frame domNode funcNode _
units_var ov_var } {
switch $ftype {
editor {
_return [function_editor $what $n $pn $frame $domNode _
$funcNode $units_var $ov_var]
}
}
}
_proc function_editor { what n pn f domNode funcNode _
units_var ov_var } {
# Create your own child window implemented in Tcl/Tk.
}
<proc n="loads_function" args="load_name">
return [chk_loads_function $domNode $load_name]
</proc>
proc chk_loads_function { domNode load_name } {
set loads [list [list scalar]]
if { [lsearch "editor" $load_name] != -1 } {
lappend loads [list editor ""]
return [join $loads ,]
}
return [join $loads ,]
}
Data tree fields>PT_data>Annex II: Using matrices
CustomLib also allows to enter square matrices of order n automatically. The Matrix Editor window is opened by locating in the data tree the field to modify, and choosing the edit button (e.g. [x]) as follows,
This will open the Matrix Editor window and load the current expression into it, which can be empty.
Matrix editor window allows to edit the contents of a square matrix
The <value/> node field in the .spd file is the following:
<value n="nu" pn="nu" function="matrix_func,scalar" dimension_function="3" state="normal" symmetric_function="0" has_diag="0" components_function="x,y,z" v="0.3" function_func="loads_function" help="Poisson coefficient"/>
The <value/> node field in the .spd file is the following:
<value n="nu_s" pn="nu" function="matrix_func,scalar" dimension_function="3" state="normal" symmetric_function="1" has_diag="1" components_function="a,b,c" v="0.3" help="Poisson coefficient"/>
The parameters are as follows,
- dimension_function: Determine the dimensions of a the given square matrix.
- symmetric_function: It is a boolean value as a 1 or 0. It allows to indicate that it is given only the upper triangular part of a symmetric matrix.
- components_function: List of numbers or names. The natural way to refer to rows and columns in a matrix is via the row and column numbers. However, the user can also give names to these entities.
- has_diag: It is a boolean value as a 1 or 0, that allows to indicate if it is a diagonal matrix.
<proc n="loads_function" args="">
return [cmas2d_CustomLIB::chk_loads_function $domNode]
</proc>
proc cmas2d_CustomLIB::chk_loads_function { domNode } {
set loads [list [list scalar]]
lappend loads [list interpolator_func x x T]
return [join $loads ,]
}