HM-8060: Calculate the Resultant Sum of Forces
In this tutorial, you will calculate the resultant sum of forces.
- Determines the components of a given set of force vectors
- Calculates a vector resultant sum of the forces
- Reports the resultant sum
The Tcl commands if, foreach and expr will be used to add logic and mathematical functions to the script. The command hm_getentityvalue is used to extract information from HyperMesh entities, based on data names.
Data names are generic references to the information that physically define an entity in the HyperMesh environment. An example of this is the x, y, and z coordinates that define a node location in three-dimensional space.
hm_getentityvalue entity_type id data_name flag
where entity_type
is the requested entity type (elements, loads, nodes,
etc.), id
is the entity ID, the data_name
is the data
field name of interest, and flag
is either 0 or 1 depending on whether
the command should return a numeric value (0) or a string (1).
set force_x [hm_getentityvalue loads 12 "comp1" 0]
Define the Process
In this step, you will define the process.
- Prompt you to select a number of forces to calculate the resultant
- Make sure you have selected one or more loads
- Extract the components of each force
- Sum the components
- Report the result to you
Determine Data Names
The following table lists several relevant data names for force loads:
Item | Description |
---|---|
comp1 | x component of the vector |
comp2 | y component of the vector |
comp3 | z component of the vector |
config | The number "1" for forces The number "2" for moments The number "8" for velocities The number "9" for accelerations |
entitytype | The type of entity to which this load is applied (1=node, 3=component, 10=set) |
node | When a load is applied to a node, this serves as a pointer to the node |
inputsystemid | Reference system ID |
Create a New File
In this step you will create a new text file.
- Open a text file in any text editor.
- Save the file as HM8060.tcl.
Select and Add Loads to a List
In this step, you will select the desired loads and then add those loads to a list.
The *createmarkpanel command is used to allow you to graphically select the loads from the HyperMesh interface and add them to the mark. The command below adds the loads to mark 1. Once the loads have been added to mark 1, the load ids are assigned to a list called loads_list, using the Tcl command set.
*createmarkpanel loads 1 "Select forces to compute resultant";
set loads_list [hm_getmark loads 1];
Initialize Variables
In this step, you will initialize the variables for the x, y, and z components.
Use the Tcl command set to initialize the variables for the x, y, and z components of force to 0. These variables will be used later in the script to compute the resultant force for each component.
set x_comp_sum "0";
set y_comp_sum "0";
set z_comp_sum "0";
Begin an If Loop
In this step you will begin an if loop which checks to see if the variable, loads_list, has values. If it does, then proceed with the macro.
Before calculating the resultant of the forces selected, we should check to make sure that the variable loads_list has values in it. This is done by using an if loop. In the if loop below, we are checking that the variable loads_list is not empty.
if {$loads_list != ""} {
Use a Foreach Loop
In this step you will use a foreach loop to iterate through each load in the list, loads_list, and extract the x, y, and z components using the hm_getentityvalue command and the appropriate data name.
Using a foreach loop, each load in the list loads_list will be iterated through. Within the foreach loop, each load is referenced by load_id and then the component value is added to the previous loads component’s value. For example, let’s look at the x component. Using the set command, the variable x_comp_sum is defined as the previous value of x_comp_sum, plus the x component of the current load. The x component of the current load is retrieved by using the hm_getentityvalue command and the data name comp1 (all the available data names for loads are shown in the table above). This process is done for the y and z components as well.
foreach load_id $loads_list {
set x_comp_sum [expr $x_comp_sum + [hm_getentityvalue
loads $load_id "comp1" 0]];
set y_comp_sum [expr $y_comp_sum + [hm_getentityvalue
loads $load_id "comp2" 0]];
set z_comp_sum [expr $z_comp_sum + [hm_getentityvalue
loads $load_id "comp3" 0]];
}
Report the Resultant Force
In this step, you will add code that reports the resultant force to you.
Use the command hm_usermessage to report each of the components of the resultant force.
hm_usermessage "Resultant force: $x_comp_sum, $y_comp_sum
$z_comp_sum ";
Complete the If Loop
In this step, you will complete the if loop and report an error message if no loads are found.
To complete the if loop, add an else statement. Remember the if statement checked to see if the variable loads_list was not empty. This else statement returns an error message to you to let you know that no loads were selected.
} else {
hm_errormessage "No loads selected";
}
Test the Script
In this step, you will test the script.