This section illustrates the manipulation of XDB attachments. All the examples are to be found in directory “RUBY/EX19”. The different examples are in increasing order of difficulty.
In order to reduce the size of extracted Results, the extractions are done on the nodes of a small Group in all the examples below. Note however that other extractions could have been done. Also, if the two last parameters of the extraction functions are omitted, all the Result values are returned by the extraction methods.
In the example “attachedXdbLcInfos.rb”, one shows how content information can be extracted from an attached XDB file. The XDB file must first be attached to the DataBase:
xdbFileName="../../MODEL/EXEC_XDB/sol111_ri_xyz.xdb" db.attachXdb(xdbFileName)
Then, the information is extracted and printed exactly as in one of the examples of section IV.2.4.6:
infos=db.getAttachmentLcInfos(xdbFileName) infos.each do |tab| STDOUT.printf("%-20s %-25s %-6d %-6d %-15g %-15g\n", tab[0],tab[1],tab[3],tab[4],tab[5],tab[6]) end
It is also possible to extract other information like the list of Result names, sub-case names or load cases names. One shows below how the list of result names can be printed:
resNames=db.getAttachmentResNames(xdbFileName) resNames.each do |resName| STDOUT.printf("%-20s\n",resName) end
The example “attachedXdbResults.rb” shows how Results can be extracted from an XDB attachment. As in the previous example, the file is first attached. Then, one decides which result types and for which load case Results are extracted:
lcName="SINUS_Z" resName="Accelerations, Translational (RI)"
Remember than only one load case name can be specified. However, an Array of result names can be provided. In this case, one decides to extract only one result type: “Accelerations, Translational (RI)”. On the other hand, an Array of sub-cases can be specified for the extraction of Results. In this case, the Array is first obtained by calling the “getAttachmentScNames” method:
scNames=db.getAttachmentScNames(xdbFileName)
Then, the Results are extracted as follows:
results=db.getAttachmentResults(xdbFileName,lcName,scNames,resName, "Nodes",grp)
The results are returned in a Hash object that contains pairs of Result keys, and the corresponding Results. The Results can be printed as follows:
results.each do |key,res| Util::printRes(STDOUT,key[1]+" ==> "+key[2],res) end
Note that at the beginning of the script, the buffer total maximum capacity is set to 1Mb as follows:
NastranDb::setStorageBufferMaxCapacity(1.0)
Another example of Results extraction from an XDB attachment is presented in file “attachedXdbExtract.rb”. There several Result types are extracted for a single load case and a single sub-case:
lcName="LAUNCH_ONE_MS2_Y" scName="Statics" resNames=[] resNames << "Shell Forces" resNames << "Shell Moments" resNames << "Strain Tensor" resNames << "Curvature Tensor" location="ElemCenters" grp=db.getGroupCopy("pan\_MZ") layers="NONE" results=db.getAttachmentResults(xdbFileName,lcName,scName,resNames, location,grp,layers)
Four Result types have been selected. The list of layers is set to “NONE” to avoid the extraction of Strains on each ply of each element. (One is interested only in the laminate average Strain.)
Results can then be accessed, individually by extracting the elements of the Hash object returned by the “getAttachmentResults” method. For example:
key=[lcName,scName,"Shell Moments"] shMoments=results[key] key=[lcName,scName,"Shell Forces"] shForces=results[key] key=[lcName,scName,"Strain Tensor"] shAvrgStrains=results[key] key=[lcName,scName,"Curvature Tensor"] shCurvatures=results[key]
In order to save time and simplify the programming of post-processing, it is also possible to extract linear combinations of Results. This is presented in example “attachedXdbCombili.rb”.
The linear combination is defined as an Array defining the factors and elementary load cases to consider:
scName="Statics" resName="Displacements, Translational" lcNames=["LAUNCH_ONE_MS2_X","LAUNCH_ONE_MS2_Y","LAUNCH_ONE_MS2_Z"] factors=[100.0, 50.0, 20.0] ... combili=[] (0..2).each do |i| combili << [factors[i], xdbFileName, lcNames[i]] end
Then, the linearly combine Results are extracted as follows:
lcName="CombiLC" results=db.getAttachmentResultsCombili(lcName,combili,scName,resName, "Nodes",grp)
Note that in this case, one single Result object is returned in the “results” Hash object. For example, in this case, one could have provided an Array of Result names instead of the “resName” String argument.
In example “attachedXdbDynamCombili.rb” the same operation is performed for dynamic Results, and an Array of String is provided as list of sub-cases argument. This illustrates the use of “getAttachmentResultsCombili” method returning several Results.
Example “EX19/attachedXdbRandom.rb” illustrates the use of method “calcRandomResponse” in “Post” Module. One calculates the RMS equivalent for a random response.
The calculation is done using the XDB file corresponding to a SOL111 Nastran analysis. The RMS values for accelerations are calculated. The example defines two functions:
Function “psdFunction” calculates the PSD excitation as a function of the frequency. In this case, as the excitation corresponds to a unit acceleration, the units for PSD are . Function “psdFunction” is called by “computeRms” function.
“computeRms” function calculates and returns the RMS value of a result extracted from PSD. The function has 8 arguments:
“db”: a NastranDb object containing the model and XDB attachment from which results are read.
“xdbFileName” is the name of XDB attachment.
“lcName” is the name of the load case for which the results are extracted.
“resName” is the name of the Result to extract from the XDB file.
“maxNbrFreqsPerSlice” is an integer corresponding to the maximum number of Results to be manipulated simultaneously. (One cuts the integration in several “slices” to avoid memory exhaustion when extracting the results.)
“integType” is a String corresponding to the same parameter in “calcRandomResponse” method. Possible values are “LogLog” or “LinLin”.
“method”is a String corresponding to XDB extraction method on Group. This parameter corresponds to the “method” argument of the “getAttachmentNbrResults” method in “NastranDb” class.
“grp” is the Group on which the Results are extracted. This parameter corresponds to the “grp” argument of the “getAttachmentNbrResults” method in “NastranDb””
The first part of “computeRms” function identifies the subcase names in XDB file, for the selected load case, recovers the corresponding frequencies, and sorts the sub-case names by order of increasing frequency:
infos=db.getAttachmentLcInfos(xdbFileName) h={} infos.each do |tab| if tab[0]==lcName then f=tab[5] scName=tab[1] h[f]=scName end end allFreqs=h.keys.sort totalNbrFreqs=allFreqs.size
Then, the integration is calculated by slices. The “addRes” output of a call to “calcRandomResponse” is used as argument for the next call to the same method. This “addRes” corresponds to the last PSD integration Result object:
idMin=idMax=0 addRes=nil res=nil while idMax<totalNbrFreqs idMin=idMax idMax=[idMin+maxNbrFreqsPerSlice-1,totalNbrFreqs].min freqs=allFreqs[idMin..idMax] scNames=[] psdInput=[] freqs.each do |f| scName=h[f] scNames << scName psdInput << psdFunction(f) end results=db.getAttachmentResults(xdbFileName,lcName,scNames, resName,method,grp) sortedResults=[] scNames.each do |scName| sortedResults << results[[lcName,scName,resName]] end ret=Post.calcRandomResponse(false,false,sortedResults,freqs, psdInput,integType,addRes) addRes=ret[1] res=ret[2] end