def assert_fields(card1, card2, i): return try: fields1 = wipe_empty_fields(card1.repr_fields()) fields2 = wipe_empty_fields(card2.repr_fields()) except: print("card1 = \n%s" % card1) print("card2 = \n%s" % card2) raise if len(fields1) != len(fields2): msg = ('len(fields1)=%s len(fields2)=%s\n%r\n%r\n%s\n%s' % (len(fields1), len(fields2), fields1, fields2, print_card(fields1), print_card(fields2))) raise RuntimeError(msg) for (i, field1, field2) in zip(count(), fields1, fields2): value1a = print_field(field1) value2a = print_field(field2) if value1a != value2a: value1 = print_field(interpret_value(value1a)) value2 = print_field(interpret_value(value2a)) if value1 != value2: msg = 'value1 != value2\n' msg += ('cardName=%s ID=%s i=%s field1=%r field2=%r value1=%r ' 'value2=%r\n%r\n%r' % (fields1[0], fields1[1], i, field1, field2, value1, value2, fields1, fields2)) raise RuntimeError(msg)
def assert_fields(card1, card2): try: fields1 = wipe_empty_fields(card1.repr_fields()) fields2 = wipe_empty_fields(card2.repr_fields()) except: print("card1 = \n%s" % (card1)) print("card2 = \n%s" % (card2)) raise if len(fields1) != len(fields2): msg = ('len(fields1)=%s len(fields2)=%s\n%r\n%r\n%s\n%s' % (len(fields1), len(fields2), fields1, fields2, print_card(fields1), print_card(fields2))) raise RuntimeError(msg) for (i, field1, field2) in zip(count(), fields1, fields2): value1a = print_field(field1) value2a = print_field(field2) if value1a != value2a: value1 = print_field(interpret_value(value1a)) value2 = print_field(interpret_value(value2a)) if value1 != value2: msg = 'value1 != value2\n' msg += ('cardName=%s ID=%s i=%s field1=%r field2=%r value1=%r ' 'value2=%r\n%r\n%r' % (fields1[0], fields1[1], i, field1, field2, value1, value2, fields1, fields2)) raise RuntimeError(msg)
def expand_thru_by(fields, set_fields=True, sort_fields=False): """ Expands a list of values of the form [1,5,THRU,9,BY,2,13] to be [1,5,7,9,13] :param fields: the fields to expand :param set_fields: should the fields be converted to a set and then back to a list? This is useful for [2, 'THRU' 5, 1] (default=True) :param sort_fields: should the fields be sorted at the end? (default=False) .. todo:: not tested .. note:: used for QBDY3 and what else ??? """ # ..todo: should this be removed...is the field capitalized when read in? fields = [ field.upper() if isinstance(field, string_types) else field for field in fields ] if len(fields) == 1: return [interpret_value(fields[0])] out = [] nFields = len(fields) i = 0 by = 1 while (i < nFields): if fields[i] == 'THRU': by = 1 byCase = False if i + 2 < nFields and fields[i + 2] == 'BY': by = interpret_value(fields[i + 3]) else: by = 1 byCase = True minValue = interpret_value(fields[i - 1]) maxValue = interpret_value(fields[i + 1]) maxR = int((maxValue - minValue) // by + 1) # max range value for j in range(0, maxR): # +1 is to include final point value = minValue + by * j out.append(value) if byCase: # null/standard case i += 2 else: # BY case i += 3 else: out.append(interpret_value(fields[i])) i += 1 if set_fields: out = list(set(out)) if sort_fields: out.sort() return out
def expand_thru_by(fields, set_fields=True, sort_fields=False): """ Expands a list of values of the form [1,5,THRU,9,BY,2,13] to be [1,5,7,9,13] :param fields: the fields to expand :param set_fields: should the fields be converted to a set and then back to a list? This is useful for [2, 'THRU' 5, 1] (default=True) :param sort_fields: should the fields be sorted at the end? (default=False) .. todo:: not tested .. note:: used for QBDY3 and what else ??? """ # ..todo: should this be removed...is the field capitalized when read in? fields = [field.upper() if isinstance(field, string_types) else field for field in fields] if len(fields) == 1: return [interpret_value(fields[0])] out = [] nFields = len(fields) i = 0 by = 1 while(i < nFields): if fields[i] == 'THRU': by = 1 byCase = False if i + 2 < nFields and fields[i + 2] == 'BY': by = interpret_value(fields[i + 3]) else: by = 1 byCase = True minValue = interpret_value(fields[i - 1]) maxValue = interpret_value(fields[i + 1]) maxR = int((maxValue - minValue) // by + 1) # max range value for j in range(0, maxR): # +1 is to include final point value = minValue + by * j out.append(value) if byCase: # null/standard case i += 2 else: # BY case i += 3 else: out.append(interpret_value(fields[i])) i += 1 if set_fields: out = list(set(out)) if sort_fields: out.sort() return out
def _read_real(self, card): # column number j = integer(card, 2, 'icol') # counter i = 0 fields = [interpret_value(field) for field in card[3:]] # Real, starts at A(i1,j), goes to A(i2,j) in a column while i < len(fields): i1 = fields[i] if isinstance(i1, integer_types): i += 1 is_done_reading_floats = False while not is_done_reading_floats and i < len(fields): real_value = fields[i] if isinstance(real_value, integer_types): is_done_reading_floats = True elif isinstance(real_value, float): #print('adding j=%s i1=%s val=%s' % (j, i1, real_value)) self.GCj.append(j) self.GCi.append(i1) self.Real.append(real_value) i += 1 i1 += 1 else: real_value = self.Real[-1] endI = fields[i + 1] for ii in range(i1, endI + 1): #print('adding j=%s i1=%s val=%s' % (j, ii, real_value)) self.GCj.append(j) self.GCi.append(ii) self.Real.append(real_value) i += 1 is_done_reading_floats = True
def __init__(self, card=None, data=None, comment=''): """ :: DRESP1 1S1 CSTRAIN PCOMP 1 1 10000 """ if comment: self._comment = comment self.oid = integer(card, 1, 'oid') self.label = string(card, 2, 'label') self.rtype = string(card, 3, 'rtype') # elem, pbar, pshell, etc. (ELEM flag or Prop Name) self.ptype = integer_string_or_blank(card, 4, 'ptype') if 0: assert self.ptype in ['ELEM', 'PSHELL', 'PBAR', 'PROD', 'PCOMP', 'PSOLID', 'PELAS', 'PBARL', 'PBEAM', 'PBEAML', 'PSHEAR', 'PTUBE', 'PKNL', #: .. todo:: is this correct? None], 'DRESP1 ptype=%s' % self.ptype self.region = integer_or_blank(card, 5, 'region') self.atta = integer_double_string_or_blank(card, 6, 'atta') self.attb = integer_double_string_or_blank(card, 7, 'attb') self.atti = integer_double_string_or_blank(card, 8, 'atti') self.others = [interpret_value(field) for field in card[9:] ]
def __init__(self, card=None, data=None, comment=''): """ Design Sensitivity Equation Response Quantities Defines equation responses that are used in the design, either as constraints or as an objective. """ if comment: self._comment = comment self.oid = integer(card, 1, 'oid') self.label = string(card, 2, 'label') self.eqidFunc = integer_or_string(card, 3, 'eqid_Func') self.region = integer_or_blank(card, 4, 'region') self.method = string_or_blank(card, 5, 'method', 'MIN') self.c1 = double_or_blank(card, 6, 'c1', 100.) self.c2 = double_or_blank(card, 7, 'c2', 0.005) self.c3 = double_or_blank(card, 8, 'c3') #: .. todo:: or blank? i = 0 fields = [interpret_value(field) for field in card[9:] ] key = '$NULL$' # dummy key self.params = {key: []} valueList = [] for (i, field) in enumerate(fields): if i % 8 == 0 and field is not None: self.params[key] = valueList key = field valueList = [] elif field is not None: valueList.append(field) #else: # pass self.params[key] = valueList del self.params['$NULL$']
def __init__(self, card=None, data=None, comment=''): """ Design Sensitivity Equation Response Quantities Defines equation responses that are used in the design, either as constraints or as an objective. """ if comment: self._comment = comment self.oid = integer(card, 1, 'oid') self.label = string(card, 2, 'label') self.eqidFunc = integer_or_string(card, 3, 'eqid_Func') self.region = integer_or_blank(card, 4, 'region') self.method = string_or_blank(card, 5, 'method', 'MIN') self.c1 = double_or_blank(card, 6, 'c1', 100.) self.c2 = double_or_blank(card, 7, 'c2', 0.005) self.c3 = double_or_blank(card, 8, 'c3') #: .. todo:: or blank? i = 0 fields = [interpret_value(field) for field in card[9:]] key = '$NULL$' # dummy key self.params = {key: []} valueList = [] for (i, field) in enumerate(fields): if i % 8 == 0 and field is not None: self.params[key] = valueList key = field valueList = [] elif field is not None: valueList.append(field) #else: # pass self.params[key] = valueList del self.params['$NULL$']
def expand_thru_exclude(self, fields): """ Expands a list of values of the form [1,5,THRU,11,EXCEPT,7,8,13] to be [1,5,6,9,10,11,13] .. warning:: hasnt been tested """ # ..todo: should this be removed...is the field capitalized when read in? fields = [interpret_value(field.upper()) if isinstance(field, basestring) else field for field in fields] fieldsOut = [] nFields = len(fields) for i in xrange(nFields): if fields[i] == 'THRU': storedList = [] for j in xrange(fields[i - 1], fields[i + 1]): storedList.append(fields[j]) elif fields[i] == 'EXCLUDE': storedSet = set(storedList) while fields[i] < max(storedList): storedSet.remove(fields[i]) storedList = list(storedSet) else: if storedList: fieldsOut += storedList fieldsOut.append(fields[i]) return fieldsOut
def __init__(self, card=None, data=None, comment=''): if comment: self._comment = comment if card: self.oid = integer(card, 1, 'ID') self.label = string(card, 2, 'label') self.group = string(card, 3, 'group') self.Type = string(card, 4, 'Type') self.region = integer(card, 5, 'Type') i = 0 fields = [interpret_value(field) for field in card[9:]] key = '$NULL$' # dummy key self.params = {key: []} value_list = [] for (i, field) in enumerate(fields): if i % 8 == 0 and field is not None: self.params[key] = value_list key = field value_list = [] elif field is not None: value_list.append(field) #else: # pass self.params[key] = value_list del self.params['$NULL$'] else: raise RuntimeError(data)
def expand_thru_exclude(self, fields): """ Expands a list of values of the form [1,5,THRU,11,EXCEPT,7,8,13] to be [1,5,6,9,10,11,13] .. warning:: hasnt been tested """ # ..todo: should this be removed...is the field capitalized when read in? fields = [ interpret_value(field.upper()) if isinstance(field, string_types) else field for field in fields ] fieldsOut = [] nFields = len(fields) for i in range(nFields): if fields[i] == 'THRU': storedList = [] for j in range(fields[i - 1], fields[i + 1]): storedList.append(fields[j]) elif fields[i] == 'EXCLUDE': storedSet = set(storedList) while fields[i] < max(storedList): storedSet.remove(fields[i]) storedList = list(storedSet) else: if storedList: fieldsOut += storedList fieldsOut.append(fields[i]) return fieldsOut
def compare(valueIn): field = print_field(valueIn) val = interpret_value(field) if val != 0: p = (val - valueIn) / val if p > 0.01: raise ValueError('val=%s valueIn=%s' % (val, valueIn))
def compare(valueIn): field = print_field(valueIn) val = interpret_value(field) if val != 0: p = (val - valueIn) / val if p > 0.01: raise ValueError('val=%s valueIn=%s' % (val, valueIn))
def interpretValue(valueRaw, card='', debug=False): """ .. seealso:: interpret_value .. deprecated: will be replaced in version 0.7 with interpret_value """ warnings.warn('interpretValue has been deprecated; use ' 'interpret_value', DeprecationWarning, stacklevel=2) return interpret_value(valueRaw, card, debug)
def compare(valueIn): #print "a = |%s|" % valueIn field = print_field(valueIn) #print("a = |%s|" % field) val = interpret_value(field) if val != 0: p = (val - valueIn) / val if p > 0.01: raise ValueError('val=%s valueIn=%s' % (val, valueIn))
def compare(valueIn): #print "a = |%s|" % valueIn field = print_field(valueIn) #print("a = |%s|" % field) val = interpret_value(field) if val != 0: p = (val - valueIn) / val if p > 0.01: raise ValueError('val=%s valueIn=%s' % (val, valueIn))
def __init__(self, card=None, data=None, sol=None, comment=''): Method.__init__(self, card, data) if comment: self._comment = comment if card: #: Set identification number. (Unique Integer > 0) self.sid = integer(card, 1, 'sid') #: For vibration analysis: frequency range of interest. For #: buckling analysis: eigenvalue range of interest. See Remark 4. #: (Real or blank, -5 10e16 <= V1 < V2 <= 5.10e16) self.v1 = double_or_blank(card, 2, 'v1') self.v2 = double_or_blank(card, 3, 'v2') #: Number of roots desired self.nd = integer_or_blank(card, 4, 'nd') #: Diagnostic level. (0 < Integer < 4; Default = 0) self.msglvl = integer_or_blank(card, 5, 'msglvl', 0) #: Number of vectors in block or set. Default is machine dependent self.maxset = integer_or_blank(card, 6, 'maxset') #: Estimate of the first flexible mode natural frequency #: (Real or blank) self.shfscl = double_or_blank(card, 7, 'shfscl') #: Method for normalizing eigenvectors (Character: 'MASS' or 'MAX') self.norm = string_or_blank(card, 8, 'norm') optionValues = [interpret_value(field) for field in card[9:]] self.options = [] self.values = [] #print "optionValues = ",optionValues for optionValue in optionValues: #print "optionValue = ",optionValue (option, value) = optionValue.split('=') self.options.append(option) self.values.append(value) #: Method for normalizing eigenvectors if sol in [103, 115, 146]: # normal modes,cyclic normal modes, flutter self.norm = string_or_blank(card, 8, 'norm', 'MASS') elif sol in [105, 110, 111, 116]: # buckling, modal complex eigenvalues, # modal frequency response,cyclic buckling self.norm = string_or_blank(card, 8, 'norm', 'MAX') else: self.norm = string_or_blank(card, 8, 'norm') #assert len(card) <= 9, 'len(EIGRL card) = %i' % len(card) assert len(card) <= 10, 'len(EIGRL card) = %i' % len(card) #msg = 'norm=%s sol=%s' % (self.norm, sol) #assert self.norm in ['MASS', 'MAX'],msg #assert card.nFields()<9,'card = %s' %(card.fields(0)) else: raise NotImplementedError('EIGRL')
def __init__(self, card=None, data=None, sol=None, comment=''): Method.__init__(self, card, data) if comment: self._comment = comment if card: #: Set identification number. (Unique Integer > 0) self.sid = integer(card, 1, 'sid') #: For vibration analysis: frequency range of interest. For #: buckling analysis: eigenvalue range of interest. See Remark 4. #: (Real or blank, -5 10e16 <= V1 < V2 <= 5.10e16) self.v1 = double_or_blank(card, 2, 'v1') self.v2 = double_or_blank(card, 3, 'v2') #: Number of roots desired self.nd = integer_or_blank(card, 4, 'nd') #: Diagnostic level. (0 < Integer < 4; Default = 0) self.msglvl = integer_or_blank(card, 5, 'msglvl', 0) #: Number of vectors in block or set. Default is machine dependent self.maxset = integer_or_blank(card, 6, 'maxset') #: Estimate of the first flexible mode natural frequency #: (Real or blank) self.shfscl = double_or_blank(card, 7, 'shfscl') #: Method for normalizing eigenvectors (Character: 'MASS' or 'MAX') self.norm = string_or_blank(card, 8, 'norm') optionValues = [interpret_value(field) for field in card[9:] ] self.options = [] self.values = [] #print "optionValues = ",optionValues for optionValue in optionValues: #print "optionValue = ",optionValue (option, value) = optionValue.split('=') self.options.append(option) self.values.append(value) #: Method for normalizing eigenvectors if sol in [103, 115, 146]: # normal modes,cyclic normal modes, flutter self.norm = string_or_blank(card, 8, 'norm', 'MASS') elif sol in [105, 110, 111, 116]: # buckling, modal complex eigenvalues, # modal frequency response,cyclic buckling self.norm = string_or_blank(card, 8, 'norm', 'MAX') else: self.norm = string_or_blank(card, 8, 'norm') #assert len(card) <= 9, 'len(EIGRL card) = %i' % len(card) assert len(card) <= 10, 'len(EIGRL card) = %i' % len(card) #msg = 'norm=%s sol=%s' % (self.norm, sol) #assert self.norm in ['MASS', 'MAX'],msg #assert card.nFields()<9,'card = %s' %(card.fields(0)) else: raise NotImplementedError('EIGRL')
def parseSetSline(listA): print("listA = ", listA) listB = [] for spot in listA: spot = spot.strip() print("spot = ", spot) if spot == '': pass elif ' ' in spot: sline = spot.split(' ') print("sline = ", sline) if sline[1] == 'THRU': if 'BY' in sline: by = sline[4] else: by = 1 #print "BY = %s" %(by) vals = set([]) startValue = interpret_value(sline[0]) endValue = interpret_value(sline[2]) + 1 for i in xrange(startValue, endValue, by): vals.add(i) #print "vals = ",vals if 'EXCEPT' in sline: iExcept = sline.index('EXCEPT') #print "e = ",sline[iExcept] excepted = int(sline[iExcept + 1]) vals.remove(excepted) vals = list(vals) listB += vals print("vals = ", vals) else: print("sline = ", sline) else: #print "spot = %s" %(spot) if '/' in spot: listB.append(spot) else: listB.append(interpret_value(spot)) return listB
def parseSetSline(listA): print("listA = ", listA) listB = [] for spot in listA: spot = spot.strip() print("spot = ", spot) if spot == '': pass elif ' ' in spot: sline = spot.split(' ') print("sline = ", sline) if sline[1] == 'THRU': if 'BY' in sline: by = sline[4] else: by = 1 #print("BY = %s" % by) vals = set([]) startValue = interpret_value(sline[0]) endValue = interpret_value(sline[2]) + 1 for i in range(startValue, endValue, by): vals.add(i) #print("vals = ", vals) if 'EXCEPT' in sline: iExcept = sline.index('EXCEPT') #print("e = ", sline[iExcept]) excepted = int(sline[iExcept + 1]) vals.remove(excepted) vals = list(vals) listB += vals print("vals = ", vals) else: print("sline = ", sline) else: #print("spot = %s" % (spot)) if '/' in spot: listB.append(spot) else: listB.append(interpret_value(spot)) return listB
def __init__(self, card=None, data=None, comment=''): """ Design Sensitivity Equation Response Quantities Defines equation responses that are used in the design, either as constraints or as an objective. """ if comment: self._comment = comment self.func = None self.dequation_str = None if card: self.oid = integer(card, 1, 'oid') self.label = string(card, 2, 'label') self.dequation = integer_or_string(card, 3, 'dequation_id') self.region = integer_or_blank(card, 4, 'region') self.method = string_or_blank(card, 5, 'method', 'MIN') self.c1 = double_or_blank(card, 6, 'c1', 100.) self.c2 = double_or_blank(card, 7, 'c2', 0.005) self.c3 = double_or_blank(card, 8, 'c3') #: .. todo:: or blank? #i = 0 fields = [interpret_value(field) for field in card[9:]] key = None # dummy key self.params = {} value_list = [] j = 0 for (i, field) in enumerate(fields): if i % 8 == 0 and field is not None: if i > 0: assert len(value_list) > 0, 'key=%s values=%s' % (key, value_list) self.params[key] = value_list j += 1 key = (j, field) value_list = [] elif field is not None: value_list.append(field) self.params[key] = value_list else: raise RuntimeError(data) print("--Params--") for key, value_list in sorted(iteritems(self.params)): print(" key=%s params=%s" %(key, value_list))
def __init__(self, card=None, data=None, comment=''): """ Design Variable to Material Relation Defines the relation between a material property and design variables.:: DVMREL1 ID TYPE MID MPNAME MPMIN MPMAX C0 DVID1 COEF1 DVID2 COEF2 DVID3 COEF3 -etc.- """ if comment: self._comment = comment if card: self.oid = integer(card, 1, 'oid') self.Type = string(card, 2, 'Type') self.mid = integer(card, 3, 'mid') self.mpName = string(card, 4, 'mpName') #if self.mpName in ['E', 'RHO', 'NU']: positive values #self.mpMin = double_or_blank(card, 5, 'mpMin', 1e-15) #else: # negative #self.mpMin = double_or_blank(card, 5, 'mpMin', -1e-35) self.mpMin = double_or_blank(card, 5, 'mpMin') #: .. todo:: bad default self.mpMax = double_or_blank(card, 6, 'mpMax', 1e20) self.c0 = double_or_blank(card, 7, 'c0', 0.0) self.dvids = [] self.coeffs = [] endFields = [interpret_value(field) for field in card[9:]] #print "endFields = ",endFields nfields = len(endFields) - 1 if nfields % 2 == 1: endFields.append(None) nfields += 1 i = 0 for i in range(0, nfields, 2): self.dvids.append(endFields[i]) self.coeffs.append(endFields[i + 1]) if nfields % 2 == 1: print(card) print("dvids = %s" % (self.dvids)) print("coeffs = %s" % (self.coeffs)) print(str(self)) raise RuntimeError('invalid DVMREL1...') else: raise RuntimeError(data)
def __init__(self, card=None, data=None, comment=''): """ +---------+--------+--------+--------+-----+ | DVPREL1 | 200000 | PCOMP | 2000 | T2 | +---------+--------+--------+--------+-----+ | | 200000 | 1.0 | | | +---------+--------+--------+--------+-----+ """ if comment: self._comment = comment if card: self.oid = integer(card, 1, 'oid') self.Type = string(card, 2, 'Type') self.pid = integer(card, 3, 'pid') self.pNameFid = integer_or_string(card, 4, 'pName_FID') #: Minimum value allowed for this property. #: .. todo:: bad default (see DVMREL1) self.pMin = double_or_blank(card, 5, 'pMin') self.pMax = double_or_blank(card, 6, 'pMax', 1e20) self.c0 = double_or_blank(card, 7, 'c0', 0.0) self.dvids = [] self.coeffs = [] endFields = [interpret_value(field) for field in card[9:]] nfields = len(endFields) - 1 if nfields % 2 == 1: endFields.append(None) nfields += 1 i = 0 for i in range(0, nfields, 2): self.dvids.append(endFields[i]) self.coeffs.append(endFields[i + 1]) if nfields % 2 == 1: print(card) print("dvids = %s" % (self.dvids)) print("coeffs = %s" % (self.coeffs)) print(str(self)) raise RuntimeError('invalid DVPREL1...') else: raise RuntimeError(data)
def __init__(self, card=None, data=None, comment=''): """ Design Variable to Material Relation Defines the relation between a material property and design variables.:: DVMREL1 ID TYPE MID MPNAME MPMIN MPMAX C0 DVID1 COEF1 DVID2 COEF2 DVID3 COEF3 -etc.- """ if comment: self._comment = comment self.oid = integer(card, 1, 'oid') self.Type = string(card, 2, 'Type') self.mid = integer(card, 3, 'mid') self.mpName = string(card, 4, 'mpName') #if self.mpName in ['E', 'RHO', 'NU']: positive values #self.mpMin = double_or_blank(card, 5, 'mpMin', 1e-15) #else: # negative #self.mpMin = double_or_blank(card, 5, 'mpMin', -1e-35) self.mpMin = double_or_blank(card, 5, 'mpMin') #: .. todo:: bad default self.mpMax = double_or_blank(card, 6, 'mpMax', 1e20) self.c0 = double_or_blank(card, 7, 'c0', 0.0) self.dvids = [] self.coeffs = [] endFields = [interpret_value(field) for field in card[9:]] #print "endFields = ",endFields nFields = len(endFields) - 1 if nFields % 2 == 1: endFields.append(None) nFields += 1 i = 0 for i in range(0, nFields, 2): self.dvids.append(endFields[i]) self.coeffs.append(endFields[i + 1]) if nFields % 2 == 1: print(card) print("dvids = %s" % (self.dvids)) print("coeffs = %s" % (self.coeffs)) print(str(self)) raise RuntimeError('invalid DVMREL1...')
def _read_real(self, card): # column number j = integer(card, 2, 'icol') # counter i = 0 fields = [interpret_value(field) for field in card[3:] ] # Real, starts at A(i1,j), goes to A(i2,j) in a column while i < len(fields): i1 = fields[i] #print("i1 = ",i1) if isinstance(i1, int): i += 1 isDoneReadingFloats = False while not isDoneReadingFloats and i < len(fields): #print("i=%s len(fields)=%s" %(i,len(fields))) realValue = fields[i] if isinstance(realValue, int): isDoneReadingFloats = True elif isinstance(realValue, float): self.GCj.append(j) self.GCi.append(i1) self.Real.append(realValue) #print("i=%s j=%s value=%s" %(i1,j,realValue) i += 1 else: #print("*i=%s j=%s value=%s type=%s" %(i1,j,realValue,type(realValue))) realValue = self.Real[-1] #print("*i=%s j=%s value=%s" %(i1,j,realValue)) endI = fields[i + 1] #print("*i=%s endI=%s j=%s value=%s" %(i1,endI,j,realValue)) for ii in range(i1, endI + 1): self.GCj.append(j) self.GCi.append(ii) self.Real.append(realValue) #print("i = ",3+i) #print('field i=',fields[i]) i += 1 isDoneReadingFloats = True
def readReal(self, card): # column number j = integer(card, 2, 'icol') # counter i = 0 fields = [interpret_value(field) for field in card[3:]] # Real, starts at A(i1,j), goes to A(i2,j) in a column while i < len(fields): i1 = fields[i] #print "i1 = ",i1 if isinstance(i1, int): i += 1 isDoneReadingFloats = False while not isDoneReadingFloats and i < len(fields): #print "i=%s len(fields)=%s" %(i,len(fields)) realValue = fields[i] if isinstance(realValue, int): isDoneReadingFloats = True elif isinstance(realValue, float): self.GCj.append(j) self.GCi.append(i1) self.Real.append(realValue) #print "i=%s j=%s value=%s" %(i1,j,realValue) i += 1 else: #print "*i=%s j=%s value=%s type=%s" %(i1,j,realValue,type(realValue)) realValue = self.Real[-1] #print "*i=%s j=%s value=%s" %(i1,j,realValue) endI = fields[i + 1] #print "*i=%s endI=%s j=%s value=%s" %(i1,endI,j,realValue) for ii in xrange(i1, endI + 1): self.GCj.append(j) self.GCi.append(ii) self.Real.append(realValue) #print "i = ",3+i #print 'field i=',fields[i] i += 1 isDoneReadingFloats = True
def _get_type(value): """ Get the type of the input value in a form that is clear. :param value: the value to get the type of """ #print('Type value=%s' % value) try: value = interpret_value(value) except: pass if value is None: Type = 'blank' elif isinstance(value, int): Type = 'an integer' elif isinstance(value, float): Type = 'a double' elif isinstance(value, string_types): Type = 'a string' else: Type = str(type(value)) return Type
def __init__(self, card=None, data=None, comment=''): """ :: DVPREL1 200000 PCOMP 2000 T2 200000 1.0 """ if comment: self._comment = comment self.oid = integer(card, 1, 'oid') self.Type = string(card, 2, 'Type') self.pid = integer(card, 3, 'pid') self.pNameFid = integer_or_string(card, 4, 'pName_FID') #: Minimum value allowed for this property. #: .. todo:: bad default (see DVMREL1) self.pMin = double_or_blank(card, 5, 'pMin') self.pMax = double_or_blank(card, 6, 'pMax', 1e20) self.c0 = double_or_blank(card, 7, 'c0', 0.0) self.dvids = [] self.coeffs = [] endFields = [interpret_value(field) for field in card[9:]] nFields = len(endFields) - 1 if nFields % 2 == 1: endFields.append(None) nFields += 1 i = 0 for i in range(0, nFields, 2): self.dvids.append(endFields[i]) self.coeffs.append(endFields[i + 1]) if nFields % 2 == 1: print(card) print("dvids = %s" % (self.dvids)) print("coeffs = %s" % (self.coeffs)) print(str(self)) raise RuntimeError('invalid DVPREL1...')
def __init__(self, card=None, data=None, comment=''): """ :: DRESP1 1S1 CSTRAIN PCOMP 1 1 10000 """ if comment: self._comment = comment self.oid = integer(card, 1, 'oid') self.label = string(card, 2, 'label') self.rtype = string(card, 3, 'rtype') # elem, pbar, pshell, etc. (ELEM flag or Prop Name) self.ptype = integer_string_or_blank(card, 4, 'ptype') if 0: assert self.ptype in [ 'ELEM', 'PSHELL', 'PBAR', 'PROD', 'PCOMP', 'PSOLID', 'PELAS', 'PBARL', 'PBEAM', 'PBEAML', 'PSHEAR', 'PTUBE', 'PKNL', #: .. todo:: is this correct? None ], 'DRESP1 ptype=%s' % self.ptype self.region = integer_or_blank(card, 5, 'region') self.atta = integer_double_string_or_blank(card, 6, 'atta') self.attb = integer_double_string_or_blank(card, 7, 'attb') self.atti = integer_double_string_or_blank(card, 8, 'atti') self.others = [interpret_value(field) for field in card[9:]]
def add_card(self, card_lines, card_name, comment='', is_list=True): """ Adds a card object to the BDF object using a streaming approach. :param self: the BDF object :param card_lines: the list of the card fields >>> ['GRID,1,2',] # (is_list = False) >>> ['GRID',1,2,] # (is_list = True; default) :param card_name: the card_name -> 'GRID' :param comment: an optional the comment for the card :param is_list: changes card_lines from a list of lines to a list of fields :returns card_object: the card object representation of card .. note:: this is a very useful method for interfacing with the code .. note:: the cardObject is not a card-type object...so not a GRID card or CQUAD4 object. It's a BDFCard Object. However, you know the type (assuming a GRID), so just call the *mesh.Node(nid)* to get the Node object that was just created. .. warning:: cardObject is not returned """ if comment: self.bdf_out_file.write(comment) if card_name in ['DEQATN']: card_obj = card_lines card = card_lines #print("card =", '\n'.join(card_lines)) self.bdf_out_file.write('\n'.join(card_lines)) else: if is_list: fields = card_lines else: fields = to_fields(card_lines, card_name) # apply OPENMDAO syntax if self._is_dynamic_syntax: fields = [ self._parse_dynamic_syntax(field) if '%' in field[0:1] else field for field in fields ] card = wipe_empty_fields([ interpret_value(field, fields) if field is not None else None for field in fields ]) #print(card) card_obj = BDFCard(card) self.bdf_out_file.write(print_card_8(card_obj)) #for reject_card in self.reject_cards: #try: #print('comment =', comment) #except RuntimeError: #for field in reject_card: #if field is not None and '=' in field: #raise SyntaxError('cannot reject equal signed ' # 'cards\ncard=%s\n' % reject_card) #raise #self.reject_cards.append(card) #print('rejecting processed auto=rejected %s' % card) return card_obj
def add_card(self, card_lines, card_name, comment='', is_list=True): """ Adds a card object to the BDF object using a streaming approach. :param self: the BDF object :param card_lines: the list of the card fields >>> ['GRID,1,2',] # (is_list = False) >>> ['GRID',1,2,] # (is_list = True; default) :param card_name: the card_name -> 'GRID' :param comment: an optional the comment for the card :param is_list: changes card_lines from a list of lines to a list of fields :returns card_object: the card object representation of card .. note:: this is a very useful method for interfacing with the code .. note:: the cardObject is not a card-type object...so not a GRID card or CQUAD4 object. It's a BDFCard Object. However, you know the type (assuming a GRID), so just call the *mesh.Node(nid)* to get the Node object that was just created. .. warning:: cardObject is not returned """ if comment: self.bdf_out_file.write(comment) if card_name in ['DEQATN']: card_obj = card_lines card = card_lines #print("card =", '\n'.join(card_lines)) self.bdf_out_file.write('\n'.join(card_lines)) else: if is_list: fields = card_lines else: fields = to_fields(card_lines, card_name) # apply OPENMDAO syntax if self._is_dynamic_syntax: fields = [self._parse_dynamic_syntax(field) if '%' in field[0:1] else field for field in fields] card = wipe_empty_fields([interpret_value(field, fields) if field is not None else None for field in fields]) #print(card) card_obj = BDFCard(card) self.bdf_out_file.write(print_card_8(card_obj)) #for reject_card in self.reject_cards: #try: #print('comment =', comment) #except RuntimeError: #for field in reject_card: #if field is not None and '=' in field: #raise SyntaxError('cannot reject equal signed ' # 'cards\ncard=%s\n' % reject_card) #raise #self.reject_cards.append(card) #print('rejecting processed auto=rejected %s' % card) return card_obj
def __init__(self, card=None, data=None, comment=''): Method.__init__(self, card, data) if comment: self._comment = comment # CLAN self.mblkszs = [] self.iblkszs = [] self.ksteps = [] self.NJIs = [] # HESS self.alphaBjs = [] self.omegaBjs = [] self.LJs = [] self.NEJs = [] self.NDJs = [] if card: #: Set identification number. (Unique Integer > 0) self.sid = integer(card, 1, 'sid') #: Method of complex eigenvalue extraction self.method = string(card, 2, 'method') assert self.method in ['INV', 'HESS', 'CLAN'],( 'method=%s is not INV, HESS, CLAN' % (self.method)) #: Method for normalizing eigenvectors self.norm = string_or_blank(card, 3, 'norm') if self.norm == 'POINT': #: Grid or scalar point identification number. Required only if #: NORM='POINT'. (Integer>0) self.G = integer(card, 4, 'G') #: Component number. Required only if NORM='POINT' and G is a #: geometric grid point. (1<Integer<6) self.C = components(card, 5, 'C') else: self.G = blank(card, 4, 'G') self.C = blank(card, 5, 'C') #: Convergence criterion. (Real > 0.0. Default values are: #: 10^-4 for METHOD = "INV", #: 10^-15 for METHOD = "HESS", #: E is machine dependent for METHOD = "CLAN".) self.E = double_or_blank(card, 6, 'E') self.ndo = integer_double_string_or_blank(card, 7, 'ND0') # ALPHAAJ OMEGAAJ ALPHABJ OMEGABJ LJ NEJ NDJ fields = [interpret_value(field) for field in card[9:] ] self.alphaAjs = [] self.omegaAjs = [] nFields = len(fields) nRows = nFields // 8 if nFields % 7 > 0: nRows += 1 if self.method == 'CLAN': self.loadCLAN(nRows, card) elif self.method in ['HESS', 'INV']: # HESS, INV self.loadHESS_INV(nRows, card) else: msg = 'invalid EIGC method...method=|%r|' % (self.method) raise RuntimeError(msg) #assert card.nFields() < 8, 'card = %s' % card else: raise NotImplementedError('EIGC')
def __init__(self, card=None, data=None, comment=''): """ :: DVPREL2 ID TYPE PID PNAME/FID PMIN PMAX EQID 'DESVAR' DVID1 DVID2 DVID3 DVID4 DVID5 DVID6 DVID7 DVID8 -etc.- 'DTABLE' LABL1 LABL2 LABL3 LABL4 LABL5 LABL6 LABL7 LABL8 -etc.- """ if comment: self._comment = comment #: Unique identification number self.oid = integer(card, 1, 'oid') #: Name of a property entry, such as PBAR, PBEAM, etc self.Type = string(card, 2, 'Type') #: Property entry identification number self.pid = integer(card, 3, 'pid') #: Property name, such as 'T', 'A', or field position of the property #: entry, or word position in the element property table of the #: analysis model. Property names that begin with an integer such as #: 12I/T**3 may only be referred to by field position. #: (Character or Integer 0) self.pNameFid = integer_or_string(card, 4, 'pName_FID') #: Minimum value allowed for this property. If FID references a stress #: recovery location field, then the default value for PMIN is -1.0+35. #: PMIN must be explicitly set to a negative number for properties that #: may be less than zero (for example, field ZO on the PCOMP entry). #: (Real; Default = 1.E-15) #: .. todo:: bad default (see DVMREL1) self.pMin = double_or_blank(card, 5, 'pMin') #: Maximum value allowed for this property. (Real; Default = 1.0E20) self.pMax = double_or_blank(card, 6, 'pMax', 1e20) #: DEQATN entry identification number. (Integer > 0) self.eqID = integer_or_blank(card, 7, 'eqID') #: .. todo:: or blank? fields = [interpret_value(field) for field in card[9:]] #print "fields = ",fields iOffset = 9 iEnd = len(fields) + iOffset try: iDesvar = fields.index('DESVAR') + iOffset except ValueError: iDesvar = None try: iDTable = fields.index('DTABLE') + iOffset #iDesMax = iDTable # the index to start parsing DESVAR iDesStop = iDTable # the index to stop parsing DESVAR except ValueError: iDTable = None iDesStop = iEnd self.dvids = [] if iDesvar: n = 1 for i in range(10, iDesStop): dvid_name = 'DVID' + str(n) dvid = integer_or_blank(card, i, dvid_name) #print("%s = %s" % (dvid_name, dvid)) if dvid: assert dvid is not None assert dvid is not 'DESVAR' self.dvids.append(dvid) n += 1 self.labels = [] if iDTable: n = 1 for i in range(iDTable + 1, iEnd): label_name = 'Label' + str(n) label = string(card, i, label_name) #print("%s = %s" % (label_name, label)) if label: assert label is not 'DTABLE' self.labels.append(label)
def _parseEntry(lines): i = 0 options = [] value = None key = None paramType = None line = lines[i] #print line #print "*****lines = ",lines equalsCount = 0 for letter in line: if letter == '=': equalsCount += 1 lineUpper = line.upper() if lineUpper.startswith('SUBCASE'): #print("line = |%r|" % line) line2 = line.replace('=', '') sline = line2.split() if len(sline) != 2: msg = "trying to parse |%s|..." % line raise SyntaxError("Invalid Subcase: %s" % msg) (key, isubcase) = sline #print "key=|%s| isubcase=|%s|" %(key,isubcase) value = int(isubcase) #self. subcase = int(isubcase) paramType = 'SUBCASE-type' elif (lineUpper.startswith(('LABEL', 'SUBTITLE')) or lineUpper.startswith('TITLE')): eIndex = line.index('=') key = line[0:eIndex].strip() value = line[eIndex + 1:].strip() options = [] paramType = 'STRING-type' elif equalsCount == 1: # STRESS if '=' in line: (key, value) = line.strip().split('=') else: msg = 'expected item of form "name = value" line=|%r|' % ( line.strip()) raise RuntimeError(msg) key = key.strip() #print value value = value.strip() #print("key=|%s| value=|%s|" %(key, value)) paramType = 'STRESS-type' #if 'SET' in key: #(i,key,value,options,paramType) = parseSetType(i,line,lines,key,value) if '(' in key: # comma may be in line - STRESS-type #paramType = 'STRESS-type' sline = key.strip(')').split('(') key = sline[0] options = sline[1].split(',') # handle TEMPERATURE(INITIAL) and TEMPERATURE(LOAD) cards if key == 'TEMPERATURE' or key == 'TEMP': key = 'TEMPERATURE(%s)' % (options[0]) options = [] #print "key=|%s| options=%s" %(key,options) elif ' ' in key and ',' in value: # SET-type (with spaces, so SET 1 = 1, not SET = ALL) (i, key, value, options, paramType) = parseSetType(i, line, lines, key, value) elif ',' in value: # STRESS-type; special TITLE = stuffA,stuffB #print 'A ??? line = ',line #raise RuntimeError(line) pass else: # STRESS-type; TITLE = stuff #print 'B ??? line = ',line if ' ' in value: sline = value.split(' ') print("sline = ", sline) value = parseSetSline(sline) else: value = interpret_value(value) ### = in line elif lineUpper.startswith('BEGIN'): # begin bulk try: (key, value) = lineUpper.split(' ') except: msg = 'excepted "BEGIN BULK" found=|%r|' % (line) raise RuntimeError(msg) paramType = 'BEGIN_BULK-type' elif 'PARAM' in lineUpper: # param sline = line.split(',') if len(sline) != 3: raise SyntaxError("Param Parse: trying to parse |%s|..." % (line)) (key, value, options) = sline paramType = 'CSV-type' elif ' ' not in line: key = line.strip() value = line.strip() options = None paramType = 'KEY-type' else: msg = 'generic catch all...line=|%r|' % (line) #print 'C ??? line = ',line #raise RuntimeError(msg) key = '' value = line options = None paramType = 'KEY-type' i += 1 #print "done with ",key return (i, key, value, options, paramType)
def test_bad(self): val = _get_type('1.000000000D+00') #print "val = ", val val = interpret_value('1.000000000D+00')
def __init__(self, card=None, data=None, comment=''): """ +----------+--------+--------+-------+-----------+-------+-------+-------+-------+ | DVPREL2 | ID | TYPE | PID | PNAME/FID | PMIN | PMAX | EQID | | +----------+--------+--------+-------+-----------+-------+-------+-------+-------+ | | DESVAR | DVID1 | DVID2 | DVID3 | DVID4 | DVID5 | DVID6 | DVID7 | +----------+--------+--------+-------+-----------+-------+-------+-------+-------+ | | DVID8 | -etc.- | | | | | | | +----------+--------+--------+-------+-----------+-------+-------+-------+-------+ | | DTABLE | LABL1 | LABL2 | LABL3 | LABL4 | LABL5 | LABL6 | LABL7 | +----------+--------+--------+-------+-----------+-------+-------+-------+-------+ | | LABL8 | -etc.- | | | | | | | +----------+--------+--------+-------+-----------+-------+-------+-------+-------+ """ if comment: self._comment = comment if card: #: Unique identification number self.oid = integer(card, 1, 'oid') #: Name of a property entry, such as PBAR, PBEAM, etc self.Type = string(card, 2, 'Type') #: Property entry identification number self.pid = integer(card, 3, 'pid') #: Property name, such as 'T', 'A', or field position of the property #: entry, or word position in the element property table of the #: analysis model. Property names that begin with an integer such as #: 12I/T**3 may only be referred to by field position. #: (Character or Integer 0) self.pNameFid = integer_or_string(card, 4, 'pName_FID') #: Minimum value allowed for this property. If FID references a stress #: recovery location field, then the default value for PMIN is -1.0+35. #: PMIN must be explicitly set to a negative number for properties that #: may be less than zero (for example, field ZO on the PCOMP entry). #: (Real; Default = 1.E-15) #: .. todo:: bad default (see DVMREL1) self.pMin = double_or_blank(card, 5, 'pMin') #: Maximum value allowed for this property. (Real; Default = 1.0E20) self.pMax = double_or_blank(card, 6, 'pMax', 1e20) #: DEQATN entry identification number. (Integer > 0) self.dequation = integer_or_blank(card, 7, 'dequation') #: .. todo:: or blank? fields = [interpret_value(field) for field in card[9:]] iOffset = 9 iEnd = len(fields) + iOffset try: iDesvar = fields.index('DESVAR') + iOffset except ValueError: iDesvar = None try: iDTable = fields.index('DTABLE') + iOffset #iDesMax = iDTable # the index to start parsing DESVAR iDesStop = iDTable # the index to stop parsing DESVAR except ValueError: iDTable = None iDesStop = iEnd self.dvids = [] if iDesvar: n = 1 for i in range(10, iDesStop): dvid_name = 'DVID' + str(n) dvid = integer_or_blank(card, i, dvid_name) #print("%s = %s" % (dvid_name, dvid)) if dvid: assert dvid is not None assert dvid is not 'DESVAR' self.dvids.append(dvid) n += 1 self.labels = [] if iDTable: n = 1 for i in range(iDTable + 1, iEnd): label_name = 'Label' + str(n) label = string(card, i, label_name) #print("%s = %s" % (label_name, label)) if label: assert label is not 'DTABLE' self.labels.append(label) else: raise RuntimeError(data)
def test_bad(self): val = _get_dtype("1.000000000D+00") # print "val = ", val val = interpret_value("1.000000000D+00")
def _parseEntry(lines): i = 0 options = [] value = None key = None paramType = None line = lines[i] #print(line) #print("*****lines = ", lines) equalsCount = 0 for letter in line: if letter == '=': equalsCount += 1 line_upper = line.upper() if line_upper.startswith('SUBCASE'): #print("line = |%r|" % line) line2 = line.replace('=', '') sline = line2.split() if len(sline) != 2: msg = "trying to parse |%s|..." % line raise SyntaxError("Invalid Subcase: %s" % msg) (key, isubcase) = sline #print("key=%r isubcase=%r" % (key, isubcase)) value = int(isubcase) #self. subcase = int(isubcase) paramType = 'SUBCASE-type' elif (line_upper.startswith(('LABEL', 'SUBTITLE')) or line_upper.startswith('TITLE')): eIndex = line.index('=') key = line[0:eIndex].strip() value = line[eIndex + 1:].strip() options = [] paramType = 'STRING-type' elif equalsCount == 1: # STRESS if '=' in line: (key, value) = line.strip().split('=') else: msg = 'expected item of form "name = value" line=|%r|' % ( line.strip()) raise RuntimeError(msg) key = key.strip() #print(value) value = value.strip() #print("key=%r value=%r" % (key, value)) paramType = 'STRESS-type' #if 'SET' in key: #(i,key,value,options,paramType) = parseSetType(i,line,lines,key,value) if '(' in key: # comma may be in line - STRESS-type #paramType = 'STRESS-type' sline = key.strip(')').split('(') key = sline[0] options = sline[1].split(',') # handle TEMPERATURE(INITIAL) and TEMPERATURE(LOAD) cards if key == 'TEMPERATURE' or key == 'TEMP': key = 'TEMPERATURE(%s)' % (options[0]) options = [] #print("key=%r options=%s" % (key, options)) elif ' ' in key and ',' in value: # SET-type (with spaces, so SET 1 = 1, not SET = ALL) (i, key, value, options, paramType) = parseSetType( i, line, lines, key, value) elif ',' in value: # STRESS-type; special TITLE = stuffA,stuffB #print('A ??? line = ',line) #raise RuntimeError(line) pass else: # STRESS-type; TITLE = stuff #print('B ??? line = ',line) if ' ' in value: sline = value.split(' ') print("sline = ", sline) value = parseSetSline(sline) else: value = interpret_value(value) elif line_upper.startswith('BEGIN'): # begin bulk try: (key, value) = line_upper.split(' ') except: msg = 'excepted "BEGIN BULK" found=|%r|' % (line) raise RuntimeError(msg) paramType = 'BEGIN_BULK-type' elif 'PARAM' in line_upper: # param sline = line.split(',') if len(sline) != 3: raise SyntaxError("Param Parse: trying to parse %r..." % line) (key, value, options) = sline paramType = 'CSV-type' elif ' ' not in line: key = line.strip() value = line.strip() options = None paramType = 'KEY-type' else: msg = 'generic catch all...line=%r' % line #print('C ??? line = ', line) #raise RuntimeError(msg) key = '' value = line options = None paramType = 'KEY-type' i += 1 #print("done with %s" % key) return (i, key, value, options, paramType)
def __init__(self, card=None, data=None, comment=''): Method.__init__(self, card, data) if comment: self._comment = comment # CLAN self.mblkszs = [] self.iblkszs = [] self.ksteps = [] self.NJIs = [] # HESS self.alphaBjs = [] self.omegaBjs = [] self.LJs = [] self.NEJs = [] self.NDJs = [] if card: #: Set identification number. (Unique Integer > 0) self.sid = integer(card, 1, 'sid') #: Method of complex eigenvalue extraction self.method = string(card, 2, 'method') assert self.method in [ 'INV', 'HESS', 'CLAN' ], ('method=%s is not INV, HESS, CLAN' % (self.method)) #: Method for normalizing eigenvectors self.norm = string_or_blank(card, 3, 'norm') if self.norm == 'POINT': #: Grid or scalar point identification number. Required only if #: NORM='POINT'. (Integer>0) self.G = integer(card, 4, 'G') #: Component number. Required only if NORM='POINT' and G is a #: geometric grid point. (1<Integer<6) self.C = components(card, 5, 'C') else: self.G = blank(card, 4, 'G') self.C = blank(card, 5, 'C') #: Convergence criterion. (Real > 0.0. Default values are: #: 10^-4 for METHOD = "INV", #: 10^-15 for METHOD = "HESS", #: E is machine dependent for METHOD = "CLAN".) self.E = double_or_blank(card, 6, 'E') self.ndo = integer_double_string_or_blank(card, 7, 'ND0') # ALPHAAJ OMEGAAJ ALPHABJ OMEGABJ LJ NEJ NDJ fields = [interpret_value(field) for field in card[9:]] self.alphaAjs = [] self.omegaAjs = [] nFields = len(fields) nRows = nFields // 8 if nFields % 7 > 0: nRows += 1 if self.method == 'CLAN': self.loadCLAN(nRows, card) elif self.method in ['HESS', 'INV']: # HESS, INV self.loadHESS_INV(nRows, card) else: msg = 'invalid EIGC method...method=|%r|' % (self.method) raise RuntimeError(msg) #assert card.nFields() < 8, 'card = %s' % card else: raise NotImplementedError('EIGC')