The C# program illustrates the reading of stresses
from a Nastran OP2 file using FeResPost .NET assembly.
The listing of the program is presented below:
using
System;
using
System.Collections;
using
System.Collections.Generic;
using
System.Text;
using
System.Globalization;
using
System.IO;
using
System.Threading;
using
FeResPost ;
using
std ;
namespace
ConsoleApplication1 {
class printStressMax {
static void Main(string[] args) {
Thread.CurrentThread.CurrentCulture=new
CultureInfo("en-US");
StreamWriter stdout=new StreamWriter(Console.OpenStandardOutput());
stdout.AutoFlush=true;
// Initialization of the DataBase :
NastranDb db = new NastranDb();
db.Name="tmpDB";
db.readBdf("../../MODEL/MAINS/orbit_unit_xyz.bdf");
db.readGroupsFromPatranSession("../../MODEL/PATRAN/groups.ses");
// Groups from Materials :
Group tmpGroup_Honey_50=db.getElementsAssociatedToMaterials(5);
tmpGroup_Honey_50=tmpGroup_Honey_50+db.getElementsAssociatedToMaterials(4);
tmpGroup_Honey_50.Name="Honey_50";
Group tmpGroup_Honey_72=db.getElementsAssociatedToMaterials(6);
tmpGroup_Honey_72.Name="Honey_72";
Group tmpGroup_Al_2024=db.getElementsAssociatedToMaterials(3);
tmpGroup_Al_2024.Name="Al_2024";
Group tmpGroup_CFRP=db.getElementsAssociatedToMaterials(10000);
tmpGroup_CFRP.Name="CFRP";
// Groups created by intersection :
ArrayList tmpAL;
tmpAL=new ArrayList();
tmpAL.Clear();
tmpAL.Add(tmpGroup_Honey_50);
tmpAL.Add(tmpGroup_Honey_72);
tmpAL.Add(tmpGroup_Al_2024);
tmpAL.Add(tmpGroup_CFRP);
object[] matGroups=tmpAL.ToArray();
db.addGroupCopy(tmpGroup_Honey_50);
db.addGroupCopy(tmpGroup_Honey_72);
db.addGroupCopy(tmpGroup_Al_2024);
db.addGroupCopy(tmpGroup_CFRP);
tmpAL.Clear();
tmpAL.Add("pan_MX");
tmpAL.Add("pan_MY");
tmpAL.Add("pan_MZ");
tmpAL.Add("pan_PX");
tmpAL.Add("pan_PY");
tmpAL.Add("pan_PZ");
tmpAL.Add("pan_SUP");
object[] panelGroupNames=tmpAL.ToArray();
foreach (string
panelGroupName in panelGroupNames)
{
//Console.WriteLine(panelGroupName);
Group panelGroup = db.getGroupCopy(panelGroupName);
foreach
(Group matGrp in matGroups)
{
Group newGrp=panelGroup*matGrp;
newGrp.Name=panelGroupName+"_"+matGrp.Name;
//Console.WriteLine(newGrp.Name);
//Console.WriteLine(newGrp.getEntitiesByType("Element").GetLength(0));
if
(newGrp.getEntitiesByType("Element").GetLength(0)>0)
db.addGroupCopy(newGrp);
} // foreach (Group matGrp in matGroups)
} // foreach
(string panelGroupName in panelGroupNames)
// Reading Results :
db.readOp2("../../MODEL/EXEC_OP2/orbit_unit_xyz.op2","Results");
object[] key;
foreach (object obj in db.iter_resultKey) {
//~ Console.WriteLine("(type=\"{0:S}\")",obj.GetType());
key=(object[])obj;
Console.WriteLine("RESULT KEY = (\"{0:S} -
{1:S} - {2:S}\")",key[0],key[1],key[2]);
}
// Retrieving some Results and performing
operations :
String[] layers=new String[0];
Group targetGrp;
Result stress,scalar,maxScalar,maxStress,sXZ,sYZ;
ResKeyList maxRkl;
object[,] maxScalarData,maxStressData;
// Maximum Von Mises stress :
targetGrp=db.getGroupCopy("pan_PZ_Al_2024");
stress= db.getResultCopy("ORBIT_ONE_MS2_Z","Statics",
"Stress Tensor","ElemCorners",targetGrp,layers);
scalar=stress.deriveTensorToOneScal("VonMises");
maxScalar=scalar.extractResultMax();
maxRkl=maxScalar.extractRkl();
maxStress=stress.extractResultOnRkl(maxRkl);
maxScalarData=maxScalar.getData();
maxStressData=maxStress.getData();
Console.WriteLine();
Console.WriteLine("Maximum
Von Mises stress in panel +Z skins :");
Console.WriteLine();
Console.Write("
{0:F2} Pa ",maxScalarData[0,5]);
Console.Write("on
element {0:D} ",maxScalarData[0,0]);
Console.WriteLine("(layer=\"{0:S}\")",maxScalarData[0,2]);
Console.Write("
Sxx = {0:F2}, ",maxStressData[0,5]);
Console.Write("Syy = {0:F2}, ",maxStressData[0,6]);
Console.WriteLine("Szz = {0:F2}, ",maxStressData[0,7]);
Console.Write("
Sxy = {0:F2}, ",maxStressData[0,8]);
Console.Write("Syz = {0:F2}, ",maxStressData[0,9]);
Console.WriteLine("Szx = {0:F2} ",maxStressData[0,10]);
// Maximum out of plane shear stress :
targetGrp=db.getGroupCopy("pan_PZ_Honey_72");
stress= db.getResultCopy("ORBIT_ONE_MS2_Z","Statics",
"Stress Tensor","ElemCorners",targetGrp,layers);
sXZ=stress.deriveTensorToOneScal("Component XZ");
sYZ=stress.deriveTensorToOneScal("Component YZ");
scalar=Post.sqrt(sXZ*sXZ+sYZ*sYZ);
maxScalar=scalar.extractResultMax();
maxRkl=maxScalar.extractRkl();
maxStress=stress.extractResultOnRkl(maxRkl);
maxScalarData=maxScalar.getData();
maxStressData=maxStress.getData();
Console.WriteLine();
Console.WriteLine("Maximum
out of plane shear stress in panel +Z honeycomb :");
Console.WriteLine();
Console.Write("
{0:F2} Pa ",maxScalarData[0,5]);
Console.Write("on
element {0:D} ",maxScalarData[0,0]);
Console.WriteLine("(layer=\"{0:S}\")",maxScalarData[0,2]);
Console.Write("
Sxx = {0:F2}, ",maxStressData[0,5]);
Console.Write("Syy = {0:F2}, ",maxStressData[0,6]);
Console.WriteLine("Szz = {0:F2}, ",maxStressData[0,7]);
Console.Write("
Sxy = {0:F2}, ",maxStressData[0,8]);
Console.Write("Syz = {0:F2}, ",maxStressData[0,9]);
Console.WriteLine("Szx = {0:F2} ",maxStressData[0,10]);
// Maximum "MaxShear" stress :
targetGrp=db.getGroupCopy("pan_PZ_Honey_72");
stress= db.getResultCopy("ORBIT_ONE_MS2_Z","Statics",
"Stress Tensor","ElemCorners",targetGrp,layers);
scalar=stress.deriveTensorToOneScal("MaxShear");
maxScalar=scalar.extractResultMax();
maxRkl=maxScalar.extractRkl();
maxStress=stress.extractResultOnRkl(maxRkl);
maxScalarData=maxScalar.getData();
maxStressData=maxStress.getData();
Console.WriteLine();
Console.WriteLine("Maximum
\"MaxShear\" stress in panel +Z honeycomb :");
Console.WriteLine();
Console.Write("
{0:F2} Pa ",maxScalarData[0,5]);
Console.Write("on
element {0:D} ",maxScalarData[0,0]);
Console.WriteLine("(layer=\"{0:S}\")",maxScalarData[0,2]);
Console.Write("
Sxx = {0:F2}, ",maxStressData[0,5]);
Console.Write("Syy = {0:F2}, ",maxStressData[0,6]);
Console.WriteLine("Szz = {0:F2}, ",maxStressData[0,7]);
Console.Write("
Sxy = {0:F2}, ",maxStressData[0,8]);
Console.Write("Syz = {0:F2}, ",maxStressData[0,9]);
Console.WriteLine("Szx = {0:F2} ",maxStressData[0,10]);
// Maximum "BeamStress"
stress :
targetGrp=db.getGroupCopy("strut_A");
stress= db.getResultCopy("ORBIT_ONE_MS2_X","Statics",
"Beam Axial
Stress for Bending Loads","ElemCorners",targetGrp,layers);
scalar=Post.abs(stress);
maxScalar=scalar.extractResultMax();
maxRkl=maxScalar.extractRkl();
maxStress=stress.extractResultOnRkl(maxRkl);
maxScalarData=maxScalar.getData();
maxStressData=maxStress.getData();
Console.WriteLine();
Console.WriteLine("Maximum
beam bending stress in strut A :");
Console.WriteLine();
Console.Write("
{0:F2} Pa ",maxScalarData[0,5]);
Console.Write("on
element {0:D} ",maxScalarData[0,0]);
Console.WriteLine("(layer=\"{0:S}\")",maxScalarData[0,2]);
Console.Write("
Sxx = {0:F2} ",maxStressData[0,5]);
Console.WriteLine();
Console.WriteLine();
} // static void Main(string[] args)
} // class printStressMax
}
// namespace ConsoleApplication1
The compilation of the program is done with Microsoft Visual C# compiler. On my
computer, the instructions look as follows:
set
FRP=../../../SRC/OUTPUTS/NET/X86_CLR2
set PLATFORM=X86
set LIB=
set INCLUDE=D:/SHARED/FERESPOST/SRC
set PATH=C:/NewProgs/MSYS/1.0/bin;C:/NewProgs/RUBY/Ruby187/bin;C:/Windows/system32
csc.exe -platform:%PLATFORM% -r:%FRP%/FeResPost.dll ..\UTIL\util.cs
printStressMax.cs
The different parts of the program are discussed
briefly below:
The example, also presents variants
of the scalar derivation as the extraction of stress tensor shear components
for the calculation of honeycomb core, or derivation of scalar result
with FeResPost pre-defined "MaxShear" criterion. One also shows that
the extraction of other results as beam stresses is possible.
You probably noticed that the example presented here is longer than other
similar examples with Ruby or Python languages. In particular, the programming
of results printing is particularly tedious with C#. On the other hand, the
programming with C# or other languages that use FeResPost .NET assembly can
have some advantages:
More information on this example, and the manual
explaining the functions used in this example are given in FeResPost
Reference Manual.