def nastran_to_abaqus(nastran_model, abqaqus_filename_out):
    """
    Handles CTRIA3, CQUAD4

    TODO: doesn't renumber
    TDOO: completely ignores properties
    TODO: assuming constant property
    """
    log = nastran_model.log
    model = Abaqus(log=log, debug=True)
    node_sets = None
    element_sets = None
    solid_sections = None

    ctria3s = []
    cquad4s = []
    for eid, elem in iteritems(nastran_model.elements):
        if elem.type == 'CTRIA3':
            node_ids = elem.nodes
            ctria3 = [eid] + node_ids
            ctria3s.append(ctria3)
        elif elem.type == 'CQUAD4':
            node_ids = elem.nodes
            cquad4 = [eid] + node_ids
            cquad4s.append(cquad4)
        else:
            pass
            #log.warning('skipping:\n%s' % elem)

    element_types = {
        'cpe3' : ctria3s,
        'cpe4' : cquad4s,
    }
    name = 'model'
    icd_transform, icp_transform, xyz_cp, nid_cp_cd = nastran_model.get_displacement_index_xyz_cp_cd(
        fdtype='float64', sort_ids=True)
    nids = nid_cp_cd[:, 0]
    xyz_cid0 = nastran_model.transform_xyzcp_to_xyz_cid(
        xyz_cp, nids, icp_transform, cid=0, in_place=False)
    nodes = xyz_cid0

    part = Part(name, nids, nodes, element_types, node_sets, element_sets,
                solid_sections, log)
    model.parts[name] = part
    model.write(abqaqus_filename_out)
    return model
Beispiel #2
0
    def read_part(self, lines, iline, line0, word):
        """reads a Part object"""
        sline2 = word.split(',', 1)[1:]
        #aq
        assert len(sline2) == 1, 'looking for part_name; word=%r sline2=%s' % (
            word, sline2)
        name_slot = sline2[0]
        assert 'name' in name_slot, name_slot
        part_name = name_slot.split('=', 1)[1]
        self.log.debug('part_name = %r' % part_name)
        self.part_name = part_name

        iline += 1
        line0 = lines[iline].strip().lower()
        assert line0 == '*node', line0

        #iline += 1
        #line0 = lines[iline].strip().lower()

        #iline += 1
        #line0 = lines[iline].strip().lower()
        #print('line0 * = ', line0)
        element_types = {}
        #print('resetting nids...')
        nids = []
        nodes = []
        is_start = True
        solid_sections = []
        while not line0.startswith('*end part'):
            #if is_start:
            iline += 1  # skips over the header line
            self.log.debug('  ' + line0)
            if '*node' in line0:
                #print('  Node iline=%s' % iline)
                line0 = lines[iline].strip().lower()
                #print('  node line0 =', line0)
                is_failed = False
                #if len(nids) > 0:
                #nids0 = copy.deepcopy(nids)
                #nids = []
                #is_failed = False

                #print('  ', line0)
                while not line0.startswith('*'):
                    sline = line0.split(',')
                    nids.append(sline[0])
                    nsline = len(sline)
                    if nsline == 3:
                        sline.append(0.)
                        nodes.append(sline[1:])
                    elif nsline == 4:
                        nodes.append(sline[1:])
                    else:
                        raise NotImplementedError(sline)

                    iline += 1
                    line0 = lines[iline].strip().lower()
                nnodes = len(nids)
                if is_failed:
                    msg = 'nids will overwrite nids0!\n'
                    #msg += 'nids0 = %s\n' % nids0
                    msg += 'nids = %s\n' % nids
                    raise RuntimeError(msg)

            elif '*element' in line0:
                line0, iline, etype, elements = self._read_elements(
                    lines, line0, iline)
                element_types[etype] = elements

            elif '*nset' in line0:
                params_map = get_param_map(word)
                name = params_map['name']
                line0 = lines[iline].strip().lower()
                assert 'part' in params_map, params_map
                set_ids, iline, line0 = read_set(lines, iline, line0,
                                                 params_map)

            elif '*elset' in line0:
                # TODO: skips header parsing
                #iline += 1
                params_map = get_param_map(word)
                name = params_map['name']
                assert 'part' in params_map, params_map
                line0 = lines[iline].strip().lower()
                set_ids, iline, line0 = read_set(lines, iline, line0,
                                                 params_map)

            elif '*surface' in line0:
                # TODO: skips header parsing
                #iline += 1
                line0 = lines[iline].strip().lower()
                data_lines = []
                while not line0.startswith('*'):
                    data_lines.append(line0.split(','))
                    iline += 1
                    line0 = lines[iline].strip().lower()

            elif '*solid section' in line0:
                # TODO: skips header parsing
                #iline += 1
                word2 = line0.strip('*').lower()
                params_map = get_param_map(word2)
                self.log.debug('    param_map = %s' % params_map)
                #line0 = lines[iline].strip().lower()
                data_lines, iline, line0 = self._read_star_block2(
                    lines, iline, line0)
                #for line in data_lines:
                #print(line)
                solid_section = SolidSection(params_map, data_lines)
                solid_sections.append(solid_section)

            elif '*cohesive section' in line0:
                # TODO: skips header parsing
                #iline += 1
                line0 = lines[iline].strip().lower()
                data_lines = []
                while not line0.startswith('*'):
                    data_lines.append(line0.split(','))
                    iline += 1
                    line0 = lines[iline].strip().lower()
            elif '*mass' in line0:
                # TODO: skips header parsing
                #iline += 1
                line0 = lines[iline].strip().lower()
                data_lines = []
                while not line0.startswith('*'):
                    data_lines.append(line0.split(','))
                    iline += 1
                    line0 = lines[iline].strip().lower()
            elif '*rotary inertia' in line0:
                # TODO: skips header parsing
                #iline += 1
                line0 = lines[iline].strip().lower()
                data_lines = []
                while not line0.startswith('*'):
                    data_lines.append(line0.split(','))
                    iline += 1
                    line0 = lines[iline].strip().lower()
            else:
                msg = 'line=%r\n' % line0
                allowed = [
                    '*node', '*element', '*nset', '*elset', '*surface',
                    '*solid section', '*cohesive section'
                ]
                msg += 'expected=[%r]' % ', '.join(allowed)
                raise NotImplementedError(msg)

            line0 = lines[iline].strip().lower()
            is_start = False

            #print(line0)
            #qqq
        node_sets = []
        element_sets = []

        if self.debug:
            self.log.debug('part_name = %r' % part_name)
        part = Part(part_name, nids, nodes, element_types, node_sets,
                    element_sets, solid_sections, self.log)
        self.part_name = None
        return iline, line0, part_name, part
