IV.2.2.2 Group examples
IV.2.2.2.1 Printing the list of a DataBase’s Groups
It shows how it is possible to obtain the list of Groups contained in a DataBase. This may be useful if
one wants to check whether all Groups read from a session file have been correctly integrated in the
DataBase. The ruby program looks like:
# Creates and initializes the DataBase :
db=NastranDb.new()
db.Name="tmpDB"
db.readBdf("../../MODEL/MAINS/unit_xyz.bdf")
db.readGroupsFromPatranSession("../../MODEL/PATRAN/groups.ses")
# Prints all the group names :
puts db.getAllGroupNames()
The last line performs the printing of the names of all Groups contained in the DataBase. The other
lines are for DataBase creation and initialization.
The example is given in file "RUBY/EX02/printGroupNames.rb".
IV.2.2.2.2 Content of DataBase’s Groups
In the previous example one simply printed the list of the names of Groups contained in a DataBase.
In this new examples, one also print information on the content of each Group. Practically, this is done
as follows:
- One initializes the DataBase “as usual”.
- One loops on the list of Group names stored in the DataBase, and for each groupName:
-
1.
- One gets a copy of the Group stored in the DataBase.
-
2.
- For the four types of entities one recovers the entities. Actually, one only stores the
respective sizes of the Arrays returned by the call to “getEntitiesByType”.
-
3.
- Finally, one prints the result (formatted print).
The program looks like this:
# Creates and initializes the DataBase :
db=NastranDb.new()
db.Name="tmpDB"
db.readBdf("../../MODEL/MAINS/unit_xyz.bdf")
db.readGroupsFromPatranSession("../../MODEL/PATRAN/groups.ses")
# Prints Groups’ data :
printf("%20s%10s%10s%10s%10s' n","groupName","Nodes",'
"Elements","RBEss","CoordSys")
db.each_groupName do |groupName|
grp = db.getGroupCopy(groupName)
nodesNbr = grp.NbrElements
elementsNbr = grp.NbrNodes
rbesNbr = grp.NbrRbes
coordNbr = grp.NbrCoordsys
printf("%20s%10d%10d%10d%10d' n",groupName,nodesNbr,'
elementsNbr,rbessNbr,coordNbr)
end
The example is given in file "RUBY/EX02/printGroups.rb".
IV.2.2.2.3 Printing a Patran session file
The third example prints Groups defined in a Patran session file without importing them into a
DataBase. Groups are directly read into a Hash object with the following statement:
h=Post.readGroupsFromPatranSession("../../MODEL/PATRAN/groups.ses")
Then, for each Group, the entities are printed as lists of integer. One shows below how it is done for
the nodes:
nbrEntitiesPerLine=8
h.each do |id,grp|
os.printf("Group ' "%s' ":' n' n",id)
...
nbr=grp.getNbrEntitiesByType("Node")
os.printf(" Nbr Nodes: %d",nbr)
counter=0
grp.each_node do |id|
if (counter%nbrEntitiesPerLine==0) then
os.printf("' n ")
end
os.printf("%8d",id)
counter+=1
end
os.printf("' n' n")
...
end
The example is given in file "RUBY/EX02/writeGroupEntities.rb".