Built-in Function Examples
Appendix A
Documentation for a typical MSC.Patran built-in function.
db_get_nodes(num_nodes, node_ids, rcids, acids, global_xyz)
This function gets nodal coordinate frames and coordinates for the requested nodes.
Input
|
|
|
INTEGER
|
num_nodes
|
Number of nodes to get information for
|
INTEGER ARRAY
|
node_ids(num_nodes)
|
Node Ids of nodes to get information for
|
Output
|
|
|
INTEGER ARRAY
|
rcids(num_nodes)
|
Reference coordinate frame Ids
|
INTEGER ARRAY
|
acids(num_nodes)
|
Analysis coordinate frame Ids
|
REAL ARRAY
|
global_xyz(num_nodes, 3)
|
Global coordinates for each node
|
INTEGER
|
|
The function returns a value of 0 when executed successfully and a non-zero value to indicate a change in status or an error
|
Notes: The C name differs. It is DbFGetNodes.
int DbFGetNodes(num_nodes, node_ids, rcids, acids, global_xyz)
int num_nodes
int *node_ids
int *rcids
int *acids
float *global_xyz
Appendix A
To get all the nodes and their global coordinates
INTEGER NumNodes, NodeIds(VIRTUAL), rcids(VIRTUAL), acids(VIRTUAL)
REAL NodeXYZ(VIRTUAL)
db_count_nodes(NumNodes)
IF (NumNodes == 0) THEN RETURN –1
sys_allocate_array(NodeIds, 1, NumNodes)
db_get_node_ids(NumNodes, NodeIds)
sys_allocate_array(rcids, 1, NumNodes)
sys_allocate_array(acids, 1, NumNodes)
sys_allocate_array(NodeXYZ, 1, NumNodes, 1, 3)
db_get_nodes(NumNodes, NodeIds, rcids, acids, NodeXYZ)
Essentially, the MSC.Patran database is comprised of a series of tables. Hence, the db_get_nodes() function is simply accessing data from a nodal data table, i.e.,
Node ID
|
RC RCID
|
AC ACID
|
X
|
Y
|
Z
|
2
|
0
|
0
|
0.00
|
0.00
|
0.00
|
5
|
0
|
2
|
5.12
|
-6.34
|
4.90
|
25
|
1
|
1
|
56.20
|
9.01
|
-1.10
|
Appendix A
To get the topology of every element
INTEGER NumElms, ElmIds(VIRTUAL), ElmTopoCodes(VIRTUAL)
db_count_elems(NumElms)
IF (NumElms == 0) THEN RETURN –1
sys_allocate_array(ElmIds, 1, NumElms)
sys_allocate_array(ElmTopoCodes, 1, NumElms)
db_get_elem_ids(NumElms, ElmIds)
db_get_elem_etop(NumElms, ElmIds, ElmTopoCodes)
An element’s topology is a term used to describe the combination of the element’s shape and the number of nodes used to define the element connectivity, i.e., 4-node and 8-node quadrilateral elements have the same shape but have different topologies.
To determine the MSC.Patran topology Ids for a particular element shape and connectivity, use the fem_get_patran25_etop() function, i.e.,
INTEGER ShapeCode, NumNodesPerElm, ElmTopoCode
fem_get_patran25_etop(ShapeCode, NumNodesPerElm, ElmTopoCode)
Elm Shape
|
Shape Code
|
Elm Shape
|
Shape Code
|
Point
|
1
|
Tet
|
5
|
Bar
|
2
|
Pyramid
|
NA
|
Tria
|
3
|
Wedge
|
7
|
Quad
|
4
|
Hex
|
8
|
Appendix A
To get the shape of every element
INTEGER NumElms, ElmIds(VIRTUAL), ElmTopoCodes(VIRTUAL)
INTEGER ElmShapeCodes(VIRTUAL), NumNodesPerElm(VIRTUAL)
db_count_elems(NumElms)
IF (NumElms == 0) THEN RETURN –1
sys_allocate_array(ElmIds, 1, NumElms)
sys_allocate_array(ElmTopoCodes, 1, NumElms)
db_get_elem_ids(NumElms, ElmIds)
db_get_elem_etop(NumElms, ElmIds, ElmTopoCodes)
sys_allocate_array(ElmShapeCodes, 1, NumElms)
sys_allocate_array(NumNodesPerElm, 1, NumElms)
db_get_elem_topology_data(NumElms, ElmTopoCodes, ElmShapeCodes, @
NumNodesPerElm)
Appendix A
To get all the element connectivity for all elements
INTEGER NumElms, ElmIds(VIRTUAL), ElmTopoCodes(VIRTUAL)
INTEGER ElmShapeCodes(VIRTUAL), NumNodesPerElm(VIRTUAL)
INTEGER MaxNodesPerElm, ElmConnect(VIRTUAL)
db_count_elems(NumElms)
IF (NumElms == 0) THEN RETURN –1
sys_allocate_array(ElmIds, 1, NumElms)
sys_allocate_array(ElmTopoCodes, 1, NumElms)
sys_allocate_array(ElmShapeCodes, 1, NumElms)
sys_allocate_array(NumNodesPerElm, 1, NumElms)
db_get_elem_ids(NumElms, ElmIds)
db_get_elem_etop(NumElms, ElmIds, ElmTopoCodes)
db_get_elem_topology_data(NumElms, ElmTopoCodes, ElmShapeCodes, @
NumNodesPerElm)
sys_free_array(ElmTopoCodes)
sys_free_array(ElmShapeCodes)
mth_sort(NumNodesPerElm, FALSE, NumElms)
MaxNodesPerElm = NumNodesPerElm(NumElms)
sys_free_array(NumNodesPerElm)
sys_allocate_array(ElmConnect, 1, NumElms, 1, MaxNodesPerElm)
db_get_nodes_for_elems(NumElms, MaxNodesPerElm, ElmIds, @
ElmConnect)
Appendix A
To get the elements associated to a particular element property set
FUNCTION GetElmsForPropSet(MyPropertySetName, NumElms, ElmIds)
INTEGER i
INTEGER NumElms, ElmIds()
INTEGER NumRegions, RegionIds(VIRTUAL)
INTEGER MyRegionId
LOGICAL match
STRING MyPropertySetName[]
STRING RegionNames[32](VIRTUAL)
db_count_region_ids(NumRegions)
sys_allocate_array(RegionNames, 1, NumRegions)
sys_allocate_array(RegionIds, 1, NumRegions)
db_get_region_ids_and_names(NumRegions, RegionIds, RegionNames)
match = FALSE
FOR (i = 1 to NumRegions)
IF (str_equal(MyPropertySetName, RegionNames(i))) THEN
match = TRUE
MyRegionId = RegionIds(i)
BREAK
END IF
END FOR
sys_free_array(RegionIds)
sys_free_array(RegionNames)
IF (!match) THEN RETURN –1
db_count_elements_in_region(MyRegionId, NumElms)
IF (NumElms == 0) THEN RETURN –1
sys_allocate_array(ElmIds, 1, NumElms)
db_get_elements_in_region(MyRegionId, NumElms, ElmIds)
RETURN 0
END FUNCTION
Appendix A
To get an element property value (shell thickness) for a specific element
Many people loosely refer to an element property set as simply the element properties. Internally, MSC.Patran distinguishes between the property set and the properties by calling the property set a region. Hence a region is a collection of elements (physical region of the model) and their associated properties (shell thickness, material, orientation, etc.).
FUNCTION get_shell_thickness(ElmId, ElmThick)
INTEGER p
INTEGER ElmId
INTEGER ElmIds(1), ElmRegionIds(1)
INTEGER MaterialId, DataType, IntegerVal, CoordId, NodeId, FieldId
REAL ElmThick, ThickVals(VIRTUAL)
REAL RealVals(3)
STRING CharVal[80]
36 is the property word Id for “thickness”. Other property words and their associated Ids can be found listed in the table of generic property words in Chapter 7 of the PCL and Customization documentation.
ElmIds(1) = ElmId
db_get_region_for_elements(1, ElmIds, ElmRegionIds)
db_count_prop(ElmRegionIds, NumWords)
IF (NumWords == 0) THEN RETURN –1
sys_allocate_array(WordIds, 1, NumWords)
db_get_props_by_region(NumWords, ElmRegionIds, WordIds)
p = mth_array_search(WordIds, 36, FALSE)
IF (p == 0) THEN RETURN –1
db_get_prop_value(ElmRegionIds(1), 36, MaterialId, DataType, @
IntegerVal, RealVals, CharVal, CoordId, NodeId, FieldId)
IF (DataType == 1) THEN /* real scalar at elm centroid */
ElmThick = RealVals(1)
ELSE IF (DataType == -1) THEN /* real scalar field at elm centroid */
MyFunc_EvalScalarFieldCentroid(ElmId, FieldId, ElmThick)
ELSE IF (DataType == -7) THEN /* real scalar field at elm nodes */
MyFunc_EvalScalarFieldNodes(ElmId, FieldId, ElmThick)
E
1
|
Real scalar at elem centroid
|
6
|
List of real values
|
2
|
Real vector
|
7
|
Real scalar at elem nodes
|
3
|
Integer
|
8
|
Node reference
|
4
|
Character string
|
9
|
Coordinate frame reference
|
5
|
Material reference
|
11
|
Section ID (dimensions)
|
|
|
12
|
Section ID (properties)
|
Negative datatypes denote field reference.
LSE
RETURN -1
END IF
RETURN 0
END FUNCTION
Appendix A
There are many other ways to accomplish this same task. The preceding function is very general and very detailed. If the element property set references a field for the shell thickness definition, then functions to evaluate the fields (MyFunc_EvalScalarFieldCentroid() and MyFunc_EvalScalarFieldNodes()) will need to be written. If the shell thickness is only defined at the element centroid, then the ep_word_val_at_el_cen() function can be used. This function has an advantage over the previous example in that this function automatically evaluates any field reference.
FUNCTION get_shell_thickness(ElmId, ElmThick)
INTEGER ElmId, ElmIds(1)
INTEGER NumFoundElms, FoundElmIds(VIRTUAL)
See note on previous page
REAL ElmThick, ThickVals(VIRTUAL)
ElmIds(1) = ElmId
ep_word_val_at_el_cen(36, 1, 1, ElmIds, NumFoundElms, @
FoundElmIds, ThickVals)
IF (NumFoundElms == 0) THEN RETURN -1
p = mth_array_search(FoundElmIds, ElmId, FALSE)
IF (p == 0) THEN RETURN -1
ElmThick = ThickVals(p)
RETURN 0
END FUNCTION
Appendix A
To get a material property value
FUNCTION get_elastic_modulus(MatlName, ElasticModulus)
INTEGER MatlId
REAL ElasticModulus
STRING MatlName[]
db_get_material_id_from_name(MatlName, MatlId)
db_get_matl_prop_value_count(MatlId, NumWords)
IF (NumWords == 0) THEN RETURN –1
sys_allocate_array(WordIds, 1, NumWords)
sys_allocate_array(FieldIds, 1, NumWords)
sys_allocate_array(WordVals, 1, NumWords)
db_get_matl_prop_value(MatlId, WordIds, FieldIds, WordVals)
p = mth_array_search(WordIds, 2, FALSE)
2 is the material property word Id for the Elastic Modulus. Other material property word Ids can be found in the table of Material Property Words in Chapter 7 of the PCL and Customization documentation.
IF (p == 0) THEN RETURN –1
IF (FieldIds(p) != 0) THEN
/* Elastic Modulus is defined
by a field */
ELSE
ElasticModulus = WordVals(p)
END IF
RETURN 0
END FUNCTION
An alternate method of extracting the Elastic Modulus for a material makes use of the db_get_matl_prop_value2() function. The advantage of using this function is that it will automatically evaluate any field references.
Appendix A
INTEGER NumGroups
STRING GroupNames[32](VIRTUAL)
ga_group_ngroups_get(NumGroups)
/* There is always at least one group */
sys_allocate_array(GroupNames, 1, NumGroups)
ga_group_groups_get(Group_names)
To get the nodes and elements associated to the current group
INTEGER GroupId
INTEGER NumNodes, NodeIds(VIRTUAL), NumElms, ElmIds(VIRTUAL)
STRING CurrentGroup[32]
ga_group_current_get(CurrentGroup)
db_get_group_id(CurrentGroup, GroupId)
db_count_nodes_in_group(GroupId, NumNodes)
IF (NumNodes > 0) THEN
sys_allocate_array(NodeIds, 1, NumNodes)
db_get_all_node_ids_in_group(NumNodes, GroupId, NodeIds)
END IF
db_count_elems_in_group(GroupId, NumElms)
IF (NumElms > 0) THEN
sys_allocate_array(ElmIds, 1, NumElms)
db_get_elem_ids_in_group(NumElms, GroupId, ElmIds)
END IF
Appendix A
To get result values for specified elements -
To access elemental results you need to know:
-
Element Ids
-
Resultcase
-
Result type
-
Position or Layer
-
Result quantity
-
Location within the element
-
Coordinate reference
Appendix A
-
Before looking at the PCL command to extract results, let’s correlate items 1-7 with the MSC.Patran result forms. This correlation is not quite one-to-one. However, it hopefully provides a familiar reference.
Appendix A
Appendix A
-
Element results are calculated at various points within the element depending on the analysis code, element type, etc.
-
Generally element results are calculated at either the element:
-
Centroid
-
Integration or Gauss points
-
Nodes
Appendix A
-
Resultcase names are comprised of 2 components, a loadcase name and a subcase name. Each of these has an associated internal Id. These are called the loadcase Id and subcase Id, respectively.
db_get_load_case_title(lc_id, lc_name)
INPUT: lc_id INTEGER
OUTPUT: lc_name STRING
db_get_load_case_id(lc_name, lc_id)
INPUT: lc_name STRING
OUTPUT: lc_id INTEGER
db_get_sub_case_title(lc_id, sc_id, sc_name)
db_get_sub_case_id(lc_id, sc_name, sc_id)
res_utl_get_loadcases(num_rc, lc_ids, num_sc_per_lc)
INPUT: num_rc INTEGER
lc_ids INTEGER ARRAY
OUTPUT: num_sc_per_lc INTEGER ARRAY
res_utl_get_subcases(lc_id, num_sc, sc_ids)
INPUT: lc_id INTEGER
OUTPUT: num_sc INTEGER
sc_ids INTEGER ARRAY
res_data_bulk_get_loadcases(num_rc, lc_ids, sc_ids, @
coordinates, rc_names)
INPUT:
OUTPUT: num_rc INTEGER
lc_ids INTEGER ARRAY
sc_ids INTEGER ARRAY
coordinates INTEGER_ARRAY
rc_names STRING ARRAY
-
Alternately, many functions refer to the resultcase via a resultcase Id.
res_db_cget_rescases(num_rc, lc_ids, sc_ids, rc_ids)
INPUT: num_rc INTEGER
lc_ids INTEGER ARRAY
sc_ids INTEGER ARRAY
OUTPUT: rc_ids INTEGER ARRYA
Appendix A
-
Result type names are also comprised ot 2 components, a primary and a secondary label. Each of these has an associated internal Id. These are called the primary label Id and the secondary label Id.
db_get_primary_res_label(prim_id, prim_label)
INPUT: prim_id INTEGER
OUTPUT: prim_label STRING
db_get_primary_res_id(prim_label, prim_id)
INPUT: prim_label STRING
OUTPUT: prim_id INTEGER
db_get_secondary_res_label(prim_id, sec_id, sec_label)
INPUT: prim_id INTEGER
sec_id INTEGER
OUTPUT: sec_label STRING
db_get_secondary_res_id(prim_id, sec_label, sec_id)
INPUT: prim_id INTEGER
sec_label STRING
OUTPUT: sec_id INTEGER
res_data_get_result_names(prim_id, sec_id, @
prim_label, sec_label)
INPUT: prim_id INTEGER
sec_id INTEGER
OUTPUT: prim_label STRING
sec_label STRING
res_data_get_result_ids(prim_label, sec_label, @
prim_id, sec_id)
res_utl_get_result_ids(num_rc, lc_ids, sc_ids, @
num_res, prim_ids, sec_ids)
INPUT: num_rc INTEGER
lc_ids INTEGER ARRAY
sc_ids INTEGER ARRAY
OUTPUT: num_res INTEGER
prim_ids INTEGER ARRAY
sec_ids INTEGER ARRAY
Appendix A
-
Alternately, some functions refer to the result type via the result type Id instead of the primary and secondary Ids
rt_id = vki_db_getresid(lc_id, prim_id, sec_id)
INPUT: lc_id INTEGER
prim_id INTEGER
sec_id INTEGER
OUTPUT: rt_id INTEGER
res_data_get_restype_ids(rt_id, prim_id, sec_id)
INPUT: rt_id INTEGER
OUTPUT: prim_id NTEGER
sec_id INTEGER
-
Layers or positions can be accessed via the following functions
res_utl_get_result_types(res_ids, num_layers, @
layer_ids, layer_labels)
INPUT: res_ids(4) INTEGER ARRAY, lc_id, sc_id, prim_id, sec_id
OUTPUT: num_layers INTEGER
layer_ids INTEGER ARRAY
layer_labels STRING ARRAY
res_data_get_layerpos_name(layer_id, layer_name)
INPUT: layer_id INTEGER
OUTPUT: layer_name STRING
res_data_get_layerpos_id(layer_name, layer_id)
Appendix A
-
Following is a description of the function used to extract element results. Similar functions exist for extracting nodal results and/or creating either element or nodal results.
res_utl_extract_elem_results(ResIds, ElmList, Derivation, Location, @
CID, DataType, ResLoc, Nres, Ids, @
Nresults, ResVals, MinLoc, MaxLoc)
INPUT
|
|
|
INTEGER
|
ResIds(5)
|
MSC.Patran internal loadcase ID, subcase ID, primary result ID, secondary result ID, and layer ID.
|
STRING
|
ElmList[]
|
List of elements to extract results for.
|
STRING
|
Derivation[10]
|
Derivation specifier if the results are to be derived, i.e., VONM, MAJOR, etc. A null value (“”) will leave the result as is.
|
STRING
|
Location[]
|
Location at which to extract the results. Null (“”) or “A”=as is, “C”=element centroid, and “N”=element nodes.
|
STRING
|
CID[]
|
Coordinate system for vector and tensor transformations. A null string (“”) is used to leave the coordinate specification as is.
|
|
|
|
OUTPUT
|
|
|
INTEGER
|
DataType
|
Datatype for extracted results. Valid values are: 1=scalar, 2=vector, and 3=tensor. Note that the Derivation parameter determines what this value should be, i.e., if the Derivation is “VONM” for the VonMises stress then the DataType will be 1 for a scalar value.
|
INTEGER
|
ResLoc
|
Location within the element for the extracted results. Valid values are: 1=centroid, 2=nodal, and 3=multiple. Note that the Location parameter essentially determines what this value should be. If the Location is specified as “C” for centroid, then the ResLoc parameter should return as 1. ResLoc is most useful if the requested Location is “A” or “As is”. In this case, ResLoc will indicate where MSC.Patran has results stored for this particular set of elements, i.e., if Location=”A” and ResLoc=2 then you know that these elements have element nodal results.
|
INTEGER
|
Nres
|
Number of returned element identifiers
|
INTEGER
|
Ids(VIRTUAL)
|
Array of element identifiers
|
INTEGER
|
Nresults(VIRTUAL)
|
Number of results per element
|
REAL
|
ResVals(VIRTUAL)
|
Result values at the specified element locations
|
INTEGER
|
MinLoc(12)
|
Offsets within the ResVals array for each minimum result component.
|
INTEGER
|
MaxLoc(12)
|
Offsets within the ResVals array for each maximum result component.
|
Share with your friends: |