Beispiel #3
0
    def read_part(self, lines, iline, line0, word):
        """reads a Part object"""
        sline2 = word.split(',', 1)[1:]

        assert len(sline2) == 1, 'looking for part_name; word=%r sline2=%s' % (
            word, sline2)
        name_slot = sline2[0]
        assert 'name' in name_slot, name_slot
        part_name = name_slot.split('=', 1)[1]
        self.log.debug('part_name = %r' % part_name)
        #self.part_name = part_name

        iline += 1
        line0 = lines[iline].strip().lower()
        assert line0.startswith('*node'), line0

        #iline += 1
        #line0 = lines[iline].strip().lower()

        #iline += 1
        #line0 = lines[iline].strip().lower()
        #print('line0 * = ', line0)
        element_types = {}
        node_sets = {}
        element_sets = {}
        #print('resetting nids...')
        nids = []
        nodes = []
        unused_is_start = True
        solid_sections = []
        while not line0.startswith('*end part'):
            #if is_start:
            iline += 1  # skips over the header line
            self.log.debug('  ' + line0)
            unused_iword = line0.strip('*').lower()
            #self.log.info('part: %s' % iword)
            if '*node' in line0:
                assert len(nids) == 0, nids
                iline, line0, nids, nodes = read_node(lines, iline, self.log)

            elif '*element' in line0:
                line0, iline, etype, elements = self._read_elements(
                    lines, line0, iline)
                element_types[etype] = elements

            elif '*nset' in line0:
                params_map = get_param_map(iline,
                                           line0,
                                           required_keys=['nset'])
                set_name = params_map['nset']
                line0 = lines[iline].strip().lower()
                set_ids, iline, line0 = read_set(lines, iline, line0,
                                                 params_map)
                node_sets[set_name] = set_ids

            elif '*elset' in line0:
                # TODO: skips header parsing
                #iline += 1
                #print('elset: ', line0)
                params_map = get_param_map(iline,
                                           line0,
                                           required_keys=['elset'])
                set_name = params_map['elset']
                line0 = lines[iline].strip().lower()
                set_ids, iline, line0 = read_set(lines, iline, line0,
                                                 params_map)
                element_sets[set_name] = set_ids

            elif '*surface' in line0:
                # TODO: skips header parsing
                #iline += 1
                line0 = lines[iline].strip().lower()
                data_lines = []
                while not line0.startswith('*'):
                    data_lines.append(line0.split(','))
                    iline += 1
                    line0 = lines[iline].strip().lower()

            elif '*solid section' in line0:
                iline, solid_section = read_solid_section(
                    line0, lines, iline, self.log)
                solid_sections.append(solid_section)

            elif '*cohesive section' in line0:
                # TODO: skips header parsing
                #iline += 1
                line0 = lines[iline].strip().lower()
                data_lines = []
                while not line0.startswith('*'):
                    data_lines.append(line0.split(','))
                    iline += 1
                    line0 = lines[iline].strip().lower()
            elif '*mass' in line0:
                # TODO: skips header parsing
                #iline += 1
                line0 = lines[iline].strip().lower()
                data_lines = []
                while not line0.startswith('*'):
                    data_lines.append(line0.split(','))
                    iline += 1
                    line0 = lines[iline].strip().lower()
            elif '*rotary inertia' in line0:
                # TODO: skips header parsing
                #iline += 1
                line0 = lines[iline].strip().lower()
                data_lines = []
                while not line0.startswith('*'):
                    data_lines.append(line0.split(','))
                    iline += 1
                    line0 = lines[iline].strip().lower()
            else:
                msg = 'line=%r\n' % line0
                allowed = [
                    '*node', '*element', '*nset', '*elset', '*surface',
                    '*solid section', '*cohesive section'
                ]
                msg += 'expected=[%r]' % ', '.join(allowed)
                raise NotImplementedError(msg)

            line0 = lines[iline].strip().lower()
            unused_is_start = False

            #print(line0)
        #node_sets = []
        #element_sets = []

        if self.debug:
            self.log.debug('part_name = %r' % part_name)
        part = Part(part_name, nids, nodes, element_types, node_sets,
                    element_sets, solid_sections, self.log)
        return iline, line0, part_name, part