0

I have a python script that extracts the temperature from my odb file however I want it to convert the temperature output from degrees F to degrees C. We input everything as english units put then our customers want things in the degrees C. How can I modify the following script to automatically convert my output to degrees C?

from odbAccess import *
import sys

# Open output file for writing
outputFile = open('OutputFileName.txt','w')

# Define odb file names
odbNameList = ('JobName.odb',)

# Define instance name and set name
instanceNameList = ('INSTANCE-1','INSTANCE-2',)
setName = 'SET-1'

# Process odb files
for odbName in odbNameList:

# Open file for reading
    odb = openOdb(path=odbName)

# Process steps
    for stepName in odb.steps.keys():

# Get field output objects for variables TEMPERATURE and ELEMENT VOLUME
        temperatureField = odb.steps[stepName].frames[-1].fieldOutputs['NT11']
        for instanceName in instanceNameList:               
            setData = odb.rootAssembly.instances[instanceName].nodeSets[setName]

            tempField = temperatureField.getSubset(region=setData, position=NODAL)
            tempValues = tempField.values

            tmax = 0
            for v in tempValues:
                if v.data > tmax:
                    tmax = v.data

            outputFile.write('%s %s %s %6.3f\n' % (odbName, stepName, instanceName, tmax))

# Close odb file
    odb.close()

# Close output file
outputFile.close()
haledaco
  • 111
  • 1
  • 11

2 Answers2

0

In the code, simply identify which variable represents the temperature in Fahrenheit. That value is tmax. Converting that value to Celsius requires a simple calculation as demonstrated below.

if v.data > tmax:
    tmax = v.data
    tmax_celsius = (tmax-32)/1.8
chishaku
  • 4,577
  • 3
  • 25
  • 33
  • Perfect!!! that did exactly what I wanted it too. I just changed one other thing in the outputFile.write step. I changed tmax to tmax_celsius. – haledaco Oct 26 '15 at 17:36
  • @haledaco Glad it worked. Feel free to upvote or accept the answer if it satisfies your requirements. – chishaku Oct 26 '15 at 17:40
0

It seems like you are writing just the max temperature of every instance. You just need to work on tmax after you find it.

To convert Farenheit to Celsius use this formula:

C = (F-32)*(5/9)

So:

def Celsius(F):
    C = (F-32)*(5/9)
    return C

 temperatureField = odb.steps[stepName].frames[-1].fieldOutputs['NT11']
 for instanceName in instanceNameList:               
     setData = odb.rootAssembly.instances[instanceName].nodeSets[setName]

     tempField = temperatureField.getSubset(region=setData, position=NODAL)
     tempValues = tempField.values

     tmax = 0
     for v in tempValues:
        if Celsius(v.data) > tmax:
            tmax = v.data

     outputFile.write('%s %s %s %6.3f\n' % (odbName, stepName, instanceName, tmax))
Kamejoin
  • 347
  • 2
  • 8
  • In Python 2, Be-careful when dividing by 1 integer with another integer. It will return a integer and not a float. In Python 2, 5/9 = 0. Instead do this: 5.0/9 = 0.5555 – DougR Oct 27 '15 at 11:16