Batch processing of Nastran OP2 files

Trade-off studies often require post-processing and extraction of data from large CAE results files via batch scripting. iChrome’s solution? The AsciiNavigator…

Introduction

This post shows a simple example on how batch scripting can be used to extract data from CAE results file to finalize trade-off studies.
In this example we will consider a thin-wall beam with square section. The scope here is to assess how stresses change along the walls of the cross-section corresponding to the hole along with the thicknesses of the beam walls.

Contents

This post is organized as it follows:

  1. The FE model
  2. Preparing the Script
  3. Running in batch
  4. Results
  5. Conclusive Remarks

The FE model

The beam has a thin-walled squared section with a circular hole at one of the corner of the center of its length. We use shells to model the structure and we define a fine-enough mesh to capture stress gradients in each wall. Mesh has been numbered so that elements 1 to 64 correspond to the cross section to be analyzed.
The Translation degrees of freedom of each node at one end of the beam are constrained. On the other end simple point constraints are used to keep the cross-section underformed. The section is bended upward and pulled.
Results from FE analysis (performed with Nastran in this case) show pick of stress at the free edges of the hole. Due to the mix of bending and pulling force, the cross section works in tension but strain gradients are observed.


AscNav_01


AscNav_02

>> Back To Top

Preparing the Script

The batch script needs to open the Nastran binary result file for the model and extract the SMAX stress components to the elements from 1 to 64 of the models. As shells have upper and lower surfaces, we arbitrary decided to extract stresses with positive Z – values.

To prepare the script we will use the AsciiNavigator, part of the Nexus Suite. The AsciiNavigator implements effective scripting capabilities based on JavaScript. The standard JavaScript language has been extended by iChrome to support file operations and to directly link the so called CAE drivers available in Nexus, thus making JavaScript to load results from the most commons CAE Solvers such as Nastran, Ansys and Abaqus.
The AsciiNavigator can be used in graphical mode or as a stand-alone command based tool. We will use the Graphical variant to prepare and debug the script first. We will thereafter use the standalone version to run the script via a DOS batch file to programmatically extract and save values from multiple OP2.

AscNav_07

An advantage of the AsciiNavigator is the possibility to define script via user-friendly Wizards. From within the script main editor, users can access the CAE Wizard:


1) first we select the CAE Driver used to extract results. In this case we will use the Nastran driver to load an OP2 binary file. We also need to extract a full table of results, i.e. the stress tables for the set of elements ranging from 1 to 64.
AscNav_03


2) then we select OP2 from where results should be extracted from, i.e. the OES1X QUAD stress table – step 1.
Then we moved on the next Wizard page to restrict the set of results to be extracted from the table.
AscNav_04


3) as we need to extract only elements from 1 to 64, we add to the extraction script a Table filter column ID by range. Finally, we add another range filter on SD column to extract values only on the shell faces having positive Z location.
AscNav_05


4) The Wizard also allows us to verify contents of the resulting table. Once done, we close the Wizard. Resulting script will be added into the Editor at the current cursor position.
AscNav_06

Here it is the complete script as returned by the wizard and inserted in the Script Editor:

