def assert_fields(card1, card2): 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_8(field1) value2a = print_field_8(field2) if value1a != value2a: value1 = print_field_8(interpret_value(value1a)) value2 = print_field_8(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] Parameters ---------- fields : List[int/str] the fields to expand set_fields : bool; default=True Should the fields be converted to a set and then back to a list? This is useful for [2, 'THRU' 5, 1] sort_fields : bool; default=False Should the fields be sorted at the end? .. 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 by_case = False if i + 2 < nfields and fields[i + 2] == 'BY': by = interpret_value(fields[i + 3]) else: by = 1 by_case = True min_value = interpret_value(fields[i - 1]) max_value = interpret_value(fields[i + 1]) max_range = int((max_value - min_value) // by + 1) # max range value for j in range(0, max_range): # +1 is to include final point value = min_value + by * j out.append(value) if by_case: # 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_complex(self, card): """reads a complex DMI column""" #msg = 'complex matrices not supported in the DMI reader...' #raise NotImplementedError(msg) # column number j = integer(card, 2, 'icol') # counter i = 0 fields = [interpret_value(field) for field in card[3:]] # Complex, starts at A(i1,j)+imag*A(i1,j), goes to A(i2,j) in a column while i < len(fields): i1 = fields[i] assert isinstance(i1, int), card i += 1 is_done_reading_floats = False while not is_done_reading_floats and i < len(fields): value = fields[i] #print("i=%s len(fields)=%s value=%s" % ( #i, len(fields), value)) if isinstance(value, integer_types): is_done_reading_floats = True elif isinstance(value, float): complex_value = fields[i + 1] assert isinstance(complex_value, float), card self.GCj.append(j) self.GCi.append(i1) self.Real.append(value) self.Complex.append(complex_value) i += 2 else: raise NotImplementedError()
def expand_thru_exclude(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] fields_out = [] nfields = len(fields) for i in range(nfields): if fields[i] == 'THRU': sorted_list = [] for j in range(fields[i - 1], fields[i + 1]): sorted_list.append(fields[j]) elif fields[i] == 'EXCLUDE': stored_set = set(sorted_list) while fields[i] < max(sorted_list): stored_set.remove(fields[i]) sorted_list = list(stored_set) else: if sorted_list: fields_out += sorted_list fields_out.append(fields[i]) return fields_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 compare(value_in): field = print_field_8(value_in) val = interpret_value(field) if val != 0: p = (val - value_in) / val if p > 0.01: raise ValueError('val=%s value_in=%s' % (val, value_in))
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') option_values = [interpret_value(field) for field in card[9:]] self.options = [] self.values = [] for option_value in option_values: try: (option, value) = option_value.split('=') except AttributeError: msg = 'parsing EIGRL card incorrectly; option_values=%s\ncard=%s' % ( option_values, card) raise RuntimeError(msg) 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 assert_fields(card1, card2): try: fields1 = wipe_empty_fields_typed(card1.repr_fields()) fields2 = wipe_empty_fields_typed(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_8(fields1), print_card_8(fields2))) raise RuntimeError(msg) msg_end = '' max_int = 99999999 for (i, field1, field2) in zip(count(), fields1, fields2): if isinstance(field1, int) and field1 > max_int: value1a = print_field_16(field1) value2a = print_field_16(field2) else: value1a = print_field_8(field1) value2a = print_field_8(field2) msg_end += '%-2s: %-8s %-8s\n' % (i, field1, field2) if value1a != value2a: if isinstance(field1, int) and field1 > max_int: value1 = print_field_16(interpret_value(value1a)) value2 = print_field_16(interpret_value(value2a)) else: value1 = print_field_8(interpret_value(value1a)) value2 = print_field_8(interpret_value(value2a)) if value1 != value2: msg = 'value1 != value2\n' msg += ('card_name=%s ID=%s i=%s field1=%r field2=%r value1=%r ' 'value2=%r\n%r\n%r\n' % (fields1[0], fields1[1], i, field1, field2, value1, value2, fields1, fields2)) raise RuntimeError(msg + msg_end)
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 add_card(cls, card, comment=''): sid = integer(card, 1, 'sid') method = string(card, 2, 'method') assert method in ['ARNO', 'INV', 'HESS', 'CLAN', 'ISRR', 'IRAM'], ( 'method=%s is not ARNO, INV, HESS, CLAN, ISRR, IRAM' % method) norm = string_or_blank(card, 3, 'norm') if norm == 'POINT': G = integer(card, 4, 'G') C = components(card, 5, 'C') else: G = blank(card, 4, 'G') C = blank(card, 5, 'C') E = double_or_blank(card, 6, 'E') 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:]] alphaAjs = [] omegaAjs = [] nfields = len(fields) nrows = nfields // 8 if nfields % 8 > 0: nrows += 1 #if nrows == 0: #msg = 'invalid row count=0; nfields=%s \ncard=%s\nfields=%s' % ( #nfields, card, fields) #raise RuntimeError(msg) if method == 'CLAN': alphaAjs, omegaAjs, mblkszs, iblkszs, ksteps, NJIs = cls._load_clan(nrows, card) elif method in ['HESS', 'INV']: # HESS, INV cls._load_hess_inv(nrows, method, card) elif method == 'ISRR': cls._load_isrr(nrows, card) else: msg = 'invalid EIGC method...method=%r' % method raise RuntimeError(msg) #assert card.nFields() < 8, 'card = %s' % card return EIGC(sid, method, norm, G, C, E, ndo, comment=comment)
def add_card(cls, card, comment=''): sid = integer(card, 1, 'sid') v1 = double_or_blank(card, 2, 'v1') v2 = double_or_blank(card, 3, 'v2') nd = integer_or_blank(card, 4, 'nd') msglvl = integer_or_blank(card, 5, 'msglvl', 0) maxset = integer_or_blank(card, 6, 'maxset') shfscl = double_or_blank(card, 7, 'shfscl') norm = string_or_blank(card, 8, 'norm') option_values = [interpret_value(field) for field in card[9:]] options = [] values = [] for option_value in option_values: try: (option, value) = option_value.split('=') except AttributeError: msg = 'parsing EIGRL card incorrectly; option_values=%s\ncard=%s' % ( option_values, card) raise RuntimeError(msg) options.append(option) 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: norm = string_or_blank(card, 8, 'norm') #assert len(card) <= 9, 'len(EIGRL card) = %i\ncard=%s' % (len(card), card) assert len(card) <= 10, 'len(EIGRL card) = %i\ncard=%s' % (len(card), 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)) return EIGRL(sid, v1, v2, nd, msglvl, maxset, shfscl, norm, options, values, comment=comment)
def test_bad(self): val = _get_dtype('1.000000000D+00') #print "val = ", val val = interpret_value('1.000000000D+00')
def add_card(self, card_lines, card_name, comment='', is_list=True): """ Adds a card object to the BDF object using a streaming approach. Parameters ---------- card_lines : List[str] the list of the card fields >>> ['GRID,1,2',] # (is_list = False) >>> ['GRID',1,2,] # (is_list = True; default) card_name : str the card_name -> 'GRID' comment : str; default=True an optional the comment for the card is_list : bool; default=True changes card_lines from a list of lines to a list of fields Returns ------- card_object : BDFCard() 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 _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 test_bad(self): val = _get_dtype('1.000000000D+00') #print "val = ", val val = interpret_value('1.000000000D+00')
def expand_thru_case_control(set_value): """ Expands a case control SET card Parameters ---------- set_value : str??? ??? Returns ------- values : List[int] / List[float] the values in the SET Examples -------- **This hasn't been verified** #set_value = 'SET 88 = 1 THRU 5, 20 THRU 30 BY 2' set_value = ['1 THRU 5', '20 THRU 30 BY 2'] >>> values = expand_thru_case_control(set_value) [1, 2, 3, 4, 5, 20, 22, 24, 26, 28, 30] """ set_value2 = set([]) add_mode = True imin = 0 imax = 0 #print('set_value = %r' % set_value) for ivalue in set_value: if isinstance(ivalue, integer_types): assert add_mode is True, add_mode set_value2.add(ivalue) continue ivalue = ivalue.strip() #print(' ivalue=%r; type=%s' % (ivalue, type(ivalue))) if '/' in ivalue: set_value2.add(ivalue) else: #if 'ALL' in ivalue: #msg = ('ALL is not supported on CaseControlDeck ' #'SET card\nvalue=%r\nset=%r' % (ivalue, set_value)) #raise RuntimeError(msg) #elif 'EXCEPT' in ivalue: #msg = ('EXCEPT is not supported on CaseControlDeck ' #'SET card\nvalue=%r\nset=%r' % (ivalue, set_value)) #raise RuntimeError(msg) ivalue = interpret_value(ivalue, card=str(set_value)) if isinstance(ivalue, integer_types): #print(' isdigit') #ivalue = int(ivalue) if not imin < ivalue < imax: add_mode = True #print(' break...\n') if add_mode: #print(' adding %s' % ivalue) set_value2.add(ivalue) else: #print(' removing %s' % ivalue) set_value2.remove(ivalue) imin = ivalue elif isinstance(ivalue, float): assert add_mode is True, add_mode set_value2.add(ivalue) elif isinstance(ivalue, string_types): #print(' not digit=%r' % set_value) if set_value == 'EXCLUDE': msg = ('EXCLUDE is not supported on CaseControlDeck ' 'SET card\n') raise RuntimeError(msg) elif 'THRU' in ivalue: svalues = ivalue.split() #print(' svalues=%s' % svalues) if len(svalues) == 3: assert add_mode is True, add_mode imin, thru, imax = svalues assert thru == 'THRU', thru imin = int(imin) imax = int(imax) assert imax > imin, 'imin=%s imax=%s' % (imin, imax) for jthru in range(imin, imax + 1): set_value2.add(jthru) elif len(svalues) == 4: imin, thru, imax, by_except = svalues imin = int(imin) imax = int(imax) assert imax > imin, 'imin=%s imax=%s' % (imin, imax) assert by_except == 'EXCEPT', by_except for jthru in range(imin, imax + 1): set_value2.add(jthru) add_mode = False elif len(svalues) == 5: imin, thru, imax, by_except, increment_except = svalues imin = int(imin) imax = int(imax) assert imax > imin, 'imin=%s imax=%s' % (imin, imax) increment_except = int(increment_except) if by_except == 'BY': for jthru in range(imin, imax + 1, by_except): set_value2.add(jthru) add_mode = True elif by_except == 'EXCEPT': for jthru in range(imin, imax + 1): if jthru == increment_except: continue set_value2.add(jthru) add_mode = False else: raise RuntimeError(ivalue) else: msg = ('expected data of the form: ' '"10 THRU 20" or "10 THRU 20 BY 5"\n' 'actual=%r; input=%s' % (ivalue.strip(), set_value)) raise RuntimeError(msg) else: assert add_mode is True, add_mode set_value2.add(ivalue) list_values = list(set_value2) try: list_values.sort() except TypeError: msg = 'sort error: list_values=%s' % (list_values) raise TypeError(msg) #print('end of expansion = %s' % list_values) return list_values
def test_bad(self): _get_dtype('1.000000000D+00') interpret_value('1.000000000D+00')
def add_card(cls, card, comment=''): """ Adds an EIGRL card from ``BDF.add_card(...)`` Parameters ---------- card : BDFCard() a BDFCard object comment : str; default='' a comment for the card """ sid = integer(card, 1, 'sid') v1 = double_or_blank(card, 2, 'v1') v2 = double_or_blank(card, 3, 'v2') nd = integer_or_blank(card, 4, 'nd') msglvl = integer_or_blank(card, 5, 'msglvl', 0) maxset = integer_or_blank(card, 6, 'maxset') shfscl = double_or_blank(card, 7, 'shfscl') norm = string_or_blank(card, 8, 'norm') option_values = [interpret_value(field) for field in card[9:]] options = [] values = [] for option_value in option_values: try: (option, value) = option_value.split('=') except AttributeError: msg = 'parsing EIGRL card incorrectly; option_values=%s\ncard=%s' % ( option_values, card) raise RuntimeError(msg) options.append(option) 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: norm = string_or_blank(card, 8, 'norm') #assert len(card) <= 9, 'len(EIGRL card) = %i\ncard=%s' % (len(card), card) assert len(card) <= 10, 'len(EIGRL card) = %i\ncard=%s' % (len(card), 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)) return EIGRL(sid, v1, v2, nd, msglvl, maxset, shfscl, norm, options, values, comment=comment)
def expand_thru_case_control(set_value): # type: (List[Union[int, float, str]]) -> List[int] """ Expands a case control SET card Parameters ---------- set_value : str??? ??? Returns ------- values : List[int] / List[float] the values in the SET Examples -------- **This hasn't been verified** #set_value = 'SET 88 = 1 THRU 5, 20 THRU 30 BY 2' set_value = ['1 THRU 5', '20 THRU 30 BY 2'] >>> values = expand_thru_case_control(set_value) [1, 2, 3, 4, 5, 20, 22, 24, 26, 28, 30] """ set_value2 = set() add_mode = True imin_int = 0 imax_int = 0 #print('set_value = %r' % set_value) for ivalue in set_value: #print('----------') if isinstance(ivalue, integer_types): assert add_mode is True, add_mode set_value2.add(ivalue) continue ivalue_str = ivalue.strip() #print(' ivalue=%r; type=%s add=%s' % (ivalue, type(ivalue), add_mode)) if '/' in ivalue_str: set_value2.add(ivalue_str) else: #if 'ALL' in ivalue: #msg = ('ALL is not supported on CaseControlDeck ' #'SET card\nvalue=%r\nset=%r' % (ivalue, set_value)) #raise RuntimeError(msg) #elif 'EXCEPT' in ivalue: #msg = ('EXCEPT is not supported on CaseControlDeck ' #'SET card\nvalue=%r\nset=%r' % (ivalue, set_value)) #raise RuntimeError(msg) ivalue2 = interpret_value( ivalue_str, card=str(set_value)) # type: Optional[Union[int, float, str]] if isinstance(ivalue2, integer_types): #print(' isdigit') #print(' imin=%s ivalue2=%s imax=%s' % (imin_int, ivalue2, imax_int)) #ivalue = int(ivalue) if not imin_int < ivalue2 < imax_int: add_mode = True #print(' break...\n') if add_mode: #print(' adding %s' % ivalue) set_value2.add(ivalue2) else: #print(' removing %s' % ivalue2) set_value2.remove(ivalue2) imin_int = int(ivalue2) elif isinstance(ivalue2, float): assert add_mode is True, add_mode set_value2.add(ivalue2) elif isinstance(ivalue2, str): #print(' not digit=%r' % set_value) if set_value == 'EXCLUDE': msg = ('EXCLUDE is not supported on CaseControlDeck ' 'SET card\n') raise RuntimeError(msg) elif 'THRU' in ivalue2: set_valuesi, imin_int, imax_int, add_mode = _expand_thru_case_control_string_thru( set_value, ivalue2, add_mode) set_value2.update(set_valuesi) else: assert add_mode is True, add_mode #print('else...', ivalue) set_value2.add(ivalue.strip()) else: raise NotImplementedError(ivalue2) list_values = list(set_value2) try: list_values.sort() except TypeError: msg = 'sort error: list_values=%s set_value2=%s' % (list_values, set_value2) raise TypeError(msg) #print('end of expansion = %s' % list_values) return list_values
def add_card(cls, card, comment=''): """ Adds an EIGC card from ``BDF.add_card(...)`` Parameters ---------- card : BDFCard() a BDFCard object comment : str; default='' a comment for the card """ sid = integer(card, 1, 'sid') method = string(card, 2, 'method') assert method in [ 'ARNO', 'INV', 'HESS', 'CLAN', 'ISRR', 'IRAM', 'DET' ], ('method=%s is not ARNO, INV, HESS, CLAN, ISRR, IRAM, DET' % method) norm = string_or_blank(card, 3, 'norm', 'MAX') if norm == 'POINT': grid = integer(card, 4, 'G') component = parse_components(card, 5, 'C') else: grid = blank(card, 4, 'G') component = blank(card, 5, 'C') epsilon = double_or_blank(card, 6, 'epsilon') neigenvalues = integer_double_string_or_blank(card, 7, 'ND0/neigenvalues') # ALPHAAJ OMEGAAJ ALPHABJ OMEGABJ LJ NEJ NDJ fields = [interpret_value(field) for field in card[9:]] #-------CLAN-------------- mblkszs = [] iblkszs = [] ksteps = [] NJIs = [] #-------CLAN-------------- #-------HESS-------------- alphaAjs = [] alphaBjs = [] omegaAjs = [] omegaBjs = [] mblkszs = [] iblkszs = [] ksteps = [] LJs = [] NEJs = [] NDJs = [] #-------HESS-------------- #-------ISRR-------------- shift_r1 = 0.0 shift_i1 = 0.0 isrr_flag = 0 nd1 = None #-------ISRR-------------- nfields = len(fields) nrows = nfields // 8 if nfields % 8 > 0: nrows += 1 #if nrows == 0: #msg = 'invalid row count=0; nfields=%s \ncard=%s\nfields=%s' % ( #nfields, card, fields) #raise RuntimeError(msg) if method == 'CLAN': alphaAjs, omegaAjs, mblkszs, iblkszs, ksteps, NJIs = cls._load_clan( nrows, card) elif method in ['HESS', 'INV', 'DET']: # HESS, INV alphaAjs, omegaAjs, alphaBjs, omegaBjs, LJs, NEJs, NDJs = cls._load_hess_inv( nrows, method, card) elif method == 'ISRR': shift_r1, shift_i1, isrr_flag, nd1 = cls._load_isrr(nrows, card) else: msg = 'invalid EIGC method...method=%r' % method raise RuntimeError(msg) #assert card.nfields() < 8, 'card = %s' % card return EIGC( sid, method, grid, component, epsilon, neigenvalues, norm, # common mblkszs, iblkszs, ksteps, NJIs, # CLAN alphaAjs, omegaAjs, alphaBjs, omegaBjs, LJs, NEJs, NDJs, # HESS/INV shift_r1, shift_i1, isrr_flag, nd1, # ISRR comment=comment)
def _parse_entry(lines): i = 0 options = [] value = None key = None param_type = None line = lines[i] #print(line) #print("*****lines = ", lines) equals_count = 0 for letter in line: if letter == '=': equals_count += 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) param_type = '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 = [] param_type = 'STRING-type' elif equals_count == 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)) param_type = 'STRESS-type' #if 'SET' in key: #(i, key, value, options, param_type) = parse_set_type(i,line,lines,key,value) if '(' in key: # comma may be in line - STRESS-type #param_type = 'STRESS-type' sline = key.strip(')').split('(') key = sline[0] options = sline[1].split(',') # handle TEMPERATURE(INITIAL) and TEMPERATURE(LOAD) cards if key in ['TEMPERATURE', '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, param_type) = parse_set_type( 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 = parse_set_sline(sline) else: value = interpret_value(value) elif line_upper.startswith('BEGIN'): # begin bulk try: (key, value) = line_upper.split(' ') except ValueError: msg = 'excepted "BEGIN BULK" found=%r' % (line) raise RuntimeError(msg) param_type = '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 param_type = 'CSV-type' elif ' ' not in line: key = line.strip() value = line.strip() options = None param_type = 'KEY-type' else: msg = 'generic catch all...line=%r' % line #print('C ??? line = ', line) #raise RuntimeError(msg) key = '' value = line options = None param_type = 'KEY-type' i += 1 #print("done with %s" % key) return (i, key, value, options, param_type)
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 #: MSC 2014 = [INV, HESS, CLAN, IRAM] #: NX 8.5 = [INV, HESS, CLAN, ISRR] #: Autodesk 2015 = [ARNO, HESS, CLAN] self.method = string(card, 2, 'method') assert self.method in ['ARNO', 'INV', 'HESS', 'CLAN', 'ISRR', 'IRAM'], ( 'method=%s is not ARNO, INV, HESS, CLAN, ISRR, IRAM' % 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^-8 for METHOD = "CLAN", #: 10^-8 for METHOD = "ISRR", #: 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 % 8 > 0: nrows += 1 #if nrows == 0: #raise RuntimeError('invalid row count=0; nfields=%s \ncard=%s\nfields=%s' % (nfields, card, fields)) if self.method == 'CLAN': self.loadCLAN(nrows, card) elif self.method in ['HESS', 'INV']: # HESS, INV self.loadHESS_INV(nrows, card) elif self.method == 'ISRR': self._load_isrr(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')