title: Creating a script for a custom field output in ABAQUS
body: <p>I want to create a custom field output in ABAQUS. For the purpose of proof on concept, I want to display the maximum shear stress as calculated from the Mohrs circle, as discussed <a href="http://www.efunda.com/formulae/solid_mechanics/mat_mechanics/calc_principal_stress.cfm" rel="nofollow noreferrer">here</a> for a 2D shell.</p>
  
  <p>I have my code below for reference:</p>
  
  <pre><code>from abaqusConstants import *
  from odbAccess import *
  from math import *
  from copy import deepcopy
  from caeModules import *
  from driverUtils import executeOnCaeStartup
  
  # ******************************************************************************
  #Items in this box require student input when changing files
  
  #must input the file path here.
  odbPath = "/home/MohrsTest.odb"
  
  odb = session.openOdb(name=odbPath, readOnly=FALSE)
  odb = session.odbs[odbPath]
  #this will display the instance names. Please choose one to input in line 14.
  print odb.rootAssembly.instances.keys()
  grout_instance = odb.rootAssembly.instances['SQUARE-1']
  # ******************************************************************************
  keys = odb.steps.keys()
  for key in keys:
      step = odb.steps[key]
      for frame in step.frames:
          print frame.description
          Stress = frame.fieldOutputs['S']
          #try modifying scalar fields rather than creating new var element by element.
          S11=Stress.getScalarField(componentLabel="S11")
          S22=Stress.getScalarField(componentLabel="S22")
          S12=Stress.getScalarField(componentLabel="S12")
          TauMax=((S11+S22)*0.5+sqrt(power((S11-S22)/2, 2)+power(S12, 2)))-((S11+S22)*0.5-sqrt(power((S11-S22)/2, 2)+power(S12, 2)))/2
          ThetaP=(atan2(2 * S12, (S11 - S22))/2) * 180/pi
          frame.FieldOutput(name='Tau Max', description='Max Tau from Mohrs circle',field=TauMax)
          frame.FieldOutput(name='Theta P', description='Thetap as measured ccw from 0 degree',field=Thetap)
  odb.save()
  odb.close()
  #  must re - open the output database to see the new custom field output
  </code></pre>
  
  <p>Abaqus throws an error immediately upon trying to calculate TauMax because of "Type Error: A float is required." However, I tried using "Tools->Field Outputs-> Create from Fields" and then created a field output in the cae for the individual frame. 
  If I look at the replay file for this action, I can see the following code:</p>
  
  <pre><code>s1f1_S = session.odbs['/home/MohrsTest.odb'].steps['Step-1'].frames[1].fieldOutputs['S']
  tmpField = (((s1f1_S.getScalarField(componentLabel="S11")+\
      s1f1_S.getScalarField(componentLabel="S22"))*0.5+sqrt(power((
      s1f1_S.getScalarField(componentLabel="S11")-s1f1_S.getScalarField(
      componentLabel="S22"))/2, 2)+power(s1f1_S.getScalarField(
      componentLabel="S12"), 2)))-((s1f1_S.getScalarField(componentLabel="S11")+\
      s1f1_S.getScalarField(componentLabel="S22"))*0.5-sqrt(power((
      s1f1_S.getScalarField(componentLabel="S11")-s1f1_S.getScalarField(
      componentLabel="S22"))/2, 2)+power(s1f1_S.getScalarField(
      componentLabel="S12"), 2))))/2
  </code></pre>
  
  <p>Thus, clearly math operations on a FieldObject must be possible. Why does my code not permit this?</p>
  
  <p>I am happy to provide all .odb and .cae files for reference and verification. </p>