loadCaeDriver("nasDrv");
openResultFile('.CAE_DRIVER("") {	 \n \
  version, STRING, "2005"	 \n \
  filename, STRING, "C:\\WORK\\Navigator_1\\TEMPLATE\\model_002.op2" \n \
  sourcetype, STRING, "op2"	 \n \
}');
var table = loadResultTable('.CAE_RESULT("NastranOp2Result") {	 \n \
  subcase, INT, 1	 \n \
  tablecode, INT, 5	 \n \
  sortcode, INT, 1	 \n \
  devicecode, INT, 1	 \n \
  analysiscode, INT, 1	 \n \
  isreal, BOOL, 1	 \n \
  issort2, BOOL, 1	 \n \
  elementcode, INT, 33	 \n \
  name, STRING, "OES1X - Stress - QUAD4 - Subcase 1"	 \n \
  analysis, STRING, "Statics"	 \n \
  lsdvmn, INT, 1	 \n \
  title, STRING, " "	 \n \
  subtitle, STRING, "STATIC ANALYSIS"	 \n \
  label, STRING,"loadstep1 - SUBCASE 1"	 \n \
  description, STRING, "Element Stress and Strain - STATIC ANALYSIS" \n \
	 \n \
  .COLUMN("") {	 \n \
    name, STRING, "ID"	 \n \
    kind, STRING, "INTEGER"	 \n \
  }	 \n \
	 \n \
  .COLUMN("") {	 \n \
    name, STRING, "FD"	 \n \
    kind, STRING, "DOUBLE"	 \n \
  }	 \n \
	 \n \
  .COLUMN("") {	 \n \
    name, STRING, "SX"	 \n \
    kind, STRING, "DOUBLE"	 \n \
  }	 \n \
	 \n \
  .COLUMN("") {	 \n \
    name, STRING, "SY"	 \n \
    kind, STRING, "DOUBLE"	 \n \
  }	 \n \
	 \n \
  .COLUMN("") {	 \n \
    name, STRING, "TXY"	 \n \
    kind, STRING, "DOUBLE"	 \n \
  }	 \n \
	 \n \
  .COLUMN("") {	 \n \
    name, STRING, "SA"	 \n \
    kind, STRING, "DOUBLE"	 \n \
  }	 \n \
	 \n \
  .COLUMN("") {	 \n \
    name, STRING, "SMJRP"	 \n \
    kind, STRING, "DOUBLE"	 \n \
  }	 \n \
	 \n \
  .COLUMN("") {	 \n \
    name, STRING, "SMNRP"	 \n \
    kind, STRING, "DOUBLE"	 \n \
  }	 \n \
	 \n \
  .COLUMN("") {	 \n \
    name, STRING, "SMAX"	 \n \
    kind, STRING, "DOUBLE"	 \n \
  }	 \n \
	 \n \
  .FILTER() {	 \n \
	 \n \
    .PREDICATE("range") {	 \n \
      column, STRING, "ID"	 \n \
      min, INT, 1	 \n \
      max, INT, 65	 \n \
    }	 \n \
	 \n \
    .PREDICATE("range") {	 \n \
      column, STRING, "FD"	 \n \
      min, DOUBLE, 0 \n \
    }	 \n \
  }	 \n \
}');

In order to save results on file and to make the script suitable for multiple batch processing, we need to implement few minor modifications to the script.
First we make parametric the name of the OP2 file from which we need to extract results. To do that we modify the first lines as it follows:

var filename = "C:\\WORK\\Navigator_1\\TEMPLATE\\model_002.op2";
if( getEnvVar("op2File") )
	filename = getEnvVar("op2File");

loadCaeDriver("nasDrv");
openResultFile('.CAE_DRIVER("") {	 \n \
  version, STRING, "2005"	 \n \
  filename, STRING, '+filename+' \n \
  sourcetype, STRING, "op2"	 \n \
}');

This will allow the batch script to pass to the AsciiNavigator the name of the OP2 file from where results will be extracted as an environmental variable named op2File.
Finally, we will need to save the table on file with format we need. In this case we will prepare the script to generate an ASCII file having two columns, tab separated.

/* extract the two columns we are 
   interested in from the table */
id = getTableColumn(table, "ID");
smax = getTableColumn(table, "SMAX");

// columns name as file header
var text = "ID\tSMAX";
// data row
for(var r=0; r<countTableRows(table); r++) {
   text += "\n"+id[r]+"\t"+smax[r];
}
// print out table for debugging purposes
echo(text);

// open and write text on file
open(filename+".txt", "W");
writeText(text);

/* no need to close the file, the 
   AsciiNavigator does that once 
   execution has been completed */

>> Back To Top

Running in batch

The goal here is to run the script we prepared and tested above on multiple OP2 file in batch, i.e. without requiring any user interaction via GUI. We do that calling the Ascii Navigator from command line. This is a typical DOS batch script, which will produce a text result file for each processed OP2.

set op2File=C:\WORK\TEMPLATE\model_001.op2
call navigator.bat noGui cmd=script_01.js

set op2File=C:\WORK\TEMPLATE\model_002.op2
call navigator.bat noGui cmd=script_01.js

set op2File=C:\WORK\TEMPLATE\model_003.op2
call navigator.bat noGui cmd=script_01.js

set op2File=C:\WORK\TEMPLATE\model_004.op2
call navigator.bat noGui cmd=script_01.js

which will produce 4 distinct result files, one for each processed OP2.

>> Back To Top

Results

Once results have been extracted and saved in plain ASCII file, we can use them to easily derive trade-off studies. As an example, we can import them in Excel or Matlab for further post-processing. We do prefer Grapheme and its charting module. Results are shown below.
AscNav_08

>> Back To Top

Remarks

In this post we have seen how scripts can be used to programmatically extract data from FE result files. More in particular, we used the Graphical User Interface of the Nexus AsciiNavigator to prepare an extraction script to work with OP2 Nastran file.
We modified the script generated by the Wizard of the Graphical User Interface to receive file names from outside with Operative System environmental variables.
Finally we prepared a DOS batch file to execute the script multiple times and we finally imported resulting files within Grapheme to visualize stress changes along the analyzed cross section.

>> Back To Top