News:

SMF - Just Installed!

Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Mark Barkey

#41
Scripting and Python / ODB temperature writer
December 15, 2016, 12:33:33 AM
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()



#44
Scripting and Python / ODB temperature reader
December 10, 2016, 02:40:54 AM

#read selected frame results for nodal temperatures from ODB file
#M. E. Barkey
# 9 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




import sys
from odbAccess import *
from abaqusConstants import *
from types import IntType
from numpy import array


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


print'------------------------------------------------'
print'This step will be read from the ODB'
#this is the step just as it is labeled in the ODB when the input file was analyzed
steptoread=odb.steps['Step-2']
print' selected step:  ', steptoread.name
print ''
print'------------------------------------------------'
#frame 0 is the first frame
# from -1 is the last frame
#these are the same frame numbers that are in the ODB
frametoread=steptoread.frames[4]

#this grabs only the NT11 field data
print'Only write out the NT11 (temperature) field from this frame of this step.'
odbSelectResults=frametoread.fieldOutputs['NT11']

#this was written for ABAQUS 6.14-2, the following may be different for other verions
#values in the field odbSelectResults
#here is an example with data in it
#({'baseElementType': '', 'conjugateData': None, 'conjugateDataDouble': 'unknown', 'data': 570.72705078125,
#'dataDouble': 'unknown', 'elementLabel': None, 'face': None, 'instance': 'OdbInstance object',
#'integrationPoint': None, 'inv3': None, 'localCoordSystem': None, 'localCoordSystemDouble': 'unknown',
#'magnitude': None, 'maxInPlanePrincipal': None, 'maxPrincipal': None, 'midPrincipal': None, 'minInPlanePrincipal': None,
#'minPrincipal': None, 'mises': None, 'nodeLabel': 41313, 'outOfPlanePrincipal': None, 'position': NODAL,
#'precision': SINGLE_PRECISION, 'press': None, 'sectionPoint': None, 'tresca': None, 'type': SCALAR})

#this is to get the nodes in the root assembly
#nodes = odbSelectResults.getSubset(region=odb.rootAssembly.nodeSets[' ALL NODES'])

#this will show the fields that are in nodes
#print nodes

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

print 'selected results  ', odbSelectResults.name

t = odbSelectResults

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

#this prints out the data (temperature) of element 50 in t
#print t.values[50].data

#this prints out the 0-10 elements of t
#for n in range (0,10):
# print t.values[n].data

#this prints out the nodeLabels and data (temperature) for the nodes
#this is a loop for all the number of entries in the tuple
#notice that nodeLabel and data are fields from above and that any of these fields can be included in the statement
#they must be spelled correctly including capitalization

for x in t.values:
    print x.nodeLabel, x.data
   

   
text = 'This is a header line'   
for x in t.values:
    output = str(x.nodeLabel) +'\t'+str(x.data)
    text = '\n'.join([text, output])
   
data = file('results.xls', 'w')   
data.write(text)
data.close()
   


odb.close()


#46
Scripting and Python / Python resources
December 04, 2016, 12:54:24 AM
Python

https://www.python.org/


ABAQUS through 6.14 appears to use Python 2.7.x

reserved words
https://docs.python.org/2/reference/lexical_analysis.html


and
del     
from     
not       
while
as   
elif     
global   
or     
with
assert
else     
if       
pass   
yield
break
except
import 
print
class   
exec     
in       
raise
continue
finally
is   
return
def     
for     
lambda 
try
#49
Welcome Center / Theme reset
November 06, 2016, 01:44:33 AM
I have reset the theme since the previous theme had some issues with Firefox.  I will update the header as I get time.
#50
Fortran / Fortran 77 statement examples
February 15, 2015, 11:25:27 PM
------------Program statement-----------------------------------

                Program coord


-------------variable declaration statements-------------------

                integer node1(50000), node2(50000), i, totn, j         
                double precision crd1(50000,3), crd2(50000,3)      
                character*100  line






#51
Useful Software / G95 Fortran
February 15, 2015, 10:20:34 PM
G95 Fortran g95-Mingw_201210.exe


local link:  http://forums.mbarkey.com/index.php?action=downloads;sa=view;down=2

http://www.g95.org/

Note:  the windows binary download link there is broken.

Quote
   G95 is a stable, production Fortran 95 compiler available for multiple cpu architectures and operating systems. Innovations and optimizations continue to be worked on. Parts of the F2003 and F2008 standards have been implemented in g95.
#52
Useful Software / Crimson Editor
February 15, 2015, 09:42:24 PM
Crimson editor is my favorite text editor for *.inp files, python files, fortran source code, data files, and other large text files.

-------------------------------------------------------------


http://www.crimsoneditor.com/

sourceforge link:  http://sourceforge.net/projects/emeraldeditor/files/

local link:  http://forums.mbarkey.com/index.php?action=downloads;sa=view;down=1



Quote
Crimson Editor is a professional source code editor for Windows.

This program is not only fast in loading time, but also small in size (so small that it can be copied in one floppy disk).

