Create custom field output in Abaqus2021 through Python and view in contour plot

98 views Asked by At

I would like to add my own custom field variable (in this case nodal U values in all 3 translational directions), then I want to view the contour plots. The following code does create the step & frame and dumps given nodal value.

from abaqus import *
from abaqusConstants import *
import odbAccess

odb_path = r"x03_test_st.odb"
instanceName = 'PART-1-1'

odb = odbAccess.openOdb(path=odb_path, readOnly=True)

instance1 = odb.rootAssembly.instances[instanceName]
step1 = odb.Step(name='step1', description='', domain=TIME, timePeriod=1.0)

frame0 = step1.Frame(incrementNumber=1, frameValue=0.1, description='dummy')
frame1 = step1.Frame(incrementNumber=2, frameValue=0.2, description='customFrame')

uField = frame1.FieldOutput(name='U', description='', type=VECTOR)

nodeLabelData = (1, 2, 3, 4, 5, 6)
dispData = ((0.15374583118418694, 0.8585851847069973, 0.3742254744931832),
            (0.4070882202130386, 0.6974154877282727, 0.2126706056738057),
            (0.5463851799965965, 0.7688165228864976, 0.8131962796810962),
            (0.11280984262947236, 0.3143623822894589, 0.905752847147511),
            (0.07679643266215119, 0.7547831307161972, 0.6137464800631778),
            (0.9094500731020884, 0.19221815308664503, 0.8331704449998695))

uField.addData(position=NODAL, instance=instance1, labels=nodeLabelData, data=dispData)
odb.steps['step1'].setDefaultField(uField)

By printing the values assigned value of node 6 -

print(odb.steps['step1'].frames[-1].fieldOutputs['U'].values[-1])

enter image description here

However, while no primary variable is present in the field output to plot -

enter image description here

Here's the inp file of the test analysis -

*Heading
** Job name: x03_test_st Model name: x03_test_st
** Generated by: Abaqus/CAE 2021.HF4
*Preprint, echo=NO, model=NO, history=NO, contact=NO
**
** PARTS
**
*Part, name=Part-1
*Node
      1,           0.,           0.,           0.
      2,           1.,           0.,           0.
      3,           1.,          0.5,           0.
      4,           0.,          0.5,           0.
      5,  0.576822102,  0.185981557,           0.
      6,  0.200000003,           0.,           0.
      7,  0.400000006,           0.,           0.
      8,  0.600000024,           0.,           0.
      9,  0.800000012,           0.,           0.
     10,           1.,  0.166666672,           0.
     11,           1.,  0.333333343,           0.
     12,  0.800000012,          0.5,           0.
     13,  0.600000024,          0.5,           0.
     14,  0.400000006,          0.5,           0.
     15,  0.200000003,          0.5,           0.
     16,           0.,  0.333333343,           0.
     17,           0.,  0.166666672,           0.
     18,  0.599589348,  0.259053588,           0.
     19,  0.564018428,  0.326822132,           0.
     20,  0.490946412,  0.349589318,           0.
     21,  0.423177868,  0.314018428,           0.
     22,  0.400410682,  0.240946427,           0.
     23,  0.435981572,  0.173177868,           0.
     24,  0.509053588,  0.150410682,           0.
     25,  0.480635941, 0.0850624219,           0.
     26,  0.517703593,  0.420923859,           0.
     27,  0.631206751,   0.16905348,           0.
     28,  0.369088441,  0.359036833,           0.
     29,  0.635420084,  0.113386989,           0.
     30,  0.330888033,   0.23710534,           0.
     31,  0.693981647,  0.232443213,           0.
     32,  0.192599267,  0.348136783,           0.
     33,   0.78786093,  0.158841655,           0.
     34,  0.779104173,  0.331114978,           0.
     35,  0.208837822,  0.180184364,           0.
     36,  0.617957652,  0.369486988,           0.
     37,  0.345436871,  0.140329778,           0.
     38,          0.5,         0.25,           0.
*Element, type=S3
1, 34, 31, 33
2, 36, 13, 26
3, 26, 13, 14
4, 25,  7,  8
5, 28, 21, 20
6, 25, 24, 23
7, 37, 30, 35
8, 36, 19, 18
*Element, type=S4R
 9,  8,  9, 33, 29
10, 29, 24, 25,  8
11, 30, 28, 32, 35
12,  9,  2, 10, 33
13, 29, 33, 31, 27
14, 12, 34, 11,  3
15, 15,  4, 16, 32
16,  6, 35, 17,  1
17, 21, 28, 30, 22
18,  5, 24, 29, 27
19, 26, 20, 19, 36
20, 37,  7, 25, 23
21, 34, 36, 18, 31
22, 32, 28, 14, 15
23, 28, 20, 26, 14
24, 18,  5, 27, 31
25, 32, 16, 17, 35
26, 33, 10, 11, 34
27,  7, 37, 35,  6
28, 34, 12, 13, 36
29, 37, 23, 22, 30
30, 20, 21, 38, 19
31, 22, 23, 38, 21
32, 18, 19, 38,  5
33, 38, 23, 24,  5
*Nset, nset=_PickedSet4, internal, generate
  1,  38,   1
