Imagine you have program X that needs the following input by the user:
fy = 355. #Yield stress (MPa)
fu = 552. #Tensile stress resistance (MPa), 460 MPa in engineering stress
E = 210.E3 #Young modulus (MPa)
F = -100.E3 #vertical force (N)
k2_2=70.82e6 #stiffness 2nd segment 2L, strong axis (N.mm/rad)
loos=0.0055 #looseness 2L (rad), strong axis
bmax=3.5e6 #maximum moment 2L, strong axis (N.mm)
Then the user also wants to add an initially undetermined number of variables, a group started by imp_local+str()
and another group by imp_global+str()
.
The number of variables to generate depends on the result of reading a txt file.
The user is aware that the program cannot handle this generated variables, but looking at a macro created by the program there is maybe a chance of introducing them.
The macro generated by the program looks like:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# import modules
from math import *
from openturns import *
from phiboot import *
# define the physical model
class TP1_Simply_supported_beam_class( OpenTURNSPythonFunction ):
def __init__( self ):
OpenTURNSPythonFunction.__init__( self, 9, 1)
self.logUser = LogUser()
self.callsNumber = 0
self.pad = 21
def padVar(self, var):
if type(var) == str:
return var.ljust(self.pad)
else:
return str('%+.11e' % var).ljust(self.pad)
def setLogFile(self, filename):
self.callsNumber = 0
self.logUser.setFile(filename)
def closeLogFile(self):
self.logUser.closeFile()
# define OpenTURNS function
def TP1_Simply_supported_beam( self, fy, fu, E, F, k2_2, loos, bmax ):
# log header
if self.callsNumber == 0:
self.logUser.level1( ''.join(map(self.padVar, ['N', 'fy', 'fu', 'E', 'F', 'k2_2', 'loos', 'bmax', 'g'])) + '\n' )
# log input vars
self.logUser.level1( str(self.callsNumber).ljust(self.pad) + ''.join(map(self.padVar, [fy, fu, E, F, k2_2, loos, bmax]))
And the code to generate the groups of variables is:
fileData = [] #array with the input file
inputFile = open("C:/Abaqus_JOBS/Job-M1-3_4.inp", "r") #CAE INPUT FILE
#fileData = variable with all the lines of the inp file
for line in inputFile:
fileData.append([x.strip() for x in line.split(',')])
fgenerate1=0
nTop=[]
for row,data in enumerate(fileData):
if data[0]=="*Nset" and data[1]=="nset=TOP":
row_Top = row
if len(data)==3 and data[0]=="*Nset" and data[1]=="nset=TOP" and data[2]=="generate":
fgenerate1=1
if row_Top!=0:
for data in fileData[row_Top+1:]: # skip first row elements
try:
int(data[0])
except ValueError:
break # found bottom_row, stop iterating
if fgenerate1==0:
nTop.append(data)
else:
iniN=data[0]
finN=int(data[1])+1
inc=data[2]
for n in range(int(iniN), int(finN), int(inc)):
data=n
nTop.append([str(data)])
loc=locals()
for k,val in enumerate(nTop) : loc["imp_local"+str(k)]
for k,val in enumerate(nTop) : loc["imp_global"+str(k)]
Now that the user has generated the imp_local
and imp_global
variables he wants to add them to the corresponding lines in the program macro. How can he do it?
def TP1_Simply_supported_beam( self, fy, fu, E, F, k2_2, loos, bmax ):
,self.logUser.level1( ''.join(map(self.padVar, ['N', 'fy', 'fu', 'E', 'F', 'k2_2', 'loos', 'bmax', 'g'])) + '\n' )
andself.logUser.level1( str(self.callsNumber).ljust(self.pad) + ''.join(map(self.padVar, [fy, fu, E, F, k2_2, loos, bmax]))
– jpcgandre May 3 at 18:51TP1_Simply_supported_beam_class
? – unutbu May 3 at 18:58TP1_Simply_supported_beam_class
must have the same structure and must have the added variables. – jpcgandre May 3 at 19:00