While it can serve as a good replacement for Notepad, it also offers many powerful features for programming languages such as HTML, C/C++, Perl and Java.

   Syntax Highlighting for HTML, C/C++, Perl, Java, Matlab and LaTeX. Also, it can be extended for other programming languages based on custom syntax files.
- how to make custom syntax files...
   Other features include undo/redo, user tools, macros, spell checker and more.
- see more crimson editor features...


Crimson Editor will be superceded by Emerald Editor. And, the lastest download version of Crimson Editor is maintained by The Emerald Editor Community.

Crimson Editor 3.72 Release (May. 14, 2008) - from sourceforge.net

Crimson Editor is FREEWARE. You are free to download and use it.
If you find it useful, please distribute it to your friends without any modification.

Crimson Editor 3.70 Release (Sep. 22, 2004, 1224KB) - from this site

System Requirements
Win95 or higher, WinNT 4.0 or higher
4MB free disk space

#53
Scripting and Python / How to run an ABAQUS python script
February 15, 2015, 09:39:50 PM
From the ABAQUS command line in the MS-DOS (command) window type:

abaqus python odbCoordinateReader2.py

where in place of odbCoordinateReader2 goes the name of your python script.

-----------------------------------------

From inside of ABAQUS CAE
file menu
run script
then select your script to run
#54
Scripting and Python / ODB Coordinate Reader
February 15, 2015, 09:35:29 PM
odbCoordinateReader2.py

Script to open an output database and print intial and final
coordinates of step 1 (first and last frames of step 1).

This could be updated by only writing out a node set instead of all the nodes.

Note that in order for this to be used, the output identifier COORD must
be written to the ODB. This is not a default setting for preselected field
variables.

M. E. Barkey 2/15/2015



"""
odbCoordinateReader2.py

Script to open an output database and print intial and final
coordinates of step 1 (first and last frames of step 1).

This could be updated by only writing out a node set instead of all the nodes.

Note that in order for this to be used, the output identifier COORD must
be written to the ODB. This is not a default setting for preselected field
variables.

M. E. Barkey 2/15/2015
"""


#based on ABAQUS 6.13 example
#9.10.3 An Abaqus Scripting Interface version of FPERT


import sys
from odbAccess import *
from types import IntType



# Get input from the user

odbName = raw_input('Enter odb name (w/o .odb): ')
odb = openOdb(odbName + '.odb')

modes = 1
factors = 2

#this reads the first frame [0] of the first step [0]
step = odb.steps.values()[0]
coords = step.frames[0].fieldOutputs['COORD']

#this reads the last frame [-1] of the first step [0]
steplast = odb.steps.values()[0]
coordslast = steplast.frames[-1].fieldOutputs['COORD']

#open a text ouput file and write the initial and final coordinates.
outFile = open(odbName + '.coordinates.dat', 'w')

#these text lines are 65 characters long
outFile.write('ODB Coordinate Reader********************************************')

header = \
"""
*****************************************************************
** Input ODB file: %s
** Coordinate data from the original mesh step 1 frame 0.    ****
*****************************************************************
"""

header2 = \
"""
*****************************************************************
*****************************************************************
** Coordinate data from the original mesh step 1 frame -1 (last).
*****************************************************************
"""

#the variable odbName is placed in the position of %s in the header
outFile.write(header % (odbName))
#this format statement if for the node label and tuple write
format = '%6i, %14.7e, %14.7e, %14.7e\n'

#the indent in python means a loop
for value in coords.values:
    outFile.write(
        format % ((value.nodeLabel,) + tuple(value.data)))
outFile.write('***** End of coordinates of first frame.*************************')


outFile.write(header2)

#this format statement if for the node label and tuple write
format = '%6i, %14.7e, %14.7e, %14.7e\n'

#the indent in python means a loop
for value in coordslast.values:
    outFile.write(
        format % ((value.nodeLabel,) + tuple(value.data)))
outFile.write('***** End of coordinates of last frame.**************************')



outFile.close()



#55
Welcome Center / Welcome to the forums
December 28, 2014, 08:51:26 PM
The purpose of this forum is a hobby website related to topics in the field of Mechanics, and in particular the use of the finite element program Simulia ABAQUS, Mechanics of Materials, and Fatigue Analysis.

My initial purpose of these forums is for me to document scripts/programs/analysis techniques so that I don't forget them.  Others are welcome to join and comment.

If you register, you will be able to view additional forums dealing with general ABAQUS CAE questions, ABAQUS scripting and Python programming, ODB file reading for ABAQUS and other topics as well as being able to download sample input files.

Please make a post about yourself in the welcome center, so that I know you are not a spam bot.  I suspect it will take a while to get people interested in this niche area, so please feel free to help me promote these forums.



My intention is to keep this forum advertisement-free, as I have found advertising clutter distracting when I have visited more established ABAQUS tip/help sites.


Here is my Youtube Channel (which is a work in progress):
https://www.youtube.com/channel/UCS5Ojenfz6cBWV1CX5pEwIA