Finding the maximum value of von Mises stress

This example illustrates how you can iterate through an output database and search for the maximum value of von Mises stress. The program opens the output database specified by the first argument on the command line and iterates through the following:

  • Each step.

  • Each frame in each step.

  • Each value of von Mises stress in each frame.

In addition, you can supply an optional assembly element set argument from the command line, in which case the program searches only the element set for the maximum value of von Mises stress.

The following illustrates how you can run the example program from the system prompt. The program will search the element set ALL ELEMENTS in the viewer tutorial output database for the maximum value of von Mises stress:

abaqus odbMaxMises.exe -odb viewer_tutorial.odb 
    -elset “ ALL ELEMENTS”

Note:

If a command line argument is a String that contains spaces, some systems will interpret the String correctly only if it is enclosed in double quotation marks. For example, “ ALL ELEMENTS”.

You can also run the example with only the -help parameter for a summary of the usage.

Use the following commands to retrieve the example program and the viewer tutorial output database:

abaqus fetch job=odbMaxMises.C
abaqus fetch job=viewer_tutorial
/***************************************************************
odbMaxMises.C
Code to determine the location and value of the maximum 
von-mises stress in an output database.
Usage: abaqus odbMaxMises -odb odbName -elset(optional)
       elsetName
Requirements:
1. -odb   : Name of the output database.
2. -elset : Name of the assembly level element set. 
            Search will be done only for element belonging 
            to this set. If this parameter is not provided, 
            search will be performed over the entire model.
3. -help  : Print usage
****************************************************************/
#if (defined(HP) && (! defined(HKS_HPUXI)))
#include <iostream.h>
#else
#include <iostream>
using namespace std;
#endif

#include <odb_API.h>
#include <sys/stat.h>
/*
*************** 
utility functions
***************
*/
bool fileExists(const odb_String  &string);
void rightTrim(odb_String  &string,const char* char_set);
void printExecutionSummary();
/***************************************************************/


int ABQmain(int argc, char **argv)
{
  odb_String odbPath;  
  bool ifOdbName = false;
  odb_String elsetName;
  bool ifElset = false;
  odb_Set myElset;
  odb_String region = "over the entire model";
  char msg[256];
  char *abaCmd = argv[0];
  
  for (int arg = 0; arg<argc; arg++)
    {
      if (strncmp(argv[arg],"-o**",2) == 0)
	{
	  arg++;
	  odbPath = argv[arg];
	  rightTrim(odbPath,".odb");
	  if (!fileExists(odbPath))
	    {
	      cerr << "**ERROR** output database  " << odbPath.CStr() 
		   << " does not exist\n" << endl;
	      exit(1);
	    }
	  ifOdbName = true;
	}	  
      else if (strncmp(argv[arg],"-e**",2)== 0)
	{
	  arg++;
	  elsetName = argv[arg];
	  ifElset = true;
	}
      else if (strncmp(argv[arg],"-h**",2)== 0)
	{
	  printExecutionSummary(); 
	  exit(0);
	}
    }
  if (!ifOdbName)
    {
      cerr << "**ERROR** output database name is not provided\n";
      printExecutionSummary();
      exit(1);
    }
  // Open the output database
  odb_Odb& myOdb = openOdb(odbPath);
  odb_Assembly& myAssembly = myOdb.rootAssembly();
  if (ifElset) 
    {
      if (myAssembly.elementSets().isMember(elsetName))
	{       
	  myElset = myAssembly.elementSets()[elsetName]; 
	  region = " in the element set : " + elsetName;
	}
      else
        {
	    cerr<<"An assembly level elset " << elsetName.CStr()
            << " does not exist in the output database :"
            << myOdb.name().CStr() << endl;
	  myOdb.close();
	  exit(0);
	}
    }
  // Initialize maximum values.
  float maxMises = -0.1;
  int numFV = 0;
  int maxElem = 0;
  odb_String maxStep = "__None__";  
  int maxFrame = -1;
  static const odb_String Stress = "S";    
  bool isStressPresent = false;
  int numBD = 0,numElems = 0, numIP = 0, numComp = 0, position = 0;
  // Iterate over all available steps
  odb_StepRepository& sRep1 = myOdb.steps();        
  odb_StepRepositoryIT sIter1 (sRep1);
  for (sIter1.first(); !sIter1.isDone(); sIter1.next())
    {
      odb_Step& step = sRep1[sIter1.currentKey()];
      cout<<"Processing Step: "<<step.name().CStr()<<endl;
      odb_SequenceFrame& frameSequence = step.frames();
      int numFrames = frameSequence.size();      
      for (int f = 0; f<numFrames; f++) 
	{
	  odb_Frame& frame = frameSequence[f]; 
	  odb_FieldOutputRepository& fieldRep = frame.fieldOutputs();
	  if (fieldRep.isMember(Stress))
	   {
	     isStressPresent = true;
	     odb_FieldOutput field = fieldRep.get(Stress);
	     if (ifElset) 
	       field = field.getSubset(myElset);
	     const odb_SequenceFieldBulkData& seqVal = 
                 field.bulkDataBlocks(); 
	     int numBlocks = seqVal.size();
	     for ( int iblock=0; iblock<numBlocks; iblock++) 
	       {
		 const odb_FieldBulkData& bulkData = seqVal[iblock];	      
		 numBD = bulkData.length();
		 numElems = bulkData.numberOfElements();
		 numIP = numBD/numElems;
		 numComp = bulkData.width();
		 float* mises = bulkData.mises();
		 int* elementLabels = bulkData.elementLabels();
		 int* integrationPoints = bulkData.integrationPoints();	
		 for (int elem=0; elem<numElems; elem++) 
		   {				    	  		     
		     for (int ip=0; ip<numIP; ip++)
		       {
			 position = elem*numIP+ip;
			 float misesData = mises[position];		
			 if (misesData > maxMises)
			   {
			     maxMises = misesData;
			     maxElem = elementLabels[elem];
			     maxStep = step.name();
			     maxFrame = frame.incrementNumber();
			   }
		       }
		   }
	       }

	   }	
	}    
    }
  if (isStressPresent)
    {
      cout << "Maximum von Mises stress " << region.CStr() 
	   << " is " << maxMises << "  in element " 
           << maxElem << endl;
      cout << "Location: frame # " << maxFrame << " step:  " 
           << maxStep.CStr() << endl;
    }
  else
    {
      cout << " Stress output is not available in  the "
	   << "output database : " << myOdb.name().CStr() << endl;
    }        
  // close the output database before exiting the program
  myOdb.close();
  return(0);
}

bool fileExists(const odb_String  &string)
{
  bool exists = false;
  struct  stat  buf;  
  if (stat(string.CStr(),&buf)==0)
    exists = true;
  return exists;
}

void rightTrim(odb_String  &string,const char* char_set)
{
  int length = string.Length();
  if (string.Find(char_set)==length)
    string.append(odb_String(char_set));
}

void printExecutionSummary()
{
  cout << " Code to determine the location and value of the\n"
  << " maximum von-mises stress in an output database.\n"
  << " Usage: abaqus odbMaxMises -odb odbName \n"
  << " -elset(optional), -elsetName\n"
  << " Requirements:\n"
  << " 1. -odb   : Name of the output database.\n"
  << " 2. -elset : Name of the assembly level element set.\n"
  << "             Search will be done only for element \n"
  << "             belonging to this set.\n"
  << "             If this parameter is not provided, search \n"
  << "             will be performed over the entire model.\n"
  << " 3. -help  : Print usage\n";
}