*Elset, elset=_PickedSet4, internal, generate
  1,  33,   1
** Section: Section-1
*Shell Section, elset=_PickedSet4, material=Material-1
0.01, 5
*End Part
**  
**
** ASSEMBLY
**
*Assembly, name=Assembly
**  
*Instance, name=Part-1-1, part=Part-1
*End Instance
**  
*Node
      1,          0.5,         0.25,  0.100000001
*Nset, nset=_PickedSet7, internal, instance=Part-1-1
  5, 18, 19, 20, 21, 22, 23, 24
*Elset, elset=_PickedSet7, internal, instance=Part-1-1
  5,  6,  8, 17, 18, 19, 24, 29, 30, 31, 32, 33
*Nset, nset=_PickedSet8, internal
 1,
*Nset, nset=_PickedSet9, internal, instance=Part-1-1
  1,  2,  3,  4,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17
*Elset, elset=_PickedSet9, internal, instance=Part-1-1
  3,  4,  9, 12, 14, 15, 16, 22, 25, 26, 27, 28
*Nset, nset=_PickedSet10, internal
 1,
*Surface, type=NODE, name=_PickedSet7_CNS_, internal
_PickedSet7, 1.
** Constraint: Constraint-1
*MPC
BEAM, _PickedSet7, _PickedSet8
*Element, type=MASS, elset=_PickedSet6_Inertia-1_
1, 1
*Mass, elset=_PickedSet6_Inertia-1_
100., 
*End Assembly
** 
** MATERIALS
** 
*Material, name=Material-1
*Density
7850.,
*Elastic
 2.1e+11, 0.3
** 
** BOUNDARY CONDITIONS
** 
** Name: BC-1 Type: Symmetry/Antisymmetry/Encastre
*Boundary
_PickedSet9, ENCASTRE
** ----------------------------------------------------------------
** 
** STEP: Step-1
** 
*Step, name=Step-1, nlgeom=YES
*Static
1., 1., 1e-05, 1.
** 
** LOADS
** 
** Name: Load-1   Type: Concentrated force
*Cload
_PickedSet10, 1, 0.
_PickedSet10, 2, 0.
_PickedSet10, 3, -1e+06
** 
** OUTPUT REQUESTS
** 
*Restart, write, frequency=0
** 
** FIELD OUTPUT: F-Output-1
** 
*Output, field
*Node Output
U, 
*Element Output, directions=YES
S, 
*Output, history, frequency=0
*End Step


1

There are 1 answers

0
Satish Thorat On BEST ANSWER

First of all, you have opened odb in readOnly=True mode. If you want to create a new field output and save it to the odb then change it to readOnly=False.
Secondly, you need to use odb.save() and odb.update() first to save and update odb file. At this point, though the odb has newly added data, the GUI somehow cannot show the same. Hence, you need to close and open the odb file.
Please check below updated code:

from abaqus import *
from abaqusConstants import *
import odbAccess

odb_path = r"model.odb"
instanceName = 'PART-1-1'

# viewport information
vpname = session.currentViewportName

odb = odbAccess.openOdb(path=odb_path, readOnly=False)

instance1 = odb.rootAssembly.instances[instanceName]
step1 = odb.Step(name='step1', description='', domain=TIME, timePeriod=1.0)

frame0 = step1.Frame(incrementNumber=1, frameValue=0.1, description='dummy')
frame1 = step1.Frame(incrementNumber=2, frameValue=0.2, description='customFrame')

uField = frame1.FieldOutput(name='U', description='', type=VECTOR)

nodeLabelData = (1, 2, 3, 4, 5, 6)
dispData = ((0.15374583118418694, 0.8585851847069973, 0.3742254744931832),
            (0.4070882202130386, 0.6974154877282727, 0.2126706056738057),
            (0.5463851799965965, 0.7688165228864976, 0.8131962796810962),
            (0.11280984262947236, 0.3143623822894589, 0.905752847147511),
            (0.07679643266215119, 0.7547831307161972, 0.6137464800631778),
            (0.9094500731020884, 0.19221815308664503, 0.8331704449998695))

uField.addData(position=NODAL, instance=instance1, labels=nodeLabelData, data=dispData)
# odb.steps['step1'].setDefaultField(uField)
odb.save()
odb.update()

odb.close()
odb = odbAccess.openOdb(path=odb_path, readOnly=False)
session.viewports[vpname].setValues(displayedObject=odb)