Reputation: 33
I want to extract the element stiffness matrix from Abaqus input file. the contents of the last lines of the file are as follows:
**
** OUTPUT REQUESTS
**
*Restart, write, frequency=0
**
** FIELD OUTPUT: F-Output-1
**
*Output, field, variable=PRESELECT
*End Step
in order to extract the element stiffness matrix from an input file, we should the following line into the input file, i.e. the line before the ((*End Step)) line:
*ELEMENT MATRIX OUTPUT,ELSET=m,STIFFNESS=YES,MASS=NO,OUTPUTFILE=USER
I want to add this line into my input file through python language which is the scripting language of Abaqus software. I try the following code to another text file to test this code, but after executing these lines, between each of two lines, it inserts an empty line which I don't want these empty line:(in the following code, I just want to show that, other codes create empty lines)
import fileinput
processing_foo1s = False
for line in fileinput.input('Input8.inp', inplace=1):
if line.startswith('*Output,'):
processing_foo1s = True
else:
if processing_foo1s:
print ('foo bar')
processing_foo1s = False
print (line,)
Upvotes: 1
Views: 784
Reputation: 1608
This code will do exactly what you need:
with open('Input8.inp', 'r+') as f:
_text = ''
for line in f:
if line.startswith('*End Step'):
_text += '*ELEMENT MATRIX OUTPUT,ELSET=m,STIFFNESS=YES,MASS=NO,OUTPUTFILE=USER\n'
_text += line
f.seek(0)
f.write(_text)
f.truncate()
Explanation:
Upvotes: 2