News:

SMF - Just Installed!

Main Menu

ODB temperature writer

Started by Mark Barkey, December 15, 2016, 12:33:33 AM

Previous topic - Next topic

Mark Barkey

data files are here:
http://forums.mbarkey.com/index.php?topic=124.0



#write selected frame results for nodal temperatures to an ODB file
#or write nodal temperature from a file to an ODB file
#M. E. Barkey
# 14 December 2016

#with reference from python code from Mustaine
#ww3.cad.de/foren/ubb/Forum254/HTML/000798.shmtl
#and
#www.eng-tips.com/viewthread.cfm?qid=306565
#and
#http://www.eng-tips.com/viewthread.cfm?qid=248461




#some of these may not be needed, but I haven't taken the time to sort it out.
import sys
import csv
from odbAccess import *
from abaqusConstants import *
from types import IntType
from numpy import array
from numpy import genfromtxt
import numpy as np
import odbAccess


odbName = 'spt1b'
odb = openOdb(odbName + '.odb', readOnly=False)

#The following is the target ODB
odbWrite=openOdb(path="spt1c.odb", readOnly=False)

print'------------------------------------------------'
print'Define step and frame to be read from existing ODB'
steptoread=odb.steps['Step-2']
frametoread=steptoread.frames[4]
odbSelectResults=frametoread.fieldOutputs['NT11']
t = odbSelectResults

#these can be uncommented for some checks of the data
#print '-------------------------------------------'
#print t.__members__
#print '-------------------------------------------'
#print t.values[1]

print odb.rootAssembly.instances.keys()


#note that this must be the part in your file
instance1 = odbWrite.rootAssembly.instances['PART-1-1']


#the following lines write the entire frame of the first ODB into the target ODB
#the step name, desctription, etc, can all be changed here
newDataSet = odbSelectResults
newResultsStep=odbWrite.Step(name='TestStep3', description = 'user defined', domain=TIME, timePeriod = 0)
newResultsFrame=newResultsStep.Frame(incrementNumber=0, frameValue=0.0)
newResultsField=newResultsFrame.FieldOutput(name='NT11', description='user def', type=SCALAR)
newResultsField.addData(field=newDataSet)
odbWrite.save()



#the following lines read a single column text file of nodes
#then reads a single column text file of corresponding temepatures
#note that the scalar field must be a "sequence of sequences"
#so it must look like this:    (  (temp1,) ,   (temp2,),   (temp3,),   (temp4,) ... )
#and NOT this: (temp1, temp2, temp3, temp4,...)

with open('nodelist.txt') as f:
    nodes = f.read().splitlines()

#makes sure this is a tuple of integer nodes   
n = map(int, nodes)   



#this line reads in the temperature values.  They must be sequentially corressponding to the nodes.
#it puts them in the proper format (sequence of sequence)   
with open('values.txt') as f:
    mylist = [tuple(map(float, i.split(','))) for i in f]   
   

v = mylist

#print v


#the following is the format of the data that will work for 6 nodes
#meblabel = (41312, 41313, 41314, 41315, 41316, 41317)
#mebdata = ( (-100.0,), (-100.0,),(-100.0,),(-100.0,),(-100.0,),(-100.0,))


#un-comment the following line if you want the read-in data to go to a new step
#newResultsStep=odbWrite.Step(name='TestStep4', description = 'user defined', domain=TIME, timePeriod = 0)

newResultsFrame=newResultsStep.Frame(incrementNumber=1, frameValue=1.0)
newResultsField=newResultsFrame.FieldOutput(name='NT11', description='user def', type=SCALAR)

#this is to double check that the correct key has been created--it should be NT11
print '-------------------------------------------'
print newResultsFrame.fieldOutputs.keys('')
print '-------------------------------------------'


newResultsField.addData(position=NODAL, instance=instance1, labels=n, data=v)


odbWrite.save()


print
print '-------------------------------------------'


odb.save()
odb.close()




Mark Barkey

Need to add that this won't work if you run it from ABAQUS CAE, you must run from command window as ABAQUS python scriptname.py