X.F.3.1 Simple extraction of components
A new post-processing class is created to allow the presentation of dynamic Results. Actually, this
class only extracts the magnitude and phase for one finite element entity and one component, and
saves it into an Array, for later output in a text file. The class is called “PostExtract” and has only one
member data: “extracts” in which the extracted Results shall be stored.
The “initialize” method calls the constructor of the parent class and initializes “extracts” to a void
Hash:
def initialize
super
@extracts = {}
end
Then the sequence of operations to perform the extractions is described below. It is performed by the
“calcOneGroup” method:
def calcOneGroup(db,lcName,scName,refName,grpContent,resName,
extractMethod,csId,component)
...
The method has nine arguments:
- The usual “db”, “lcName” and “scName” arguments.
- “refName”: is used to reference the extracted Results in “extracts” member data.
- “grpContent” the description of entities for which Results are extracted. This argument
contains a String that must correspond to exactly one extracted value. For example:
“Element 10”, “Node 17”.
- “resName”: a String containing the name of the Result stored in the DataBase “db” and
from which one value shall be extracted.
- “extractMethod”: a String corresponding to the extraction method of “getResultCopy”
DataBase method.
- “csId” the identifier of the coordinate system in which the Result shall be expressed. This
argument can be an integer or a String.
- “component” The name of the component one shall extract. This is a String with 0, 1
or 2 characters. For example: "", "Y", "ZZ", "ZY"... (The void String is used if no
extraction operation is necessary. This is the case when the Result obtained from the
DataBase is already scalar.
Then the following sequence of operations:
- One builds a Group “grp” that shall be used for the extraction of a Result from the DataBase
“db”:
grp=Group.new
grp.Name=refName
grp.setEntities(grpContent)
- The Result is extracted:
res=db.getResultCopy(lcName,scName,resName,extractMethod,grp,[])
- If the Result is vectorial or tensorial, the transformation of coordinate system is done:
if (res.TensorOrder>0) then
res.modifyRefCoordSys(db,csId)
end
- One builds a new Result “compRes” by extraction of a component. Of course, if the Result is
already scalar, one just performs an assignation operation:
if (component.size==0) then
compRes=res
elsif (component.size==1) then
compRes=res.deriveVectorToOneScal("Component "+component)
elsif (component.size==2) then
compRes=res.deriveTensorToOneScal("Component "+component)
end
- Then, one retrieves an Array “grpHashRes” from “extracts” member data. If the Array is not
found in the Hash by key “refName”, this means that this key appears for the first time. then,
one initializes a new Array and inserts it in “extracts”.
if @extracts.has_key?(refName) then
grpHashRes=@extracts[refName]
else
grpHashRes=[]
@extracts[refName]=grpHashRes
end
- Finally, one inserts extracted values in “grpHashRes”. The four values inserted are the output
index, the frequency, the magnitude and the phase:
compRes.set2MP
data=compRes.getData
mag=data[0][5]
phase=data[0][6]
grpHashRes << [compRes.getIntId(1),compRes.getRealId(0),mag,phase]
The class “PostExtract” also defines a method for the final processing of the values stored in “extracts”
member data. This method, called “gnuplot” outputs the Results in text files created in
“OUT_DYNAM” directory. Also, a “dat” file containing the gnuplot commands to create graphical
outputs is created in the same directory. The name of this command file is the argument of “gnuplot”
method:
def gnuplot(datName)
gnuplotOs=File::open("OUT' _DYNAM/"+datName,"w")
gnuplotOs.printf("' nset terminal png' n' n")
@extracts.each do |key,tabs|
fileName="OUT' _DYNAM/"+key+".txt"
os=File::open(fileName,"w")
tabs.each do |mode,freq,mag,phase|
os.printf("%4d%15g%15g%15g' n",mode,freq,mag,phase)
end
os.close
gnuplotOs.printf("set output ' "%s_m.png' "' n",key)
gnuplotOs.printf("plot ' "%s.txt' " using 2:3 with lines' n",key)
gnuplotOs.printf("set output ' "%s_p.png' "' n",key)
gnuplotOs.printf("plot ' "%s.txt' " using 2:4 with points 1' n' n",key)
end
gnuplotOs.close
end